feat: promises
This commit is contained in:
parent
d4b8af601d
commit
a1ba60d9c6
|
@ -94,22 +94,22 @@ export default class SocketClient extends decorate(Class) {
|
|||
return this.socket ? this.socket.id : undefined;
|
||||
}
|
||||
|
||||
static send(latus, socket, packetOrDehydrated) {
|
||||
static send(latus, socket, packetOrDehydrated, method) {
|
||||
const packet = Array.isArray(packetOrDehydrated)
|
||||
? this.hydrate(latus, packetOrDehydrated)
|
||||
: packetOrDehydrated;
|
||||
debug('sending packet %o', packet);
|
||||
const {id} = packet.constructor;
|
||||
return socket.emitPromise(id, packet.data);
|
||||
return socket[method](id, packet.data);
|
||||
}
|
||||
|
||||
send(packet) {
|
||||
return this.constructor.send(this.latus, this.socket, packet);
|
||||
return this.constructor.send(this.latus, this.socket, packet, 'emitPromise');
|
||||
}
|
||||
|
||||
to(room) {
|
||||
return {
|
||||
send: (packet) => this.constructor.send(this.latus, this.socket.to(room), packet),
|
||||
send: (packet) => this.constructor.send(this.latus, this.socket.to(room), packet, 'emit'),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -72,22 +72,22 @@ export default class ServerSocket extends decorate(Class) {
|
|||
return this.socket.rooms;
|
||||
}
|
||||
|
||||
static send(latus, socket, packetOrDehydrated) {
|
||||
static send(latus, socket, packetOrDehydrated, method) {
|
||||
const packet = Array.isArray(packetOrDehydrated)
|
||||
? this.hydrate(latus, packetOrDehydrated)
|
||||
: packetOrDehydrated;
|
||||
debug('sending packet %s(%o)', packet.constructor.name, packet.data);
|
||||
const {id} = packet.constructor;
|
||||
return socket.emitPromise(id, packet.data);
|
||||
return socket[method](id, packet.data);
|
||||
}
|
||||
|
||||
send(packet) {
|
||||
return this.constructor.send(this.latus, this.socket, packet);
|
||||
return this.constructor.send(this.latus, this.socket, packet, 'emitPromise');
|
||||
}
|
||||
|
||||
to(room) {
|
||||
return {
|
||||
send: (packet) => this.constructor.send(this.latus, this.socket.to(room), packet),
|
||||
send: (packet) => this.constructor.send(this.latus, this.socket.to(room), packet, 'emit'),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user