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
+23
View File
@@ -0,0 +1,23 @@
import {EventBus} from "./util/EventBus"
export class Plex {
constructor(urls, socket) {
this.urls = urls
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([{relays: this.urls}, payload])
}
cleanup() {
this.bus.clear()
this.listeners.map(unsubscribe => unsubscribe())
}
}