chore: debugging

This commit is contained in:
cha0s 2020-05-22 08:43:12 -05:00
parent 95f0dd8189
commit 7fea7e0ca9
2 changed files with 12 additions and 3 deletions

View File

@ -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);
}

View File

@ -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);
}