feat: cheap channel API

This commit is contained in:
cha0s 2020-05-21 08:57:01 -05:00
parent 8c876f7efb
commit 7e4e3e12ee

View File

@ -67,11 +67,28 @@ export class SocketClient extends decorate(class {}) {
this.socket.disconnect();
}
get id() {
return this.socket ? this.socket.id : undefined;
}
send(packet) {
const id = idFromPacket(packet.constructor);
this.socket.binary(true).emit(id, packet.data);
}
get session() {
return this.socket.handshake.session;
}
to(channel) {
return {
send: (packet) => {
const id = idFromPacket(packet.constructor);
this.socket.binary(true).to(channel).emit(id, packet.data);
},
};
}
tryReconnect() {
if (this.isReconnecting) {
return;