Fix various repository bugs
This commit is contained in:
@@ -11,3 +11,4 @@ export * from "./target/Multi"
|
||||
export * from "./target/Plex"
|
||||
export * from "./target/Relay"
|
||||
export * from "./target/Relays"
|
||||
export * from "./target/Local"
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user