feat: callbacks

This commit is contained in:
cha0s 2020-06-27 01:35:11 -05:00
parent 99178af065
commit d18ed7171e
2 changed files with 8 additions and 8 deletions

View File

@ -61,10 +61,10 @@ export class SocketClient extends decorate(class {}) {
const [, M] = entries[i];
const {default: Packet} = M;
const id = idFrom(M);
this.socket.on(id, (data) => {
this.socket.on(id, (data, fn) => {
const packet = new Packet(data);
debug('recieved packet %o', packet);
this.emit('packet', packet);
this.emit('packet', packet, fn);
});
}
}
@ -77,11 +77,11 @@ export class SocketClient extends decorate(class {}) {
return this.socket ? this.socket.id : undefined;
}
send(packet) {
send(packet, fn) {
debug('sending packet %o', packet);
const {idFrom} = require('../packet/registrar');
const id = idFrom(packet.constructor);
this.socket.binary(true).emit(id, packet.data);
this.socket.binary(true).emit(id, packet.data, fn);
}
get session() {

View File

@ -68,10 +68,10 @@ class ServerSocket extends decorateSocket(class {}) {
const [, M] = entries[i];
const {default: Packet} = M;
const id = idFrom(M);
this.socket.on(id, (data) => {
this.socket.on(id, (data, fn) => {
const packet = new Packet(data);
debug('recieved packet %o', packet);
this.emit('packet', packet);
this.emit('packet', packet, fn);
});
}
this.socket.on('disconnect', (...args) => {
@ -95,11 +95,11 @@ class ServerSocket extends decorateSocket(class {}) {
this.socket.join(channel);
}
send(packet) {
send(packet, fn) {
debug('sending packet %o', packet);
const {idFrom} = require('../packet/registrar');
const id = idFrom(packet.constructor);
this.socket.binary(true).emit(id, packet.data);
this.socket.binary(true).emit(id, packet.data, fn);
}
get session() {