mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 07:43:12 +09:00
Implement broadcast for events
Add broadcastTo property to events that broadcasts them to all entities of the specified target that's downstream to the connection it was sent to.
This commit is contained in:
1 parent
21d9fdff7b
commit
e5115df28b
4 files changed
+65
-1
No files matched your search
@@ -300,6 +300,17 @@ class InstanceConnection extends link.Link {
|
||||
async forwardEventToMaster(message, event) {
|
||||
event.send(this.slave, message.data);
|
||||
}
|
||||
|
||||
async broadcastEventToInstance(message, event) {
|
||||
for (let instanceConnection of this.slave.instanceConnections.values()) {
|
||||
if (instanceConnection === this) {
|
||||
continue; // Do not broadcast back to the source
|
||||
}
|
||||
|
||||
console.log("Broadcasting event");
|
||||
event.send(instanceConnection, message.data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SlaveConnector extends link.SocketIOClientConnector {
|
||||
@@ -377,6 +388,12 @@ class Slave extends link.Link {
|
||||
return await request.send(instanceConnection, message.data);
|
||||
}
|
||||
|
||||
async broadcastEventToInstance(message, event) {
|
||||
for (let instanceConnection of this.instanceConnections.values()) {
|
||||
event.send(instanceConnection, message.data);
|
||||
}
|
||||
}
|
||||
|
||||
async createInstanceRequestHandler(message) {
|
||||
let { id, options } = message.data;
|
||||
if (this.instanceInfos.has(id)) {
|
||||
|
||||
Reference in new issue
Block a user