feat: socket API

This commit is contained in:
cha0s 2020-05-21 08:58:18 -05:00
parent 3a1f3730c9
commit 0d96cb6ad5

View File

@ -37,6 +37,11 @@ export class SocketServer extends decorateServer(class {}) {
this.io.on('connect', this.onConnect);
}
send(packet, channel) {
const id = idFromPacket(packet.constructor);
this.io.sockets.to(channel).binary(true).emit(id, packet.data);
}
}
const decorateSocket = compose(
@ -63,9 +68,21 @@ class ServerSocket extends decorateSocket(class {}) {
this.socket.disconnect(true);
}
get id() {
return this.socket ? this.socket.id : undefined;
}
join(channel) {
this.socket.join(channel);
}
send(packet) {
const id = idFromPacket(packet.constructor);
this.socket.binary(true).emit(id, packet.data);
}
get session() {
return this.socket.handshake.session;
}
}