chore: forwarding
This commit is contained in:
parent
a0528a8cb5
commit
278ad313ac
|
@ -13,11 +13,11 @@ const decorateServer = compose(
|
|||
|
||||
export class SocketServer extends decorateServer(class {}) {
|
||||
|
||||
constructor(httpServer) {
|
||||
constructor(httpServer, options) {
|
||||
super();
|
||||
this.onConnect = this.onConnect.bind(this);
|
||||
if (httpServer) {
|
||||
this.open(httpServer);
|
||||
this.open(httpServer, options);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,12 +26,17 @@ export class SocketServer extends decorateServer(class {}) {
|
|||
this.io.close(fn);
|
||||
}
|
||||
|
||||
of(nsp) {
|
||||
return this.io.of(nsp);
|
||||
}
|
||||
|
||||
onConnect(socket) {
|
||||
this.emit('connect', new ServerSocket(socket));
|
||||
}
|
||||
|
||||
open(httpServer) {
|
||||
open(httpServer, options = {}) {
|
||||
this.io = new SocketIoServer(httpServer, {
|
||||
...options,
|
||||
parser: SocketIoParser,
|
||||
path: '/avocado',
|
||||
perMessageDeflate: false,
|
||||
|
@ -40,7 +45,7 @@ export class SocketServer extends decorateServer(class {}) {
|
|||
this.io.on('connect', this.onConnect);
|
||||
}
|
||||
|
||||
send(packet, channel) {
|
||||
send(packet, channel = '/') {
|
||||
const id = idFromPacket(packet.constructor);
|
||||
this.io.sockets.to(channel).binary(true).emit(id, packet.data);
|
||||
}
|
||||
|
@ -77,6 +82,10 @@ class ServerSocket extends decorateSocket(class {}) {
|
|||
return this.socket ? this.socket.id : undefined;
|
||||
}
|
||||
|
||||
leave(channel) {
|
||||
this.socket.leave(channel);
|
||||
}
|
||||
|
||||
join(channel) {
|
||||
this.socket.join(channel);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user