flop send to have name first then packet
parent
d0173c045f
commit
e6774301c2
12
src/base.mjs
12
src/base.mjs
|
@ -45,11 +45,9 @@ export default class Base extends EventEmitter {
|
|||
|
||||
} // init
|
||||
|
||||
async send (packet,name) {
|
||||
if (name) {
|
||||
if (this.socket[name]) await this.socket[name].send(packet)
|
||||
}
|
||||
else {
|
||||
async send (name,packet) {
|
||||
if (typeof name !== 'string') {
|
||||
packet = name
|
||||
let sends = []
|
||||
for(let name of Object.keys(this.socket)){
|
||||
if (this.socket[name].type ==='c') {
|
||||
|
@ -60,8 +58,10 @@ export default class Base extends EventEmitter {
|
|||
// console.log(sends.map(send => {return send(packet)}))
|
||||
if (sends.length === 1) return sends[0](packet)
|
||||
return Promise.all(sends.map(send => {return send(packet)}))
|
||||
} else {
|
||||
if (this.socket[name]) return await this.socket[name].send(packet)
|
||||
else return {error: `not consumer socket of name ${name}`}
|
||||
}
|
||||
this.emit('packet', packet) // emits on instance for instance use
|
||||
}
|
||||
|
||||
async sendTransport(packet,transport) {
|
||||
|
|
Loading…
Reference in New Issue