osc
Advanced tools
Comparing version 1.1.2 to 1.1.3
{ | ||
"name": "osc.js", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"main": "dist/osc.min.js", | ||
@@ -18,4 +18,4 @@ "ignore": [ | ||
"devDependencies": { | ||
"qunit": "1.14.0" | ||
"requirejs": ">=2.1.14" | ||
} | ||
} |
/*! osc.js 1.1.2, Copyright 2015 Colin Clark | github.com/colinbdclark/osc.js */ | ||
var osc=osc||{};!function(){"use strict";var a;osc.SECS_70YRS=2208988800,osc.TWO_32=4294967296,osc.defaults={metadata:!1,unpackSingleArgs:!0},osc.isBufferEnv="undefined"!=typeof Buffer,osc.isArray=function(a){return a&&"[object Array]"===Object.prototype.toString.call(a)},osc.isTypedArrayView=function(a){return a.buffer&&a.buffer instanceof ArrayBuffer},osc.isBuffer=function(a){return osc.isBufferEnv&&a instanceof Buffer},osc.dataView=function(b){return b instanceof DataView?b:"undefined"!=typeof a&&b instanceof a?b:osc.isBufferEnv&&b instanceof Buffer?new a(b):b.buffer?new DataView(b.buffer):b instanceof ArrayBuffer?new DataView(b):new DataView(new Uint8Array(b))},osc.byteArray=function(a){if(a instanceof Uint8Array)return a;var b=a.buffer?a.buffer:a;if("undefined"==typeof a.length||"string"==typeof a)throw new Error("Can't wrap a non-array-like object as Uint8Array. Object was: "+JSON.stringify(a,null,2));return new Uint8Array(b)},osc.makeByteArray=function(a){return osc.isBufferEnv?new Buffer(a):new Uint8Array(a)},osc.copyByteArray=function(a,b,c){if(osc.isTypedArrayView(a)&&osc.isTypedArrayView(b))b.set(a,c);else if(osc.isBuffer(a)&&osc.isBuffer(b))a.copy(b,c);else for(var d=void 0===c?0:c,e=Math.min(b.length-c,a.length),f=0,g=d;e>f;f++,g++)b[g]=a[f];return b},osc.readString=function(a,b){for(var c=[],d=b.idx;d<a.byteLength;d++){var e=a.getUint8(d);if(0===e){d++;break}c.push(e)}return d=d+3&-4,b.idx=d,String.fromCharCode.apply(null,c)},osc.writeString=function(a){for(var b=a+"\x00",c=b.length,d=c+3&-4,e=new Uint8Array(d),f=0;f<b.length;f++){var g=b.charCodeAt(f);e[f]=g}return e},osc.readPrimitive=function(a,b,c,d){var e=a[b](d.idx,!1);return d.idx+=c,e},osc.writePrimitive=function(a,b,c,d,e){e=void 0===e?0:e;var f;return b?f=new Uint8Array(b.buffer):(f=new Uint8Array(d),b=new DataView(f.buffer)),b[c](e,a,!1),f},osc.readInt32=function(a,b){return osc.readPrimitive(a,"getInt32",4,b)},osc.writeInt32=function(a,b,c){return osc.writePrimitive(a,b,"setInt32",4,c)},osc.readFloat32=function(a,b){return osc.readPrimitive(a,"getFloat32",4,b)},osc.writeFloat32=function(a,b,c){return osc.writePrimitive(a,b,"setFloat32",4,c)},osc.readFloat64=function(a,b){return osc.readPrimitive(a,"getFloat64",8,b)},osc.writeFloat64=function(a,b,c){return osc.writePrimitive(a,b,"setFloat64",8,c)},osc.readChar32=function(a,b){var c=osc.readPrimitive(a,"getUint32",4,b);return String.fromCharCode(c)},osc.writeChar32=function(a,b,c){var d=a.charCodeAt(0);return void 0===d||-1>d?void 0:osc.writePrimitive(d,b,"setUint32",4,c)},osc.readBlob=function(a,b){var c=osc.readInt32(a,b),d=c+3&-4,e=new Uint8Array(a.buffer,b.idx,c);return b.idx+=d,e},osc.writeBlob=function(a){a=osc.byteArray(a);var b=a.byteLength,c=b+3&-4,d=4,e=c+d,f=new Uint8Array(e),g=new DataView(f.buffer);return osc.writeInt32(b,g),f.set(a,d),f},osc.readMIDIBytes=function(a,b){var c=new Uint8Array(a.buffer,b.idx,4);return b.idx+=4,c},osc.writeMIDIBytes=function(a){a=osc.byteArray(a);var b=new Uint8Array(4);return b.set(a),b},osc.readColor=function(a,b){var c=new Uint8Array(a.buffer,b.idx,4),d=c[3]/255;return b.idx+=4,{r:c[0],g:c[1],b:c[2],a:d}},osc.writeColor=function(a){var b=Math.round(255*a.a),c=new Uint8Array([a.r,a.g,a.b,b]);return c},osc.readTrue=function(){return!0},osc.readFalse=function(){return!1},osc.readNull=function(){return null},osc.readImpulse=function(){return 1},osc.readTimeTag=function(a,b){var c=osc.readPrimitive(a,"getUint32",4,b),d=osc.readPrimitive(a,"getUint32",4,b),e=0===c&&1===d?Date.now():osc.ntpToJSTime(c,d);return{raw:[c,d],"native":e}},osc.writeTimeTag=function(a){var b=a.raw?a.raw:osc.jsToNTPTime(a["native"]),c=new Uint8Array(8),d=new DataView(c.buffer);return osc.writeInt32(b[0],d,0),osc.writeInt32(b[1],d,4),c},osc.timeTag=function(a){a=a||0;var b=Date.now()/1e3,c=Math.floor(b),d=b-c,e=Math.floor(a),f=a-e,g=d+f;if(g>1){var h=Math.floor(g),i=g-h;e+=h,g=i}var j=c+e+osc.SECS_70YRS,k=Math.round(osc.TWO_32*g);return{raw:[j,k]}},osc.ntpToJSTime=function(a,b){var c=a-osc.SECS_70YRS,d=b/osc.TWO_32,e=1e3*(c+d);return e},osc.jsToNTPTime=function(a){var b=a/1e3,c=Math.floor(b),d=b-c,e=c+osc.SECS_70YRS,f=Math.round(osc.TWO_32*d);return[e,f]},osc.readArguments=function(a,b,c){var d=osc.readString(a,c);if(0!==d.indexOf(","))throw new Error("A malformed type tag string was found while reading the arguments of an OSC message. String was: "+d," at offset: "+c.idx);var e=d.substring(1).split(""),f=[];return osc.readArgumentsIntoArray(f,e,d,a,b,c),f},osc.readArgument=function(a,b,c,d,e){var f=osc.argumentTypes[a];if(!f)throw new Error("'"+a+"' is not a valid OSC type tag. Type tag string was: "+b);var g=f.reader,h=osc[g](c,e);return d.metadata&&(h={type:a,value:h}),h},osc.readArgumentsIntoArray=function(a,b,c,d,e,f){for(var g=0;g<b.length;){var h,i=b[g];if("["===i){var j=b.slice(g+1),k=j.indexOf("]");if(0>k)throw new Error("Invalid argument type tag: an open array type tag ('[') was found without a matching close array tag ('[]'). Type tag was: "+c);var l=j.slice(0,k);h=osc.readArgumentsIntoArray([],l,c,d,e,f),g+=k+2}else h=osc.readArgument(i,c,d,e,f),g++;a.push(h)}return a},osc.writeArguments=function(a,b){var c=osc.collectArguments(a,b);return osc.joinParts(c)},osc.joinParts=function(a){for(var b=osc.makeByteArray(a.byteLength),c=a.parts,d=0,e=0;e<c.length;e++){var f=c[e];osc.copyByteArray(f,b,d),d+=f.length}return b},osc.addDataPart=function(a,b){b.parts.push(a),b.byteLength+=a.length},osc.collectArguments=function(a,b,c){osc.isArray(a)||(a=[a]),c=c||{byteLength:0,parts:[]},b.metadata||(a=osc.annotateArguments(a));for(var d=",",e=c.parts.length,f=0;f<a.length;f++){var g=a[f],h=g.type,i=osc.argumentTypes[h].writer;if(d+=g.type,i){var j=osc[i](g.value);osc.addDataPart(j,c)}}var k=osc.writeString(d);return c.byteLength+=k.byteLength,c.parts.splice(e,0,k),c},osc.readMessage=function(a,b,c){b=b||osc.defaults;var d=osc.dataView(a);c=c||{idx:0};var e=osc.readString(d,c);return osc.readMessageContents(e,d,b,c)},osc.readMessageContents=function(a,b,c,d){if(0!==a.indexOf("/"))throw new Error("A malformed OSC address was found while reading an OSC message. String was: "+a);var e=osc.readArguments(b,c,d);return{address:a,args:1===e.length&&c.unpackSingleArgs?e[0]:e}},osc.collectMessageParts=function(a,b,c){return c=c||{byteLength:0,parts:[]},osc.addDataPart(osc.writeString(a.address),c),osc.collectArguments(a.args,b,c)},osc.writeMessage=function(a,b){b=b||osc.defaults;var c=osc.collectMessageParts(a,b);return osc.joinParts(c)},osc.readBundle=function(a,b,c){return osc.readPacket(a,b,c)},osc.collectBundlePackets=function(a,b,c){c=c||{byteLength:0,parts:[]},osc.addDataPart(osc.writeString("#bundle"),c),osc.addDataPart(osc.writeTimeTag(a.timeTag),c);for(var d=0;d<a.packets.length;d++){var e=a.packets[d],f=e.address?osc.collectMessageParts:osc.collectBundlePackets,g=f(e,b);c.byteLength+=g.byteLength,osc.addDataPart(osc.writeInt32(g.byteLength),c),c.parts=c.parts.concat(g.parts)}return c},osc.writeBundle=function(a,b){if(a.timeTag&&a.packets){b=b||osc.defaults;var c=osc.collectBundlePackets(a,b);return osc.joinParts(c)}},osc.readBundleContents=function(a,b,c,d){for(var e=osc.readTimeTag(a,c),f=[];c.idx<d;){var g=osc.readInt32(a,c),h=c.idx+g,i=osc.readPacket(a,b,c,h);f.push(i)}return{timeTag:e,packets:f}},osc.readPacket=function(a,b,c,d){var e=osc.dataView(a);d=void 0===d?e.byteLength:d,c=c||{idx:0};var f=osc.readString(e,c),g=f[0];if("#"===g)return osc.readBundleContents(e,b,c,d);if("/"===g)return osc.readMessageContents(f,e,b,c);throw new Error("The header of an OSC packet didn't contain an OSC address or a #bundle string. Header was: "+f)},osc.writePacket=function(a,b){var c=a.address?osc.writeMessage:osc.writeBundle;return c(a,b)},osc.argumentTypes={i:{reader:"readInt32",writer:"writeInt32"},f:{reader:"readFloat32",writer:"writeFloat32"},s:{reader:"readString",writer:"writeString"},S:{reader:"readString",writer:"writeString"},b:{reader:"readBlob",writer:"writeBlob"},t:{reader:"readTimeTag",writer:"writeTimeTag"},T:{reader:"readTrue"},F:{reader:"readFalse"},N:{reader:"readNull"},I:{reader:"readImpulse"},d:{reader:"readFloat64",writer:"writeFloat64"},c:{reader:"readChar32",writer:"writeChar32"},r:{reader:"readColor",writer:"writeColor"},m:{reader:"readMIDIBytes",writer:"writeMIDIBytes"}},osc.inferTypeForArgument=function(a){var b=typeof a;switch(b){case"boolean":return a?"T":"F";case"string":return"s";case"number":return"f";case"undefined":return"N";case"object":if(null===a)return"N";if(a instanceof Uint8Array||a instanceof ArrayBuffer||osc.isBufferEnv&&a instanceof Buffer)return"b"}throw new Error("Can't infer OSC argument type for value: "+JSON.stringify(a,null,2))},osc.annotateArguments=function(a){osc.isArray(a)||(a=[a]);for(var b=[],c=0;c<a.length;c++){var d,e=a[c];if("object"==typeof e&&e.type&&void 0!==e.value)d=e;else{var f=osc.inferTypeForArgument(e);d={type:f,value:e}}b.push(d)}return b},"undefined"!=typeof module&&module.exports&&(osc.isBufferEnv&&(a=require("buffer-dataview")),module.exports=osc)}();var slip=slip||{};!function(){"use strict";"undefined"!=typeof module&&module.exports&&(module.exports=slip),slip.END=192,slip.ESC=219,slip.ESC_END=220,slip.ESC_ESC=221,slip.byteArray=function(a,b,c){return a instanceof ArrayBuffer?new Uint8Array(a,b,c):a},slip.expandByteArray=function(a){var b=new Uint8Array(2*a.length);return b.set(a),b},slip.sliceByteArray=function(a,b,c){var d=a.buffer.slice?a.buffer.slice(b,c):a.subarray(b,c);return new Uint8Array(d)},slip.encode=function(a,b){b=b||{},b.bufferPadding=b.bufferPadding||4,a=slip.byteArray(a,b.offset,b.byteLength);var c=a.length+b.bufferPadding+3&-4,d=new Uint8Array(c),e=1;d[0]=slip.END;for(var f=0;f<a.length;f++){e>d.length-3&&(d=slip.expandByteArray(d));var g=a[f];g===slip.END?(d[e++]=slip.ESC,g=slip.ESC_END):g===slip.ESC&&(d[e++]=slip.ESC,g=slip.ESC_ESC),d[e++]=g}return d[e]=slip.END,slip.sliceByteArray(d,0,e+1)},slip.Decoder=function(a){a="function"!=typeof a?a||{}:{onMessage:a},this.maxMessageSize=a.maxMessageSize||10485760,this.bufferSize=a.bufferSize||1024,this.msgBuffer=new Uint8Array(this.bufferSize),this.msgBufferIdx=0,this.onMessage=a.onMessage,this.onError=a.onError,this.escape=!1};var a=slip.Decoder.prototype;a.decode=function(a){a=slip.byteArray(a);for(var b,c=0;c<a.length;c++){var d=a[c];if(this.escape)d===slip.ESC_ESC?d=slip.ESC:d===slip.ESC_END&&(d=slip.END);else{if(d===slip.ESC){this.escape=!0;continue}if(d===slip.END){b=this.handleEnd();continue}}var e=this.addByte(d);e||this.handleMessageMaxError()}return b},a.handleMessageMaxError=function(){this.onError&&this.onError(this.msgBuffer.subarray(0),"The message is too large; the maximum message size is "+this.maxMessageSize/1024+"KB. Use a larger maxMessageSize if necessary."),this.msgBufferIdx=0,this.escape=!1},a.addByte=function(a){return this.msgBufferIdx>this.msgBuffer.length-1&&(this.msgBuffer=slip.expandByteArray(this.msgBuffer)),this.msgBuffer[this.msgBufferIdx++]=a,this.escape=!1,this.msgBuffer.length<this.maxMessageSize},a.handleEnd=function(){if(0!==this.msgBufferIdx){var a=slip.sliceByteArray(this.msgBuffer,0,this.msgBufferIdx);return this.onMessage&&this.onMessage(a),this.msgBufferIdx=0,a}}}(),function(){"use strict";function a(){}function b(a,b){for(var c=a.length;c--;)if(a[c].listener===b)return c;return-1}function c(a){return function(){return this[a].apply(this,arguments)}}var d=a.prototype,e=this,f=e.EventEmitter;d.getListeners=function(a){var b,c,d=this._getEvents();if(a instanceof RegExp){b={};for(c in d)d.hasOwnProperty(c)&&a.test(c)&&(b[c]=d[c])}else b=d[a]||(d[a]=[]);return b},d.flattenListeners=function(a){var b,c=[];for(b=0;b<a.length;b+=1)c.push(a[b].listener);return c},d.getListenersAsObject=function(a){var b,c=this.getListeners(a);return c instanceof Array&&(b={},b[a]=c),b||c},d.addListener=function(a,c){var d,e=this.getListenersAsObject(a),f="object"==typeof c;for(d in e)e.hasOwnProperty(d)&&-1===b(e[d],c)&&e[d].push(f?c:{listener:c,once:!1});return this},d.on=c("addListener"),d.addOnceListener=function(a,b){return this.addListener(a,{listener:b,once:!0})},d.once=c("addOnceListener"),d.defineEvent=function(a){return this.getListeners(a),this},d.defineEvents=function(a){for(var b=0;b<a.length;b+=1)this.defineEvent(a[b]);return this},d.removeListener=function(a,c){var d,e,f=this.getListenersAsObject(a);for(e in f)f.hasOwnProperty(e)&&(d=b(f[e],c),-1!==d&&f[e].splice(d,1));return this},d.off=c("removeListener"),d.addListeners=function(a,b){return this.manipulateListeners(!1,a,b)},d.removeListeners=function(a,b){return this.manipulateListeners(!0,a,b)},d.manipulateListeners=function(a,b,c){var d,e,f=a?this.removeListener:this.addListener,g=a?this.removeListeners:this.addListeners;if("object"!=typeof b||b instanceof RegExp)for(d=c.length;d--;)f.call(this,b,c[d]);else for(d in b)b.hasOwnProperty(d)&&(e=b[d])&&("function"==typeof e?f.call(this,d,e):g.call(this,d,e));return this},d.removeEvent=function(a){var b,c=typeof a,d=this._getEvents();if("string"===c)delete d[a];else if(a instanceof RegExp)for(b in d)d.hasOwnProperty(b)&&a.test(b)&&delete d[b];else delete this._events;return this},d.removeAllListeners=c("removeEvent"),d.emitEvent=function(a,b){var c,d,e,f,g=this.getListenersAsObject(a);for(e in g)if(g.hasOwnProperty(e))for(d=g[e].length;d--;)c=g[e][d],c.once===!0&&this.removeListener(a,c.listener),f=c.listener.apply(this,b||[]),f===this._getOnceReturnValue()&&this.removeListener(a,c.listener);return this},d.trigger=c("emitEvent"),d.emit=function(a){var b=Array.prototype.slice.call(arguments,1);return this.emitEvent(a,b)},d.setOnceReturnValue=function(a){return this._onceReturnValue=a,this},d._getOnceReturnValue=function(){return this.hasOwnProperty("_onceReturnValue")?this._onceReturnValue:!0},d._getEvents=function(){return this._events||(this._events={})},a.noConflict=function(){return e.EventEmitter=f,a},"function"==typeof define&&define.amd?define(function(){return a}):"object"==typeof module&&module.exports?module.exports=a:e.EventEmitter=a}.call(this);var osc=osc||require("./osc.js"),slip=slip||require("slip"),EventEmitter=EventEmitter||require("events").EventEmitter;!function(){"use strict";osc.firePacketEvents=function(a,b,c){b.address?a.emit("message",b,c):osc.fireBundleEvents(a,b,c)},osc.fireBundleEvents=function(a,b,c){a.emit("bundle",b,c);for(var d=0;d<b.packets.length;d++){var e=b.packets[d];osc.firePacketEvents(a,e,b.timeTag)}},osc.Port=function(a){this.options=a||{},this.on("data",this.decodeOSC.bind(this))};var a=osc.Port.prototype=Object.create(EventEmitter.prototype);a.constructor=osc.Port,a.send=function(a){var b=Array.prototype.slice.call(arguments),c=this.encodeOSC(a);b[0]=c,this.sendRaw.apply(this,b)},a.encodeOSC=function(a){a=a.buffer?a.buffer:a;var b=osc.writePacket(a,this.options);return b},a.decodeOSC=function(a){this.emit("raw",a);var b=osc.readPacket(a,this.options);this.emit("osc",b),osc.firePacketEvents(this,b)},osc.SLIPPort=function(a){var b=this,c=this.options=a||{};c.useSLIP=void 0===c.useSLIP?!0:c.useSLIP,this.decoder=new slip.Decoder({onMessage:this.decodeOSC.bind(this),onError:function(a){b.emit("error",a)}});var d=c.useSLIP?this.decodeSLIPData:this.decodeOSC;this.on("data",d.bind(this))},a=osc.SLIPPort.prototype=Object.create(osc.Port.prototype),a.constructor=osc.SLIPPort,a.encodeOSC=function(a){a=a.buffer?a.buffer:a;var b=osc.writePacket(a,this.options);return slip.encode(b)},a.decodeSLIPData=function(a){this.decoder.decode(a)},osc.relay=function(a,b,c,d,e,f){c=c||"message",d=d||"send",e=e||function(){},f=f?[null].concat(f):[];var g=function(a){f[0]=a,a=e(a),b[d].apply(b,f)};return a.on(c,g),{eventName:c,listener:g}},osc.relayPorts=function(a,b,c){var d=c.raw?"raw":"osc",e=c.raw?"sendRaw":"send";return osc.relay(a,b,d,e,c.transform)},osc.stopRelaying=function(a,b){a.removeListener(b.eventName,b.listener)},osc.Relay=function(a,b,c){var d=this.options=c||{};d.raw=!1,this.port1=a,this.port2=b,this.listen()},a=osc.Relay.prototype,a.open=function(){this.port1.open(),this.port2.open()},a.listen=function(){this.port1Spec&&this.port2Spec&&this.close(),this.port1Spec=osc.relayPorts(this.port1,this.port2,this.options),this.port2Spec=osc.relayPorts(this.port2,this.port1,this.options)},a.close=function(){osc.stopRelaying(this.port1,this.port1Spec),osc.stopRelaying(this.port2,this.port2Spec)},"undefined"!=typeof module&&module.exports&&(module.exports=osc)}();var osc=osc;!function(){"use strict";osc.WebSocketPort=function(a){osc.Port.call(this,a),this.on("open",this.listen.bind(this))};var a=osc.WebSocketPort.prototype=Object.create(osc.Port.prototype);a.constructor=osc.WebSocketPort,a.open=function(){this.socket=new WebSocket(this.options.url),this.socket.binaryType="arraybuffer";var a=this;this.socket.onopen=function(){a.emit("open",a.socket)}},a.listen=function(){var a=this;this.socket.onmessage=function(b){a.emit("data",b.data)},this.socket.onerror=function(b){a.emit("error",b)},this.socket.onclose=function(b){a.emit("close",b)},a.emit("ready")},a.sendRaw=function(a){this.socket&&this.socket.send(a.buffer)},a.close=function(a,b){this.socket.close(a,b)}}(); | ||
var osc=osc||{};!function(){"use strict";var a;osc.SECS_70YRS=2208988800,osc.TWO_32=4294967296,osc.defaults={metadata:!1,unpackSingleArgs:!0},osc.isBufferEnv="undefined"!=typeof Buffer,osc.isArray=function(a){return a&&"[object Array]"===Object.prototype.toString.call(a)},osc.isTypedArrayView=function(a){return a.buffer&&a.buffer instanceof ArrayBuffer},osc.isBuffer=function(a){return osc.isBufferEnv&&a instanceof Buffer},osc.dataView=function(b){return b instanceof DataView?b:"undefined"!=typeof a&&b instanceof a?b:osc.isBufferEnv&&b instanceof Buffer?new a(b):b.buffer?new DataView(b.buffer):b instanceof ArrayBuffer?new DataView(b):new DataView(new Uint8Array(b))},osc.byteArray=function(a){if(a instanceof Uint8Array)return a;var b=a.buffer?a.buffer:a;if("undefined"==typeof a.length||"string"==typeof a)throw new Error("Can't wrap a non-array-like object as Uint8Array. Object was: "+JSON.stringify(a,null,2));return new Uint8Array(b)},osc.makeByteArray=function(a){return osc.isBufferEnv?new Buffer(a):new Uint8Array(a)},osc.copyByteArray=function(a,b,c){if(osc.isTypedArrayView(a)&&osc.isTypedArrayView(b))b.set(a,c);else if(osc.isBuffer(a)&&osc.isBuffer(b))a.copy(b,c);else for(var d=void 0===c?0:c,e=Math.min(b.length-c,a.length),f=0,g=d;e>f;f++,g++)b[g]=a[f];return b},osc.readString=function(a,b){for(var c=[],d=b.idx;d<a.byteLength;d++){var e=a.getUint8(d);if(0===e){d++;break}c.push(e)}return d=d+3&-4,b.idx=d,String.fromCharCode.apply(null,c)},osc.writeString=function(a){for(var b=a+"\x00",c=b.length,d=c+3&-4,e=new Uint8Array(d),f=0;f<b.length;f++){var g=b.charCodeAt(f);e[f]=g}return e},osc.readPrimitive=function(a,b,c,d){var e=a[b](d.idx,!1);return d.idx+=c,e},osc.writePrimitive=function(a,b,c,d,e){e=void 0===e?0:e;var f;return b?f=new Uint8Array(b.buffer):(f=new Uint8Array(d),b=new DataView(f.buffer)),b[c](e,a,!1),f},osc.readInt32=function(a,b){return osc.readPrimitive(a,"getInt32",4,b)},osc.writeInt32=function(a,b,c){return osc.writePrimitive(a,b,"setInt32",4,c)},osc.readFloat32=function(a,b){return osc.readPrimitive(a,"getFloat32",4,b)},osc.writeFloat32=function(a,b,c){return osc.writePrimitive(a,b,"setFloat32",4,c)},osc.readFloat64=function(a,b){return osc.readPrimitive(a,"getFloat64",8,b)},osc.writeFloat64=function(a,b,c){return osc.writePrimitive(a,b,"setFloat64",8,c)},osc.readChar32=function(a,b){var c=osc.readPrimitive(a,"getUint32",4,b);return String.fromCharCode(c)},osc.writeChar32=function(a,b,c){var d=a.charCodeAt(0);return void 0===d||-1>d?void 0:osc.writePrimitive(d,b,"setUint32",4,c)},osc.readBlob=function(a,b){var c=osc.readInt32(a,b),d=c+3&-4,e=new Uint8Array(a.buffer,b.idx,c);return b.idx+=d,e},osc.writeBlob=function(a){a=osc.byteArray(a);var b=a.byteLength,c=b+3&-4,d=4,e=c+d,f=new Uint8Array(e),g=new DataView(f.buffer);return osc.writeInt32(b,g),f.set(a,d),f},osc.readMIDIBytes=function(a,b){var c=new Uint8Array(a.buffer,b.idx,4);return b.idx+=4,c},osc.writeMIDIBytes=function(a){a=osc.byteArray(a);var b=new Uint8Array(4);return b.set(a),b},osc.readColor=function(a,b){var c=new Uint8Array(a.buffer,b.idx,4),d=c[3]/255;return b.idx+=4,{r:c[0],g:c[1],b:c[2],a:d}},osc.writeColor=function(a){var b=Math.round(255*a.a),c=new Uint8Array([a.r,a.g,a.b,b]);return c},osc.readTrue=function(){return!0},osc.readFalse=function(){return!1},osc.readNull=function(){return null},osc.readImpulse=function(){return 1},osc.readTimeTag=function(a,b){var c=osc.readPrimitive(a,"getUint32",4,b),d=osc.readPrimitive(a,"getUint32",4,b),e=0===c&&1===d?Date.now():osc.ntpToJSTime(c,d);return{raw:[c,d],"native":e}},osc.writeTimeTag=function(a){var b=a.raw?a.raw:osc.jsToNTPTime(a["native"]),c=new Uint8Array(8),d=new DataView(c.buffer);return osc.writeInt32(b[0],d,0),osc.writeInt32(b[1],d,4),c},osc.timeTag=function(a){a=a||0;var b=Date.now()/1e3,c=Math.floor(b),d=b-c,e=Math.floor(a),f=a-e,g=d+f;if(g>1){var h=Math.floor(g),i=g-h;e+=h,g=i}var j=c+e+osc.SECS_70YRS,k=Math.round(osc.TWO_32*g);return{raw:[j,k]}},osc.ntpToJSTime=function(a,b){var c=a-osc.SECS_70YRS,d=b/osc.TWO_32,e=1e3*(c+d);return e},osc.jsToNTPTime=function(a){var b=a/1e3,c=Math.floor(b),d=b-c,e=c+osc.SECS_70YRS,f=Math.round(osc.TWO_32*d);return[e,f]},osc.readArguments=function(a,b,c){var d=osc.readString(a,c);if(0!==d.indexOf(","))throw new Error("A malformed type tag string was found while reading the arguments of an OSC message. String was: "+d," at offset: "+c.idx);var e=d.substring(1).split(""),f=[];return osc.readArgumentsIntoArray(f,e,d,a,b,c),f},osc.readArgument=function(a,b,c,d,e){var f=osc.argumentTypes[a];if(!f)throw new Error("'"+a+"' is not a valid OSC type tag. Type tag string was: "+b);var g=f.reader,h=osc[g](c,e);return d.metadata&&(h={type:a,value:h}),h},osc.readArgumentsIntoArray=function(a,b,c,d,e,f){for(var g=0;g<b.length;){var h,i=b[g];if("["===i){var j=b.slice(g+1),k=j.indexOf("]");if(0>k)throw new Error("Invalid argument type tag: an open array type tag ('[') was found without a matching close array tag ('[]'). Type tag was: "+c);var l=j.slice(0,k);h=osc.readArgumentsIntoArray([],l,c,d,e,f),g+=k+2}else h=osc.readArgument(i,c,d,e,f),g++;a.push(h)}return a},osc.writeArguments=function(a,b){var c=osc.collectArguments(a,b);return osc.joinParts(c)},osc.joinParts=function(a){for(var b=osc.makeByteArray(a.byteLength),c=a.parts,d=0,e=0;e<c.length;e++){var f=c[e];osc.copyByteArray(f,b,d),d+=f.length}return b},osc.addDataPart=function(a,b){b.parts.push(a),b.byteLength+=a.length},osc.collectArguments=function(a,b,c){osc.isArray(a)||(a=[a]),c=c||{byteLength:0,parts:[]},b.metadata||(a=osc.annotateArguments(a));for(var d=",",e=c.parts.length,f=0;f<a.length;f++){var g=a[f],h=g.type,i=osc.argumentTypes[h].writer;if(d+=g.type,i){var j=osc[i](g.value);osc.addDataPart(j,c)}}var k=osc.writeString(d);return c.byteLength+=k.byteLength,c.parts.splice(e,0,k),c},osc.readMessage=function(a,b,c){b=b||osc.defaults;var d=osc.dataView(a);c=c||{idx:0};var e=osc.readString(d,c);return osc.readMessageContents(e,d,b,c)},osc.readMessageContents=function(a,b,c,d){if(0!==a.indexOf("/"))throw new Error("A malformed OSC address was found while reading an OSC message. String was: "+a);var e=osc.readArguments(b,c,d);return{address:a,args:1===e.length&&c.unpackSingleArgs?e[0]:e}},osc.collectMessageParts=function(a,b,c){return c=c||{byteLength:0,parts:[]},osc.addDataPart(osc.writeString(a.address),c),osc.collectArguments(a.args,b,c)},osc.writeMessage=function(a,b){b=b||osc.defaults;var c=osc.collectMessageParts(a,b);return osc.joinParts(c)},osc.readBundle=function(a,b,c){return osc.readPacket(a,b,c)},osc.collectBundlePackets=function(a,b,c){c=c||{byteLength:0,parts:[]},osc.addDataPart(osc.writeString("#bundle"),c),osc.addDataPart(osc.writeTimeTag(a.timeTag),c);for(var d=0;d<a.packets.length;d++){var e=a.packets[d],f=e.address?osc.collectMessageParts:osc.collectBundlePackets,g=f(e,b);c.byteLength+=g.byteLength,osc.addDataPart(osc.writeInt32(g.byteLength),c),c.parts=c.parts.concat(g.parts)}return c},osc.writeBundle=function(a,b){if(a.timeTag&&a.packets){b=b||osc.defaults;var c=osc.collectBundlePackets(a,b);return osc.joinParts(c)}},osc.readBundleContents=function(a,b,c,d){for(var e=osc.readTimeTag(a,c),f=[];c.idx<d;){var g=osc.readInt32(a,c),h=c.idx+g,i=osc.readPacket(a,b,c,h);f.push(i)}return{timeTag:e,packets:f}},osc.readPacket=function(a,b,c,d){var e=osc.dataView(a);d=void 0===d?e.byteLength:d,c=c||{idx:0};var f=osc.readString(e,c),g=f[0];if("#"===g)return osc.readBundleContents(e,b,c,d);if("/"===g)return osc.readMessageContents(f,e,b,c);throw new Error("The header of an OSC packet didn't contain an OSC address or a #bundle string. Header was: "+f)},osc.writePacket=function(a,b){var c=a.address?osc.writeMessage:osc.writeBundle;return c(a,b)},osc.argumentTypes={i:{reader:"readInt32",writer:"writeInt32"},f:{reader:"readFloat32",writer:"writeFloat32"},s:{reader:"readString",writer:"writeString"},S:{reader:"readString",writer:"writeString"},b:{reader:"readBlob",writer:"writeBlob"},t:{reader:"readTimeTag",writer:"writeTimeTag"},T:{reader:"readTrue"},F:{reader:"readFalse"},N:{reader:"readNull"},I:{reader:"readImpulse"},d:{reader:"readFloat64",writer:"writeFloat64"},c:{reader:"readChar32",writer:"writeChar32"},r:{reader:"readColor",writer:"writeColor"},m:{reader:"readMIDIBytes",writer:"writeMIDIBytes"}},osc.inferTypeForArgument=function(a){var b=typeof a;switch(b){case"boolean":return a?"T":"F";case"string":return"s";case"number":return"f";case"undefined":return"N";case"object":if(null===a)return"N";if(a instanceof Uint8Array||a instanceof ArrayBuffer||osc.isBufferEnv&&a instanceof Buffer)return"b"}throw new Error("Can't infer OSC argument type for value: "+JSON.stringify(a,null,2))},osc.annotateArguments=function(a){osc.isArray(a)||(a=[a]);for(var b=[],c=0;c<a.length;c++){var d,e=a[c];if("object"==typeof e&&e.type&&void 0!==e.value)d=e;else{var f=osc.inferTypeForArgument(e);d={type:f,value:e}}b.push(d)}return b},"undefined"!=typeof module&&module.exports&&(osc.isBufferEnv&&(a=require("buffer-dataview")),module.exports=osc)}(),function(a,b){"use strict";"object"==typeof exports?(a.slip=exports,b(exports)):"function"==typeof define&&define.amd?define(["exports"],function(c){return a.slip=c,a.slip,b(c)}):(a.slip={},b(a.slip))}(this,function(a){"use strict";var b=a;b.END=192,b.ESC=219,b.ESC_END=220,b.ESC_ESC=221,b.byteArray=function(a,b,c){return a instanceof ArrayBuffer?new Uint8Array(a,b,c):a},b.expandByteArray=function(a){var b=new Uint8Array(2*a.length);return b.set(a),b},b.sliceByteArray=function(a,b,c){var d=a.buffer.slice?a.buffer.slice(b,c):a.subarray(b,c);return new Uint8Array(d)},b.encode=function(a,c){c=c||{},c.bufferPadding=c.bufferPadding||4,a=b.byteArray(a,c.offset,c.byteLength);var d=a.length+c.bufferPadding+3&-4,e=new Uint8Array(d),f=1;e[0]=b.END;for(var g=0;g<a.length;g++){f>e.length-3&&(e=b.expandByteArray(e));var h=a[g];h===b.END?(e[f++]=b.ESC,h=b.ESC_END):h===b.ESC&&(e[f++]=b.ESC,h=b.ESC_ESC),e[f++]=h}return e[f]=b.END,b.sliceByteArray(e,0,f+1)},b.Decoder=function(a){a="function"!=typeof a?a||{}:{onMessage:a},this.maxMessageSize=a.maxMessageSize||10485760,this.bufferSize=a.bufferSize||1024,this.msgBuffer=new Uint8Array(this.bufferSize),this.msgBufferIdx=0,this.onMessage=a.onMessage,this.onError=a.onError,this.escape=!1};var c=b.Decoder.prototype;return c.decode=function(a){a=b.byteArray(a);for(var c,d=0;d<a.length;d++){var e=a[d];if(this.escape)e===b.ESC_ESC?e=b.ESC:e===b.ESC_END&&(e=b.END);else{if(e===b.ESC){this.escape=!0;continue}if(e===b.END){c=this.handleEnd();continue}}var f=this.addByte(e);f||this.handleMessageMaxError()}return c},c.handleMessageMaxError=function(){this.onError&&this.onError(this.msgBuffer.subarray(0),"The message is too large; the maximum message size is "+this.maxMessageSize/1024+"KB. Use a larger maxMessageSize if necessary."),this.msgBufferIdx=0,this.escape=!1},c.addByte=function(a){return this.msgBufferIdx>this.msgBuffer.length-1&&(this.msgBuffer=b.expandByteArray(this.msgBuffer)),this.msgBuffer[this.msgBufferIdx++]=a,this.escape=!1,this.msgBuffer.length<this.maxMessageSize},c.handleEnd=function(){if(0!==this.msgBufferIdx){var a=b.sliceByteArray(this.msgBuffer,0,this.msgBufferIdx);return this.onMessage&&this.onMessage(a),this.msgBufferIdx=0,a}},b}),function(){"use strict";function a(){}function b(a,b){for(var c=a.length;c--;)if(a[c].listener===b)return c;return-1}function c(a){return function(){return this[a].apply(this,arguments)}}var d=a.prototype,e=this,f=e.EventEmitter;d.getListeners=function(a){var b,c,d=this._getEvents();if(a instanceof RegExp){b={};for(c in d)d.hasOwnProperty(c)&&a.test(c)&&(b[c]=d[c])}else b=d[a]||(d[a]=[]);return b},d.flattenListeners=function(a){var b,c=[];for(b=0;b<a.length;b+=1)c.push(a[b].listener);return c},d.getListenersAsObject=function(a){var b,c=this.getListeners(a);return c instanceof Array&&(b={},b[a]=c),b||c},d.addListener=function(a,c){var d,e=this.getListenersAsObject(a),f="object"==typeof c;for(d in e)e.hasOwnProperty(d)&&-1===b(e[d],c)&&e[d].push(f?c:{listener:c,once:!1});return this},d.on=c("addListener"),d.addOnceListener=function(a,b){return this.addListener(a,{listener:b,once:!0})},d.once=c("addOnceListener"),d.defineEvent=function(a){return this.getListeners(a),this},d.defineEvents=function(a){for(var b=0;b<a.length;b+=1)this.defineEvent(a[b]);return this},d.removeListener=function(a,c){var d,e,f=this.getListenersAsObject(a);for(e in f)f.hasOwnProperty(e)&&(d=b(f[e],c),-1!==d&&f[e].splice(d,1));return this},d.off=c("removeListener"),d.addListeners=function(a,b){return this.manipulateListeners(!1,a,b)},d.removeListeners=function(a,b){return this.manipulateListeners(!0,a,b)},d.manipulateListeners=function(a,b,c){var d,e,f=a?this.removeListener:this.addListener,g=a?this.removeListeners:this.addListeners;if("object"!=typeof b||b instanceof RegExp)for(d=c.length;d--;)f.call(this,b,c[d]);else for(d in b)b.hasOwnProperty(d)&&(e=b[d])&&("function"==typeof e?f.call(this,d,e):g.call(this,d,e));return this},d.removeEvent=function(a){var b,c=typeof a,d=this._getEvents();if("string"===c)delete d[a];else if(a instanceof RegExp)for(b in d)d.hasOwnProperty(b)&&a.test(b)&&delete d[b];else delete this._events;return this},d.removeAllListeners=c("removeEvent"),d.emitEvent=function(a,b){var c,d,e,f,g=this.getListenersAsObject(a);for(e in g)if(g.hasOwnProperty(e))for(d=g[e].length;d--;)c=g[e][d],c.once===!0&&this.removeListener(a,c.listener),f=c.listener.apply(this,b||[]),f===this._getOnceReturnValue()&&this.removeListener(a,c.listener);return this},d.trigger=c("emitEvent"),d.emit=function(a){var b=Array.prototype.slice.call(arguments,1);return this.emitEvent(a,b)},d.setOnceReturnValue=function(a){return this._onceReturnValue=a,this},d._getOnceReturnValue=function(){return this.hasOwnProperty("_onceReturnValue")?this._onceReturnValue:!0},d._getEvents=function(){return this._events||(this._events={})},a.noConflict=function(){return e.EventEmitter=f,a},"function"==typeof define&&define.amd?define(function(){return a}):"object"==typeof module&&module.exports?module.exports=a:e.EventEmitter=a}.call(this);var osc=osc||require("./osc.js"),slip=slip||require("slip"),EventEmitter=EventEmitter||require("events").EventEmitter;!function(){"use strict";osc.firePacketEvents=function(a,b,c){b.address?a.emit("message",b,c):osc.fireBundleEvents(a,b,c)},osc.fireBundleEvents=function(a,b,c){a.emit("bundle",b,c);for(var d=0;d<b.packets.length;d++){var e=b.packets[d];osc.firePacketEvents(a,e,b.timeTag)}},osc.Port=function(a){this.options=a||{},this.on("data",this.decodeOSC.bind(this))};var a=osc.Port.prototype=Object.create(EventEmitter.prototype);a.constructor=osc.Port,a.send=function(a){var b=Array.prototype.slice.call(arguments),c=this.encodeOSC(a);b[0]=c,this.sendRaw.apply(this,b)},a.encodeOSC=function(a){a=a.buffer?a.buffer:a;var b=osc.writePacket(a,this.options);return b},a.decodeOSC=function(a){this.emit("raw",a);var b=osc.readPacket(a,this.options);this.emit("osc",b),osc.firePacketEvents(this,b)},osc.SLIPPort=function(a){var b=this,c=this.options=a||{};c.useSLIP=void 0===c.useSLIP?!0:c.useSLIP,this.decoder=new slip.Decoder({onMessage:this.decodeOSC.bind(this),onError:function(a){b.emit("error",a)}});var d=c.useSLIP?this.decodeSLIPData:this.decodeOSC;this.on("data",d.bind(this))},a=osc.SLIPPort.prototype=Object.create(osc.Port.prototype),a.constructor=osc.SLIPPort,a.encodeOSC=function(a){a=a.buffer?a.buffer:a;var b=osc.writePacket(a,this.options);return slip.encode(b)},a.decodeSLIPData=function(a){this.decoder.decode(a)},osc.relay=function(a,b,c,d,e,f){c=c||"message",d=d||"send",e=e||function(){},f=f?[null].concat(f):[];var g=function(a){f[0]=a,a=e(a),b[d].apply(b,f)};return a.on(c,g),{eventName:c,listener:g}},osc.relayPorts=function(a,b,c){var d=c.raw?"raw":"osc",e=c.raw?"sendRaw":"send";return osc.relay(a,b,d,e,c.transform)},osc.stopRelaying=function(a,b){a.removeListener(b.eventName,b.listener)},osc.Relay=function(a,b,c){var d=this.options=c||{};d.raw=!1,this.port1=a,this.port2=b,this.listen()},a=osc.Relay.prototype,a.open=function(){this.port1.open(),this.port2.open()},a.listen=function(){this.port1Spec&&this.port2Spec&&this.close(),this.port1Spec=osc.relayPorts(this.port1,this.port2,this.options),this.port2Spec=osc.relayPorts(this.port2,this.port1,this.options)},a.close=function(){osc.stopRelaying(this.port1,this.port1Spec),osc.stopRelaying(this.port2,this.port2Spec)},"undefined"!=typeof module&&module.exports&&(module.exports=osc)}();var osc=osc;!function(){"use strict";osc.WebSocketPort=function(a){osc.Port.call(this,a),this.on("open",this.listen.bind(this))};var a=osc.WebSocketPort.prototype=Object.create(osc.Port.prototype);a.constructor=osc.WebSocketPort,a.open=function(){this.socket=new WebSocket(this.options.url),this.socket.binaryType="arraybuffer";var a=this;this.socket.onopen=function(){a.emit("open",a.socket)}},a.listen=function(){var a=this;this.socket.onmessage=function(b){a.emit("data",b.data)},this.socket.onerror=function(b){a.emit("error",b)},this.socket.onclose=function(b){a.emit("close",b)},a.emit("ready")},a.sendRaw=function(a){this.socket&&this.socket.send(a.buffer)},a.close=function(a,b){this.socket.close(a,b)}}(); |
/*! osc.js 1.1.2, Copyright 2015 Colin Clark | github.com/colinbdclark/osc.js */ | ||
var osc=osc||{};!function(){"use strict";var a;osc.SECS_70YRS=2208988800,osc.TWO_32=4294967296,osc.defaults={metadata:!1,unpackSingleArgs:!0},osc.isBufferEnv="undefined"!=typeof Buffer,osc.isArray=function(a){return a&&"[object Array]"===Object.prototype.toString.call(a)},osc.isTypedArrayView=function(a){return a.buffer&&a.buffer instanceof ArrayBuffer},osc.isBuffer=function(a){return osc.isBufferEnv&&a instanceof Buffer},osc.dataView=function(b){return b instanceof DataView?b:"undefined"!=typeof a&&b instanceof a?b:osc.isBufferEnv&&b instanceof Buffer?new a(b):b.buffer?new DataView(b.buffer):b instanceof ArrayBuffer?new DataView(b):new DataView(new Uint8Array(b))},osc.byteArray=function(a){if(a instanceof Uint8Array)return a;var b=a.buffer?a.buffer:a;if("undefined"==typeof a.length||"string"==typeof a)throw new Error("Can't wrap a non-array-like object as Uint8Array. Object was: "+JSON.stringify(a,null,2));return new Uint8Array(b)},osc.makeByteArray=function(a){return osc.isBufferEnv?new Buffer(a):new Uint8Array(a)},osc.copyByteArray=function(a,b,c){if(osc.isTypedArrayView(a)&&osc.isTypedArrayView(b))b.set(a,c);else if(osc.isBuffer(a)&&osc.isBuffer(b))a.copy(b,c);else for(var d=void 0===c?0:c,e=Math.min(b.length-c,a.length),f=0,g=d;e>f;f++,g++)b[g]=a[f];return b},osc.readString=function(a,b){for(var c=[],d=b.idx;d<a.byteLength;d++){var e=a.getUint8(d);if(0===e){d++;break}c.push(e)}return d=d+3&-4,b.idx=d,String.fromCharCode.apply(null,c)},osc.writeString=function(a){for(var b=a+"\x00",c=b.length,d=c+3&-4,e=new Uint8Array(d),f=0;f<b.length;f++){var g=b.charCodeAt(f);e[f]=g}return e},osc.readPrimitive=function(a,b,c,d){var e=a[b](d.idx,!1);return d.idx+=c,e},osc.writePrimitive=function(a,b,c,d,e){e=void 0===e?0:e;var f;return b?f=new Uint8Array(b.buffer):(f=new Uint8Array(d),b=new DataView(f.buffer)),b[c](e,a,!1),f},osc.readInt32=function(a,b){return osc.readPrimitive(a,"getInt32",4,b)},osc.writeInt32=function(a,b,c){return osc.writePrimitive(a,b,"setInt32",4,c)},osc.readFloat32=function(a,b){return osc.readPrimitive(a,"getFloat32",4,b)},osc.writeFloat32=function(a,b,c){return osc.writePrimitive(a,b,"setFloat32",4,c)},osc.readFloat64=function(a,b){return osc.readPrimitive(a,"getFloat64",8,b)},osc.writeFloat64=function(a,b,c){return osc.writePrimitive(a,b,"setFloat64",8,c)},osc.readChar32=function(a,b){var c=osc.readPrimitive(a,"getUint32",4,b);return String.fromCharCode(c)},osc.writeChar32=function(a,b,c){var d=a.charCodeAt(0);return void 0===d||-1>d?void 0:osc.writePrimitive(d,b,"setUint32",4,c)},osc.readBlob=function(a,b){var c=osc.readInt32(a,b),d=c+3&-4,e=new Uint8Array(a.buffer,b.idx,c);return b.idx+=d,e},osc.writeBlob=function(a){a=osc.byteArray(a);var b=a.byteLength,c=b+3&-4,d=4,e=c+d,f=new Uint8Array(e),g=new DataView(f.buffer);return osc.writeInt32(b,g),f.set(a,d),f},osc.readMIDIBytes=function(a,b){var c=new Uint8Array(a.buffer,b.idx,4);return b.idx+=4,c},osc.writeMIDIBytes=function(a){a=osc.byteArray(a);var b=new Uint8Array(4);return b.set(a),b},osc.readColor=function(a,b){var c=new Uint8Array(a.buffer,b.idx,4),d=c[3]/255;return b.idx+=4,{r:c[0],g:c[1],b:c[2],a:d}},osc.writeColor=function(a){var b=Math.round(255*a.a),c=new Uint8Array([a.r,a.g,a.b,b]);return c},osc.readTrue=function(){return!0},osc.readFalse=function(){return!1},osc.readNull=function(){return null},osc.readImpulse=function(){return 1},osc.readTimeTag=function(a,b){var c=osc.readPrimitive(a,"getUint32",4,b),d=osc.readPrimitive(a,"getUint32",4,b),e=0===c&&1===d?Date.now():osc.ntpToJSTime(c,d);return{raw:[c,d],"native":e}},osc.writeTimeTag=function(a){var b=a.raw?a.raw:osc.jsToNTPTime(a["native"]),c=new Uint8Array(8),d=new DataView(c.buffer);return osc.writeInt32(b[0],d,0),osc.writeInt32(b[1],d,4),c},osc.timeTag=function(a){a=a||0;var b=Date.now()/1e3,c=Math.floor(b),d=b-c,e=Math.floor(a),f=a-e,g=d+f;if(g>1){var h=Math.floor(g),i=g-h;e+=h,g=i}var j=c+e+osc.SECS_70YRS,k=Math.round(osc.TWO_32*g);return{raw:[j,k]}},osc.ntpToJSTime=function(a,b){var c=a-osc.SECS_70YRS,d=b/osc.TWO_32,e=1e3*(c+d);return e},osc.jsToNTPTime=function(a){var b=a/1e3,c=Math.floor(b),d=b-c,e=c+osc.SECS_70YRS,f=Math.round(osc.TWO_32*d);return[e,f]},osc.readArguments=function(a,b,c){var d=osc.readString(a,c);if(0!==d.indexOf(","))throw new Error("A malformed type tag string was found while reading the arguments of an OSC message. String was: "+d," at offset: "+c.idx);var e=d.substring(1).split(""),f=[];return osc.readArgumentsIntoArray(f,e,d,a,b,c),f},osc.readArgument=function(a,b,c,d,e){var f=osc.argumentTypes[a];if(!f)throw new Error("'"+a+"' is not a valid OSC type tag. Type tag string was: "+b);var g=f.reader,h=osc[g](c,e);return d.metadata&&(h={type:a,value:h}),h},osc.readArgumentsIntoArray=function(a,b,c,d,e,f){for(var g=0;g<b.length;){var h,i=b[g];if("["===i){var j=b.slice(g+1),k=j.indexOf("]");if(0>k)throw new Error("Invalid argument type tag: an open array type tag ('[') was found without a matching close array tag ('[]'). Type tag was: "+c);var l=j.slice(0,k);h=osc.readArgumentsIntoArray([],l,c,d,e,f),g+=k+2}else h=osc.readArgument(i,c,d,e,f),g++;a.push(h)}return a},osc.writeArguments=function(a,b){var c=osc.collectArguments(a,b);return osc.joinParts(c)},osc.joinParts=function(a){for(var b=osc.makeByteArray(a.byteLength),c=a.parts,d=0,e=0;e<c.length;e++){var f=c[e];osc.copyByteArray(f,b,d),d+=f.length}return b},osc.addDataPart=function(a,b){b.parts.push(a),b.byteLength+=a.length},osc.collectArguments=function(a,b,c){osc.isArray(a)||(a=[a]),c=c||{byteLength:0,parts:[]},b.metadata||(a=osc.annotateArguments(a));for(var d=",",e=c.parts.length,f=0;f<a.length;f++){var g=a[f],h=g.type,i=osc.argumentTypes[h].writer;if(d+=g.type,i){var j=osc[i](g.value);osc.addDataPart(j,c)}}var k=osc.writeString(d);return c.byteLength+=k.byteLength,c.parts.splice(e,0,k),c},osc.readMessage=function(a,b,c){b=b||osc.defaults;var d=osc.dataView(a);c=c||{idx:0};var e=osc.readString(d,c);return osc.readMessageContents(e,d,b,c)},osc.readMessageContents=function(a,b,c,d){if(0!==a.indexOf("/"))throw new Error("A malformed OSC address was found while reading an OSC message. String was: "+a);var e=osc.readArguments(b,c,d);return{address:a,args:1===e.length&&c.unpackSingleArgs?e[0]:e}},osc.collectMessageParts=function(a,b,c){return c=c||{byteLength:0,parts:[]},osc.addDataPart(osc.writeString(a.address),c),osc.collectArguments(a.args,b,c)},osc.writeMessage=function(a,b){b=b||osc.defaults;var c=osc.collectMessageParts(a,b);return osc.joinParts(c)},osc.readBundle=function(a,b,c){return osc.readPacket(a,b,c)},osc.collectBundlePackets=function(a,b,c){c=c||{byteLength:0,parts:[]},osc.addDataPart(osc.writeString("#bundle"),c),osc.addDataPart(osc.writeTimeTag(a.timeTag),c);for(var d=0;d<a.packets.length;d++){var e=a.packets[d],f=e.address?osc.collectMessageParts:osc.collectBundlePackets,g=f(e,b);c.byteLength+=g.byteLength,osc.addDataPart(osc.writeInt32(g.byteLength),c),c.parts=c.parts.concat(g.parts)}return c},osc.writeBundle=function(a,b){if(a.timeTag&&a.packets){b=b||osc.defaults;var c=osc.collectBundlePackets(a,b);return osc.joinParts(c)}},osc.readBundleContents=function(a,b,c,d){for(var e=osc.readTimeTag(a,c),f=[];c.idx<d;){var g=osc.readInt32(a,c),h=c.idx+g,i=osc.readPacket(a,b,c,h);f.push(i)}return{timeTag:e,packets:f}},osc.readPacket=function(a,b,c,d){var e=osc.dataView(a);d=void 0===d?e.byteLength:d,c=c||{idx:0};var f=osc.readString(e,c),g=f[0];if("#"===g)return osc.readBundleContents(e,b,c,d);if("/"===g)return osc.readMessageContents(f,e,b,c);throw new Error("The header of an OSC packet didn't contain an OSC address or a #bundle string. Header was: "+f)},osc.writePacket=function(a,b){var c=a.address?osc.writeMessage:osc.writeBundle;return c(a,b)},osc.argumentTypes={i:{reader:"readInt32",writer:"writeInt32"},f:{reader:"readFloat32",writer:"writeFloat32"},s:{reader:"readString",writer:"writeString"},S:{reader:"readString",writer:"writeString"},b:{reader:"readBlob",writer:"writeBlob"},t:{reader:"readTimeTag",writer:"writeTimeTag"},T:{reader:"readTrue"},F:{reader:"readFalse"},N:{reader:"readNull"},I:{reader:"readImpulse"},d:{reader:"readFloat64",writer:"writeFloat64"},c:{reader:"readChar32",writer:"writeChar32"},r:{reader:"readColor",writer:"writeColor"},m:{reader:"readMIDIBytes",writer:"writeMIDIBytes"}},osc.inferTypeForArgument=function(a){var b=typeof a;switch(b){case"boolean":return a?"T":"F";case"string":return"s";case"number":return"f";case"undefined":return"N";case"object":if(null===a)return"N";if(a instanceof Uint8Array||a instanceof ArrayBuffer||osc.isBufferEnv&&a instanceof Buffer)return"b"}throw new Error("Can't infer OSC argument type for value: "+JSON.stringify(a,null,2))},osc.annotateArguments=function(a){osc.isArray(a)||(a=[a]);for(var b=[],c=0;c<a.length;c++){var d,e=a[c];if("object"==typeof e&&e.type&&void 0!==e.value)d=e;else{var f=osc.inferTypeForArgument(e);d={type:f,value:e}}b.push(d)}return b},"undefined"!=typeof module&&module.exports&&(osc.isBufferEnv&&(a=require("buffer-dataview")),module.exports=osc)}();var slip=slip||{};!function(){"use strict";"undefined"!=typeof module&&module.exports&&(module.exports=slip),slip.END=192,slip.ESC=219,slip.ESC_END=220,slip.ESC_ESC=221,slip.byteArray=function(a,b,c){return a instanceof ArrayBuffer?new Uint8Array(a,b,c):a},slip.expandByteArray=function(a){var b=new Uint8Array(2*a.length);return b.set(a),b},slip.sliceByteArray=function(a,b,c){var d=a.buffer.slice?a.buffer.slice(b,c):a.subarray(b,c);return new Uint8Array(d)},slip.encode=function(a,b){b=b||{},b.bufferPadding=b.bufferPadding||4,a=slip.byteArray(a,b.offset,b.byteLength);var c=a.length+b.bufferPadding+3&-4,d=new Uint8Array(c),e=1;d[0]=slip.END;for(var f=0;f<a.length;f++){e>d.length-3&&(d=slip.expandByteArray(d));var g=a[f];g===slip.END?(d[e++]=slip.ESC,g=slip.ESC_END):g===slip.ESC&&(d[e++]=slip.ESC,g=slip.ESC_ESC),d[e++]=g}return d[e]=slip.END,slip.sliceByteArray(d,0,e+1)},slip.Decoder=function(a){a="function"!=typeof a?a||{}:{onMessage:a},this.maxMessageSize=a.maxMessageSize||10485760,this.bufferSize=a.bufferSize||1024,this.msgBuffer=new Uint8Array(this.bufferSize),this.msgBufferIdx=0,this.onMessage=a.onMessage,this.onError=a.onError,this.escape=!1};var a=slip.Decoder.prototype;a.decode=function(a){a=slip.byteArray(a);for(var b,c=0;c<a.length;c++){var d=a[c];if(this.escape)d===slip.ESC_ESC?d=slip.ESC:d===slip.ESC_END&&(d=slip.END);else{if(d===slip.ESC){this.escape=!0;continue}if(d===slip.END){b=this.handleEnd();continue}}var e=this.addByte(d);e||this.handleMessageMaxError()}return b},a.handleMessageMaxError=function(){this.onError&&this.onError(this.msgBuffer.subarray(0),"The message is too large; the maximum message size is "+this.maxMessageSize/1024+"KB. Use a larger maxMessageSize if necessary."),this.msgBufferIdx=0,this.escape=!1},a.addByte=function(a){return this.msgBufferIdx>this.msgBuffer.length-1&&(this.msgBuffer=slip.expandByteArray(this.msgBuffer)),this.msgBuffer[this.msgBufferIdx++]=a,this.escape=!1,this.msgBuffer.length<this.maxMessageSize},a.handleEnd=function(){if(0!==this.msgBufferIdx){var a=slip.sliceByteArray(this.msgBuffer,0,this.msgBufferIdx);return this.onMessage&&this.onMessage(a),this.msgBufferIdx=0,a}}}(),function(){"use strict";function a(){}function b(a,b){for(var c=a.length;c--;)if(a[c].listener===b)return c;return-1}function c(a){return function(){return this[a].apply(this,arguments)}}var d=a.prototype,e=this,f=e.EventEmitter;d.getListeners=function(a){var b,c,d=this._getEvents();if(a instanceof RegExp){b={};for(c in d)d.hasOwnProperty(c)&&a.test(c)&&(b[c]=d[c])}else b=d[a]||(d[a]=[]);return b},d.flattenListeners=function(a){var b,c=[];for(b=0;b<a.length;b+=1)c.push(a[b].listener);return c},d.getListenersAsObject=function(a){var b,c=this.getListeners(a);return c instanceof Array&&(b={},b[a]=c),b||c},d.addListener=function(a,c){var d,e=this.getListenersAsObject(a),f="object"==typeof c;for(d in e)e.hasOwnProperty(d)&&-1===b(e[d],c)&&e[d].push(f?c:{listener:c,once:!1});return this},d.on=c("addListener"),d.addOnceListener=function(a,b){return this.addListener(a,{listener:b,once:!0})},d.once=c("addOnceListener"),d.defineEvent=function(a){return this.getListeners(a),this},d.defineEvents=function(a){for(var b=0;b<a.length;b+=1)this.defineEvent(a[b]);return this},d.removeListener=function(a,c){var d,e,f=this.getListenersAsObject(a);for(e in f)f.hasOwnProperty(e)&&(d=b(f[e],c),-1!==d&&f[e].splice(d,1));return this},d.off=c("removeListener"),d.addListeners=function(a,b){return this.manipulateListeners(!1,a,b)},d.removeListeners=function(a,b){return this.manipulateListeners(!0,a,b)},d.manipulateListeners=function(a,b,c){var d,e,f=a?this.removeListener:this.addListener,g=a?this.removeListeners:this.addListeners;if("object"!=typeof b||b instanceof RegExp)for(d=c.length;d--;)f.call(this,b,c[d]);else for(d in b)b.hasOwnProperty(d)&&(e=b[d])&&("function"==typeof e?f.call(this,d,e):g.call(this,d,e));return this},d.removeEvent=function(a){var b,c=typeof a,d=this._getEvents();if("string"===c)delete d[a];else if(a instanceof RegExp)for(b in d)d.hasOwnProperty(b)&&a.test(b)&&delete d[b];else delete this._events;return this},d.removeAllListeners=c("removeEvent"),d.emitEvent=function(a,b){var c,d,e,f,g=this.getListenersAsObject(a);for(e in g)if(g.hasOwnProperty(e))for(d=g[e].length;d--;)c=g[e][d],c.once===!0&&this.removeListener(a,c.listener),f=c.listener.apply(this,b||[]),f===this._getOnceReturnValue()&&this.removeListener(a,c.listener);return this},d.trigger=c("emitEvent"),d.emit=function(a){var b=Array.prototype.slice.call(arguments,1);return this.emitEvent(a,b)},d.setOnceReturnValue=function(a){return this._onceReturnValue=a,this},d._getOnceReturnValue=function(){return this.hasOwnProperty("_onceReturnValue")?this._onceReturnValue:!0},d._getEvents=function(){return this._events||(this._events={})},a.noConflict=function(){return e.EventEmitter=f,a},"function"==typeof define&&define.amd?define(function(){return a}):"object"==typeof module&&module.exports?module.exports=a:e.EventEmitter=a}.call(this);var osc=osc||require("./osc.js"),slip=slip||require("slip"),EventEmitter=EventEmitter||require("events").EventEmitter;!function(){"use strict";osc.firePacketEvents=function(a,b,c){b.address?a.emit("message",b,c):osc.fireBundleEvents(a,b,c)},osc.fireBundleEvents=function(a,b,c){a.emit("bundle",b,c);for(var d=0;d<b.packets.length;d++){var e=b.packets[d];osc.firePacketEvents(a,e,b.timeTag)}},osc.Port=function(a){this.options=a||{},this.on("data",this.decodeOSC.bind(this))};var a=osc.Port.prototype=Object.create(EventEmitter.prototype);a.constructor=osc.Port,a.send=function(a){var b=Array.prototype.slice.call(arguments),c=this.encodeOSC(a);b[0]=c,this.sendRaw.apply(this,b)},a.encodeOSC=function(a){a=a.buffer?a.buffer:a;var b=osc.writePacket(a,this.options);return b},a.decodeOSC=function(a){this.emit("raw",a);var b=osc.readPacket(a,this.options);this.emit("osc",b),osc.firePacketEvents(this,b)},osc.SLIPPort=function(a){var b=this,c=this.options=a||{};c.useSLIP=void 0===c.useSLIP?!0:c.useSLIP,this.decoder=new slip.Decoder({onMessage:this.decodeOSC.bind(this),onError:function(a){b.emit("error",a)}});var d=c.useSLIP?this.decodeSLIPData:this.decodeOSC;this.on("data",d.bind(this))},a=osc.SLIPPort.prototype=Object.create(osc.Port.prototype),a.constructor=osc.SLIPPort,a.encodeOSC=function(a){a=a.buffer?a.buffer:a;var b=osc.writePacket(a,this.options);return slip.encode(b)},a.decodeSLIPData=function(a){this.decoder.decode(a)},osc.relay=function(a,b,c,d,e,f){c=c||"message",d=d||"send",e=e||function(){},f=f?[null].concat(f):[];var g=function(a){f[0]=a,a=e(a),b[d].apply(b,f)};return a.on(c,g),{eventName:c,listener:g}},osc.relayPorts=function(a,b,c){var d=c.raw?"raw":"osc",e=c.raw?"sendRaw":"send";return osc.relay(a,b,d,e,c.transform)},osc.stopRelaying=function(a,b){a.removeListener(b.eventName,b.listener)},osc.Relay=function(a,b,c){var d=this.options=c||{};d.raw=!1,this.port1=a,this.port2=b,this.listen()},a=osc.Relay.prototype,a.open=function(){this.port1.open(),this.port2.open()},a.listen=function(){this.port1Spec&&this.port2Spec&&this.close(),this.port1Spec=osc.relayPorts(this.port1,this.port2,this.options),this.port2Spec=osc.relayPorts(this.port2,this.port1,this.options)},a.close=function(){osc.stopRelaying(this.port1,this.port1Spec),osc.stopRelaying(this.port2,this.port2Spec)},"undefined"!=typeof module&&module.exports&&(module.exports=osc)}();var osc=osc;!function(){"use strict";osc.WebSocketPort=function(a){osc.Port.call(this,a),this.on("open",this.listen.bind(this))};var a=osc.WebSocketPort.prototype=Object.create(osc.Port.prototype);a.constructor=osc.WebSocketPort,a.open=function(){this.socket=new WebSocket(this.options.url),this.socket.binaryType="arraybuffer";var a=this;this.socket.onopen=function(){a.emit("open",a.socket)}},a.listen=function(){var a=this;this.socket.onmessage=function(b){a.emit("data",b.data)},this.socket.onerror=function(b){a.emit("error",b)},this.socket.onclose=function(b){a.emit("close",b)},a.emit("ready")},a.sendRaw=function(a){this.socket&&this.socket.send(a.buffer)},a.close=function(a,b){this.socket.close(a,b)}}();var osc=osc||{};!function(){"use strict";osc.listenToTransport=function(a,b,c){b.onReceive.addListener(function(b){b[c]===a[c]&&a.emit("data",b.data)}),b.onReceiveError.addListener(function(b){a.emit("error",b)}),a.emit("ready")},osc.emitNetworkError=function(a,b){a.emit("error","There was an error while opening the UDP socket connection. Result code: "+b)},osc.SerialPort=function(a){this.on("open",this.listen.bind(this)),osc.SLIPPort.call(this,a)};var a=osc.SerialPort.prototype=Object.create(osc.SLIPPort.prototype);a.constructor=osc.SerialPort,a.open=function(){var a=this,b={bitrate:a.options.bitrate};chrome.serial.connect(this.options.devicePath,b,function(b){a.connectionId=b.connectionId,a.emit("open",b)})},a.listen=function(){osc.listenToTransport(this,chrome.serial,"connectionId")},a.sendRaw=function(a){if(this.connectionId){var b=this;chrome.serial.send(this.connectionId,a.buffer,function(a,c){c&&b.emit("error",c+". Total bytes sent: "+a)})}},a.close=function(){if(this.connectionId){var a=this;chrome.serial.disconnect(this.connectionId,function(b){b&&a.emit("close")})}},osc.UDPPort=function(a){osc.Port.call(this,a);var b=this.options;b.localAddress=b.localAddress||"127.0.0.1",b.localPort=void 0!==b.localPort?b.localPort:57121,this.on("open",this.listen.bind(this))},a=osc.UDPPort.prototype=Object.create(osc.Port.prototype),a.constructor=osc.UDPPort,a.open=function(){var a=this.options,b={persistent:a.persistent,name:a.name,bufferSize:a.bufferSize},c=this;chrome.sockets.udp.create(b,function(a){c.socketId=a.socketId,c.bindSocket()})},a.bindSocket=function(){var a=this,b=this.options;chrome.sockets.udp.bind(this.socketId,b.localAddress,b.localPort,function(b){return b>0?void osc.emitNetworkError(a,b):void a.emit("open",b)})},a.listen=function(){osc.listenToTransport(this,chrome.sockets.udp,"socketId")},a.sendRaw=function(a,b,c){if(this.socketId){var d=this.options,e=this;b=b||d.remoteAddress,c=void 0!==c?c:d.remotePort,chrome.sockets.udp.send(this.socketId,a.buffer,b,c,function(a){a||e.emit("error","There was an unknown error while trying to send a UDP message. Have you declared the appropriate udp send permissions in your application's manifest file?"),a.resultCode>0&&osc.emitNetworkError(e,a.resultCode)})}},a.close=function(){if(this.socketId){var a=this;chrome.sockets.udp.close(this.socketId,function(){a.emit("close")})}}}(); | ||
var osc=osc||{};!function(){"use strict";var a;osc.SECS_70YRS=2208988800,osc.TWO_32=4294967296,osc.defaults={metadata:!1,unpackSingleArgs:!0},osc.isBufferEnv="undefined"!=typeof Buffer,osc.isArray=function(a){return a&&"[object Array]"===Object.prototype.toString.call(a)},osc.isTypedArrayView=function(a){return a.buffer&&a.buffer instanceof ArrayBuffer},osc.isBuffer=function(a){return osc.isBufferEnv&&a instanceof Buffer},osc.dataView=function(b){return b instanceof DataView?b:"undefined"!=typeof a&&b instanceof a?b:osc.isBufferEnv&&b instanceof Buffer?new a(b):b.buffer?new DataView(b.buffer):b instanceof ArrayBuffer?new DataView(b):new DataView(new Uint8Array(b))},osc.byteArray=function(a){if(a instanceof Uint8Array)return a;var b=a.buffer?a.buffer:a;if("undefined"==typeof a.length||"string"==typeof a)throw new Error("Can't wrap a non-array-like object as Uint8Array. Object was: "+JSON.stringify(a,null,2));return new Uint8Array(b)},osc.makeByteArray=function(a){return osc.isBufferEnv?new Buffer(a):new Uint8Array(a)},osc.copyByteArray=function(a,b,c){if(osc.isTypedArrayView(a)&&osc.isTypedArrayView(b))b.set(a,c);else if(osc.isBuffer(a)&&osc.isBuffer(b))a.copy(b,c);else for(var d=void 0===c?0:c,e=Math.min(b.length-c,a.length),f=0,g=d;e>f;f++,g++)b[g]=a[f];return b},osc.readString=function(a,b){for(var c=[],d=b.idx;d<a.byteLength;d++){var e=a.getUint8(d);if(0===e){d++;break}c.push(e)}return d=d+3&-4,b.idx=d,String.fromCharCode.apply(null,c)},osc.writeString=function(a){for(var b=a+"\x00",c=b.length,d=c+3&-4,e=new Uint8Array(d),f=0;f<b.length;f++){var g=b.charCodeAt(f);e[f]=g}return e},osc.readPrimitive=function(a,b,c,d){var e=a[b](d.idx,!1);return d.idx+=c,e},osc.writePrimitive=function(a,b,c,d,e){e=void 0===e?0:e;var f;return b?f=new Uint8Array(b.buffer):(f=new Uint8Array(d),b=new DataView(f.buffer)),b[c](e,a,!1),f},osc.readInt32=function(a,b){return osc.readPrimitive(a,"getInt32",4,b)},osc.writeInt32=function(a,b,c){return osc.writePrimitive(a,b,"setInt32",4,c)},osc.readFloat32=function(a,b){return osc.readPrimitive(a,"getFloat32",4,b)},osc.writeFloat32=function(a,b,c){return osc.writePrimitive(a,b,"setFloat32",4,c)},osc.readFloat64=function(a,b){return osc.readPrimitive(a,"getFloat64",8,b)},osc.writeFloat64=function(a,b,c){return osc.writePrimitive(a,b,"setFloat64",8,c)},osc.readChar32=function(a,b){var c=osc.readPrimitive(a,"getUint32",4,b);return String.fromCharCode(c)},osc.writeChar32=function(a,b,c){var d=a.charCodeAt(0);return void 0===d||-1>d?void 0:osc.writePrimitive(d,b,"setUint32",4,c)},osc.readBlob=function(a,b){var c=osc.readInt32(a,b),d=c+3&-4,e=new Uint8Array(a.buffer,b.idx,c);return b.idx+=d,e},osc.writeBlob=function(a){a=osc.byteArray(a);var b=a.byteLength,c=b+3&-4,d=4,e=c+d,f=new Uint8Array(e),g=new DataView(f.buffer);return osc.writeInt32(b,g),f.set(a,d),f},osc.readMIDIBytes=function(a,b){var c=new Uint8Array(a.buffer,b.idx,4);return b.idx+=4,c},osc.writeMIDIBytes=function(a){a=osc.byteArray(a);var b=new Uint8Array(4);return b.set(a),b},osc.readColor=function(a,b){var c=new Uint8Array(a.buffer,b.idx,4),d=c[3]/255;return b.idx+=4,{r:c[0],g:c[1],b:c[2],a:d}},osc.writeColor=function(a){var b=Math.round(255*a.a),c=new Uint8Array([a.r,a.g,a.b,b]);return c},osc.readTrue=function(){return!0},osc.readFalse=function(){return!1},osc.readNull=function(){return null},osc.readImpulse=function(){return 1},osc.readTimeTag=function(a,b){var c=osc.readPrimitive(a,"getUint32",4,b),d=osc.readPrimitive(a,"getUint32",4,b),e=0===c&&1===d?Date.now():osc.ntpToJSTime(c,d);return{raw:[c,d],"native":e}},osc.writeTimeTag=function(a){var b=a.raw?a.raw:osc.jsToNTPTime(a["native"]),c=new Uint8Array(8),d=new DataView(c.buffer);return osc.writeInt32(b[0],d,0),osc.writeInt32(b[1],d,4),c},osc.timeTag=function(a){a=a||0;var b=Date.now()/1e3,c=Math.floor(b),d=b-c,e=Math.floor(a),f=a-e,g=d+f;if(g>1){var h=Math.floor(g),i=g-h;e+=h,g=i}var j=c+e+osc.SECS_70YRS,k=Math.round(osc.TWO_32*g);return{raw:[j,k]}},osc.ntpToJSTime=function(a,b){var c=a-osc.SECS_70YRS,d=b/osc.TWO_32,e=1e3*(c+d);return e},osc.jsToNTPTime=function(a){var b=a/1e3,c=Math.floor(b),d=b-c,e=c+osc.SECS_70YRS,f=Math.round(osc.TWO_32*d);return[e,f]},osc.readArguments=function(a,b,c){var d=osc.readString(a,c);if(0!==d.indexOf(","))throw new Error("A malformed type tag string was found while reading the arguments of an OSC message. String was: "+d," at offset: "+c.idx);var e=d.substring(1).split(""),f=[];return osc.readArgumentsIntoArray(f,e,d,a,b,c),f},osc.readArgument=function(a,b,c,d,e){var f=osc.argumentTypes[a];if(!f)throw new Error("'"+a+"' is not a valid OSC type tag. Type tag string was: "+b);var g=f.reader,h=osc[g](c,e);return d.metadata&&(h={type:a,value:h}),h},osc.readArgumentsIntoArray=function(a,b,c,d,e,f){for(var g=0;g<b.length;){var h,i=b[g];if("["===i){var j=b.slice(g+1),k=j.indexOf("]");if(0>k)throw new Error("Invalid argument type tag: an open array type tag ('[') was found without a matching close array tag ('[]'). Type tag was: "+c);var l=j.slice(0,k);h=osc.readArgumentsIntoArray([],l,c,d,e,f),g+=k+2}else h=osc.readArgument(i,c,d,e,f),g++;a.push(h)}return a},osc.writeArguments=function(a,b){var c=osc.collectArguments(a,b);return osc.joinParts(c)},osc.joinParts=function(a){for(var b=osc.makeByteArray(a.byteLength),c=a.parts,d=0,e=0;e<c.length;e++){var f=c[e];osc.copyByteArray(f,b,d),d+=f.length}return b},osc.addDataPart=function(a,b){b.parts.push(a),b.byteLength+=a.length},osc.collectArguments=function(a,b,c){osc.isArray(a)||(a=[a]),c=c||{byteLength:0,parts:[]},b.metadata||(a=osc.annotateArguments(a));for(var d=",",e=c.parts.length,f=0;f<a.length;f++){var g=a[f],h=g.type,i=osc.argumentTypes[h].writer;if(d+=g.type,i){var j=osc[i](g.value);osc.addDataPart(j,c)}}var k=osc.writeString(d);return c.byteLength+=k.byteLength,c.parts.splice(e,0,k),c},osc.readMessage=function(a,b,c){b=b||osc.defaults;var d=osc.dataView(a);c=c||{idx:0};var e=osc.readString(d,c);return osc.readMessageContents(e,d,b,c)},osc.readMessageContents=function(a,b,c,d){if(0!==a.indexOf("/"))throw new Error("A malformed OSC address was found while reading an OSC message. String was: "+a);var e=osc.readArguments(b,c,d);return{address:a,args:1===e.length&&c.unpackSingleArgs?e[0]:e}},osc.collectMessageParts=function(a,b,c){return c=c||{byteLength:0,parts:[]},osc.addDataPart(osc.writeString(a.address),c),osc.collectArguments(a.args,b,c)},osc.writeMessage=function(a,b){b=b||osc.defaults;var c=osc.collectMessageParts(a,b);return osc.joinParts(c)},osc.readBundle=function(a,b,c){return osc.readPacket(a,b,c)},osc.collectBundlePackets=function(a,b,c){c=c||{byteLength:0,parts:[]},osc.addDataPart(osc.writeString("#bundle"),c),osc.addDataPart(osc.writeTimeTag(a.timeTag),c);for(var d=0;d<a.packets.length;d++){var e=a.packets[d],f=e.address?osc.collectMessageParts:osc.collectBundlePackets,g=f(e,b);c.byteLength+=g.byteLength,osc.addDataPart(osc.writeInt32(g.byteLength),c),c.parts=c.parts.concat(g.parts)}return c},osc.writeBundle=function(a,b){if(a.timeTag&&a.packets){b=b||osc.defaults;var c=osc.collectBundlePackets(a,b);return osc.joinParts(c)}},osc.readBundleContents=function(a,b,c,d){for(var e=osc.readTimeTag(a,c),f=[];c.idx<d;){var g=osc.readInt32(a,c),h=c.idx+g,i=osc.readPacket(a,b,c,h);f.push(i)}return{timeTag:e,packets:f}},osc.readPacket=function(a,b,c,d){var e=osc.dataView(a);d=void 0===d?e.byteLength:d,c=c||{idx:0};var f=osc.readString(e,c),g=f[0];if("#"===g)return osc.readBundleContents(e,b,c,d);if("/"===g)return osc.readMessageContents(f,e,b,c);throw new Error("The header of an OSC packet didn't contain an OSC address or a #bundle string. Header was: "+f)},osc.writePacket=function(a,b){var c=a.address?osc.writeMessage:osc.writeBundle;return c(a,b)},osc.argumentTypes={i:{reader:"readInt32",writer:"writeInt32"},f:{reader:"readFloat32",writer:"writeFloat32"},s:{reader:"readString",writer:"writeString"},S:{reader:"readString",writer:"writeString"},b:{reader:"readBlob",writer:"writeBlob"},t:{reader:"readTimeTag",writer:"writeTimeTag"},T:{reader:"readTrue"},F:{reader:"readFalse"},N:{reader:"readNull"},I:{reader:"readImpulse"},d:{reader:"readFloat64",writer:"writeFloat64"},c:{reader:"readChar32",writer:"writeChar32"},r:{reader:"readColor",writer:"writeColor"},m:{reader:"readMIDIBytes",writer:"writeMIDIBytes"}},osc.inferTypeForArgument=function(a){var b=typeof a;switch(b){case"boolean":return a?"T":"F";case"string":return"s";case"number":return"f";case"undefined":return"N";case"object":if(null===a)return"N";if(a instanceof Uint8Array||a instanceof ArrayBuffer||osc.isBufferEnv&&a instanceof Buffer)return"b"}throw new Error("Can't infer OSC argument type for value: "+JSON.stringify(a,null,2))},osc.annotateArguments=function(a){osc.isArray(a)||(a=[a]);for(var b=[],c=0;c<a.length;c++){var d,e=a[c];if("object"==typeof e&&e.type&&void 0!==e.value)d=e;else{var f=osc.inferTypeForArgument(e);d={type:f,value:e}}b.push(d)}return b},"undefined"!=typeof module&&module.exports&&(osc.isBufferEnv&&(a=require("buffer-dataview")),module.exports=osc)}(),function(a,b){"use strict";"object"==typeof exports?(a.slip=exports,b(exports)):"function"==typeof define&&define.amd?define(["exports"],function(c){return a.slip=c,a.slip,b(c)}):(a.slip={},b(a.slip))}(this,function(a){"use strict";var b=a;b.END=192,b.ESC=219,b.ESC_END=220,b.ESC_ESC=221,b.byteArray=function(a,b,c){return a instanceof ArrayBuffer?new Uint8Array(a,b,c):a},b.expandByteArray=function(a){var b=new Uint8Array(2*a.length);return b.set(a),b},b.sliceByteArray=function(a,b,c){var d=a.buffer.slice?a.buffer.slice(b,c):a.subarray(b,c);return new Uint8Array(d)},b.encode=function(a,c){c=c||{},c.bufferPadding=c.bufferPadding||4,a=b.byteArray(a,c.offset,c.byteLength);var d=a.length+c.bufferPadding+3&-4,e=new Uint8Array(d),f=1;e[0]=b.END;for(var g=0;g<a.length;g++){f>e.length-3&&(e=b.expandByteArray(e));var h=a[g];h===b.END?(e[f++]=b.ESC,h=b.ESC_END):h===b.ESC&&(e[f++]=b.ESC,h=b.ESC_ESC),e[f++]=h}return e[f]=b.END,b.sliceByteArray(e,0,f+1)},b.Decoder=function(a){a="function"!=typeof a?a||{}:{onMessage:a},this.maxMessageSize=a.maxMessageSize||10485760,this.bufferSize=a.bufferSize||1024,this.msgBuffer=new Uint8Array(this.bufferSize),this.msgBufferIdx=0,this.onMessage=a.onMessage,this.onError=a.onError,this.escape=!1};var c=b.Decoder.prototype;return c.decode=function(a){a=b.byteArray(a);for(var c,d=0;d<a.length;d++){var e=a[d];if(this.escape)e===b.ESC_ESC?e=b.ESC:e===b.ESC_END&&(e=b.END);else{if(e===b.ESC){this.escape=!0;continue}if(e===b.END){c=this.handleEnd();continue}}var f=this.addByte(e);f||this.handleMessageMaxError()}return c},c.handleMessageMaxError=function(){this.onError&&this.onError(this.msgBuffer.subarray(0),"The message is too large; the maximum message size is "+this.maxMessageSize/1024+"KB. Use a larger maxMessageSize if necessary."),this.msgBufferIdx=0,this.escape=!1},c.addByte=function(a){return this.msgBufferIdx>this.msgBuffer.length-1&&(this.msgBuffer=b.expandByteArray(this.msgBuffer)),this.msgBuffer[this.msgBufferIdx++]=a,this.escape=!1,this.msgBuffer.length<this.maxMessageSize},c.handleEnd=function(){if(0!==this.msgBufferIdx){var a=b.sliceByteArray(this.msgBuffer,0,this.msgBufferIdx);return this.onMessage&&this.onMessage(a),this.msgBufferIdx=0,a}},b}),function(){"use strict";function a(){}function b(a,b){for(var c=a.length;c--;)if(a[c].listener===b)return c;return-1}function c(a){return function(){return this[a].apply(this,arguments)}}var d=a.prototype,e=this,f=e.EventEmitter;d.getListeners=function(a){var b,c,d=this._getEvents();if(a instanceof RegExp){b={};for(c in d)d.hasOwnProperty(c)&&a.test(c)&&(b[c]=d[c])}else b=d[a]||(d[a]=[]);return b},d.flattenListeners=function(a){var b,c=[];for(b=0;b<a.length;b+=1)c.push(a[b].listener);return c},d.getListenersAsObject=function(a){var b,c=this.getListeners(a);return c instanceof Array&&(b={},b[a]=c),b||c},d.addListener=function(a,c){var d,e=this.getListenersAsObject(a),f="object"==typeof c;for(d in e)e.hasOwnProperty(d)&&-1===b(e[d],c)&&e[d].push(f?c:{listener:c,once:!1});return this},d.on=c("addListener"),d.addOnceListener=function(a,b){return this.addListener(a,{listener:b,once:!0})},d.once=c("addOnceListener"),d.defineEvent=function(a){return this.getListeners(a),this},d.defineEvents=function(a){for(var b=0;b<a.length;b+=1)this.defineEvent(a[b]);return this},d.removeListener=function(a,c){var d,e,f=this.getListenersAsObject(a);for(e in f)f.hasOwnProperty(e)&&(d=b(f[e],c),-1!==d&&f[e].splice(d,1));return this},d.off=c("removeListener"),d.addListeners=function(a,b){return this.manipulateListeners(!1,a,b)},d.removeListeners=function(a,b){return this.manipulateListeners(!0,a,b)},d.manipulateListeners=function(a,b,c){var d,e,f=a?this.removeListener:this.addListener,g=a?this.removeListeners:this.addListeners;if("object"!=typeof b||b instanceof RegExp)for(d=c.length;d--;)f.call(this,b,c[d]);else for(d in b)b.hasOwnProperty(d)&&(e=b[d])&&("function"==typeof e?f.call(this,d,e):g.call(this,d,e));return this},d.removeEvent=function(a){var b,c=typeof a,d=this._getEvents();if("string"===c)delete d[a];else if(a instanceof RegExp)for(b in d)d.hasOwnProperty(b)&&a.test(b)&&delete d[b];else delete this._events;return this},d.removeAllListeners=c("removeEvent"),d.emitEvent=function(a,b){var c,d,e,f,g=this.getListenersAsObject(a);for(e in g)if(g.hasOwnProperty(e))for(d=g[e].length;d--;)c=g[e][d],c.once===!0&&this.removeListener(a,c.listener),f=c.listener.apply(this,b||[]),f===this._getOnceReturnValue()&&this.removeListener(a,c.listener);return this},d.trigger=c("emitEvent"),d.emit=function(a){var b=Array.prototype.slice.call(arguments,1);return this.emitEvent(a,b)},d.setOnceReturnValue=function(a){return this._onceReturnValue=a,this},d._getOnceReturnValue=function(){return this.hasOwnProperty("_onceReturnValue")?this._onceReturnValue:!0},d._getEvents=function(){return this._events||(this._events={})},a.noConflict=function(){return e.EventEmitter=f,a},"function"==typeof define&&define.amd?define(function(){return a}):"object"==typeof module&&module.exports?module.exports=a:e.EventEmitter=a}.call(this);var osc=osc||require("./osc.js"),slip=slip||require("slip"),EventEmitter=EventEmitter||require("events").EventEmitter;!function(){"use strict";osc.firePacketEvents=function(a,b,c){b.address?a.emit("message",b,c):osc.fireBundleEvents(a,b,c)},osc.fireBundleEvents=function(a,b,c){a.emit("bundle",b,c);for(var d=0;d<b.packets.length;d++){var e=b.packets[d];osc.firePacketEvents(a,e,b.timeTag)}},osc.Port=function(a){this.options=a||{},this.on("data",this.decodeOSC.bind(this))};var a=osc.Port.prototype=Object.create(EventEmitter.prototype);a.constructor=osc.Port,a.send=function(a){var b=Array.prototype.slice.call(arguments),c=this.encodeOSC(a);b[0]=c,this.sendRaw.apply(this,b)},a.encodeOSC=function(a){a=a.buffer?a.buffer:a;var b=osc.writePacket(a,this.options);return b},a.decodeOSC=function(a){this.emit("raw",a);var b=osc.readPacket(a,this.options);this.emit("osc",b),osc.firePacketEvents(this,b)},osc.SLIPPort=function(a){var b=this,c=this.options=a||{};c.useSLIP=void 0===c.useSLIP?!0:c.useSLIP,this.decoder=new slip.Decoder({onMessage:this.decodeOSC.bind(this),onError:function(a){b.emit("error",a)}});var d=c.useSLIP?this.decodeSLIPData:this.decodeOSC;this.on("data",d.bind(this))},a=osc.SLIPPort.prototype=Object.create(osc.Port.prototype),a.constructor=osc.SLIPPort,a.encodeOSC=function(a){a=a.buffer?a.buffer:a;var b=osc.writePacket(a,this.options);return slip.encode(b)},a.decodeSLIPData=function(a){this.decoder.decode(a)},osc.relay=function(a,b,c,d,e,f){c=c||"message",d=d||"send",e=e||function(){},f=f?[null].concat(f):[];var g=function(a){f[0]=a,a=e(a),b[d].apply(b,f)};return a.on(c,g),{eventName:c,listener:g}},osc.relayPorts=function(a,b,c){var d=c.raw?"raw":"osc",e=c.raw?"sendRaw":"send";return osc.relay(a,b,d,e,c.transform)},osc.stopRelaying=function(a,b){a.removeListener(b.eventName,b.listener)},osc.Relay=function(a,b,c){var d=this.options=c||{};d.raw=!1,this.port1=a,this.port2=b,this.listen()},a=osc.Relay.prototype,a.open=function(){this.port1.open(),this.port2.open()},a.listen=function(){this.port1Spec&&this.port2Spec&&this.close(),this.port1Spec=osc.relayPorts(this.port1,this.port2,this.options),this.port2Spec=osc.relayPorts(this.port2,this.port1,this.options)},a.close=function(){osc.stopRelaying(this.port1,this.port1Spec),osc.stopRelaying(this.port2,this.port2Spec)},"undefined"!=typeof module&&module.exports&&(module.exports=osc)}();var osc=osc;!function(){"use strict";osc.WebSocketPort=function(a){osc.Port.call(this,a),this.on("open",this.listen.bind(this))};var a=osc.WebSocketPort.prototype=Object.create(osc.Port.prototype);a.constructor=osc.WebSocketPort,a.open=function(){this.socket=new WebSocket(this.options.url),this.socket.binaryType="arraybuffer";var a=this;this.socket.onopen=function(){a.emit("open",a.socket)}},a.listen=function(){var a=this;this.socket.onmessage=function(b){a.emit("data",b.data)},this.socket.onerror=function(b){a.emit("error",b)},this.socket.onclose=function(b){a.emit("close",b)},a.emit("ready")},a.sendRaw=function(a){this.socket&&this.socket.send(a.buffer)},a.close=function(a,b){this.socket.close(a,b)}}();var osc=osc||{};!function(){"use strict";osc.listenToTransport=function(a,b,c){b.onReceive.addListener(function(b){b[c]===a[c]&&a.emit("data",b.data)}),b.onReceiveError.addListener(function(b){a.emit("error",b)}),a.emit("ready")},osc.emitNetworkError=function(a,b){a.emit("error","There was an error while opening the UDP socket connection. Result code: "+b)},osc.SerialPort=function(a){this.on("open",this.listen.bind(this)),osc.SLIPPort.call(this,a)};var a=osc.SerialPort.prototype=Object.create(osc.SLIPPort.prototype);a.constructor=osc.SerialPort,a.open=function(){var a=this,b={bitrate:a.options.bitrate};chrome.serial.connect(this.options.devicePath,b,function(b){a.connectionId=b.connectionId,a.emit("open",b)})},a.listen=function(){osc.listenToTransport(this,chrome.serial,"connectionId")},a.sendRaw=function(a){if(this.connectionId){var b=this;chrome.serial.send(this.connectionId,a.buffer,function(a,c){c&&b.emit("error",c+". Total bytes sent: "+a)})}},a.close=function(){if(this.connectionId){var a=this;chrome.serial.disconnect(this.connectionId,function(b){b&&a.emit("close")})}},osc.UDPPort=function(a){osc.Port.call(this,a);var b=this.options;b.localAddress=b.localAddress||"127.0.0.1",b.localPort=void 0!==b.localPort?b.localPort:57121,this.on("open",this.listen.bind(this))},a=osc.UDPPort.prototype=Object.create(osc.Port.prototype),a.constructor=osc.UDPPort,a.open=function(){var a=this.options,b={persistent:a.persistent,name:a.name,bufferSize:a.bufferSize},c=this;chrome.sockets.udp.create(b,function(a){c.socketId=a.socketId,c.bindSocket()})},a.bindSocket=function(){var a=this,b=this.options;chrome.sockets.udp.bind(this.socketId,b.localAddress,b.localPort,function(b){return b>0?void osc.emitNetworkError(a,b):void a.emit("open",b)})},a.listen=function(){osc.listenToTransport(this,chrome.sockets.udp,"socketId")},a.sendRaw=function(a,b,c){if(this.socketId){var d=this.options,e=this;b=b||d.remoteAddress,c=void 0!==c?c:d.remotePort,chrome.sockets.udp.send(this.socketId,a.buffer,b,c,function(a){a||e.emit("error","There was an unknown error while trying to send a UDP message. Have you declared the appropriate udp send permissions in your application's manifest file?"),a.resultCode>0&&osc.emitNetworkError(e,a.resultCode)})}},a.close=function(){if(this.socketId){var a=this;chrome.sockets.udp.close(this.socketId,function(){a.emit("close")})}}}(); |
110
Gruntfile.js
@@ -6,2 +6,30 @@ /*global module*/ | ||
var files = { | ||
moduleDeps: [ | ||
"bower_components/slip.js/src/slip.js", | ||
"bower_components/eventEmitter/EventEmitter.js" | ||
], | ||
osc: [ | ||
"src/osc.js" | ||
], | ||
oscWeb: [ | ||
"src/osc-transports.js", | ||
"src/platforms/osc-browser.js" | ||
], | ||
oscChrome: [ | ||
"src/platforms/osc-chromeapp.js" | ||
], | ||
moduleHeader: [ | ||
"build-support/js/module-header.js" | ||
], | ||
moduleFooter: [ | ||
"build-support/js/module-footer.js" | ||
] | ||
}; | ||
grunt.initConfig({ | ||
@@ -11,3 +39,3 @@ pkg: grunt.file.readJSON("package.json"), | ||
jshint: { | ||
all: ["src/*.js", "tests/**/*.js"], | ||
all: ["src/*.js", "tests/**/*.js", "!**/third-party/**"], | ||
options: { | ||
@@ -18,49 +46,52 @@ jshintrc: true | ||
uglify: { | ||
concat: { | ||
options: { | ||
separator: ";", | ||
banner: "<%= oscjs.banners.short %>" | ||
}, | ||
dist: { | ||
files: { | ||
"dist/osc.min.js": ["src/osc.js"], | ||
"dist/osc-chromeapp.min.js": [ | ||
"src/osc.js", | ||
"bower_components/slip.js/src/slip.js", | ||
"bower_components/eventEmitter/EventEmitter.js", | ||
"src/osc-transports.js", | ||
"src/platforms/osc-browser.js", | ||
"src/platforms/osc-chromeapp.js" | ||
], | ||
"dist/osc-browser.min.js": [ | ||
"src/osc.js", | ||
"bower_components/slip.js/src/slip.js", | ||
"bower_components/eventEmitter/EventEmitter.js", | ||
"src/osc-transports.js", | ||
"src/platforms/osc-browser.js" | ||
] | ||
} | ||
base: { | ||
src: [].concat(files.osc), | ||
dest: "dist/<%= pkg.name %>.js" | ||
}, | ||
browser: { | ||
src: [].concat(files.osc, files.moduleDeps, files.oscWeb), | ||
dest: "dist/<%= pkg.name %>-browser.js" | ||
}, | ||
chromeapp: { | ||
src: [].concat(files.osc, files.moduleDeps, files.oscWeb, files.oscChrome), | ||
dest: "dist/<%= pkg.name %>-chromeapp.js" | ||
}, | ||
module: { | ||
src: [].concat(files.moduleHeader, files.osc, files.oscWeb, files.moduleFooter), | ||
dest: "dist/<%= pkg.name %>-module.js" | ||
} | ||
}, | ||
clean: { | ||
uglify: { | ||
options: { | ||
banner: "<%= oscjs.banners.short %>", | ||
beautify: { | ||
ascii_only: true | ||
} | ||
}, | ||
all: { | ||
src: ["dist/osc.min.js", "dist/osc-chromeapp.min.js"] | ||
files: [ | ||
{ | ||
expand: true, | ||
cwd: "dist/", | ||
src: ["*.js"], | ||
dest: "dist/", | ||
ext: ".min.js", | ||
} | ||
] | ||
} | ||
}, | ||
qunit: { | ||
all: ["tests/**/*.html"] | ||
}, | ||
"node-qunit": { | ||
clean: { | ||
all: { | ||
code: { | ||
path: "./src/platforms/osc-node.js", | ||
namespace: "osc" | ||
}, | ||
tests: [ | ||
"./tests/osc-tests.js", | ||
"./tests/node-buffer-tests.js", | ||
"./tests/node-transport-tests.js" | ||
] | ||
src: ["dist/"] | ||
} | ||
@@ -79,9 +110,8 @@ }, | ||
// Load relevant Grunt plugins. | ||
grunt.loadNpmTasks("grunt-contrib-concat"); | ||
grunt.loadNpmTasks("grunt-contrib-uglify"); | ||
grunt.loadNpmTasks("grunt-contrib-clean"); | ||
grunt.loadNpmTasks("grunt-contrib-jshint"); | ||
grunt.loadNpmTasks("grunt-contrib-qunit"); | ||
grunt.loadNpmTasks("grunt-node-qunit"); | ||
grunt.registerTask("default", ["clean", "jshint", "uglify", "qunit", "node-qunit"]); | ||
grunt.registerTask("default", ["clean", "jshint", "concat", "uglify"]); | ||
}; |
{ | ||
"name": "osc", | ||
"main": "src/platforms/osc-node.js", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "A JavaScript Open Sound Control (OSC) library that works in Node.js and the browser.", | ||
@@ -13,12 +13,3 @@ "author": "Colin Clark", | ||
"bugs": "https://github.com/colinbdclark/osc.js/issues", | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "http://opensource.org/licenses/MIT" | ||
}, | ||
{ | ||
"type": "GPL", | ||
"url": "http://opensource.org/licenses/GPL-3.0" | ||
} | ||
], | ||
"license": "(MIT OR GPL-2.0)", | ||
"keywords": [ | ||
@@ -37,9 +28,9 @@ "Open Sound Control", | ||
"devDependencies": { | ||
"qunit": "0.7.5", | ||
"infusion": "git://github.com/fluid-project/infusion.git", | ||
"jqUnit": "git://github.com/fluid-project/node-jqUnit.git", | ||
"grunt": "~0.4.2", | ||
"grunt-contrib-concat": "~0.3.0", | ||
"grunt-contrib-uglify": "~0.3.2", | ||
"grunt-contrib-clean": "~0.4.1", | ||
"grunt-contrib-jshint": "~0.8.0", | ||
"grunt-contrib-qunit": "~0.5.1", | ||
"grunt-node-qunit": "~2.0.2" | ||
"grunt-contrib-jshint": "~0.8.0" | ||
}, | ||
@@ -46,0 +37,0 @@ "dependencies": { |
@@ -1,29 +0,13 @@ | ||
/*global require, __dirname*/ | ||
/*jshint nomen: false, node: true*/ | ||
/*jshint node:true*/ | ||
var testRunner = require("qunit"); | ||
"use strict"; | ||
testRunner.setup({ | ||
log: { | ||
assertions: true, | ||
errors: true, | ||
tests: true, | ||
summary: true, | ||
globalSummary: true, | ||
testing: true | ||
} | ||
var testIncludes = [ | ||
"./osc-tests.js", | ||
"./node-buffer-tests.js", | ||
"./node-transport-tests.js" | ||
]; | ||
testIncludes.forEach(function (path) { | ||
require(path); | ||
}); | ||
testRunner.run([ | ||
{ | ||
code: { | ||
path: __dirname + "/../src/platforms/osc-node.js", | ||
namespace: "osc" | ||
}, | ||
tests: [ | ||
__dirname + "/osc-tests.js", | ||
__dirname + "/node-buffer-tests.js", | ||
__dirname + "/node-transport-tests.js" | ||
] | ||
} | ||
]); |
@@ -1,44 +0,48 @@ | ||
/*global QUnit, osc, Buffer, test, deepEqual, ok*/ | ||
/*global Buffer, require*/ | ||
/*jshint node:true*/ | ||
(function () { | ||
"use strict"; | ||
"use strict"; | ||
QUnit.module("Node.js buffer tests"); | ||
var fluid = require("infusion"), | ||
jqUnit = fluid.require("jqUnit"), | ||
osc = require("../src/platforms/osc-node.js"); | ||
// "/oscillator/4/frequency" | ",f" | 440 | ||
var oscMessageBuffer = new Buffer([ | ||
0x2f, 0x6f, 0x73, 0x63, | ||
0x69, 0x6c, 0x6c, 0x61, | ||
0x74, 0x6f, 0x72, 0x2f, | ||
0x34, 0x2f, 0x66, 0x72, | ||
0x65, 0x71, 0x75, 0x65, | ||
0x6e, 0x63, 0x79, 0, | ||
0x2c, 0x66, 0, 0, | ||
0x43, 0xdc, 0, 0 | ||
]); | ||
var QUnit = fluid.registerNamespace("QUnit"); | ||
var decodedMessage = { | ||
address: "/oscillator/4/frequency", | ||
args: 440 | ||
}; | ||
jqUnit.module("Node.js buffer tests"); | ||
test("Read from a Node.js buffer", function () { | ||
var actual = osc.readMessage(oscMessageBuffer); | ||
deepEqual(actual, decodedMessage, "A message specified as a Node.js buffer should be read correctly."); | ||
}); | ||
// "/oscillator/4/frequency" | ",f" | 440 | ||
var oscMessageBuffer = new Buffer([ | ||
0x2f, 0x6f, 0x73, 0x63, | ||
0x69, 0x6c, 0x6c, 0x61, | ||
0x74, 0x6f, 0x72, 0x2f, | ||
0x34, 0x2f, 0x66, 0x72, | ||
0x65, 0x71, 0x75, 0x65, | ||
0x6e, 0x63, 0x79, 0, | ||
0x2c, 0x66, 0, 0, | ||
0x43, 0xdc, 0, 0 | ||
]); | ||
test("Write to a Node.js buffer", function () { | ||
var actual = osc.writePacket({ | ||
timeTag: osc.timeTag(0), | ||
packets: [ | ||
{ | ||
address: "/oscillator/4/frequency", | ||
args: 440 | ||
} | ||
] | ||
}); | ||
var decodedMessage = { | ||
address: "/oscillator/4/frequency", | ||
args: 440 | ||
}; | ||
ok(actual instanceof Buffer, "Writing a packet should produce a Node.js Buffer object."); | ||
jqUnit.test("Read from a Node.js buffer", function () { | ||
var actual = osc.readMessage(oscMessageBuffer); | ||
QUnit.deepEqual(actual, decodedMessage, "A message specified as a Node.js buffer should be read correctly."); | ||
}); | ||
jqUnit.test("Write to a Node.js buffer", function () { | ||
var actual = osc.writePacket({ | ||
timeTag: osc.timeTag(0), | ||
packets: [ | ||
{ | ||
address: "/oscillator/4/frequency", | ||
args: 440 | ||
} | ||
] | ||
}); | ||
}()); | ||
QUnit.ok(actual instanceof Buffer, "Writing a packet should produce a Node.js Buffer object."); | ||
}); |
@@ -1,2 +0,2 @@ | ||
/*global console, require, QUnit, osc, asyncTest, ok, equal, deepEqual, start*/ | ||
/*global require*/ | ||
/*jshint node:true*/ | ||
@@ -6,4 +6,10 @@ | ||
QUnit.module("Node.js transport tests"); | ||
var fluid = require("infusion"), | ||
jqUnit = fluid.require("jqUnit"), | ||
osc = require("../src/platforms/osc-node.js"); | ||
var QUnit = fluid.registerNamespace("QUnit"); | ||
jqUnit.module("Node.js transport tests"); | ||
var testMessage = { | ||
@@ -26,3 +32,5 @@ address: "/test/freq", | ||
if (onMessage) { | ||
oscUDP.on("message", onMessage); | ||
oscUDP.on("message", function (msg) { | ||
onMessage(msg, oscUDP); | ||
}); | ||
} | ||
@@ -35,7 +43,8 @@ | ||
asyncTest("Send a message via a UDP socket", function () { | ||
jqUnit.asyncTest("Send a message via a UDP socket", function () { | ||
var oscUDP = createUDPServer(function (msg) { | ||
deepEqual(msg, testMessage, | ||
QUnit.deepEqual(msg, testMessage, | ||
"The message should have been sent to the web socket."); | ||
start(); | ||
oscUDP.close(); | ||
jqUnit.start(); | ||
}); | ||
@@ -48,3 +57,3 @@ | ||
asyncTest("Read from a UDP socket with metadata: true", function () { | ||
jqUnit.asyncTest("Read from a UDP socket with metadata: true", function () { | ||
var expected = { | ||
@@ -60,13 +69,14 @@ address: "/sl/1/down", | ||
var udpListener = function (msg) { | ||
equal(msg.address, expected.address); | ||
ok(Object.prototype.toString.call(msg.args) === "[object Array]", | ||
var udpListener = function (msg, udpPort) { | ||
QUnit.equal(msg.address, expected.address); | ||
QUnit.ok(Object.prototype.toString.call(msg.args) === "[object Array]", | ||
"The message arguments should be in an array."); | ||
equal(msg.args.length, 1, "There should only be one argument."); | ||
equal(msg.args[0].type, expected.args[0].type, | ||
QUnit.equal(msg.args.length, 1, "There should only be one argument."); | ||
QUnit.equal(msg.args[0].type, expected.args[0].type, | ||
"Type metadata should have been included."); | ||
equal(typeof msg.args[0].value, "number", | ||
QUnit.equal(typeof msg.args[0].value, "number", | ||
"The argument type should be a number."); | ||
start(); | ||
udpPort.close(); | ||
jqUnit.start(); | ||
}; | ||
@@ -124,3 +134,3 @@ | ||
function checkMessageReceived(oscMessage, wss, wsc, assertMessage) { | ||
deepEqual(oscMessage, testMessage, assertMessage); | ||
QUnit.deepEqual(oscMessage, testMessage, assertMessage); | ||
@@ -130,9 +140,9 @@ wss.close(); | ||
start(); | ||
jqUnit.start(); | ||
} | ||
asyncTest("Send OSC messages both directions via a Web Socket", function () { | ||
jqUnit.asyncTest("Send OSC messages both directions via a Web Socket", function () { | ||
var wss = createWSServer(function (oscServerPort) { | ||
oscServerPort.on("message", function (oscMessage) { | ||
deepEqual(oscMessage, testMessage, | ||
QUnit.deepEqual(oscMessage, testMessage, | ||
"The message should have been sent to the web socket server."); | ||
@@ -155,3 +165,3 @@ oscServerPort.send(testMessage); | ||
var udpPort = createUDPServer(), | ||
relay; | ||
relay; | ||
@@ -170,2 +180,3 @@ udpPort.on("ready", function () { | ||
"The message should have been proxied from UDP to the web socket."); | ||
udpPort.close(); | ||
}); | ||
@@ -175,7 +186,7 @@ }); | ||
asyncTest("Parsed message relaying between UDP and Web Sockets", function () { | ||
jqUnit.asyncTest("Parsed message relaying between UDP and Web Sockets", function () { | ||
testRelay(false); | ||
}); | ||
asyncTest("Raw relaying between UDP and Web Sockets", function () { | ||
jqUnit.asyncTest("Raw relaying between UDP and Web Sockets", function () { | ||
testRelay(true); | ||
@@ -191,3 +202,3 @@ }); | ||
asyncTest("Send an OSC message via TCP", function () { | ||
jqUnit.asyncTest("Send an OSC message via TCP", function () { | ||
var port = 57122; | ||
@@ -205,7 +216,7 @@ | ||
tcpServerPort.on("message", function (msg) { | ||
deepEqual(msg, testMessage, | ||
QUnit.deepEqual(msg, testMessage, | ||
"The message should have been sent to the TCP server."); | ||
tcpServer.close(); | ||
start(); | ||
jqUnit.start(); | ||
}); | ||
@@ -212,0 +223,0 @@ }); |
@@ -1,7 +0,12 @@ | ||
/*global QUnit, equal, deepEqual, osc, test, ok*/ | ||
/*global require*/ | ||
var fluid = fluid || require("infusion"), | ||
jqUnit = jqUnit || fluid.require("jqUnit"), | ||
osc = osc || require("../src/platforms/osc-node.js"); | ||
(function () { | ||
"use strict"; | ||
var QUnit = fluid.registerNamespace("QUnit"); | ||
/************* | ||
@@ -36,3 +41,3 @@ * Utilities * | ||
var arrayEqual = function (actual, expected, msg) { | ||
equal(actual.length, expected.length, "The array should be the expected length."); | ||
QUnit.equal(actual.length, expected.length, "The array should be the expected length."); | ||
for (var i = 0; i < actual.length; i++) { | ||
@@ -45,3 +50,3 @@ var actualVal = actual[i], | ||
} else { | ||
deepEqual(actualVal, expectedVal, msg); | ||
QUnit.deepEqual(actualVal, expectedVal, msg); | ||
} | ||
@@ -59,3 +64,3 @@ } | ||
equal(actualRounded, expectedRounded, msg + "\nUnrounded value was: " + expected); | ||
QUnit.equal(actualRounded, expectedRounded, msg + "\nUnrounded value was: " + expected); | ||
}; | ||
@@ -103,3 +108,3 @@ | ||
deepEqual(roundedActual, roundedExpected, msg = "\nUnrounded actual object was: " + | ||
QUnit.deepEqual(roundedActual, roundedExpected, msg = "\nUnrounded actual object was: " + | ||
JSON.stringify(roundedActual)); | ||
@@ -113,3 +118,3 @@ }; | ||
QUnit.module("Strings"); | ||
jqUnit.module("Strings"); | ||
@@ -121,3 +126,3 @@ var testReadString = function (testSpec) { | ||
test("readString " + testSpec.name, function () { | ||
jqUnit.test("readString " + testSpec.name, function () { | ||
var expected = testSpec.rawString, | ||
@@ -127,4 +132,4 @@ dv = stringToDataView(testSpec.paddedString), | ||
equal(actual, expected, "The string should have been read correctly."); | ||
equal(offsetState.idx, testSpec.paddedString.length, | ||
QUnit.equal(actual, expected, "The string should have been read correctly."); | ||
QUnit.equal(offsetState.idx, testSpec.paddedString.length, | ||
"The offset state should correctly reflect the null padding of the OSC string."); | ||
@@ -137,3 +142,3 @@ }); | ||
var testWriteString = function (testSpec) { | ||
test("writeString " + testSpec.name, function () { | ||
jqUnit.test("writeString " + testSpec.name, function () { | ||
var expectedDV = stringToDataView(testSpec.paddedString), | ||
@@ -145,3 +150,3 @@ expected = new Uint8Array(expectedDV.buffer), | ||
arrayEqual(actual, expected, "The string should have been written correctly."); | ||
ok(actualBuf instanceof Uint8Array, "The returned value should be a Uint8Array."); | ||
QUnit.ok(actualBuf instanceof Uint8Array, "The returned value should be a Uint8Array."); | ||
}); | ||
@@ -178,3 +183,3 @@ }; | ||
QUnit.module("Numbers"); | ||
jqUnit.module("Numbers"); | ||
@@ -205,3 +210,3 @@ var typeTesters = { | ||
equalRoundedTo(actual, expected, 5, "The correct value should have been read."); | ||
equal(offsetState.idx, expectedOffsetIdx, "The offset state should have been updated appropriately."); | ||
QUnit.equal(offsetState.idx, expectedOffsetIdx, "The offset state should have been updated appropriately."); | ||
}; | ||
@@ -223,3 +228,3 @@ | ||
var spec = specsForType[i]; | ||
test(spec.name, makeReadPrimitiveTester(type, spec)); | ||
jqUnit.test(spec.name, makeReadPrimitiveTester(type, spec)); | ||
} | ||
@@ -277,3 +282,3 @@ } | ||
var testWritePrimitive = function (testSpec) { | ||
test(testSpec.writer + " " + testSpec.name, function () { | ||
jqUnit.test(testSpec.writer + " " + testSpec.name, function () { | ||
var expected = testSpec.expected, | ||
@@ -345,3 +350,3 @@ outBuf = new ArrayBuffer(expected.buffer.byteLength), | ||
QUnit.module("Blobs"); | ||
jqUnit.module("Blobs"); | ||
@@ -360,3 +365,3 @@ var oscBlobOctets = [ | ||
test("readBlob", function () { | ||
jqUnit.test("readBlob", function () { | ||
var dv = new DataView(oscExtraBlob.buffer); | ||
@@ -372,8 +377,8 @@ var expected = rawData; | ||
arrayEqual(actual, expected, "The blob should be returned as-is."); | ||
ok(actual instanceof Uint8Array, "The blob should be returned as a Uint8Array."); | ||
equal(offsetState.idx, 8, "The offset state should have been updated correctly."); | ||
QUnit.ok(actual instanceof Uint8Array, "The blob should be returned as a Uint8Array."); | ||
QUnit.equal(offsetState.idx, 8, "The offset state should have been updated correctly."); | ||
}); | ||
test("writeBlob", function () { | ||
jqUnit.test("writeBlob", function () { | ||
var expected = oscBlob, | ||
@@ -384,3 +389,3 @@ actual = osc.writeBlob(rawData); | ||
"The data should have been packed into a correctly-formatted OSC blob."); | ||
ok(actual instanceof Uint8Array, "The written blob should be a Uint8Array"); | ||
QUnit.ok(actual instanceof Uint8Array, "The written blob should be a Uint8Array"); | ||
}); | ||
@@ -393,3 +398,3 @@ | ||
QUnit.module("Time Tags"); | ||
jqUnit.module("Time Tags"); | ||
@@ -400,8 +405,8 @@ var equalWithinTolerance = function (actual, expected, tolerance, msg) { | ||
ok(actual <= max, "The value should be no greater than " + tolerance + ". " + msg); | ||
ok(actual >= min, "The value should be no less than " + tolerance + ". " + msg); | ||
QUnit.ok(actual <= max, "The value should be no greater than " + tolerance + ". " + msg); | ||
QUnit.ok(actual >= min, "The value should be no less than " + tolerance + ". " + msg); | ||
}; | ||
var testReadTimeTag = function (testSpec) { | ||
test("Read time tag " + testSpec.name, function () { | ||
jqUnit.test("Read time tag " + testSpec.name, function () { | ||
var expected = testSpec.timeTag, | ||
@@ -419,5 +424,5 @@ dv = new DataView(testSpec.timeTagBytes.buffer); | ||
"ms of expected. Difference was: " + (actual.native - expected.native) + "ms."); | ||
deepEqual(actual.raw, expected.raw, "The raw time should match identically."); | ||
QUnit.deepEqual(actual.raw, expected.raw, "The raw time should match identically."); | ||
} else { | ||
deepEqual(actual, expected, "The date should have be read correctly."); | ||
QUnit.deepEqual(actual, expected, "The date should have be read correctly."); | ||
} | ||
@@ -429,3 +434,3 @@ | ||
var testWriteTimeTag = function (testSpec) { | ||
test("Write time tag " + testSpec.name, function () { | ||
jqUnit.test("Write time tag " + testSpec.name, function () { | ||
var expected = testSpec.timeTagBytes, | ||
@@ -487,3 +492,3 @@ actual = osc.writeTimeTag(testSpec.timeTag); | ||
test("Write native-only time tag.", function () { | ||
jqUnit.test("Write native-only time tag.", function () { | ||
var testSpec = timeTagTestSpecs[1], | ||
@@ -509,10 +514,10 @@ expected = testSpec.timeTagBytes, | ||
equal(actual.raw[0], expected[0], "The generated timestamp should be accurate to the second."); | ||
ok(actual.raw[1] <= max, "The generated timestamp should be no greater than " + tolerance + | ||
QUnit.equal(actual.raw[0], expected[0], "The generated timestamp should be accurate to the second."); | ||
QUnit.ok(actual.raw[1] <= max, "The generated timestamp should be no greater than " + tolerance + | ||
" NTP fractions of a second from expected."); | ||
ok(actual.raw[1] >= min, "The generated timestamp should be no less than " + tolerance + | ||
QUnit.ok(actual.raw[1] >= min, "The generated timestamp should be no less than " + tolerance + | ||
" NTP fractions of a second from expected."); | ||
}; | ||
test("osc.timeTag now", function () { | ||
jqUnit.test("osc.timeTag now", function () { | ||
var actual = osc.timeTag(); | ||
@@ -525,3 +530,3 @@ testTimeTag(actual, Date.now()); | ||
test("osc.timeTag future", function () { | ||
jqUnit.test("osc.timeTag future", function () { | ||
var actual = osc.timeTag(10.5), | ||
@@ -537,3 +542,3 @@ expected = Date.now() + 10500; | ||
test("osc.timeTag past", function () { | ||
jqUnit.test("osc.timeTag past", function () { | ||
var actual = osc.timeTag(-1000), | ||
@@ -552,5 +557,5 @@ expected = Date.now() - 1000000; | ||
QUnit.module("Type-Only Arguments"); | ||
jqUnit.module("Type-Only Arguments"); | ||
test("Type-only arguments", function () { | ||
jqUnit.test("Type-only arguments", function () { | ||
var offsetState = { | ||
@@ -561,16 +566,16 @@ idx: 27 | ||
var bool = osc.readTrue(); | ||
equal(bool, true, "readTrue() should return a true value"); | ||
equal(offsetState.idx, 27, "The offset state should not have been changed."); | ||
QUnit.equal(bool, true, "readTrue() should return a true value"); | ||
QUnit.equal(offsetState.idx, 27, "The offset state should not have been changed."); | ||
bool = osc.readFalse(); | ||
equal(bool, false, "readFalse() should return false value"); | ||
equal(offsetState.idx, 27, "The offset state should not have been changed."); | ||
QUnit.equal(bool, false, "readFalse() should return false value"); | ||
QUnit.equal(offsetState.idx, 27, "The offset state should not have been changed."); | ||
var nully = osc.readNull(); | ||
equal(nully, null, "readNull() should return null."); | ||
equal(offsetState.idx, 27, "The offset state should not have been changed."); | ||
QUnit.equal(nully, null, "readNull() should return null."); | ||
QUnit.equal(offsetState.idx, 27, "The offset state should not have been changed."); | ||
var imp = osc.readImpulse(); | ||
equal(imp, 1.0, "readImpulse() should return 1.0."); | ||
equal(offsetState.idx, 27, "The offset state should not have been changed."); | ||
QUnit.equal(imp, 1.0, "readImpulse() should return 1.0."); | ||
QUnit.equal(offsetState.idx, 27, "The offset state should not have been changed."); | ||
}); | ||
@@ -583,3 +588,3 @@ | ||
QUnit.module("readArguments()"); | ||
jqUnit.module("readArguments()"); | ||
@@ -589,3 +594,3 @@ var testArguments = function (testSpec) { | ||
//testSpec.rawArgBuffer, testSpec.expected, testSpec.roundToDecimals | ||
test(testSpec.name, function () { | ||
jqUnit.test(testSpec.name, function () { | ||
var offsetState = { | ||
@@ -778,3 +783,3 @@ idx: 0 | ||
QUnit.module("Messages"); | ||
jqUnit.module("Messages"); | ||
@@ -786,3 +791,3 @@ var testReadMessage = function (testSpec) { | ||
test("readMessage " + testSpec.name, function () { | ||
jqUnit.test("readMessage " + testSpec.name, function () { | ||
var expected = testSpec.message, | ||
@@ -796,3 +801,3 @@ dv = new DataView(testSpec.oscMessageBuffer.buffer), | ||
} else { | ||
deepEqual(actual, expected, msg); | ||
QUnit.deepEqual(actual, expected, msg); | ||
} | ||
@@ -803,3 +808,3 @@ }); | ||
var testWriteMessage = function (testSpec) { | ||
test("writeMessage " + testSpec.name, function () { | ||
jqUnit.test("writeMessage " + testSpec.name, function () { | ||
var expected = testSpec.oscMessageBuffer, | ||
@@ -898,3 +903,3 @@ actual = osc.writeMessage(testSpec.message, testSpec.options); | ||
test("gh-17", function () { | ||
jqUnit.test("gh-17", function () { | ||
var msg = { | ||
@@ -922,6 +927,6 @@ address: "/sl/1/down", | ||
QUnit.module("Bundles"); | ||
jqUnit.module("Bundles"); | ||
var testReadBundle = function (testSpec) { | ||
test("readBundle " + testSpec.name, function () { | ||
jqUnit.test("readBundle " + testSpec.name, function () { | ||
var expected = testSpec.bundle, | ||
@@ -936,3 +941,3 @@ dv = new DataView(testSpec.bytes.buffer), | ||
"The bundle should have been read correctly."); | ||
equal(offsetState.idx, dv.byteLength, | ||
QUnit.equal(offsetState.idx, dv.byteLength, | ||
"The offset state should have been adjusted correctly."); | ||
@@ -943,3 +948,3 @@ }); | ||
var testWriteBundle = function (testSpec) { | ||
test("writeBundle " + testSpec.name, function () { | ||
jqUnit.test("writeBundle " + testSpec.name, function () { | ||
var expected = testSpec.bytes, | ||
@@ -946,0 +951,0 @@ actual = osc.writeBundle(testSpec.bundle, testSpec.options); |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
spdx disjunction for an artifact's license information
Licensespdx disjunction for an artifact's license information
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
spdx disjunction for an artifact's license information
Licensespdx disjunction for an artifact's license information
Found 1 instance in 1 package
1060240
45
25059
90
4
4
7