Fix some bugs with message delivery

This commit is contained in:
Jonathan Staab
2023-03-28 14:23:31 -05:00
parent 9b6a779397
commit 5a1a72491e
20 changed files with 275 additions and 224 deletions
+22
View File
@@ -0,0 +1,22 @@
import {EventBus} from "./util/EventBus"
export class Relay {
constructor(socket) {
this.socket = socket
this.bus = new EventBus()
this.listeners = sockets.map(socket => {
return socket.bus.addListener('message', (url, [verb, ...payload]) => {
this.bus.emit(verb, url, ...payload)
})
})
}
async send(...payload) {
await this.socket.connect()
this.socket.send(payload)
}
cleanup() {
this.bus.clear()
this.listeners.map(unsubscribe => unsubscribe())
}
}