Comparing version 4.1.6 to 4.1.7
@@ -30,6 +30,9 @@ 'use strict'; | ||
let message = args[0]; | ||
let callback = () => {}; | ||
let callback; | ||
if (typeof args[args.length - 1] === 'function') { | ||
callback = args.pop(); | ||
} | ||
else { | ||
callback = () => {}; | ||
} | ||
@@ -45,18 +48,26 @@ if (message instanceof Array) { | ||
let buf; | ||
switch (typeof message) { | ||
case 'object': | ||
buf = toBuffer(message); | ||
this._sock.send(buf, 0, buf.length, this.port, this.host, callback); | ||
break; | ||
case 'string': | ||
mes = new Message(args[0]); | ||
for (let i = 1; i < args.length; i++) { | ||
mes.append(args[i]); | ||
} | ||
buf = toBuffer(mes); | ||
this._sock.send(buf, 0, buf.length, this.port, this.host, callback); | ||
break; | ||
default: | ||
throw new Error('That Message Just Doesn\'t Seem Right'); | ||
try { | ||
switch (typeof message) { | ||
case 'object': | ||
buf = toBuffer(message); | ||
this._sock.send(buf, 0, buf.length, this.port, this.host, callback); | ||
break; | ||
case 'string': | ||
mes = new Message(args[0]); | ||
for (let i = 1; i < args.length; i++) { | ||
mes.append(args[i]); | ||
} | ||
buf = toBuffer(mes); | ||
this._sock.send(buf, 0, buf.length, this.port, this.host, callback); | ||
break; | ||
default: | ||
throw new TypeError('That Message Just Doesn\'t Seem Right'); | ||
} | ||
} | ||
catch (e) { | ||
if (e.code !== 'ERR_SOCKET_DGRAM_NOT_RUNNING') throw e; | ||
const error = new ReferenceError('Cannot send message on closed socket.'); | ||
error.code = e.code; | ||
callback(error); | ||
} | ||
} | ||
@@ -63,0 +74,0 @@ } |
{ | ||
"name": "node-osc", | ||
"description": "pyOSC inspired library", | ||
"version": "4.1.6", | ||
"version": "4.1.7", | ||
"main": "./lib/index.js", | ||
@@ -6,0 +6,0 @@ "exports": { |
@@ -76,3 +76,4 @@ 'use strict'; | ||
t.plan(1); | ||
t.plan(2); | ||
t.throws(() => { | ||
@@ -84,2 +85,5 @@ client.send(123, (err) => { | ||
client.close(); | ||
client.send('/boom', (err) => { | ||
t.equals(err.code, 'ERR_SOCKET_DGRAM_NOT_RUNNING'); | ||
}); | ||
}); |
50218
808