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

+3 -3
View File
@@ -254,7 +254,7 @@ class BaseConnection extends link.Connection {
link.attachAllMessages(this);
}
async forwardInstanceRequest(message, request) {
async forwardInstanceRequest(request, message) {
let instance = db.instances.get(message.data.instance_id);
if (!instance) {
throw new errors.RequestError(`Instance with ID ${instance_id} does not exist`);
@@ -321,7 +321,7 @@ class ControlConnection extends BaseConnection {
throw new errors.RequestError("Slave is not connected");
}
await link.requests.createInstance.send(connection, {
await link.messages.createInstance.send(connection, {
id: Math.random() * 2**31 | 0, // TODO: add id option
options: {
'name': name,
@@ -414,7 +414,7 @@ class SlaveConnection extends BaseConnection {
let { instance_id, output } = message.data;
for (let controlConnection of controlConnections) {
if (controlConnection.instanceOutputSubscriptions.has(instance_id)) {
link.events.instanceOutput.send(controlConnection, message.data);
link.messages.instanceOutput.send(controlConnection, message.data);
}
}
}