feat: callbacks
This commit is contained in:
parent
99178af065
commit
d18ed7171e
|
@ -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() {
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user