osc-browser.min.js 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893
  1. /*! osc.js 2.4.1, Copyright 2020 Colin Clark | github.com/colinbdclark/osc.js */
  2. var osc = osc || {};
  3. !function() {
  4. "use strict";
  5. osc.SECS_70YRS = 2208988800, osc.TWO_32 = 4294967296, osc.defaults = {
  6. metadata: !1,
  7. unpackSingleArgs: !0
  8. }, osc.isCommonJS = !("undefined" == typeof module || !module.exports), osc.isNode = osc.isCommonJS && "undefined" == typeof window,
  9. osc.isElectron = !("undefined" == typeof process || !process.versions || !process.versions.electron),
  10. osc.isBufferEnv = osc.isNode || osc.isElectron, osc.isArray = function(e) {
  11. return e && "[object Array]" === Object.prototype.toString.call(e);
  12. }, osc.isTypedArrayView = function(e) {
  13. return e.buffer && e.buffer instanceof ArrayBuffer;
  14. }, osc.isBuffer = function(e) {
  15. return osc.isBufferEnv && e instanceof Buffer;
  16. }, osc.Long = "undefined" != typeof Long ? Long : osc.isNode ? require("long") : void 0,
  17. osc.TextDecoder = "undefined" != typeof TextDecoder ? new TextDecoder("utf-8") : "undefined" != typeof util && (util.TextDecoder,
  18. 1) ? new util.TextDecoder("utf-8") : void 0, osc.TextEncoder = "undefined" != typeof TextEncoder ? new TextEncoder("utf-8") : "undefined" != typeof util && (util.TextEncoder,
  19. 1) ? new util.TextEncoder("utf-8") : void 0, osc.dataView = function(e, t, r) {
  20. return e.buffer ? new DataView(e.buffer, t, r) : e instanceof ArrayBuffer ? new DataView(e, t, r) : new DataView(new Uint8Array(e), t, r);
  21. }, osc.byteArray = function(e) {
  22. if (e instanceof Uint8Array) return e;
  23. var t = e.buffer ? e.buffer : e;
  24. if (!(t instanceof ArrayBuffer || void 0 !== t.length && "string" != typeof t)) throw new Error("Can't wrap a non-array-like object as Uint8Array. Object was: " + JSON.stringify(e, null, 2));
  25. return new Uint8Array(t);
  26. }, osc.nativeBuffer = function(e) {
  27. return osc.isBufferEnv ? osc.isBuffer(e) ? e : Buffer.from(e.buffer ? e : new Uint8Array(e)) : osc.isTypedArrayView(e) ? e : new Uint8Array(e);
  28. }, osc.copyByteArray = function(e, t, r) {
  29. if (osc.isTypedArrayView(e) && osc.isTypedArrayView(t)) t.set(e, r); else for (var n = void 0 === r ? 0 : r, i = Math.min(t.length - r, e.length), s = 0, o = n; s < i; s++,
  30. o++) t[o] = e[s];
  31. return t;
  32. }, osc.readString = function(e, t) {
  33. for (var r = [], n = t.idx; n < e.byteLength; n++) {
  34. var i = e.getUint8(n);
  35. if (0 === i) {
  36. n++;
  37. break;
  38. }
  39. r.push(i);
  40. }
  41. return n = n + 3 & -4, t.idx = n, (osc.isBufferEnv ? osc.readString.withBuffer : osc.TextDecoder ? osc.readString.withTextDecoder : osc.readString.raw)(r);
  42. }, osc.readString.raw = function(e) {
  43. for (var t = "", r = 0; r < e.length; r += 1e4) t += String.fromCharCode.apply(null, e.slice(r, r + 1e4));
  44. return t;
  45. }, osc.readString.withTextDecoder = function(e) {
  46. var t = new Int8Array(e);
  47. return osc.TextDecoder.decode(t);
  48. }, osc.readString.withBuffer = function(e) {
  49. return Buffer.from(e).toString("utf-8");
  50. }, osc.writeString = function(e) {
  51. var t, r = e + "\0", n = r.length, i = new Uint8Array(n + 3 & -4), s = osc.isBufferEnv ? osc.writeString.withBuffer : osc.TextEncoder ? osc.writeString.withTextEncoder : null;
  52. s && (t = s(r));
  53. for (var o = 0; o < r.length; o++) {
  54. var a = s ? t[o] : r.charCodeAt(o);
  55. i[o] = a;
  56. }
  57. return i;
  58. }, osc.writeString.withTextEncoder = function(e) {
  59. return osc.TextEncoder.encode(e);
  60. }, osc.writeString.withBuffer = function(e) {
  61. return Buffer.from(e);
  62. }, osc.readPrimitive = function(e, t, r, n) {
  63. var i = e[t](n.idx, !1);
  64. return n.idx += r, i;
  65. }, osc.writePrimitive = function(e, t, r, n, i) {
  66. var s;
  67. return i = void 0 === i ? 0 : i, t ? s = new Uint8Array(t.buffer) : (s = new Uint8Array(n),
  68. t = new DataView(s.buffer)), t[r](i, e, !1), s;
  69. }, osc.readInt32 = function(e, t) {
  70. return osc.readPrimitive(e, "getInt32", 4, t);
  71. }, osc.writeInt32 = function(e, t, r) {
  72. return osc.writePrimitive(e, t, "setInt32", 4, r);
  73. }, osc.readInt64 = function(e, t) {
  74. var r = osc.readPrimitive(e, "getInt32", 4, t), n = osc.readPrimitive(e, "getInt32", 4, t);
  75. return osc.Long ? new osc.Long(n, r) : {
  76. high: r,
  77. low: n,
  78. unsigned: !1
  79. };
  80. }, osc.writeInt64 = function(e, t, r) {
  81. var n = new Uint8Array(8);
  82. return n.set(osc.writePrimitive(e.high, t, "setInt32", 4, r), 0), n.set(osc.writePrimitive(e.low, t, "setInt32", 4, r + 4), 4),
  83. n;
  84. }, osc.readFloat32 = function(e, t) {
  85. return osc.readPrimitive(e, "getFloat32", 4, t);
  86. }, osc.writeFloat32 = function(e, t, r) {
  87. return osc.writePrimitive(e, t, "setFloat32", 4, r);
  88. }, osc.readFloat64 = function(e, t) {
  89. return osc.readPrimitive(e, "getFloat64", 8, t);
  90. }, osc.writeFloat64 = function(e, t, r) {
  91. return osc.writePrimitive(e, t, "setFloat64", 8, r);
  92. }, osc.readChar32 = function(e, t) {
  93. var r = osc.readPrimitive(e, "getUint32", 4, t);
  94. return String.fromCharCode(r);
  95. }, osc.writeChar32 = function(e, t, r) {
  96. var n = e.charCodeAt(0);
  97. if (!(void 0 === n || n < -1)) return osc.writePrimitive(n, t, "setUint32", 4, r);
  98. }, osc.readBlob = function(e, t) {
  99. var r = osc.readInt32(e, t), n = r + 3 & -4, i = new Uint8Array(e.buffer, t.idx, r);
  100. return t.idx += n, i;
  101. }, osc.writeBlob = function(e) {
  102. var t = (e = osc.byteArray(e)).byteLength, r = new Uint8Array(4 + (t + 3 & -4)), n = new DataView(r.buffer);
  103. return osc.writeInt32(t, n), r.set(e, 4), r;
  104. }, osc.readMIDIBytes = function(e, t) {
  105. var r = new Uint8Array(e.buffer, t.idx, 4);
  106. return t.idx += 4, r;
  107. }, osc.writeMIDIBytes = function(e) {
  108. e = osc.byteArray(e);
  109. var t = new Uint8Array(4);
  110. return t.set(e), t;
  111. }, osc.readColor = function(e, t) {
  112. var r = new Uint8Array(e.buffer, t.idx, 4), n = r[3] / 255;
  113. return t.idx += 4, {
  114. r: r[0],
  115. g: r[1],
  116. b: r[2],
  117. a: n
  118. };
  119. }, osc.writeColor = function(e) {
  120. var t = Math.round(255 * e.a);
  121. return new Uint8Array([ e.r, e.g, e.b, t ]);
  122. }, osc.readTrue = function() {
  123. return !0;
  124. }, osc.readFalse = function() {
  125. return !1;
  126. }, osc.readNull = function() {
  127. return null;
  128. }, osc.readImpulse = function() {
  129. return 1;
  130. }, osc.readTimeTag = function(e, t) {
  131. var r = osc.readPrimitive(e, "getUint32", 4, t), n = osc.readPrimitive(e, "getUint32", 4, t);
  132. return {
  133. raw: [ r, n ],
  134. native: 0 === r && 1 === n ? Date.now() : osc.ntpToJSTime(r, n)
  135. };
  136. }, osc.writeTimeTag = function(e) {
  137. var t = e.raw ? e.raw : osc.jsToNTPTime(e.native), r = new Uint8Array(8), n = new DataView(r.buffer);
  138. return osc.writeInt32(t[0], n, 0), osc.writeInt32(t[1], n, 4), r;
  139. }, osc.timeTag = function(e, t) {
  140. e = e || 0;
  141. var r = (t = t || Date.now()) / 1e3, n = Math.floor(r), i = r - n, s = Math.floor(e), o = i + (e - s);
  142. if (1 < o) {
  143. var a = Math.floor(o);
  144. s += a, o = o - a;
  145. }
  146. return {
  147. raw: [ n + s + osc.SECS_70YRS, Math.round(osc.TWO_32 * o) ]
  148. };
  149. }, osc.ntpToJSTime = function(e, t) {
  150. return 1e3 * (e - osc.SECS_70YRS + t / osc.TWO_32);
  151. }, osc.jsToNTPTime = function(e) {
  152. var t = e / 1e3, r = Math.floor(t), n = t - r;
  153. return [ r + osc.SECS_70YRS, Math.round(osc.TWO_32 * n) ];
  154. }, osc.readArguments = function(e, t, r) {
  155. var n = osc.readString(e, r);
  156. if (0 !== n.indexOf(",")) throw new Error("A malformed type tag string was found while reading the arguments of an OSC message. String was: " + n, " at offset: " + r.idx);
  157. var i = n.substring(1).split(""), s = [];
  158. return osc.readArgumentsIntoArray(s, i, n, e, t, r), s;
  159. }, osc.readArgument = function(e, t, r, n, i) {
  160. var s = osc.argumentTypes[e];
  161. if (!s) throw new Error("'" + e + "' is not a valid OSC type tag. Type tag string was: " + t);
  162. var o = s.reader, a = osc[o](r, i);
  163. return n.metadata && (a = {
  164. type: e,
  165. value: a
  166. }), a;
  167. }, osc.readArgumentsIntoArray = function(e, t, r, n, i, s) {
  168. for (var o = 0; o < t.length; ) {
  169. var a, u = t[o];
  170. if ("[" === u) {
  171. var c = t.slice(o + 1), f = c.indexOf("]");
  172. if (f < 0) throw new Error("Invalid argument type tag: an open array type tag ('[') was found without a matching close array tag ('[]'). Type tag was: " + r);
  173. var h = c.slice(0, f);
  174. a = osc.readArgumentsIntoArray([], h, r, n, i, s), o += f + 2;
  175. } else a = osc.readArgument(u, r, n, i, s), o++;
  176. e.push(a);
  177. }
  178. return e;
  179. }, osc.writeArguments = function(e, t) {
  180. var r = osc.collectArguments(e, t);
  181. return osc.joinParts(r);
  182. }, osc.joinParts = function(e) {
  183. for (var t = new Uint8Array(e.byteLength), r = e.parts, n = 0, i = 0; i < r.length; i++) {
  184. var s = r[i];
  185. osc.copyByteArray(s, t, n), n += s.length;
  186. }
  187. return t;
  188. }, osc.addDataPart = function(e, t) {
  189. t.parts.push(e), t.byteLength += e.length;
  190. }, osc.writeArrayArguments = function(e, t) {
  191. for (var r = "[", n = 0; n < e.length; n++) {
  192. var i = e[n];
  193. r += osc.writeArgument(i, t);
  194. }
  195. return r += "]";
  196. }, osc.writeArgument = function(e, t) {
  197. if (osc.isArray(e)) return osc.writeArrayArguments(e, t);
  198. var r = e.type, n = osc.argumentTypes[r].writer;
  199. if (n) {
  200. var i = osc[n](e.value);
  201. osc.addDataPart(i, t);
  202. }
  203. return e.type;
  204. }, osc.collectArguments = function(e, t, r) {
  205. osc.isArray(e) || (e = void 0 === e ? [] : [ e ]), r = r || {
  206. byteLength: 0,
  207. parts: []
  208. }, t.metadata || (e = osc.annotateArguments(e));
  209. for (var n = ",", i = r.parts.length, s = 0; s < e.length; s++) {
  210. var o = e[s];
  211. n += osc.writeArgument(o, r);
  212. }
  213. var a = osc.writeString(n);
  214. return r.byteLength += a.byteLength, r.parts.splice(i, 0, a), r;
  215. }, osc.readMessage = function(e, t, r) {
  216. t = t || osc.defaults;
  217. var n = osc.dataView(e, e.byteOffset, e.byteLength);
  218. r = r || {
  219. idx: 0
  220. };
  221. var i = osc.readString(n, r);
  222. return osc.readMessageContents(i, n, t, r);
  223. }, osc.readMessageContents = function(e, t, r, n) {
  224. if (0 !== e.indexOf("/")) throw new Error("A malformed OSC address was found while reading an OSC message. String was: " + e);
  225. var i = osc.readArguments(t, r, n);
  226. return {
  227. address: e,
  228. args: 1 === i.length && r.unpackSingleArgs ? i[0] : i
  229. };
  230. }, osc.collectMessageParts = function(e, t, r) {
  231. return r = r || {
  232. byteLength: 0,
  233. parts: []
  234. }, osc.addDataPart(osc.writeString(e.address), r), osc.collectArguments(e.args, t, r);
  235. }, osc.writeMessage = function(e, t) {
  236. if (t = t || osc.defaults, !osc.isValidMessage(e)) throw new Error("An OSC message must contain a valid address. Message was: " + JSON.stringify(e, null, 2));
  237. var r = osc.collectMessageParts(e, t);
  238. return osc.joinParts(r);
  239. }, osc.isValidMessage = function(e) {
  240. return e.address && 0 === e.address.indexOf("/");
  241. }, osc.readBundle = function(e, t, r) {
  242. return osc.readPacket(e, t, r);
  243. }, osc.collectBundlePackets = function(e, t, r) {
  244. r = r || {
  245. byteLength: 0,
  246. parts: []
  247. }, osc.addDataPart(osc.writeString("#bundle"), r), osc.addDataPart(osc.writeTimeTag(e.timeTag), r);
  248. for (var n = 0; n < e.packets.length; n++) {
  249. var i = e.packets[n], s = (i.address ? osc.collectMessageParts : osc.collectBundlePackets)(i, t);
  250. r.byteLength += s.byteLength, osc.addDataPart(osc.writeInt32(s.byteLength), r),
  251. r.parts = r.parts.concat(s.parts);
  252. }
  253. return r;
  254. }, osc.writeBundle = function(e, t) {
  255. if (!osc.isValidBundle(e)) throw new Error("An OSC bundle must contain 'timeTag' and 'packets' properties. Bundle was: " + JSON.stringify(e, null, 2));
  256. t = t || osc.defaults;
  257. var r = osc.collectBundlePackets(e, t);
  258. return osc.joinParts(r);
  259. }, osc.isValidBundle = function(e) {
  260. return void 0 !== e.timeTag && void 0 !== e.packets;
  261. }, osc.readBundleContents = function(e, t, r, n) {
  262. for (var i = osc.readTimeTag(e, r), s = []; r.idx < n; ) {
  263. var o = osc.readInt32(e, r), a = r.idx + o, u = osc.readPacket(e, t, r, a);
  264. s.push(u);
  265. }
  266. return {
  267. timeTag: i,
  268. packets: s
  269. };
  270. }, osc.readPacket = function(e, t, r, n) {
  271. var i = osc.dataView(e, e.byteOffset, e.byteLength);
  272. n = void 0 === n ? i.byteLength : n, r = r || {
  273. idx: 0
  274. };
  275. var s = osc.readString(i, r), o = s[0];
  276. if ("#" === o) return osc.readBundleContents(i, t, r, n);
  277. if ("/" === o) return osc.readMessageContents(s, i, t, r);
  278. throw new Error("The header of an OSC packet didn't contain an OSC address or a #bundle string. Header was: " + s);
  279. }, osc.writePacket = function(e, t) {
  280. if (osc.isValidMessage(e)) return osc.writeMessage(e, t);
  281. if (osc.isValidBundle(e)) return osc.writeBundle(e, t);
  282. throw new Error("The specified packet was not recognized as a valid OSC message or bundle. Packet was: " + JSON.stringify(e, null, 2));
  283. }, osc.argumentTypes = {
  284. i: {
  285. reader: "readInt32",
  286. writer: "writeInt32"
  287. },
  288. h: {
  289. reader: "readInt64",
  290. writer: "writeInt64"
  291. },
  292. f: {
  293. reader: "readFloat32",
  294. writer: "writeFloat32"
  295. },
  296. s: {
  297. reader: "readString",
  298. writer: "writeString"
  299. },
  300. S: {
  301. reader: "readString",
  302. writer: "writeString"
  303. },
  304. b: {
  305. reader: "readBlob",
  306. writer: "writeBlob"
  307. },
  308. t: {
  309. reader: "readTimeTag",
  310. writer: "writeTimeTag"
  311. },
  312. T: {
  313. reader: "readTrue"
  314. },
  315. F: {
  316. reader: "readFalse"
  317. },
  318. N: {
  319. reader: "readNull"
  320. },
  321. I: {
  322. reader: "readImpulse"
  323. },
  324. d: {
  325. reader: "readFloat64",
  326. writer: "writeFloat64"
  327. },
  328. c: {
  329. reader: "readChar32",
  330. writer: "writeChar32"
  331. },
  332. r: {
  333. reader: "readColor",
  334. writer: "writeColor"
  335. },
  336. m: {
  337. reader: "readMIDIBytes",
  338. writer: "writeMIDIBytes"
  339. }
  340. }, osc.inferTypeForArgument = function(e) {
  341. switch (typeof e) {
  342. case "boolean":
  343. return e ? "T" : "F";
  344. case "string":
  345. return "s";
  346. case "number":
  347. return "f";
  348. case "undefined":
  349. return "N";
  350. case "object":
  351. if (null === e) return "N";
  352. if (e instanceof Uint8Array || e instanceof ArrayBuffer) return "b";
  353. if ("number" == typeof e.high && "number" == typeof e.low) return "h";
  354. }
  355. throw new Error("Can't infer OSC argument type for value: " + JSON.stringify(e, null, 2));
  356. }, osc.annotateArguments = function(e) {
  357. for (var t = [], r = 0; r < e.length; r++) {
  358. var n, i = e[r];
  359. if ("object" == typeof i && i.type && void 0 !== i.value) n = i; else if (osc.isArray(i)) n = osc.annotateArguments(i); else {
  360. n = {
  361. type: osc.inferTypeForArgument(i),
  362. value: i
  363. };
  364. }
  365. t.push(n);
  366. }
  367. return t;
  368. }, osc.isCommonJS && (module.exports = osc);
  369. }(), function(e, t) {
  370. "object" == typeof exports && "object" == typeof module ? module.exports = t() : "function" == typeof define && define.amd ? define([], t) : "object" == typeof exports ? exports.Long = t() : e.Long = t();
  371. }("undefined" != typeof self ? self : this, function() {
  372. return i = {}, n.m = r = [ function(e, t) {
  373. function n(e, t, r) {
  374. this.low = 0 | e, this.high = 0 | t, this.unsigned = !!r;
  375. }
  376. function g(e) {
  377. return !0 === (e && e.__isLong__);
  378. }
  379. function r(e, t) {
  380. var r, n, i;
  381. return t ? (i = 0 <= (e >>>= 0) && e < 256) && (n = o[e]) ? n : (r = p(e, (0 | e) < 0 ? -1 : 0, !0),
  382. i && (o[e] = r), r) : (i = -128 <= (e |= 0) && e < 128) && (n = s[e]) ? n : (r = p(e, e < 0 ? -1 : 0, !1),
  383. i && (s[e] = r), r);
  384. }
  385. function l(e, t) {
  386. if (isNaN(e)) return t ? c : m;
  387. if (t) {
  388. if (e < 0) return c;
  389. if (a <= e) return A;
  390. } else {
  391. if (e <= -u) return B;
  392. if (u <= e + 1) return S;
  393. }
  394. return e < 0 ? l(-e, t).neg() : p(e % i | 0, e / i | 0, t);
  395. }
  396. function p(e, t, r) {
  397. return new n(e, t, r);
  398. }
  399. function f(e, t, r) {
  400. if (0 === e.length) throw Error("empty string");
  401. if ("NaN" === e || "Infinity" === e || "+Infinity" === e || "-Infinity" === e) return m;
  402. if (t = "number" == typeof t ? (r = t, !1) : !!t, (r = r || 10) < 2 || 36 < r) throw RangeError("radix");
  403. var n;
  404. if (0 < (n = e.indexOf("-"))) throw Error("interior hyphen");
  405. if (0 === n) return f(e.substring(1), t, r).neg();
  406. for (var i = l(h(r, 8)), s = m, o = 0; o < e.length; o += 8) {
  407. var a = Math.min(8, e.length - o), u = parseInt(e.substring(o, o + a), r);
  408. if (a < 8) {
  409. var c = l(h(r, a));
  410. s = s.mul(c).add(l(u));
  411. } else s = (s = s.mul(i)).add(l(u));
  412. }
  413. return s.unsigned = t, s;
  414. }
  415. function w(e, t) {
  416. return "number" == typeof e ? l(e, t) : "string" == typeof e ? f(e, t) : p(e.low, e.high, "boolean" == typeof t ? t : e.unsigned);
  417. }
  418. e.exports = n;
  419. var v = null;
  420. try {
  421. v = new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([ 0, 97, 115, 109, 1, 0, 0, 0, 1, 13, 2, 96, 0, 1, 127, 96, 4, 127, 127, 127, 127, 1, 127, 3, 7, 6, 0, 1, 1, 1, 1, 1, 6, 6, 1, 127, 1, 65, 0, 11, 7, 50, 6, 3, 109, 117, 108, 0, 1, 5, 100, 105, 118, 95, 115, 0, 2, 5, 100, 105, 118, 95, 117, 0, 3, 5, 114, 101, 109, 95, 115, 0, 4, 5, 114, 101, 109, 95, 117, 0, 5, 8, 103, 101, 116, 95, 104, 105, 103, 104, 0, 0, 10, 191, 1, 6, 4, 0, 35, 0, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 126, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 127, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 128, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 129, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 130, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11 ])), {}).exports;
  422. } catch (e) {}
  423. Object.defineProperty(n.prototype, "__isLong__", {
  424. value: !0
  425. }), n.isLong = g;
  426. var s = {}, o = {};
  427. n.fromInt = r, n.fromNumber = l, n.fromBits = p;
  428. var h = Math.pow;
  429. n.fromString = f, n.fromValue = w;
  430. var i = 4294967296, a = i * i, u = a / 2, y = r(1 << 24), m = r(0);
  431. n.ZERO = m;
  432. var c = r(0, !0);
  433. n.UZERO = c;
  434. var d = r(1);
  435. n.ONE = d;
  436. var b = r(1, !0);
  437. n.UONE = b;
  438. var E = r(-1);
  439. n.NEG_ONE = E;
  440. var S = p(-1, 2147483647, !1);
  441. n.MAX_VALUE = S;
  442. var A = p(-1, -1, !0);
  443. n.MAX_UNSIGNED_VALUE = A;
  444. var B = p(0, -2147483648, !1);
  445. n.MIN_VALUE = B;
  446. var P = n.prototype;
  447. P.toInt = function() {
  448. return this.unsigned ? this.low >>> 0 : this.low;
  449. }, P.toNumber = function() {
  450. return this.unsigned ? (this.high >>> 0) * i + (this.low >>> 0) : this.high * i + (this.low >>> 0);
  451. }, P.toString = function(e) {
  452. if ((e = e || 10) < 2 || 36 < e) throw RangeError("radix");
  453. if (this.isZero()) return "0";
  454. if (this.isNegative()) {
  455. if (this.eq(B)) {
  456. var t = l(e), r = this.div(t), n = r.mul(t).sub(this);
  457. return r.toString(e) + n.toInt().toString(e);
  458. }
  459. return "-" + this.neg().toString(e);
  460. }
  461. for (var i = l(h(e, 6), this.unsigned), s = this, o = ""; ;) {
  462. var a = s.div(i), u = (s.sub(a.mul(i)).toInt() >>> 0).toString(e);
  463. if ((s = a).isZero()) return u + o;
  464. for (;u.length < 6; ) u = "0" + u;
  465. o = "" + u + o;
  466. }
  467. }, P.getHighBits = function() {
  468. return this.high;
  469. }, P.getHighBitsUnsigned = function() {
  470. return this.high >>> 0;
  471. }, P.getLowBits = function() {
  472. return this.low;
  473. }, P.getLowBitsUnsigned = function() {
  474. return this.low >>> 0;
  475. }, P.getNumBitsAbs = function() {
  476. if (this.isNegative()) return this.eq(B) ? 64 : this.neg().getNumBitsAbs();
  477. for (var e = 0 != this.high ? this.high : this.low, t = 31; 0 < t && 0 == (e & 1 << t); t--) ;
  478. return 0 != this.high ? t + 33 : t + 1;
  479. }, P.isZero = function() {
  480. return 0 === this.high && 0 === this.low;
  481. }, P.eqz = P.isZero, P.isNegative = function() {
  482. return !this.unsigned && this.high < 0;
  483. }, P.isPositive = function() {
  484. return this.unsigned || 0 <= this.high;
  485. }, P.isOdd = function() {
  486. return 1 == (1 & this.low);
  487. }, P.isEven = function() {
  488. return 0 == (1 & this.low);
  489. }, P.equals = function(e) {
  490. return g(e) || (e = w(e)), (this.unsigned === e.unsigned || this.high >>> 31 != 1 || e.high >>> 31 != 1) && this.high === e.high && this.low === e.low;
  491. }, P.eq = P.equals, P.notEquals = function(e) {
  492. return !this.eq(e);
  493. }, P.neq = P.notEquals, P.ne = P.notEquals, P.lessThan = function(e) {
  494. return this.comp(e) < 0;
  495. }, P.lt = P.lessThan, P.lessThanOrEqual = function(e) {
  496. return this.comp(e) <= 0;
  497. }, P.lte = P.lessThanOrEqual, P.le = P.lessThanOrEqual, P.greaterThan = function(e) {
  498. return 0 < this.comp(e);
  499. }, P.gt = P.greaterThan, P.greaterThanOrEqual = function(e) {
  500. return 0 <= this.comp(e);
  501. }, P.gte = P.greaterThanOrEqual, P.ge = P.greaterThanOrEqual, P.compare = function(e) {
  502. if (g(e) || (e = w(e)), this.eq(e)) return 0;
  503. var t = this.isNegative(), r = e.isNegative();
  504. return t && !r ? -1 : !t && r ? 1 : this.unsigned ? e.high >>> 0 > this.high >>> 0 || e.high === this.high && e.low >>> 0 > this.low >>> 0 ? -1 : 1 : this.sub(e).isNegative() ? -1 : 1;
  505. }, P.comp = P.compare, P.negate = function() {
  506. return !this.unsigned && this.eq(B) ? B : this.not().add(d);
  507. }, P.neg = P.negate, P.add = function(e) {
  508. g(e) || (e = w(e));
  509. var t = this.high >>> 16, r = 65535 & this.high, n = this.low >>> 16, i = 65535 & this.low, s = e.high >>> 16, o = 65535 & e.high, a = e.low >>> 16, u = 0, c = 0, f = 0, h = 0;
  510. return f += (h += i + (65535 & e.low)) >>> 16, c += (f += n + a) >>> 16, u += (c += r + o) >>> 16,
  511. u += t + s, p((f &= 65535) << 16 | (h &= 65535), (u &= 65535) << 16 | (c &= 65535), this.unsigned);
  512. }, P.subtract = function(e) {
  513. return g(e) || (e = w(e)), this.add(e.neg());
  514. }, P.sub = P.subtract, P.multiply = function(e) {
  515. if (this.isZero()) return m;
  516. if (g(e) || (e = w(e)), v) return p(v.mul(this.low, this.high, e.low, e.high), v.get_high(), this.unsigned);
  517. if (e.isZero()) return m;
  518. if (this.eq(B)) return e.isOdd() ? B : m;
  519. if (e.eq(B)) return this.isOdd() ? B : m;
  520. if (this.isNegative()) return e.isNegative() ? this.neg().mul(e.neg()) : this.neg().mul(e).neg();
  521. if (e.isNegative()) return this.mul(e.neg()).neg();
  522. if (this.lt(y) && e.lt(y)) return l(this.toNumber() * e.toNumber(), this.unsigned);
  523. var t = this.high >>> 16, r = 65535 & this.high, n = this.low >>> 16, i = 65535 & this.low, s = e.high >>> 16, o = 65535 & e.high, a = e.low >>> 16, u = 65535 & e.low, c = 0, f = 0, h = 0, d = 0;
  524. return h += (d += i * u) >>> 16, f += (h += n * u) >>> 16, h &= 65535, f += (h += i * a) >>> 16,
  525. c += (f += r * u) >>> 16, f &= 65535, c += (f += n * a) >>> 16, f &= 65535, c += (f += i * o) >>> 16,
  526. c += t * u + r * a + n * o + i * s, p((h &= 65535) << 16 | (d &= 65535), (c &= 65535) << 16 | (f &= 65535), this.unsigned);
  527. }, P.mul = P.multiply, P.divide = function(e) {
  528. if (g(e) || (e = w(e)), e.isZero()) throw Error("division by zero");
  529. if (v) return this.unsigned || -2147483648 !== this.high || -1 !== e.low || -1 !== e.high ? p((this.unsigned ? v.div_u : v.div_s)(this.low, this.high, e.low, e.high), v.get_high(), this.unsigned) : this;
  530. if (this.isZero()) return this.unsigned ? c : m;
  531. var t, r, n;
  532. if (this.unsigned) {
  533. if (e.unsigned || (e = e.toUnsigned()), e.gt(this)) return c;
  534. if (e.gt(this.shru(1))) return b;
  535. n = c;
  536. } else {
  537. if (this.eq(B)) return e.eq(d) || e.eq(E) ? B : e.eq(B) ? d : (t = this.shr(1).div(e).shl(1)).eq(m) ? e.isNegative() ? d : E : (r = this.sub(e.mul(t)),
  538. n = t.add(r.div(e)));
  539. if (e.eq(B)) return this.unsigned ? c : m;
  540. if (this.isNegative()) return e.isNegative() ? this.neg().div(e.neg()) : this.neg().div(e).neg();
  541. if (e.isNegative()) return this.div(e.neg()).neg();
  542. n = m;
  543. }
  544. for (r = this; r.gte(e); ) {
  545. t = Math.max(1, Math.floor(r.toNumber() / e.toNumber()));
  546. for (var i = Math.ceil(Math.log(t) / Math.LN2), s = i <= 48 ? 1 : h(2, i - 48), o = l(t), a = o.mul(e); a.isNegative() || a.gt(r); ) a = (o = l(t -= s, this.unsigned)).mul(e);
  547. o.isZero() && (o = d), n = n.add(o), r = r.sub(a);
  548. }
  549. return n;
  550. }, P.div = P.divide, P.modulo = function(e) {
  551. return g(e) || (e = w(e)), v ? p((this.unsigned ? v.rem_u : v.rem_s)(this.low, this.high, e.low, e.high), v.get_high(), this.unsigned) : this.sub(this.div(e).mul(e));
  552. }, P.mod = P.modulo, P.rem = P.modulo, P.not = function() {
  553. return p(~this.low, ~this.high, this.unsigned);
  554. }, P.and = function(e) {
  555. return g(e) || (e = w(e)), p(this.low & e.low, this.high & e.high, this.unsigned);
  556. }, P.or = function(e) {
  557. return g(e) || (e = w(e)), p(this.low | e.low, this.high | e.high, this.unsigned);
  558. }, P.xor = function(e) {
  559. return g(e) || (e = w(e)), p(this.low ^ e.low, this.high ^ e.high, this.unsigned);
  560. }, P.shiftLeft = function(e) {
  561. return g(e) && (e = e.toInt()), 0 == (e &= 63) ? this : e < 32 ? p(this.low << e, this.high << e | this.low >>> 32 - e, this.unsigned) : p(0, this.low << e - 32, this.unsigned);
  562. }, P.shl = P.shiftLeft, P.shiftRight = function(e) {
  563. return g(e) && (e = e.toInt()), 0 == (e &= 63) ? this : e < 32 ? p(this.low >>> e | this.high << 32 - e, this.high >> e, this.unsigned) : p(this.high >> e - 32, 0 <= this.high ? 0 : -1, this.unsigned);
  564. }, P.shr = P.shiftRight, P.shiftRightUnsigned = function(e) {
  565. if (g(e) && (e = e.toInt()), 0 == (e &= 63)) return this;
  566. var t = this.high;
  567. return e < 32 ? p(this.low >>> e | t << 32 - e, t >>> e, this.unsigned) : p(32 === e ? t : t >>> e - 32, 0, this.unsigned);
  568. }, P.shru = P.shiftRightUnsigned, P.shr_u = P.shiftRightUnsigned, P.toSigned = function() {
  569. return this.unsigned ? p(this.low, this.high, !1) : this;
  570. }, P.toUnsigned = function() {
  571. return this.unsigned ? this : p(this.low, this.high, !0);
  572. }, P.toBytes = function(e) {
  573. return e ? this.toBytesLE() : this.toBytesBE();
  574. }, P.toBytesLE = function() {
  575. var e = this.high, t = this.low;
  576. return [ 255 & t, t >>> 8 & 255, t >>> 16 & 255, t >>> 24, 255 & e, e >>> 8 & 255, e >>> 16 & 255, e >>> 24 ];
  577. }, P.toBytesBE = function() {
  578. var e = this.high, t = this.low;
  579. return [ e >>> 24, e >>> 16 & 255, e >>> 8 & 255, 255 & e, t >>> 24, t >>> 16 & 255, t >>> 8 & 255, 255 & t ];
  580. }, n.fromBytes = function(e, t, r) {
  581. return r ? n.fromBytesLE(e, t) : n.fromBytesBE(e, t);
  582. }, n.fromBytesLE = function(e, t) {
  583. return new n(e[0] | e[1] << 8 | e[2] << 16 | e[3] << 24, e[4] | e[5] << 8 | e[6] << 16 | e[7] << 24, t);
  584. }, n.fromBytesBE = function(e, t) {
  585. return new n(e[4] << 24 | e[5] << 16 | e[6] << 8 | e[7], e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3], t);
  586. };
  587. } ], n.c = i, n.d = function(e, t, r) {
  588. n.o(e, t) || Object.defineProperty(e, t, {
  589. configurable: !1,
  590. enumerable: !0,
  591. get: r
  592. });
  593. }, n.n = function(e) {
  594. var t = e && e.__esModule ? function() {
  595. return e.default;
  596. } : function() {
  597. return e;
  598. };
  599. return n.d(t, "a", t), t;
  600. }, n.o = function(e, t) {
  601. return Object.prototype.hasOwnProperty.call(e, t);
  602. }, n.p = "", n(n.s = 0);
  603. function n(e) {
  604. if (i[e]) return i[e].exports;
  605. var t = i[e] = {
  606. i: e,
  607. l: !1,
  608. exports: {}
  609. };
  610. return r[e].call(t.exports, t, t.exports, n), t.l = !0, t.exports;
  611. }
  612. var r, i;
  613. }), function(t, r) {
  614. "use strict";
  615. "object" == typeof exports ? (t.slip = exports, r(exports)) : "function" == typeof define && define.amd ? define([ "exports" ], function(e) {
  616. return t.slip = e, t.slip, r(e);
  617. }) : (t.slip = {}, r(t.slip));
  618. }(this, function(e) {
  619. "use strict";
  620. var a = e;
  621. a.END = 192, a.ESC = 219, a.ESC_END = 220, a.ESC_ESC = 221, a.byteArray = function(e, t, r) {
  622. return e instanceof ArrayBuffer ? new Uint8Array(e, t, r) : e;
  623. }, a.expandByteArray = function(e) {
  624. var t = new Uint8Array(2 * e.length);
  625. return t.set(e), t;
  626. }, a.sliceByteArray = function(e, t, r) {
  627. var n = e.buffer.slice ? e.buffer.slice(t, r) : e.subarray(t, r);
  628. return new Uint8Array(n);
  629. }, a.encode = function(e, t) {
  630. (t = t || {}).bufferPadding = t.bufferPadding || 4;
  631. var r = (e = a.byteArray(e, t.offset, t.byteLength)).length + t.bufferPadding + 3 & -4, n = new Uint8Array(r), i = 1;
  632. n[0] = a.END;
  633. for (var s = 0; s < e.length; s++) {
  634. i > n.length - 3 && (n = a.expandByteArray(n));
  635. var o = e[s];
  636. o === a.END ? (n[i++] = a.ESC, o = a.ESC_END) : o === a.ESC && (n[i++] = a.ESC,
  637. o = a.ESC_ESC), n[i++] = o;
  638. }
  639. return n[i] = a.END, a.sliceByteArray(n, 0, i + 1);
  640. }, a.Decoder = function(e) {
  641. e = "function" != typeof e ? e || {} : {
  642. onMessage: e
  643. }, this.maxMessageSize = e.maxMessageSize || 10485760, this.bufferSize = e.bufferSize || 1024,
  644. this.msgBuffer = new Uint8Array(this.bufferSize), this.msgBufferIdx = 0, this.onMessage = e.onMessage,
  645. this.onError = e.onError, this.escape = !1;
  646. };
  647. var t = a.Decoder.prototype;
  648. return t.decode = function(e) {
  649. var t;
  650. e = a.byteArray(e);
  651. for (var r = 0; r < e.length; r++) {
  652. var n = e[r];
  653. if (this.escape) n === a.ESC_ESC ? n = a.ESC : n === a.ESC_END && (n = a.END); else {
  654. if (n === a.ESC) {
  655. this.escape = !0;
  656. continue;
  657. }
  658. if (n === a.END) {
  659. t = this.handleEnd();
  660. continue;
  661. }
  662. }
  663. this.addByte(n) || this.handleMessageMaxError();
  664. }
  665. return t;
  666. }, t.handleMessageMaxError = function() {
  667. this.onError && this.onError(this.msgBuffer.subarray(0), "The message is too large; the maximum message size is " + this.maxMessageSize / 1024 + "KB. Use a larger maxMessageSize if necessary."),
  668. this.msgBufferIdx = 0, this.escape = !1;
  669. }, t.addByte = function(e) {
  670. return this.msgBufferIdx > this.msgBuffer.length - 1 && (this.msgBuffer = a.expandByteArray(this.msgBuffer)),
  671. this.msgBuffer[this.msgBufferIdx++] = e, this.escape = !1, this.msgBuffer.length < this.maxMessageSize;
  672. }, t.handleEnd = function() {
  673. if (0 !== this.msgBufferIdx) {
  674. var e = a.sliceByteArray(this.msgBuffer, 0, this.msgBufferIdx);
  675. return this.onMessage && this.onMessage(e), this.msgBufferIdx = 0, e;
  676. }
  677. }, a;
  678. }), function(e) {
  679. "use strict";
  680. function t() {}
  681. var r = t.prototype, n = e.EventEmitter;
  682. function s(e, t) {
  683. for (var r = e.length; r--; ) if (e[r].listener === t) return r;
  684. return -1;
  685. }
  686. function i(e) {
  687. return function() {
  688. return this[e].apply(this, arguments);
  689. };
  690. }
  691. r.getListeners = function(e) {
  692. var t, r, n = this._getEvents();
  693. if (e instanceof RegExp) for (r in t = {}, n) n.hasOwnProperty(r) && e.test(r) && (t[r] = n[r]); else t = n[e] || (n[e] = []);
  694. return t;
  695. }, r.flattenListeners = function(e) {
  696. var t, r = [];
  697. for (t = 0; t < e.length; t += 1) r.push(e[t].listener);
  698. return r;
  699. }, r.getListenersAsObject = function(e) {
  700. var t, r = this.getListeners(e);
  701. return r instanceof Array && ((t = {})[e] = r), t || r;
  702. }, r.addListener = function(e, t) {
  703. if (!function e(t) {
  704. return "function" == typeof t || t instanceof RegExp || !(!t || "object" != typeof t) && e(t.listener);
  705. }(t)) throw new TypeError("listener must be a function");
  706. var r, n = this.getListenersAsObject(e), i = "object" == typeof t;
  707. for (r in n) n.hasOwnProperty(r) && -1 === s(n[r], t) && n[r].push(i ? t : {
  708. listener: t,
  709. once: !1
  710. });
  711. return this;
  712. }, r.on = i("addListener"), r.addOnceListener = function(e, t) {
  713. return this.addListener(e, {
  714. listener: t,
  715. once: !0
  716. });
  717. }, r.once = i("addOnceListener"), r.defineEvent = function(e) {
  718. return this.getListeners(e), this;
  719. }, r.defineEvents = function(e) {
  720. for (var t = 0; t < e.length; t += 1) this.defineEvent(e[t]);
  721. return this;
  722. }, r.removeListener = function(e, t) {
  723. var r, n, i = this.getListenersAsObject(e);
  724. for (n in i) i.hasOwnProperty(n) && -1 !== (r = s(i[n], t)) && i[n].splice(r, 1);
  725. return this;
  726. }, r.off = i("removeListener"), r.addListeners = function(e, t) {
  727. return this.manipulateListeners(!1, e, t);
  728. }, r.removeListeners = function(e, t) {
  729. return this.manipulateListeners(!0, e, t);
  730. }, r.manipulateListeners = function(e, t, r) {
  731. var n, i, s = e ? this.removeListener : this.addListener, o = e ? this.removeListeners : this.addListeners;
  732. if ("object" != typeof t || t instanceof RegExp) for (n = r.length; n--; ) s.call(this, t, r[n]); else for (n in t) t.hasOwnProperty(n) && (i = t[n]) && ("function" == typeof i ? s.call(this, n, i) : o.call(this, n, i));
  733. return this;
  734. }, r.removeEvent = function(e) {
  735. var t, r = typeof e, n = this._getEvents();
  736. if ("string" == r) delete n[e]; else if (e instanceof RegExp) for (t in n) n.hasOwnProperty(t) && e.test(t) && delete n[t]; else delete this._events;
  737. return this;
  738. }, r.removeAllListeners = i("removeEvent"), r.emitEvent = function(e, t) {
  739. var r, n, i, s, o = this.getListenersAsObject(e);
  740. for (s in o) if (o.hasOwnProperty(s)) for (r = o[s].slice(0), i = 0; i < r.length; i++) !0 === (n = r[i]).once && this.removeListener(e, n.listener),
  741. n.listener.apply(this, t || []) === this._getOnceReturnValue() && this.removeListener(e, n.listener);
  742. return this;
  743. }, r.trigger = i("emitEvent"), r.emit = function(e) {
  744. var t = Array.prototype.slice.call(arguments, 1);
  745. return this.emitEvent(e, t);
  746. }, r.setOnceReturnValue = function(e) {
  747. return this._onceReturnValue = e, this;
  748. }, r._getOnceReturnValue = function() {
  749. return !this.hasOwnProperty("_onceReturnValue") || this._onceReturnValue;
  750. }, r._getEvents = function() {
  751. return this._events || (this._events = {});
  752. }, t.noConflict = function() {
  753. return e.EventEmitter = n, t;
  754. }, "function" == typeof define && define.amd ? define(function() {
  755. return t;
  756. }) : "object" == typeof module && module.exports ? module.exports = t : e.EventEmitter = t;
  757. }("undefined" != typeof window ? window : this || {});
  758. osc = osc || require("./osc.js");
  759. var slip = slip || require("slip"), EventEmitter = EventEmitter || require("events").EventEmitter;
  760. !function() {
  761. "use strict";
  762. osc.supportsSerial = !1, osc.firePacketEvents = function(e, t, r, n) {
  763. t.address ? e.emit("message", t, r, n) : osc.fireBundleEvents(e, t, r, n);
  764. }, osc.fireBundleEvents = function(e, t, r, n) {
  765. e.emit("bundle", t, r, n);
  766. for (var i = 0; i < t.packets.length; i++) {
  767. var s = t.packets[i];
  768. osc.firePacketEvents(e, s, t.timeTag, n);
  769. }
  770. }, osc.fireClosedPortSendError = function(e, t) {
  771. t = t || "Can't send packets on a closed osc.Port object. Please open (or reopen) this Port by calling open().",
  772. e.emit("error", t);
  773. }, osc.Port = function(e) {
  774. this.options = e || {}, this.on("data", this.decodeOSC.bind(this));
  775. };
  776. var e = osc.Port.prototype = Object.create(EventEmitter.prototype);
  777. e.constructor = osc.Port, e.send = function(e) {
  778. var t = Array.prototype.slice.call(arguments), r = this.encodeOSC(e), n = osc.nativeBuffer(r);
  779. t[0] = n, this.sendRaw.apply(this, t);
  780. }, e.encodeOSC = function(e) {
  781. var t;
  782. e = e.buffer ? e.buffer : e;
  783. try {
  784. t = osc.writePacket(e, this.options);
  785. } catch (e) {
  786. this.emit("error", e);
  787. }
  788. return t;
  789. }, e.decodeOSC = function(e, t) {
  790. e = osc.byteArray(e), this.emit("raw", e, t);
  791. try {
  792. var r = osc.readPacket(e, this.options);
  793. this.emit("osc", r, t), osc.firePacketEvents(this, r, void 0, t);
  794. } catch (e) {
  795. this.emit("error", e);
  796. }
  797. }, osc.SLIPPort = function(e) {
  798. var t = this, r = this.options = e || {};
  799. r.useSLIP = void 0 === r.useSLIP || r.useSLIP, this.decoder = new slip.Decoder({
  800. onMessage: this.decodeOSC.bind(this),
  801. onError: function(e) {
  802. t.emit("error", e);
  803. }
  804. });
  805. var n = r.useSLIP ? this.decodeSLIPData : this.decodeOSC;
  806. this.on("data", n.bind(this));
  807. }, (e = osc.SLIPPort.prototype = Object.create(osc.Port.prototype)).constructor = osc.SLIPPort,
  808. e.encodeOSC = function(e) {
  809. var t;
  810. e = e.buffer ? e.buffer : e;
  811. try {
  812. var r = osc.writePacket(e, this.options);
  813. t = slip.encode(r);
  814. } catch (e) {
  815. this.emit("error", e);
  816. }
  817. return t;
  818. }, e.decodeSLIPData = function(e, t) {
  819. this.decoder.decode(e, t);
  820. }, osc.relay = function(e, t, r, n, i, s) {
  821. r = r || "message", n = n || "send", i = i || function() {}, s = s ? [ null ].concat(s) : [];
  822. function o(e) {
  823. s[0] = e, e = i(e), t[n].apply(t, s);
  824. }
  825. return e.on(r, o), {
  826. eventName: r,
  827. listener: o
  828. };
  829. }, osc.relayPorts = function(e, t, r) {
  830. var n = r.raw ? "raw" : "osc", i = r.raw ? "sendRaw" : "send";
  831. return osc.relay(e, t, n, i, r.transform);
  832. }, osc.stopRelaying = function(e, t) {
  833. e.removeListener(t.eventName, t.listener);
  834. }, osc.Relay = function(e, t, r) {
  835. (this.options = r || {}).raw = !1, this.port1 = e, this.port2 = t, this.listen();
  836. }, (e = osc.Relay.prototype = Object.create(EventEmitter.prototype)).constructor = osc.Relay,
  837. e.open = function() {
  838. this.port1.open(), this.port2.open();
  839. }, e.listen = function() {
  840. this.port1Spec && this.port2Spec && this.close(), this.port1Spec = osc.relayPorts(this.port1, this.port2, this.options),
  841. this.port2Spec = osc.relayPorts(this.port2, this.port1, this.options);
  842. var e = this.close.bind(this);
  843. this.port1.on("close", e), this.port2.on("close", e);
  844. }, e.close = function() {
  845. osc.stopRelaying(this.port1, this.port1Spec), osc.stopRelaying(this.port2, this.port2Spec),
  846. this.emit("close", this.port1, this.port2);
  847. }, "undefined" != typeof module && module.exports && (module.exports = osc);
  848. }();
  849. osc = osc || require("./osc.js");
  850. !function() {
  851. "use strict";
  852. osc.WebSocket = "undefined" != typeof WebSocket ? WebSocket : require("ws"), osc.WebSocketPort = function(e) {
  853. osc.Port.call(this, e), this.on("open", this.listen.bind(this)), this.socket = e.socket,
  854. this.socket && (1 === this.socket.readyState ? (osc.WebSocketPort.setupSocketForBinary(this.socket),
  855. this.emit("open", this.socket)) : this.open());
  856. };
  857. var e = osc.WebSocketPort.prototype = Object.create(osc.Port.prototype);
  858. e.constructor = osc.WebSocketPort, e.open = function() {
  859. (!this.socket || 1 < this.socket.readyState) && (this.socket = new osc.WebSocket(this.options.url)),
  860. osc.WebSocketPort.setupSocketForBinary(this.socket);
  861. var t = this;
  862. this.socket.onopen = function() {
  863. t.emit("open", t.socket);
  864. }, this.socket.onerror = function(e) {
  865. t.emit("error", e);
  866. };
  867. }, e.listen = function() {
  868. var t = this;
  869. this.socket.onmessage = function(e) {
  870. t.emit("data", e.data, e);
  871. }, this.socket.onclose = function(e) {
  872. t.emit("close", e);
  873. }, t.emit("ready");
  874. }, e.sendRaw = function(e) {
  875. this.socket && 1 === this.socket.readyState ? this.socket.send(e) : osc.fireClosedPortSendError(this);
  876. }, e.close = function(e, t) {
  877. this.socket.close(e, t);
  878. }, osc.WebSocketPort.setupSocketForBinary = function(e) {
  879. e.binaryType = osc.isNode ? "nodebuffer" : "arraybuffer";
  880. };
  881. }();