Socket
Socket
Sign inDemoInstall

osc-js

Package Overview
Dependencies
5
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.1.0 to 2.1.1

130

lib/osc.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = global || self, global.OSC = factory());
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.OSC = factory());
}(this, (function () { 'use strict';

@@ -109,2 +109,15 @@

function _isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
return true;
} catch (e) {
return false;
}
}
function _assertThisInitialized(self) {

@@ -126,2 +139,21 @@ if (self === void 0) {

function _createSuper(Derived) {
var hasNativeReflectConstruct = _isNativeReflectConstruct();
return function _createSuperInternal() {
var Super = _getPrototypeOf(Derived),
result;
if (hasNativeReflectConstruct) {
var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possibleConstructorReturn(this, result);
};
}
function _superPropBase(object, property) {

@@ -244,4 +276,3 @@ while (!Object.prototype.hasOwnProperty.call(object, property)) {

}
var EncodeHelper =
function () {
var EncodeHelper = function () {
function EncodeHelper() {

@@ -275,4 +306,3 @@ _classCallCheck(this, EncodeHelper);

var Atomic =
function () {
var Atomic = function () {
function Atomic(value) {

@@ -315,5 +345,5 @@ _classCallCheck(this, Atomic);

var AtomicInt32 =
function (_Atomic) {
var AtomicInt32 = function (_Atomic) {
_inherits(AtomicInt32, _Atomic);
var _super = _createSuper(AtomicInt32);
function AtomicInt32(value) {

@@ -324,3 +354,3 @@ _classCallCheck(this, AtomicInt32);

}
return _possibleConstructorReturn(this, _getPrototypeOf(AtomicInt32).call(this, value));
return _super.call(this, value);
}

@@ -357,5 +387,5 @@ _createClass(AtomicInt32, [{

}
var AtomicString =
function (_Atomic) {
var AtomicString = function (_Atomic) {
_inherits(AtomicString, _Atomic);
var _super = _createSuper(AtomicString);
function AtomicString(value) {

@@ -366,3 +396,3 @@ _classCallCheck(this, AtomicString);

}
return _possibleConstructorReturn(this, _getPrototypeOf(AtomicString).call(this, value));
return _super.call(this, value);
}

@@ -415,4 +445,3 @@ _createClass(AtomicString, [{

var TWO_POWER_32 = 4294967296;
var Timetag =
function () {
var Timetag = function () {
function Timetag() {

@@ -445,5 +474,5 @@ var seconds = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;

}();
var AtomicTimetag =
function (_Atomic) {
var AtomicTimetag = function (_Atomic) {
_inherits(AtomicTimetag, _Atomic);
var _super = _createSuper(AtomicTimetag);
function AtomicTimetag() {

@@ -460,3 +489,3 @@ var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : Date.now();

}
return _possibleConstructorReturn(this, _getPrototypeOf(AtomicTimetag).call(this, timetag));
return _super.call(this, timetag);
}

@@ -495,5 +524,5 @@ _createClass(AtomicTimetag, [{

var AtomicBlob =
function (_Atomic) {
var AtomicBlob = function (_Atomic) {
_inherits(AtomicBlob, _Atomic);
var _super = _createSuper(AtomicBlob);
function AtomicBlob(value) {

@@ -504,3 +533,3 @@ _classCallCheck(this, AtomicBlob);

}
return _possibleConstructorReturn(this, _getPrototypeOf(AtomicBlob).call(this, value));
return _super.call(this, value);
}

@@ -536,5 +565,5 @@ _createClass(AtomicBlob, [{

var AtomicFloat32 =
function (_Atomic) {
var AtomicFloat32 = function (_Atomic) {
_inherits(AtomicFloat32, _Atomic);
var _super = _createSuper(AtomicFloat32);
function AtomicFloat32(value) {

@@ -545,3 +574,3 @@ _classCallCheck(this, AtomicFloat32);

}
return _possibleConstructorReturn(this, _getPrototypeOf(AtomicFloat32).call(this, value));
return _super.call(this, value);
}

@@ -563,4 +592,3 @@ _createClass(AtomicFloat32, [{

var Message =
function () {
var Message = function () {
function Message() {

@@ -671,4 +699,3 @@ _classCallCheck(this, Message);

var BUNDLE_TAG = '#bundle';
var Bundle =
function () {
var Bundle = function () {
function Bundle() {

@@ -768,4 +795,3 @@ var _this = this;

var Packet =
function () {
var Packet = function () {
function Packet(value) {

@@ -817,7 +843,6 @@ _classCallCheck(this, Packet);

};
var EventHandler =
function () {
var EventHandler = function () {
function EventHandler(options) {
_classCallCheck(this, EventHandler);
this.options = _objectSpread2({}, defaultOptions, {}, options);
this.options = _objectSpread2(_objectSpread2({}, defaultOptions), options);
this.addressHandlers = [];

@@ -1030,9 +1055,8 @@ this.eventHandlers = {

function mergeOptions(base, custom) {
return _objectSpread2({}, defaultOptions$1, {}, base, {}, custom, {
open: _objectSpread2({}, defaultOptions$1.open, {}, base.open, {}, custom.open),
send: _objectSpread2({}, defaultOptions$1.send, {}, base.send, {}, custom.send)
return _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, defaultOptions$1), base), custom), {}, {
open: _objectSpread2(_objectSpread2(_objectSpread2({}, defaultOptions$1.open), base.open), custom.open),
send: _objectSpread2(_objectSpread2(_objectSpread2({}, defaultOptions$1.send), base.send), custom.send)
});
}
var DatagramPlugin =
function () {
var DatagramPlugin = function () {
function DatagramPlugin() {

@@ -1071,3 +1095,3 @@ var _this = this;

var customOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var options = _objectSpread2({}, this.options.open, {}, customOptions);
var options = _objectSpread2(_objectSpread2({}, this.options.open), customOptions);
var port = options.port,

@@ -1099,3 +1123,3 @@ exclusive = options.exclusive;

var customOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var options = _objectSpread2({}, this.options.send, {}, customOptions);
var options = _objectSpread2(_objectSpread2({}, this.options.send), customOptions);
var port = options.port,

@@ -1135,10 +1159,9 @@ host = options.host;

function mergeOptions$1(base, custom) {
return _objectSpread2({}, defaultOptions$2, {}, base, {}, custom, {
udpServer: _objectSpread2({}, defaultOptions$2.udpServer, {}, base.udpServer, {}, custom.udpServer),
udpClient: _objectSpread2({}, defaultOptions$2.udpClient, {}, base.udpClient, {}, custom.udpClient),
wsServer: _objectSpread2({}, defaultOptions$2.wsServer, {}, base.wsServer, {}, custom.wsServer)
return _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, defaultOptions$2), base), custom), {}, {
udpServer: _objectSpread2(_objectSpread2(_objectSpread2({}, defaultOptions$2.udpServer), base.udpServer), custom.udpServer),
udpClient: _objectSpread2(_objectSpread2(_objectSpread2({}, defaultOptions$2.udpClient), base.udpClient), custom.udpClient),
wsServer: _objectSpread2(_objectSpread2(_objectSpread2({}, defaultOptions$2.wsServer), base.wsServer), custom.wsServer)
});
}
var BridgePlugin =
function () {
var BridgePlugin = function () {
function BridgePlugin() {

@@ -1259,4 +1282,3 @@ var _this = this;

};
var WebsocketClientPlugin =
function () {
var WebsocketClientPlugin = function () {
function WebsocketClientPlugin(customOptions) {

@@ -1267,3 +1289,3 @@ _classCallCheck(this, WebsocketClientPlugin);

}
this.options = _objectSpread2({}, defaultOptions$3, {}, customOptions);
this.options = _objectSpread2(_objectSpread2({}, defaultOptions$3), customOptions);
this.socket = null;

@@ -1288,3 +1310,3 @@ this.socketStatus = STATUS$2.IS_NOT_INITIALIZED;

var customOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var options = _objectSpread2({}, this.options, {}, customOptions);
var options = _objectSpread2(_objectSpread2({}, this.options), customOptions);
var port = options.port,

@@ -1348,4 +1370,3 @@ host = options.host,

};
var WebsocketServerPlugin =
function () {
var WebsocketServerPlugin = function () {
function WebsocketServerPlugin(customOptions) {

@@ -1356,3 +1377,3 @@ _classCallCheck(this, WebsocketServerPlugin);

}
this.options = _objectSpread2({}, defaultOptions$4, {}, customOptions);
this.options = _objectSpread2(_objectSpread2({}, defaultOptions$4), customOptions);
this.socket = null;

@@ -1377,3 +1398,3 @@ this.socketStatus = STATUS$3.IS_NOT_INITIALIZED;

var customOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var options = _objectSpread2({}, this.options, {}, customOptions);
var options = _objectSpread2(_objectSpread2({}, this.options), customOptions);
var port = options.port,

@@ -1443,4 +1464,3 @@ host = options.host;

};
var OSC =
function () {
var OSC = function () {
function OSC(options) {

@@ -1451,3 +1471,3 @@ _classCallCheck(this, OSC);

}
this.options = _objectSpread2({}, defaultOptions$5, {}, options);
this.options = _objectSpread2(_objectSpread2({}, defaultOptions$5), options);
this.eventHandler = new EventHandler({

@@ -1454,0 +1474,0 @@ discardLateMessages: this.options.discardLateMessages

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

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

@@ -38,6 +38,6 @@ "main": "lib/osc.js",

"devDependencies": {
"@babel/core": "7.7.4",
"@babel/preset-env": "7.7.4",
"@babel/register": "7.7.4",
"babel-eslint": "10.0.3",
"@babel/core": "7.12.10",
"@babel/preset-env": "7.12.11",
"@babel/register": "7.12.10",
"babel-eslint": "10.1.0",
"chai": "4.2.0",

@@ -47,15 +47,15 @@ "chai-spies-next": "0.9.3",

"esdoc-standard-plugin": "1.0.0",
"eslint": "6.7.1",
"eslint-config-airbnb-base": "14.0.0",
"eslint-plugin-import": "2.18.2",
"mocha": "6.2.2",
"rollup": "1.27.5",
"eslint": "7.17.0",
"eslint-config-airbnb-base": "14.2.1",
"eslint-plugin-import": "2.22.1",
"mocha": "8.2.1",
"rollup": "2.35.1",
"rollup-plugin-babel": "4.3.3",
"rollup-plugin-cleanup": "3.1.1",
"rollup-plugin-uglify": "6.0.3"
"rollup-plugin-cleanup": "3.2.1",
"rollup-plugin-terser": "7.0.2"
},
"dependencies": {
"isomorphic-ws": "4.0.1",
"ws": "7.2.0"
"ws": "7.4.2"
}
}

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