Put everything in src directories

This commit is contained in:
Jon Staab
2024-06-12 09:34:45 -07:00
parent f2f16bc3d3
commit 39ca2fe6aa
48 changed files with 22 additions and 22 deletions
+28
View File
@@ -0,0 +1,28 @@
import {Emitter} from '@welshman/lib'
import type {Message} from '../Socket'
import type {Connection} from '../Connection'
export class Relay extends Emitter {
constructor(readonly connection: Connection) {
super()
this.connection.on('receive', this.onMessage)
}
get connections() {
return [this.connection]
}
send(...payload: Message) {
this.connection.send(payload)
}
onMessage = (connection: Connection, [verb, ...payload]: Message) => {
this.emit(verb, connection.url, ...payload)
}
cleanup = () => {
this.removeAllListeners()
this.connection.off('receive', this.onMessage)
}
}