chore: debugging
This commit is contained in:
parent
95f0dd8189
commit
7fea7e0ca9
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user