From 1b932a27bb65efc68d99e18a8b5cd80876193f1b Mon Sep 17 00:00:00 2001 From: Jesse Friedman Date: Fri, 14 Jul 2017 22:47:55 -0400 Subject: [PATCH 1/6] Changing osc.readString to use Buffer.toString or TextDecoder if available Otherwise, it will use charCodeAt as before, but it applies it to the array in chunks so as not to hit the argument limit. --- src/osc.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/osc.js b/src/osc.js index 8313d8c..3690df6 100644 --- a/src/osc.js +++ b/src/osc.js @@ -163,7 +163,31 @@ var osc = osc || {}; idx = (idx + 3) & ~0x03; offsetState.idx = idx; - return String.fromCharCode.apply(null, charCodes); + if (global.Buffer) { + // Check for Buffer API (Node/Electron) + if (Buffer.from) { + // new Buffer() is now deprecated, so we use Buffer.from if available + return Buffer.from(charCodes).toString('utf-8'); + } else { + return new Buffer(charCodes).toString('utf-8'); + } + } else if (global.TextDecoder) { + // Check for TextDecoder API (Browser/WebKit-based) + return new TextDecoder('utf-8').decode(charCodes); + } else { + // If no Buffer or TextDecoder, resort to fromCharCode + // This does not properly decode multi-byte Unicode characters. + + var str = ''; + var sliceSize = 10000; + + // Processing the array in chunks so as not to exceed argument + // limit, see https://bugs.webkit.org/show_bug.cgi?id=80797 + for (var i = 0; i < charCodes.length; i += sliceSize) { + str += String.fromCharCode.apply(null, charCodes.slice(i, i + sliceSize)); + } + return str; + } }; /** From 71c5974323986354572ae2e1929c62b4eeec162d Mon Sep 17 00:00:00 2001 From: Jesse Friedman Date: Fri, 14 Jul 2017 23:22:18 -0400 Subject: [PATCH 2/6] Fixing style --- src/osc.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/osc.js b/src/osc.js index 3690df6..bcaf10e 100644 --- a/src/osc.js +++ b/src/osc.js @@ -163,22 +163,22 @@ var osc = osc || {}; idx = (idx + 3) & ~0x03; offsetState.idx = idx; - if (global.Buffer) { + if (Buffer) { // Check for Buffer API (Node/Electron) if (Buffer.from) { // new Buffer() is now deprecated, so we use Buffer.from if available - return Buffer.from(charCodes).toString('utf-8'); + return Buffer.from(charCodes).toString("utf-8"); } else { - return new Buffer(charCodes).toString('utf-8'); + return new Buffer(charCodes).toString("utf-8"); } - } else if (global.TextDecoder) { + } else if (TextDecoder) { // Check for TextDecoder API (Browser/WebKit-based) - return new TextDecoder('utf-8').decode(charCodes); + return new TextDecoder("utf-8").decode(charCodes); } else { // If no Buffer or TextDecoder, resort to fromCharCode // This does not properly decode multi-byte Unicode characters. - var str = ''; + var str = ""; var sliceSize = 10000; // Processing the array in chunks so as not to exceed argument From 5dd518e6b527fd838b7322952daf3f781eae5e3e Mon Sep 17 00:00:00 2001 From: Jesse Friedman Date: Fri, 14 Jul 2017 23:39:20 -0400 Subject: [PATCH 3/6] Changing checks for Buffer/TextDecoder --- src/osc.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/osc.js b/src/osc.js index bcaf10e..b0daa4b 100644 --- a/src/osc.js +++ b/src/osc.js @@ -163,7 +163,7 @@ var osc = osc || {}; idx = (idx + 3) & ~0x03; offsetState.idx = idx; - if (Buffer) { + if ((typeof global !== "undefined" ? global : window).hasOwnProperty("Buffer")) { // jshint ignore:line // Check for Buffer API (Node/Electron) if (Buffer.from) { // new Buffer() is now deprecated, so we use Buffer.from if available @@ -171,9 +171,9 @@ var osc = osc || {}; } else { return new Buffer(charCodes).toString("utf-8"); } - } else if (TextDecoder) { + } else if ((typeof global !== "undefined" ? global : window).hasOwnProperty("TextDecoder")) { // jshint ignore:line // Check for TextDecoder API (Browser/WebKit-based) - return new TextDecoder("utf-8").decode(charCodes); + return new TextDecoder("utf-8").decode(new Int8Array(charCodes)); } else { // If no Buffer or TextDecoder, resort to fromCharCode // This does not properly decode multi-byte Unicode characters. From 75c9224945205b9ef351bb34220086a5e92c3f88 Mon Sep 17 00:00:00 2001 From: Jesse Friedman Date: Sat, 15 Jul 2017 00:41:19 -0400 Subject: [PATCH 4/6] Adding tests --- tests/osc-tests.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/osc-tests.js b/tests/osc-tests.js index 8811d4f..7acbd33 100644 --- a/tests/osc-tests.js +++ b/tests/osc-tests.js @@ -247,6 +247,18 @@ var fluid = fluid || require("infusion"), }); }); + QUnit.test("readString very long string argument", function () { + var expectedChars = new Array(400000); + for (var i = 0; i < expectedChars.length; i++) { + expectedChars[i] = "A"; + } + var expected = expectedChars.join(""), + dv = oscjsTests.stringToDataView(expected), + actual = osc.readString(dv, {idx: 0}); + + QUnit.equal(actual, expected, "The string should have been read correctly."); + }); + /*********** * Numbers * From c6f882362a7d9e9d17ac4e10e7e0d115322be41f Mon Sep 17 00:00:00 2001 From: Jesse Friedman Date: Sat, 15 Jul 2017 00:41:54 -0400 Subject: [PATCH 5/6] Updating dist files --- dist/osc-browser.js | 26 +++++++++++++++++++++++++- dist/osc-browser.min.js | 2 +- dist/osc-chromeapp.js | 26 +++++++++++++++++++++++++- dist/osc-chromeapp.min.js | 2 +- dist/osc-module.js | 26 +++++++++++++++++++++++++- dist/osc-module.min.js | 2 +- dist/osc.js | 26 +++++++++++++++++++++++++- dist/osc.min.js | 2 +- 8 files changed, 104 insertions(+), 8 deletions(-) diff --git a/dist/osc-browser.js b/dist/osc-browser.js index ed90fcc..3f8a275 100644 --- a/dist/osc-browser.js +++ b/dist/osc-browser.js @@ -165,7 +165,31 @@ var osc = osc || {}; idx = (idx + 3) & ~0x03; offsetState.idx = idx; - return String.fromCharCode.apply(null, charCodes); + if ((typeof global !== "undefined" ? global : window).hasOwnProperty("Buffer")) { // jshint ignore:line + // Check for Buffer API (Node/Electron) + if (Buffer.from) { + // new Buffer() is now deprecated, so we use Buffer.from if available + return Buffer.from(charCodes).toString("utf-8"); + } else { + return new Buffer(charCodes).toString("utf-8"); + } + } else if ((typeof global !== "undefined" ? global : window).hasOwnProperty("TextDecoder")) { // jshint ignore:line + // Check for TextDecoder API (Browser/WebKit-based) + return new TextDecoder("utf-8").decode(new Int8Array(charCodes)); + } else { + // If no Buffer or TextDecoder, resort to fromCharCode + // This does not properly decode multi-byte Unicode characters. + + var str = ""; + var sliceSize = 10000; + + // Processing the array in chunks so as not to exceed argument + // limit, see https://bugs.webkit.org/show_bug.cgi?id=80797 + for (var i = 0; i < charCodes.length; i += sliceSize) { + str += String.fromCharCode.apply(null, charCodes.slice(i, i + sliceSize)); + } + return str; + } }; /** diff --git a/dist/osc-browser.min.js b/dist/osc-browser.min.js index 75ee1b0..cd7da6d 100644 --- a/dist/osc-browser.min.js +++ b/dist/osc-browser.min.js @@ -1,3 +1,3 @@ /*! osc.js 2.2.0, Copyright 2017 Colin Clark | github.com/colinbdclark/osc.js */ -var osc=osc||{};!function(){"use strict";osc.SECS_70YRS=2208988800,osc.TWO_32=4294967296,osc.defaults={metadata:!1,unpackSingleArgs:!0},osc.isCommonJS=!("undefined"==typeof module||!module.exports),osc.isNode=osc.isCommonJS&&"undefined"==typeof window,osc.isElectron=!("undefined"==typeof process||!process.versions||!process.versions.electron),osc.isBufferEnv=osc.isNode||osc.isElectron,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};var a="undefined"!=typeof dcodeIO?dcodeIO.Long:"undefined"!=typeof a?a:osc.isNode?require("long"):void 0;osc.dataView=function(a,b,c){return a.buffer?new DataView(a.buffer,b,c):a instanceof ArrayBuffer?new DataView(a,b,c):new DataView(new Uint8Array(a),b,c)},osc.byteArray=function(a){if(a instanceof Uint8Array)return a;var b=a.buffer?a.buffer:a;if(!(b instanceof ArrayBuffer||"undefined"!=typeof b.length&&"string"!=typeof b))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.nativeBuffer=function(a){return osc.isBufferEnv?osc.isBuffer(a)?a:new Buffer(a.buffer?a:new Uint8Array(a)):osc.isTypedArrayView(a)?a:new Uint8Array(a)},osc.copyByteArray=function(a,b,c){if(osc.isTypedArrayView(a)&&osc.isTypedArrayView(b))b.set(a,c);else for(var d=void 0===c?0:c,e=Math.min(b.length-c,a.length),f=0,g=d;f1){var i=Math.floor(h),j=h-i;f+=i,h=j}var k=d+f+osc.SECS_70YRS,l=Math.round(osc.TWO_32*h);return{raw:[k,l]}},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>>=0,(f=0<=a&&a<256)&&(d=i[a])?d:(c=e(a,(0|a)<0?-1:0,!0),f&&(i[a]=c),c)):(a|=0,(f=-128<=a&&a<128)&&(d=h[a])?d:(c=e(a,a<0?-1:0,!1),f&&(h[a]=c),c))}function d(a,b){if(isNaN(a)||!isFinite(a))return b?q:p;if(b){if(a<0)return q;if(a>=m)return v}else{if(a<=-n)return w;if(a+1>=n)return u}return a<0?d(-a,b).neg():e(a%l|0,a/l|0,b)}function e(b,c,d){return new a(b,c,d)}function f(a,b,c){if(0===a.length)throw Error("empty string");if("NaN"===a||"Infinity"===a||"+Infinity"===a||"-Infinity"===a)return p;if("number"==typeof b?(c=b,b=!1):b=!!b,c=c||10,c<2||360)throw Error("interior hyphen");if(0===e)return f(a.substring(1),b,c).neg();for(var g=d(j(c,8)),h=p,i=0;i>>0:this.low},x.toNumber=function(){return this.unsigned?(this.high>>>0)*l+(this.low>>>0):this.high*l+(this.low>>>0)},x.toString=function(a){if(a=a||10,a<2||36>>0,l=k.toString(a);if(g=i,g.isZero())return l+h;for(;l.length<6;)l="0"+l;h=""+l+h}},x.getHighBits=function(){return this.high},x.getHighBitsUnsigned=function(){return this.high>>>0},x.getLowBits=function(){return this.low},x.getLowBitsUnsigned=function(){return this.low>>>0},x.getNumBitsAbs=function(){if(this.isNegative())return this.eq(w)?64:this.neg().getNumBitsAbs();for(var a=0!=this.high?this.high:this.low,b=31;b>0&&0==(a&1<=0},x.isOdd=function(){return 1===(1&this.low)},x.isEven=function(){return 0===(1&this.low)},x.equals=function(a){return b(a)||(a=g(a)),(this.unsigned===a.unsigned||this.high>>>31!==1||a.high>>>31!==1)&&(this.high===a.high&&this.low===a.low)},x.eq=x.equals,x.notEquals=function(a){return!this.eq(a)},x.neq=x.notEquals,x.lessThan=function(a){return this.comp(a)<0},x.lt=x.lessThan,x.lessThanOrEqual=function(a){return this.comp(a)<=0},x.lte=x.lessThanOrEqual,x.greaterThan=function(a){return this.comp(a)>0},x.gt=x.greaterThan,x.greaterThanOrEqual=function(a){return this.comp(a)>=0},x.gte=x.greaterThanOrEqual,x.compare=function(a){if(b(a)||(a=g(a)),this.eq(a))return 0;var c=this.isNegative(),d=a.isNegative();return c&&!d?-1:!c&&d?1:this.unsigned?a.high>>>0>this.high>>>0||a.high===this.high&&a.low>>>0>this.low>>>0?-1:1:this.sub(a).isNegative()?-1:1},x.comp=x.compare,x.negate=function(){return!this.unsigned&&this.eq(w)?w:this.not().add(r)},x.neg=x.negate,x.add=function(a){b(a)||(a=g(a));var c=this.high>>>16,d=65535&this.high,f=this.low>>>16,h=65535&this.low,i=a.high>>>16,j=65535&a.high,k=a.low>>>16,l=65535&a.low,m=0,n=0,o=0,p=0;return p+=h+l,o+=p>>>16,p&=65535,o+=f+k,n+=o>>>16,o&=65535,n+=d+j,m+=n>>>16,n&=65535,m+=c+i,m&=65535,e(o<<16|p,m<<16|n,this.unsigned)},x.subtract=function(a){return b(a)||(a=g(a)),this.add(a.neg())},x.sub=x.subtract,x.multiply=function(a){if(this.isZero())return p;if(b(a)||(a=g(a)),a.isZero())return p;if(this.eq(w))return a.isOdd()?w:p;if(a.eq(w))return this.isOdd()?w:p;if(this.isNegative())return a.isNegative()?this.neg().mul(a.neg()):this.neg().mul(a).neg();if(a.isNegative())return this.mul(a.neg()).neg();if(this.lt(o)&&a.lt(o))return d(this.toNumber()*a.toNumber(),this.unsigned);var c=this.high>>>16,f=65535&this.high,h=this.low>>>16,i=65535&this.low,j=a.high>>>16,k=65535&a.high,l=a.low>>>16,m=65535&a.low,n=0,q=0,r=0,s=0;return s+=i*m,r+=s>>>16,s&=65535,r+=h*m,q+=r>>>16,r&=65535,r+=i*l,q+=r>>>16,r&=65535,q+=f*m,n+=q>>>16,q&=65535,q+=h*l,n+=q>>>16,q&=65535,q+=i*k,n+=q>>>16,q&=65535,n+=c*m+f*l+h*k+i*j,n&=65535,e(r<<16|s,n<<16|q,this.unsigned)},x.mul=x.multiply,x.divide=function(a){if(b(a)||(a=g(a)),a.isZero())throw Error("division by zero");if(this.isZero())return this.unsigned?q:p;var c,e,f;if(this.unsigned){if(a.unsigned||(a=a.toUnsigned()),a.gt(this))return q;if(a.gt(this.shru(1)))return s;f=q}else{if(this.eq(w)){if(a.eq(r)||a.eq(t))return w;if(a.eq(w))return r;var h=this.shr(1);return c=h.div(a).shl(1),c.eq(p)?a.isNegative()?r:t:(e=this.sub(a.mul(c)),f=c.add(e.div(a)))}if(a.eq(w))return this.unsigned?q:p;if(this.isNegative())return a.isNegative()?this.neg().div(a.neg()):this.neg().div(a).neg();if(a.isNegative())return this.div(a.neg()).neg();f=p}for(e=this;e.gte(a);){c=Math.max(1,Math.floor(e.toNumber()/a.toNumber()));for(var i=Math.ceil(Math.log(c)/Math.LN2),k=i<=48?1:j(2,i-48),l=d(c),m=l.mul(a);m.isNegative()||m.gt(e);)c-=k,l=d(c,this.unsigned),m=l.mul(a);l.isZero()&&(l=r),f=f.add(l),e=e.sub(m)}return f},x.div=x.divide,x.modulo=function(a){return b(a)||(a=g(a)),this.sub(this.div(a).mul(a))},x.mod=x.modulo,x.not=function(){return e(~this.low,~this.high,this.unsigned)},x.and=function(a){return b(a)||(a=g(a)),e(this.low&a.low,this.high&a.high,this.unsigned)},x.or=function(a){return b(a)||(a=g(a)),e(this.low|a.low,this.high|a.high,this.unsigned)},x.xor=function(a){return b(a)||(a=g(a)),e(this.low^a.low,this.high^a.high,this.unsigned)},x.shiftLeft=function(a){return b(a)&&(a=a.toInt()),0===(a&=63)?this:a<32?e(this.low<>>32-a,this.unsigned):e(0,this.low<>>a|this.high<<32-a,this.high>>a,this.unsigned):e(this.high>>a-32,this.high>=0?0:-1,this.unsigned)},x.shr=x.shiftRight,x.shiftRightUnsigned=function(a){if(b(a)&&(a=a.toInt()),a&=63,0===a)return this;var c=this.high;if(a<32){var d=this.low;return e(d>>>a|c<<32-a,c>>>a,this.unsigned)}return 32===a?e(c,0,this.unsigned):e(c>>>a-32,0,this.unsigned)},x.shru=x.shiftRightUnsigned,x.toSigned=function(){return this.unsigned?e(this.low,this.high,!1):this},x.toUnsigned=function(){return this.unsigned?this:e(this.low,this.high,!0)},x.toBytes=function(a){return a?this.toBytesLE():this.toBytesBE()},x.toBytesLE=function(){var a=this.high,b=this.low;return[255&b,b>>>8&255,b>>>16&255,b>>>24&255,255&a,a>>>8&255,a>>>16&255,a>>>24&255]},x.toBytesBE=function(){var a=this.high,b=this.low;return[a>>>24&255,a>>>16&255,a>>>8&255,255&a,b>>>24&255,b>>>16&255,b>>>8&255,255&b]},a}),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;ge.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;dthis.msgBuffer.length-1&&(this.msgBuffer=b.expandByteArray(this.msgBuffer)),this.msgBuffer[this.msgBufferIdx++]=a,this.escape=!1,this.msgBuffer.length1)&&(this.socket=new osc.WebSocket(this.options.url)),osc.WebSocketPort.setupSocketForBinary(this.socket);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,b)},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){return this.socket&&1===this.socket.readyState?void this.socket.send(a):void osc.fireClosedPortSendError(this)},a.close=function(a,b){this.socket.close(a,b)},osc.WebSocketPort.setupSocketForBinary=function(a){a.binaryType=osc.isNode?"nodebuffer":"arraybuffer"}}(); \ No newline at end of file +var osc=osc||{};!function(){"use strict";osc.SECS_70YRS=2208988800,osc.TWO_32=4294967296,osc.defaults={metadata:!1,unpackSingleArgs:!0},osc.isCommonJS=!("undefined"==typeof module||!module.exports),osc.isNode=osc.isCommonJS&&"undefined"==typeof window,osc.isElectron=!("undefined"==typeof process||!process.versions||!process.versions.electron),osc.isBufferEnv=osc.isNode||osc.isElectron,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};var a="undefined"!=typeof dcodeIO?dcodeIO.Long:"undefined"!=typeof a?a:osc.isNode?require("long"):void 0;osc.dataView=function(a,b,c){return a.buffer?new DataView(a.buffer,b,c):a instanceof ArrayBuffer?new DataView(a,b,c):new DataView(new Uint8Array(a),b,c)},osc.byteArray=function(a){if(a instanceof Uint8Array)return a;var b=a.buffer?a.buffer:a;if(!(b instanceof ArrayBuffer||"undefined"!=typeof b.length&&"string"!=typeof b))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.nativeBuffer=function(a){return osc.isBufferEnv?osc.isBuffer(a)?a:new Buffer(a.buffer?a:new Uint8Array(a)):osc.isTypedArrayView(a)?a:new Uint8Array(a)},osc.copyByteArray=function(a,b,c){if(osc.isTypedArrayView(a)&&osc.isTypedArrayView(b))b.set(a,c);else for(var d=void 0===c?0:c,e=Math.min(b.length-c,a.length),f=0,g=d;f1){var i=Math.floor(h),j=h-i;f+=i,h=j}var k=d+f+osc.SECS_70YRS,l=Math.round(osc.TWO_32*h);return{raw:[k,l]}},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>>=0,(f=0<=a&&a<256)&&(d=i[a])?d:(c=e(a,(0|a)<0?-1:0,!0),f&&(i[a]=c),c)):(a|=0,(f=-128<=a&&a<128)&&(d=h[a])?d:(c=e(a,a<0?-1:0,!1),f&&(h[a]=c),c))}function d(a,b){if(isNaN(a)||!isFinite(a))return b?q:p;if(b){if(a<0)return q;if(a>=m)return v}else{if(a<=-n)return w;if(a+1>=n)return u}return a<0?d(-a,b).neg():e(a%l|0,a/l|0,b)}function e(b,c,d){return new a(b,c,d)}function f(a,b,c){if(0===a.length)throw Error("empty string");if("NaN"===a||"Infinity"===a||"+Infinity"===a||"-Infinity"===a)return p;if("number"==typeof b?(c=b,b=!1):b=!!b,c=c||10,c<2||360)throw Error("interior hyphen");if(0===e)return f(a.substring(1),b,c).neg();for(var g=d(j(c,8)),h=p,i=0;i>>0:this.low},x.toNumber=function(){return this.unsigned?(this.high>>>0)*l+(this.low>>>0):this.high*l+(this.low>>>0)},x.toString=function(a){if(a=a||10,a<2||36>>0,l=k.toString(a);if(g=i,g.isZero())return l+h;for(;l.length<6;)l="0"+l;h=""+l+h}},x.getHighBits=function(){return this.high},x.getHighBitsUnsigned=function(){return this.high>>>0},x.getLowBits=function(){return this.low},x.getLowBitsUnsigned=function(){return this.low>>>0},x.getNumBitsAbs=function(){if(this.isNegative())return this.eq(w)?64:this.neg().getNumBitsAbs();for(var a=0!=this.high?this.high:this.low,b=31;b>0&&0==(a&1<=0},x.isOdd=function(){return 1===(1&this.low)},x.isEven=function(){return 0===(1&this.low)},x.equals=function(a){return b(a)||(a=g(a)),(this.unsigned===a.unsigned||this.high>>>31!==1||a.high>>>31!==1)&&(this.high===a.high&&this.low===a.low)},x.eq=x.equals,x.notEquals=function(a){return!this.eq(a)},x.neq=x.notEquals,x.lessThan=function(a){return this.comp(a)<0},x.lt=x.lessThan,x.lessThanOrEqual=function(a){return this.comp(a)<=0},x.lte=x.lessThanOrEqual,x.greaterThan=function(a){return this.comp(a)>0},x.gt=x.greaterThan,x.greaterThanOrEqual=function(a){return this.comp(a)>=0},x.gte=x.greaterThanOrEqual,x.compare=function(a){if(b(a)||(a=g(a)),this.eq(a))return 0;var c=this.isNegative(),d=a.isNegative();return c&&!d?-1:!c&&d?1:this.unsigned?a.high>>>0>this.high>>>0||a.high===this.high&&a.low>>>0>this.low>>>0?-1:1:this.sub(a).isNegative()?-1:1},x.comp=x.compare,x.negate=function(){return!this.unsigned&&this.eq(w)?w:this.not().add(r)},x.neg=x.negate,x.add=function(a){b(a)||(a=g(a));var c=this.high>>>16,d=65535&this.high,f=this.low>>>16,h=65535&this.low,i=a.high>>>16,j=65535&a.high,k=a.low>>>16,l=65535&a.low,m=0,n=0,o=0,p=0;return p+=h+l,o+=p>>>16,p&=65535,o+=f+k,n+=o>>>16,o&=65535,n+=d+j,m+=n>>>16,n&=65535,m+=c+i,m&=65535,e(o<<16|p,m<<16|n,this.unsigned)},x.subtract=function(a){return b(a)||(a=g(a)),this.add(a.neg())},x.sub=x.subtract,x.multiply=function(a){if(this.isZero())return p;if(b(a)||(a=g(a)),a.isZero())return p;if(this.eq(w))return a.isOdd()?w:p;if(a.eq(w))return this.isOdd()?w:p;if(this.isNegative())return a.isNegative()?this.neg().mul(a.neg()):this.neg().mul(a).neg();if(a.isNegative())return this.mul(a.neg()).neg();if(this.lt(o)&&a.lt(o))return d(this.toNumber()*a.toNumber(),this.unsigned);var c=this.high>>>16,f=65535&this.high,h=this.low>>>16,i=65535&this.low,j=a.high>>>16,k=65535&a.high,l=a.low>>>16,m=65535&a.low,n=0,q=0,r=0,s=0;return s+=i*m,r+=s>>>16,s&=65535,r+=h*m,q+=r>>>16,r&=65535,r+=i*l,q+=r>>>16,r&=65535,q+=f*m,n+=q>>>16,q&=65535,q+=h*l,n+=q>>>16,q&=65535,q+=i*k,n+=q>>>16,q&=65535,n+=c*m+f*l+h*k+i*j,n&=65535,e(r<<16|s,n<<16|q,this.unsigned)},x.mul=x.multiply,x.divide=function(a){if(b(a)||(a=g(a)),a.isZero())throw Error("division by zero");if(this.isZero())return this.unsigned?q:p;var c,e,f;if(this.unsigned){if(a.unsigned||(a=a.toUnsigned()),a.gt(this))return q;if(a.gt(this.shru(1)))return s;f=q}else{if(this.eq(w)){if(a.eq(r)||a.eq(t))return w;if(a.eq(w))return r;var h=this.shr(1);return c=h.div(a).shl(1),c.eq(p)?a.isNegative()?r:t:(e=this.sub(a.mul(c)),f=c.add(e.div(a)))}if(a.eq(w))return this.unsigned?q:p;if(this.isNegative())return a.isNegative()?this.neg().div(a.neg()):this.neg().div(a).neg();if(a.isNegative())return this.div(a.neg()).neg();f=p}for(e=this;e.gte(a);){c=Math.max(1,Math.floor(e.toNumber()/a.toNumber()));for(var i=Math.ceil(Math.log(c)/Math.LN2),k=i<=48?1:j(2,i-48),l=d(c),m=l.mul(a);m.isNegative()||m.gt(e);)c-=k,l=d(c,this.unsigned),m=l.mul(a);l.isZero()&&(l=r),f=f.add(l),e=e.sub(m)}return f},x.div=x.divide,x.modulo=function(a){return b(a)||(a=g(a)),this.sub(this.div(a).mul(a))},x.mod=x.modulo,x.not=function(){return e(~this.low,~this.high,this.unsigned)},x.and=function(a){return b(a)||(a=g(a)),e(this.low&a.low,this.high&a.high,this.unsigned)},x.or=function(a){return b(a)||(a=g(a)),e(this.low|a.low,this.high|a.high,this.unsigned)},x.xor=function(a){return b(a)||(a=g(a)),e(this.low^a.low,this.high^a.high,this.unsigned)},x.shiftLeft=function(a){return b(a)&&(a=a.toInt()),0===(a&=63)?this:a<32?e(this.low<>>32-a,this.unsigned):e(0,this.low<>>a|this.high<<32-a,this.high>>a,this.unsigned):e(this.high>>a-32,this.high>=0?0:-1,this.unsigned)},x.shr=x.shiftRight,x.shiftRightUnsigned=function(a){if(b(a)&&(a=a.toInt()),a&=63,0===a)return this;var c=this.high;if(a<32){var d=this.low;return e(d>>>a|c<<32-a,c>>>a,this.unsigned)}return 32===a?e(c,0,this.unsigned):e(c>>>a-32,0,this.unsigned)},x.shru=x.shiftRightUnsigned,x.toSigned=function(){return this.unsigned?e(this.low,this.high,!1):this},x.toUnsigned=function(){return this.unsigned?this:e(this.low,this.high,!0)},x.toBytes=function(a){return a?this.toBytesLE():this.toBytesBE()},x.toBytesLE=function(){var a=this.high,b=this.low;return[255&b,b>>>8&255,b>>>16&255,b>>>24&255,255&a,a>>>8&255,a>>>16&255,a>>>24&255]},x.toBytesBE=function(){var a=this.high,b=this.low;return[a>>>24&255,a>>>16&255,a>>>8&255,255&a,b>>>24&255,b>>>16&255,b>>>8&255,255&b]},a}),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;ge.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;dthis.msgBuffer.length-1&&(this.msgBuffer=b.expandByteArray(this.msgBuffer)),this.msgBuffer[this.msgBufferIdx++]=a,this.escape=!1,this.msgBuffer.length1)&&(this.socket=new osc.WebSocket(this.options.url)),osc.WebSocketPort.setupSocketForBinary(this.socket);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,b)},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){return this.socket&&1===this.socket.readyState?void this.socket.send(a):void osc.fireClosedPortSendError(this)},a.close=function(a,b){this.socket.close(a,b)},osc.WebSocketPort.setupSocketForBinary=function(a){a.binaryType=osc.isNode?"nodebuffer":"arraybuffer"}}(); \ No newline at end of file diff --git a/dist/osc-chromeapp.js b/dist/osc-chromeapp.js index e898949..3c2e2e3 100644 --- a/dist/osc-chromeapp.js +++ b/dist/osc-chromeapp.js @@ -165,7 +165,31 @@ var osc = osc || {}; idx = (idx + 3) & ~0x03; offsetState.idx = idx; - return String.fromCharCode.apply(null, charCodes); + if ((typeof global !== "undefined" ? global : window).hasOwnProperty("Buffer")) { // jshint ignore:line + // Check for Buffer API (Node/Electron) + if (Buffer.from) { + // new Buffer() is now deprecated, so we use Buffer.from if available + return Buffer.from(charCodes).toString("utf-8"); + } else { + return new Buffer(charCodes).toString("utf-8"); + } + } else if ((typeof global !== "undefined" ? global : window).hasOwnProperty("TextDecoder")) { // jshint ignore:line + // Check for TextDecoder API (Browser/WebKit-based) + return new TextDecoder("utf-8").decode(new Int8Array(charCodes)); + } else { + // If no Buffer or TextDecoder, resort to fromCharCode + // This does not properly decode multi-byte Unicode characters. + + var str = ""; + var sliceSize = 10000; + + // Processing the array in chunks so as not to exceed argument + // limit, see https://bugs.webkit.org/show_bug.cgi?id=80797 + for (var i = 0; i < charCodes.length; i += sliceSize) { + str += String.fromCharCode.apply(null, charCodes.slice(i, i + sliceSize)); + } + return str; + } }; /** diff --git a/dist/osc-chromeapp.min.js b/dist/osc-chromeapp.min.js index bab030c..f7373a5 100644 --- a/dist/osc-chromeapp.min.js +++ b/dist/osc-chromeapp.min.js @@ -1,3 +1,3 @@ /*! osc.js 2.2.0, Copyright 2017 Colin Clark | github.com/colinbdclark/osc.js */ -var osc=osc||{};!function(){"use strict";osc.SECS_70YRS=2208988800,osc.TWO_32=4294967296,osc.defaults={metadata:!1,unpackSingleArgs:!0},osc.isCommonJS=!("undefined"==typeof module||!module.exports),osc.isNode=osc.isCommonJS&&"undefined"==typeof window,osc.isElectron=!("undefined"==typeof process||!process.versions||!process.versions.electron),osc.isBufferEnv=osc.isNode||osc.isElectron,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};var a="undefined"!=typeof dcodeIO?dcodeIO.Long:"undefined"!=typeof a?a:osc.isNode?require("long"):void 0;osc.dataView=function(a,b,c){return a.buffer?new DataView(a.buffer,b,c):a instanceof ArrayBuffer?new DataView(a,b,c):new DataView(new Uint8Array(a),b,c)},osc.byteArray=function(a){if(a instanceof Uint8Array)return a;var b=a.buffer?a.buffer:a;if(!(b instanceof ArrayBuffer||"undefined"!=typeof b.length&&"string"!=typeof b))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.nativeBuffer=function(a){return osc.isBufferEnv?osc.isBuffer(a)?a:new Buffer(a.buffer?a:new Uint8Array(a)):osc.isTypedArrayView(a)?a:new Uint8Array(a)},osc.copyByteArray=function(a,b,c){if(osc.isTypedArrayView(a)&&osc.isTypedArrayView(b))b.set(a,c);else for(var d=void 0===c?0:c,e=Math.min(b.length-c,a.length),f=0,g=d;f1){var i=Math.floor(h),j=h-i;f+=i,h=j}var k=d+f+osc.SECS_70YRS,l=Math.round(osc.TWO_32*h);return{raw:[k,l]}},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>>=0,(f=0<=a&&a<256)&&(d=i[a])?d:(c=e(a,(0|a)<0?-1:0,!0),f&&(i[a]=c),c)):(a|=0,(f=-128<=a&&a<128)&&(d=h[a])?d:(c=e(a,a<0?-1:0,!1),f&&(h[a]=c),c))}function d(a,b){if(isNaN(a)||!isFinite(a))return b?q:p;if(b){if(a<0)return q;if(a>=m)return v}else{if(a<=-n)return w;if(a+1>=n)return u}return a<0?d(-a,b).neg():e(a%l|0,a/l|0,b)}function e(b,c,d){return new a(b,c,d)}function f(a,b,c){if(0===a.length)throw Error("empty string");if("NaN"===a||"Infinity"===a||"+Infinity"===a||"-Infinity"===a)return p;if("number"==typeof b?(c=b,b=!1):b=!!b,c=c||10,c<2||360)throw Error("interior hyphen");if(0===e)return f(a.substring(1),b,c).neg();for(var g=d(j(c,8)),h=p,i=0;i>>0:this.low},x.toNumber=function(){return this.unsigned?(this.high>>>0)*l+(this.low>>>0):this.high*l+(this.low>>>0)},x.toString=function(a){if(a=a||10,a<2||36>>0,l=k.toString(a);if(g=i,g.isZero())return l+h;for(;l.length<6;)l="0"+l;h=""+l+h}},x.getHighBits=function(){return this.high},x.getHighBitsUnsigned=function(){return this.high>>>0},x.getLowBits=function(){return this.low},x.getLowBitsUnsigned=function(){return this.low>>>0},x.getNumBitsAbs=function(){if(this.isNegative())return this.eq(w)?64:this.neg().getNumBitsAbs();for(var a=0!=this.high?this.high:this.low,b=31;b>0&&0==(a&1<=0},x.isOdd=function(){return 1===(1&this.low)},x.isEven=function(){return 0===(1&this.low)},x.equals=function(a){return b(a)||(a=g(a)),(this.unsigned===a.unsigned||this.high>>>31!==1||a.high>>>31!==1)&&(this.high===a.high&&this.low===a.low)},x.eq=x.equals,x.notEquals=function(a){return!this.eq(a)},x.neq=x.notEquals,x.lessThan=function(a){return this.comp(a)<0},x.lt=x.lessThan,x.lessThanOrEqual=function(a){return this.comp(a)<=0},x.lte=x.lessThanOrEqual,x.greaterThan=function(a){return this.comp(a)>0},x.gt=x.greaterThan,x.greaterThanOrEqual=function(a){return this.comp(a)>=0},x.gte=x.greaterThanOrEqual,x.compare=function(a){if(b(a)||(a=g(a)),this.eq(a))return 0;var c=this.isNegative(),d=a.isNegative();return c&&!d?-1:!c&&d?1:this.unsigned?a.high>>>0>this.high>>>0||a.high===this.high&&a.low>>>0>this.low>>>0?-1:1:this.sub(a).isNegative()?-1:1},x.comp=x.compare,x.negate=function(){return!this.unsigned&&this.eq(w)?w:this.not().add(r)},x.neg=x.negate,x.add=function(a){b(a)||(a=g(a));var c=this.high>>>16,d=65535&this.high,f=this.low>>>16,h=65535&this.low,i=a.high>>>16,j=65535&a.high,k=a.low>>>16,l=65535&a.low,m=0,n=0,o=0,p=0;return p+=h+l,o+=p>>>16,p&=65535,o+=f+k,n+=o>>>16,o&=65535,n+=d+j,m+=n>>>16,n&=65535,m+=c+i,m&=65535,e(o<<16|p,m<<16|n,this.unsigned)},x.subtract=function(a){return b(a)||(a=g(a)),this.add(a.neg())},x.sub=x.subtract,x.multiply=function(a){if(this.isZero())return p;if(b(a)||(a=g(a)),a.isZero())return p;if(this.eq(w))return a.isOdd()?w:p;if(a.eq(w))return this.isOdd()?w:p;if(this.isNegative())return a.isNegative()?this.neg().mul(a.neg()):this.neg().mul(a).neg();if(a.isNegative())return this.mul(a.neg()).neg();if(this.lt(o)&&a.lt(o))return d(this.toNumber()*a.toNumber(),this.unsigned);var c=this.high>>>16,f=65535&this.high,h=this.low>>>16,i=65535&this.low,j=a.high>>>16,k=65535&a.high,l=a.low>>>16,m=65535&a.low,n=0,q=0,r=0,s=0;return s+=i*m,r+=s>>>16,s&=65535,r+=h*m,q+=r>>>16,r&=65535,r+=i*l,q+=r>>>16,r&=65535,q+=f*m,n+=q>>>16,q&=65535,q+=h*l,n+=q>>>16,q&=65535,q+=i*k,n+=q>>>16,q&=65535,n+=c*m+f*l+h*k+i*j,n&=65535,e(r<<16|s,n<<16|q,this.unsigned)},x.mul=x.multiply,x.divide=function(a){if(b(a)||(a=g(a)),a.isZero())throw Error("division by zero");if(this.isZero())return this.unsigned?q:p;var c,e,f;if(this.unsigned){if(a.unsigned||(a=a.toUnsigned()),a.gt(this))return q;if(a.gt(this.shru(1)))return s;f=q}else{if(this.eq(w)){if(a.eq(r)||a.eq(t))return w;if(a.eq(w))return r;var h=this.shr(1);return c=h.div(a).shl(1),c.eq(p)?a.isNegative()?r:t:(e=this.sub(a.mul(c)),f=c.add(e.div(a)))}if(a.eq(w))return this.unsigned?q:p;if(this.isNegative())return a.isNegative()?this.neg().div(a.neg()):this.neg().div(a).neg();if(a.isNegative())return this.div(a.neg()).neg();f=p}for(e=this;e.gte(a);){c=Math.max(1,Math.floor(e.toNumber()/a.toNumber()));for(var i=Math.ceil(Math.log(c)/Math.LN2),k=i<=48?1:j(2,i-48),l=d(c),m=l.mul(a);m.isNegative()||m.gt(e);)c-=k,l=d(c,this.unsigned),m=l.mul(a);l.isZero()&&(l=r),f=f.add(l),e=e.sub(m)}return f},x.div=x.divide,x.modulo=function(a){return b(a)||(a=g(a)),this.sub(this.div(a).mul(a))},x.mod=x.modulo,x.not=function(){return e(~this.low,~this.high,this.unsigned)},x.and=function(a){return b(a)||(a=g(a)),e(this.low&a.low,this.high&a.high,this.unsigned)},x.or=function(a){return b(a)||(a=g(a)),e(this.low|a.low,this.high|a.high,this.unsigned)},x.xor=function(a){return b(a)||(a=g(a)),e(this.low^a.low,this.high^a.high,this.unsigned)},x.shiftLeft=function(a){return b(a)&&(a=a.toInt()),0===(a&=63)?this:a<32?e(this.low<>>32-a,this.unsigned):e(0,this.low<>>a|this.high<<32-a,this.high>>a,this.unsigned):e(this.high>>a-32,this.high>=0?0:-1,this.unsigned)},x.shr=x.shiftRight,x.shiftRightUnsigned=function(a){if(b(a)&&(a=a.toInt()),a&=63,0===a)return this;var c=this.high;if(a<32){var d=this.low;return e(d>>>a|c<<32-a,c>>>a,this.unsigned)}return 32===a?e(c,0,this.unsigned):e(c>>>a-32,0,this.unsigned)},x.shru=x.shiftRightUnsigned,x.toSigned=function(){return this.unsigned?e(this.low,this.high,!1):this},x.toUnsigned=function(){return this.unsigned?this:e(this.low,this.high,!0)},x.toBytes=function(a){return a?this.toBytesLE():this.toBytesBE()},x.toBytesLE=function(){var a=this.high,b=this.low;return[255&b,b>>>8&255,b>>>16&255,b>>>24&255,255&a,a>>>8&255,a>>>16&255,a>>>24&255]},x.toBytesBE=function(){var a=this.high,b=this.low;return[a>>>24&255,a>>>16&255,a>>>8&255,255&a,b>>>24&255,b>>>16&255,b>>>8&255,255&b]},a}),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;ge.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;dthis.msgBuffer.length-1&&(this.msgBuffer=b.expandByteArray(this.msgBuffer)),this.msgBuffer[this.msgBufferIdx++]=a,this.escape=!1,this.msgBuffer.length1)&&(this.socket=new osc.WebSocket(this.options.url)),osc.WebSocketPort.setupSocketForBinary(this.socket);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,b)},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){return this.socket&&1===this.socket.readyState?void this.socket.send(a):void osc.fireClosedPortSendError(this)},a.close=function(a,b){this.socket.close(a,b)},osc.WebSocketPort.setupSocketForBinary=function(a){a.binaryType=osc.isNode?"nodebuffer":"arraybuffer"}}();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)}),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),this.connectionId=this.options.connectionId,this.connectionId&&this.emit("open",this.connectionId)};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)return void osc.fireClosedPortSendError(this);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)),this.socketId=b.socketId,this.socketId&&this.emit("open",0)},a=osc.UDPPort.prototype=Object.create(osc.Port.prototype),a.constructor=osc.UDPPort,a.open=function(){if(!this.socketId){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;void 0!==b.broadcast&&chrome.sockets.udp.setBroadcast(this.socketId,b.broadcast,function(b){b<0&&a.emit("error",new Error("An error occurred while setting the socket's broadcast flag. Result code: "+b))}),void 0!==b.multicastTTL&&chrome.sockets.udp.setMulticastTimeToLive(this.socketId,b.multicastTTL,function(b){b<0&&a.emit("error",new Error("An error occurred while setting the socket's multicast time to live flag. Result code: "+b))}),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(){var a=this.options;osc.listenToTransport(this,chrome.sockets.udp,"socketId"),a.multicastMembership&&("string"==typeof a.multicastMembership&&(a.multicastMembership=[a.multicastMembership]),a.multicastMembership.forEach(function(a){chrome.sockets.udp.joinGroup(this.socketId,a,function(b){b<0&&this.emit("error",new Error("There was an error while trying to join the multicast group "+a+". Result code: "+b))})}))},a.sendRaw=function(a,b,c){if(!this.socketId)return void osc.fireClosedPortSendError(this);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")})}}}(); \ No newline at end of file +var osc=osc||{};!function(){"use strict";osc.SECS_70YRS=2208988800,osc.TWO_32=4294967296,osc.defaults={metadata:!1,unpackSingleArgs:!0},osc.isCommonJS=!("undefined"==typeof module||!module.exports),osc.isNode=osc.isCommonJS&&"undefined"==typeof window,osc.isElectron=!("undefined"==typeof process||!process.versions||!process.versions.electron),osc.isBufferEnv=osc.isNode||osc.isElectron,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};var a="undefined"!=typeof dcodeIO?dcodeIO.Long:"undefined"!=typeof a?a:osc.isNode?require("long"):void 0;osc.dataView=function(a,b,c){return a.buffer?new DataView(a.buffer,b,c):a instanceof ArrayBuffer?new DataView(a,b,c):new DataView(new Uint8Array(a),b,c)},osc.byteArray=function(a){if(a instanceof Uint8Array)return a;var b=a.buffer?a.buffer:a;if(!(b instanceof ArrayBuffer||"undefined"!=typeof b.length&&"string"!=typeof b))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.nativeBuffer=function(a){return osc.isBufferEnv?osc.isBuffer(a)?a:new Buffer(a.buffer?a:new Uint8Array(a)):osc.isTypedArrayView(a)?a:new Uint8Array(a)},osc.copyByteArray=function(a,b,c){if(osc.isTypedArrayView(a)&&osc.isTypedArrayView(b))b.set(a,c);else for(var d=void 0===c?0:c,e=Math.min(b.length-c,a.length),f=0,g=d;f1){var i=Math.floor(h),j=h-i;f+=i,h=j}var k=d+f+osc.SECS_70YRS,l=Math.round(osc.TWO_32*h);return{raw:[k,l]}},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>>=0,(f=0<=a&&a<256)&&(d=i[a])?d:(c=e(a,(0|a)<0?-1:0,!0),f&&(i[a]=c),c)):(a|=0,(f=-128<=a&&a<128)&&(d=h[a])?d:(c=e(a,a<0?-1:0,!1),f&&(h[a]=c),c))}function d(a,b){if(isNaN(a)||!isFinite(a))return b?q:p;if(b){if(a<0)return q;if(a>=m)return v}else{if(a<=-n)return w;if(a+1>=n)return u}return a<0?d(-a,b).neg():e(a%l|0,a/l|0,b)}function e(b,c,d){return new a(b,c,d)}function f(a,b,c){if(0===a.length)throw Error("empty string");if("NaN"===a||"Infinity"===a||"+Infinity"===a||"-Infinity"===a)return p;if("number"==typeof b?(c=b,b=!1):b=!!b,c=c||10,c<2||360)throw Error("interior hyphen");if(0===e)return f(a.substring(1),b,c).neg();for(var g=d(j(c,8)),h=p,i=0;i>>0:this.low},x.toNumber=function(){return this.unsigned?(this.high>>>0)*l+(this.low>>>0):this.high*l+(this.low>>>0)},x.toString=function(a){if(a=a||10,a<2||36>>0,l=k.toString(a);if(g=i,g.isZero())return l+h;for(;l.length<6;)l="0"+l;h=""+l+h}},x.getHighBits=function(){return this.high},x.getHighBitsUnsigned=function(){return this.high>>>0},x.getLowBits=function(){return this.low},x.getLowBitsUnsigned=function(){return this.low>>>0},x.getNumBitsAbs=function(){if(this.isNegative())return this.eq(w)?64:this.neg().getNumBitsAbs();for(var a=0!=this.high?this.high:this.low,b=31;b>0&&0==(a&1<=0},x.isOdd=function(){return 1===(1&this.low)},x.isEven=function(){return 0===(1&this.low)},x.equals=function(a){return b(a)||(a=g(a)),(this.unsigned===a.unsigned||this.high>>>31!==1||a.high>>>31!==1)&&(this.high===a.high&&this.low===a.low)},x.eq=x.equals,x.notEquals=function(a){return!this.eq(a)},x.neq=x.notEquals,x.lessThan=function(a){return this.comp(a)<0},x.lt=x.lessThan,x.lessThanOrEqual=function(a){return this.comp(a)<=0},x.lte=x.lessThanOrEqual,x.greaterThan=function(a){return this.comp(a)>0},x.gt=x.greaterThan,x.greaterThanOrEqual=function(a){return this.comp(a)>=0},x.gte=x.greaterThanOrEqual,x.compare=function(a){if(b(a)||(a=g(a)),this.eq(a))return 0;var c=this.isNegative(),d=a.isNegative();return c&&!d?-1:!c&&d?1:this.unsigned?a.high>>>0>this.high>>>0||a.high===this.high&&a.low>>>0>this.low>>>0?-1:1:this.sub(a).isNegative()?-1:1},x.comp=x.compare,x.negate=function(){return!this.unsigned&&this.eq(w)?w:this.not().add(r)},x.neg=x.negate,x.add=function(a){b(a)||(a=g(a));var c=this.high>>>16,d=65535&this.high,f=this.low>>>16,h=65535&this.low,i=a.high>>>16,j=65535&a.high,k=a.low>>>16,l=65535&a.low,m=0,n=0,o=0,p=0;return p+=h+l,o+=p>>>16,p&=65535,o+=f+k,n+=o>>>16,o&=65535,n+=d+j,m+=n>>>16,n&=65535,m+=c+i,m&=65535,e(o<<16|p,m<<16|n,this.unsigned)},x.subtract=function(a){return b(a)||(a=g(a)),this.add(a.neg())},x.sub=x.subtract,x.multiply=function(a){if(this.isZero())return p;if(b(a)||(a=g(a)),a.isZero())return p;if(this.eq(w))return a.isOdd()?w:p;if(a.eq(w))return this.isOdd()?w:p;if(this.isNegative())return a.isNegative()?this.neg().mul(a.neg()):this.neg().mul(a).neg();if(a.isNegative())return this.mul(a.neg()).neg();if(this.lt(o)&&a.lt(o))return d(this.toNumber()*a.toNumber(),this.unsigned);var c=this.high>>>16,f=65535&this.high,h=this.low>>>16,i=65535&this.low,j=a.high>>>16,k=65535&a.high,l=a.low>>>16,m=65535&a.low,n=0,q=0,r=0,s=0;return s+=i*m,r+=s>>>16,s&=65535,r+=h*m,q+=r>>>16,r&=65535,r+=i*l,q+=r>>>16,r&=65535,q+=f*m,n+=q>>>16,q&=65535,q+=h*l,n+=q>>>16,q&=65535,q+=i*k,n+=q>>>16,q&=65535,n+=c*m+f*l+h*k+i*j,n&=65535,e(r<<16|s,n<<16|q,this.unsigned)},x.mul=x.multiply,x.divide=function(a){if(b(a)||(a=g(a)),a.isZero())throw Error("division by zero");if(this.isZero())return this.unsigned?q:p;var c,e,f;if(this.unsigned){if(a.unsigned||(a=a.toUnsigned()),a.gt(this))return q;if(a.gt(this.shru(1)))return s;f=q}else{if(this.eq(w)){if(a.eq(r)||a.eq(t))return w;if(a.eq(w))return r;var h=this.shr(1);return c=h.div(a).shl(1),c.eq(p)?a.isNegative()?r:t:(e=this.sub(a.mul(c)),f=c.add(e.div(a)))}if(a.eq(w))return this.unsigned?q:p;if(this.isNegative())return a.isNegative()?this.neg().div(a.neg()):this.neg().div(a).neg();if(a.isNegative())return this.div(a.neg()).neg();f=p}for(e=this;e.gte(a);){c=Math.max(1,Math.floor(e.toNumber()/a.toNumber()));for(var i=Math.ceil(Math.log(c)/Math.LN2),k=i<=48?1:j(2,i-48),l=d(c),m=l.mul(a);m.isNegative()||m.gt(e);)c-=k,l=d(c,this.unsigned),m=l.mul(a);l.isZero()&&(l=r),f=f.add(l),e=e.sub(m)}return f},x.div=x.divide,x.modulo=function(a){return b(a)||(a=g(a)),this.sub(this.div(a).mul(a))},x.mod=x.modulo,x.not=function(){return e(~this.low,~this.high,this.unsigned)},x.and=function(a){return b(a)||(a=g(a)),e(this.low&a.low,this.high&a.high,this.unsigned)},x.or=function(a){return b(a)||(a=g(a)),e(this.low|a.low,this.high|a.high,this.unsigned)},x.xor=function(a){return b(a)||(a=g(a)),e(this.low^a.low,this.high^a.high,this.unsigned)},x.shiftLeft=function(a){return b(a)&&(a=a.toInt()),0===(a&=63)?this:a<32?e(this.low<>>32-a,this.unsigned):e(0,this.low<>>a|this.high<<32-a,this.high>>a,this.unsigned):e(this.high>>a-32,this.high>=0?0:-1,this.unsigned)},x.shr=x.shiftRight,x.shiftRightUnsigned=function(a){if(b(a)&&(a=a.toInt()),a&=63,0===a)return this;var c=this.high;if(a<32){var d=this.low;return e(d>>>a|c<<32-a,c>>>a,this.unsigned)}return 32===a?e(c,0,this.unsigned):e(c>>>a-32,0,this.unsigned)},x.shru=x.shiftRightUnsigned,x.toSigned=function(){return this.unsigned?e(this.low,this.high,!1):this},x.toUnsigned=function(){return this.unsigned?this:e(this.low,this.high,!0)},x.toBytes=function(a){return a?this.toBytesLE():this.toBytesBE()},x.toBytesLE=function(){var a=this.high,b=this.low;return[255&b,b>>>8&255,b>>>16&255,b>>>24&255,255&a,a>>>8&255,a>>>16&255,a>>>24&255]},x.toBytesBE=function(){var a=this.high,b=this.low;return[a>>>24&255,a>>>16&255,a>>>8&255,255&a,b>>>24&255,b>>>16&255,b>>>8&255,255&b]},a}),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;ge.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;dthis.msgBuffer.length-1&&(this.msgBuffer=b.expandByteArray(this.msgBuffer)),this.msgBuffer[this.msgBufferIdx++]=a,this.escape=!1,this.msgBuffer.length1)&&(this.socket=new osc.WebSocket(this.options.url)),osc.WebSocketPort.setupSocketForBinary(this.socket);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,b)},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){return this.socket&&1===this.socket.readyState?void this.socket.send(a):void osc.fireClosedPortSendError(this)},a.close=function(a,b){this.socket.close(a,b)},osc.WebSocketPort.setupSocketForBinary=function(a){a.binaryType=osc.isNode?"nodebuffer":"arraybuffer"}}();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)}),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),this.connectionId=this.options.connectionId,this.connectionId&&this.emit("open",this.connectionId)};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)return void osc.fireClosedPortSendError(this);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)),this.socketId=b.socketId,this.socketId&&this.emit("open",0)},a=osc.UDPPort.prototype=Object.create(osc.Port.prototype),a.constructor=osc.UDPPort,a.open=function(){if(!this.socketId){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;void 0!==b.broadcast&&chrome.sockets.udp.setBroadcast(this.socketId,b.broadcast,function(b){b<0&&a.emit("error",new Error("An error occurred while setting the socket's broadcast flag. Result code: "+b))}),void 0!==b.multicastTTL&&chrome.sockets.udp.setMulticastTimeToLive(this.socketId,b.multicastTTL,function(b){b<0&&a.emit("error",new Error("An error occurred while setting the socket's multicast time to live flag. Result code: "+b))}),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(){var a=this.options;osc.listenToTransport(this,chrome.sockets.udp,"socketId"),a.multicastMembership&&("string"==typeof a.multicastMembership&&(a.multicastMembership=[a.multicastMembership]),a.multicastMembership.forEach(function(a){chrome.sockets.udp.joinGroup(this.socketId,a,function(b){b<0&&this.emit("error",new Error("There was an error while trying to join the multicast group "+a+". Result code: "+b))})}))},a.sendRaw=function(a,b,c){if(!this.socketId)return void osc.fireClosedPortSendError(this);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")})}}}(); \ No newline at end of file diff --git a/dist/osc-module.js b/dist/osc-module.js index 33d68ad..b229492 100644 --- a/dist/osc-module.js +++ b/dist/osc-module.js @@ -182,7 +182,31 @@ var osc = osc || {}; idx = (idx + 3) & ~0x03; offsetState.idx = idx; - return String.fromCharCode.apply(null, charCodes); + if ((typeof global !== "undefined" ? global : window).hasOwnProperty("Buffer")) { // jshint ignore:line + // Check for Buffer API (Node/Electron) + if (Buffer.from) { + // new Buffer() is now deprecated, so we use Buffer.from if available + return Buffer.from(charCodes).toString("utf-8"); + } else { + return new Buffer(charCodes).toString("utf-8"); + } + } else if ((typeof global !== "undefined" ? global : window).hasOwnProperty("TextDecoder")) { // jshint ignore:line + // Check for TextDecoder API (Browser/WebKit-based) + return new TextDecoder("utf-8").decode(new Int8Array(charCodes)); + } else { + // If no Buffer or TextDecoder, resort to fromCharCode + // This does not properly decode multi-byte Unicode characters. + + var str = ""; + var sliceSize = 10000; + + // Processing the array in chunks so as not to exceed argument + // limit, see https://bugs.webkit.org/show_bug.cgi?id=80797 + for (var i = 0; i < charCodes.length; i += sliceSize) { + str += String.fromCharCode.apply(null, charCodes.slice(i, i + sliceSize)); + } + return str; + } }; /** diff --git a/dist/osc-module.min.js b/dist/osc-module.min.js index 3cf9992..a9a43e0 100644 --- a/dist/osc-module.min.js +++ b/dist/osc-module.min.js @@ -1,3 +1,3 @@ /*! osc.js 2.2.0, Copyright 2017 Colin Clark | github.com/colinbdclark/osc.js */ -!function(a,b){"object"==typeof exports?(a.osc=exports,b(exports,require("slip"),require("EventEmitter"),require("long"))):"function"==typeof define&&define.amd?define(["exports","slip","EventEmitter","long"],function(c,d,e,f){return a.osc=c,a.osc,b(c,d,e,f)}):(a.osc={},b(a.osc,slip,EventEmitter))}(this,function(a,b,c,d){var e=e||{};!function(){"use strict";e.SECS_70YRS=2208988800,e.TWO_32=4294967296,e.defaults={metadata:!1,unpackSingleArgs:!0},e.isCommonJS=!("undefined"==typeof module||!module.exports),e.isNode=e.isCommonJS&&"undefined"==typeof window,e.isElectron=!("undefined"==typeof process||!process.versions||!process.versions.electron),e.isBufferEnv=e.isNode||e.isElectron,e.isArray=function(a){return a&&"[object Array]"===Object.prototype.toString.call(a)},e.isTypedArrayView=function(a){return a.buffer&&a.buffer instanceof ArrayBuffer},e.isBuffer=function(a){return e.isBufferEnv&&a instanceof Buffer};var a="undefined"!=typeof dcodeIO?dcodeIO.Long:"undefined"!=typeof a?a:e.isNode?require("long"):void 0;e.dataView=function(a,b,c){return a.buffer?new DataView(a.buffer,b,c):a instanceof ArrayBuffer?new DataView(a,b,c):new DataView(new Uint8Array(a),b,c)},e.byteArray=function(a){if(a instanceof Uint8Array)return a;var b=a.buffer?a.buffer:a;if(!(b instanceof ArrayBuffer||"undefined"!=typeof b.length&&"string"!=typeof b))throw new Error("Can't wrap a non-array-like object as Uint8Array. Object was: "+JSON.stringify(a,null,2));return new Uint8Array(b)},e.nativeBuffer=function(a){return e.isBufferEnv?e.isBuffer(a)?a:new Buffer(a.buffer?a:new Uint8Array(a)):e.isTypedArrayView(a)?a:new Uint8Array(a)},e.copyByteArray=function(a,b,c){if(e.isTypedArrayView(a)&&e.isTypedArrayView(b))b.set(a,c);else for(var d=void 0===c?0:c,f=Math.min(b.length-c,a.length),g=0,h=d;g1){var j=Math.floor(i),k=i-j;g+=j,i=k}var l=d+g+e.SECS_70YRS,m=Math.round(e.TWO_32*i);return{raw:[l,m]}},e.ntpToJSTime=function(a,b){var c=a-e.SECS_70YRS,d=b/e.TWO_32,f=1e3*(c+d);return f},e.jsToNTPTime=function(a){var b=a/1e3,c=Math.floor(b),d=b-c,f=c+e.SECS_70YRS,g=Math.round(e.TWO_32*d);return[f,g]},e.readArguments=function(a,b,c){var d=e.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 f=d.substring(1).split(""),g=[];return e.readArgumentsIntoArray(g,f,d,a,b,c),g},e.readArgument=function(a,b,c,d,f){var g=e.argumentTypes[a];if(!g)throw new Error("'"+a+"' is not a valid OSC type tag. Type tag string was: "+b);var h=g.reader,i=e[h](c,f);return d.metadata&&(i={type:a,value:i}),i},e.readArgumentsIntoArray=function(a,b,c,d,f,g){for(var h=0;h1)&&(this.socket=new e.WebSocket(this.options.url)),e.WebSocketPort.setupSocketForBinary(this.socket);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,b)},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){return this.socket&&1===this.socket.readyState?void this.socket.send(a):void e.fireClosedPortSendError(this)},a.close=function(a,b){this.socket.close(a,b)},e.WebSocketPort.setupSocketForBinary=function(a){a.binaryType=e.isNode?"nodebuffer":"arraybuffer"}}(),e}); \ No newline at end of file +!function(a,b){"object"==typeof exports?(a.osc=exports,b(exports,require("slip"),require("EventEmitter"),require("long"))):"function"==typeof define&&define.amd?define(["exports","slip","EventEmitter","long"],function(c,d,e,f){return a.osc=c,a.osc,b(c,d,e,f)}):(a.osc={},b(a.osc,slip,EventEmitter))}(this,function(a,b,c,d){var e=e||{};!function(){"use strict";e.SECS_70YRS=2208988800,e.TWO_32=4294967296,e.defaults={metadata:!1,unpackSingleArgs:!0},e.isCommonJS=!("undefined"==typeof module||!module.exports),e.isNode=e.isCommonJS&&"undefined"==typeof window,e.isElectron=!("undefined"==typeof process||!process.versions||!process.versions.electron),e.isBufferEnv=e.isNode||e.isElectron,e.isArray=function(a){return a&&"[object Array]"===Object.prototype.toString.call(a)},e.isTypedArrayView=function(a){return a.buffer&&a.buffer instanceof ArrayBuffer},e.isBuffer=function(a){return e.isBufferEnv&&a instanceof Buffer};var a="undefined"!=typeof dcodeIO?dcodeIO.Long:"undefined"!=typeof a?a:e.isNode?require("long"):void 0;e.dataView=function(a,b,c){return a.buffer?new DataView(a.buffer,b,c):a instanceof ArrayBuffer?new DataView(a,b,c):new DataView(new Uint8Array(a),b,c)},e.byteArray=function(a){if(a instanceof Uint8Array)return a;var b=a.buffer?a.buffer:a;if(!(b instanceof ArrayBuffer||"undefined"!=typeof b.length&&"string"!=typeof b))throw new Error("Can't wrap a non-array-like object as Uint8Array. Object was: "+JSON.stringify(a,null,2));return new Uint8Array(b)},e.nativeBuffer=function(a){return e.isBufferEnv?e.isBuffer(a)?a:new Buffer(a.buffer?a:new Uint8Array(a)):e.isTypedArrayView(a)?a:new Uint8Array(a)},e.copyByteArray=function(a,b,c){if(e.isTypedArrayView(a)&&e.isTypedArrayView(b))b.set(a,c);else for(var d=void 0===c?0:c,f=Math.min(b.length-c,a.length),g=0,h=d;g1){var j=Math.floor(i),k=i-j;g+=j,i=k}var l=d+g+e.SECS_70YRS,m=Math.round(e.TWO_32*i);return{raw:[l,m]}},e.ntpToJSTime=function(a,b){var c=a-e.SECS_70YRS,d=b/e.TWO_32,f=1e3*(c+d);return f},e.jsToNTPTime=function(a){var b=a/1e3,c=Math.floor(b),d=b-c,f=c+e.SECS_70YRS,g=Math.round(e.TWO_32*d);return[f,g]},e.readArguments=function(a,b,c){var d=e.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 f=d.substring(1).split(""),g=[];return e.readArgumentsIntoArray(g,f,d,a,b,c),g},e.readArgument=function(a,b,c,d,f){var g=e.argumentTypes[a];if(!g)throw new Error("'"+a+"' is not a valid OSC type tag. Type tag string was: "+b);var h=g.reader,i=e[h](c,f);return d.metadata&&(i={type:a,value:i}),i},e.readArgumentsIntoArray=function(a,b,c,d,f,g){for(var h=0;h1)&&(this.socket=new e.WebSocket(this.options.url)),e.WebSocketPort.setupSocketForBinary(this.socket);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,b)},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){return this.socket&&1===this.socket.readyState?void this.socket.send(a):void e.fireClosedPortSendError(this)},a.close=function(a,b){this.socket.close(a,b)},e.WebSocketPort.setupSocketForBinary=function(a){a.binaryType=e.isNode?"nodebuffer":"arraybuffer"}}(),e}); \ No newline at end of file diff --git a/dist/osc.js b/dist/osc.js index f402381..d50bd1f 100644 --- a/dist/osc.js +++ b/dist/osc.js @@ -165,7 +165,31 @@ var osc = osc || {}; idx = (idx + 3) & ~0x03; offsetState.idx = idx; - return String.fromCharCode.apply(null, charCodes); + if ((typeof global !== "undefined" ? global : window).hasOwnProperty("Buffer")) { // jshint ignore:line + // Check for Buffer API (Node/Electron) + if (Buffer.from) { + // new Buffer() is now deprecated, so we use Buffer.from if available + return Buffer.from(charCodes).toString("utf-8"); + } else { + return new Buffer(charCodes).toString("utf-8"); + } + } else if ((typeof global !== "undefined" ? global : window).hasOwnProperty("TextDecoder")) { // jshint ignore:line + // Check for TextDecoder API (Browser/WebKit-based) + return new TextDecoder("utf-8").decode(new Int8Array(charCodes)); + } else { + // If no Buffer or TextDecoder, resort to fromCharCode + // This does not properly decode multi-byte Unicode characters. + + var str = ""; + var sliceSize = 10000; + + // Processing the array in chunks so as not to exceed argument + // limit, see https://bugs.webkit.org/show_bug.cgi?id=80797 + for (var i = 0; i < charCodes.length; i += sliceSize) { + str += String.fromCharCode.apply(null, charCodes.slice(i, i + sliceSize)); + } + return str; + } }; /** diff --git a/dist/osc.min.js b/dist/osc.min.js index 5c42582..44457a5 100644 --- a/dist/osc.min.js +++ b/dist/osc.min.js @@ -1,3 +1,3 @@ /*! osc.js 2.2.0, Copyright 2017 Colin Clark | github.com/colinbdclark/osc.js */ -var osc=osc||{};!function(){"use strict";osc.SECS_70YRS=2208988800,osc.TWO_32=4294967296,osc.defaults={metadata:!1,unpackSingleArgs:!0},osc.isCommonJS=!("undefined"==typeof module||!module.exports),osc.isNode=osc.isCommonJS&&"undefined"==typeof window,osc.isElectron=!("undefined"==typeof process||!process.versions||!process.versions.electron),osc.isBufferEnv=osc.isNode||osc.isElectron,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};var a="undefined"!=typeof dcodeIO?dcodeIO.Long:"undefined"!=typeof a?a:osc.isNode?require("long"):void 0;osc.dataView=function(a,b,c){return a.buffer?new DataView(a.buffer,b,c):a instanceof ArrayBuffer?new DataView(a,b,c):new DataView(new Uint8Array(a),b,c)},osc.byteArray=function(a){if(a instanceof Uint8Array)return a;var b=a.buffer?a.buffer:a;if(!(b instanceof ArrayBuffer||"undefined"!=typeof b.length&&"string"!=typeof b))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.nativeBuffer=function(a){return osc.isBufferEnv?osc.isBuffer(a)?a:new Buffer(a.buffer?a:new Uint8Array(a)):osc.isTypedArrayView(a)?a:new Uint8Array(a)},osc.copyByteArray=function(a,b,c){if(osc.isTypedArrayView(a)&&osc.isTypedArrayView(b))b.set(a,c);else for(var d=void 0===c?0:c,e=Math.min(b.length-c,a.length),f=0,g=d;f1){var i=Math.floor(h),j=h-i;f+=i,h=j}var k=d+f+osc.SECS_70YRS,l=Math.round(osc.TWO_32*h);return{raw:[k,l]}},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;g1){var i=Math.floor(h),j=h-i;f+=i,h=j}var k=d+f+osc.SECS_70YRS,l=Math.round(osc.TWO_32*h);return{raw:[k,l]}},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 Date: Mon, 14 May 2018 00:00:53 -0400 Subject: [PATCH 6/6] Updating dist files --- dist/osc-browser.js | 1267 ++---------------------------------- dist/osc-browser.min.js | 883 +++++++++++++++++++++++++- dist/osc-chromeapp.js | 1270 ++----------------------------------- dist/osc-chromeapp.min.js | 975 +++++++++++++++++++++++++++- dist/osc-module.js | 29 +- dist/osc-module.min.js | 489 +++++++++++++- dist/osc.js | 19 +- dist/osc.min.js | 364 ++++++++++- 8 files changed, 2806 insertions(+), 2490 deletions(-) diff --git a/dist/osc-browser.js b/dist/osc-browser.js index 3f8a275..04dade0 100644 --- a/dist/osc-browser.js +++ b/dist/osc-browser.js @@ -1,4 +1,4 @@ -/*! osc.js 2.2.0, Copyright 2017 Colin Clark | github.com/colinbdclark/osc.js */ +/*! osc.js 2.2.1, Copyright 2018 Colin Clark | github.com/colinbdclark/osc.js */ /* * osc.js: An Open Sound Control library for JavaScript that works in both the browser and Node.js @@ -7,7 +7,7 @@ * Licensed under the MIT and GPL 3 licenses. */ -/* global require, module, process, Buffer, dcodeIO */ +/* global require, module, process, Buffer, Long */ var osc = osc || {}; @@ -41,19 +41,18 @@ var osc = osc || {}; return obj && Object.prototype.toString.call(obj) === "[object Array]"; }; - // Unsupported, non-API function + // Unsupported, non-API function. osc.isTypedArrayView = function (obj) { return obj.buffer && obj.buffer instanceof ArrayBuffer; }; - // Unsupported, non-API function + // Unsupported, non-API function. osc.isBuffer = function (obj) { return osc.isBufferEnv && obj instanceof Buffer; }; - // Private instance of the optional Long dependency. - var Long = typeof dcodeIO !== "undefined" ? dcodeIO.Long : - typeof Long !== "undefined" ? Long : + // Unsupported, non-API member. + osc.Long = typeof Long !== "undefined" ? Long : osc.isNode ? require("long") : undefined; /** @@ -270,8 +269,8 @@ var osc = osc || {}; var high = osc.readPrimitive(dv, "getInt32", 4, offsetState), low = osc.readPrimitive(dv, "getInt32", 4, offsetState); - if (Long) { - return new Long(low, high); + if (osc.Long) { + return new osc.Long(low, high); } else { return { high: high, @@ -608,7 +607,7 @@ var osc = osc || {}; * * @param {DataView} dv a DataView instance to read from * @param {Object} offsetState the offsetState object that stores the current offset into dv - * @param {Oobject} [options] read options + * @param {Object} [options] read options * @return {Array} an array of the OSC arguments that were read */ osc.readArguments = function (dv, options, offsetState) { @@ -1090,1216 +1089,10 @@ var osc = osc || {}; module.exports = osc; } }()); -;/* - Copyright 2013 Daniel Wirtz - Copyright 2009 The Closure Library Authors. All Rights Reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS-IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - */ - -/** - * @license long.js (c) 2013 Daniel Wirtz - * Released under the Apache License, Version 2.0 - * see: https://github.com/dcodeIO/long.js for details - */ -(function(global, factory) { - - /* AMD */ if (typeof define === 'function' && define["amd"]) - define([], factory); - /* CommonJS */ else if (typeof require === 'function' && typeof module === "object" && module && module["exports"]) - module["exports"] = factory(); - /* Global */ else - (global["dcodeIO"] = global["dcodeIO"] || {})["Long"] = factory(); - -})(this, function() { - "use strict"; - - /** - * Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as *signed* integers. - * See the from* functions below for more convenient ways of constructing Longs. - * @exports Long - * @class A Long class for representing a 64 bit two's-complement integer value. - * @param {number} low The low (signed) 32 bits of the long - * @param {number} high The high (signed) 32 bits of the long - * @param {boolean=} unsigned Whether unsigned or not, defaults to `false` for signed - * @constructor - */ - function Long(low, high, unsigned) { - - /** - * The low 32 bits as a signed value. - * @type {number} - */ - this.low = low | 0; - - /** - * The high 32 bits as a signed value. - * @type {number} - */ - this.high = high | 0; - - /** - * Whether unsigned or not. - * @type {boolean} - */ - this.unsigned = !!unsigned; - } - - // The internal representation of a long is the two given signed, 32-bit values. - // We use 32-bit pieces because these are the size of integers on which - // Javascript performs bit-operations. For operations like addition and - // multiplication, we split each number into 16 bit pieces, which can easily be - // multiplied within Javascript's floating-point representation without overflow - // or change in sign. - // - // In the algorithms below, we frequently reduce the negative case to the - // positive case by negating the input(s) and then post-processing the result. - // Note that we must ALWAYS check specially whether those values are MIN_VALUE - // (-2^63) because -MIN_VALUE == MIN_VALUE (since 2^63 cannot be represented as - // a positive number, it overflows back into a negative). Not handling this - // case would often result in infinite recursion. - // - // Common constant values ZERO, ONE, NEG_ONE, etc. are defined below the from* - // methods on which they depend. - - /** - * An indicator used to reliably determine if an object is a Long or not. - * @type {boolean} - * @const - * @private - */ - Long.prototype.__isLong__; - - Object.defineProperty(Long.prototype, "__isLong__", { - value: true, - enumerable: false, - configurable: false - }); - - /** - * @function - * @param {*} obj Object - * @returns {boolean} - * @inner - */ - function isLong(obj) { - return (obj && obj["__isLong__"]) === true; - } - - /** - * Tests if the specified object is a Long. - * @function - * @param {*} obj Object - * @returns {boolean} - */ - Long.isLong = isLong; - - /** - * A cache of the Long representations of small integer values. - * @type {!Object} - * @inner - */ - var INT_CACHE = {}; - - /** - * A cache of the Long representations of small unsigned integer values. - * @type {!Object} - * @inner - */ - var UINT_CACHE = {}; - - /** - * @param {number} value - * @param {boolean=} unsigned - * @returns {!Long} - * @inner - */ - function fromInt(value, unsigned) { - var obj, cachedObj, cache; - if (unsigned) { - value >>>= 0; - if (cache = (0 <= value && value < 256)) { - cachedObj = UINT_CACHE[value]; - if (cachedObj) - return cachedObj; - } - obj = fromBits(value, (value | 0) < 0 ? -1 : 0, true); - if (cache) - UINT_CACHE[value] = obj; - return obj; - } else { - value |= 0; - if (cache = (-128 <= value && value < 128)) { - cachedObj = INT_CACHE[value]; - if (cachedObj) - return cachedObj; - } - obj = fromBits(value, value < 0 ? -1 : 0, false); - if (cache) - INT_CACHE[value] = obj; - return obj; - } - } - - /** - * Returns a Long representing the given 32 bit integer value. - * @function - * @param {number} value The 32 bit integer in question - * @param {boolean=} unsigned Whether unsigned or not, defaults to `false` for signed - * @returns {!Long} The corresponding Long value - */ - Long.fromInt = fromInt; - - /** - * @param {number} value - * @param {boolean=} unsigned - * @returns {!Long} - * @inner - */ - function fromNumber(value, unsigned) { - if (isNaN(value) || !isFinite(value)) - return unsigned ? UZERO : ZERO; - if (unsigned) { - if (value < 0) - return UZERO; - if (value >= TWO_PWR_64_DBL) - return MAX_UNSIGNED_VALUE; - } else { - if (value <= -TWO_PWR_63_DBL) - return MIN_VALUE; - if (value + 1 >= TWO_PWR_63_DBL) - return MAX_VALUE; - } - if (value < 0) - return fromNumber(-value, unsigned).neg(); - return fromBits((value % TWO_PWR_32_DBL) | 0, (value / TWO_PWR_32_DBL) | 0, unsigned); - } - - /** - * Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned. - * @function - * @param {number} value The number in question - * @param {boolean=} unsigned Whether unsigned or not, defaults to `false` for signed - * @returns {!Long} The corresponding Long value - */ - Long.fromNumber = fromNumber; - - /** - * @param {number} lowBits - * @param {number} highBits - * @param {boolean=} unsigned - * @returns {!Long} - * @inner - */ - function fromBits(lowBits, highBits, unsigned) { - return new Long(lowBits, highBits, unsigned); - } - - /** - * Returns a Long representing the 64 bit integer that comes by concatenating the given low and high bits. Each is - * assumed to use 32 bits. - * @function - * @param {number} lowBits The low 32 bits - * @param {number} highBits The high 32 bits - * @param {boolean=} unsigned Whether unsigned or not, defaults to `false` for signed - * @returns {!Long} The corresponding Long value - */ - Long.fromBits = fromBits; - - /** - * @function - * @param {number} base - * @param {number} exponent - * @returns {number} - * @inner - */ - var pow_dbl = Math.pow; // Used 4 times (4*8 to 15+4) - - /** - * @param {string} str - * @param {(boolean|number)=} unsigned - * @param {number=} radix - * @returns {!Long} - * @inner - */ - function fromString(str, unsigned, radix) { - if (str.length === 0) - throw Error('empty string'); - if (str === "NaN" || str === "Infinity" || str === "+Infinity" || str === "-Infinity") - return ZERO; - if (typeof unsigned === 'number') { - // For goog.math.long compatibility - radix = unsigned, - unsigned = false; - } else { - unsigned = !! unsigned; - } - radix = radix || 10; - if (radix < 2 || 36 < radix) - throw RangeError('radix'); - - var p; - if ((p = str.indexOf('-')) > 0) - throw Error('interior hyphen'); - else if (p === 0) { - return fromString(str.substring(1), unsigned, radix).neg(); - } - - // Do several (8) digits each time through the loop, so as to - // minimize the calls to the very expensive emulated div. - var radixToPower = fromNumber(pow_dbl(radix, 8)); - - var result = ZERO; - for (var i = 0; i < str.length; i += 8) { - var size = Math.min(8, str.length - i), - value = parseInt(str.substring(i, i + size), radix); - if (size < 8) { - var power = fromNumber(pow_dbl(radix, size)); - result = result.mul(power).add(fromNumber(value)); - } else { - result = result.mul(radixToPower); - result = result.add(fromNumber(value)); - } - } - result.unsigned = unsigned; - return result; - } - - /** - * Returns a Long representation of the given string, written using the specified radix. - * @function - * @param {string} str The textual representation of the Long - * @param {(boolean|number)=} unsigned Whether unsigned or not, defaults to `false` for signed - * @param {number=} radix The radix in which the text is written (2-36), defaults to 10 - * @returns {!Long} The corresponding Long value - */ - Long.fromString = fromString; - - /** - * @function - * @param {!Long|number|string|!{low: number, high: number, unsigned: boolean}} val - * @returns {!Long} - * @inner - */ - function fromValue(val) { - if (val /* is compatible */ instanceof Long) - return val; - if (typeof val === 'number') - return fromNumber(val); - if (typeof val === 'string') - return fromString(val); - // Throws for non-objects, converts non-instanceof Long: - return fromBits(val.low, val.high, val.unsigned); - } - - /** - * Converts the specified value to a Long. - * @function - * @param {!Long|number|string|!{low: number, high: number, unsigned: boolean}} val Value - * @returns {!Long} - */ - Long.fromValue = fromValue; - - // NOTE: the compiler should inline these constant values below and then remove these variables, so there should be - // no runtime penalty for these. - - /** - * @type {number} - * @const - * @inner - */ - var TWO_PWR_16_DBL = 1 << 16; - - /** - * @type {number} - * @const - * @inner - */ - var TWO_PWR_24_DBL = 1 << 24; - - /** - * @type {number} - * @const - * @inner - */ - var TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL; - - /** - * @type {number} - * @const - * @inner - */ - var TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL; - - /** - * @type {number} - * @const - * @inner - */ - var TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2; - - /** - * @type {!Long} - * @const - * @inner - */ - var TWO_PWR_24 = fromInt(TWO_PWR_24_DBL); - - /** - * @type {!Long} - * @inner - */ - var ZERO = fromInt(0); - - /** - * Signed zero. - * @type {!Long} - */ - Long.ZERO = ZERO; - - /** - * @type {!Long} - * @inner - */ - var UZERO = fromInt(0, true); - - /** - * Unsigned zero. - * @type {!Long} - */ - Long.UZERO = UZERO; - - /** - * @type {!Long} - * @inner - */ - var ONE = fromInt(1); - - /** - * Signed one. - * @type {!Long} - */ - Long.ONE = ONE; - - /** - * @type {!Long} - * @inner - */ - var UONE = fromInt(1, true); - - /** - * Unsigned one. - * @type {!Long} - */ - Long.UONE = UONE; - - /** - * @type {!Long} - * @inner - */ - var NEG_ONE = fromInt(-1); - - /** - * Signed negative one. - * @type {!Long} - */ - Long.NEG_ONE = NEG_ONE; - - /** - * @type {!Long} - * @inner - */ - var MAX_VALUE = fromBits(0xFFFFFFFF|0, 0x7FFFFFFF|0, false); - - /** - * Maximum signed value. - * @type {!Long} - */ - Long.MAX_VALUE = MAX_VALUE; - - /** - * @type {!Long} - * @inner - */ - var MAX_UNSIGNED_VALUE = fromBits(0xFFFFFFFF|0, 0xFFFFFFFF|0, true); - - /** - * Maximum unsigned value. - * @type {!Long} - */ - Long.MAX_UNSIGNED_VALUE = MAX_UNSIGNED_VALUE; - - /** - * @type {!Long} - * @inner - */ - var MIN_VALUE = fromBits(0, 0x80000000|0, false); - - /** - * Minimum signed value. - * @type {!Long} - */ - Long.MIN_VALUE = MIN_VALUE; - - /** - * @alias Long.prototype - * @inner - */ - var LongPrototype = Long.prototype; - - /** - * Converts the Long to a 32 bit integer, assuming it is a 32 bit integer. - * @returns {number} - */ - LongPrototype.toInt = function toInt() { - return this.unsigned ? this.low >>> 0 : this.low; - }; - - /** - * Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa). - * @returns {number} - */ - LongPrototype.toNumber = function toNumber() { - if (this.unsigned) - return ((this.high >>> 0) * TWO_PWR_32_DBL) + (this.low >>> 0); - return this.high * TWO_PWR_32_DBL + (this.low >>> 0); - }; - - /** - * Converts the Long to a string written in the specified radix. - * @param {number=} radix Radix (2-36), defaults to 10 - * @returns {string} - * @override - * @throws {RangeError} If `radix` is out of range - */ - LongPrototype.toString = function toString(radix) { - radix = radix || 10; - if (radix < 2 || 36 < radix) - throw RangeError('radix'); - if (this.isZero()) - return '0'; - if (this.isNegative()) { // Unsigned Longs are never negative - if (this.eq(MIN_VALUE)) { - // We need to change the Long value before it can be negated, so we remove - // the bottom-most digit in this base and then recurse to do the rest. - var radixLong = fromNumber(radix), - div = this.div(radixLong), - rem1 = div.mul(radixLong).sub(this); - return div.toString(radix) + rem1.toInt().toString(radix); - } else - return '-' + this.neg().toString(radix); - } - - // Do several (6) digits each time through the loop, so as to - // minimize the calls to the very expensive emulated div. - var radixToPower = fromNumber(pow_dbl(radix, 6), this.unsigned), - rem = this; - var result = ''; - while (true) { - var remDiv = rem.div(radixToPower), - intval = rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0, - digits = intval.toString(radix); - rem = remDiv; - if (rem.isZero()) - return digits + result; - else { - while (digits.length < 6) - digits = '0' + digits; - result = '' + digits + result; - } - } - }; - - /** - * Gets the high 32 bits as a signed integer. - * @returns {number} Signed high bits - */ - LongPrototype.getHighBits = function getHighBits() { - return this.high; - }; - - /** - * Gets the high 32 bits as an unsigned integer. - * @returns {number} Unsigned high bits - */ - LongPrototype.getHighBitsUnsigned = function getHighBitsUnsigned() { - return this.high >>> 0; - }; - - /** - * Gets the low 32 bits as a signed integer. - * @returns {number} Signed low bits - */ - LongPrototype.getLowBits = function getLowBits() { - return this.low; - }; - - /** - * Gets the low 32 bits as an unsigned integer. - * @returns {number} Unsigned low bits - */ - LongPrototype.getLowBitsUnsigned = function getLowBitsUnsigned() { - return this.low >>> 0; - }; - - /** - * Gets the number of bits needed to represent the absolute value of this Long. - * @returns {number} - */ - LongPrototype.getNumBitsAbs = function getNumBitsAbs() { - if (this.isNegative()) // Unsigned Longs are never negative - return this.eq(MIN_VALUE) ? 64 : this.neg().getNumBitsAbs(); - var val = this.high != 0 ? this.high : this.low; - for (var bit = 31; bit > 0; bit--) - if ((val & (1 << bit)) != 0) - break; - return this.high != 0 ? bit + 33 : bit + 1; - }; - - /** - * Tests if this Long's value equals zero. - * @returns {boolean} - */ - LongPrototype.isZero = function isZero() { - return this.high === 0 && this.low === 0; - }; - - /** - * Tests if this Long's value is negative. - * @returns {boolean} - */ - LongPrototype.isNegative = function isNegative() { - return !this.unsigned && this.high < 0; - }; - - /** - * Tests if this Long's value is positive. - * @returns {boolean} - */ - LongPrototype.isPositive = function isPositive() { - return this.unsigned || this.high >= 0; - }; - - /** - * Tests if this Long's value is odd. - * @returns {boolean} - */ - LongPrototype.isOdd = function isOdd() { - return (this.low & 1) === 1; - }; - - /** - * Tests if this Long's value is even. - * @returns {boolean} - */ - LongPrototype.isEven = function isEven() { - return (this.low & 1) === 0; - }; - - /** - * Tests if this Long's value equals the specified's. - * @param {!Long|number|string} other Other value - * @returns {boolean} - */ - LongPrototype.equals = function equals(other) { - if (!isLong(other)) - other = fromValue(other); - if (this.unsigned !== other.unsigned && (this.high >>> 31) === 1 && (other.high >>> 31) === 1) - return false; - return this.high === other.high && this.low === other.low; - }; - - /** - * Tests if this Long's value equals the specified's. This is an alias of {@link Long#equals}. - * @function - * @param {!Long|number|string} other Other value - * @returns {boolean} - */ - LongPrototype.eq = LongPrototype.equals; - - /** - * Tests if this Long's value differs from the specified's. - * @param {!Long|number|string} other Other value - * @returns {boolean} - */ - LongPrototype.notEquals = function notEquals(other) { - return !this.eq(/* validates */ other); - }; - - /** - * Tests if this Long's value differs from the specified's. This is an alias of {@link Long#notEquals}. - * @function - * @param {!Long|number|string} other Other value - * @returns {boolean} - */ - LongPrototype.neq = LongPrototype.notEquals; - - /** - * Tests if this Long's value is less than the specified's. - * @param {!Long|number|string} other Other value - * @returns {boolean} - */ - LongPrototype.lessThan = function lessThan(other) { - return this.comp(/* validates */ other) < 0; - }; - - /** - * Tests if this Long's value is less than the specified's. This is an alias of {@link Long#lessThan}. - * @function - * @param {!Long|number|string} other Other value - * @returns {boolean} - */ - LongPrototype.lt = LongPrototype.lessThan; - - /** - * Tests if this Long's value is less than or equal the specified's. - * @param {!Long|number|string} other Other value - * @returns {boolean} - */ - LongPrototype.lessThanOrEqual = function lessThanOrEqual(other) { - return this.comp(/* validates */ other) <= 0; - }; - - /** - * Tests if this Long's value is less than or equal the specified's. This is an alias of {@link Long#lessThanOrEqual}. - * @function - * @param {!Long|number|string} other Other value - * @returns {boolean} - */ - LongPrototype.lte = LongPrototype.lessThanOrEqual; - - /** - * Tests if this Long's value is greater than the specified's. - * @param {!Long|number|string} other Other value - * @returns {boolean} - */ - LongPrototype.greaterThan = function greaterThan(other) { - return this.comp(/* validates */ other) > 0; - }; - - /** - * Tests if this Long's value is greater than the specified's. This is an alias of {@link Long#greaterThan}. - * @function - * @param {!Long|number|string} other Other value - * @returns {boolean} - */ - LongPrototype.gt = LongPrototype.greaterThan; - - /** - * Tests if this Long's value is greater than or equal the specified's. - * @param {!Long|number|string} other Other value - * @returns {boolean} - */ - LongPrototype.greaterThanOrEqual = function greaterThanOrEqual(other) { - return this.comp(/* validates */ other) >= 0; - }; - - /** - * Tests if this Long's value is greater than or equal the specified's. This is an alias of {@link Long#greaterThanOrEqual}. - * @function - * @param {!Long|number|string} other Other value - * @returns {boolean} - */ - LongPrototype.gte = LongPrototype.greaterThanOrEqual; - - /** - * Compares this Long's value with the specified's. - * @param {!Long|number|string} other Other value - * @returns {number} 0 if they are the same, 1 if the this is greater and -1 - * if the given one is greater - */ - LongPrototype.compare = function compare(other) { - if (!isLong(other)) - other = fromValue(other); - if (this.eq(other)) - return 0; - var thisNeg = this.isNegative(), - otherNeg = other.isNegative(); - if (thisNeg && !otherNeg) - return -1; - if (!thisNeg && otherNeg) - return 1; - // At this point the sign bits are the same - if (!this.unsigned) - return this.sub(other).isNegative() ? -1 : 1; - // Both are positive if at least one is unsigned - return (other.high >>> 0) > (this.high >>> 0) || (other.high === this.high && (other.low >>> 0) > (this.low >>> 0)) ? -1 : 1; - }; - - /** - * Compares this Long's value with the specified's. This is an alias of {@link Long#compare}. - * @function - * @param {!Long|number|string} other Other value - * @returns {number} 0 if they are the same, 1 if the this is greater and -1 - * if the given one is greater - */ - LongPrototype.comp = LongPrototype.compare; - - /** - * Negates this Long's value. - * @returns {!Long} Negated Long - */ - LongPrototype.negate = function negate() { - if (!this.unsigned && this.eq(MIN_VALUE)) - return MIN_VALUE; - return this.not().add(ONE); - }; - - /** - * Negates this Long's value. This is an alias of {@link Long#negate}. - * @function - * @returns {!Long} Negated Long - */ - LongPrototype.neg = LongPrototype.negate; - - /** - * Returns the sum of this and the specified Long. - * @param {!Long|number|string} addend Addend - * @returns {!Long} Sum - */ - LongPrototype.add = function add(addend) { - if (!isLong(addend)) - addend = fromValue(addend); - - // Divide each number into 4 chunks of 16 bits, and then sum the chunks. - - var a48 = this.high >>> 16; - var a32 = this.high & 0xFFFF; - var a16 = this.low >>> 16; - var a00 = this.low & 0xFFFF; - - var b48 = addend.high >>> 16; - var b32 = addend.high & 0xFFFF; - var b16 = addend.low >>> 16; - var b00 = addend.low & 0xFFFF; - - var c48 = 0, c32 = 0, c16 = 0, c00 = 0; - c00 += a00 + b00; - c16 += c00 >>> 16; - c00 &= 0xFFFF; - c16 += a16 + b16; - c32 += c16 >>> 16; - c16 &= 0xFFFF; - c32 += a32 + b32; - c48 += c32 >>> 16; - c32 &= 0xFFFF; - c48 += a48 + b48; - c48 &= 0xFFFF; - return fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned); - }; - - /** - * Returns the difference of this and the specified Long. - * @param {!Long|number|string} subtrahend Subtrahend - * @returns {!Long} Difference - */ - LongPrototype.subtract = function subtract(subtrahend) { - if (!isLong(subtrahend)) - subtrahend = fromValue(subtrahend); - return this.add(subtrahend.neg()); - }; - - /** - * Returns the difference of this and the specified Long. This is an alias of {@link Long#subtract}. - * @function - * @param {!Long|number|string} subtrahend Subtrahend - * @returns {!Long} Difference - */ - LongPrototype.sub = LongPrototype.subtract; - - /** - * Returns the product of this and the specified Long. - * @param {!Long|number|string} multiplier Multiplier - * @returns {!Long} Product - */ - LongPrototype.multiply = function multiply(multiplier) { - if (this.isZero()) - return ZERO; - if (!isLong(multiplier)) - multiplier = fromValue(multiplier); - if (multiplier.isZero()) - return ZERO; - if (this.eq(MIN_VALUE)) - return multiplier.isOdd() ? MIN_VALUE : ZERO; - if (multiplier.eq(MIN_VALUE)) - return this.isOdd() ? MIN_VALUE : ZERO; - - if (this.isNegative()) { - if (multiplier.isNegative()) - return this.neg().mul(multiplier.neg()); - else - return this.neg().mul(multiplier).neg(); - } else if (multiplier.isNegative()) - return this.mul(multiplier.neg()).neg(); - - // If both longs are small, use float multiplication - if (this.lt(TWO_PWR_24) && multiplier.lt(TWO_PWR_24)) - return fromNumber(this.toNumber() * multiplier.toNumber(), this.unsigned); - - // Divide each long into 4 chunks of 16 bits, and then add up 4x4 products. - // We can skip products that would overflow. - - var a48 = this.high >>> 16; - var a32 = this.high & 0xFFFF; - var a16 = this.low >>> 16; - var a00 = this.low & 0xFFFF; - - var b48 = multiplier.high >>> 16; - var b32 = multiplier.high & 0xFFFF; - var b16 = multiplier.low >>> 16; - var b00 = multiplier.low & 0xFFFF; - - var c48 = 0, c32 = 0, c16 = 0, c00 = 0; - c00 += a00 * b00; - c16 += c00 >>> 16; - c00 &= 0xFFFF; - c16 += a16 * b00; - c32 += c16 >>> 16; - c16 &= 0xFFFF; - c16 += a00 * b16; - c32 += c16 >>> 16; - c16 &= 0xFFFF; - c32 += a32 * b00; - c48 += c32 >>> 16; - c32 &= 0xFFFF; - c32 += a16 * b16; - c48 += c32 >>> 16; - c32 &= 0xFFFF; - c32 += a00 * b32; - c48 += c32 >>> 16; - c32 &= 0xFFFF; - c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48; - c48 &= 0xFFFF; - return fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned); - }; - - /** - * Returns the product of this and the specified Long. This is an alias of {@link Long#multiply}. - * @function - * @param {!Long|number|string} multiplier Multiplier - * @returns {!Long} Product - */ - LongPrototype.mul = LongPrototype.multiply; - - /** - * Returns this Long divided by the specified. The result is signed if this Long is signed or - * unsigned if this Long is unsigned. - * @param {!Long|number|string} divisor Divisor - * @returns {!Long} Quotient - */ - LongPrototype.divide = function divide(divisor) { - if (!isLong(divisor)) - divisor = fromValue(divisor); - if (divisor.isZero()) - throw Error('division by zero'); - if (this.isZero()) - return this.unsigned ? UZERO : ZERO; - var approx, rem, res; - if (!this.unsigned) { - // This section is only relevant for signed longs and is derived from the - // closure library as a whole. - if (this.eq(MIN_VALUE)) { - if (divisor.eq(ONE) || divisor.eq(NEG_ONE)) - return MIN_VALUE; // recall that -MIN_VALUE == MIN_VALUE - else if (divisor.eq(MIN_VALUE)) - return ONE; - else { - // At this point, we have |other| >= 2, so |this/other| < |MIN_VALUE|. - var halfThis = this.shr(1); - approx = halfThis.div(divisor).shl(1); - if (approx.eq(ZERO)) { - return divisor.isNegative() ? ONE : NEG_ONE; - } else { - rem = this.sub(divisor.mul(approx)); - res = approx.add(rem.div(divisor)); - return res; - } - } - } else if (divisor.eq(MIN_VALUE)) - return this.unsigned ? UZERO : ZERO; - if (this.isNegative()) { - if (divisor.isNegative()) - return this.neg().div(divisor.neg()); - return this.neg().div(divisor).neg(); - } else if (divisor.isNegative()) - return this.div(divisor.neg()).neg(); - res = ZERO; - } else { - // The algorithm below has not been made for unsigned longs. It's therefore - // required to take special care of the MSB prior to running it. - if (!divisor.unsigned) - divisor = divisor.toUnsigned(); - if (divisor.gt(this)) - return UZERO; - if (divisor.gt(this.shru(1))) // 15 >>> 1 = 7 ; with divisor = 8 ; true - return UONE; - res = UZERO; - } - - // Repeat the following until the remainder is less than other: find a - // floating-point that approximates remainder / other *from below*, add this - // into the result, and subtract it from the remainder. It is critical that - // the approximate value is less than or equal to the real value so that the - // remainder never becomes negative. - rem = this; - while (rem.gte(divisor)) { - // Approximate the result of division. This may be a little greater or - // smaller than the actual value. - approx = Math.max(1, Math.floor(rem.toNumber() / divisor.toNumber())); - - // We will tweak the approximate result by changing it in the 48-th digit or - // the smallest non-fractional digit, whichever is larger. - var log2 = Math.ceil(Math.log(approx) / Math.LN2), - delta = (log2 <= 48) ? 1 : pow_dbl(2, log2 - 48), - - // Decrease the approximation until it is smaller than the remainder. Note - // that if it is too large, the product overflows and is negative. - approxRes = fromNumber(approx), - approxRem = approxRes.mul(divisor); - while (approxRem.isNegative() || approxRem.gt(rem)) { - approx -= delta; - approxRes = fromNumber(approx, this.unsigned); - approxRem = approxRes.mul(divisor); - } - - // We know the answer can't be zero... and actually, zero would cause - // infinite recursion since we would make no progress. - if (approxRes.isZero()) - approxRes = ONE; - - res = res.add(approxRes); - rem = rem.sub(approxRem); - } - return res; - }; - - /** - * Returns this Long divided by the specified. This is an alias of {@link Long#divide}. - * @function - * @param {!Long|number|string} divisor Divisor - * @returns {!Long} Quotient - */ - LongPrototype.div = LongPrototype.divide; - - /** - * Returns this Long modulo the specified. - * @param {!Long|number|string} divisor Divisor - * @returns {!Long} Remainder - */ - LongPrototype.modulo = function modulo(divisor) { - if (!isLong(divisor)) - divisor = fromValue(divisor); - return this.sub(this.div(divisor).mul(divisor)); - }; - - /** - * Returns this Long modulo the specified. This is an alias of {@link Long#modulo}. - * @function - * @param {!Long|number|string} divisor Divisor - * @returns {!Long} Remainder - */ - LongPrototype.mod = LongPrototype.modulo; - - /** - * Returns the bitwise NOT of this Long. - * @returns {!Long} - */ - LongPrototype.not = function not() { - return fromBits(~this.low, ~this.high, this.unsigned); - }; - - /** - * Returns the bitwise AND of this Long and the specified. - * @param {!Long|number|string} other Other Long - * @returns {!Long} - */ - LongPrototype.and = function and(other) { - if (!isLong(other)) - other = fromValue(other); - return fromBits(this.low & other.low, this.high & other.high, this.unsigned); - }; - - /** - * Returns the bitwise OR of this Long and the specified. - * @param {!Long|number|string} other Other Long - * @returns {!Long} - */ - LongPrototype.or = function or(other) { - if (!isLong(other)) - other = fromValue(other); - return fromBits(this.low | other.low, this.high | other.high, this.unsigned); - }; - - /** - * Returns the bitwise XOR of this Long and the given one. - * @param {!Long|number|string} other Other Long - * @returns {!Long} - */ - LongPrototype.xor = function xor(other) { - if (!isLong(other)) - other = fromValue(other); - return fromBits(this.low ^ other.low, this.high ^ other.high, this.unsigned); - }; - - /** - * Returns this Long with bits shifted to the left by the given amount. - * @param {number|!Long} numBits Number of bits - * @returns {!Long} Shifted Long - */ - LongPrototype.shiftLeft = function shiftLeft(numBits) { - if (isLong(numBits)) - numBits = numBits.toInt(); - if ((numBits &= 63) === 0) - return this; - else if (numBits < 32) - return fromBits(this.low << numBits, (this.high << numBits) | (this.low >>> (32 - numBits)), this.unsigned); - else - return fromBits(0, this.low << (numBits - 32), this.unsigned); - }; - - /** - * Returns this Long with bits shifted to the left by the given amount. This is an alias of {@link Long#shiftLeft}. - * @function - * @param {number|!Long} numBits Number of bits - * @returns {!Long} Shifted Long - */ - LongPrototype.shl = LongPrototype.shiftLeft; - - /** - * Returns this Long with bits arithmetically shifted to the right by the given amount. - * @param {number|!Long} numBits Number of bits - * @returns {!Long} Shifted Long - */ - LongPrototype.shiftRight = function shiftRight(numBits) { - if (isLong(numBits)) - numBits = numBits.toInt(); - if ((numBits &= 63) === 0) - return this; - else if (numBits < 32) - return fromBits((this.low >>> numBits) | (this.high << (32 - numBits)), this.high >> numBits, this.unsigned); - else - return fromBits(this.high >> (numBits - 32), this.high >= 0 ? 0 : -1, this.unsigned); - }; - - /** - * Returns this Long with bits arithmetically shifted to the right by the given amount. This is an alias of {@link Long#shiftRight}. - * @function - * @param {number|!Long} numBits Number of bits - * @returns {!Long} Shifted Long - */ - LongPrototype.shr = LongPrototype.shiftRight; - - /** - * Returns this Long with bits logically shifted to the right by the given amount. - * @param {number|!Long} numBits Number of bits - * @returns {!Long} Shifted Long - */ - LongPrototype.shiftRightUnsigned = function shiftRightUnsigned(numBits) { - if (isLong(numBits)) - numBits = numBits.toInt(); - numBits &= 63; - if (numBits === 0) - return this; - else { - var high = this.high; - if (numBits < 32) { - var low = this.low; - return fromBits((low >>> numBits) | (high << (32 - numBits)), high >>> numBits, this.unsigned); - } else if (numBits === 32) - return fromBits(high, 0, this.unsigned); - else - return fromBits(high >>> (numBits - 32), 0, this.unsigned); - } - }; - - /** - * Returns this Long with bits logically shifted to the right by the given amount. This is an alias of {@link Long#shiftRightUnsigned}. - * @function - * @param {number|!Long} numBits Number of bits - * @returns {!Long} Shifted Long - */ - LongPrototype.shru = LongPrototype.shiftRightUnsigned; - - /** - * Converts this Long to signed. - * @returns {!Long} Signed long - */ - LongPrototype.toSigned = function toSigned() { - if (!this.unsigned) - return this; - return fromBits(this.low, this.high, false); - }; - - /** - * Converts this Long to unsigned. - * @returns {!Long} Unsigned long - */ - LongPrototype.toUnsigned = function toUnsigned() { - if (this.unsigned) - return this; - return fromBits(this.low, this.high, true); - }; - - /** - * Converts this Long to its byte representation. - * @param {boolean=} le Whether little or big endian, defaults to big endian - * @returns {!Array.} Byte representation - */ - LongPrototype.toBytes = function(le) { - return le ? this.toBytesLE() : this.toBytesBE(); - } - - /** - * Converts this Long to its little endian byte representation. - * @returns {!Array.} Little endian byte representation - */ - LongPrototype.toBytesLE = function() { - var hi = this.high, - lo = this.low; - return [ - lo & 0xff, - (lo >>> 8) & 0xff, - (lo >>> 16) & 0xff, - (lo >>> 24) & 0xff, - hi & 0xff, - (hi >>> 8) & 0xff, - (hi >>> 16) & 0xff, - (hi >>> 24) & 0xff - ]; - } - - /** - * Converts this Long to its big endian byte representation. - * @returns {!Array.} Big endian byte representation - */ - LongPrototype.toBytesBE = function() { - var hi = this.high, - lo = this.low; - return [ - (hi >>> 24) & 0xff, - (hi >>> 16) & 0xff, - (hi >>> 8) & 0xff, - hi & 0xff, - (lo >>> 24) & 0xff, - (lo >>> 16) & 0xff, - (lo >>> 8) & 0xff, - lo & 0xff - ]; - } - - return Long; -}); -;/* +; +!function(t,i){"object"==typeof exports&&"object"==typeof module?module.exports=i():"function"==typeof define&&define.amd?define([],i):"object"==typeof exports?exports.Long=i():t.Long=i()}("undefined"!=typeof self?self:this,function(){return function(t){function i(e){if(n[e])return n[e].exports;var r=n[e]={i:e,l:!1,exports:{}};return t[e].call(r.exports,r,r.exports,i),r.l=!0,r.exports}var n={};return i.m=t,i.c=n,i.d=function(t,n,e){i.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:e})},i.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(n,"a",n),n},i.o=function(t,i){return Object.prototype.hasOwnProperty.call(t,i)},i.p="",i(i.s=0)}([function(t,i){function n(t,i,n){this.low=0|t,this.high=0|i,this.unsigned=!!n}function e(t){return!0===(t&&t.__isLong__)}function r(t,i){var n,e,r;return i?(t>>>=0,(r=0<=t&&t<256)&&(e=l[t])?e:(n=h(t,(0|t)<0?-1:0,!0),r&&(l[t]=n),n)):(t|=0,(r=-128<=t&&t<128)&&(e=f[t])?e:(n=h(t,t<0?-1:0,!1),r&&(f[t]=n),n))}function s(t,i){if(isNaN(t))return i?p:m;if(i){if(t<0)return p;if(t>=c)return q}else{if(t<=-v)return _;if(t+1>=v)return E}return t<0?s(-t,i).neg():h(t%d|0,t/d|0,i)}function h(t,i,e){return new n(t,i,e)}function u(t,i,n){if(0===t.length)throw Error("empty string");if("NaN"===t||"Infinity"===t||"+Infinity"===t||"-Infinity"===t)return m;if("number"==typeof i?(n=i,i=!1):i=!!i,(n=n||10)<2||360)throw Error("interior hyphen");if(0===e)return u(t.substring(1),i,n).neg();for(var r=s(a(n,8)),h=m,o=0;o>>0:this.low},B.toNumber=function(){return this.unsigned?(this.high>>>0)*d+(this.low>>>0):this.high*d+(this.low>>>0)},B.toString=function(t){if((t=t||10)<2||36>>0,f=g.toString(t);if(h=o,h.isZero())return f+u;for(;f.length<6;)f="0"+f;u=""+f+u}},B.getHighBits=function(){return this.high},B.getHighBitsUnsigned=function(){return this.high>>>0},B.getLowBits=function(){return this.low},B.getLowBitsUnsigned=function(){return this.low>>>0},B.getNumBitsAbs=function(){if(this.isNegative())return this.eq(_)?64:this.neg().getNumBitsAbs();for(var t=0!=this.high?this.high:this.low,i=31;i>0&&0==(t&1<=0},B.isOdd=function(){return 1==(1&this.low)},B.isEven=function(){return 0==(1&this.low)},B.equals=function(t){return e(t)||(t=o(t)),(this.unsigned===t.unsigned||this.high>>>31!=1||t.high>>>31!=1)&&(this.high===t.high&&this.low===t.low)},B.eq=B.equals,B.notEquals=function(t){return!this.eq(t)},B.neq=B.notEquals,B.ne=B.notEquals,B.lessThan=function(t){return this.comp(t)<0},B.lt=B.lessThan,B.lessThanOrEqual=function(t){return this.comp(t)<=0},B.lte=B.lessThanOrEqual,B.le=B.lessThanOrEqual,B.greaterThan=function(t){return this.comp(t)>0},B.gt=B.greaterThan,B.greaterThanOrEqual=function(t){return this.comp(t)>=0},B.gte=B.greaterThanOrEqual,B.ge=B.greaterThanOrEqual,B.compare=function(t){if(e(t)||(t=o(t)),this.eq(t))return 0;var i=this.isNegative(),n=t.isNegative();return i&&!n?-1:!i&&n?1:this.unsigned?t.high>>>0>this.high>>>0||t.high===this.high&&t.low>>>0>this.low>>>0?-1:1:this.sub(t).isNegative()?-1:1},B.comp=B.compare,B.negate=function(){return!this.unsigned&&this.eq(_)?_:this.not().add(y)},B.neg=B.negate,B.add=function(t){e(t)||(t=o(t));var i=this.high>>>16,n=65535&this.high,r=this.low>>>16,s=65535&this.low,u=t.high>>>16,g=65535&t.high,f=t.low>>>16,l=65535&t.low,a=0,d=0,c=0,v=0;return v+=s+l,c+=v>>>16,v&=65535,c+=r+f,d+=c>>>16,c&=65535,d+=n+g,a+=d>>>16,d&=65535,a+=i+u,a&=65535,h(c<<16|v,a<<16|d,this.unsigned)},B.subtract=function(t){return e(t)||(t=o(t)),this.add(t.neg())},B.sub=B.subtract,B.multiply=function(t){if(this.isZero())return m;if(e(t)||(t=o(t)),g){return h(g.mul(this.low,this.high,t.low,t.high),g.get_high(),this.unsigned)}if(t.isZero())return m;if(this.eq(_))return t.isOdd()?_:m;if(t.eq(_))return this.isOdd()?_:m;if(this.isNegative())return t.isNegative()?this.neg().mul(t.neg()):this.neg().mul(t).neg();if(t.isNegative())return this.mul(t.neg()).neg();if(this.lt(w)&&t.lt(w))return s(this.toNumber()*t.toNumber(),this.unsigned);var i=this.high>>>16,n=65535&this.high,r=this.low>>>16,u=65535&this.low,f=t.high>>>16,l=65535&t.high,a=t.low>>>16,d=65535&t.low,c=0,v=0,p=0,y=0;return y+=u*d,p+=y>>>16,y&=65535,p+=r*d,v+=p>>>16,p&=65535,p+=u*a,v+=p>>>16,p&=65535,v+=n*d,c+=v>>>16,v&=65535,v+=r*a,c+=v>>>16,v&=65535,v+=u*l,c+=v>>>16,v&=65535,c+=i*d+n*a+r*l+u*f,c&=65535,h(p<<16|y,c<<16|v,this.unsigned)},B.mul=B.multiply,B.divide=function(t){if(e(t)||(t=o(t)),t.isZero())throw Error("division by zero");if(g){if(!this.unsigned&&-2147483648===this.high&&-1===t.low&&-1===t.high)return this;return h((this.unsigned?g.div_u:g.div_s)(this.low,this.high,t.low,t.high),g.get_high(),this.unsigned)}if(this.isZero())return this.unsigned?p:m;var i,n,r;if(this.unsigned){if(t.unsigned||(t=t.toUnsigned()),t.gt(this))return p;if(t.gt(this.shru(1)))return b;r=p}else{if(this.eq(_)){if(t.eq(y)||t.eq(N))return _;if(t.eq(_))return y;return i=this.shr(1).div(t).shl(1),i.eq(m)?t.isNegative()?y:N:(n=this.sub(t.mul(i)),r=i.add(n.div(t)))}if(t.eq(_))return this.unsigned?p:m;if(this.isNegative())return t.isNegative()?this.neg().div(t.neg()):this.neg().div(t).neg();if(t.isNegative())return this.div(t.neg()).neg();r=m}for(n=this;n.gte(t);){i=Math.max(1,Math.floor(n.toNumber()/t.toNumber()));for(var u=Math.ceil(Math.log(i)/Math.LN2),f=u<=48?1:a(2,u-48),l=s(i),d=l.mul(t);d.isNegative()||d.gt(n);)i-=f,l=s(i,this.unsigned),d=l.mul(t);l.isZero()&&(l=y),r=r.add(l),n=n.sub(d)}return r},B.div=B.divide,B.modulo=function(t){if(e(t)||(t=o(t)),g){return h((this.unsigned?g.rem_u:g.rem_s)(this.low,this.high,t.low,t.high),g.get_high(),this.unsigned)}return this.sub(this.div(t).mul(t))},B.mod=B.modulo,B.rem=B.modulo,B.not=function(){return h(~this.low,~this.high,this.unsigned)},B.and=function(t){return e(t)||(t=o(t)),h(this.low&t.low,this.high&t.high,this.unsigned)},B.or=function(t){return e(t)||(t=o(t)),h(this.low|t.low,this.high|t.high,this.unsigned)},B.xor=function(t){return e(t)||(t=o(t)),h(this.low^t.low,this.high^t.high,this.unsigned)},B.shiftLeft=function(t){return e(t)&&(t=t.toInt()),0==(t&=63)?this:t<32?h(this.low<>>32-t,this.unsigned):h(0,this.low<>>t|this.high<<32-t,this.high>>t,this.unsigned):h(this.high>>t-32,this.high>=0?0:-1,this.unsigned)},B.shr=B.shiftRight,B.shiftRightUnsigned=function(t){if(e(t)&&(t=t.toInt()),0===(t&=63))return this;var i=this.high;if(t<32){return h(this.low>>>t|i<<32-t,i>>>t,this.unsigned)}return 32===t?h(i,0,this.unsigned):h(i>>>t-32,0,this.unsigned)},B.shru=B.shiftRightUnsigned,B.shr_u=B.shiftRightUnsigned,B.toSigned=function(){return this.unsigned?h(this.low,this.high,!1):this},B.toUnsigned=function(){return this.unsigned?this:h(this.low,this.high,!0)},B.toBytes=function(t){return t?this.toBytesLE():this.toBytesBE()},B.toBytesLE=function(){var t=this.high,i=this.low;return[255&i,i>>>8&255,i>>>16&255,i>>>24,255&t,t>>>8&255,t>>>16&255,t>>>24]},B.toBytesBE=function(){var t=this.high,i=this.low;return[t>>>24,t>>>16&255,t>>>8&255,255&t,i>>>24,i>>>16&255,i>>>8&255,255&i]},n.fromBytes=function(t,i,e){return e?n.fromBytesLE(t,i):n.fromBytesBE(t,i)},n.fromBytesLE=function(t,i){return new n(t[0]|t[1]<<8|t[2]<<16|t[3]<<24,t[4]|t[5]<<8|t[6]<<16|t[7]<<24,i)},n.fromBytesBE=function(t,i){return new n(t[4]<<24|t[5]<<16|t[6]<<8|t[7],t[0]<<24|t[1]<<16|t[2]<<8|t[3],i)}}])}); +//# sourceMappingURL=long.js.map; +/* * slip.js: A plain JavaScript SLIP implementation that works in both the browser and Node.js * * Copyright 2014, Colin Clark @@ -2498,14 +1291,15 @@ var osc = osc || {}; return slip; })); -;/*! - * EventEmitter v5.0.0 - git.io/ee +; +/*! + * EventEmitter v5.2.4 - git.io/ee * Unlicense - http://unlicense.org/ * Oliver Caldwell - http://oli.me.uk/ * @preserve */ -;(function () { +;(function (exports) { 'use strict'; /** @@ -2518,7 +1312,6 @@ var osc = osc || {}; // Shortcuts to improve speed and size var proto = EventEmitter.prototype; - var exports = this; var originalGlobalValue = exports.EventEmitter; /** @@ -2619,6 +1412,16 @@ var osc = osc || {}; return response || listeners; }; + function isValidListener (listener) { + if (typeof listener === 'function' || listener instanceof RegExp) { + return true + } else if (listener && typeof listener === 'object') { + return isValidListener(listener.listener) + } else { + return false + } + } + /** * Adds a listener function to the specified event. * The listener will not be added if it is a duplicate. @@ -2630,6 +1433,10 @@ var osc = osc || {}; * @return {Object} Current instance of EventEmitter for chaining. */ proto.addListener = function addListener(evt, listener) { + if (!isValidListener(listener)) { + throw new TypeError('listener must be a function'); + } + var listeners = this.getListenersAsObject(evt); var listenerIsWrapped = typeof listener === 'object'; var key; @@ -2729,7 +1536,7 @@ var osc = osc || {}; /** * Adds listeners in bulk using the manipulateListeners method. - * If you pass an object as the second argument you can add to multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. You can also pass it an event name and an array of listeners to be added. + * If you pass an object as the first argument you can add to multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. You can also pass it an event name and an array of listeners to be added. * You can also pass it a regular expression to add the array of listeners to all events that match it. * Yeah, this function does quite a bit. That's probably a bad thing. * @@ -2744,7 +1551,7 @@ var osc = osc || {}; /** * Removes listeners in bulk using the manipulateListeners method. - * If you pass an object as the second argument you can remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. + * If you pass an object as the first argument you can remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. * You can also pass it an event name and an array of listeners to be removed. * You can also pass it a regular expression to remove the listeners from all events that match it. * @@ -2970,8 +1777,9 @@ var osc = osc || {}; else { exports.EventEmitter = EventEmitter; } -}.call(this)); -;/* +}(this || {})); +; +/* * osc.js: An Open Sound Control library for JavaScript that works in both the browser and Node.js * * Cross-platform base transport library for osc.js. @@ -3192,7 +2000,8 @@ var osc = osc || require("./osc.js"), module.exports = osc; } }()); -;/* +; +/* * osc.js: An Open Sound Control library for JavaScript that works in both the browser and Node.js * * Cross-Platform Web Socket client transport for osc.js. diff --git a/dist/osc-browser.min.js b/dist/osc-browser.min.js index cd7da6d..95562b7 100644 --- a/dist/osc-browser.min.js +++ b/dist/osc-browser.min.js @@ -1,3 +1,882 @@ -/*! osc.js 2.2.0, Copyright 2017 Colin Clark | github.com/colinbdclark/osc.js */ +/*! osc.js 2.2.1, Copyright 2018 Colin Clark | github.com/colinbdclark/osc.js */ -var osc=osc||{};!function(){"use strict";osc.SECS_70YRS=2208988800,osc.TWO_32=4294967296,osc.defaults={metadata:!1,unpackSingleArgs:!0},osc.isCommonJS=!("undefined"==typeof module||!module.exports),osc.isNode=osc.isCommonJS&&"undefined"==typeof window,osc.isElectron=!("undefined"==typeof process||!process.versions||!process.versions.electron),osc.isBufferEnv=osc.isNode||osc.isElectron,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};var a="undefined"!=typeof dcodeIO?dcodeIO.Long:"undefined"!=typeof a?a:osc.isNode?require("long"):void 0;osc.dataView=function(a,b,c){return a.buffer?new DataView(a.buffer,b,c):a instanceof ArrayBuffer?new DataView(a,b,c):new DataView(new Uint8Array(a),b,c)},osc.byteArray=function(a){if(a instanceof Uint8Array)return a;var b=a.buffer?a.buffer:a;if(!(b instanceof ArrayBuffer||"undefined"!=typeof b.length&&"string"!=typeof b))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.nativeBuffer=function(a){return osc.isBufferEnv?osc.isBuffer(a)?a:new Buffer(a.buffer?a:new Uint8Array(a)):osc.isTypedArrayView(a)?a:new Uint8Array(a)},osc.copyByteArray=function(a,b,c){if(osc.isTypedArrayView(a)&&osc.isTypedArrayView(b))b.set(a,c);else for(var d=void 0===c?0:c,e=Math.min(b.length-c,a.length),f=0,g=d;f1){var i=Math.floor(h),j=h-i;f+=i,h=j}var k=d+f+osc.SECS_70YRS,l=Math.round(osc.TWO_32*h);return{raw:[k,l]}},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>>=0,(f=0<=a&&a<256)&&(d=i[a])?d:(c=e(a,(0|a)<0?-1:0,!0),f&&(i[a]=c),c)):(a|=0,(f=-128<=a&&a<128)&&(d=h[a])?d:(c=e(a,a<0?-1:0,!1),f&&(h[a]=c),c))}function d(a,b){if(isNaN(a)||!isFinite(a))return b?q:p;if(b){if(a<0)return q;if(a>=m)return v}else{if(a<=-n)return w;if(a+1>=n)return u}return a<0?d(-a,b).neg():e(a%l|0,a/l|0,b)}function e(b,c,d){return new a(b,c,d)}function f(a,b,c){if(0===a.length)throw Error("empty string");if("NaN"===a||"Infinity"===a||"+Infinity"===a||"-Infinity"===a)return p;if("number"==typeof b?(c=b,b=!1):b=!!b,c=c||10,c<2||360)throw Error("interior hyphen");if(0===e)return f(a.substring(1),b,c).neg();for(var g=d(j(c,8)),h=p,i=0;i>>0:this.low},x.toNumber=function(){return this.unsigned?(this.high>>>0)*l+(this.low>>>0):this.high*l+(this.low>>>0)},x.toString=function(a){if(a=a||10,a<2||36>>0,l=k.toString(a);if(g=i,g.isZero())return l+h;for(;l.length<6;)l="0"+l;h=""+l+h}},x.getHighBits=function(){return this.high},x.getHighBitsUnsigned=function(){return this.high>>>0},x.getLowBits=function(){return this.low},x.getLowBitsUnsigned=function(){return this.low>>>0},x.getNumBitsAbs=function(){if(this.isNegative())return this.eq(w)?64:this.neg().getNumBitsAbs();for(var a=0!=this.high?this.high:this.low,b=31;b>0&&0==(a&1<=0},x.isOdd=function(){return 1===(1&this.low)},x.isEven=function(){return 0===(1&this.low)},x.equals=function(a){return b(a)||(a=g(a)),(this.unsigned===a.unsigned||this.high>>>31!==1||a.high>>>31!==1)&&(this.high===a.high&&this.low===a.low)},x.eq=x.equals,x.notEquals=function(a){return!this.eq(a)},x.neq=x.notEquals,x.lessThan=function(a){return this.comp(a)<0},x.lt=x.lessThan,x.lessThanOrEqual=function(a){return this.comp(a)<=0},x.lte=x.lessThanOrEqual,x.greaterThan=function(a){return this.comp(a)>0},x.gt=x.greaterThan,x.greaterThanOrEqual=function(a){return this.comp(a)>=0},x.gte=x.greaterThanOrEqual,x.compare=function(a){if(b(a)||(a=g(a)),this.eq(a))return 0;var c=this.isNegative(),d=a.isNegative();return c&&!d?-1:!c&&d?1:this.unsigned?a.high>>>0>this.high>>>0||a.high===this.high&&a.low>>>0>this.low>>>0?-1:1:this.sub(a).isNegative()?-1:1},x.comp=x.compare,x.negate=function(){return!this.unsigned&&this.eq(w)?w:this.not().add(r)},x.neg=x.negate,x.add=function(a){b(a)||(a=g(a));var c=this.high>>>16,d=65535&this.high,f=this.low>>>16,h=65535&this.low,i=a.high>>>16,j=65535&a.high,k=a.low>>>16,l=65535&a.low,m=0,n=0,o=0,p=0;return p+=h+l,o+=p>>>16,p&=65535,o+=f+k,n+=o>>>16,o&=65535,n+=d+j,m+=n>>>16,n&=65535,m+=c+i,m&=65535,e(o<<16|p,m<<16|n,this.unsigned)},x.subtract=function(a){return b(a)||(a=g(a)),this.add(a.neg())},x.sub=x.subtract,x.multiply=function(a){if(this.isZero())return p;if(b(a)||(a=g(a)),a.isZero())return p;if(this.eq(w))return a.isOdd()?w:p;if(a.eq(w))return this.isOdd()?w:p;if(this.isNegative())return a.isNegative()?this.neg().mul(a.neg()):this.neg().mul(a).neg();if(a.isNegative())return this.mul(a.neg()).neg();if(this.lt(o)&&a.lt(o))return d(this.toNumber()*a.toNumber(),this.unsigned);var c=this.high>>>16,f=65535&this.high,h=this.low>>>16,i=65535&this.low,j=a.high>>>16,k=65535&a.high,l=a.low>>>16,m=65535&a.low,n=0,q=0,r=0,s=0;return s+=i*m,r+=s>>>16,s&=65535,r+=h*m,q+=r>>>16,r&=65535,r+=i*l,q+=r>>>16,r&=65535,q+=f*m,n+=q>>>16,q&=65535,q+=h*l,n+=q>>>16,q&=65535,q+=i*k,n+=q>>>16,q&=65535,n+=c*m+f*l+h*k+i*j,n&=65535,e(r<<16|s,n<<16|q,this.unsigned)},x.mul=x.multiply,x.divide=function(a){if(b(a)||(a=g(a)),a.isZero())throw Error("division by zero");if(this.isZero())return this.unsigned?q:p;var c,e,f;if(this.unsigned){if(a.unsigned||(a=a.toUnsigned()),a.gt(this))return q;if(a.gt(this.shru(1)))return s;f=q}else{if(this.eq(w)){if(a.eq(r)||a.eq(t))return w;if(a.eq(w))return r;var h=this.shr(1);return c=h.div(a).shl(1),c.eq(p)?a.isNegative()?r:t:(e=this.sub(a.mul(c)),f=c.add(e.div(a)))}if(a.eq(w))return this.unsigned?q:p;if(this.isNegative())return a.isNegative()?this.neg().div(a.neg()):this.neg().div(a).neg();if(a.isNegative())return this.div(a.neg()).neg();f=p}for(e=this;e.gte(a);){c=Math.max(1,Math.floor(e.toNumber()/a.toNumber()));for(var i=Math.ceil(Math.log(c)/Math.LN2),k=i<=48?1:j(2,i-48),l=d(c),m=l.mul(a);m.isNegative()||m.gt(e);)c-=k,l=d(c,this.unsigned),m=l.mul(a);l.isZero()&&(l=r),f=f.add(l),e=e.sub(m)}return f},x.div=x.divide,x.modulo=function(a){return b(a)||(a=g(a)),this.sub(this.div(a).mul(a))},x.mod=x.modulo,x.not=function(){return e(~this.low,~this.high,this.unsigned)},x.and=function(a){return b(a)||(a=g(a)),e(this.low&a.low,this.high&a.high,this.unsigned)},x.or=function(a){return b(a)||(a=g(a)),e(this.low|a.low,this.high|a.high,this.unsigned)},x.xor=function(a){return b(a)||(a=g(a)),e(this.low^a.low,this.high^a.high,this.unsigned)},x.shiftLeft=function(a){return b(a)&&(a=a.toInt()),0===(a&=63)?this:a<32?e(this.low<>>32-a,this.unsigned):e(0,this.low<>>a|this.high<<32-a,this.high>>a,this.unsigned):e(this.high>>a-32,this.high>=0?0:-1,this.unsigned)},x.shr=x.shiftRight,x.shiftRightUnsigned=function(a){if(b(a)&&(a=a.toInt()),a&=63,0===a)return this;var c=this.high;if(a<32){var d=this.low;return e(d>>>a|c<<32-a,c>>>a,this.unsigned)}return 32===a?e(c,0,this.unsigned):e(c>>>a-32,0,this.unsigned)},x.shru=x.shiftRightUnsigned,x.toSigned=function(){return this.unsigned?e(this.low,this.high,!1):this},x.toUnsigned=function(){return this.unsigned?this:e(this.low,this.high,!0)},x.toBytes=function(a){return a?this.toBytesLE():this.toBytesBE()},x.toBytesLE=function(){var a=this.high,b=this.low;return[255&b,b>>>8&255,b>>>16&255,b>>>24&255,255&a,a>>>8&255,a>>>16&255,a>>>24&255]},x.toBytesBE=function(){var a=this.high,b=this.low;return[a>>>24&255,a>>>16&255,a>>>8&255,255&a,b>>>24&255,b>>>16&255,b>>>8&255,255&b]},a}),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;ge.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;dthis.msgBuffer.length-1&&(this.msgBuffer=b.expandByteArray(this.msgBuffer)),this.msgBuffer[this.msgBufferIdx++]=a,this.escape=!1,this.msgBuffer.length1)&&(this.socket=new osc.WebSocket(this.options.url)),osc.WebSocketPort.setupSocketForBinary(this.socket);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,b)},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){return this.socket&&1===this.socket.readyState?void this.socket.send(a):void osc.fireClosedPortSendError(this)},a.close=function(a,b){this.socket.close(a,b)},osc.WebSocketPort.setupSocketForBinary=function(a){a.binaryType=osc.isNode?"nodebuffer":"arraybuffer"}}(); \ No newline at end of file + +var osc = osc || {}; + +!function() { + "use strict"; + osc.SECS_70YRS = 2208988800, osc.TWO_32 = 4294967296, osc.defaults = { + metadata: !1, + unpackSingleArgs: !0 + }, osc.isCommonJS = !("undefined" == typeof module || !module.exports), osc.isNode = osc.isCommonJS && "undefined" == typeof window, + osc.isElectron = !("undefined" == typeof process || !process.versions || !process.versions.electron), + osc.isBufferEnv = osc.isNode || osc.isElectron, osc.isArray = function(e) { + return e && "[object Array]" === Object.prototype.toString.call(e); + }, osc.isTypedArrayView = function(e) { + return e.buffer && e.buffer instanceof ArrayBuffer; + }, osc.isBuffer = function(e) { + return osc.isBufferEnv && e instanceof Buffer; + }, osc.Long = "undefined" != typeof Long ? Long : osc.isNode ? require("long") : void 0, + osc.dataView = function(e, t, r) { + return e.buffer ? new DataView(e.buffer, t, r) : e instanceof ArrayBuffer ? new DataView(e, t, r) : new DataView(new Uint8Array(e), t, r); + }, osc.byteArray = function(e) { + if (e instanceof Uint8Array) return e; + var t = e.buffer ? e.buffer : e; + if (!(t instanceof ArrayBuffer || void 0 !== t.length && "string" != typeof t)) throw new Error("Can't wrap a non-array-like object as Uint8Array. Object was: " + JSON.stringify(e, null, 2)); + return new Uint8Array(t); + }, osc.nativeBuffer = function(e) { + return osc.isBufferEnv ? osc.isBuffer(e) ? e : new Buffer(e.buffer ? e : new Uint8Array(e)) : osc.isTypedArrayView(e) ? e : new Uint8Array(e); + }, osc.copyByteArray = function(e, t, r) { + if (osc.isTypedArrayView(e) && osc.isTypedArrayView(t)) t.set(e, r); else for (var n = void 0 === r ? 0 : r, i = Math.min(t.length - r, e.length), s = 0, o = n; s < i; s++, + o++) t[o] = e[s]; + return t; + }, osc.readString = function(e, t) { + for (var r = [], n = t.idx; n < e.byteLength; n++) { + var i = e.getUint8(n); + if (0 === i) { + n++; + break; + } + r.push(i); + } + if (n = n + 3 & -4, t.idx = n, ("undefined" != typeof global ? global : window).hasOwnProperty("Buffer")) return Buffer.from ? Buffer.from(r).toString("utf-8") : new Buffer(r).toString("utf-8"); + if (("undefined" != typeof global ? global : window).hasOwnProperty("TextDecoder")) return new TextDecoder("utf-8").decode(new Int8Array(r)); + for (var s = "", o = 0; o < r.length; o += 1e4) s += String.fromCharCode.apply(null, r.slice(o, o + 1e4)); + return s; + }, osc.writeString = function(e) { + for (var t = e + "\0", r = t.length, n = new Uint8Array(r + 3 & -4), i = 0; i < t.length; i++) { + var s = t.charCodeAt(i); + n[i] = s; + } + return n; + }, osc.readPrimitive = function(e, t, r, n) { + var i = e[t](n.idx, !1); + return n.idx += r, i; + }, osc.writePrimitive = function(e, t, r, n, i) { + var s; + return i = void 0 === i ? 0 : i, t ? s = new Uint8Array(t.buffer) : (s = new Uint8Array(n), + t = new DataView(s.buffer)), t[r](i, e, !1), s; + }, osc.readInt32 = function(e, t) { + return osc.readPrimitive(e, "getInt32", 4, t); + }, osc.writeInt32 = function(e, t, r) { + return osc.writePrimitive(e, t, "setInt32", 4, r); + }, osc.readInt64 = function(e, t) { + var r = osc.readPrimitive(e, "getInt32", 4, t), n = osc.readPrimitive(e, "getInt32", 4, t); + return osc.Long ? new osc.Long(n, r) : { + high: r, + low: n, + unsigned: !1 + }; + }, osc.writeInt64 = function(e, t, r) { + var n = new Uint8Array(8); + return n.set(osc.writePrimitive(e.high, t, "setInt32", 4, r), 0), n.set(osc.writePrimitive(e.low, t, "setInt32", 4, r + 4), 4), + n; + }, osc.readFloat32 = function(e, t) { + return osc.readPrimitive(e, "getFloat32", 4, t); + }, osc.writeFloat32 = function(e, t, r) { + return osc.writePrimitive(e, t, "setFloat32", 4, r); + }, osc.readFloat64 = function(e, t) { + return osc.readPrimitive(e, "getFloat64", 8, t); + }, osc.writeFloat64 = function(e, t, r) { + return osc.writePrimitive(e, t, "setFloat64", 8, r); + }, osc.readChar32 = function(e, t) { + var r = osc.readPrimitive(e, "getUint32", 4, t); + return String.fromCharCode(r); + }, osc.writeChar32 = function(e, t, r) { + var n = e.charCodeAt(0); + if (!(void 0 === n || n < -1)) return osc.writePrimitive(n, t, "setUint32", 4, r); + }, osc.readBlob = function(e, t) { + var r = osc.readInt32(e, t), n = r + 3 & -4, i = new Uint8Array(e.buffer, t.idx, r); + return t.idx += n, i; + }, osc.writeBlob = function(e) { + var t = (e = osc.byteArray(e)).byteLength, r = new Uint8Array((t + 3 & -4) + 4), n = new DataView(r.buffer); + return osc.writeInt32(t, n), r.set(e, 4), r; + }, osc.readMIDIBytes = function(e, t) { + var r = new Uint8Array(e.buffer, t.idx, 4); + return t.idx += 4, r; + }, osc.writeMIDIBytes = function(e) { + e = osc.byteArray(e); + var t = new Uint8Array(4); + return t.set(e), t; + }, osc.readColor = function(e, t) { + var r = new Uint8Array(e.buffer, t.idx, 4), n = r[3] / 255; + return t.idx += 4, { + r: r[0], + g: r[1], + b: r[2], + a: n + }; + }, osc.writeColor = function(e) { + var t = Math.round(255 * e.a); + return new Uint8Array([ e.r, e.g, e.b, t ]); + }, osc.readTrue = function() { + return !0; + }, osc.readFalse = function() { + return !1; + }, osc.readNull = function() { + return null; + }, osc.readImpulse = function() { + return 1; + }, osc.readTimeTag = function(e, t) { + var r = osc.readPrimitive(e, "getUint32", 4, t), n = osc.readPrimitive(e, "getUint32", 4, t); + return { + raw: [ r, n ], + native: 0 === r && 1 === n ? Date.now() : osc.ntpToJSTime(r, n) + }; + }, osc.writeTimeTag = function(e) { + var t = e.raw ? e.raw : osc.jsToNTPTime(e.native), r = new Uint8Array(8), n = new DataView(r.buffer); + return osc.writeInt32(t[0], n, 0), osc.writeInt32(t[1], n, 4), r; + }, osc.timeTag = function(e, t) { + e = e || 0; + var r = (t = t || Date.now()) / 1e3, n = Math.floor(r), i = r - n, s = Math.floor(e), o = i + (e - s); + if (1 < o) { + var a = Math.floor(o); + s += a, o = o - a; + } + return { + raw: [ n + s + osc.SECS_70YRS, Math.round(osc.TWO_32 * o) ] + }; + }, osc.ntpToJSTime = function(e, t) { + return 1e3 * (e - osc.SECS_70YRS + t / osc.TWO_32); + }, osc.jsToNTPTime = function(e) { + var t = e / 1e3, r = Math.floor(t), n = t - r; + return [ r + osc.SECS_70YRS, Math.round(osc.TWO_32 * n) ]; + }, osc.readArguments = function(e, t, r) { + var n = osc.readString(e, r); + if (0 !== n.indexOf(",")) throw new Error("A malformed type tag string was found while reading the arguments of an OSC message. String was: " + n, " at offset: " + r.idx); + var i = n.substring(1).split(""), s = []; + return osc.readArgumentsIntoArray(s, i, n, e, t, r), s; + }, osc.readArgument = function(e, t, r, n, i) { + var s = osc.argumentTypes[e]; + if (!s) throw new Error("'" + e + "' is not a valid OSC type tag. Type tag string was: " + t); + var o = s.reader, a = osc[o](r, i); + return n.metadata && (a = { + type: e, + value: a + }), a; + }, osc.readArgumentsIntoArray = function(e, t, r, n, i, s) { + for (var o = 0; o < t.length; ) { + var a, u = t[o]; + if ("[" === u) { + var c = t.slice(o + 1), h = c.indexOf("]"); + if (h < 0) throw new Error("Invalid argument type tag: an open array type tag ('[') was found without a matching close array tag ('[]'). Type tag was: " + r); + var f = c.slice(0, h); + a = osc.readArgumentsIntoArray([], f, r, n, i, s), o += h + 2; + } else a = osc.readArgument(u, r, n, i, s), o++; + e.push(a); + } + return e; + }, osc.writeArguments = function(e, t) { + var r = osc.collectArguments(e, t); + return osc.joinParts(r); + }, osc.joinParts = function(e) { + for (var t = new Uint8Array(e.byteLength), r = e.parts, n = 0, i = 0; i < r.length; i++) { + var s = r[i]; + osc.copyByteArray(s, t, n), n += s.length; + } + return t; + }, osc.addDataPart = function(e, t) { + t.parts.push(e), t.byteLength += e.length; + }, osc.writeArrayArguments = function(e, t) { + for (var r = "[", n = 0; n < e.length; n++) { + var i = e[n]; + r += osc.writeArgument(i, t); + } + return r += "]"; + }, osc.writeArgument = function(e, t) { + if (osc.isArray(e)) return osc.writeArrayArguments(e, t); + var r = e.type, n = osc.argumentTypes[r].writer; + if (n) { + var i = osc[n](e.value); + osc.addDataPart(i, t); + } + return e.type; + }, osc.collectArguments = function(e, t, r) { + osc.isArray(e) || (e = void 0 === e ? [] : [ e ]), r = r || { + byteLength: 0, + parts: [] + }, t.metadata || (e = osc.annotateArguments(e)); + for (var n = ",", i = r.parts.length, s = 0; s < e.length; s++) { + var o = e[s]; + n += osc.writeArgument(o, r); + } + var a = osc.writeString(n); + return r.byteLength += a.byteLength, r.parts.splice(i, 0, a), r; + }, osc.readMessage = function(e, t, r) { + t = t || osc.defaults; + var n = osc.dataView(e, e.byteOffset, e.byteLength); + r = r || { + idx: 0 + }; + var i = osc.readString(n, r); + return osc.readMessageContents(i, n, t, r); + }, osc.readMessageContents = function(e, t, r, n) { + if (0 !== e.indexOf("/")) throw new Error("A malformed OSC address was found while reading an OSC message. String was: " + e); + var i = osc.readArguments(t, r, n); + return { + address: e, + args: 1 === i.length && r.unpackSingleArgs ? i[0] : i + }; + }, osc.collectMessageParts = function(e, t, r) { + return r = r || { + byteLength: 0, + parts: [] + }, osc.addDataPart(osc.writeString(e.address), r), osc.collectArguments(e.args, t, r); + }, osc.writeMessage = function(e, t) { + if (t = t || osc.defaults, !osc.isValidMessage(e)) throw new Error("An OSC message must contain a valid address. Message was: " + JSON.stringify(e, null, 2)); + var r = osc.collectMessageParts(e, t); + return osc.joinParts(r); + }, osc.isValidMessage = function(e) { + return e.address && 0 === e.address.indexOf("/"); + }, osc.readBundle = function(e, t, r) { + return osc.readPacket(e, t, r); + }, osc.collectBundlePackets = function(e, t, r) { + r = r || { + byteLength: 0, + parts: [] + }, osc.addDataPart(osc.writeString("#bundle"), r), osc.addDataPart(osc.writeTimeTag(e.timeTag), r); + for (var n = 0; n < e.packets.length; n++) { + var i = e.packets[n], s = (i.address ? osc.collectMessageParts : osc.collectBundlePackets)(i, t); + r.byteLength += s.byteLength, osc.addDataPart(osc.writeInt32(s.byteLength), r), + r.parts = r.parts.concat(s.parts); + } + return r; + }, osc.writeBundle = function(e, t) { + if (!osc.isValidBundle(e)) throw new Error("An OSC bundle must contain 'timeTag' and 'packets' properties. Bundle was: " + JSON.stringify(e, null, 2)); + t = t || osc.defaults; + var r = osc.collectBundlePackets(e, t); + return osc.joinParts(r); + }, osc.isValidBundle = function(e) { + return void 0 !== e.timeTag && void 0 !== e.packets; + }, osc.readBundleContents = function(e, t, r, n) { + for (var i = osc.readTimeTag(e, r), s = []; r.idx < n; ) { + var o = osc.readInt32(e, r), a = r.idx + o, u = osc.readPacket(e, t, r, a); + s.push(u); + } + return { + timeTag: i, + packets: s + }; + }, osc.readPacket = function(e, t, r, n) { + var i = osc.dataView(e, e.byteOffset, e.byteLength); + n = void 0 === n ? i.byteLength : n, r = r || { + idx: 0 + }; + var s = osc.readString(i, r), o = s[0]; + if ("#" === o) return osc.readBundleContents(i, t, r, n); + if ("/" === o) return osc.readMessageContents(s, i, t, r); + throw new Error("The header of an OSC packet didn't contain an OSC address or a #bundle string. Header was: " + s); + }, osc.writePacket = function(e, t) { + if (osc.isValidMessage(e)) return osc.writeMessage(e, t); + if (osc.isValidBundle(e)) return osc.writeBundle(e, t); + throw new Error("The specified packet was not recognized as a valid OSC message or bundle. Packet was: " + JSON.stringify(e, null, 2)); + }, osc.argumentTypes = { + i: { + reader: "readInt32", + writer: "writeInt32" + }, + h: { + reader: "readInt64", + writer: "writeInt64" + }, + 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(e) { + switch (typeof e) { + case "boolean": + return e ? "T" : "F"; + + case "string": + return "s"; + + case "number": + return "f"; + + case "undefined": + return "N"; + + case "object": + if (null === e) return "N"; + if (e instanceof Uint8Array || e instanceof ArrayBuffer) return "b"; + if ("number" == typeof e.high && "number" == typeof e.low) return "h"; + } + throw new Error("Can't infer OSC argument type for value: " + JSON.stringify(e, null, 2)); + }, osc.annotateArguments = function(e) { + for (var t = [], r = 0; r < e.length; r++) { + var n, i = e[r]; + if ("object" == typeof i && i.type && void 0 !== i.value) n = i; else if (osc.isArray(i)) n = osc.annotateArguments(i); else { + n = { + type: osc.inferTypeForArgument(i), + value: i + }; + } + t.push(n); + } + return t; + }, osc.isCommonJS && (module.exports = osc); +}(), function(e, t) { + "object" == typeof exports && "object" == typeof module ? module.exports = t() : "function" == typeof define && define.amd ? define([], t) : "object" == typeof exports ? exports.Long = t() : e.Long = t(); +}("undefined" != typeof self ? self : this, function() { + return function(r) { + function n(e) { + if (i[e]) return i[e].exports; + var t = i[e] = { + i: e, + l: !1, + exports: {} + }; + return r[e].call(t.exports, t, t.exports, n), t.l = !0, t.exports; + } + var i = {}; + return n.m = r, n.c = i, n.d = function(e, t, r) { + n.o(e, t) || Object.defineProperty(e, t, { + configurable: !1, + enumerable: !0, + get: r + }); + }, n.n = function(e) { + var t = e && e.__esModule ? function() { + return e.default; + } : function() { + return e; + }; + return n.d(t, "a", t), t; + }, n.o = function(e, t) { + return Object.prototype.hasOwnProperty.call(e, t); + }, n.p = "", n(n.s = 0); + }([ function(e, t) { + function n(e, t, r) { + this.low = 0 | e, this.high = 0 | t, this.unsigned = !!r; + } + function g(e) { + return !0 === (e && e.__isLong__); + } + function r(e, t) { + var r, n, i; + return t ? (i = 0 <= (e >>>= 0) && e < 256) && (n = o[e]) ? n : (r = p(e, (0 | e) < 0 ? -1 : 0, !0), + i && (o[e] = r), r) : (i = -128 <= (e |= 0) && e < 128) && (n = s[e]) ? n : (r = p(e, e < 0 ? -1 : 0, !1), + i && (s[e] = r), r); + } + function l(e, t) { + if (isNaN(e)) return t ? c : m; + if (t) { + if (e < 0) return c; + if (a <= e) return A; + } else { + if (e <= -u) return P; + if (u <= e + 1) return E; + } + return e < 0 ? l(-e, t).neg() : p(e % i | 0, e / i | 0, t); + } + function p(e, t, r) { + return new n(e, t, r); + } + function h(e, t, r) { + if (0 === e.length) throw Error("empty string"); + if ("NaN" === e || "Infinity" === e || "+Infinity" === e || "-Infinity" === e) return m; + if ("number" == typeof t ? (r = t, t = !1) : t = !!t, (r = r || 10) < 2 || 36 < r) throw RangeError("radix"); + var n; + if (0 < (n = e.indexOf("-"))) throw Error("interior hyphen"); + if (0 === n) return h(e.substring(1), t, r).neg(); + for (var i = l(f(r, 8)), s = m, o = 0; o < e.length; o += 8) { + var a = Math.min(8, e.length - o), u = parseInt(e.substring(o, o + a), r); + if (a < 8) { + var c = l(f(r, a)); + s = s.mul(c).add(l(u)); + } else s = (s = s.mul(i)).add(l(u)); + } + return s.unsigned = t, s; + } + function y(e, t) { + return "number" == typeof e ? l(e, t) : "string" == typeof e ? h(e, t) : p(e.low, e.high, "boolean" == typeof t ? t : e.unsigned); + } + e.exports = n; + var v = null; + try { + v = new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([ 0, 97, 115, 109, 1, 0, 0, 0, 1, 13, 2, 96, 0, 1, 127, 96, 4, 127, 127, 127, 127, 1, 127, 3, 7, 6, 0, 1, 1, 1, 1, 1, 6, 6, 1, 127, 1, 65, 0, 11, 7, 50, 6, 3, 109, 117, 108, 0, 1, 5, 100, 105, 118, 95, 115, 0, 2, 5, 100, 105, 118, 95, 117, 0, 3, 5, 114, 101, 109, 95, 115, 0, 4, 5, 114, 101, 109, 95, 117, 0, 5, 8, 103, 101, 116, 95, 104, 105, 103, 104, 0, 0, 10, 191, 1, 6, 4, 0, 35, 0, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 126, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 127, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 128, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 129, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 130, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11 ])), {}).exports; + } catch (e) {} + Object.defineProperty(n.prototype, "__isLong__", { + value: !0 + }), n.isLong = g; + var s = {}, o = {}; + n.fromInt = r, n.fromNumber = l, n.fromBits = p; + var f = Math.pow; + n.fromString = h, n.fromValue = y; + var i = 4294967296, a = i * i, u = a / 2, w = r(1 << 24), m = r(0); + n.ZERO = m; + var c = r(0, !0); + n.UZERO = c; + var d = r(1); + n.ONE = d; + var b = r(1, !0); + n.UONE = b; + var S = r(-1); + n.NEG_ONE = S; + var E = p(-1, 2147483647, !1); + n.MAX_VALUE = E; + var A = p(-1, -1, !0); + n.MAX_UNSIGNED_VALUE = A; + var P = p(0, -2147483648, !1); + n.MIN_VALUE = P; + var B = n.prototype; + B.toInt = function() { + return this.unsigned ? this.low >>> 0 : this.low; + }, B.toNumber = function() { + return this.unsigned ? (this.high >>> 0) * i + (this.low >>> 0) : this.high * i + (this.low >>> 0); + }, B.toString = function(e) { + if ((e = e || 10) < 2 || 36 < e) throw RangeError("radix"); + if (this.isZero()) return "0"; + if (this.isNegative()) { + if (this.eq(P)) { + var t = l(e), r = this.div(t), n = r.mul(t).sub(this); + return r.toString(e) + n.toInt().toString(e); + } + return "-" + this.neg().toString(e); + } + for (var i = l(f(e, 6), this.unsigned), s = this, o = ""; ;) { + var a = s.div(i), u = (s.sub(a.mul(i)).toInt() >>> 0).toString(e); + if ((s = a).isZero()) return u + o; + for (;u.length < 6; ) u = "0" + u; + o = "" + u + o; + } + }, B.getHighBits = function() { + return this.high; + }, B.getHighBitsUnsigned = function() { + return this.high >>> 0; + }, B.getLowBits = function() { + return this.low; + }, B.getLowBitsUnsigned = function() { + return this.low >>> 0; + }, B.getNumBitsAbs = function() { + if (this.isNegative()) return this.eq(P) ? 64 : this.neg().getNumBitsAbs(); + for (var e = 0 != this.high ? this.high : this.low, t = 31; 0 < t && 0 == (e & 1 << t); t--) ; + return 0 != this.high ? t + 33 : t + 1; + }, B.isZero = function() { + return 0 === this.high && 0 === this.low; + }, B.eqz = B.isZero, B.isNegative = function() { + return !this.unsigned && this.high < 0; + }, B.isPositive = function() { + return this.unsigned || 0 <= this.high; + }, B.isOdd = function() { + return 1 == (1 & this.low); + }, B.isEven = function() { + return 0 == (1 & this.low); + }, B.equals = function(e) { + return g(e) || (e = y(e)), (this.unsigned === e.unsigned || this.high >>> 31 != 1 || e.high >>> 31 != 1) && this.high === e.high && this.low === e.low; + }, B.eq = B.equals, B.notEquals = function(e) { + return !this.eq(e); + }, B.neq = B.notEquals, B.ne = B.notEquals, B.lessThan = function(e) { + return this.comp(e) < 0; + }, B.lt = B.lessThan, B.lessThanOrEqual = function(e) { + return this.comp(e) <= 0; + }, B.lte = B.lessThanOrEqual, B.le = B.lessThanOrEqual, B.greaterThan = function(e) { + return 0 < this.comp(e); + }, B.gt = B.greaterThan, B.greaterThanOrEqual = function(e) { + return 0 <= this.comp(e); + }, B.gte = B.greaterThanOrEqual, B.ge = B.greaterThanOrEqual, B.compare = function(e) { + if (g(e) || (e = y(e)), this.eq(e)) return 0; + var t = this.isNegative(), r = e.isNegative(); + return t && !r ? -1 : !t && r ? 1 : this.unsigned ? e.high >>> 0 > this.high >>> 0 || e.high === this.high && e.low >>> 0 > this.low >>> 0 ? -1 : 1 : this.sub(e).isNegative() ? -1 : 1; + }, B.comp = B.compare, B.negate = function() { + return !this.unsigned && this.eq(P) ? P : this.not().add(d); + }, B.neg = B.negate, B.add = function(e) { + g(e) || (e = y(e)); + var t = this.high >>> 16, r = 65535 & this.high, n = this.low >>> 16, i = 65535 & this.low, s = e.high >>> 16, o = 65535 & e.high, a = e.low >>> 16, u = 0, c = 0, h = 0, f = 0; + return h += (f += i + (65535 & e.low)) >>> 16, c += (h += n + a) >>> 16, u += (c += r + o) >>> 16, + u += t + s, p((h &= 65535) << 16 | (f &= 65535), (u &= 65535) << 16 | (c &= 65535), this.unsigned); + }, B.subtract = function(e) { + return g(e) || (e = y(e)), this.add(e.neg()); + }, B.sub = B.subtract, B.multiply = function(e) { + if (this.isZero()) return m; + if (g(e) || (e = y(e)), v) return p(v.mul(this.low, this.high, e.low, e.high), v.get_high(), this.unsigned); + if (e.isZero()) return m; + if (this.eq(P)) return e.isOdd() ? P : m; + if (e.eq(P)) return this.isOdd() ? P : m; + if (this.isNegative()) return e.isNegative() ? this.neg().mul(e.neg()) : this.neg().mul(e).neg(); + if (e.isNegative()) return this.mul(e.neg()).neg(); + if (this.lt(w) && e.lt(w)) return l(this.toNumber() * e.toNumber(), this.unsigned); + var t = this.high >>> 16, r = 65535 & this.high, n = this.low >>> 16, i = 65535 & this.low, s = e.high >>> 16, o = 65535 & e.high, a = e.low >>> 16, u = 65535 & e.low, c = 0, h = 0, f = 0, d = 0; + return f += (d += i * u) >>> 16, h += (f += n * u) >>> 16, f &= 65535, h += (f += i * a) >>> 16, + c += (h += r * u) >>> 16, h &= 65535, c += (h += n * a) >>> 16, h &= 65535, c += (h += i * o) >>> 16, + c += t * u + r * a + n * o + i * s, p((f &= 65535) << 16 | (d &= 65535), (c &= 65535) << 16 | (h &= 65535), this.unsigned); + }, B.mul = B.multiply, B.divide = function(e) { + if (g(e) || (e = y(e)), e.isZero()) throw Error("division by zero"); + if (v) return this.unsigned || -2147483648 !== this.high || -1 !== e.low || -1 !== e.high ? p((this.unsigned ? v.div_u : v.div_s)(this.low, this.high, e.low, e.high), v.get_high(), this.unsigned) : this; + if (this.isZero()) return this.unsigned ? c : m; + var t, r, n; + if (this.unsigned) { + if (e.unsigned || (e = e.toUnsigned()), e.gt(this)) return c; + if (e.gt(this.shru(1))) return b; + n = c; + } else { + if (this.eq(P)) return e.eq(d) || e.eq(S) ? P : e.eq(P) ? d : (t = this.shr(1).div(e).shl(1)).eq(m) ? e.isNegative() ? d : S : (r = this.sub(e.mul(t)), + n = t.add(r.div(e))); + if (e.eq(P)) return this.unsigned ? c : m; + if (this.isNegative()) return e.isNegative() ? this.neg().div(e.neg()) : this.neg().div(e).neg(); + if (e.isNegative()) return this.div(e.neg()).neg(); + n = m; + } + for (r = this; r.gte(e); ) { + t = Math.max(1, Math.floor(r.toNumber() / e.toNumber())); + for (var i = Math.ceil(Math.log(t) / Math.LN2), s = i <= 48 ? 1 : f(2, i - 48), o = l(t), a = o.mul(e); a.isNegative() || a.gt(r); ) a = (o = l(t -= s, this.unsigned)).mul(e); + o.isZero() && (o = d), n = n.add(o), r = r.sub(a); + } + return n; + }, B.div = B.divide, B.modulo = function(e) { + return g(e) || (e = y(e)), v ? p((this.unsigned ? v.rem_u : v.rem_s)(this.low, this.high, e.low, e.high), v.get_high(), this.unsigned) : this.sub(this.div(e).mul(e)); + }, B.mod = B.modulo, B.rem = B.modulo, B.not = function() { + return p(~this.low, ~this.high, this.unsigned); + }, B.and = function(e) { + return g(e) || (e = y(e)), p(this.low & e.low, this.high & e.high, this.unsigned); + }, B.or = function(e) { + return g(e) || (e = y(e)), p(this.low | e.low, this.high | e.high, this.unsigned); + }, B.xor = function(e) { + return g(e) || (e = y(e)), p(this.low ^ e.low, this.high ^ e.high, this.unsigned); + }, B.shiftLeft = function(e) { + return g(e) && (e = e.toInt()), 0 == (e &= 63) ? this : e < 32 ? p(this.low << e, this.high << e | this.low >>> 32 - e, this.unsigned) : p(0, this.low << e - 32, this.unsigned); + }, B.shl = B.shiftLeft, B.shiftRight = function(e) { + return g(e) && (e = e.toInt()), 0 == (e &= 63) ? this : e < 32 ? p(this.low >>> e | this.high << 32 - e, this.high >> e, this.unsigned) : p(this.high >> e - 32, 0 <= this.high ? 0 : -1, this.unsigned); + }, B.shr = B.shiftRight, B.shiftRightUnsigned = function(e) { + if (g(e) && (e = e.toInt()), 0 == (e &= 63)) return this; + var t = this.high; + return e < 32 ? p(this.low >>> e | t << 32 - e, t >>> e, this.unsigned) : p(32 === e ? t : t >>> e - 32, 0, this.unsigned); + }, B.shru = B.shiftRightUnsigned, B.shr_u = B.shiftRightUnsigned, B.toSigned = function() { + return this.unsigned ? p(this.low, this.high, !1) : this; + }, B.toUnsigned = function() { + return this.unsigned ? this : p(this.low, this.high, !0); + }, B.toBytes = function(e) { + return e ? this.toBytesLE() : this.toBytesBE(); + }, B.toBytesLE = function() { + var e = this.high, t = this.low; + return [ 255 & t, t >>> 8 & 255, t >>> 16 & 255, t >>> 24, 255 & e, e >>> 8 & 255, e >>> 16 & 255, e >>> 24 ]; + }, B.toBytesBE = function() { + var e = this.high, t = this.low; + return [ e >>> 24, e >>> 16 & 255, e >>> 8 & 255, 255 & e, t >>> 24, t >>> 16 & 255, t >>> 8 & 255, 255 & t ]; + }, n.fromBytes = function(e, t, r) { + return r ? n.fromBytesLE(e, t) : n.fromBytesBE(e, t); + }, n.fromBytesLE = function(e, t) { + return new n(e[0] | e[1] << 8 | e[2] << 16 | e[3] << 24, e[4] | e[5] << 8 | e[6] << 16 | e[7] << 24, t); + }, n.fromBytesBE = function(e, t) { + return new n(e[4] << 24 | e[5] << 16 | e[6] << 8 | e[7], e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3], t); + }; + } ]); +}), function(t, r) { + "use strict"; + "object" == typeof exports ? (t.slip = exports, r(exports)) : "function" == typeof define && define.amd ? define([ "exports" ], function(e) { + return t.slip = e, t.slip, r(e); + }) : (t.slip = {}, r(t.slip)); +}(this, function(e) { + "use strict"; + var a = e; + a.END = 192, a.ESC = 219, a.ESC_END = 220, a.ESC_ESC = 221, a.byteArray = function(e, t, r) { + return e instanceof ArrayBuffer ? new Uint8Array(e, t, r) : e; + }, a.expandByteArray = function(e) { + var t = new Uint8Array(2 * e.length); + return t.set(e), t; + }, a.sliceByteArray = function(e, t, r) { + var n = e.buffer.slice ? e.buffer.slice(t, r) : e.subarray(t, r); + return new Uint8Array(n); + }, a.encode = function(e, t) { + (t = t || {}).bufferPadding = t.bufferPadding || 4; + var r = (e = a.byteArray(e, t.offset, t.byteLength)).length + t.bufferPadding + 3 & -4, n = new Uint8Array(r), i = 1; + n[0] = a.END; + for (var s = 0; s < e.length; s++) { + i > n.length - 3 && (n = a.expandByteArray(n)); + var o = e[s]; + o === a.END ? (n[i++] = a.ESC, o = a.ESC_END) : o === a.ESC && (n[i++] = a.ESC, + o = a.ESC_ESC), n[i++] = o; + } + return n[i] = a.END, a.sliceByteArray(n, 0, i + 1); + }, a.Decoder = function(e) { + e = "function" != typeof e ? e || {} : { + onMessage: e + }, this.maxMessageSize = e.maxMessageSize || 10485760, this.bufferSize = e.bufferSize || 1024, + this.msgBuffer = new Uint8Array(this.bufferSize), this.msgBufferIdx = 0, this.onMessage = e.onMessage, + this.onError = e.onError, this.escape = !1; + }; + var t = a.Decoder.prototype; + return t.decode = function(e) { + var t; + e = a.byteArray(e); + for (var r = 0; r < e.length; r++) { + var n = e[r]; + if (this.escape) n === a.ESC_ESC ? n = a.ESC : n === a.ESC_END && (n = a.END); else { + if (n === a.ESC) { + this.escape = !0; + continue; + } + if (n === a.END) { + t = this.handleEnd(); + continue; + } + } + this.addByte(n) || this.handleMessageMaxError(); + } + return t; + }, t.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; + }, t.addByte = function(e) { + return this.msgBufferIdx > this.msgBuffer.length - 1 && (this.msgBuffer = a.expandByteArray(this.msgBuffer)), + this.msgBuffer[this.msgBufferIdx++] = e, this.escape = !1, this.msgBuffer.length < this.maxMessageSize; + }, t.handleEnd = function() { + if (0 !== this.msgBufferIdx) { + var e = a.sliceByteArray(this.msgBuffer, 0, this.msgBufferIdx); + return this.onMessage && this.onMessage(e), this.msgBufferIdx = 0, e; + } + }, a; +}), function(e) { + "use strict"; + function t() {} + var r = t.prototype, n = e.EventEmitter; + function s(e, t) { + for (var r = e.length; r--; ) if (e[r].listener === t) return r; + return -1; + } + function i(e) { + return function() { + return this[e].apply(this, arguments); + }; + } + r.getListeners = function(e) { + var t, r, n = this._getEvents(); + if (e instanceof RegExp) for (r in t = {}, n) n.hasOwnProperty(r) && e.test(r) && (t[r] = n[r]); else t = n[e] || (n[e] = []); + return t; + }, r.flattenListeners = function(e) { + var t, r = []; + for (t = 0; t < e.length; t += 1) r.push(e[t].listener); + return r; + }, r.getListenersAsObject = function(e) { + var t, r = this.getListeners(e); + return r instanceof Array && ((t = {})[e] = r), t || r; + }, r.addListener = function(e, t) { + if (!function e(t) { + return "function" == typeof t || t instanceof RegExp || !(!t || "object" != typeof t) && e(t.listener); + }(t)) throw new TypeError("listener must be a function"); + var r, n = this.getListenersAsObject(e), i = "object" == typeof t; + for (r in n) n.hasOwnProperty(r) && -1 === s(n[r], t) && n[r].push(i ? t : { + listener: t, + once: !1 + }); + return this; + }, r.on = i("addListener"), r.addOnceListener = function(e, t) { + return this.addListener(e, { + listener: t, + once: !0 + }); + }, r.once = i("addOnceListener"), r.defineEvent = function(e) { + return this.getListeners(e), this; + }, r.defineEvents = function(e) { + for (var t = 0; t < e.length; t += 1) this.defineEvent(e[t]); + return this; + }, r.removeListener = function(e, t) { + var r, n, i = this.getListenersAsObject(e); + for (n in i) i.hasOwnProperty(n) && -1 !== (r = s(i[n], t)) && i[n].splice(r, 1); + return this; + }, r.off = i("removeListener"), r.addListeners = function(e, t) { + return this.manipulateListeners(!1, e, t); + }, r.removeListeners = function(e, t) { + return this.manipulateListeners(!0, e, t); + }, r.manipulateListeners = function(e, t, r) { + var n, i, s = e ? this.removeListener : this.addListener, o = e ? this.removeListeners : this.addListeners; + if ("object" != typeof t || t instanceof RegExp) for (n = r.length; n--; ) s.call(this, t, r[n]); else for (n in t) t.hasOwnProperty(n) && (i = t[n]) && ("function" == typeof i ? s.call(this, n, i) : o.call(this, n, i)); + return this; + }, r.removeEvent = function(e) { + var t, r = typeof e, n = this._getEvents(); + if ("string" === r) delete n[e]; else if (e instanceof RegExp) for (t in n) n.hasOwnProperty(t) && e.test(t) && delete n[t]; else delete this._events; + return this; + }, r.removeAllListeners = i("removeEvent"), r.emitEvent = function(e, t) { + var r, n, i, s, o = this.getListenersAsObject(e); + for (s in o) if (o.hasOwnProperty(s)) for (r = o[s].slice(0), i = 0; i < r.length; i++) !0 === (n = r[i]).once && this.removeListener(e, n.listener), + n.listener.apply(this, t || []) === this._getOnceReturnValue() && this.removeListener(e, n.listener); + return this; + }, r.trigger = i("emitEvent"), r.emit = function(e) { + var t = Array.prototype.slice.call(arguments, 1); + return this.emitEvent(e, t); + }, r.setOnceReturnValue = function(e) { + return this._onceReturnValue = e, this; + }, r._getOnceReturnValue = function() { + return !this.hasOwnProperty("_onceReturnValue") || this._onceReturnValue; + }, r._getEvents = function() { + return this._events || (this._events = {}); + }, t.noConflict = function() { + return e.EventEmitter = n, t; + }, "function" == typeof define && define.amd ? define(function() { + return t; + }) : "object" == typeof module && module.exports ? module.exports = t : e.EventEmitter = t; +}(this || {}); + +osc = osc || require("./osc.js"); + +var slip = slip || require("slip"), EventEmitter = EventEmitter || require("events").EventEmitter; + +!function() { + "use strict"; + osc.firePacketEvents = function(e, t, r, n) { + t.address ? e.emit("message", t, r, n) : osc.fireBundleEvents(e, t, r, n); + }, osc.fireBundleEvents = function(e, t, r, n) { + e.emit("bundle", t, r, n); + for (var i = 0; i < t.packets.length; i++) { + var s = t.packets[i]; + osc.firePacketEvents(e, s, t.timeTag, n); + } + }, osc.fireClosedPortSendError = function(e, t) { + t = t || "Can't send packets on a closed osc.Port object. Please open (or reopen) this Port by calling open().", + e.emit("error", t); + }, osc.Port = function(e) { + this.options = e || {}, this.on("data", this.decodeOSC.bind(this)); + }; + var e = osc.Port.prototype = Object.create(EventEmitter.prototype); + e.constructor = osc.Port, e.send = function(e) { + var t = Array.prototype.slice.call(arguments), r = this.encodeOSC(e), n = osc.nativeBuffer(r); + t[0] = n, this.sendRaw.apply(this, t); + }, e.encodeOSC = function(e) { + var t; + e = e.buffer ? e.buffer : e; + try { + t = osc.writePacket(e, this.options); + } catch (e) { + this.emit("error", e); + } + return t; + }, e.decodeOSC = function(e, t) { + e = osc.byteArray(e), this.emit("raw", e, t); + try { + var r = osc.readPacket(e, this.options); + this.emit("osc", r, t), osc.firePacketEvents(this, r, void 0, t); + } catch (e) { + this.emit("error", e); + } + }, osc.SLIPPort = function(e) { + var t = this, r = this.options = e || {}; + r.useSLIP = void 0 === r.useSLIP || r.useSLIP, this.decoder = new slip.Decoder({ + onMessage: this.decodeOSC.bind(this), + onError: function(e) { + t.emit("error", e); + } + }); + var n = r.useSLIP ? this.decodeSLIPData : this.decodeOSC; + this.on("data", n.bind(this)); + }, (e = osc.SLIPPort.prototype = Object.create(osc.Port.prototype)).constructor = osc.SLIPPort, + e.encodeOSC = function(e) { + var t; + e = e.buffer ? e.buffer : e; + try { + var r = osc.writePacket(e, this.options); + t = slip.encode(r); + } catch (e) { + this.emit("error", e); + } + return t; + }, e.decodeSLIPData = function(e, t) { + this.decoder.decode(e, t); + }, osc.relay = function(e, t, r, n, i, s) { + r = r || "message", n = n || "send", i = i || function() {}, s = s ? [ null ].concat(s) : []; + var o = function(e) { + s[0] = e, e = i(e), t[n].apply(t, s); + }; + return e.on(r, o), { + eventName: r, + listener: o + }; + }, osc.relayPorts = function(e, t, r) { + var n = r.raw ? "raw" : "osc", i = r.raw ? "sendRaw" : "send"; + return osc.relay(e, t, n, i, r.transform); + }, osc.stopRelaying = function(e, t) { + e.removeListener(t.eventName, t.listener); + }, osc.Relay = function(e, t, r) { + (this.options = r || {}).raw = !1, this.port1 = e, this.port2 = t, this.listen(); + }, (e = osc.Relay.prototype = Object.create(EventEmitter.prototype)).constructor = osc.Relay, + e.open = function() { + this.port1.open(), this.port2.open(); + }, e.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); + var e = this.close.bind(this); + this.port1.on("close", e), this.port2.on("close", e); + }, e.close = function() { + osc.stopRelaying(this.port1, this.port1Spec), osc.stopRelaying(this.port2, this.port2Spec), + this.emit("close", this.port1, this.port2); + }, "undefined" != typeof module && module.exports && (module.exports = osc); +}(); + +osc = osc || require("../osc.js"); + +!function() { + "use strict"; + osc.WebSocket = "undefined" != typeof WebSocket ? WebSocket : require("ws"), osc.WebSocketPort = function(e) { + osc.Port.call(this, e), this.on("open", this.listen.bind(this)), this.socket = e.socket, + this.socket && (1 === this.socket.readyState ? (osc.WebSocketPort.setupSocketForBinary(this.socket), + this.emit("open", this.socket)) : this.open()); + }; + var e = osc.WebSocketPort.prototype = Object.create(osc.Port.prototype); + e.constructor = osc.WebSocketPort, e.open = function() { + (!this.socket || 1 < this.socket.readyState) && (this.socket = new osc.WebSocket(this.options.url)), + osc.WebSocketPort.setupSocketForBinary(this.socket); + var e = this; + this.socket.onopen = function() { + e.emit("open", e.socket); + }; + }, e.listen = function() { + var t = this; + this.socket.onmessage = function(e) { + t.emit("data", e.data, e); + }, this.socket.onerror = function(e) { + t.emit("error", e); + }, this.socket.onclose = function(e) { + t.emit("close", e); + }, t.emit("ready"); + }, e.sendRaw = function(e) { + this.socket && 1 === this.socket.readyState ? this.socket.send(e) : osc.fireClosedPortSendError(this); + }, e.close = function(e, t) { + this.socket.close(e, t); + }, osc.WebSocketPort.setupSocketForBinary = function(e) { + e.binaryType = osc.isNode ? "nodebuffer" : "arraybuffer"; + }; +}(); \ No newline at end of file diff --git a/dist/osc-chromeapp.js b/dist/osc-chromeapp.js index 3c2e2e3..8dac592 100644 --- a/dist/osc-chromeapp.js +++ b/dist/osc-chromeapp.js @@ -1,4 +1,4 @@ -/*! osc.js 2.2.0, Copyright 2017 Colin Clark | github.com/colinbdclark/osc.js */ +/*! osc.js 2.2.1, Copyright 2018 Colin Clark | github.com/colinbdclark/osc.js */ /* * osc.js: An Open Sound Control library for JavaScript that works in both the browser and Node.js @@ -7,7 +7,7 @@ * Licensed under the MIT and GPL 3 licenses. */ -/* global require, module, process, Buffer, dcodeIO */ +/* global require, module, process, Buffer, Long */ var osc = osc || {}; @@ -41,19 +41,18 @@ var osc = osc || {}; return obj && Object.prototype.toString.call(obj) === "[object Array]"; }; - // Unsupported, non-API function + // Unsupported, non-API function. osc.isTypedArrayView = function (obj) { return obj.buffer && obj.buffer instanceof ArrayBuffer; }; - // Unsupported, non-API function + // Unsupported, non-API function. osc.isBuffer = function (obj) { return osc.isBufferEnv && obj instanceof Buffer; }; - // Private instance of the optional Long dependency. - var Long = typeof dcodeIO !== "undefined" ? dcodeIO.Long : - typeof Long !== "undefined" ? Long : + // Unsupported, non-API member. + osc.Long = typeof Long !== "undefined" ? Long : osc.isNode ? require("long") : undefined; /** @@ -270,8 +269,8 @@ var osc = osc || {}; var high = osc.readPrimitive(dv, "getInt32", 4, offsetState), low = osc.readPrimitive(dv, "getInt32", 4, offsetState); - if (Long) { - return new Long(low, high); + if (osc.Long) { + return new osc.Long(low, high); } else { return { high: high, @@ -608,7 +607,7 @@ var osc = osc || {}; * * @param {DataView} dv a DataView instance to read from * @param {Object} offsetState the offsetState object that stores the current offset into dv - * @param {Oobject} [options] read options + * @param {Object} [options] read options * @return {Array} an array of the OSC arguments that were read */ osc.readArguments = function (dv, options, offsetState) { @@ -1090,1216 +1089,10 @@ var osc = osc || {}; module.exports = osc; } }()); -;/* - Copyright 2013 Daniel Wirtz - Copyright 2009 The Closure Library Authors. All Rights Reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS-IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - */ - -/** - * @license long.js (c) 2013 Daniel Wirtz - * Released under the Apache License, Version 2.0 - * see: https://github.com/dcodeIO/long.js for details - */ -(function(global, factory) { - - /* AMD */ if (typeof define === 'function' && define["amd"]) - define([], factory); - /* CommonJS */ else if (typeof require === 'function' && typeof module === "object" && module && module["exports"]) - module["exports"] = factory(); - /* Global */ else - (global["dcodeIO"] = global["dcodeIO"] || {})["Long"] = factory(); - -})(this, function() { - "use strict"; - - /** - * Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as *signed* integers. - * See the from* functions below for more convenient ways of constructing Longs. - * @exports Long - * @class A Long class for representing a 64 bit two's-complement integer value. - * @param {number} low The low (signed) 32 bits of the long - * @param {number} high The high (signed) 32 bits of the long - * @param {boolean=} unsigned Whether unsigned or not, defaults to `false` for signed - * @constructor - */ - function Long(low, high, unsigned) { - - /** - * The low 32 bits as a signed value. - * @type {number} - */ - this.low = low | 0; - - /** - * The high 32 bits as a signed value. - * @type {number} - */ - this.high = high | 0; - - /** - * Whether unsigned or not. - * @type {boolean} - */ - this.unsigned = !!unsigned; - } - - // The internal representation of a long is the two given signed, 32-bit values. - // We use 32-bit pieces because these are the size of integers on which - // Javascript performs bit-operations. For operations like addition and - // multiplication, we split each number into 16 bit pieces, which can easily be - // multiplied within Javascript's floating-point representation without overflow - // or change in sign. - // - // In the algorithms below, we frequently reduce the negative case to the - // positive case by negating the input(s) and then post-processing the result. - // Note that we must ALWAYS check specially whether those values are MIN_VALUE - // (-2^63) because -MIN_VALUE == MIN_VALUE (since 2^63 cannot be represented as - // a positive number, it overflows back into a negative). Not handling this - // case would often result in infinite recursion. - // - // Common constant values ZERO, ONE, NEG_ONE, etc. are defined below the from* - // methods on which they depend. - - /** - * An indicator used to reliably determine if an object is a Long or not. - * @type {boolean} - * @const - * @private - */ - Long.prototype.__isLong__; - - Object.defineProperty(Long.prototype, "__isLong__", { - value: true, - enumerable: false, - configurable: false - }); - - /** - * @function - * @param {*} obj Object - * @returns {boolean} - * @inner - */ - function isLong(obj) { - return (obj && obj["__isLong__"]) === true; - } - - /** - * Tests if the specified object is a Long. - * @function - * @param {*} obj Object - * @returns {boolean} - */ - Long.isLong = isLong; - - /** - * A cache of the Long representations of small integer values. - * @type {!Object} - * @inner - */ - var INT_CACHE = {}; - - /** - * A cache of the Long representations of small unsigned integer values. - * @type {!Object} - * @inner - */ - var UINT_CACHE = {}; - - /** - * @param {number} value - * @param {boolean=} unsigned - * @returns {!Long} - * @inner - */ - function fromInt(value, unsigned) { - var obj, cachedObj, cache; - if (unsigned) { - value >>>= 0; - if (cache = (0 <= value && value < 256)) { - cachedObj = UINT_CACHE[value]; - if (cachedObj) - return cachedObj; - } - obj = fromBits(value, (value | 0) < 0 ? -1 : 0, true); - if (cache) - UINT_CACHE[value] = obj; - return obj; - } else { - value |= 0; - if (cache = (-128 <= value && value < 128)) { - cachedObj = INT_CACHE[value]; - if (cachedObj) - return cachedObj; - } - obj = fromBits(value, value < 0 ? -1 : 0, false); - if (cache) - INT_CACHE[value] = obj; - return obj; - } - } - - /** - * Returns a Long representing the given 32 bit integer value. - * @function - * @param {number} value The 32 bit integer in question - * @param {boolean=} unsigned Whether unsigned or not, defaults to `false` for signed - * @returns {!Long} The corresponding Long value - */ - Long.fromInt = fromInt; - - /** - * @param {number} value - * @param {boolean=} unsigned - * @returns {!Long} - * @inner - */ - function fromNumber(value, unsigned) { - if (isNaN(value) || !isFinite(value)) - return unsigned ? UZERO : ZERO; - if (unsigned) { - if (value < 0) - return UZERO; - if (value >= TWO_PWR_64_DBL) - return MAX_UNSIGNED_VALUE; - } else { - if (value <= -TWO_PWR_63_DBL) - return MIN_VALUE; - if (value + 1 >= TWO_PWR_63_DBL) - return MAX_VALUE; - } - if (value < 0) - return fromNumber(-value, unsigned).neg(); - return fromBits((value % TWO_PWR_32_DBL) | 0, (value / TWO_PWR_32_DBL) | 0, unsigned); - } - - /** - * Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned. - * @function - * @param {number} value The number in question - * @param {boolean=} unsigned Whether unsigned or not, defaults to `false` for signed - * @returns {!Long} The corresponding Long value - */ - Long.fromNumber = fromNumber; - - /** - * @param {number} lowBits - * @param {number} highBits - * @param {boolean=} unsigned - * @returns {!Long} - * @inner - */ - function fromBits(lowBits, highBits, unsigned) { - return new Long(lowBits, highBits, unsigned); - } - - /** - * Returns a Long representing the 64 bit integer that comes by concatenating the given low and high bits. Each is - * assumed to use 32 bits. - * @function - * @param {number} lowBits The low 32 bits - * @param {number} highBits The high 32 bits - * @param {boolean=} unsigned Whether unsigned or not, defaults to `false` for signed - * @returns {!Long} The corresponding Long value - */ - Long.fromBits = fromBits; - - /** - * @function - * @param {number} base - * @param {number} exponent - * @returns {number} - * @inner - */ - var pow_dbl = Math.pow; // Used 4 times (4*8 to 15+4) - - /** - * @param {string} str - * @param {(boolean|number)=} unsigned - * @param {number=} radix - * @returns {!Long} - * @inner - */ - function fromString(str, unsigned, radix) { - if (str.length === 0) - throw Error('empty string'); - if (str === "NaN" || str === "Infinity" || str === "+Infinity" || str === "-Infinity") - return ZERO; - if (typeof unsigned === 'number') { - // For goog.math.long compatibility - radix = unsigned, - unsigned = false; - } else { - unsigned = !! unsigned; - } - radix = radix || 10; - if (radix < 2 || 36 < radix) - throw RangeError('radix'); - - var p; - if ((p = str.indexOf('-')) > 0) - throw Error('interior hyphen'); - else if (p === 0) { - return fromString(str.substring(1), unsigned, radix).neg(); - } - - // Do several (8) digits each time through the loop, so as to - // minimize the calls to the very expensive emulated div. - var radixToPower = fromNumber(pow_dbl(radix, 8)); - - var result = ZERO; - for (var i = 0; i < str.length; i += 8) { - var size = Math.min(8, str.length - i), - value = parseInt(str.substring(i, i + size), radix); - if (size < 8) { - var power = fromNumber(pow_dbl(radix, size)); - result = result.mul(power).add(fromNumber(value)); - } else { - result = result.mul(radixToPower); - result = result.add(fromNumber(value)); - } - } - result.unsigned = unsigned; - return result; - } - - /** - * Returns a Long representation of the given string, written using the specified radix. - * @function - * @param {string} str The textual representation of the Long - * @param {(boolean|number)=} unsigned Whether unsigned or not, defaults to `false` for signed - * @param {number=} radix The radix in which the text is written (2-36), defaults to 10 - * @returns {!Long} The corresponding Long value - */ - Long.fromString = fromString; - - /** - * @function - * @param {!Long|number|string|!{low: number, high: number, unsigned: boolean}} val - * @returns {!Long} - * @inner - */ - function fromValue(val) { - if (val /* is compatible */ instanceof Long) - return val; - if (typeof val === 'number') - return fromNumber(val); - if (typeof val === 'string') - return fromString(val); - // Throws for non-objects, converts non-instanceof Long: - return fromBits(val.low, val.high, val.unsigned); - } - - /** - * Converts the specified value to a Long. - * @function - * @param {!Long|number|string|!{low: number, high: number, unsigned: boolean}} val Value - * @returns {!Long} - */ - Long.fromValue = fromValue; - - // NOTE: the compiler should inline these constant values below and then remove these variables, so there should be - // no runtime penalty for these. - - /** - * @type {number} - * @const - * @inner - */ - var TWO_PWR_16_DBL = 1 << 16; - - /** - * @type {number} - * @const - * @inner - */ - var TWO_PWR_24_DBL = 1 << 24; - - /** - * @type {number} - * @const - * @inner - */ - var TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL; - - /** - * @type {number} - * @const - * @inner - */ - var TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL; - - /** - * @type {number} - * @const - * @inner - */ - var TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2; - - /** - * @type {!Long} - * @const - * @inner - */ - var TWO_PWR_24 = fromInt(TWO_PWR_24_DBL); - - /** - * @type {!Long} - * @inner - */ - var ZERO = fromInt(0); - - /** - * Signed zero. - * @type {!Long} - */ - Long.ZERO = ZERO; - - /** - * @type {!Long} - * @inner - */ - var UZERO = fromInt(0, true); - - /** - * Unsigned zero. - * @type {!Long} - */ - Long.UZERO = UZERO; - - /** - * @type {!Long} - * @inner - */ - var ONE = fromInt(1); - - /** - * Signed one. - * @type {!Long} - */ - Long.ONE = ONE; - - /** - * @type {!Long} - * @inner - */ - var UONE = fromInt(1, true); - - /** - * Unsigned one. - * @type {!Long} - */ - Long.UONE = UONE; - - /** - * @type {!Long} - * @inner - */ - var NEG_ONE = fromInt(-1); - - /** - * Signed negative one. - * @type {!Long} - */ - Long.NEG_ONE = NEG_ONE; - - /** - * @type {!Long} - * @inner - */ - var MAX_VALUE = fromBits(0xFFFFFFFF|0, 0x7FFFFFFF|0, false); - - /** - * Maximum signed value. - * @type {!Long} - */ - Long.MAX_VALUE = MAX_VALUE; - - /** - * @type {!Long} - * @inner - */ - var MAX_UNSIGNED_VALUE = fromBits(0xFFFFFFFF|0, 0xFFFFFFFF|0, true); - - /** - * Maximum unsigned value. - * @type {!Long} - */ - Long.MAX_UNSIGNED_VALUE = MAX_UNSIGNED_VALUE; - - /** - * @type {!Long} - * @inner - */ - var MIN_VALUE = fromBits(0, 0x80000000|0, false); - - /** - * Minimum signed value. - * @type {!Long} - */ - Long.MIN_VALUE = MIN_VALUE; - - /** - * @alias Long.prototype - * @inner - */ - var LongPrototype = Long.prototype; - - /** - * Converts the Long to a 32 bit integer, assuming it is a 32 bit integer. - * @returns {number} - */ - LongPrototype.toInt = function toInt() { - return this.unsigned ? this.low >>> 0 : this.low; - }; - - /** - * Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa). - * @returns {number} - */ - LongPrototype.toNumber = function toNumber() { - if (this.unsigned) - return ((this.high >>> 0) * TWO_PWR_32_DBL) + (this.low >>> 0); - return this.high * TWO_PWR_32_DBL + (this.low >>> 0); - }; - - /** - * Converts the Long to a string written in the specified radix. - * @param {number=} radix Radix (2-36), defaults to 10 - * @returns {string} - * @override - * @throws {RangeError} If `radix` is out of range - */ - LongPrototype.toString = function toString(radix) { - radix = radix || 10; - if (radix < 2 || 36 < radix) - throw RangeError('radix'); - if (this.isZero()) - return '0'; - if (this.isNegative()) { // Unsigned Longs are never negative - if (this.eq(MIN_VALUE)) { - // We need to change the Long value before it can be negated, so we remove - // the bottom-most digit in this base and then recurse to do the rest. - var radixLong = fromNumber(radix), - div = this.div(radixLong), - rem1 = div.mul(radixLong).sub(this); - return div.toString(radix) + rem1.toInt().toString(radix); - } else - return '-' + this.neg().toString(radix); - } - - // Do several (6) digits each time through the loop, so as to - // minimize the calls to the very expensive emulated div. - var radixToPower = fromNumber(pow_dbl(radix, 6), this.unsigned), - rem = this; - var result = ''; - while (true) { - var remDiv = rem.div(radixToPower), - intval = rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0, - digits = intval.toString(radix); - rem = remDiv; - if (rem.isZero()) - return digits + result; - else { - while (digits.length < 6) - digits = '0' + digits; - result = '' + digits + result; - } - } - }; - - /** - * Gets the high 32 bits as a signed integer. - * @returns {number} Signed high bits - */ - LongPrototype.getHighBits = function getHighBits() { - return this.high; - }; - - /** - * Gets the high 32 bits as an unsigned integer. - * @returns {number} Unsigned high bits - */ - LongPrototype.getHighBitsUnsigned = function getHighBitsUnsigned() { - return this.high >>> 0; - }; - - /** - * Gets the low 32 bits as a signed integer. - * @returns {number} Signed low bits - */ - LongPrototype.getLowBits = function getLowBits() { - return this.low; - }; - - /** - * Gets the low 32 bits as an unsigned integer. - * @returns {number} Unsigned low bits - */ - LongPrototype.getLowBitsUnsigned = function getLowBitsUnsigned() { - return this.low >>> 0; - }; - - /** - * Gets the number of bits needed to represent the absolute value of this Long. - * @returns {number} - */ - LongPrototype.getNumBitsAbs = function getNumBitsAbs() { - if (this.isNegative()) // Unsigned Longs are never negative - return this.eq(MIN_VALUE) ? 64 : this.neg().getNumBitsAbs(); - var val = this.high != 0 ? this.high : this.low; - for (var bit = 31; bit > 0; bit--) - if ((val & (1 << bit)) != 0) - break; - return this.high != 0 ? bit + 33 : bit + 1; - }; - - /** - * Tests if this Long's value equals zero. - * @returns {boolean} - */ - LongPrototype.isZero = function isZero() { - return this.high === 0 && this.low === 0; - }; - - /** - * Tests if this Long's value is negative. - * @returns {boolean} - */ - LongPrototype.isNegative = function isNegative() { - return !this.unsigned && this.high < 0; - }; - - /** - * Tests if this Long's value is positive. - * @returns {boolean} - */ - LongPrototype.isPositive = function isPositive() { - return this.unsigned || this.high >= 0; - }; - - /** - * Tests if this Long's value is odd. - * @returns {boolean} - */ - LongPrototype.isOdd = function isOdd() { - return (this.low & 1) === 1; - }; - - /** - * Tests if this Long's value is even. - * @returns {boolean} - */ - LongPrototype.isEven = function isEven() { - return (this.low & 1) === 0; - }; - - /** - * Tests if this Long's value equals the specified's. - * @param {!Long|number|string} other Other value - * @returns {boolean} - */ - LongPrototype.equals = function equals(other) { - if (!isLong(other)) - other = fromValue(other); - if (this.unsigned !== other.unsigned && (this.high >>> 31) === 1 && (other.high >>> 31) === 1) - return false; - return this.high === other.high && this.low === other.low; - }; - - /** - * Tests if this Long's value equals the specified's. This is an alias of {@link Long#equals}. - * @function - * @param {!Long|number|string} other Other value - * @returns {boolean} - */ - LongPrototype.eq = LongPrototype.equals; - - /** - * Tests if this Long's value differs from the specified's. - * @param {!Long|number|string} other Other value - * @returns {boolean} - */ - LongPrototype.notEquals = function notEquals(other) { - return !this.eq(/* validates */ other); - }; - - /** - * Tests if this Long's value differs from the specified's. This is an alias of {@link Long#notEquals}. - * @function - * @param {!Long|number|string} other Other value - * @returns {boolean} - */ - LongPrototype.neq = LongPrototype.notEquals; - - /** - * Tests if this Long's value is less than the specified's. - * @param {!Long|number|string} other Other value - * @returns {boolean} - */ - LongPrototype.lessThan = function lessThan(other) { - return this.comp(/* validates */ other) < 0; - }; - - /** - * Tests if this Long's value is less than the specified's. This is an alias of {@link Long#lessThan}. - * @function - * @param {!Long|number|string} other Other value - * @returns {boolean} - */ - LongPrototype.lt = LongPrototype.lessThan; - - /** - * Tests if this Long's value is less than or equal the specified's. - * @param {!Long|number|string} other Other value - * @returns {boolean} - */ - LongPrototype.lessThanOrEqual = function lessThanOrEqual(other) { - return this.comp(/* validates */ other) <= 0; - }; - - /** - * Tests if this Long's value is less than or equal the specified's. This is an alias of {@link Long#lessThanOrEqual}. - * @function - * @param {!Long|number|string} other Other value - * @returns {boolean} - */ - LongPrototype.lte = LongPrototype.lessThanOrEqual; - - /** - * Tests if this Long's value is greater than the specified's. - * @param {!Long|number|string} other Other value - * @returns {boolean} - */ - LongPrototype.greaterThan = function greaterThan(other) { - return this.comp(/* validates */ other) > 0; - }; - - /** - * Tests if this Long's value is greater than the specified's. This is an alias of {@link Long#greaterThan}. - * @function - * @param {!Long|number|string} other Other value - * @returns {boolean} - */ - LongPrototype.gt = LongPrototype.greaterThan; - - /** - * Tests if this Long's value is greater than or equal the specified's. - * @param {!Long|number|string} other Other value - * @returns {boolean} - */ - LongPrototype.greaterThanOrEqual = function greaterThanOrEqual(other) { - return this.comp(/* validates */ other) >= 0; - }; - - /** - * Tests if this Long's value is greater than or equal the specified's. This is an alias of {@link Long#greaterThanOrEqual}. - * @function - * @param {!Long|number|string} other Other value - * @returns {boolean} - */ - LongPrototype.gte = LongPrototype.greaterThanOrEqual; - - /** - * Compares this Long's value with the specified's. - * @param {!Long|number|string} other Other value - * @returns {number} 0 if they are the same, 1 if the this is greater and -1 - * if the given one is greater - */ - LongPrototype.compare = function compare(other) { - if (!isLong(other)) - other = fromValue(other); - if (this.eq(other)) - return 0; - var thisNeg = this.isNegative(), - otherNeg = other.isNegative(); - if (thisNeg && !otherNeg) - return -1; - if (!thisNeg && otherNeg) - return 1; - // At this point the sign bits are the same - if (!this.unsigned) - return this.sub(other).isNegative() ? -1 : 1; - // Both are positive if at least one is unsigned - return (other.high >>> 0) > (this.high >>> 0) || (other.high === this.high && (other.low >>> 0) > (this.low >>> 0)) ? -1 : 1; - }; - - /** - * Compares this Long's value with the specified's. This is an alias of {@link Long#compare}. - * @function - * @param {!Long|number|string} other Other value - * @returns {number} 0 if they are the same, 1 if the this is greater and -1 - * if the given one is greater - */ - LongPrototype.comp = LongPrototype.compare; - - /** - * Negates this Long's value. - * @returns {!Long} Negated Long - */ - LongPrototype.negate = function negate() { - if (!this.unsigned && this.eq(MIN_VALUE)) - return MIN_VALUE; - return this.not().add(ONE); - }; - - /** - * Negates this Long's value. This is an alias of {@link Long#negate}. - * @function - * @returns {!Long} Negated Long - */ - LongPrototype.neg = LongPrototype.negate; - - /** - * Returns the sum of this and the specified Long. - * @param {!Long|number|string} addend Addend - * @returns {!Long} Sum - */ - LongPrototype.add = function add(addend) { - if (!isLong(addend)) - addend = fromValue(addend); - - // Divide each number into 4 chunks of 16 bits, and then sum the chunks. - - var a48 = this.high >>> 16; - var a32 = this.high & 0xFFFF; - var a16 = this.low >>> 16; - var a00 = this.low & 0xFFFF; - - var b48 = addend.high >>> 16; - var b32 = addend.high & 0xFFFF; - var b16 = addend.low >>> 16; - var b00 = addend.low & 0xFFFF; - - var c48 = 0, c32 = 0, c16 = 0, c00 = 0; - c00 += a00 + b00; - c16 += c00 >>> 16; - c00 &= 0xFFFF; - c16 += a16 + b16; - c32 += c16 >>> 16; - c16 &= 0xFFFF; - c32 += a32 + b32; - c48 += c32 >>> 16; - c32 &= 0xFFFF; - c48 += a48 + b48; - c48 &= 0xFFFF; - return fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned); - }; - - /** - * Returns the difference of this and the specified Long. - * @param {!Long|number|string} subtrahend Subtrahend - * @returns {!Long} Difference - */ - LongPrototype.subtract = function subtract(subtrahend) { - if (!isLong(subtrahend)) - subtrahend = fromValue(subtrahend); - return this.add(subtrahend.neg()); - }; - - /** - * Returns the difference of this and the specified Long. This is an alias of {@link Long#subtract}. - * @function - * @param {!Long|number|string} subtrahend Subtrahend - * @returns {!Long} Difference - */ - LongPrototype.sub = LongPrototype.subtract; - - /** - * Returns the product of this and the specified Long. - * @param {!Long|number|string} multiplier Multiplier - * @returns {!Long} Product - */ - LongPrototype.multiply = function multiply(multiplier) { - if (this.isZero()) - return ZERO; - if (!isLong(multiplier)) - multiplier = fromValue(multiplier); - if (multiplier.isZero()) - return ZERO; - if (this.eq(MIN_VALUE)) - return multiplier.isOdd() ? MIN_VALUE : ZERO; - if (multiplier.eq(MIN_VALUE)) - return this.isOdd() ? MIN_VALUE : ZERO; - - if (this.isNegative()) { - if (multiplier.isNegative()) - return this.neg().mul(multiplier.neg()); - else - return this.neg().mul(multiplier).neg(); - } else if (multiplier.isNegative()) - return this.mul(multiplier.neg()).neg(); - - // If both longs are small, use float multiplication - if (this.lt(TWO_PWR_24) && multiplier.lt(TWO_PWR_24)) - return fromNumber(this.toNumber() * multiplier.toNumber(), this.unsigned); - - // Divide each long into 4 chunks of 16 bits, and then add up 4x4 products. - // We can skip products that would overflow. - - var a48 = this.high >>> 16; - var a32 = this.high & 0xFFFF; - var a16 = this.low >>> 16; - var a00 = this.low & 0xFFFF; - - var b48 = multiplier.high >>> 16; - var b32 = multiplier.high & 0xFFFF; - var b16 = multiplier.low >>> 16; - var b00 = multiplier.low & 0xFFFF; - - var c48 = 0, c32 = 0, c16 = 0, c00 = 0; - c00 += a00 * b00; - c16 += c00 >>> 16; - c00 &= 0xFFFF; - c16 += a16 * b00; - c32 += c16 >>> 16; - c16 &= 0xFFFF; - c16 += a00 * b16; - c32 += c16 >>> 16; - c16 &= 0xFFFF; - c32 += a32 * b00; - c48 += c32 >>> 16; - c32 &= 0xFFFF; - c32 += a16 * b16; - c48 += c32 >>> 16; - c32 &= 0xFFFF; - c32 += a00 * b32; - c48 += c32 >>> 16; - c32 &= 0xFFFF; - c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48; - c48 &= 0xFFFF; - return fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned); - }; - - /** - * Returns the product of this and the specified Long. This is an alias of {@link Long#multiply}. - * @function - * @param {!Long|number|string} multiplier Multiplier - * @returns {!Long} Product - */ - LongPrototype.mul = LongPrototype.multiply; - - /** - * Returns this Long divided by the specified. The result is signed if this Long is signed or - * unsigned if this Long is unsigned. - * @param {!Long|number|string} divisor Divisor - * @returns {!Long} Quotient - */ - LongPrototype.divide = function divide(divisor) { - if (!isLong(divisor)) - divisor = fromValue(divisor); - if (divisor.isZero()) - throw Error('division by zero'); - if (this.isZero()) - return this.unsigned ? UZERO : ZERO; - var approx, rem, res; - if (!this.unsigned) { - // This section is only relevant for signed longs and is derived from the - // closure library as a whole. - if (this.eq(MIN_VALUE)) { - if (divisor.eq(ONE) || divisor.eq(NEG_ONE)) - return MIN_VALUE; // recall that -MIN_VALUE == MIN_VALUE - else if (divisor.eq(MIN_VALUE)) - return ONE; - else { - // At this point, we have |other| >= 2, so |this/other| < |MIN_VALUE|. - var halfThis = this.shr(1); - approx = halfThis.div(divisor).shl(1); - if (approx.eq(ZERO)) { - return divisor.isNegative() ? ONE : NEG_ONE; - } else { - rem = this.sub(divisor.mul(approx)); - res = approx.add(rem.div(divisor)); - return res; - } - } - } else if (divisor.eq(MIN_VALUE)) - return this.unsigned ? UZERO : ZERO; - if (this.isNegative()) { - if (divisor.isNegative()) - return this.neg().div(divisor.neg()); - return this.neg().div(divisor).neg(); - } else if (divisor.isNegative()) - return this.div(divisor.neg()).neg(); - res = ZERO; - } else { - // The algorithm below has not been made for unsigned longs. It's therefore - // required to take special care of the MSB prior to running it. - if (!divisor.unsigned) - divisor = divisor.toUnsigned(); - if (divisor.gt(this)) - return UZERO; - if (divisor.gt(this.shru(1))) // 15 >>> 1 = 7 ; with divisor = 8 ; true - return UONE; - res = UZERO; - } - - // Repeat the following until the remainder is less than other: find a - // floating-point that approximates remainder / other *from below*, add this - // into the result, and subtract it from the remainder. It is critical that - // the approximate value is less than or equal to the real value so that the - // remainder never becomes negative. - rem = this; - while (rem.gte(divisor)) { - // Approximate the result of division. This may be a little greater or - // smaller than the actual value. - approx = Math.max(1, Math.floor(rem.toNumber() / divisor.toNumber())); - - // We will tweak the approximate result by changing it in the 48-th digit or - // the smallest non-fractional digit, whichever is larger. - var log2 = Math.ceil(Math.log(approx) / Math.LN2), - delta = (log2 <= 48) ? 1 : pow_dbl(2, log2 - 48), - - // Decrease the approximation until it is smaller than the remainder. Note - // that if it is too large, the product overflows and is negative. - approxRes = fromNumber(approx), - approxRem = approxRes.mul(divisor); - while (approxRem.isNegative() || approxRem.gt(rem)) { - approx -= delta; - approxRes = fromNumber(approx, this.unsigned); - approxRem = approxRes.mul(divisor); - } - - // We know the answer can't be zero... and actually, zero would cause - // infinite recursion since we would make no progress. - if (approxRes.isZero()) - approxRes = ONE; - - res = res.add(approxRes); - rem = rem.sub(approxRem); - } - return res; - }; - - /** - * Returns this Long divided by the specified. This is an alias of {@link Long#divide}. - * @function - * @param {!Long|number|string} divisor Divisor - * @returns {!Long} Quotient - */ - LongPrototype.div = LongPrototype.divide; - - /** - * Returns this Long modulo the specified. - * @param {!Long|number|string} divisor Divisor - * @returns {!Long} Remainder - */ - LongPrototype.modulo = function modulo(divisor) { - if (!isLong(divisor)) - divisor = fromValue(divisor); - return this.sub(this.div(divisor).mul(divisor)); - }; - - /** - * Returns this Long modulo the specified. This is an alias of {@link Long#modulo}. - * @function - * @param {!Long|number|string} divisor Divisor - * @returns {!Long} Remainder - */ - LongPrototype.mod = LongPrototype.modulo; - - /** - * Returns the bitwise NOT of this Long. - * @returns {!Long} - */ - LongPrototype.not = function not() { - return fromBits(~this.low, ~this.high, this.unsigned); - }; - - /** - * Returns the bitwise AND of this Long and the specified. - * @param {!Long|number|string} other Other Long - * @returns {!Long} - */ - LongPrototype.and = function and(other) { - if (!isLong(other)) - other = fromValue(other); - return fromBits(this.low & other.low, this.high & other.high, this.unsigned); - }; - - /** - * Returns the bitwise OR of this Long and the specified. - * @param {!Long|number|string} other Other Long - * @returns {!Long} - */ - LongPrototype.or = function or(other) { - if (!isLong(other)) - other = fromValue(other); - return fromBits(this.low | other.low, this.high | other.high, this.unsigned); - }; - - /** - * Returns the bitwise XOR of this Long and the given one. - * @param {!Long|number|string} other Other Long - * @returns {!Long} - */ - LongPrototype.xor = function xor(other) { - if (!isLong(other)) - other = fromValue(other); - return fromBits(this.low ^ other.low, this.high ^ other.high, this.unsigned); - }; - - /** - * Returns this Long with bits shifted to the left by the given amount. - * @param {number|!Long} numBits Number of bits - * @returns {!Long} Shifted Long - */ - LongPrototype.shiftLeft = function shiftLeft(numBits) { - if (isLong(numBits)) - numBits = numBits.toInt(); - if ((numBits &= 63) === 0) - return this; - else if (numBits < 32) - return fromBits(this.low << numBits, (this.high << numBits) | (this.low >>> (32 - numBits)), this.unsigned); - else - return fromBits(0, this.low << (numBits - 32), this.unsigned); - }; - - /** - * Returns this Long with bits shifted to the left by the given amount. This is an alias of {@link Long#shiftLeft}. - * @function - * @param {number|!Long} numBits Number of bits - * @returns {!Long} Shifted Long - */ - LongPrototype.shl = LongPrototype.shiftLeft; - - /** - * Returns this Long with bits arithmetically shifted to the right by the given amount. - * @param {number|!Long} numBits Number of bits - * @returns {!Long} Shifted Long - */ - LongPrototype.shiftRight = function shiftRight(numBits) { - if (isLong(numBits)) - numBits = numBits.toInt(); - if ((numBits &= 63) === 0) - return this; - else if (numBits < 32) - return fromBits((this.low >>> numBits) | (this.high << (32 - numBits)), this.high >> numBits, this.unsigned); - else - return fromBits(this.high >> (numBits - 32), this.high >= 0 ? 0 : -1, this.unsigned); - }; - - /** - * Returns this Long with bits arithmetically shifted to the right by the given amount. This is an alias of {@link Long#shiftRight}. - * @function - * @param {number|!Long} numBits Number of bits - * @returns {!Long} Shifted Long - */ - LongPrototype.shr = LongPrototype.shiftRight; - - /** - * Returns this Long with bits logically shifted to the right by the given amount. - * @param {number|!Long} numBits Number of bits - * @returns {!Long} Shifted Long - */ - LongPrototype.shiftRightUnsigned = function shiftRightUnsigned(numBits) { - if (isLong(numBits)) - numBits = numBits.toInt(); - numBits &= 63; - if (numBits === 0) - return this; - else { - var high = this.high; - if (numBits < 32) { - var low = this.low; - return fromBits((low >>> numBits) | (high << (32 - numBits)), high >>> numBits, this.unsigned); - } else if (numBits === 32) - return fromBits(high, 0, this.unsigned); - else - return fromBits(high >>> (numBits - 32), 0, this.unsigned); - } - }; - - /** - * Returns this Long with bits logically shifted to the right by the given amount. This is an alias of {@link Long#shiftRightUnsigned}. - * @function - * @param {number|!Long} numBits Number of bits - * @returns {!Long} Shifted Long - */ - LongPrototype.shru = LongPrototype.shiftRightUnsigned; - - /** - * Converts this Long to signed. - * @returns {!Long} Signed long - */ - LongPrototype.toSigned = function toSigned() { - if (!this.unsigned) - return this; - return fromBits(this.low, this.high, false); - }; - - /** - * Converts this Long to unsigned. - * @returns {!Long} Unsigned long - */ - LongPrototype.toUnsigned = function toUnsigned() { - if (this.unsigned) - return this; - return fromBits(this.low, this.high, true); - }; - - /** - * Converts this Long to its byte representation. - * @param {boolean=} le Whether little or big endian, defaults to big endian - * @returns {!Array.} Byte representation - */ - LongPrototype.toBytes = function(le) { - return le ? this.toBytesLE() : this.toBytesBE(); - } - - /** - * Converts this Long to its little endian byte representation. - * @returns {!Array.} Little endian byte representation - */ - LongPrototype.toBytesLE = function() { - var hi = this.high, - lo = this.low; - return [ - lo & 0xff, - (lo >>> 8) & 0xff, - (lo >>> 16) & 0xff, - (lo >>> 24) & 0xff, - hi & 0xff, - (hi >>> 8) & 0xff, - (hi >>> 16) & 0xff, - (hi >>> 24) & 0xff - ]; - } - - /** - * Converts this Long to its big endian byte representation. - * @returns {!Array.} Big endian byte representation - */ - LongPrototype.toBytesBE = function() { - var hi = this.high, - lo = this.low; - return [ - (hi >>> 24) & 0xff, - (hi >>> 16) & 0xff, - (hi >>> 8) & 0xff, - hi & 0xff, - (lo >>> 24) & 0xff, - (lo >>> 16) & 0xff, - (lo >>> 8) & 0xff, - lo & 0xff - ]; - } - - return Long; -}); -;/* +; +!function(t,i){"object"==typeof exports&&"object"==typeof module?module.exports=i():"function"==typeof define&&define.amd?define([],i):"object"==typeof exports?exports.Long=i():t.Long=i()}("undefined"!=typeof self?self:this,function(){return function(t){function i(e){if(n[e])return n[e].exports;var r=n[e]={i:e,l:!1,exports:{}};return t[e].call(r.exports,r,r.exports,i),r.l=!0,r.exports}var n={};return i.m=t,i.c=n,i.d=function(t,n,e){i.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:e})},i.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(n,"a",n),n},i.o=function(t,i){return Object.prototype.hasOwnProperty.call(t,i)},i.p="",i(i.s=0)}([function(t,i){function n(t,i,n){this.low=0|t,this.high=0|i,this.unsigned=!!n}function e(t){return!0===(t&&t.__isLong__)}function r(t,i){var n,e,r;return i?(t>>>=0,(r=0<=t&&t<256)&&(e=l[t])?e:(n=h(t,(0|t)<0?-1:0,!0),r&&(l[t]=n),n)):(t|=0,(r=-128<=t&&t<128)&&(e=f[t])?e:(n=h(t,t<0?-1:0,!1),r&&(f[t]=n),n))}function s(t,i){if(isNaN(t))return i?p:m;if(i){if(t<0)return p;if(t>=c)return q}else{if(t<=-v)return _;if(t+1>=v)return E}return t<0?s(-t,i).neg():h(t%d|0,t/d|0,i)}function h(t,i,e){return new n(t,i,e)}function u(t,i,n){if(0===t.length)throw Error("empty string");if("NaN"===t||"Infinity"===t||"+Infinity"===t||"-Infinity"===t)return m;if("number"==typeof i?(n=i,i=!1):i=!!i,(n=n||10)<2||360)throw Error("interior hyphen");if(0===e)return u(t.substring(1),i,n).neg();for(var r=s(a(n,8)),h=m,o=0;o>>0:this.low},B.toNumber=function(){return this.unsigned?(this.high>>>0)*d+(this.low>>>0):this.high*d+(this.low>>>0)},B.toString=function(t){if((t=t||10)<2||36>>0,f=g.toString(t);if(h=o,h.isZero())return f+u;for(;f.length<6;)f="0"+f;u=""+f+u}},B.getHighBits=function(){return this.high},B.getHighBitsUnsigned=function(){return this.high>>>0},B.getLowBits=function(){return this.low},B.getLowBitsUnsigned=function(){return this.low>>>0},B.getNumBitsAbs=function(){if(this.isNegative())return this.eq(_)?64:this.neg().getNumBitsAbs();for(var t=0!=this.high?this.high:this.low,i=31;i>0&&0==(t&1<=0},B.isOdd=function(){return 1==(1&this.low)},B.isEven=function(){return 0==(1&this.low)},B.equals=function(t){return e(t)||(t=o(t)),(this.unsigned===t.unsigned||this.high>>>31!=1||t.high>>>31!=1)&&(this.high===t.high&&this.low===t.low)},B.eq=B.equals,B.notEquals=function(t){return!this.eq(t)},B.neq=B.notEquals,B.ne=B.notEquals,B.lessThan=function(t){return this.comp(t)<0},B.lt=B.lessThan,B.lessThanOrEqual=function(t){return this.comp(t)<=0},B.lte=B.lessThanOrEqual,B.le=B.lessThanOrEqual,B.greaterThan=function(t){return this.comp(t)>0},B.gt=B.greaterThan,B.greaterThanOrEqual=function(t){return this.comp(t)>=0},B.gte=B.greaterThanOrEqual,B.ge=B.greaterThanOrEqual,B.compare=function(t){if(e(t)||(t=o(t)),this.eq(t))return 0;var i=this.isNegative(),n=t.isNegative();return i&&!n?-1:!i&&n?1:this.unsigned?t.high>>>0>this.high>>>0||t.high===this.high&&t.low>>>0>this.low>>>0?-1:1:this.sub(t).isNegative()?-1:1},B.comp=B.compare,B.negate=function(){return!this.unsigned&&this.eq(_)?_:this.not().add(y)},B.neg=B.negate,B.add=function(t){e(t)||(t=o(t));var i=this.high>>>16,n=65535&this.high,r=this.low>>>16,s=65535&this.low,u=t.high>>>16,g=65535&t.high,f=t.low>>>16,l=65535&t.low,a=0,d=0,c=0,v=0;return v+=s+l,c+=v>>>16,v&=65535,c+=r+f,d+=c>>>16,c&=65535,d+=n+g,a+=d>>>16,d&=65535,a+=i+u,a&=65535,h(c<<16|v,a<<16|d,this.unsigned)},B.subtract=function(t){return e(t)||(t=o(t)),this.add(t.neg())},B.sub=B.subtract,B.multiply=function(t){if(this.isZero())return m;if(e(t)||(t=o(t)),g){return h(g.mul(this.low,this.high,t.low,t.high),g.get_high(),this.unsigned)}if(t.isZero())return m;if(this.eq(_))return t.isOdd()?_:m;if(t.eq(_))return this.isOdd()?_:m;if(this.isNegative())return t.isNegative()?this.neg().mul(t.neg()):this.neg().mul(t).neg();if(t.isNegative())return this.mul(t.neg()).neg();if(this.lt(w)&&t.lt(w))return s(this.toNumber()*t.toNumber(),this.unsigned);var i=this.high>>>16,n=65535&this.high,r=this.low>>>16,u=65535&this.low,f=t.high>>>16,l=65535&t.high,a=t.low>>>16,d=65535&t.low,c=0,v=0,p=0,y=0;return y+=u*d,p+=y>>>16,y&=65535,p+=r*d,v+=p>>>16,p&=65535,p+=u*a,v+=p>>>16,p&=65535,v+=n*d,c+=v>>>16,v&=65535,v+=r*a,c+=v>>>16,v&=65535,v+=u*l,c+=v>>>16,v&=65535,c+=i*d+n*a+r*l+u*f,c&=65535,h(p<<16|y,c<<16|v,this.unsigned)},B.mul=B.multiply,B.divide=function(t){if(e(t)||(t=o(t)),t.isZero())throw Error("division by zero");if(g){if(!this.unsigned&&-2147483648===this.high&&-1===t.low&&-1===t.high)return this;return h((this.unsigned?g.div_u:g.div_s)(this.low,this.high,t.low,t.high),g.get_high(),this.unsigned)}if(this.isZero())return this.unsigned?p:m;var i,n,r;if(this.unsigned){if(t.unsigned||(t=t.toUnsigned()),t.gt(this))return p;if(t.gt(this.shru(1)))return b;r=p}else{if(this.eq(_)){if(t.eq(y)||t.eq(N))return _;if(t.eq(_))return y;return i=this.shr(1).div(t).shl(1),i.eq(m)?t.isNegative()?y:N:(n=this.sub(t.mul(i)),r=i.add(n.div(t)))}if(t.eq(_))return this.unsigned?p:m;if(this.isNegative())return t.isNegative()?this.neg().div(t.neg()):this.neg().div(t).neg();if(t.isNegative())return this.div(t.neg()).neg();r=m}for(n=this;n.gte(t);){i=Math.max(1,Math.floor(n.toNumber()/t.toNumber()));for(var u=Math.ceil(Math.log(i)/Math.LN2),f=u<=48?1:a(2,u-48),l=s(i),d=l.mul(t);d.isNegative()||d.gt(n);)i-=f,l=s(i,this.unsigned),d=l.mul(t);l.isZero()&&(l=y),r=r.add(l),n=n.sub(d)}return r},B.div=B.divide,B.modulo=function(t){if(e(t)||(t=o(t)),g){return h((this.unsigned?g.rem_u:g.rem_s)(this.low,this.high,t.low,t.high),g.get_high(),this.unsigned)}return this.sub(this.div(t).mul(t))},B.mod=B.modulo,B.rem=B.modulo,B.not=function(){return h(~this.low,~this.high,this.unsigned)},B.and=function(t){return e(t)||(t=o(t)),h(this.low&t.low,this.high&t.high,this.unsigned)},B.or=function(t){return e(t)||(t=o(t)),h(this.low|t.low,this.high|t.high,this.unsigned)},B.xor=function(t){return e(t)||(t=o(t)),h(this.low^t.low,this.high^t.high,this.unsigned)},B.shiftLeft=function(t){return e(t)&&(t=t.toInt()),0==(t&=63)?this:t<32?h(this.low<>>32-t,this.unsigned):h(0,this.low<>>t|this.high<<32-t,this.high>>t,this.unsigned):h(this.high>>t-32,this.high>=0?0:-1,this.unsigned)},B.shr=B.shiftRight,B.shiftRightUnsigned=function(t){if(e(t)&&(t=t.toInt()),0===(t&=63))return this;var i=this.high;if(t<32){return h(this.low>>>t|i<<32-t,i>>>t,this.unsigned)}return 32===t?h(i,0,this.unsigned):h(i>>>t-32,0,this.unsigned)},B.shru=B.shiftRightUnsigned,B.shr_u=B.shiftRightUnsigned,B.toSigned=function(){return this.unsigned?h(this.low,this.high,!1):this},B.toUnsigned=function(){return this.unsigned?this:h(this.low,this.high,!0)},B.toBytes=function(t){return t?this.toBytesLE():this.toBytesBE()},B.toBytesLE=function(){var t=this.high,i=this.low;return[255&i,i>>>8&255,i>>>16&255,i>>>24,255&t,t>>>8&255,t>>>16&255,t>>>24]},B.toBytesBE=function(){var t=this.high,i=this.low;return[t>>>24,t>>>16&255,t>>>8&255,255&t,i>>>24,i>>>16&255,i>>>8&255,255&i]},n.fromBytes=function(t,i,e){return e?n.fromBytesLE(t,i):n.fromBytesBE(t,i)},n.fromBytesLE=function(t,i){return new n(t[0]|t[1]<<8|t[2]<<16|t[3]<<24,t[4]|t[5]<<8|t[6]<<16|t[7]<<24,i)},n.fromBytesBE=function(t,i){return new n(t[4]<<24|t[5]<<16|t[6]<<8|t[7],t[0]<<24|t[1]<<16|t[2]<<8|t[3],i)}}])}); +//# sourceMappingURL=long.js.map; +/* * slip.js: A plain JavaScript SLIP implementation that works in both the browser and Node.js * * Copyright 2014, Colin Clark @@ -2498,14 +1291,15 @@ var osc = osc || {}; return slip; })); -;/*! - * EventEmitter v5.0.0 - git.io/ee +; +/*! + * EventEmitter v5.2.4 - git.io/ee * Unlicense - http://unlicense.org/ * Oliver Caldwell - http://oli.me.uk/ * @preserve */ -;(function () { +;(function (exports) { 'use strict'; /** @@ -2518,7 +1312,6 @@ var osc = osc || {}; // Shortcuts to improve speed and size var proto = EventEmitter.prototype; - var exports = this; var originalGlobalValue = exports.EventEmitter; /** @@ -2619,6 +1412,16 @@ var osc = osc || {}; return response || listeners; }; + function isValidListener (listener) { + if (typeof listener === 'function' || listener instanceof RegExp) { + return true + } else if (listener && typeof listener === 'object') { + return isValidListener(listener.listener) + } else { + return false + } + } + /** * Adds a listener function to the specified event. * The listener will not be added if it is a duplicate. @@ -2630,6 +1433,10 @@ var osc = osc || {}; * @return {Object} Current instance of EventEmitter for chaining. */ proto.addListener = function addListener(evt, listener) { + if (!isValidListener(listener)) { + throw new TypeError('listener must be a function'); + } + var listeners = this.getListenersAsObject(evt); var listenerIsWrapped = typeof listener === 'object'; var key; @@ -2729,7 +1536,7 @@ var osc = osc || {}; /** * Adds listeners in bulk using the manipulateListeners method. - * If you pass an object as the second argument you can add to multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. You can also pass it an event name and an array of listeners to be added. + * If you pass an object as the first argument you can add to multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. You can also pass it an event name and an array of listeners to be added. * You can also pass it a regular expression to add the array of listeners to all events that match it. * Yeah, this function does quite a bit. That's probably a bad thing. * @@ -2744,7 +1551,7 @@ var osc = osc || {}; /** * Removes listeners in bulk using the manipulateListeners method. - * If you pass an object as the second argument you can remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. + * If you pass an object as the first argument you can remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. * You can also pass it an event name and an array of listeners to be removed. * You can also pass it a regular expression to remove the listeners from all events that match it. * @@ -2970,8 +1777,9 @@ var osc = osc || {}; else { exports.EventEmitter = EventEmitter; } -}.call(this)); -;/* +}(this || {})); +; +/* * osc.js: An Open Sound Control library for JavaScript that works in both the browser and Node.js * * Cross-platform base transport library for osc.js. @@ -3192,7 +2000,8 @@ var osc = osc || require("./osc.js"), module.exports = osc; } }()); -;/* +; +/* * osc.js: An Open Sound Control library for JavaScript that works in both the browser and Node.js * * Cross-Platform Web Socket client transport for osc.js. @@ -3277,7 +2086,8 @@ var osc = osc || require("../osc.js"); }; }()); -;/* +; +/* * osc.js: An Open Sound Control library for JavaScript that works in both the browser and Node.js * * Chrome App transports for osc.js diff --git a/dist/osc-chromeapp.min.js b/dist/osc-chromeapp.min.js index f7373a5..b0ea816 100644 --- a/dist/osc-chromeapp.min.js +++ b/dist/osc-chromeapp.min.js @@ -1,3 +1,974 @@ -/*! osc.js 2.2.0, Copyright 2017 Colin Clark | github.com/colinbdclark/osc.js */ +/*! osc.js 2.2.1, Copyright 2018 Colin Clark | github.com/colinbdclark/osc.js */ -var osc=osc||{};!function(){"use strict";osc.SECS_70YRS=2208988800,osc.TWO_32=4294967296,osc.defaults={metadata:!1,unpackSingleArgs:!0},osc.isCommonJS=!("undefined"==typeof module||!module.exports),osc.isNode=osc.isCommonJS&&"undefined"==typeof window,osc.isElectron=!("undefined"==typeof process||!process.versions||!process.versions.electron),osc.isBufferEnv=osc.isNode||osc.isElectron,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};var a="undefined"!=typeof dcodeIO?dcodeIO.Long:"undefined"!=typeof a?a:osc.isNode?require("long"):void 0;osc.dataView=function(a,b,c){return a.buffer?new DataView(a.buffer,b,c):a instanceof ArrayBuffer?new DataView(a,b,c):new DataView(new Uint8Array(a),b,c)},osc.byteArray=function(a){if(a instanceof Uint8Array)return a;var b=a.buffer?a.buffer:a;if(!(b instanceof ArrayBuffer||"undefined"!=typeof b.length&&"string"!=typeof b))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.nativeBuffer=function(a){return osc.isBufferEnv?osc.isBuffer(a)?a:new Buffer(a.buffer?a:new Uint8Array(a)):osc.isTypedArrayView(a)?a:new Uint8Array(a)},osc.copyByteArray=function(a,b,c){if(osc.isTypedArrayView(a)&&osc.isTypedArrayView(b))b.set(a,c);else for(var d=void 0===c?0:c,e=Math.min(b.length-c,a.length),f=0,g=d;f1){var i=Math.floor(h),j=h-i;f+=i,h=j}var k=d+f+osc.SECS_70YRS,l=Math.round(osc.TWO_32*h);return{raw:[k,l]}},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>>=0,(f=0<=a&&a<256)&&(d=i[a])?d:(c=e(a,(0|a)<0?-1:0,!0),f&&(i[a]=c),c)):(a|=0,(f=-128<=a&&a<128)&&(d=h[a])?d:(c=e(a,a<0?-1:0,!1),f&&(h[a]=c),c))}function d(a,b){if(isNaN(a)||!isFinite(a))return b?q:p;if(b){if(a<0)return q;if(a>=m)return v}else{if(a<=-n)return w;if(a+1>=n)return u}return a<0?d(-a,b).neg():e(a%l|0,a/l|0,b)}function e(b,c,d){return new a(b,c,d)}function f(a,b,c){if(0===a.length)throw Error("empty string");if("NaN"===a||"Infinity"===a||"+Infinity"===a||"-Infinity"===a)return p;if("number"==typeof b?(c=b,b=!1):b=!!b,c=c||10,c<2||360)throw Error("interior hyphen");if(0===e)return f(a.substring(1),b,c).neg();for(var g=d(j(c,8)),h=p,i=0;i>>0:this.low},x.toNumber=function(){return this.unsigned?(this.high>>>0)*l+(this.low>>>0):this.high*l+(this.low>>>0)},x.toString=function(a){if(a=a||10,a<2||36>>0,l=k.toString(a);if(g=i,g.isZero())return l+h;for(;l.length<6;)l="0"+l;h=""+l+h}},x.getHighBits=function(){return this.high},x.getHighBitsUnsigned=function(){return this.high>>>0},x.getLowBits=function(){return this.low},x.getLowBitsUnsigned=function(){return this.low>>>0},x.getNumBitsAbs=function(){if(this.isNegative())return this.eq(w)?64:this.neg().getNumBitsAbs();for(var a=0!=this.high?this.high:this.low,b=31;b>0&&0==(a&1<=0},x.isOdd=function(){return 1===(1&this.low)},x.isEven=function(){return 0===(1&this.low)},x.equals=function(a){return b(a)||(a=g(a)),(this.unsigned===a.unsigned||this.high>>>31!==1||a.high>>>31!==1)&&(this.high===a.high&&this.low===a.low)},x.eq=x.equals,x.notEquals=function(a){return!this.eq(a)},x.neq=x.notEquals,x.lessThan=function(a){return this.comp(a)<0},x.lt=x.lessThan,x.lessThanOrEqual=function(a){return this.comp(a)<=0},x.lte=x.lessThanOrEqual,x.greaterThan=function(a){return this.comp(a)>0},x.gt=x.greaterThan,x.greaterThanOrEqual=function(a){return this.comp(a)>=0},x.gte=x.greaterThanOrEqual,x.compare=function(a){if(b(a)||(a=g(a)),this.eq(a))return 0;var c=this.isNegative(),d=a.isNegative();return c&&!d?-1:!c&&d?1:this.unsigned?a.high>>>0>this.high>>>0||a.high===this.high&&a.low>>>0>this.low>>>0?-1:1:this.sub(a).isNegative()?-1:1},x.comp=x.compare,x.negate=function(){return!this.unsigned&&this.eq(w)?w:this.not().add(r)},x.neg=x.negate,x.add=function(a){b(a)||(a=g(a));var c=this.high>>>16,d=65535&this.high,f=this.low>>>16,h=65535&this.low,i=a.high>>>16,j=65535&a.high,k=a.low>>>16,l=65535&a.low,m=0,n=0,o=0,p=0;return p+=h+l,o+=p>>>16,p&=65535,o+=f+k,n+=o>>>16,o&=65535,n+=d+j,m+=n>>>16,n&=65535,m+=c+i,m&=65535,e(o<<16|p,m<<16|n,this.unsigned)},x.subtract=function(a){return b(a)||(a=g(a)),this.add(a.neg())},x.sub=x.subtract,x.multiply=function(a){if(this.isZero())return p;if(b(a)||(a=g(a)),a.isZero())return p;if(this.eq(w))return a.isOdd()?w:p;if(a.eq(w))return this.isOdd()?w:p;if(this.isNegative())return a.isNegative()?this.neg().mul(a.neg()):this.neg().mul(a).neg();if(a.isNegative())return this.mul(a.neg()).neg();if(this.lt(o)&&a.lt(o))return d(this.toNumber()*a.toNumber(),this.unsigned);var c=this.high>>>16,f=65535&this.high,h=this.low>>>16,i=65535&this.low,j=a.high>>>16,k=65535&a.high,l=a.low>>>16,m=65535&a.low,n=0,q=0,r=0,s=0;return s+=i*m,r+=s>>>16,s&=65535,r+=h*m,q+=r>>>16,r&=65535,r+=i*l,q+=r>>>16,r&=65535,q+=f*m,n+=q>>>16,q&=65535,q+=h*l,n+=q>>>16,q&=65535,q+=i*k,n+=q>>>16,q&=65535,n+=c*m+f*l+h*k+i*j,n&=65535,e(r<<16|s,n<<16|q,this.unsigned)},x.mul=x.multiply,x.divide=function(a){if(b(a)||(a=g(a)),a.isZero())throw Error("division by zero");if(this.isZero())return this.unsigned?q:p;var c,e,f;if(this.unsigned){if(a.unsigned||(a=a.toUnsigned()),a.gt(this))return q;if(a.gt(this.shru(1)))return s;f=q}else{if(this.eq(w)){if(a.eq(r)||a.eq(t))return w;if(a.eq(w))return r;var h=this.shr(1);return c=h.div(a).shl(1),c.eq(p)?a.isNegative()?r:t:(e=this.sub(a.mul(c)),f=c.add(e.div(a)))}if(a.eq(w))return this.unsigned?q:p;if(this.isNegative())return a.isNegative()?this.neg().div(a.neg()):this.neg().div(a).neg();if(a.isNegative())return this.div(a.neg()).neg();f=p}for(e=this;e.gte(a);){c=Math.max(1,Math.floor(e.toNumber()/a.toNumber()));for(var i=Math.ceil(Math.log(c)/Math.LN2),k=i<=48?1:j(2,i-48),l=d(c),m=l.mul(a);m.isNegative()||m.gt(e);)c-=k,l=d(c,this.unsigned),m=l.mul(a);l.isZero()&&(l=r),f=f.add(l),e=e.sub(m)}return f},x.div=x.divide,x.modulo=function(a){return b(a)||(a=g(a)),this.sub(this.div(a).mul(a))},x.mod=x.modulo,x.not=function(){return e(~this.low,~this.high,this.unsigned)},x.and=function(a){return b(a)||(a=g(a)),e(this.low&a.low,this.high&a.high,this.unsigned)},x.or=function(a){return b(a)||(a=g(a)),e(this.low|a.low,this.high|a.high,this.unsigned)},x.xor=function(a){return b(a)||(a=g(a)),e(this.low^a.low,this.high^a.high,this.unsigned)},x.shiftLeft=function(a){return b(a)&&(a=a.toInt()),0===(a&=63)?this:a<32?e(this.low<>>32-a,this.unsigned):e(0,this.low<>>a|this.high<<32-a,this.high>>a,this.unsigned):e(this.high>>a-32,this.high>=0?0:-1,this.unsigned)},x.shr=x.shiftRight,x.shiftRightUnsigned=function(a){if(b(a)&&(a=a.toInt()),a&=63,0===a)return this;var c=this.high;if(a<32){var d=this.low;return e(d>>>a|c<<32-a,c>>>a,this.unsigned)}return 32===a?e(c,0,this.unsigned):e(c>>>a-32,0,this.unsigned)},x.shru=x.shiftRightUnsigned,x.toSigned=function(){return this.unsigned?e(this.low,this.high,!1):this},x.toUnsigned=function(){return this.unsigned?this:e(this.low,this.high,!0)},x.toBytes=function(a){return a?this.toBytesLE():this.toBytesBE()},x.toBytesLE=function(){var a=this.high,b=this.low;return[255&b,b>>>8&255,b>>>16&255,b>>>24&255,255&a,a>>>8&255,a>>>16&255,a>>>24&255]},x.toBytesBE=function(){var a=this.high,b=this.low;return[a>>>24&255,a>>>16&255,a>>>8&255,255&a,b>>>24&255,b>>>16&255,b>>>8&255,255&b]},a}),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;ge.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;dthis.msgBuffer.length-1&&(this.msgBuffer=b.expandByteArray(this.msgBuffer)),this.msgBuffer[this.msgBufferIdx++]=a,this.escape=!1,this.msgBuffer.length1)&&(this.socket=new osc.WebSocket(this.options.url)),osc.WebSocketPort.setupSocketForBinary(this.socket);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,b)},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){return this.socket&&1===this.socket.readyState?void this.socket.send(a):void osc.fireClosedPortSendError(this)},a.close=function(a,b){this.socket.close(a,b)},osc.WebSocketPort.setupSocketForBinary=function(a){a.binaryType=osc.isNode?"nodebuffer":"arraybuffer"}}();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)}),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),this.connectionId=this.options.connectionId,this.connectionId&&this.emit("open",this.connectionId)};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)return void osc.fireClosedPortSendError(this);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)),this.socketId=b.socketId,this.socketId&&this.emit("open",0)},a=osc.UDPPort.prototype=Object.create(osc.Port.prototype),a.constructor=osc.UDPPort,a.open=function(){if(!this.socketId){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;void 0!==b.broadcast&&chrome.sockets.udp.setBroadcast(this.socketId,b.broadcast,function(b){b<0&&a.emit("error",new Error("An error occurred while setting the socket's broadcast flag. Result code: "+b))}),void 0!==b.multicastTTL&&chrome.sockets.udp.setMulticastTimeToLive(this.socketId,b.multicastTTL,function(b){b<0&&a.emit("error",new Error("An error occurred while setting the socket's multicast time to live flag. Result code: "+b))}),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(){var a=this.options;osc.listenToTransport(this,chrome.sockets.udp,"socketId"),a.multicastMembership&&("string"==typeof a.multicastMembership&&(a.multicastMembership=[a.multicastMembership]),a.multicastMembership.forEach(function(a){chrome.sockets.udp.joinGroup(this.socketId,a,function(b){b<0&&this.emit("error",new Error("There was an error while trying to join the multicast group "+a+". Result code: "+b))})}))},a.sendRaw=function(a,b,c){if(!this.socketId)return void osc.fireClosedPortSendError(this);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")})}}}(); \ No newline at end of file + +var osc = osc || {}; + +!function() { + "use strict"; + osc.SECS_70YRS = 2208988800, osc.TWO_32 = 4294967296, osc.defaults = { + metadata: !1, + unpackSingleArgs: !0 + }, osc.isCommonJS = !("undefined" == typeof module || !module.exports), osc.isNode = osc.isCommonJS && "undefined" == typeof window, + osc.isElectron = !("undefined" == typeof process || !process.versions || !process.versions.electron), + osc.isBufferEnv = osc.isNode || osc.isElectron, osc.isArray = function(e) { + return e && "[object Array]" === Object.prototype.toString.call(e); + }, osc.isTypedArrayView = function(e) { + return e.buffer && e.buffer instanceof ArrayBuffer; + }, osc.isBuffer = function(e) { + return osc.isBufferEnv && e instanceof Buffer; + }, osc.Long = "undefined" != typeof Long ? Long : osc.isNode ? require("long") : void 0, + osc.dataView = function(e, t, r) { + return e.buffer ? new DataView(e.buffer, t, r) : e instanceof ArrayBuffer ? new DataView(e, t, r) : new DataView(new Uint8Array(e), t, r); + }, osc.byteArray = function(e) { + if (e instanceof Uint8Array) return e; + var t = e.buffer ? e.buffer : e; + if (!(t instanceof ArrayBuffer || void 0 !== t.length && "string" != typeof t)) throw new Error("Can't wrap a non-array-like object as Uint8Array. Object was: " + JSON.stringify(e, null, 2)); + return new Uint8Array(t); + }, osc.nativeBuffer = function(e) { + return osc.isBufferEnv ? osc.isBuffer(e) ? e : new Buffer(e.buffer ? e : new Uint8Array(e)) : osc.isTypedArrayView(e) ? e : new Uint8Array(e); + }, osc.copyByteArray = function(e, t, r) { + if (osc.isTypedArrayView(e) && osc.isTypedArrayView(t)) t.set(e, r); else for (var n = void 0 === r ? 0 : r, i = Math.min(t.length - r, e.length), s = 0, o = n; s < i; s++, + o++) t[o] = e[s]; + return t; + }, osc.readString = function(e, t) { + for (var r = [], n = t.idx; n < e.byteLength; n++) { + var i = e.getUint8(n); + if (0 === i) { + n++; + break; + } + r.push(i); + } + if (n = n + 3 & -4, t.idx = n, ("undefined" != typeof global ? global : window).hasOwnProperty("Buffer")) return Buffer.from ? Buffer.from(r).toString("utf-8") : new Buffer(r).toString("utf-8"); + if (("undefined" != typeof global ? global : window).hasOwnProperty("TextDecoder")) return new TextDecoder("utf-8").decode(new Int8Array(r)); + for (var s = "", o = 0; o < r.length; o += 1e4) s += String.fromCharCode.apply(null, r.slice(o, o + 1e4)); + return s; + }, osc.writeString = function(e) { + for (var t = e + "\0", r = t.length, n = new Uint8Array(r + 3 & -4), i = 0; i < t.length; i++) { + var s = t.charCodeAt(i); + n[i] = s; + } + return n; + }, osc.readPrimitive = function(e, t, r, n) { + var i = e[t](n.idx, !1); + return n.idx += r, i; + }, osc.writePrimitive = function(e, t, r, n, i) { + var s; + return i = void 0 === i ? 0 : i, t ? s = new Uint8Array(t.buffer) : (s = new Uint8Array(n), + t = new DataView(s.buffer)), t[r](i, e, !1), s; + }, osc.readInt32 = function(e, t) { + return osc.readPrimitive(e, "getInt32", 4, t); + }, osc.writeInt32 = function(e, t, r) { + return osc.writePrimitive(e, t, "setInt32", 4, r); + }, osc.readInt64 = function(e, t) { + var r = osc.readPrimitive(e, "getInt32", 4, t), n = osc.readPrimitive(e, "getInt32", 4, t); + return osc.Long ? new osc.Long(n, r) : { + high: r, + low: n, + unsigned: !1 + }; + }, osc.writeInt64 = function(e, t, r) { + var n = new Uint8Array(8); + return n.set(osc.writePrimitive(e.high, t, "setInt32", 4, r), 0), n.set(osc.writePrimitive(e.low, t, "setInt32", 4, r + 4), 4), + n; + }, osc.readFloat32 = function(e, t) { + return osc.readPrimitive(e, "getFloat32", 4, t); + }, osc.writeFloat32 = function(e, t, r) { + return osc.writePrimitive(e, t, "setFloat32", 4, r); + }, osc.readFloat64 = function(e, t) { + return osc.readPrimitive(e, "getFloat64", 8, t); + }, osc.writeFloat64 = function(e, t, r) { + return osc.writePrimitive(e, t, "setFloat64", 8, r); + }, osc.readChar32 = function(e, t) { + var r = osc.readPrimitive(e, "getUint32", 4, t); + return String.fromCharCode(r); + }, osc.writeChar32 = function(e, t, r) { + var n = e.charCodeAt(0); + if (!(void 0 === n || n < -1)) return osc.writePrimitive(n, t, "setUint32", 4, r); + }, osc.readBlob = function(e, t) { + var r = osc.readInt32(e, t), n = r + 3 & -4, i = new Uint8Array(e.buffer, t.idx, r); + return t.idx += n, i; + }, osc.writeBlob = function(e) { + var t = (e = osc.byteArray(e)).byteLength, r = new Uint8Array((t + 3 & -4) + 4), n = new DataView(r.buffer); + return osc.writeInt32(t, n), r.set(e, 4), r; + }, osc.readMIDIBytes = function(e, t) { + var r = new Uint8Array(e.buffer, t.idx, 4); + return t.idx += 4, r; + }, osc.writeMIDIBytes = function(e) { + e = osc.byteArray(e); + var t = new Uint8Array(4); + return t.set(e), t; + }, osc.readColor = function(e, t) { + var r = new Uint8Array(e.buffer, t.idx, 4), n = r[3] / 255; + return t.idx += 4, { + r: r[0], + g: r[1], + b: r[2], + a: n + }; + }, osc.writeColor = function(e) { + var t = Math.round(255 * e.a); + return new Uint8Array([ e.r, e.g, e.b, t ]); + }, osc.readTrue = function() { + return !0; + }, osc.readFalse = function() { + return !1; + }, osc.readNull = function() { + return null; + }, osc.readImpulse = function() { + return 1; + }, osc.readTimeTag = function(e, t) { + var r = osc.readPrimitive(e, "getUint32", 4, t), n = osc.readPrimitive(e, "getUint32", 4, t); + return { + raw: [ r, n ], + native: 0 === r && 1 === n ? Date.now() : osc.ntpToJSTime(r, n) + }; + }, osc.writeTimeTag = function(e) { + var t = e.raw ? e.raw : osc.jsToNTPTime(e.native), r = new Uint8Array(8), n = new DataView(r.buffer); + return osc.writeInt32(t[0], n, 0), osc.writeInt32(t[1], n, 4), r; + }, osc.timeTag = function(e, t) { + e = e || 0; + var r = (t = t || Date.now()) / 1e3, n = Math.floor(r), i = r - n, s = Math.floor(e), o = i + (e - s); + if (1 < o) { + var a = Math.floor(o); + s += a, o = o - a; + } + return { + raw: [ n + s + osc.SECS_70YRS, Math.round(osc.TWO_32 * o) ] + }; + }, osc.ntpToJSTime = function(e, t) { + return 1e3 * (e - osc.SECS_70YRS + t / osc.TWO_32); + }, osc.jsToNTPTime = function(e) { + var t = e / 1e3, r = Math.floor(t), n = t - r; + return [ r + osc.SECS_70YRS, Math.round(osc.TWO_32 * n) ]; + }, osc.readArguments = function(e, t, r) { + var n = osc.readString(e, r); + if (0 !== n.indexOf(",")) throw new Error("A malformed type tag string was found while reading the arguments of an OSC message. String was: " + n, " at offset: " + r.idx); + var i = n.substring(1).split(""), s = []; + return osc.readArgumentsIntoArray(s, i, n, e, t, r), s; + }, osc.readArgument = function(e, t, r, n, i) { + var s = osc.argumentTypes[e]; + if (!s) throw new Error("'" + e + "' is not a valid OSC type tag. Type tag string was: " + t); + var o = s.reader, a = osc[o](r, i); + return n.metadata && (a = { + type: e, + value: a + }), a; + }, osc.readArgumentsIntoArray = function(e, t, r, n, i, s) { + for (var o = 0; o < t.length; ) { + var a, c = t[o]; + if ("[" === c) { + var u = t.slice(o + 1), h = u.indexOf("]"); + if (h < 0) throw new Error("Invalid argument type tag: an open array type tag ('[') was found without a matching close array tag ('[]'). Type tag was: " + r); + var f = u.slice(0, h); + a = osc.readArgumentsIntoArray([], f, r, n, i, s), o += h + 2; + } else a = osc.readArgument(c, r, n, i, s), o++; + e.push(a); + } + return e; + }, osc.writeArguments = function(e, t) { + var r = osc.collectArguments(e, t); + return osc.joinParts(r); + }, osc.joinParts = function(e) { + for (var t = new Uint8Array(e.byteLength), r = e.parts, n = 0, i = 0; i < r.length; i++) { + var s = r[i]; + osc.copyByteArray(s, t, n), n += s.length; + } + return t; + }, osc.addDataPart = function(e, t) { + t.parts.push(e), t.byteLength += e.length; + }, osc.writeArrayArguments = function(e, t) { + for (var r = "[", n = 0; n < e.length; n++) { + var i = e[n]; + r += osc.writeArgument(i, t); + } + return r += "]"; + }, osc.writeArgument = function(e, t) { + if (osc.isArray(e)) return osc.writeArrayArguments(e, t); + var r = e.type, n = osc.argumentTypes[r].writer; + if (n) { + var i = osc[n](e.value); + osc.addDataPart(i, t); + } + return e.type; + }, osc.collectArguments = function(e, t, r) { + osc.isArray(e) || (e = void 0 === e ? [] : [ e ]), r = r || { + byteLength: 0, + parts: [] + }, t.metadata || (e = osc.annotateArguments(e)); + for (var n = ",", i = r.parts.length, s = 0; s < e.length; s++) { + var o = e[s]; + n += osc.writeArgument(o, r); + } + var a = osc.writeString(n); + return r.byteLength += a.byteLength, r.parts.splice(i, 0, a), r; + }, osc.readMessage = function(e, t, r) { + t = t || osc.defaults; + var n = osc.dataView(e, e.byteOffset, e.byteLength); + r = r || { + idx: 0 + }; + var i = osc.readString(n, r); + return osc.readMessageContents(i, n, t, r); + }, osc.readMessageContents = function(e, t, r, n) { + if (0 !== e.indexOf("/")) throw new Error("A malformed OSC address was found while reading an OSC message. String was: " + e); + var i = osc.readArguments(t, r, n); + return { + address: e, + args: 1 === i.length && r.unpackSingleArgs ? i[0] : i + }; + }, osc.collectMessageParts = function(e, t, r) { + return r = r || { + byteLength: 0, + parts: [] + }, osc.addDataPart(osc.writeString(e.address), r), osc.collectArguments(e.args, t, r); + }, osc.writeMessage = function(e, t) { + if (t = t || osc.defaults, !osc.isValidMessage(e)) throw new Error("An OSC message must contain a valid address. Message was: " + JSON.stringify(e, null, 2)); + var r = osc.collectMessageParts(e, t); + return osc.joinParts(r); + }, osc.isValidMessage = function(e) { + return e.address && 0 === e.address.indexOf("/"); + }, osc.readBundle = function(e, t, r) { + return osc.readPacket(e, t, r); + }, osc.collectBundlePackets = function(e, t, r) { + r = r || { + byteLength: 0, + parts: [] + }, osc.addDataPart(osc.writeString("#bundle"), r), osc.addDataPart(osc.writeTimeTag(e.timeTag), r); + for (var n = 0; n < e.packets.length; n++) { + var i = e.packets[n], s = (i.address ? osc.collectMessageParts : osc.collectBundlePackets)(i, t); + r.byteLength += s.byteLength, osc.addDataPart(osc.writeInt32(s.byteLength), r), + r.parts = r.parts.concat(s.parts); + } + return r; + }, osc.writeBundle = function(e, t) { + if (!osc.isValidBundle(e)) throw new Error("An OSC bundle must contain 'timeTag' and 'packets' properties. Bundle was: " + JSON.stringify(e, null, 2)); + t = t || osc.defaults; + var r = osc.collectBundlePackets(e, t); + return osc.joinParts(r); + }, osc.isValidBundle = function(e) { + return void 0 !== e.timeTag && void 0 !== e.packets; + }, osc.readBundleContents = function(e, t, r, n) { + for (var i = osc.readTimeTag(e, r), s = []; r.idx < n; ) { + var o = osc.readInt32(e, r), a = r.idx + o, c = osc.readPacket(e, t, r, a); + s.push(c); + } + return { + timeTag: i, + packets: s + }; + }, osc.readPacket = function(e, t, r, n) { + var i = osc.dataView(e, e.byteOffset, e.byteLength); + n = void 0 === n ? i.byteLength : n, r = r || { + idx: 0 + }; + var s = osc.readString(i, r), o = s[0]; + if ("#" === o) return osc.readBundleContents(i, t, r, n); + if ("/" === o) return osc.readMessageContents(s, i, t, r); + throw new Error("The header of an OSC packet didn't contain an OSC address or a #bundle string. Header was: " + s); + }, osc.writePacket = function(e, t) { + if (osc.isValidMessage(e)) return osc.writeMessage(e, t); + if (osc.isValidBundle(e)) return osc.writeBundle(e, t); + throw new Error("The specified packet was not recognized as a valid OSC message or bundle. Packet was: " + JSON.stringify(e, null, 2)); + }, osc.argumentTypes = { + i: { + reader: "readInt32", + writer: "writeInt32" + }, + h: { + reader: "readInt64", + writer: "writeInt64" + }, + 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(e) { + switch (typeof e) { + case "boolean": + return e ? "T" : "F"; + + case "string": + return "s"; + + case "number": + return "f"; + + case "undefined": + return "N"; + + case "object": + if (null === e) return "N"; + if (e instanceof Uint8Array || e instanceof ArrayBuffer) return "b"; + if ("number" == typeof e.high && "number" == typeof e.low) return "h"; + } + throw new Error("Can't infer OSC argument type for value: " + JSON.stringify(e, null, 2)); + }, osc.annotateArguments = function(e) { + for (var t = [], r = 0; r < e.length; r++) { + var n, i = e[r]; + if ("object" == typeof i && i.type && void 0 !== i.value) n = i; else if (osc.isArray(i)) n = osc.annotateArguments(i); else { + n = { + type: osc.inferTypeForArgument(i), + value: i + }; + } + t.push(n); + } + return t; + }, osc.isCommonJS && (module.exports = osc); +}(), function(e, t) { + "object" == typeof exports && "object" == typeof module ? module.exports = t() : "function" == typeof define && define.amd ? define([], t) : "object" == typeof exports ? exports.Long = t() : e.Long = t(); +}("undefined" != typeof self ? self : this, function() { + return function(r) { + function n(e) { + if (i[e]) return i[e].exports; + var t = i[e] = { + i: e, + l: !1, + exports: {} + }; + return r[e].call(t.exports, t, t.exports, n), t.l = !0, t.exports; + } + var i = {}; + return n.m = r, n.c = i, n.d = function(e, t, r) { + n.o(e, t) || Object.defineProperty(e, t, { + configurable: !1, + enumerable: !0, + get: r + }); + }, n.n = function(e) { + var t = e && e.__esModule ? function() { + return e.default; + } : function() { + return e; + }; + return n.d(t, "a", t), t; + }, n.o = function(e, t) { + return Object.prototype.hasOwnProperty.call(e, t); + }, n.p = "", n(n.s = 0); + }([ function(e, t) { + function n(e, t, r) { + this.low = 0 | e, this.high = 0 | t, this.unsigned = !!r; + } + function l(e) { + return !0 === (e && e.__isLong__); + } + function r(e, t) { + var r, n, i; + return t ? (i = 0 <= (e >>>= 0) && e < 256) && (n = o[e]) ? n : (r = p(e, (0 | e) < 0 ? -1 : 0, !0), + i && (o[e] = r), r) : (i = -128 <= (e |= 0) && e < 128) && (n = s[e]) ? n : (r = p(e, e < 0 ? -1 : 0, !1), + i && (s[e] = r), r); + } + function g(e, t) { + if (isNaN(e)) return t ? u : y; + if (t) { + if (e < 0) return u; + if (a <= e) return P; + } else { + if (e <= -c) return A; + if (c <= e + 1) return E; + } + return e < 0 ? g(-e, t).neg() : p(e % i | 0, e / i | 0, t); + } + function p(e, t, r) { + return new n(e, t, r); + } + function h(e, t, r) { + if (0 === e.length) throw Error("empty string"); + if ("NaN" === e || "Infinity" === e || "+Infinity" === e || "-Infinity" === e) return y; + if ("number" == typeof t ? (r = t, t = !1) : t = !!t, (r = r || 10) < 2 || 36 < r) throw RangeError("radix"); + var n; + if (0 < (n = e.indexOf("-"))) throw Error("interior hyphen"); + if (0 === n) return h(e.substring(1), t, r).neg(); + for (var i = g(f(r, 8)), s = y, o = 0; o < e.length; o += 8) { + var a = Math.min(8, e.length - o), c = parseInt(e.substring(o, o + a), r); + if (a < 8) { + var u = g(f(r, a)); + s = s.mul(u).add(g(c)); + } else s = (s = s.mul(i)).add(g(c)); + } + return s.unsigned = t, s; + } + function m(e, t) { + return "number" == typeof e ? g(e, t) : "string" == typeof e ? h(e, t) : p(e.low, e.high, "boolean" == typeof t ? t : e.unsigned); + } + e.exports = n; + var v = null; + try { + v = new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([ 0, 97, 115, 109, 1, 0, 0, 0, 1, 13, 2, 96, 0, 1, 127, 96, 4, 127, 127, 127, 127, 1, 127, 3, 7, 6, 0, 1, 1, 1, 1, 1, 6, 6, 1, 127, 1, 65, 0, 11, 7, 50, 6, 3, 109, 117, 108, 0, 1, 5, 100, 105, 118, 95, 115, 0, 2, 5, 100, 105, 118, 95, 117, 0, 3, 5, 114, 101, 109, 95, 115, 0, 4, 5, 114, 101, 109, 95, 117, 0, 5, 8, 103, 101, 116, 95, 104, 105, 103, 104, 0, 0, 10, 191, 1, 6, 4, 0, 35, 0, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 126, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 127, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 128, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 129, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 130, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11 ])), {}).exports; + } catch (e) {} + Object.defineProperty(n.prototype, "__isLong__", { + value: !0 + }), n.isLong = l; + var s = {}, o = {}; + n.fromInt = r, n.fromNumber = g, n.fromBits = p; + var f = Math.pow; + n.fromString = h, n.fromValue = m; + var i = 4294967296, a = i * i, c = a / 2, w = r(1 << 24), y = r(0); + n.ZERO = y; + var u = r(0, !0); + n.UZERO = u; + var d = r(1); + n.ONE = d; + var b = r(1, !0); + n.UONE = b; + var S = r(-1); + n.NEG_ONE = S; + var E = p(-1, 2147483647, !1); + n.MAX_VALUE = E; + var P = p(-1, -1, !0); + n.MAX_UNSIGNED_VALUE = P; + var A = p(0, -2147483648, !1); + n.MIN_VALUE = A; + var I = n.prototype; + I.toInt = function() { + return this.unsigned ? this.low >>> 0 : this.low; + }, I.toNumber = function() { + return this.unsigned ? (this.high >>> 0) * i + (this.low >>> 0) : this.high * i + (this.low >>> 0); + }, I.toString = function(e) { + if ((e = e || 10) < 2 || 36 < e) throw RangeError("radix"); + if (this.isZero()) return "0"; + if (this.isNegative()) { + if (this.eq(A)) { + var t = g(e), r = this.div(t), n = r.mul(t).sub(this); + return r.toString(e) + n.toInt().toString(e); + } + return "-" + this.neg().toString(e); + } + for (var i = g(f(e, 6), this.unsigned), s = this, o = ""; ;) { + var a = s.div(i), c = (s.sub(a.mul(i)).toInt() >>> 0).toString(e); + if ((s = a).isZero()) return c + o; + for (;c.length < 6; ) c = "0" + c; + o = "" + c + o; + } + }, I.getHighBits = function() { + return this.high; + }, I.getHighBitsUnsigned = function() { + return this.high >>> 0; + }, I.getLowBits = function() { + return this.low; + }, I.getLowBitsUnsigned = function() { + return this.low >>> 0; + }, I.getNumBitsAbs = function() { + if (this.isNegative()) return this.eq(A) ? 64 : this.neg().getNumBitsAbs(); + for (var e = 0 != this.high ? this.high : this.low, t = 31; 0 < t && 0 == (e & 1 << t); t--) ; + return 0 != this.high ? t + 33 : t + 1; + }, I.isZero = function() { + return 0 === this.high && 0 === this.low; + }, I.eqz = I.isZero, I.isNegative = function() { + return !this.unsigned && this.high < 0; + }, I.isPositive = function() { + return this.unsigned || 0 <= this.high; + }, I.isOdd = function() { + return 1 == (1 & this.low); + }, I.isEven = function() { + return 0 == (1 & this.low); + }, I.equals = function(e) { + return l(e) || (e = m(e)), (this.unsigned === e.unsigned || this.high >>> 31 != 1 || e.high >>> 31 != 1) && this.high === e.high && this.low === e.low; + }, I.eq = I.equals, I.notEquals = function(e) { + return !this.eq(e); + }, I.neq = I.notEquals, I.ne = I.notEquals, I.lessThan = function(e) { + return this.comp(e) < 0; + }, I.lt = I.lessThan, I.lessThanOrEqual = function(e) { + return this.comp(e) <= 0; + }, I.lte = I.lessThanOrEqual, I.le = I.lessThanOrEqual, I.greaterThan = function(e) { + return 0 < this.comp(e); + }, I.gt = I.greaterThan, I.greaterThanOrEqual = function(e) { + return 0 <= this.comp(e); + }, I.gte = I.greaterThanOrEqual, I.ge = I.greaterThanOrEqual, I.compare = function(e) { + if (l(e) || (e = m(e)), this.eq(e)) return 0; + var t = this.isNegative(), r = e.isNegative(); + return t && !r ? -1 : !t && r ? 1 : this.unsigned ? e.high >>> 0 > this.high >>> 0 || e.high === this.high && e.low >>> 0 > this.low >>> 0 ? -1 : 1 : this.sub(e).isNegative() ? -1 : 1; + }, I.comp = I.compare, I.negate = function() { + return !this.unsigned && this.eq(A) ? A : this.not().add(d); + }, I.neg = I.negate, I.add = function(e) { + l(e) || (e = m(e)); + var t = this.high >>> 16, r = 65535 & this.high, n = this.low >>> 16, i = 65535 & this.low, s = e.high >>> 16, o = 65535 & e.high, a = e.low >>> 16, c = 0, u = 0, h = 0, f = 0; + return h += (f += i + (65535 & e.low)) >>> 16, u += (h += n + a) >>> 16, c += (u += r + o) >>> 16, + c += t + s, p((h &= 65535) << 16 | (f &= 65535), (c &= 65535) << 16 | (u &= 65535), this.unsigned); + }, I.subtract = function(e) { + return l(e) || (e = m(e)), this.add(e.neg()); + }, I.sub = I.subtract, I.multiply = function(e) { + if (this.isZero()) return y; + if (l(e) || (e = m(e)), v) return p(v.mul(this.low, this.high, e.low, e.high), v.get_high(), this.unsigned); + if (e.isZero()) return y; + if (this.eq(A)) return e.isOdd() ? A : y; + if (e.eq(A)) return this.isOdd() ? A : y; + if (this.isNegative()) return e.isNegative() ? this.neg().mul(e.neg()) : this.neg().mul(e).neg(); + if (e.isNegative()) return this.mul(e.neg()).neg(); + if (this.lt(w) && e.lt(w)) return g(this.toNumber() * e.toNumber(), this.unsigned); + var t = this.high >>> 16, r = 65535 & this.high, n = this.low >>> 16, i = 65535 & this.low, s = e.high >>> 16, o = 65535 & e.high, a = e.low >>> 16, c = 65535 & e.low, u = 0, h = 0, f = 0, d = 0; + return f += (d += i * c) >>> 16, h += (f += n * c) >>> 16, f &= 65535, h += (f += i * a) >>> 16, + u += (h += r * c) >>> 16, h &= 65535, u += (h += n * a) >>> 16, h &= 65535, u += (h += i * o) >>> 16, + u += t * c + r * a + n * o + i * s, p((f &= 65535) << 16 | (d &= 65535), (u &= 65535) << 16 | (h &= 65535), this.unsigned); + }, I.mul = I.multiply, I.divide = function(e) { + if (l(e) || (e = m(e)), e.isZero()) throw Error("division by zero"); + if (v) return this.unsigned || -2147483648 !== this.high || -1 !== e.low || -1 !== e.high ? p((this.unsigned ? v.div_u : v.div_s)(this.low, this.high, e.low, e.high), v.get_high(), this.unsigned) : this; + if (this.isZero()) return this.unsigned ? u : y; + var t, r, n; + if (this.unsigned) { + if (e.unsigned || (e = e.toUnsigned()), e.gt(this)) return u; + if (e.gt(this.shru(1))) return b; + n = u; + } else { + if (this.eq(A)) return e.eq(d) || e.eq(S) ? A : e.eq(A) ? d : (t = this.shr(1).div(e).shl(1)).eq(y) ? e.isNegative() ? d : S : (r = this.sub(e.mul(t)), + n = t.add(r.div(e))); + if (e.eq(A)) return this.unsigned ? u : y; + if (this.isNegative()) return e.isNegative() ? this.neg().div(e.neg()) : this.neg().div(e).neg(); + if (e.isNegative()) return this.div(e.neg()).neg(); + n = y; + } + for (r = this; r.gte(e); ) { + t = Math.max(1, Math.floor(r.toNumber() / e.toNumber())); + for (var i = Math.ceil(Math.log(t) / Math.LN2), s = i <= 48 ? 1 : f(2, i - 48), o = g(t), a = o.mul(e); a.isNegative() || a.gt(r); ) a = (o = g(t -= s, this.unsigned)).mul(e); + o.isZero() && (o = d), n = n.add(o), r = r.sub(a); + } + return n; + }, I.div = I.divide, I.modulo = function(e) { + return l(e) || (e = m(e)), v ? p((this.unsigned ? v.rem_u : v.rem_s)(this.low, this.high, e.low, e.high), v.get_high(), this.unsigned) : this.sub(this.div(e).mul(e)); + }, I.mod = I.modulo, I.rem = I.modulo, I.not = function() { + return p(~this.low, ~this.high, this.unsigned); + }, I.and = function(e) { + return l(e) || (e = m(e)), p(this.low & e.low, this.high & e.high, this.unsigned); + }, I.or = function(e) { + return l(e) || (e = m(e)), p(this.low | e.low, this.high | e.high, this.unsigned); + }, I.xor = function(e) { + return l(e) || (e = m(e)), p(this.low ^ e.low, this.high ^ e.high, this.unsigned); + }, I.shiftLeft = function(e) { + return l(e) && (e = e.toInt()), 0 == (e &= 63) ? this : e < 32 ? p(this.low << e, this.high << e | this.low >>> 32 - e, this.unsigned) : p(0, this.low << e - 32, this.unsigned); + }, I.shl = I.shiftLeft, I.shiftRight = function(e) { + return l(e) && (e = e.toInt()), 0 == (e &= 63) ? this : e < 32 ? p(this.low >>> e | this.high << 32 - e, this.high >> e, this.unsigned) : p(this.high >> e - 32, 0 <= this.high ? 0 : -1, this.unsigned); + }, I.shr = I.shiftRight, I.shiftRightUnsigned = function(e) { + if (l(e) && (e = e.toInt()), 0 == (e &= 63)) return this; + var t = this.high; + return e < 32 ? p(this.low >>> e | t << 32 - e, t >>> e, this.unsigned) : p(32 === e ? t : t >>> e - 32, 0, this.unsigned); + }, I.shru = I.shiftRightUnsigned, I.shr_u = I.shiftRightUnsigned, I.toSigned = function() { + return this.unsigned ? p(this.low, this.high, !1) : this; + }, I.toUnsigned = function() { + return this.unsigned ? this : p(this.low, this.high, !0); + }, I.toBytes = function(e) { + return e ? this.toBytesLE() : this.toBytesBE(); + }, I.toBytesLE = function() { + var e = this.high, t = this.low; + return [ 255 & t, t >>> 8 & 255, t >>> 16 & 255, t >>> 24, 255 & e, e >>> 8 & 255, e >>> 16 & 255, e >>> 24 ]; + }, I.toBytesBE = function() { + var e = this.high, t = this.low; + return [ e >>> 24, e >>> 16 & 255, e >>> 8 & 255, 255 & e, t >>> 24, t >>> 16 & 255, t >>> 8 & 255, 255 & t ]; + }, n.fromBytes = function(e, t, r) { + return r ? n.fromBytesLE(e, t) : n.fromBytesBE(e, t); + }, n.fromBytesLE = function(e, t) { + return new n(e[0] | e[1] << 8 | e[2] << 16 | e[3] << 24, e[4] | e[5] << 8 | e[6] << 16 | e[7] << 24, t); + }, n.fromBytesBE = function(e, t) { + return new n(e[4] << 24 | e[5] << 16 | e[6] << 8 | e[7], e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3], t); + }; + } ]); +}), function(t, r) { + "use strict"; + "object" == typeof exports ? (t.slip = exports, r(exports)) : "function" == typeof define && define.amd ? define([ "exports" ], function(e) { + return t.slip = e, t.slip, r(e); + }) : (t.slip = {}, r(t.slip)); +}(this, function(e) { + "use strict"; + var a = e; + a.END = 192, a.ESC = 219, a.ESC_END = 220, a.ESC_ESC = 221, a.byteArray = function(e, t, r) { + return e instanceof ArrayBuffer ? new Uint8Array(e, t, r) : e; + }, a.expandByteArray = function(e) { + var t = new Uint8Array(2 * e.length); + return t.set(e), t; + }, a.sliceByteArray = function(e, t, r) { + var n = e.buffer.slice ? e.buffer.slice(t, r) : e.subarray(t, r); + return new Uint8Array(n); + }, a.encode = function(e, t) { + (t = t || {}).bufferPadding = t.bufferPadding || 4; + var r = (e = a.byteArray(e, t.offset, t.byteLength)).length + t.bufferPadding + 3 & -4, n = new Uint8Array(r), i = 1; + n[0] = a.END; + for (var s = 0; s < e.length; s++) { + i > n.length - 3 && (n = a.expandByteArray(n)); + var o = e[s]; + o === a.END ? (n[i++] = a.ESC, o = a.ESC_END) : o === a.ESC && (n[i++] = a.ESC, + o = a.ESC_ESC), n[i++] = o; + } + return n[i] = a.END, a.sliceByteArray(n, 0, i + 1); + }, a.Decoder = function(e) { + e = "function" != typeof e ? e || {} : { + onMessage: e + }, this.maxMessageSize = e.maxMessageSize || 10485760, this.bufferSize = e.bufferSize || 1024, + this.msgBuffer = new Uint8Array(this.bufferSize), this.msgBufferIdx = 0, this.onMessage = e.onMessage, + this.onError = e.onError, this.escape = !1; + }; + var t = a.Decoder.prototype; + return t.decode = function(e) { + var t; + e = a.byteArray(e); + for (var r = 0; r < e.length; r++) { + var n = e[r]; + if (this.escape) n === a.ESC_ESC ? n = a.ESC : n === a.ESC_END && (n = a.END); else { + if (n === a.ESC) { + this.escape = !0; + continue; + } + if (n === a.END) { + t = this.handleEnd(); + continue; + } + } + this.addByte(n) || this.handleMessageMaxError(); + } + return t; + }, t.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; + }, t.addByte = function(e) { + return this.msgBufferIdx > this.msgBuffer.length - 1 && (this.msgBuffer = a.expandByteArray(this.msgBuffer)), + this.msgBuffer[this.msgBufferIdx++] = e, this.escape = !1, this.msgBuffer.length < this.maxMessageSize; + }, t.handleEnd = function() { + if (0 !== this.msgBufferIdx) { + var e = a.sliceByteArray(this.msgBuffer, 0, this.msgBufferIdx); + return this.onMessage && this.onMessage(e), this.msgBufferIdx = 0, e; + } + }, a; +}), function(e) { + "use strict"; + function t() {} + var r = t.prototype, n = e.EventEmitter; + function s(e, t) { + for (var r = e.length; r--; ) if (e[r].listener === t) return r; + return -1; + } + function i(e) { + return function() { + return this[e].apply(this, arguments); + }; + } + r.getListeners = function(e) { + var t, r, n = this._getEvents(); + if (e instanceof RegExp) for (r in t = {}, n) n.hasOwnProperty(r) && e.test(r) && (t[r] = n[r]); else t = n[e] || (n[e] = []); + return t; + }, r.flattenListeners = function(e) { + var t, r = []; + for (t = 0; t < e.length; t += 1) r.push(e[t].listener); + return r; + }, r.getListenersAsObject = function(e) { + var t, r = this.getListeners(e); + return r instanceof Array && ((t = {})[e] = r), t || r; + }, r.addListener = function(e, t) { + if (!function e(t) { + return "function" == typeof t || t instanceof RegExp || !(!t || "object" != typeof t) && e(t.listener); + }(t)) throw new TypeError("listener must be a function"); + var r, n = this.getListenersAsObject(e), i = "object" == typeof t; + for (r in n) n.hasOwnProperty(r) && -1 === s(n[r], t) && n[r].push(i ? t : { + listener: t, + once: !1 + }); + return this; + }, r.on = i("addListener"), r.addOnceListener = function(e, t) { + return this.addListener(e, { + listener: t, + once: !0 + }); + }, r.once = i("addOnceListener"), r.defineEvent = function(e) { + return this.getListeners(e), this; + }, r.defineEvents = function(e) { + for (var t = 0; t < e.length; t += 1) this.defineEvent(e[t]); + return this; + }, r.removeListener = function(e, t) { + var r, n, i = this.getListenersAsObject(e); + for (n in i) i.hasOwnProperty(n) && -1 !== (r = s(i[n], t)) && i[n].splice(r, 1); + return this; + }, r.off = i("removeListener"), r.addListeners = function(e, t) { + return this.manipulateListeners(!1, e, t); + }, r.removeListeners = function(e, t) { + return this.manipulateListeners(!0, e, t); + }, r.manipulateListeners = function(e, t, r) { + var n, i, s = e ? this.removeListener : this.addListener, o = e ? this.removeListeners : this.addListeners; + if ("object" != typeof t || t instanceof RegExp) for (n = r.length; n--; ) s.call(this, t, r[n]); else for (n in t) t.hasOwnProperty(n) && (i = t[n]) && ("function" == typeof i ? s.call(this, n, i) : o.call(this, n, i)); + return this; + }, r.removeEvent = function(e) { + var t, r = typeof e, n = this._getEvents(); + if ("string" === r) delete n[e]; else if (e instanceof RegExp) for (t in n) n.hasOwnProperty(t) && e.test(t) && delete n[t]; else delete this._events; + return this; + }, r.removeAllListeners = i("removeEvent"), r.emitEvent = function(e, t) { + var r, n, i, s, o = this.getListenersAsObject(e); + for (s in o) if (o.hasOwnProperty(s)) for (r = o[s].slice(0), i = 0; i < r.length; i++) !0 === (n = r[i]).once && this.removeListener(e, n.listener), + n.listener.apply(this, t || []) === this._getOnceReturnValue() && this.removeListener(e, n.listener); + return this; + }, r.trigger = i("emitEvent"), r.emit = function(e) { + var t = Array.prototype.slice.call(arguments, 1); + return this.emitEvent(e, t); + }, r.setOnceReturnValue = function(e) { + return this._onceReturnValue = e, this; + }, r._getOnceReturnValue = function() { + return !this.hasOwnProperty("_onceReturnValue") || this._onceReturnValue; + }, r._getEvents = function() { + return this._events || (this._events = {}); + }, t.noConflict = function() { + return e.EventEmitter = n, t; + }, "function" == typeof define && define.amd ? define(function() { + return t; + }) : "object" == typeof module && module.exports ? module.exports = t : e.EventEmitter = t; +}(this || {}); + +osc = osc || require("./osc.js"); + +var slip = slip || require("slip"), EventEmitter = EventEmitter || require("events").EventEmitter; + +!function() { + "use strict"; + osc.firePacketEvents = function(e, t, r, n) { + t.address ? e.emit("message", t, r, n) : osc.fireBundleEvents(e, t, r, n); + }, osc.fireBundleEvents = function(e, t, r, n) { + e.emit("bundle", t, r, n); + for (var i = 0; i < t.packets.length; i++) { + var s = t.packets[i]; + osc.firePacketEvents(e, s, t.timeTag, n); + } + }, osc.fireClosedPortSendError = function(e, t) { + t = t || "Can't send packets on a closed osc.Port object. Please open (or reopen) this Port by calling open().", + e.emit("error", t); + }, osc.Port = function(e) { + this.options = e || {}, this.on("data", this.decodeOSC.bind(this)); + }; + var e = osc.Port.prototype = Object.create(EventEmitter.prototype); + e.constructor = osc.Port, e.send = function(e) { + var t = Array.prototype.slice.call(arguments), r = this.encodeOSC(e), n = osc.nativeBuffer(r); + t[0] = n, this.sendRaw.apply(this, t); + }, e.encodeOSC = function(e) { + var t; + e = e.buffer ? e.buffer : e; + try { + t = osc.writePacket(e, this.options); + } catch (e) { + this.emit("error", e); + } + return t; + }, e.decodeOSC = function(e, t) { + e = osc.byteArray(e), this.emit("raw", e, t); + try { + var r = osc.readPacket(e, this.options); + this.emit("osc", r, t), osc.firePacketEvents(this, r, void 0, t); + } catch (e) { + this.emit("error", e); + } + }, osc.SLIPPort = function(e) { + var t = this, r = this.options = e || {}; + r.useSLIP = void 0 === r.useSLIP || r.useSLIP, this.decoder = new slip.Decoder({ + onMessage: this.decodeOSC.bind(this), + onError: function(e) { + t.emit("error", e); + } + }); + var n = r.useSLIP ? this.decodeSLIPData : this.decodeOSC; + this.on("data", n.bind(this)); + }, (e = osc.SLIPPort.prototype = Object.create(osc.Port.prototype)).constructor = osc.SLIPPort, + e.encodeOSC = function(e) { + var t; + e = e.buffer ? e.buffer : e; + try { + var r = osc.writePacket(e, this.options); + t = slip.encode(r); + } catch (e) { + this.emit("error", e); + } + return t; + }, e.decodeSLIPData = function(e, t) { + this.decoder.decode(e, t); + }, osc.relay = function(e, t, r, n, i, s) { + r = r || "message", n = n || "send", i = i || function() {}, s = s ? [ null ].concat(s) : []; + var o = function(e) { + s[0] = e, e = i(e), t[n].apply(t, s); + }; + return e.on(r, o), { + eventName: r, + listener: o + }; + }, osc.relayPorts = function(e, t, r) { + var n = r.raw ? "raw" : "osc", i = r.raw ? "sendRaw" : "send"; + return osc.relay(e, t, n, i, r.transform); + }, osc.stopRelaying = function(e, t) { + e.removeListener(t.eventName, t.listener); + }, osc.Relay = function(e, t, r) { + (this.options = r || {}).raw = !1, this.port1 = e, this.port2 = t, this.listen(); + }, (e = osc.Relay.prototype = Object.create(EventEmitter.prototype)).constructor = osc.Relay, + e.open = function() { + this.port1.open(), this.port2.open(); + }, e.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); + var e = this.close.bind(this); + this.port1.on("close", e), this.port2.on("close", e); + }, e.close = function() { + osc.stopRelaying(this.port1, this.port1Spec), osc.stopRelaying(this.port2, this.port2Spec), + this.emit("close", this.port1, this.port2); + }, "undefined" != typeof module && module.exports && (module.exports = osc); +}(); + +osc = osc || require("../osc.js"); + +!function() { + "use strict"; + osc.WebSocket = "undefined" != typeof WebSocket ? WebSocket : require("ws"), osc.WebSocketPort = function(e) { + osc.Port.call(this, e), this.on("open", this.listen.bind(this)), this.socket = e.socket, + this.socket && (1 === this.socket.readyState ? (osc.WebSocketPort.setupSocketForBinary(this.socket), + this.emit("open", this.socket)) : this.open()); + }; + var e = osc.WebSocketPort.prototype = Object.create(osc.Port.prototype); + e.constructor = osc.WebSocketPort, e.open = function() { + (!this.socket || 1 < this.socket.readyState) && (this.socket = new osc.WebSocket(this.options.url)), + osc.WebSocketPort.setupSocketForBinary(this.socket); + var e = this; + this.socket.onopen = function() { + e.emit("open", e.socket); + }; + }, e.listen = function() { + var t = this; + this.socket.onmessage = function(e) { + t.emit("data", e.data, e); + }, this.socket.onerror = function(e) { + t.emit("error", e); + }, this.socket.onclose = function(e) { + t.emit("close", e); + }, t.emit("ready"); + }, e.sendRaw = function(e) { + this.socket && 1 === this.socket.readyState ? this.socket.send(e) : osc.fireClosedPortSendError(this); + }, e.close = function(e, t) { + this.socket.close(e, t); + }, osc.WebSocketPort.setupSocketForBinary = function(e) { + e.binaryType = osc.isNode ? "nodebuffer" : "arraybuffer"; + }; +}(); + +osc = osc || {}; + +!function() { + "use strict"; + osc.listenToTransport = function(t, e, r) { + e.onReceive.addListener(function(e) { + e[r] === t[r] && t.emit("data", e.data, e); + }), e.onReceiveError.addListener(function(e) { + t.emit("error", e); + }), t.emit("ready"); + }, osc.emitNetworkError = function(e, t) { + e.emit("error", "There was an error while opening the UDP socket connection. Result code: " + t); + }, osc.SerialPort = function(e) { + this.on("open", this.listen.bind(this)), osc.SLIPPort.call(this, e), this.connectionId = this.options.connectionId, + this.connectionId && this.emit("open", this.connectionId); + }; + var e = osc.SerialPort.prototype = Object.create(osc.SLIPPort.prototype); + e.constructor = osc.SerialPort, e.open = function() { + var t = this, e = { + bitrate: t.options.bitrate + }; + chrome.serial.connect(this.options.devicePath, e, function(e) { + t.connectionId = e.connectionId, t.emit("open", e); + }); + }, e.listen = function() { + osc.listenToTransport(this, chrome.serial, "connectionId"); + }, e.sendRaw = function(e) { + if (this.connectionId) { + var r = this; + chrome.serial.send(this.connectionId, e.buffer, function(e, t) { + t && r.emit("error", t + ". Total bytes sent: " + e); + }); + } else osc.fireClosedPortSendError(this); + }, e.close = function() { + if (this.connectionId) { + var t = this; + chrome.serial.disconnect(this.connectionId, function(e) { + e && t.emit("close"); + }); + } + }, osc.UDPPort = function(e) { + osc.Port.call(this, e); + var t = this.options; + t.localAddress = t.localAddress || "127.0.0.1", t.localPort = void 0 !== t.localPort ? t.localPort : 57121, + this.on("open", this.listen.bind(this)), this.socketId = t.socketId, this.socketId && this.emit("open", 0); + }, (e = osc.UDPPort.prototype = Object.create(osc.Port.prototype)).constructor = osc.UDPPort, + e.open = function() { + if (!this.socketId) { + var e = this.options, t = { + persistent: e.persistent, + name: e.name, + bufferSize: e.bufferSize + }, r = this; + chrome.sockets.udp.create(t, function(e) { + r.socketId = e.socketId, r.bindSocket(); + }); + } + }, e.bindSocket = function() { + var t = this, e = this.options; + void 0 !== e.broadcast && chrome.sockets.udp.setBroadcast(this.socketId, e.broadcast, function(e) { + e < 0 && t.emit("error", new Error("An error occurred while setting the socket's broadcast flag. Result code: " + e)); + }), void 0 !== e.multicastTTL && chrome.sockets.udp.setMulticastTimeToLive(this.socketId, e.multicastTTL, function(e) { + e < 0 && t.emit("error", new Error("An error occurred while setting the socket's multicast time to live flag. Result code: " + e)); + }), chrome.sockets.udp.bind(this.socketId, e.localAddress, e.localPort, function(e) { + 0 < e ? osc.emitNetworkError(t, e) : t.emit("open", e); + }); + }, e.listen = function() { + var e = this.options; + osc.listenToTransport(this, chrome.sockets.udp, "socketId"), e.multicastMembership && ("string" == typeof e.multicastMembership && (e.multicastMembership = [ e.multicastMembership ]), + e.multicastMembership.forEach(function(t) { + chrome.sockets.udp.joinGroup(this.socketId, t, function(e) { + e < 0 && this.emit("error", new Error("There was an error while trying to join the multicast group " + t + ". Result code: " + e)); + }); + })); + }, e.sendRaw = function(e, t, r) { + if (this.socketId) { + var n = this.options, i = this; + t = t || n.remoteAddress, r = void 0 !== r ? r : n.remotePort, chrome.sockets.udp.send(this.socketId, e.buffer, t, r, function(e) { + e || i.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?"), + 0 < e.resultCode && osc.emitNetworkError(i, e.resultCode); + }); + } else osc.fireClosedPortSendError(this); + }, e.close = function() { + if (this.socketId) { + var e = this; + chrome.sockets.udp.close(this.socketId, function() { + e.emit("close"); + }); + } + }; +}(); \ No newline at end of file diff --git a/dist/osc-module.js b/dist/osc-module.js index b229492..4e730ec 100644 --- a/dist/osc-module.js +++ b/dist/osc-module.js @@ -1,4 +1,4 @@ -/*! osc.js 2.2.0, Copyright 2017 Colin Clark | github.com/colinbdclark/osc.js */ +/*! osc.js 2.2.1, Copyright 2018 Colin Clark | github.com/colinbdclark/osc.js */ (function (root, factory) { if (typeof exports === "object") { @@ -17,14 +17,15 @@ factory(root.osc, slip, EventEmitter); } }(this, function (exports, slip, EventEmitter, Long) { -;/* +; +/* * osc.js: An Open Sound Control library for JavaScript that works in both the browser and Node.js * * Copyright 2014-2016, Colin Clark * Licensed under the MIT and GPL 3 licenses. */ -/* global require, module, process, Buffer, dcodeIO */ +/* global require, module, process, Buffer, Long */ var osc = osc || {}; @@ -58,19 +59,18 @@ var osc = osc || {}; return obj && Object.prototype.toString.call(obj) === "[object Array]"; }; - // Unsupported, non-API function + // Unsupported, non-API function. osc.isTypedArrayView = function (obj) { return obj.buffer && obj.buffer instanceof ArrayBuffer; }; - // Unsupported, non-API function + // Unsupported, non-API function. osc.isBuffer = function (obj) { return osc.isBufferEnv && obj instanceof Buffer; }; - // Private instance of the optional Long dependency. - var Long = typeof dcodeIO !== "undefined" ? dcodeIO.Long : - typeof Long !== "undefined" ? Long : + // Unsupported, non-API member. + osc.Long = typeof Long !== "undefined" ? Long : osc.isNode ? require("long") : undefined; /** @@ -287,8 +287,8 @@ var osc = osc || {}; var high = osc.readPrimitive(dv, "getInt32", 4, offsetState), low = osc.readPrimitive(dv, "getInt32", 4, offsetState); - if (Long) { - return new Long(low, high); + if (osc.Long) { + return new osc.Long(low, high); } else { return { high: high, @@ -625,7 +625,7 @@ var osc = osc || {}; * * @param {DataView} dv a DataView instance to read from * @param {Object} offsetState the offsetState object that stores the current offset into dv - * @param {Oobject} [options] read options + * @param {Object} [options] read options * @return {Array} an array of the OSC arguments that were read */ osc.readArguments = function (dv, options, offsetState) { @@ -1107,7 +1107,8 @@ var osc = osc || {}; module.exports = osc; } }()); -;/* +; +/* * osc.js: An Open Sound Control library for JavaScript that works in both the browser and Node.js * * Cross-platform base transport library for osc.js. @@ -1328,7 +1329,8 @@ var osc = osc || require("./osc.js"), module.exports = osc; } }()); -;/* +; +/* * osc.js: An Open Sound Control library for JavaScript that works in both the browser and Node.js * * Cross-Platform Web Socket client transport for osc.js. @@ -1414,5 +1416,6 @@ var osc = osc || require("../osc.js"); }()); ; + return osc; })); diff --git a/dist/osc-module.min.js b/dist/osc-module.min.js index a9a43e0..1e3fe45 100644 --- a/dist/osc-module.min.js +++ b/dist/osc-module.min.js @@ -1,3 +1,488 @@ -/*! osc.js 2.2.0, Copyright 2017 Colin Clark | github.com/colinbdclark/osc.js */ +/*! osc.js 2.2.1, Copyright 2018 Colin Clark | github.com/colinbdclark/osc.js */ -!function(a,b){"object"==typeof exports?(a.osc=exports,b(exports,require("slip"),require("EventEmitter"),require("long"))):"function"==typeof define&&define.amd?define(["exports","slip","EventEmitter","long"],function(c,d,e,f){return a.osc=c,a.osc,b(c,d,e,f)}):(a.osc={},b(a.osc,slip,EventEmitter))}(this,function(a,b,c,d){var e=e||{};!function(){"use strict";e.SECS_70YRS=2208988800,e.TWO_32=4294967296,e.defaults={metadata:!1,unpackSingleArgs:!0},e.isCommonJS=!("undefined"==typeof module||!module.exports),e.isNode=e.isCommonJS&&"undefined"==typeof window,e.isElectron=!("undefined"==typeof process||!process.versions||!process.versions.electron),e.isBufferEnv=e.isNode||e.isElectron,e.isArray=function(a){return a&&"[object Array]"===Object.prototype.toString.call(a)},e.isTypedArrayView=function(a){return a.buffer&&a.buffer instanceof ArrayBuffer},e.isBuffer=function(a){return e.isBufferEnv&&a instanceof Buffer};var a="undefined"!=typeof dcodeIO?dcodeIO.Long:"undefined"!=typeof a?a:e.isNode?require("long"):void 0;e.dataView=function(a,b,c){return a.buffer?new DataView(a.buffer,b,c):a instanceof ArrayBuffer?new DataView(a,b,c):new DataView(new Uint8Array(a),b,c)},e.byteArray=function(a){if(a instanceof Uint8Array)return a;var b=a.buffer?a.buffer:a;if(!(b instanceof ArrayBuffer||"undefined"!=typeof b.length&&"string"!=typeof b))throw new Error("Can't wrap a non-array-like object as Uint8Array. Object was: "+JSON.stringify(a,null,2));return new Uint8Array(b)},e.nativeBuffer=function(a){return e.isBufferEnv?e.isBuffer(a)?a:new Buffer(a.buffer?a:new Uint8Array(a)):e.isTypedArrayView(a)?a:new Uint8Array(a)},e.copyByteArray=function(a,b,c){if(e.isTypedArrayView(a)&&e.isTypedArrayView(b))b.set(a,c);else for(var d=void 0===c?0:c,f=Math.min(b.length-c,a.length),g=0,h=d;g1){var j=Math.floor(i),k=i-j;g+=j,i=k}var l=d+g+e.SECS_70YRS,m=Math.round(e.TWO_32*i);return{raw:[l,m]}},e.ntpToJSTime=function(a,b){var c=a-e.SECS_70YRS,d=b/e.TWO_32,f=1e3*(c+d);return f},e.jsToNTPTime=function(a){var b=a/1e3,c=Math.floor(b),d=b-c,f=c+e.SECS_70YRS,g=Math.round(e.TWO_32*d);return[f,g]},e.readArguments=function(a,b,c){var d=e.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 f=d.substring(1).split(""),g=[];return e.readArgumentsIntoArray(g,f,d,a,b,c),g},e.readArgument=function(a,b,c,d,f){var g=e.argumentTypes[a];if(!g)throw new Error("'"+a+"' is not a valid OSC type tag. Type tag string was: "+b);var h=g.reader,i=e[h](c,f);return d.metadata&&(i={type:a,value:i}),i},e.readArgumentsIntoArray=function(a,b,c,d,f,g){for(var h=0;h1)&&(this.socket=new e.WebSocket(this.options.url)),e.WebSocketPort.setupSocketForBinary(this.socket);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,b)},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){return this.socket&&1===this.socket.readyState?void this.socket.send(a):void e.fireClosedPortSendError(this)},a.close=function(a,b){this.socket.close(a,b)},e.WebSocketPort.setupSocketForBinary=function(a){a.binaryType=e.isNode?"nodebuffer":"arraybuffer"}}(),e}); \ No newline at end of file + +!function(i, a) { + "object" == typeof exports ? (i.osc = exports, a(exports, require("slip"), require("EventEmitter"), require("long"))) : "function" == typeof define && define.amd ? define([ "exports", "slip", "EventEmitter", "long" ], function(e, t, r, n) { + return i.osc = e, i.osc, a(e, t, r, n); + }) : (i.osc = {}, a(i.osc, slip, EventEmitter)); +}(this, function(e, i, t, r) { + var l = l || {}; + !function() { + "use strict"; + l.SECS_70YRS = 2208988800, l.TWO_32 = 4294967296, l.defaults = { + metadata: !1, + unpackSingleArgs: !0 + }, l.isCommonJS = !("undefined" == typeof module || !module.exports), l.isNode = l.isCommonJS && "undefined" == typeof window, + l.isElectron = !("undefined" == typeof process || !process.versions || !process.versions.electron), + l.isBufferEnv = l.isNode || l.isElectron, l.isArray = function(e) { + return e && "[object Array]" === Object.prototype.toString.call(e); + }, l.isTypedArrayView = function(e) { + return e.buffer && e.buffer instanceof ArrayBuffer; + }, l.isBuffer = function(e) { + return l.isBufferEnv && e instanceof Buffer; + }, l.Long = void 0 !== r ? r : l.isNode ? require("long") : void 0, l.dataView = function(e, t, r) { + return e.buffer ? new DataView(e.buffer, t, r) : e instanceof ArrayBuffer ? new DataView(e, t, r) : new DataView(new Uint8Array(e), t, r); + }, l.byteArray = function(e) { + if (e instanceof Uint8Array) return e; + var t = e.buffer ? e.buffer : e; + if (!(t instanceof ArrayBuffer || void 0 !== t.length && "string" != typeof t)) throw new Error("Can't wrap a non-array-like object as Uint8Array. Object was: " + JSON.stringify(e, null, 2)); + return new Uint8Array(t); + }, l.nativeBuffer = function(e) { + return l.isBufferEnv ? l.isBuffer(e) ? e : new Buffer(e.buffer ? e : new Uint8Array(e)) : l.isTypedArrayView(e) ? e : new Uint8Array(e); + }, l.copyByteArray = function(e, t, r) { + if (l.isTypedArrayView(e) && l.isTypedArrayView(t)) t.set(e, r); else for (var n = void 0 === r ? 0 : r, i = Math.min(t.length - r, e.length), a = 0, o = n; a < i; a++, + o++) t[o] = e[a]; + return t; + }, l.readString = function(e, t) { + for (var r = [], n = t.idx; n < e.byteLength; n++) { + var i = e.getUint8(n); + if (0 === i) { + n++; + break; + } + r.push(i); + } + if (n = n + 3 & -4, t.idx = n, ("undefined" != typeof global ? global : window).hasOwnProperty("Buffer")) return Buffer.from ? Buffer.from(r).toString("utf-8") : new Buffer(r).toString("utf-8"); + if (("undefined" != typeof global ? global : window).hasOwnProperty("TextDecoder")) return new TextDecoder("utf-8").decode(new Int8Array(r)); + for (var a = "", o = 0; o < r.length; o += 1e4) a += String.fromCharCode.apply(null, r.slice(o, o + 1e4)); + return a; + }, l.writeString = function(e) { + for (var t = e + "\0", r = t.length, n = new Uint8Array(r + 3 & -4), i = 0; i < t.length; i++) { + var a = t.charCodeAt(i); + n[i] = a; + } + return n; + }, l.readPrimitive = function(e, t, r, n) { + var i = e[t](n.idx, !1); + return n.idx += r, i; + }, l.writePrimitive = function(e, t, r, n, i) { + var a; + return i = void 0 === i ? 0 : i, t ? a = new Uint8Array(t.buffer) : (a = new Uint8Array(n), + t = new DataView(a.buffer)), t[r](i, e, !1), a; + }, l.readInt32 = function(e, t) { + return l.readPrimitive(e, "getInt32", 4, t); + }, l.writeInt32 = function(e, t, r) { + return l.writePrimitive(e, t, "setInt32", 4, r); + }, l.readInt64 = function(e, t) { + var r = l.readPrimitive(e, "getInt32", 4, t), n = l.readPrimitive(e, "getInt32", 4, t); + return l.Long ? new l.Long(n, r) : { + high: r, + low: n, + unsigned: !1 + }; + }, l.writeInt64 = function(e, t, r) { + var n = new Uint8Array(8); + return n.set(l.writePrimitive(e.high, t, "setInt32", 4, r), 0), n.set(l.writePrimitive(e.low, t, "setInt32", 4, r + 4), 4), + n; + }, l.readFloat32 = function(e, t) { + return l.readPrimitive(e, "getFloat32", 4, t); + }, l.writeFloat32 = function(e, t, r) { + return l.writePrimitive(e, t, "setFloat32", 4, r); + }, l.readFloat64 = function(e, t) { + return l.readPrimitive(e, "getFloat64", 8, t); + }, l.writeFloat64 = function(e, t, r) { + return l.writePrimitive(e, t, "setFloat64", 8, r); + }, l.readChar32 = function(e, t) { + var r = l.readPrimitive(e, "getUint32", 4, t); + return String.fromCharCode(r); + }, l.writeChar32 = function(e, t, r) { + var n = e.charCodeAt(0); + if (!(void 0 === n || n < -1)) return l.writePrimitive(n, t, "setUint32", 4, r); + }, l.readBlob = function(e, t) { + var r = l.readInt32(e, t), n = r + 3 & -4, i = new Uint8Array(e.buffer, t.idx, r); + return t.idx += n, i; + }, l.writeBlob = function(e) { + var t = (e = l.byteArray(e)).byteLength, r = new Uint8Array((t + 3 & -4) + 4), n = new DataView(r.buffer); + return l.writeInt32(t, n), r.set(e, 4), r; + }, l.readMIDIBytes = function(e, t) { + var r = new Uint8Array(e.buffer, t.idx, 4); + return t.idx += 4, r; + }, l.writeMIDIBytes = function(e) { + e = l.byteArray(e); + var t = new Uint8Array(4); + return t.set(e), t; + }, l.readColor = function(e, t) { + var r = new Uint8Array(e.buffer, t.idx, 4), n = r[3] / 255; + return t.idx += 4, { + r: r[0], + g: r[1], + b: r[2], + a: n + }; + }, l.writeColor = function(e) { + var t = Math.round(255 * e.a); + return new Uint8Array([ e.r, e.g, e.b, t ]); + }, l.readTrue = function() { + return !0; + }, l.readFalse = function() { + return !1; + }, l.readNull = function() { + return null; + }, l.readImpulse = function() { + return 1; + }, l.readTimeTag = function(e, t) { + var r = l.readPrimitive(e, "getUint32", 4, t), n = l.readPrimitive(e, "getUint32", 4, t); + return { + raw: [ r, n ], + native: 0 === r && 1 === n ? Date.now() : l.ntpToJSTime(r, n) + }; + }, l.writeTimeTag = function(e) { + var t = e.raw ? e.raw : l.jsToNTPTime(e.native), r = new Uint8Array(8), n = new DataView(r.buffer); + return l.writeInt32(t[0], n, 0), l.writeInt32(t[1], n, 4), r; + }, l.timeTag = function(e, t) { + e = e || 0; + var r = (t = t || Date.now()) / 1e3, n = Math.floor(r), i = r - n, a = Math.floor(e), o = i + (e - a); + if (1 < o) { + var s = Math.floor(o); + a += s, o = o - s; + } + return { + raw: [ n + a + l.SECS_70YRS, Math.round(l.TWO_32 * o) ] + }; + }, l.ntpToJSTime = function(e, t) { + return 1e3 * (e - l.SECS_70YRS + t / l.TWO_32); + }, l.jsToNTPTime = function(e) { + var t = e / 1e3, r = Math.floor(t), n = t - r; + return [ r + l.SECS_70YRS, Math.round(l.TWO_32 * n) ]; + }, l.readArguments = function(e, t, r) { + var n = l.readString(e, r); + if (0 !== n.indexOf(",")) throw new Error("A malformed type tag string was found while reading the arguments of an OSC message. String was: " + n, " at offset: " + r.idx); + var i = n.substring(1).split(""), a = []; + return l.readArgumentsIntoArray(a, i, n, e, t, r), a; + }, l.readArgument = function(e, t, r, n, i) { + var a = l.argumentTypes[e]; + if (!a) throw new Error("'" + e + "' is not a valid OSC type tag. Type tag string was: " + t); + var o = a.reader, s = l[o](r, i); + return n.metadata && (s = { + type: e, + value: s + }), s; + }, l.readArgumentsIntoArray = function(e, t, r, n, i, a) { + for (var o = 0; o < t.length; ) { + var s, u = t[o]; + if ("[" === u) { + var c = t.slice(o + 1), d = c.indexOf("]"); + if (d < 0) throw new Error("Invalid argument type tag: an open array type tag ('[') was found without a matching close array tag ('[]'). Type tag was: " + r); + var f = c.slice(0, d); + s = l.readArgumentsIntoArray([], f, r, n, i, a), o += d + 2; + } else s = l.readArgument(u, r, n, i, a), o++; + e.push(s); + } + return e; + }, l.writeArguments = function(e, t) { + var r = l.collectArguments(e, t); + return l.joinParts(r); + }, l.joinParts = function(e) { + for (var t = new Uint8Array(e.byteLength), r = e.parts, n = 0, i = 0; i < r.length; i++) { + var a = r[i]; + l.copyByteArray(a, t, n), n += a.length; + } + return t; + }, l.addDataPart = function(e, t) { + t.parts.push(e), t.byteLength += e.length; + }, l.writeArrayArguments = function(e, t) { + for (var r = "[", n = 0; n < e.length; n++) { + var i = e[n]; + r += l.writeArgument(i, t); + } + return r += "]"; + }, l.writeArgument = function(e, t) { + if (l.isArray(e)) return l.writeArrayArguments(e, t); + var r = e.type, n = l.argumentTypes[r].writer; + if (n) { + var i = l[n](e.value); + l.addDataPart(i, t); + } + return e.type; + }, l.collectArguments = function(e, t, r) { + l.isArray(e) || (e = void 0 === e ? [] : [ e ]), r = r || { + byteLength: 0, + parts: [] + }, t.metadata || (e = l.annotateArguments(e)); + for (var n = ",", i = r.parts.length, a = 0; a < e.length; a++) { + var o = e[a]; + n += l.writeArgument(o, r); + } + var s = l.writeString(n); + return r.byteLength += s.byteLength, r.parts.splice(i, 0, s), r; + }, l.readMessage = function(e, t, r) { + t = t || l.defaults; + var n = l.dataView(e, e.byteOffset, e.byteLength); + r = r || { + idx: 0 + }; + var i = l.readString(n, r); + return l.readMessageContents(i, n, t, r); + }, l.readMessageContents = function(e, t, r, n) { + if (0 !== e.indexOf("/")) throw new Error("A malformed OSC address was found while reading an OSC message. String was: " + e); + var i = l.readArguments(t, r, n); + return { + address: e, + args: 1 === i.length && r.unpackSingleArgs ? i[0] : i + }; + }, l.collectMessageParts = function(e, t, r) { + return r = r || { + byteLength: 0, + parts: [] + }, l.addDataPart(l.writeString(e.address), r), l.collectArguments(e.args, t, r); + }, l.writeMessage = function(e, t) { + if (t = t || l.defaults, !l.isValidMessage(e)) throw new Error("An OSC message must contain a valid address. Message was: " + JSON.stringify(e, null, 2)); + var r = l.collectMessageParts(e, t); + return l.joinParts(r); + }, l.isValidMessage = function(e) { + return e.address && 0 === e.address.indexOf("/"); + }, l.readBundle = function(e, t, r) { + return l.readPacket(e, t, r); + }, l.collectBundlePackets = function(e, t, r) { + r = r || { + byteLength: 0, + parts: [] + }, l.addDataPart(l.writeString("#bundle"), r), l.addDataPart(l.writeTimeTag(e.timeTag), r); + for (var n = 0; n < e.packets.length; n++) { + var i = e.packets[n], a = (i.address ? l.collectMessageParts : l.collectBundlePackets)(i, t); + r.byteLength += a.byteLength, l.addDataPart(l.writeInt32(a.byteLength), r), r.parts = r.parts.concat(a.parts); + } + return r; + }, l.writeBundle = function(e, t) { + if (!l.isValidBundle(e)) throw new Error("An OSC bundle must contain 'timeTag' and 'packets' properties. Bundle was: " + JSON.stringify(e, null, 2)); + t = t || l.defaults; + var r = l.collectBundlePackets(e, t); + return l.joinParts(r); + }, l.isValidBundle = function(e) { + return void 0 !== e.timeTag && void 0 !== e.packets; + }, l.readBundleContents = function(e, t, r, n) { + for (var i = l.readTimeTag(e, r), a = []; r.idx < n; ) { + var o = l.readInt32(e, r), s = r.idx + o, u = l.readPacket(e, t, r, s); + a.push(u); + } + return { + timeTag: i, + packets: a + }; + }, l.readPacket = function(e, t, r, n) { + var i = l.dataView(e, e.byteOffset, e.byteLength); + n = void 0 === n ? i.byteLength : n, r = r || { + idx: 0 + }; + var a = l.readString(i, r), o = a[0]; + if ("#" === o) return l.readBundleContents(i, t, r, n); + if ("/" === o) return l.readMessageContents(a, i, t, r); + throw new Error("The header of an OSC packet didn't contain an OSC address or a #bundle string. Header was: " + a); + }, l.writePacket = function(e, t) { + if (l.isValidMessage(e)) return l.writeMessage(e, t); + if (l.isValidBundle(e)) return l.writeBundle(e, t); + throw new Error("The specified packet was not recognized as a valid OSC message or bundle. Packet was: " + JSON.stringify(e, null, 2)); + }, l.argumentTypes = { + i: { + reader: "readInt32", + writer: "writeInt32" + }, + h: { + reader: "readInt64", + writer: "writeInt64" + }, + 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" + } + }, l.inferTypeForArgument = function(e) { + switch (typeof e) { + case "boolean": + return e ? "T" : "F"; + + case "string": + return "s"; + + case "number": + return "f"; + + case "undefined": + return "N"; + + case "object": + if (null === e) return "N"; + if (e instanceof Uint8Array || e instanceof ArrayBuffer) return "b"; + if ("number" == typeof e.high && "number" == typeof e.low) return "h"; + } + throw new Error("Can't infer OSC argument type for value: " + JSON.stringify(e, null, 2)); + }, l.annotateArguments = function(e) { + for (var t = [], r = 0; r < e.length; r++) { + var n, i = e[r]; + if ("object" == typeof i && i.type && void 0 !== i.value) n = i; else if (l.isArray(i)) n = l.annotateArguments(i); else { + n = { + type: l.inferTypeForArgument(i), + value: i + }; + } + t.push(n); + } + return t; + }, l.isCommonJS && (module.exports = l); + }(); + l = l || require("./osc.js"), i = i || require("slip"), t = t || require("events").EventEmitter; + !function() { + "use strict"; + l.firePacketEvents = function(e, t, r, n) { + t.address ? e.emit("message", t, r, n) : l.fireBundleEvents(e, t, r, n); + }, l.fireBundleEvents = function(e, t, r, n) { + e.emit("bundle", t, r, n); + for (var i = 0; i < t.packets.length; i++) { + var a = t.packets[i]; + l.firePacketEvents(e, a, t.timeTag, n); + } + }, l.fireClosedPortSendError = function(e, t) { + t = t || "Can't send packets on a closed osc.Port object. Please open (or reopen) this Port by calling open().", + e.emit("error", t); + }, l.Port = function(e) { + this.options = e || {}, this.on("data", this.decodeOSC.bind(this)); + }; + var e = l.Port.prototype = Object.create(t.prototype); + e.constructor = l.Port, e.send = function(e) { + var t = Array.prototype.slice.call(arguments), r = this.encodeOSC(e), n = l.nativeBuffer(r); + t[0] = n, this.sendRaw.apply(this, t); + }, e.encodeOSC = function(e) { + var t; + e = e.buffer ? e.buffer : e; + try { + t = l.writePacket(e, this.options); + } catch (e) { + this.emit("error", e); + } + return t; + }, e.decodeOSC = function(e, t) { + e = l.byteArray(e), this.emit("raw", e, t); + try { + var r = l.readPacket(e, this.options); + this.emit("osc", r, t), l.firePacketEvents(this, r, void 0, t); + } catch (e) { + this.emit("error", e); + } + }, l.SLIPPort = function(e) { + var t = this, r = this.options = e || {}; + r.useSLIP = void 0 === r.useSLIP || r.useSLIP, this.decoder = new i.Decoder({ + onMessage: this.decodeOSC.bind(this), + onError: function(e) { + t.emit("error", e); + } + }); + var n = r.useSLIP ? this.decodeSLIPData : this.decodeOSC; + this.on("data", n.bind(this)); + }, (e = l.SLIPPort.prototype = Object.create(l.Port.prototype)).constructor = l.SLIPPort, + e.encodeOSC = function(e) { + var t; + e = e.buffer ? e.buffer : e; + try { + var r = l.writePacket(e, this.options); + t = i.encode(r); + } catch (e) { + this.emit("error", e); + } + return t; + }, e.decodeSLIPData = function(e, t) { + this.decoder.decode(e, t); + }, l.relay = function(e, t, r, n, i, a) { + r = r || "message", n = n || "send", i = i || function() {}, a = a ? [ null ].concat(a) : []; + var o = function(e) { + a[0] = e, e = i(e), t[n].apply(t, a); + }; + return e.on(r, o), { + eventName: r, + listener: o + }; + }, l.relayPorts = function(e, t, r) { + var n = r.raw ? "raw" : "osc", i = r.raw ? "sendRaw" : "send"; + return l.relay(e, t, n, i, r.transform); + }, l.stopRelaying = function(e, t) { + e.removeListener(t.eventName, t.listener); + }, l.Relay = function(e, t, r) { + (this.options = r || {}).raw = !1, this.port1 = e, this.port2 = t, this.listen(); + }, (e = l.Relay.prototype = Object.create(t.prototype)).constructor = l.Relay, e.open = function() { + this.port1.open(), this.port2.open(); + }, e.listen = function() { + this.port1Spec && this.port2Spec && this.close(), this.port1Spec = l.relayPorts(this.port1, this.port2, this.options), + this.port2Spec = l.relayPorts(this.port2, this.port1, this.options); + var e = this.close.bind(this); + this.port1.on("close", e), this.port2.on("close", e); + }, e.close = function() { + l.stopRelaying(this.port1, this.port1Spec), l.stopRelaying(this.port2, this.port2Spec), + this.emit("close", this.port1, this.port2); + }, "undefined" != typeof module && module.exports && (module.exports = l); + }(); + l = l || require("../osc.js"); + return function() { + "use strict"; + l.WebSocket = "undefined" != typeof WebSocket ? WebSocket : require("ws"), l.WebSocketPort = function(e) { + l.Port.call(this, e), this.on("open", this.listen.bind(this)), this.socket = e.socket, + this.socket && (1 === this.socket.readyState ? (l.WebSocketPort.setupSocketForBinary(this.socket), + this.emit("open", this.socket)) : this.open()); + }; + var e = l.WebSocketPort.prototype = Object.create(l.Port.prototype); + e.constructor = l.WebSocketPort, e.open = function() { + (!this.socket || 1 < this.socket.readyState) && (this.socket = new l.WebSocket(this.options.url)), + l.WebSocketPort.setupSocketForBinary(this.socket); + var e = this; + this.socket.onopen = function() { + e.emit("open", e.socket); + }; + }, e.listen = function() { + var t = this; + this.socket.onmessage = function(e) { + t.emit("data", e.data, e); + }, this.socket.onerror = function(e) { + t.emit("error", e); + }, this.socket.onclose = function(e) { + t.emit("close", e); + }, t.emit("ready"); + }, e.sendRaw = function(e) { + this.socket && 1 === this.socket.readyState ? this.socket.send(e) : l.fireClosedPortSendError(this); + }, e.close = function(e, t) { + this.socket.close(e, t); + }, l.WebSocketPort.setupSocketForBinary = function(e) { + e.binaryType = l.isNode ? "nodebuffer" : "arraybuffer"; + }; + }(), l; +}); \ No newline at end of file diff --git a/dist/osc.js b/dist/osc.js index d50bd1f..dc874e6 100644 --- a/dist/osc.js +++ b/dist/osc.js @@ -1,4 +1,4 @@ -/*! osc.js 2.2.0, Copyright 2017 Colin Clark | github.com/colinbdclark/osc.js */ +/*! osc.js 2.2.1, Copyright 2018 Colin Clark | github.com/colinbdclark/osc.js */ /* * osc.js: An Open Sound Control library for JavaScript that works in both the browser and Node.js @@ -7,7 +7,7 @@ * Licensed under the MIT and GPL 3 licenses. */ -/* global require, module, process, Buffer, dcodeIO */ +/* global require, module, process, Buffer, Long */ var osc = osc || {}; @@ -41,19 +41,18 @@ var osc = osc || {}; return obj && Object.prototype.toString.call(obj) === "[object Array]"; }; - // Unsupported, non-API function + // Unsupported, non-API function. osc.isTypedArrayView = function (obj) { return obj.buffer && obj.buffer instanceof ArrayBuffer; }; - // Unsupported, non-API function + // Unsupported, non-API function. osc.isBuffer = function (obj) { return osc.isBufferEnv && obj instanceof Buffer; }; - // Private instance of the optional Long dependency. - var Long = typeof dcodeIO !== "undefined" ? dcodeIO.Long : - typeof Long !== "undefined" ? Long : + // Unsupported, non-API member. + osc.Long = typeof Long !== "undefined" ? Long : osc.isNode ? require("long") : undefined; /** @@ -270,8 +269,8 @@ var osc = osc || {}; var high = osc.readPrimitive(dv, "getInt32", 4, offsetState), low = osc.readPrimitive(dv, "getInt32", 4, offsetState); - if (Long) { - return new Long(low, high); + if (osc.Long) { + return new osc.Long(low, high); } else { return { high: high, @@ -608,7 +607,7 @@ var osc = osc || {}; * * @param {DataView} dv a DataView instance to read from * @param {Object} offsetState the offsetState object that stores the current offset into dv - * @param {Oobject} [options] read options + * @param {Object} [options] read options * @return {Array} an array of the OSC arguments that were read */ osc.readArguments = function (dv, options, offsetState) { diff --git a/dist/osc.min.js b/dist/osc.min.js index 44457a5..d35c077 100644 --- a/dist/osc.min.js +++ b/dist/osc.min.js @@ -1,3 +1,363 @@ -/*! osc.js 2.2.0, Copyright 2017 Colin Clark | github.com/colinbdclark/osc.js */ +/*! osc.js 2.2.1, Copyright 2018 Colin Clark | github.com/colinbdclark/osc.js */ -var osc=osc||{};!function(){"use strict";osc.SECS_70YRS=2208988800,osc.TWO_32=4294967296,osc.defaults={metadata:!1,unpackSingleArgs:!0},osc.isCommonJS=!("undefined"==typeof module||!module.exports),osc.isNode=osc.isCommonJS&&"undefined"==typeof window,osc.isElectron=!("undefined"==typeof process||!process.versions||!process.versions.electron),osc.isBufferEnv=osc.isNode||osc.isElectron,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};var a="undefined"!=typeof dcodeIO?dcodeIO.Long:"undefined"!=typeof a?a:osc.isNode?require("long"):void 0;osc.dataView=function(a,b,c){return a.buffer?new DataView(a.buffer,b,c):a instanceof ArrayBuffer?new DataView(a,b,c):new DataView(new Uint8Array(a),b,c)},osc.byteArray=function(a){if(a instanceof Uint8Array)return a;var b=a.buffer?a.buffer:a;if(!(b instanceof ArrayBuffer||"undefined"!=typeof b.length&&"string"!=typeof b))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.nativeBuffer=function(a){return osc.isBufferEnv?osc.isBuffer(a)?a:new Buffer(a.buffer?a:new Uint8Array(a)):osc.isTypedArrayView(a)?a:new Uint8Array(a)},osc.copyByteArray=function(a,b,c){if(osc.isTypedArrayView(a)&&osc.isTypedArrayView(b))b.set(a,c);else for(var d=void 0===c?0:c,e=Math.min(b.length-c,a.length),f=0,g=d;f1){var i=Math.floor(h),j=h-i;f+=i,h=j}var k=d+f+osc.SECS_70YRS,l=Math.round(osc.TWO_32*h);return{raw:[k,l]}},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