server: ipc: deduplicate packet serialization when sending to multiple clients
This commit is contained in:
parent
aec5ba9d9c
commit
dd3ca188ab
2 changed files with 16 additions and 6 deletions
|
|
@ -97,9 +97,9 @@ class Client extends EventEmitter {
|
|||
|
||||
}
|
||||
|
||||
send(event, data) {
|
||||
send(packet) {
|
||||
|
||||
var packet = JSON.stringify([event, data])
|
||||
// see IpcServer.send
|
||||
|
||||
if (this.connected()) {
|
||||
this.socket.send(packet)
|
||||
|
|
|
|||
|
|
@ -66,12 +66,22 @@ class IpcServer {
|
|||
|
||||
send(event, data, id, except) {
|
||||
|
||||
var clients = id ? [this.clients[id]] : this.clients
|
||||
var packet = JSON.stringify([event, data])
|
||||
|
||||
for (var k in clients) {
|
||||
if (!except || this.clients[k] != this.clients[except]) {
|
||||
if (clients[k]) clients[k].send(event, data)
|
||||
if (id) {
|
||||
// send to a single client
|
||||
if (this.clients[id]){
|
||||
this.clients[id].send(packet)
|
||||
}
|
||||
|
||||
} else {
|
||||
// send to all clients except one if specified
|
||||
for (var id in this.clients) {
|
||||
if (id != except) {
|
||||
this.clients[id].send(packet)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue