Move events and requests into messages

Merge the events and requests categories in lib/link into messages and
use the class name of the message to determine which handler to call.

Also swaps the order of the arguments for forwardInstanceRequest to be
consistent with the rest of the lib/link code and fixes up the docs for
requests and events.
This commit is contained in:
Hornwitser committed 2019-11-30 00:08:10 +01:00
1 parent 278dc9b2d2
commit 039b41d3e6
5 files changed
+68 -57

No files matched your search

+8 -8
View File
@@ -289,7 +289,7 @@ class Slave extends link.Client {
*
* Called by the handler for InstanceRequest.
*/
async forwardInstanceRequest(message, handler) {
async forwardInstanceRequest(handler, message) {
let instance = this.instances.get(message.data.instance_id);
if (!instance) {
throw new errors.RequestError(`Instance with ID ${instanceId} does not exist`);
@@ -312,19 +312,19 @@ class Slave extends link.Client {
this.updateInstances();
}
async createSaveRequestHandler(instance, message) {
async createSaveInstanceRequestHandler(instance, message) {
await instance.createSave();
}
async startInstanceRequestHandler(instance, message) {
async startInstanceInstanceRequestHandler(instance, message) {
await instance.start(this.config, this.socket);
}
async stopInstanceRequestHandler(instance, message) {
async stopInstanceInstanceRequestHandler(instance, message) {
await instance.stop();
}
async deleteInstanceRequestHandler(instance, message) {
async deleteInstanceInstanceRequestHandler(instance, message) {
await instance.stop();
this.instances.delete(instance.config.id);
@@ -332,7 +332,7 @@ class Slave extends link.Client {
this.updateInstances();
}
async sendRconRequestHandler(instance, message) {
async sendRconInstanceRequestHandler(instance, message) {
let result = await instance.server.sendRcon(message.data.command);
return { result };
}
@@ -378,7 +378,7 @@ class Slave extends link.Client {
hookInstance(instance) {
instance.server.on('output', (output) => {
link.events.instanceOutput.send(this, { instance_id: instance.config.id, output })
link.messages.instanceOutput.send(this, { instance_id: instance.config.id, output })
});
}
@@ -391,7 +391,7 @@ class Slave extends link.Client {
name: instance.config.name,
});
}
link.events.updateInstances.send(this, { instances: list });
link.messages.updateInstances.send(this, { instances: list });
}
async start() {