Fix various repository bugs

This commit is contained in:
Jon Staab
2024-05-14 14:32:21 -07:00
parent c91d02f3ea
commit 5c9b1893ba
14 changed files with 269 additions and 207 deletions
+1
View File
@@ -11,3 +11,4 @@ export * from "./target/Multi"
export * from "./target/Plex"
export * from "./target/Relay"
export * from "./target/Relays"
export * from "./target/Local"
+32
View File
@@ -0,0 +1,32 @@
import {Emitter} from '@welshman/lib'
import {Repository, LOCAL_RELAY_URL, Relay} from '@welshman/util'
import type {Message} from '../Socket'
export class Local extends Emitter {
relay: Relay
constructor(readonly repository: Repository) {
super()
this.relay = new Relay(repository)
this.relay.on('*', this.onMessage)
}
get connections() {
return []
}
send(...payload: Message) {
this.relay.send(...payload)
}
onMessage = (...message: Message) => {
const [verb, ...payload] = message
this.emit(verb, LOCAL_RELAY_URL, ...payload)
}
cleanup = () => {
this.removeAllListeners()
this.relay.off('*', this.onMessage)
}
}