diff --git a/packages/net/client/socket.js b/packages/net/client/socket.js index 717010d..ab1aa35 100644 --- a/packages/net/client/socket.js +++ b/packages/net/client/socket.js @@ -5,7 +5,7 @@ import {compose, EventEmitter} from '@avocado/core'; import {SocketIoParser, allPackets, idFromPacket} from '../packet'; -const debug = D('@avocado:client:socket'); +const debug = D('@avocado/net:socket'); const decorate = compose( EventEmitter, @@ -58,7 +58,9 @@ export class SocketClient extends decorate(class {}) { for (const Packet of allPackets()) { const id = idFromPacket(Packet); this.socket.on(id, (data) => { - this.emit('packet', new Packet(data)); + const packet = new Packet(data); + debug('recieved packet %o', packet); + this.emit('packet', packet); }); } } @@ -72,6 +74,7 @@ export class SocketClient extends decorate(class {}) { } send(packet) { + debug('sending packet %o', packet); const id = idFromPacket(packet.constructor); this.socket.binary(true).emit(id, packet.data); } diff --git a/packages/net/server/socket.js b/packages/net/server/socket.js index 5fca170..8ea5f1b 100644 --- a/packages/net/server/socket.js +++ b/packages/net/server/socket.js @@ -1,9 +1,12 @@ +import D from 'debug'; import SocketIoServer from 'socket.io'; import {compose, EventEmitter} from '@avocado/core'; import {SocketIoParser, allPackets, idFromPacket} from '../packet'; +const debug = D('@avocado/net:socket'); + const decorateServer = compose( EventEmitter, ); @@ -56,7 +59,9 @@ class ServerSocket extends decorateSocket(class {}) { for (const Packet of allPackets()) { const id = idFromPacket(Packet); this.socket.on(id, (data) => { - this.emit('packet', new Packet(data)); + const packet = new Packet(data); + debug('recieved packet %o', packet); + this.emit('packet', packet); }); } this.socket.on('disconnect', (...args) => { @@ -77,6 +82,7 @@ class ServerSocket extends decorateSocket(class {}) { } send(packet) { + debug('sending packet %o', packet); const id = idFromPacket(packet.constructor); this.socket.binary(true).emit(id, packet.data); }