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 [, M] = entries[i];
|
||||||
const {default: Packet} = M;
|
const {default: Packet} = M;
|
||||||
const id = idFrom(M);
|
const id = idFrom(M);
|
||||||
this.socket.on(id, (data) => {
|
this.socket.on(id, (data, fn) => {
|
||||||
const packet = new Packet(data);
|
const packet = new Packet(data);
|
||||||
debug('recieved packet %o', packet);
|
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;
|
return this.socket ? this.socket.id : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
send(packet) {
|
send(packet, fn) {
|
||||||
debug('sending packet %o', packet);
|
debug('sending packet %o', packet);
|
||||||
const {idFrom} = require('../packet/registrar');
|
const {idFrom} = require('../packet/registrar');
|
||||||
const id = idFrom(packet.constructor);
|
const id = idFrom(packet.constructor);
|
||||||
this.socket.binary(true).emit(id, packet.data);
|
this.socket.binary(true).emit(id, packet.data, fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
get session() {
|
get session() {
|
||||||
|
|
|
@ -68,10 +68,10 @@ class ServerSocket extends decorateSocket(class {}) {
|
||||||
const [, M] = entries[i];
|
const [, M] = entries[i];
|
||||||
const {default: Packet} = M;
|
const {default: Packet} = M;
|
||||||
const id = idFrom(M);
|
const id = idFrom(M);
|
||||||
this.socket.on(id, (data) => {
|
this.socket.on(id, (data, fn) => {
|
||||||
const packet = new Packet(data);
|
const packet = new Packet(data);
|
||||||
debug('recieved packet %o', packet);
|
debug('recieved packet %o', packet);
|
||||||
this.emit('packet', packet);
|
this.emit('packet', packet, fn);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
this.socket.on('disconnect', (...args) => {
|
this.socket.on('disconnect', (...args) => {
|
||||||
|
@ -95,11 +95,11 @@ class ServerSocket extends decorateSocket(class {}) {
|
||||||
this.socket.join(channel);
|
this.socket.join(channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
send(packet) {
|
send(packet, fn) {
|
||||||
debug('sending packet %o', packet);
|
debug('sending packet %o', packet);
|
||||||
const {idFrom} = require('../packet/registrar');
|
const {idFrom} = require('../packet/registrar');
|
||||||
const id = idFrom(packet.constructor);
|
const id = idFrom(packet.constructor);
|
||||||
this.socket.binary(true).emit(id, packet.data);
|
this.socket.binary(true).emit(id, packet.data, fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
get session() {
|
get session() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user