Fix Plex data transformation, handle socket errors

This commit is contained in:
Jonathan Staab
2023-03-29 10:06:12 -05:00
parent 557ab542b7
commit da3b176b49
4 changed files with 36 additions and 23 deletions
+5 -5
View File
@@ -5,10 +5,10 @@ export class Plex {
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)
})
this.unsubscribe = socket.bus.addListeners({
message: (websocketUrl, [{relays}, [verb, ...payload]]) => {
this.bus.emit(verb, relays[0], ...payload)
},
})
}
async send(...payload) {
@@ -18,6 +18,6 @@ export class Plex {
}
cleanup() {
this.bus.clear()
this.listeners.map(unsubscribe => unsubscribe())
this.unsubscribe()
}
}