From 0d96cb6ad5c79abd42ba4a6487209138e38867c1 Mon Sep 17 00:00:00 2001 From: cha0s Date: Thu, 21 May 2020 08:58:18 -0500 Subject: [PATCH] feat: socket API --- packages/net/server/socket.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/net/server/socket.js b/packages/net/server/socket.js index c571eb5..5fca170 100644 --- a/packages/net/server/socket.js +++ b/packages/net/server/socket.js @@ -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; + } + }