flop send to have name first then packet

master
David Kebler 2018-02-13 22:31:02 -08:00
parent d0173c045f
commit e6774301c2
1 changed files with 6 additions and 6 deletions

View File

@ -45,11 +45,9 @@ export default class Base extends EventEmitter {
} // init } // init
async send (packet,name) { async send (name,packet) {
if (name) { if (typeof name !== 'string') {
if (this.socket[name]) await this.socket[name].send(packet) packet = name
}
else {
let sends = [] let sends = []
for(let name of Object.keys(this.socket)){ for(let name of Object.keys(this.socket)){
if (this.socket[name].type ==='c') { if (this.socket[name].type ==='c') {
@ -60,8 +58,10 @@ export default class Base extends EventEmitter {
// console.log(sends.map(send => {return send(packet)})) // console.log(sends.map(send => {return send(packet)}))
if (sends.length === 1) return sends[0](packet) if (sends.length === 1) return sends[0](packet)
return Promise.all(sends.map(send => {return send(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) { async sendTransport(packet,transport) {