Socket
Socket
Sign inDemoInstall

osc-js

Package Overview
Dependencies
6
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.1 to 2.0.2

3

lib/osc.js

@@ -1169,3 +1169,4 @@ (function (global, factory) {

var WebSocket = require('isomorphic-ws');
var scope = typeof global === 'undefined' ? window : global;
var WebSocket = typeof __dirname === 'undefined' ? scope.WebSocket : require('isomorphic-ws');
var STATUS$2 = {

@@ -1172,0 +1173,0 @@ IS_NOT_INITIALIZED: -1,

@@ -1,2 +0,2 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.OSC=e()}(this,function(){"use strict";function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function s(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),t}function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&n(t,e)}function a(t){return(a=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function n(t,e){return(n=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function u(t,e){return!e||"object"!=typeof e&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function c(t,e,n){return(c="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var r=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=a(t)););return t}(t,e);if(r){var i=Object.getOwnPropertyDescriptor(r,e);return i.get?i.get.call(n):i.value}})(t,e,n||t)}function f(t){return Number(t)===t&&t%1==0}function h(t){return Number(t)===t&&t%1!=0}function l(t){return"string"==typeof t}function d(t){return"[object Array]"===Object.prototype.toString.call(t)}function p(t){return"[object Object]"===Object.prototype.toString.call(t)}function v(t){return"function"==typeof t}function w(t){return t instanceof Uint8Array}function g(t){return void 0===t}function y(t){return t+3&-4}function k(t){return Object.prototype.hasOwnProperty.call("undefined"!=typeof global?global:window,t)}function b(t){if(f(t))return"i";if(h(t))return"f";if(l(t))return"s";if(w(t))return"b";throw new Error("OSC typeTag() found unknown value type")}function m(t){var e="";if(d(t))return"/".concat(t.join("/"));if(l(t))return 1<(e=t).length&&"/"===e[e.length-1]&&(e=e.slice(0,e.length-1)),1<e.length&&"/"!==e[0]&&(e="/".concat(e)),e;throw new Error("OSC prepareAddress() needs addresses of type array or string")}function S(t){if(!l(t))throw new Error("OSC prepareRegExPattern() needs strings");return t.replace(/\./g,"\\.").replace(/\(/g,"\\(").replace(/\)/g,"\\)").replace(/\{/g,"(").replace(/\}/g,")").replace(/,/g,"|").replace(/\[!/g,"[^").replace(/\?/g,".").replace(/\*/g,".*")}var t=function(){function t(){o(this,t),this.data=[],this.byteLength=0}return s(t,[{key:"add",value:function(t){var e=t.pack();return this.byteLength+=e.byteLength,this.data.push(e),this}},{key:"merge",value:function(){var e=new Uint8Array(this.byteLength),n=0;return this.data.forEach(function(t){e.set(t,n),n+=t.byteLength}),e}}]),t}(),O=function(){function e(t){o(this,e),this.value=t,this.offset=0}return s(e,[{key:"pack",value:function(t,e){if(!t||!e)throw new Error("OSC Atomic cant't be packed without given method or byteLength");var n=new Uint8Array(e),r=new DataView(n.buffer);if(g(this.value))throw new Error("OSC Atomic cant't be encoded with empty value");return r[t](this.offset,this.value,!1),n}},{key:"unpack",value:function(t,e,n){var r=3<arguments.length&&void 0!==arguments[3]?arguments[3]:0;if(!(t&&e&&n))throw new Error("OSC Atomic cant't be unpacked without given dataView, method or byteLength");if(!(t instanceof DataView))throw new Error("OSC Atomic expects an instance of type DataView");return this.value=t[e](r,!1),this.offset=r+n,this.offset}}]),e}(),E=function(t){function n(t){if(o(this,n),t&&!f(t))throw new Error("OSC AtomicInt32 constructor expects value of type number");return u(this,a(n).call(this,t))}return i(n,O),s(n,[{key:"pack",value:function(){return c(a(n.prototype),"pack",this).call(this,"setInt32",4)}},{key:"unpack",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0;return c(a(n.prototype),"unpack",this).call(this,t,"getInt32",4,e)}}]),n}(),C="utf-8";var A=function(t){function e(t){if(o(this,e),t&&!l(t))throw new Error("OSC AtomicString constructor expects value of type string");return u(this,a(e).call(this,t))}return i(e,O),s(e,[{key:"pack",value:function(){if(g(this.value))throw new Error("OSC AtomicString can not be encoded with empty value");for(var t="".concat(this.value,"\0"),e=y(t.length),n=new Uint8Array(e),r=0;r<t.length;r+=1)n[r]=t.charCodeAt(r);return n}},{key:"unpack",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0;if(!(t instanceof DataView))throw new Error("OSC AtomicString expects an instance of type DataView");for(var n,r=e,i=[];r<t.byteLength;r+=1){if(0===(n=t.getUint8(r))){r+=1;break}i.push(n)}if(r===t.length)throw new Error("OSC AtomicString found a malformed OSC string");return this.offset=y(r),this.value=function(t){if(k("Buffer"))return Buffer.from(t).toString(C);if(k("TextDecoder"))return new TextDecoder(C).decode(new Int8Array(t));for(var e="",n=0;n<t.length;n+=65537)e+=String.fromCharCode.apply(null,t.slice(n,n+65537));return e}(i),this.offset}}]),e}(),j=2208988800,P=4294967296,D=function(){function n(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:0,e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0;if(o(this,n),!f(t)||!f(e))throw new Error("OSC Timetag constructor expects values of type integer number");this.seconds=t,this.fractions=e}return s(n,[{key:"timestamp",value:function(t){var e;if("number"!=typeof t)return 1e3*((e=this.seconds-j)+Math.round(this.fractions/P));e=t/1e3;var n=Math.floor(e);return this.seconds=n+j,this.fractions=Math.round(P*(e-n)),t}}]),n}(),x=function(t){function n(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:Date.now();o(this,n);var e=new D;return t instanceof D?e=t:f(t)?e.timestamp(t):t instanceof Date&&e.timestamp(t.getTime()),u(this,a(n).call(this,e))}return i(n,O),s(n,[{key:"pack",value:function(){if(g(this.value))throw new Error("OSC AtomicTimetag can not be encoded with empty value");var t=this.value,e=t.seconds,n=t.fractions,r=new Uint8Array(8),i=new DataView(r.buffer);return i.setInt32(0,e,!1),i.setInt32(4,n,!1),r}},{key:"unpack",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0;if(!(t instanceof DataView))throw new Error("OSC AtomicTimetag expects an instance of type DataView");var n=t.getUint32(e,!1),r=t.getUint32(e+4,!1);return this.value=new D(n,r),this.offset=e+8,this.offset}}]),n}(),H=function(t){function e(t){if(o(this,e),t&&!w(t))throw new Error("OSC AtomicBlob constructor expects value of type Uint8Array");return u(this,a(e).call(this,t))}return i(e,O),s(e,[{key:"pack",value:function(){if(g(this.value))throw new Error("OSC AtomicBlob can not be encoded with empty value");var t=y(this.value.byteLength),e=new Uint8Array(t+4);return new DataView(e.buffer).setInt32(0,this.value.byteLength,!1),e.set(this.value,4),e}},{key:"unpack",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0;if(!(t instanceof DataView))throw new Error("OSC AtomicBlob expects an instance of type DataView");var n=t.getInt32(e,!1);return this.value=new Uint8Array(t.buffer,e+4,n),this.offset=y(e+4+n),this.offset}}]),e}(),I=function(t){function n(t){if(o(this,n),t&&!h(t))throw new Error("OSC AtomicFloat32 constructor expects value of type float");return u(this,a(n).call(this,t))}return i(n,O),s(n,[{key:"pack",value:function(){return c(a(n.prototype),"pack",this).call(this,"setFloat32",4)}},{key:"unpack",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0;return c(a(n.prototype),"unpack",this).call(this,t,"getFloat32",4,e)}}]),n}(),L=function(){function r(){o(this,r),this.offset=0,this.address="",this.types="",this.args=[];for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];if(0<e.length){if(!l(e[0])&&!d(e[0]))throw new Error("OSC Message constructor first argument (address) must be a string or array");this.address=m(e.shift()),this.types=e.map(function(t){return b(t)}).join(""),this.args=e}}return s(r,[{key:"add",value:function(t){if(g(t))throw new Error("OSC Message needs a valid OSC Atomic Data Type");this.args.push(t),this.types+=b(t)}},{key:"pack",value:function(){if(0===this.address.length||"/"!==this.address[0])throw new Error("OSC Message has an invalid address");var e,n=new t;(n.add(new A(this.address)),n.add(new A(",".concat(this.types))),0<this.args.length)&&this.args.forEach(function(t){if(f(t))e=new E(t);else if(h(t))e=new I(t);else if(l(t))e=new A(t);else{if(!w(t))throw new Error("OSC Message found unknown argument type");e=new H(t)}n.add(e)});return n.merge()}},{key:"unpack",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0;if(!(t instanceof DataView))throw new Error("OSC Message expects an instance of type DataView.");var n=new A;n.unpack(t,e);var r=new A;if(r.unpack(t,n.offset),0===n.value.length||"/"!==n.value[0])throw new Error("OSC Message found malformed or missing address string");if(0===r.value.length&&","!==r.value[0])throw new Error("OSC Message found malformed or missing type string");for(var i,o,s=r.offset,a=[],u=1;u<r.value.length;u+=1){if("i"===(o=r.value[u]))i=new E;else if("f"===o)i=new I;else if("s"===o)i=new A;else{if("b"!==o)throw new Error("OSC Message found non-standard argument type");i=new H}s=i.unpack(t,s),a.push(i.value)}return this.offset=s,this.address=n.value,this.types=r.value,this.args=a,this.offset}}]),r}(),B="#bundle",_=function(){function a(){var e=this;o(this,a),this.offset=0,this.timetag=new x,this.bundleElements=[];for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];0<n.length&&(n[0]instanceof Date||f(n[0])?this.timetag=new x(n[0]):d(n[0])?(n[0].forEach(function(t){e.add(t)}),1<n.length&&(n[1]instanceof Date||f(n[0]))&&(this.timetag=new x(n[1]))):n.forEach(function(t){e.add(t)}))}return s(a,[{key:"timestamp",value:function(t){if(!f(t))throw new Error("OSC Bundle needs an integer for setting the timestamp");this.timetag=new x(t)}},{key:"add",value:function(t){if(!(t instanceof L||t instanceof a))throw new Error("OSC Bundle contains only Messages and Bundles");this.bundleElements.push(t)}},{key:"pack",value:function(){var e=new t;return e.add(new A(B)),this.timetag||(this.timetag=new x),e.add(this.timetag),this.bundleElements.forEach(function(t){e.add(new E(t.pack().byteLength)),e.add(t)}),e.merge()}},{key:"unpack",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0;if(!(t instanceof DataView))throw new Error("OSC Bundle expects an instance of type DataView");var n=new A;if(n.unpack(t,e),n.value!==B)throw new Error("OSC Bundle does not contain a valid #bundle head");var r=new x,i=r.unpack(t,n.offset);for(this.bundleElements=[];i<t.byteLength;){var o=new A;i=(new E).unpack(t,i);var s=void 0;o.unpack(t,i),i=(s=o.value===B?new a:new L).unpack(t,i),this.bundleElements.push(s)}return this.offset=i,this.timetag=r,this.offset}}]),a}(),V=function(){function e(t){if(o(this,e),t&&!(t instanceof L||t instanceof _))throw new Error("OSC Packet value has to be Message or Bundle");this.value=t,this.offset=0}return s(e,[{key:"pack",value:function(){if(!this.value)throw new Error("OSC Packet can not be encoded with empty body");return this.value.pack()}},{key:"unpack",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0;if(!(t instanceof DataView))throw new Error("OSC Packet expects an instance of type DataView");if(t.byteLength%4!=0)throw new Error("OSC Packet byteLength has to be a multiple of four");var n,r=new A;return r.unpack(t,e),(n=r.value===B?new _:new L).unpack(t,e),this.offset=n.offset,this.value=n,this.offset}}]),e}(),M={discardLateMessages:!1},T=function(){function e(t){o(this,e),this.options=Object.assign({},M,t),this.addressHandlers=[],this.eventHandlers={open:[],error:[],close:[]},this.uuid=0}return s(e,[{key:"dispatch",value:function(t){var n=this;if(!(t instanceof V))throw new Error("OSC EventHander dispatch() accepts only arguments of type Packet");if(!t.value)throw new Error("OSC EventHander dispatch() can't read empty Packets");if(t.value instanceof _){var r=t.value;return r.bundleElements.forEach(function(t){if(t instanceof _){if(r.timetag.value.timestamp()<t.timetag.value.timestamp())throw new Error("OSC Bundle timestamp is older than the timestamp of enclosed Bundles");return n.dispatch(t)}if(t instanceof L){var e=t;return n.notify(e.address,e,r.timetag.value.timestamp())}throw new Error("OSC EventHander dispatch() can't dispatch unknown Packet value")})}if(t.value instanceof L){var e=t.value;return this.notify(e.address,e)}throw new Error("OSC EventHander dispatch() can't dispatch unknown Packet value")}},{key:"call",value:function(i,o){var s=!1;if(l(i)&&i in this.eventHandlers)return this.eventHandlers[i].forEach(function(t){t.callback(o),s=!0}),s;var t=Object.keys(this.addressHandlers),a=this.addressHandlers;return t.forEach(function(t){var e=!1,n=new RegExp(S(m(i)),"g");if(n.test(t)&&t.length===n.lastIndex&&(e=!0),!e){var r=new RegExp(S(m(t)),"g");r.test(i)&&i.length===r.lastIndex&&(e=!0)}e&&a[t].forEach(function(t){t.callback(o),s=!0})}),s}},{key:"notify",value:function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];if(0===e.length)throw new Error("OSC EventHandler can not be called without any argument");if(e[0]instanceof V)return this.dispatch(e[0]);if(e[0]instanceof _||e[0]instanceof L)return this.dispatch(new V(e[0]));if(!l(e[0])){var r=new V;return r.unpack((i=e[0]).buffer?new DataView(i.buffer):i instanceof ArrayBuffer?new DataView(i):new DataView(new Uint8Array(i))),this.dispatch(r)}var i,o=e[0],s=null;1<e.length&&(s=e[1]);var a=null;if(2<e.length)if(f(e[2]))a=e[2];else{if(!(e[2]instanceof Date))throw new Error("OSC EventHandler timestamp has to be a number or Date");a=e[2].getTime()}if(a){var u=Date.now();if(a<u&&!this.options.discardLateMessages)return this.call(o,s);var c=this;return setTimeout(function(){c.call(o,s)},a-u),!0}return this.call(o,s)}},{key:"on",value:function(t,e){if(!l(t)&&!d(t))throw new Error("OSC EventHandler accepts only strings or arrays for address patterns");if(!v(e))throw new Error("OSC EventHandler callback has to be a function");this.uuid+=1;var n={id:this.uuid,callback:e};if(l(t)&&t in this.eventHandlers)return this.eventHandlers[t].push(n),this.uuid;var r=m(t);return r in this.addressHandlers||(this.addressHandlers[r]=[]),this.addressHandlers[r].push(n),this.uuid}},{key:"off",value:function(t,n){if(!l(t)&&!d(t))throw new Error("OSC EventHandler accepts only strings or arrays for address patterns");if(!f(n))throw new Error("OSC EventHandler subscription id has to be a number");var r,i;return i=l(t)&&t in this.eventHandlers?(r=t,this.eventHandlers):(r=m(t),this.addressHandlers),r in i&&i[r].some(function(t,e){return t.id===n&&(i[r].splice(e,1),!0)})}}]),e}(),N="undefined"!=typeof __dirname?require("dgram"):void 0,U=-1,R=0,q=1,e=2,W=3,F={type:"udp4",open:{host:"localhost",port:41234,exclusive:!1},send:{host:"localhost",port:41235}};var G=function(){function i(){var t,e,n=this,r=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};if(o(this,i),!N)throw new Error("DatagramPlugin can not be used in browser context");this.options=(t={},e=r,Object.assign({},F,t,e,{open:Object.assign({},F.open,t.open,e.open),send:Object.assign({},F.send,t.send,e.send)})),this.socket=N.createSocket(this.options.type),this.socketStatus=U,this.socket.on("message",function(t){n.notify(t)}),this.socket.on("error",function(t){n.notify("error",t)}),this.notify=function(){}}return s(i,[{key:"registerNotify",value:function(t){this.notify=t}},{key:"status",value:function(){return this.socketStatus}},{key:"open",value:function(){var t=this,e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},n=Object.assign({},this.options.open,e),r=n.port,i=n.exclusive;this.socketStatus=R,this.socket.bind({address:n.host,port:r,exclusive:i},function(){t.socketStatus=q,t.notify("open")})}},{key:"close",value:function(){var t=this;this.socketStatus=e,this.socket.close(function(){t.socketStatus=W,t.notify("close")})}},{key:"send",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},n=Object.assign({},this.options.send,e),r=n.port,i=n.host;this.socket.send(Buffer.from(t),0,t.byteLength,r,i)}}]),i}(),Z="undefined"!=typeof __dirname?require("dgram"):void 0,z="undefined"!=typeof __dirname?require("isomorphic-ws").Server:void 0,J=-1,K=0,Q=1,X=2,Y=3,$={udpServer:{host:"localhost",port:41234,exclusive:!1},udpClient:{host:"localhost",port:41235},wsServer:{host:"localhost",port:8080},receiver:"ws"};function tt(t,e){return Object.assign({},$,t,e,{udpServer:Object.assign({},$.udpServer,t.udpServer,e.udpServer),udpClient:Object.assign({},$.udpClient,t.udpClient,e.udpClient),wsServer:Object.assign({},$.wsServer,t.wsServer,e.wsServer)})}var et=function(){function n(){var e=this,t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};if(o(this,n),!Z||!z)throw new Error("BridgePlugin can not be used in browser context");this.options=tt({},t),this.websocket=null,this.socket=Z.createSocket("udp4"),this.socketStatus=J,this.socket.on("message",function(t){e.send(t,{receiver:"ws"}),e.notify(t.buffer)}),this.socket.on("error",function(t){e.notify("error",t)}),this.notify=function(){}}return s(n,[{key:"registerNotify",value:function(t){this.notify=t}},{key:"status",value:function(){return this.socketStatus}},{key:"open",value:function(){var e=this,t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},n=tt(this.options,t);this.socketStatus=K,this.socket.bind({address:n.udpServer.host,port:n.udpServer.port,exclusive:n.udpServer.exclusive},function(){e.websocket=new z({host:n.wsServer.host,port:n.wsServer.port}),e.websocket.binaryType="arraybuffer",e.websocket.on("listening",function(){e.socketStatus=Q,e.notify("open")}),e.websocket.on("error",function(t){e.notify("error",t)}),e.websocket.on("connection",function(t){t.on("message",function(t){e.send(t,{receiver:"udp"}),e.notify(new Uint8Array(t))})})})}},{key:"close",value:function(){var t=this;this.socketStatus=X,this.socket.close(function(){t.websocket.close(function(){t.socketStatus=Y,t.notify("close")})})}},{key:"send",value:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},n=tt(this.options,t),r=n.receiver;if("udp"===r){var i=e instanceof Buffer?e:Buffer.from(e);this.socket.send(i,0,i.byteLength,n.udpClient.port,n.udpClient.host)}else{if("ws"!==r)throw new Error("BridgePlugin can not send message to unknown receiver");this.websocket.clients.forEach(function(t){t.send(e,{binary:!0})})}}}]),n}(),nt=require("isomorphic-ws"),rt=-1,it=0,ot=1,st=2,at=3,ut={host:"localhost",port:8080,secure:!1},ct=function(){function e(t){if(o(this,e),!nt)throw new Error("WebsocketClientPlugin can't find a WebSocket class");this.options=Object.assign({},ut,t),this.socket=null,this.socketStatus=rt,this.notify=function(){}}return s(e,[{key:"registerNotify",value:function(t){this.notify=t}},{key:"status",value:function(){return this.socketStatus}},{key:"open",value:function(){var e=this,t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},n=Object.assign({},this.options,t),r=n.port,i=n.host,o=n.secure;this.socket&&this.close();var s=o?"wss":"ws";this.socket=new nt("".concat(s,"://").concat(i,":").concat(r)),this.socket.binaryType="arraybuffer",this.socketStatus=it,this.socket.onopen=function(){e.socketStatus=ot,e.notify("open")},this.socket.onclose=function(){e.socketStatus=at,e.notify("close")},this.socket.onerror=function(t){e.notify("error",t)},this.socket.onmessage=function(t){e.notify(t.data)}}},{key:"close",value:function(){this.socketStatus=st,this.socket.close()}},{key:"send",value:function(t){this.socket.send(t)}}]),e}(),ft="undefined"!=typeof __dirname?require("isomorphic-ws").Server:void 0,ht=-1,lt=0,dt=1,pt=2,vt=3,wt={host:"localhost",port:8080},gt=function(){function e(t){if(o(this,e),!ft)throw new Error("WebsocketServerPlugin can not be used in browser context");this.options=Object.assign({},wt,t),this.socket=null,this.socketStatus=ht,this.notify=function(){}}return s(e,[{key:"registerNotify",value:function(t){this.notify=t}},{key:"status",value:function(){return this.socketStatus}},{key:"open",value:function(){var e=this,t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},n=Object.assign({},this.options,t),r=n.port,i=n.host;this.socket&&this.close(),this.socket=new ft({host:i,port:r}),this.socket.binaryType="arraybuffer",this.socketStatus=lt,this.socket.on("listening",function(){e.socketStatus=dt,e.notify("open")}),this.socket.on("error",function(t){e.notify("error",t)}),this.socket.on("connection",function(t){t.on("message",function(t){e.notify(new Uint8Array(t))})})}},{key:"close",value:function(){var t=this;this.socketStatus=pt,this.socket.close(function(){t.socketStatus=vt,t.notify("close")})}},{key:"send",value:function(e){this.socket.clients.forEach(function(t){t.send(e,{binary:!0})})}}]),e}(),yt={discardLateMessages:!1,plugin:new ct},kt=function(){function n(t){if(o(this,n),t&&!p(t))throw new Error("OSC options argument has to be an object.");this.options=Object.assign({},yt,t),this.eventHandler=new T({discardLateMessages:this.options.discardLateMessages});var e=this.eventHandler;this.options.plugin&&this.options.plugin.registerNotify&&this.options.plugin.registerNotify(function(){return e.notify.apply(e,arguments)})}return s(n,[{key:"on",value:function(t,e){if(!l(t)||!v(e))throw new Error("OSC on() needs event- or address string and callback function");return this.eventHandler.on(t,e)}},{key:"off",value:function(t,e){if(!l(t)||!f(e))throw new Error("OSC off() needs string and number (subscriptionId) to unsubscribe");return this.eventHandler.off(t,e)}},{key:"open",value:function(t){if(t&&!p(t))throw new Error("OSC open() options argument needs to be an object");if(!this.options.plugin||!v(this.options.plugin.open))throw new Error("OSC Plugin API #open is not implemented!");return this.options.plugin.open(t)}},{key:"status",value:function(){if(!this.options.plugin||!v(this.options.plugin.status))throw new Error("OSC Plugin API #status is not implemented!");return this.options.plugin.status()}},{key:"close",value:function(){if(!this.options.plugin||!v(this.options.plugin.close))throw new Error("OSC Plugin API #close is not implemented!");return this.options.plugin.close()}},{key:"send",value:function(t,e){if(!this.options.plugin||!v(this.options.plugin.send))throw new Error("OSC Plugin API #send is not implemented!");if(!(t instanceof L||t instanceof _||t instanceof V))throw new Error("OSC send() needs Messages, Bundles or Packets");if(e&&!p(e))throw new Error("OSC send() options argument has to be an object");return this.options.plugin.send(t.pack(),e)}}]),n}();return kt.STATUS={IS_NOT_INITIALIZED:-1,IS_CONNECTING:0,IS_OPEN:1,IS_CLOSING:2,IS_CLOSED:3},kt.Packet=V,kt.Bundle=_,kt.Message=L,kt.DatagramPlugin=G,kt.WebsocketClientPlugin=ct,kt.WebsocketServerPlugin=gt,kt.BridgePlugin=et,kt});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.OSC=e()}(this,function(){"use strict";function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function s(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),t}function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&n(t,e)}function a(t){return(a=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function n(t,e){return(n=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function u(t,e){return!e||"object"!=typeof e&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function c(t,e,n){return(c="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var r=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=a(t)););return t}(t,e);if(r){var i=Object.getOwnPropertyDescriptor(r,e);return i.get?i.get.call(n):i.value}})(t,e,n||t)}function f(t){return Number(t)===t&&t%1==0}function h(t){return Number(t)===t&&t%1!=0}function l(t){return"string"==typeof t}function d(t){return"[object Array]"===Object.prototype.toString.call(t)}function p(t){return"[object Object]"===Object.prototype.toString.call(t)}function v(t){return"function"==typeof t}function w(t){return t instanceof Uint8Array}function g(t){return void 0===t}function y(t){return t+3&-4}function k(t){return Object.prototype.hasOwnProperty.call("undefined"!=typeof global?global:window,t)}function b(t){if(f(t))return"i";if(h(t))return"f";if(l(t))return"s";if(w(t))return"b";throw new Error("OSC typeTag() found unknown value type")}function m(t){var e="";if(d(t))return"/".concat(t.join("/"));if(l(t))return 1<(e=t).length&&"/"===e[e.length-1]&&(e=e.slice(0,e.length-1)),1<e.length&&"/"!==e[0]&&(e="/".concat(e)),e;throw new Error("OSC prepareAddress() needs addresses of type array or string")}function S(t){if(!l(t))throw new Error("OSC prepareRegExPattern() needs strings");return t.replace(/\./g,"\\.").replace(/\(/g,"\\(").replace(/\)/g,"\\)").replace(/\{/g,"(").replace(/\}/g,")").replace(/,/g,"|").replace(/\[!/g,"[^").replace(/\?/g,".").replace(/\*/g,".*")}var t=function(){function t(){o(this,t),this.data=[],this.byteLength=0}return s(t,[{key:"add",value:function(t){var e=t.pack();return this.byteLength+=e.byteLength,this.data.push(e),this}},{key:"merge",value:function(){var e=new Uint8Array(this.byteLength),n=0;return this.data.forEach(function(t){e.set(t,n),n+=t.byteLength}),e}}]),t}(),O=function(){function e(t){o(this,e),this.value=t,this.offset=0}return s(e,[{key:"pack",value:function(t,e){if(!t||!e)throw new Error("OSC Atomic cant't be packed without given method or byteLength");var n=new Uint8Array(e),r=new DataView(n.buffer);if(g(this.value))throw new Error("OSC Atomic cant't be encoded with empty value");return r[t](this.offset,this.value,!1),n}},{key:"unpack",value:function(t,e,n){var r=3<arguments.length&&void 0!==arguments[3]?arguments[3]:0;if(!(t&&e&&n))throw new Error("OSC Atomic cant't be unpacked without given dataView, method or byteLength");if(!(t instanceof DataView))throw new Error("OSC Atomic expects an instance of type DataView");return this.value=t[e](r,!1),this.offset=r+n,this.offset}}]),e}(),E=function(t){function n(t){if(o(this,n),t&&!f(t))throw new Error("OSC AtomicInt32 constructor expects value of type number");return u(this,a(n).call(this,t))}return i(n,O),s(n,[{key:"pack",value:function(){return c(a(n.prototype),"pack",this).call(this,"setInt32",4)}},{key:"unpack",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0;return c(a(n.prototype),"unpack",this).call(this,t,"getInt32",4,e)}}]),n}(),C="utf-8";var A=function(t){function e(t){if(o(this,e),t&&!l(t))throw new Error("OSC AtomicString constructor expects value of type string");return u(this,a(e).call(this,t))}return i(e,O),s(e,[{key:"pack",value:function(){if(g(this.value))throw new Error("OSC AtomicString can not be encoded with empty value");for(var t="".concat(this.value,"\0"),e=y(t.length),n=new Uint8Array(e),r=0;r<t.length;r+=1)n[r]=t.charCodeAt(r);return n}},{key:"unpack",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0;if(!(t instanceof DataView))throw new Error("OSC AtomicString expects an instance of type DataView");for(var n,r=e,i=[];r<t.byteLength;r+=1){if(0===(n=t.getUint8(r))){r+=1;break}i.push(n)}if(r===t.length)throw new Error("OSC AtomicString found a malformed OSC string");return this.offset=y(r),this.value=function(t){if(k("Buffer"))return Buffer.from(t).toString(C);if(k("TextDecoder"))return new TextDecoder(C).decode(new Int8Array(t));for(var e="",n=0;n<t.length;n+=65537)e+=String.fromCharCode.apply(null,t.slice(n,n+65537));return e}(i),this.offset}}]),e}(),j=2208988800,P=4294967296,D=function(){function n(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:0,e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0;if(o(this,n),!f(t)||!f(e))throw new Error("OSC Timetag constructor expects values of type integer number");this.seconds=t,this.fractions=e}return s(n,[{key:"timestamp",value:function(t){var e;if("number"!=typeof t)return 1e3*((e=this.seconds-j)+Math.round(this.fractions/P));e=t/1e3;var n=Math.floor(e);return this.seconds=n+j,this.fractions=Math.round(P*(e-n)),t}}]),n}(),x=function(t){function n(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:Date.now();o(this,n);var e=new D;return t instanceof D?e=t:f(t)?e.timestamp(t):t instanceof Date&&e.timestamp(t.getTime()),u(this,a(n).call(this,e))}return i(n,O),s(n,[{key:"pack",value:function(){if(g(this.value))throw new Error("OSC AtomicTimetag can not be encoded with empty value");var t=this.value,e=t.seconds,n=t.fractions,r=new Uint8Array(8),i=new DataView(r.buffer);return i.setInt32(0,e,!1),i.setInt32(4,n,!1),r}},{key:"unpack",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0;if(!(t instanceof DataView))throw new Error("OSC AtomicTimetag expects an instance of type DataView");var n=t.getUint32(e,!1),r=t.getUint32(e+4,!1);return this.value=new D(n,r),this.offset=e+8,this.offset}}]),n}(),H=function(t){function e(t){if(o(this,e),t&&!w(t))throw new Error("OSC AtomicBlob constructor expects value of type Uint8Array");return u(this,a(e).call(this,t))}return i(e,O),s(e,[{key:"pack",value:function(){if(g(this.value))throw new Error("OSC AtomicBlob can not be encoded with empty value");var t=y(this.value.byteLength),e=new Uint8Array(t+4);return new DataView(e.buffer).setInt32(0,this.value.byteLength,!1),e.set(this.value,4),e}},{key:"unpack",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0;if(!(t instanceof DataView))throw new Error("OSC AtomicBlob expects an instance of type DataView");var n=t.getInt32(e,!1);return this.value=new Uint8Array(t.buffer,e+4,n),this.offset=y(e+4+n),this.offset}}]),e}(),I=function(t){function n(t){if(o(this,n),t&&!h(t))throw new Error("OSC AtomicFloat32 constructor expects value of type float");return u(this,a(n).call(this,t))}return i(n,O),s(n,[{key:"pack",value:function(){return c(a(n.prototype),"pack",this).call(this,"setFloat32",4)}},{key:"unpack",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0;return c(a(n.prototype),"unpack",this).call(this,t,"getFloat32",4,e)}}]),n}(),L=function(){function r(){o(this,r),this.offset=0,this.address="",this.types="",this.args=[];for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];if(0<e.length){if(!l(e[0])&&!d(e[0]))throw new Error("OSC Message constructor first argument (address) must be a string or array");this.address=m(e.shift()),this.types=e.map(function(t){return b(t)}).join(""),this.args=e}}return s(r,[{key:"add",value:function(t){if(g(t))throw new Error("OSC Message needs a valid OSC Atomic Data Type");this.args.push(t),this.types+=b(t)}},{key:"pack",value:function(){if(0===this.address.length||"/"!==this.address[0])throw new Error("OSC Message has an invalid address");var e,n=new t;(n.add(new A(this.address)),n.add(new A(",".concat(this.types))),0<this.args.length)&&this.args.forEach(function(t){if(f(t))e=new E(t);else if(h(t))e=new I(t);else if(l(t))e=new A(t);else{if(!w(t))throw new Error("OSC Message found unknown argument type");e=new H(t)}n.add(e)});return n.merge()}},{key:"unpack",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0;if(!(t instanceof DataView))throw new Error("OSC Message expects an instance of type DataView.");var n=new A;n.unpack(t,e);var r=new A;if(r.unpack(t,n.offset),0===n.value.length||"/"!==n.value[0])throw new Error("OSC Message found malformed or missing address string");if(0===r.value.length&&","!==r.value[0])throw new Error("OSC Message found malformed or missing type string");for(var i,o,s=r.offset,a=[],u=1;u<r.value.length;u+=1){if("i"===(o=r.value[u]))i=new E;else if("f"===o)i=new I;else if("s"===o)i=new A;else{if("b"!==o)throw new Error("OSC Message found non-standard argument type");i=new H}s=i.unpack(t,s),a.push(i.value)}return this.offset=s,this.address=n.value,this.types=r.value,this.args=a,this.offset}}]),r}(),_="#bundle",B=function(){function a(){var e=this;o(this,a),this.offset=0,this.timetag=new x,this.bundleElements=[];for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];0<n.length&&(n[0]instanceof Date||f(n[0])?this.timetag=new x(n[0]):d(n[0])?(n[0].forEach(function(t){e.add(t)}),1<n.length&&(n[1]instanceof Date||f(n[0]))&&(this.timetag=new x(n[1]))):n.forEach(function(t){e.add(t)}))}return s(a,[{key:"timestamp",value:function(t){if(!f(t))throw new Error("OSC Bundle needs an integer for setting the timestamp");this.timetag=new x(t)}},{key:"add",value:function(t){if(!(t instanceof L||t instanceof a))throw new Error("OSC Bundle contains only Messages and Bundles");this.bundleElements.push(t)}},{key:"pack",value:function(){var e=new t;return e.add(new A(_)),this.timetag||(this.timetag=new x),e.add(this.timetag),this.bundleElements.forEach(function(t){e.add(new E(t.pack().byteLength)),e.add(t)}),e.merge()}},{key:"unpack",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0;if(!(t instanceof DataView))throw new Error("OSC Bundle expects an instance of type DataView");var n=new A;if(n.unpack(t,e),n.value!==_)throw new Error("OSC Bundle does not contain a valid #bundle head");var r=new x,i=r.unpack(t,n.offset);for(this.bundleElements=[];i<t.byteLength;){var o=new A;i=(new E).unpack(t,i);var s=void 0;o.unpack(t,i),i=(s=o.value===_?new a:new L).unpack(t,i),this.bundleElements.push(s)}return this.offset=i,this.timetag=r,this.offset}}]),a}(),V=function(){function e(t){if(o(this,e),t&&!(t instanceof L||t instanceof B))throw new Error("OSC Packet value has to be Message or Bundle");this.value=t,this.offset=0}return s(e,[{key:"pack",value:function(){if(!this.value)throw new Error("OSC Packet can not be encoded with empty body");return this.value.pack()}},{key:"unpack",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0;if(!(t instanceof DataView))throw new Error("OSC Packet expects an instance of type DataView");if(t.byteLength%4!=0)throw new Error("OSC Packet byteLength has to be a multiple of four");var n,r=new A;return r.unpack(t,e),(n=r.value===_?new B:new L).unpack(t,e),this.offset=n.offset,this.value=n,this.offset}}]),e}(),M={discardLateMessages:!1},T=function(){function e(t){o(this,e),this.options=Object.assign({},M,t),this.addressHandlers=[],this.eventHandlers={open:[],error:[],close:[]},this.uuid=0}return s(e,[{key:"dispatch",value:function(t){var n=this;if(!(t instanceof V))throw new Error("OSC EventHander dispatch() accepts only arguments of type Packet");if(!t.value)throw new Error("OSC EventHander dispatch() can't read empty Packets");if(t.value instanceof B){var r=t.value;return r.bundleElements.forEach(function(t){if(t instanceof B){if(r.timetag.value.timestamp()<t.timetag.value.timestamp())throw new Error("OSC Bundle timestamp is older than the timestamp of enclosed Bundles");return n.dispatch(t)}if(t instanceof L){var e=t;return n.notify(e.address,e,r.timetag.value.timestamp())}throw new Error("OSC EventHander dispatch() can't dispatch unknown Packet value")})}if(t.value instanceof L){var e=t.value;return this.notify(e.address,e)}throw new Error("OSC EventHander dispatch() can't dispatch unknown Packet value")}},{key:"call",value:function(i,o){var s=!1;if(l(i)&&i in this.eventHandlers)return this.eventHandlers[i].forEach(function(t){t.callback(o),s=!0}),s;var t=Object.keys(this.addressHandlers),a=this.addressHandlers;return t.forEach(function(t){var e=!1,n=new RegExp(S(m(i)),"g");if(n.test(t)&&t.length===n.lastIndex&&(e=!0),!e){var r=new RegExp(S(m(t)),"g");r.test(i)&&i.length===r.lastIndex&&(e=!0)}e&&a[t].forEach(function(t){t.callback(o),s=!0})}),s}},{key:"notify",value:function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];if(0===e.length)throw new Error("OSC EventHandler can not be called without any argument");if(e[0]instanceof V)return this.dispatch(e[0]);if(e[0]instanceof B||e[0]instanceof L)return this.dispatch(new V(e[0]));if(!l(e[0])){var r=new V;return r.unpack((i=e[0]).buffer?new DataView(i.buffer):i instanceof ArrayBuffer?new DataView(i):new DataView(new Uint8Array(i))),this.dispatch(r)}var i,o=e[0],s=null;1<e.length&&(s=e[1]);var a=null;if(2<e.length)if(f(e[2]))a=e[2];else{if(!(e[2]instanceof Date))throw new Error("OSC EventHandler timestamp has to be a number or Date");a=e[2].getTime()}if(a){var u=Date.now();if(a<u&&!this.options.discardLateMessages)return this.call(o,s);var c=this;return setTimeout(function(){c.call(o,s)},a-u),!0}return this.call(o,s)}},{key:"on",value:function(t,e){if(!l(t)&&!d(t))throw new Error("OSC EventHandler accepts only strings or arrays for address patterns");if(!v(e))throw new Error("OSC EventHandler callback has to be a function");this.uuid+=1;var n={id:this.uuid,callback:e};if(l(t)&&t in this.eventHandlers)return this.eventHandlers[t].push(n),this.uuid;var r=m(t);return r in this.addressHandlers||(this.addressHandlers[r]=[]),this.addressHandlers[r].push(n),this.uuid}},{key:"off",value:function(t,n){if(!l(t)&&!d(t))throw new Error("OSC EventHandler accepts only strings or arrays for address patterns");if(!f(n))throw new Error("OSC EventHandler subscription id has to be a number");var r,i;return i=l(t)&&t in this.eventHandlers?(r=t,this.eventHandlers):(r=m(t),this.addressHandlers),r in i&&i[r].some(function(t,e){return t.id===n&&(i[r].splice(e,1),!0)})}}]),e}(),N="undefined"!=typeof __dirname?require("dgram"):void 0,U=-1,R=0,W=1,e=2,q=3,F={type:"udp4",open:{host:"localhost",port:41234,exclusive:!1},send:{host:"localhost",port:41235}};var G=function(){function i(){var t,e,n=this,r=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};if(o(this,i),!N)throw new Error("DatagramPlugin can not be used in browser context");this.options=(t={},e=r,Object.assign({},F,t,e,{open:Object.assign({},F.open,t.open,e.open),send:Object.assign({},F.send,t.send,e.send)})),this.socket=N.createSocket(this.options.type),this.socketStatus=U,this.socket.on("message",function(t){n.notify(t)}),this.socket.on("error",function(t){n.notify("error",t)}),this.notify=function(){}}return s(i,[{key:"registerNotify",value:function(t){this.notify=t}},{key:"status",value:function(){return this.socketStatus}},{key:"open",value:function(){var t=this,e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},n=Object.assign({},this.options.open,e),r=n.port,i=n.exclusive;this.socketStatus=R,this.socket.bind({address:n.host,port:r,exclusive:i},function(){t.socketStatus=W,t.notify("open")})}},{key:"close",value:function(){var t=this;this.socketStatus=e,this.socket.close(function(){t.socketStatus=q,t.notify("close")})}},{key:"send",value:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},n=Object.assign({},this.options.send,e),r=n.port,i=n.host;this.socket.send(Buffer.from(t),0,t.byteLength,r,i)}}]),i}(),Z="undefined"!=typeof __dirname?require("dgram"):void 0,z="undefined"!=typeof __dirname?require("isomorphic-ws").Server:void 0,J=-1,K=0,Q=1,X=2,Y=3,$={udpServer:{host:"localhost",port:41234,exclusive:!1},udpClient:{host:"localhost",port:41235},wsServer:{host:"localhost",port:8080},receiver:"ws"};function tt(t,e){return Object.assign({},$,t,e,{udpServer:Object.assign({},$.udpServer,t.udpServer,e.udpServer),udpClient:Object.assign({},$.udpClient,t.udpClient,e.udpClient),wsServer:Object.assign({},$.wsServer,t.wsServer,e.wsServer)})}var et=function(){function n(){var e=this,t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};if(o(this,n),!Z||!z)throw new Error("BridgePlugin can not be used in browser context");this.options=tt({},t),this.websocket=null,this.socket=Z.createSocket("udp4"),this.socketStatus=J,this.socket.on("message",function(t){e.send(t,{receiver:"ws"}),e.notify(t.buffer)}),this.socket.on("error",function(t){e.notify("error",t)}),this.notify=function(){}}return s(n,[{key:"registerNotify",value:function(t){this.notify=t}},{key:"status",value:function(){return this.socketStatus}},{key:"open",value:function(){var e=this,t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},n=tt(this.options,t);this.socketStatus=K,this.socket.bind({address:n.udpServer.host,port:n.udpServer.port,exclusive:n.udpServer.exclusive},function(){e.websocket=new z({host:n.wsServer.host,port:n.wsServer.port}),e.websocket.binaryType="arraybuffer",e.websocket.on("listening",function(){e.socketStatus=Q,e.notify("open")}),e.websocket.on("error",function(t){e.notify("error",t)}),e.websocket.on("connection",function(t){t.on("message",function(t){e.send(t,{receiver:"udp"}),e.notify(new Uint8Array(t))})})})}},{key:"close",value:function(){var t=this;this.socketStatus=X,this.socket.close(function(){t.websocket.close(function(){t.socketStatus=Y,t.notify("close")})})}},{key:"send",value:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},n=tt(this.options,t),r=n.receiver;if("udp"===r){var i=e instanceof Buffer?e:Buffer.from(e);this.socket.send(i,0,i.byteLength,n.udpClient.port,n.udpClient.host)}else{if("ws"!==r)throw new Error("BridgePlugin can not send message to unknown receiver");this.websocket.clients.forEach(function(t){t.send(e,{binary:!0})})}}}]),n}(),nt="undefined"==typeof global?window:global,rt="undefined"==typeof __dirname?nt.WebSocket:require("isomorphic-ws"),it=-1,ot=0,st=1,at=2,ut=3,ct={host:"localhost",port:8080,secure:!1},ft=function(){function e(t){if(o(this,e),!rt)throw new Error("WebsocketClientPlugin can't find a WebSocket class");this.options=Object.assign({},ct,t),this.socket=null,this.socketStatus=it,this.notify=function(){}}return s(e,[{key:"registerNotify",value:function(t){this.notify=t}},{key:"status",value:function(){return this.socketStatus}},{key:"open",value:function(){var e=this,t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},n=Object.assign({},this.options,t),r=n.port,i=n.host,o=n.secure;this.socket&&this.close();var s=o?"wss":"ws";this.socket=new rt("".concat(s,"://").concat(i,":").concat(r)),this.socket.binaryType="arraybuffer",this.socketStatus=ot,this.socket.onopen=function(){e.socketStatus=st,e.notify("open")},this.socket.onclose=function(){e.socketStatus=ut,e.notify("close")},this.socket.onerror=function(t){e.notify("error",t)},this.socket.onmessage=function(t){e.notify(t.data)}}},{key:"close",value:function(){this.socketStatus=at,this.socket.close()}},{key:"send",value:function(t){this.socket.send(t)}}]),e}(),ht="undefined"!=typeof __dirname?require("isomorphic-ws").Server:void 0,lt=-1,dt=0,pt=1,vt=2,wt=3,gt={host:"localhost",port:8080},yt=function(){function e(t){if(o(this,e),!ht)throw new Error("WebsocketServerPlugin can not be used in browser context");this.options=Object.assign({},gt,t),this.socket=null,this.socketStatus=lt,this.notify=function(){}}return s(e,[{key:"registerNotify",value:function(t){this.notify=t}},{key:"status",value:function(){return this.socketStatus}},{key:"open",value:function(){var e=this,t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},n=Object.assign({},this.options,t),r=n.port,i=n.host;this.socket&&this.close(),this.socket=new ht({host:i,port:r}),this.socket.binaryType="arraybuffer",this.socketStatus=dt,this.socket.on("listening",function(){e.socketStatus=pt,e.notify("open")}),this.socket.on("error",function(t){e.notify("error",t)}),this.socket.on("connection",function(t){t.on("message",function(t){e.notify(new Uint8Array(t))})})}},{key:"close",value:function(){var t=this;this.socketStatus=vt,this.socket.close(function(){t.socketStatus=wt,t.notify("close")})}},{key:"send",value:function(e){this.socket.clients.forEach(function(t){t.send(e,{binary:!0})})}}]),e}(),kt={discardLateMessages:!1,plugin:new ft},bt=function(){function n(t){if(o(this,n),t&&!p(t))throw new Error("OSC options argument has to be an object.");this.options=Object.assign({},kt,t),this.eventHandler=new T({discardLateMessages:this.options.discardLateMessages});var e=this.eventHandler;this.options.plugin&&this.options.plugin.registerNotify&&this.options.plugin.registerNotify(function(){return e.notify.apply(e,arguments)})}return s(n,[{key:"on",value:function(t,e){if(!l(t)||!v(e))throw new Error("OSC on() needs event- or address string and callback function");return this.eventHandler.on(t,e)}},{key:"off",value:function(t,e){if(!l(t)||!f(e))throw new Error("OSC off() needs string and number (subscriptionId) to unsubscribe");return this.eventHandler.off(t,e)}},{key:"open",value:function(t){if(t&&!p(t))throw new Error("OSC open() options argument needs to be an object");if(!this.options.plugin||!v(this.options.plugin.open))throw new Error("OSC Plugin API #open is not implemented!");return this.options.plugin.open(t)}},{key:"status",value:function(){if(!this.options.plugin||!v(this.options.plugin.status))throw new Error("OSC Plugin API #status is not implemented!");return this.options.plugin.status()}},{key:"close",value:function(){if(!this.options.plugin||!v(this.options.plugin.close))throw new Error("OSC Plugin API #close is not implemented!");return this.options.plugin.close()}},{key:"send",value:function(t,e){if(!this.options.plugin||!v(this.options.plugin.send))throw new Error("OSC Plugin API #send is not implemented!");if(!(t instanceof L||t instanceof B||t instanceof V))throw new Error("OSC send() needs Messages, Bundles or Packets");if(e&&!p(e))throw new Error("OSC send() options argument has to be an object");return this.options.plugin.send(t.pack(),e)}}]),n}();return bt.STATUS={IS_NOT_INITIALIZED:-1,IS_CONNECTING:0,IS_OPEN:1,IS_CLOSING:2,IS_CLOSED:3},bt.Packet=V,bt.Bundle=B,bt.Message=L,bt.DatagramPlugin=G,bt.WebsocketClientPlugin=ft,bt.WebsocketServerPlugin=yt,bt.BridgePlugin=et,bt});
//# sourceMappingURL=osc.min.js.map
{
"name": "osc-js",
"version": "2.0.1",
"version": "2.0.2",
"description": "OSC library for Node.js and the browser, with customizable Plugin API for WebSocket, UDP or bridge networking",

@@ -5,0 +5,0 @@ "main": "lib/osc.js",

@@ -25,3 +25,3 @@ osc-js

- UMD Module running in Node.js, Electron, Chrome Apps, your browser or any other JS environment
- UMD Module running in Node.js, Electron, Chrome Apps, browser or any other JS environment
- Can be used with Webpack and Browserify

@@ -31,3 +31,3 @@ - No dependencies (except of `ws` in Node.js or similar environments)

- Special bridge plugin for easy communication between *UDP*- and *WebSocket* clients
- Plugin API for custom networking protocols
- Plugin API for custom network protocols
- Featuring all [OSC 1.0 specifications](http://opensoundcontrol.org/spec-1_0)

@@ -50,6 +50,2 @@ - OSC Address pattern matching

osc.on(['param', 'volume'], message => {
console.log(message.args)
})
osc.on('*', message => {

@@ -66,6 +62,2 @@ console.log(message.args)

osc.send(message)
const bundle = new OSC.Bundle(Date.now() + 5000)
bundle.add(message)
osc.send(bundle, { host: '192.168.178.5' })
})

@@ -78,3 +70,3 @@

Recommended installation via npm: `npm install osc-js --save` or yarn `yarn add osc-js`.
Recommended installation via npm: `npm install osc-js --save` or `yarn add osc-js`.

@@ -85,3 +77,3 @@ Import the library `const OSC = require('osc-js')` or add the script `lib/osc.js` or `lib/osc.min.js` (minified version) for usage in a browser.

osc-js offers a plugin architecture for extending it's networking capabilities. The library comes already with four built-in plugins. This is propably all you will ever need for your OSC applications:
osc-js offers a plugin architecture for extending it's networking capabilities. The library comes with four built-in plugins. This is propably all you need for an OSC application:

@@ -142,3 +134,3 @@ - `WebsocketClientPlugin` (default)

It is possible to write even more sophisticated solutions for your OSC application without loosing the simple osc-js interface (including it's nice message handling etc.). Read the [Plugin API documentation](https://github.com/adzialocha/osc-js/wiki/Plugin-API) for further information.
It is possible to write more sophisticated solutions for OSC applications without loosing the osc-js interface (including it's message handling etc.). Read the [Plugin API documentation](https://github.com/adzialocha/osc-js/wiki/Plugin-API) for further information.

@@ -160,3 +152,3 @@ ```js

The library can also be used without the mentioned features in case you need to write and read binary OSC data. See this example below for using the [Low-Level API](https://github.com/adzialocha/osc-js/wiki/Low-Level-API) (even though the library already has a solution for handling UDP like in this example):
The library can be used without the mentioned features in case you need to write and read binary OSC data. See this example below for using the [Low-Level API](https://github.com/adzialocha/osc-js/wiki/Low-Level-API) (even though the library already has a solution for handling UDP like in this example):

@@ -163,0 +155,0 @@ ```js

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc