diff --git a/dist/osc.js b/dist/osc.js index 685d881..e39926d 100644 --- a/dist/osc.js +++ b/dist/osc.js @@ -425,7 +425,7 @@ var Message = function () { createClass(Message, [{ key: 'add', value: function add(item) { - if (!item) { + if (isUndefined(item)) { throw new Error('OSC Message needs a valid OSC Atomic Data Type'); } this.args.push(item); diff --git a/dist/osc.js.map b/dist/osc.js.map index 03c1a34..4481b56 100644 --- a/dist/osc.js.map +++ b/dist/osc.js.map @@ -1 +1 @@ -{"version":3,"file":"osc.js","sources":["../src/common/utils.js","../src/common/helpers.js","../src/atomic.js","../src/atomic/int32.js","../src/atomic/float32.js","../src/atomic/string.js","../src/atomic/blob.js","../src/message.js","../src/atomic/timetag.js","../src/bundle.js","../src/packet.js","../src/events.js","../src/osc.js","../src/plugin/wsbrowser.js","../entry/osc.browser.js"],"sourcesContent":["/**\n * Check if given object is an integer number\n * @param {*} n\n * @return {boolean}\n */\nexport function isInt(n) {\n return Number(n) === n && n % 1 === 0\n}\n\n/**\n * Check if given object is a float number\n * @param {*} n\n * @return {boolean}\n */\nexport function isFloat(n) {\n return Number(n) === n && n % 1 !== 0\n}\n\n/**\n * Check if given object is a string\n * @param {*} n\n * @return {boolean}\n */\nexport function isString(n) {\n return typeof n === 'string'\n}\n\n/**\n * Check if given object is an array\n * @param {*} n\n * @return {boolean}\n */\nexport function isArray(n) {\n return Object.prototype.toString.call(n) === '[object Array]'\n}\n\n/**\n * Check if given object is an object\n * @param {*} n\n * @return {boolean}\n */\nexport function isObject(n) {\n return Object.prototype.toString.call(n) === '[object Object]'\n}\n\n/**\n * Check if given object is a function\n * @param {*} n\n * @return {boolean}\n */\nexport function isFunction(n) {\n return typeof n === 'function'\n}\n\n/**\n * Check if given object is a Uint8Array\n * @param {*} n\n * @return {boolean}\n */\nexport function isBlob(n) {\n return n instanceof Uint8Array\n}\n\n/**\n * Check if given object is a Date\n * @param {*} n\n * @return {boolean}\n */\nexport function isDate(n) {\n return n instanceof Date\n}\n\n/**\n * Check if given object is undefined\n * @param {*} n\n * @return {boolean}\n */\nexport function isUndefined(n) {\n return typeof n === 'undefined'\n}\n\n/**\n * Return the next multiple of four\n * @param {number} n\n */\nexport function pad(n) {\n return (n + 3) & ~0x03\n}\n\n/**\n * Checks if environment provides a feature\n * @param {string} name Name of needed feature\n * @return {boolean}\n */\nexport function hasProperty(name) {\n return Object.prototype.hasOwnProperty.call(\n (typeof global !== 'undefined' ? global : window), // eslint-disable-line no-undef\n name\n )\n}\n\n/**\n * Wrap binary data in DataView\n * @param {*} obj\n * @return {DataView}\n */\nexport function dataView(obj) {\n if (obj.buffer) {\n return new DataView(obj.buffer)\n } else if (obj instanceof ArrayBuffer) {\n return new DataView(obj)\n }\n\n return new DataView(new Uint8Array(obj))\n}\n","import { isArray, isInt, isFloat, isString, isBlob } from './utils'\n\n/**\n * Checks type of given object and returns the regarding OSC\n * Type tag character\n * @param {*} item Any object\n * @return {string} OSC Type tag character\n */\nexport function typeTag(item) {\n if (isInt(item)) {\n return 'i'\n } else if (isFloat(item)) {\n return 'f'\n } else if (isString(item)) {\n return 's'\n } else if (isBlob(item)) {\n return 'b'\n }\n\n throw new Error('OSC typeTag() found unknown value type')\n}\n\n/**\n * Sanitizes an OSC-ready Address Pattern\n * @param {array|string} obj Address as string or array of strings\n * @return {string} Corrected address string\n *\n * @example\n * // all calls return '/test/path' string:\n * prepareAddress('test/path')\n * prepareAddress('/test/path/')\n * prepareAddress([test, path])\n */\nexport function prepareAddress(obj) {\n let address = ''\n\n if (isArray(obj)) {\n return `/${obj.join('/')}`\n } else if (isString(obj)) {\n address = obj\n\n // remove slash at ending of address\n if (address.length > 1 && address[address.length - 1] === '/') {\n address = address.slice(0, address.length - 1)\n }\n\n // add slash at beginning of address\n if (address.length > 1 && address[0] !== '/') {\n address = `/${address}`\n }\n\n return address\n }\n\n throw new Error('OSC prepareAddress() needs addresses of type array or string')\n}\n\n/**\n * Make an OSC address pattern javascript-regex-ready\n * @param {string} str OSC address pattern\n * @return {string} Javascript RegEx string\n */\nexport function prepareRegExPattern(str) {\n let pattern\n\n if (!(isString(str))) {\n throw new Error('OSC prepareRegExPattern() needs strings')\n }\n\n pattern = str.replace(/\\./g, '\\\\.')\n pattern = pattern.replace(/\\(/g, '\\\\(')\n pattern = pattern.replace(/\\)/g, '\\\\)')\n\n pattern = pattern.replace(/\\{/g, '(')\n pattern = pattern.replace(/\\}/g, ')')\n pattern = pattern.replace(/,/g, '|')\n\n pattern = pattern.replace(/\\[!/g, '[^')\n\n pattern = pattern.replace(/\\?/g, '.')\n pattern = pattern.replace(/\\*/g, '.*')\n\n return pattern\n}\n\n/**\n * Holds a list of items and helps to merge them\n * into a single array of packed binary data\n */\nexport default class EncodeHelper {\n /**\n * Create a new EncodeHelper instance\n */\n constructor() {\n /** @type {array} data */\n this.data = []\n /** @type {number} byteLength */\n this.byteLength = 0\n }\n\n /**\n * Packs an item and adds it to the list\n * @param {*} item Any object\n * @return {EncodeHelper}\n */\n add(item) {\n const buffer = item.pack()\n this.byteLength += buffer.byteLength\n this.data.push(buffer)\n\n return this\n }\n\n /**\n * Merge all added items into one Uint8Array\n * @return {Uint8Array} Merged binary data array of all items\n */\n merge() {\n const result = new Uint8Array(this.byteLength)\n let offset = 0\n\n this.data.forEach((data) => {\n result.set(data, offset)\n offset += data.byteLength\n })\n\n return result\n }\n}\n","import { isUndefined } from './common/utils'\n\n/**\n * Base class for OSC Atomic Data Types\n */\nexport default class Atomic {\n /**\n * Create an Atomic instance\n * @param {*} [value] Initial value of any type\n */\n constructor(value) {\n /** @type {*} value */\n this.value = value\n /** @type {number} offset */\n this.offset = 0\n }\n\n /**\n * Interpret the given value of this entity as packed binary data\n * @param {string} method The DataView method to write to the ArrayBuffer\n * @param {number} byteLength Size of array in bytes\n * @return {Uint8Array} Packed binary data\n */\n pack(method, byteLength) {\n if (!(method && byteLength)) {\n throw new Error('OSC Atomic cant\\'t be packed without given method or byteLength')\n }\n\n const data = new Uint8Array(byteLength)\n const dataView = new DataView(data.buffer)\n\n if (isUndefined(this.value)) {\n throw new Error('OSC Atomic cant\\'t be encoded with empty value')\n }\n\n // use DataView to write to ArrayBuffer\n dataView[method](this.offset, this.value, false)\n\n // always return binary Uint8Array after packing\n return data\n }\n\n /**\n * Unpack binary data from DataView according to the given format\n * @param {DataView} dataView The DataView holding the binary representation of the value\n * @param {string} method The DataView method to read the format from the ArrayBuffer\n * @param {number} byteLength Size of array in bytes\n * @param {number} [initialOffset=0] Offset of DataView before unpacking\n * @return {number} Offset after unpacking\n */\n unpack(dataView, method, byteLength, initialOffset = 0) {\n if (!(dataView && method && byteLength)) {\n throw new Error('OSC Atomic cant\\'t be unpacked without given dataView, method or byteLength')\n }\n\n if (!(dataView instanceof DataView)) {\n throw new Error('OSC Atomic expects an instance of type DataView')\n }\n\n // use DataView to read from ArrayBuffer and add offset\n this.value = dataView[method](initialOffset, false)\n this.offset = initialOffset + byteLength\n\n // always return offset number after unpacking\n return this.offset\n }\n}\n","import { isInt } from '../common/utils'\n\nimport Atomic from '../atomic'\n\n/**\n * 32-bit big-endian two's complement integer OSC Atomic Data Type\n */\nexport default class AtomicInt32 extends Atomic {\n /**\n * Create an AtomicInt32 instance\n * @param {number} [value] Initial integer value\n */\n constructor(value) {\n if (value && !isInt(value)) {\n throw new Error('OSC AtomicInt32 constructor expects value of type number')\n }\n\n super(value)\n }\n\n /**\n * Interpret the given number as packed binary data\n * @return {Uint8Array} Packed binary data\n */\n pack() {\n return super.pack('setInt32', 4)\n }\n\n /**\n * Unpack binary data from DataView and read a Int32 number\n * @param {DataView} dataView The DataView holding the binary representation of the value\n * @param {number} [initialOffset=0] Offset of DataView before unpacking\n * @return {number} Offset after unpacking\n */\n unpack(dataView, initialOffset = 0) {\n return super.unpack(dataView, 'getInt32', 4, initialOffset)\n }\n}\n","import { isFloat } from '../common/utils'\n\nimport Atomic from '../atomic'\n\n/**\n * 32-bit big-endian IEEE 754 floating point number OSC Atomic Data Type\n */\nexport default class AtomicFloat32 extends Atomic {\n /**\n * Create an AtomicFloat32 instance\n * @param {number} [value] Float number\n */\n constructor(value) {\n if (value && !isFloat(value)) {\n throw new Error('OSC AtomicFloat32 constructor expects value of type float')\n }\n\n super(value)\n }\n\n /**\n * Interpret the given number as packed binary data\n * @return {Uint8Array} Packed binary data\n */\n pack() {\n return super.pack('setFloat32', 4)\n }\n\n /**\n * Unpack binary data from DataView and read a Float32 number\n * @param {DataView} dataView The DataView holding the binary representation of the value\n * @param {number} [initialOffset=0] Offset of DataView before unpacking\n * @return {number} Offset after unpacking\n */\n unpack(dataView, initialOffset = 0) {\n return super.unpack(dataView, 'getFloat32', 4, initialOffset)\n }\n}\n","import { pad, isString, isUndefined, hasProperty } from '../common/utils'\n\nimport Atomic from '../atomic'\n\n/** Slice size of large strings for fallback method */\nconst STR_SLICE_SIZE = 65537\n\n/** Text encoding format */\nconst STR_ENCODING = 'utf-8'\n\n/**\n * Helper method to decode a string using different methods depending on environment\n * @param {array} charCodes Array of char codes\n * @return {string} Decoded string\n */\nfunction charCodesToString(charCodes) {\n // Use these methods to be able to convert large strings\n if (hasProperty('Buffer')) {\n return Buffer.from(charCodes).toString(STR_ENCODING)\n } else if (hasProperty('TextDecoder')) {\n return new TextDecoder(STR_ENCODING) // eslint-disable-line no-undef\n .decode(new Int8Array(charCodes))\n }\n\n // Fallback method\n let str = ''\n\n for (let i = 0; i < charCodes.length; i += STR_SLICE_SIZE) {\n str += String.fromCharCode.apply(\n null,\n charCodes.slice(i, i + STR_SLICE_SIZE)\n )\n }\n\n return str\n}\n\n/**\n * A sequence of non-null ASCII characters OSC Atomic Data Type\n */\nexport default class AtomicString extends Atomic {\n /**\n * Create an AtomicString instance\n * @param {string} [value] Initial string value\n */\n constructor(value) {\n if (value && !isString(value)) {\n throw new Error('OSC AtomicString constructor expects value of type string')\n }\n\n super(value)\n }\n\n /**\n * Interpret the given string as packed binary data\n * @return {Uint8Array} Packed binary data\n */\n pack() {\n if (isUndefined(this.value)) {\n throw new Error('OSC AtomicString can not be encoded with empty value')\n }\n\n // add 0-3 null characters for total number of bits a multiple of 32\n const terminated = `${this.value}\\u0000`\n const byteLength = pad(terminated.length)\n\n const buffer = new Uint8Array(byteLength)\n\n for (let i = 0; i < terminated.length; i += 1) {\n buffer[i] = terminated.charCodeAt(i)\n }\n\n return buffer\n }\n\n /**\n * Unpack binary data from DataView and read a string\n * @param {DataView} dataView The DataView holding the binary representation of the string\n * @param {number} [initialOffset=0] Offset of DataView before unpacking\n * @return {number} Offset after unpacking\n */\n unpack(dataView, initialOffset = 0) {\n if (!(dataView instanceof DataView)) {\n throw new Error('OSC AtomicString expects an instance of type DataView')\n }\n\n let offset = initialOffset\n let charcode\n const charCodes = []\n\n for (; offset < dataView.byteLength; offset += 1) {\n charcode = dataView.getUint8(offset)\n\n // check for terminating null character\n if (charcode !== 0) {\n charCodes.push(charcode)\n } else {\n offset += 1\n break\n }\n }\n\n if (offset === dataView.length) {\n throw new Error('OSC AtomicString found a malformed OSC string')\n }\n\n /** @type {number} offset */\n this.offset = pad(offset)\n /** @type {string} value */\n this.value = charCodesToString(charCodes)\n\n return this.offset\n }\n}\n","import { pad, isBlob, isUndefined } from '../common/utils'\n\nimport Atomic from '../atomic'\n\n/**\n * 8-bit bytes of arbitrary binary data OSC Atomic Data Type\n */\nexport default class AtomicBlob extends Atomic {\n /**\n * Create an AtomicBlob instance\n * @param {Uint8Array} [value] Binary data\n */\n constructor(value) {\n if (value && !isBlob(value)) {\n throw new Error('OSC AtomicBlob constructor expects value of type Uint8Array')\n }\n\n super(value)\n }\n\n /**\n * Interpret the given blob as packed binary data\n * @return {Uint8Array} Packed binary data\n */\n pack() {\n if (isUndefined(this.value)) {\n throw new Error('OSC AtomicBlob can not be encoded with empty value')\n }\n\n const byteLength = pad(this.value.byteLength)\n const data = new Uint8Array(byteLength + 4)\n const dataView = new DataView(data.buffer)\n\n // an int32 size count\n dataView.setInt32(0, this.value.byteLength, false)\n // followed by 8-bit bytes of arbitrary binary data\n data.set(this.value, 4)\n\n return data\n }\n\n /**\n * Unpack binary data from DataView and read a blob\n * @param {DataView} dataView The DataView holding the binary representation of the blob\n * @param {number} [initialOffset=0] Offset of DataView before unpacking\n * @return {number} Offset after unpacking\n */\n unpack(dataView, initialOffset = 0) {\n if (!(dataView instanceof DataView)) {\n throw new Error('OSC AtomicBlob expects an instance of type DataView')\n }\n\n const byteLength = dataView.getInt32(initialOffset, false)\n\n /** @type {Uint8Array} value */\n this.value = new Uint8Array(dataView.buffer, initialOffset + 4, byteLength)\n /** @type {number} offset */\n this.offset = pad(initialOffset + 4 + byteLength)\n\n return this.offset\n }\n}\n","import { isString, isArray, isInt, isFloat, isBlob } from './common/utils'\nimport Helper, { typeTag, prepareAddress } from './common/helpers'\n\nimport AtomicInt32 from './atomic/int32'\nimport AtomicFloat32 from './atomic/float32'\nimport AtomicString from './atomic/string'\nimport AtomicBlob from './atomic/blob'\n\n/**\n * An OSC message consists of an OSC Address Pattern followed\n * by an OSC Type Tag String followed by zero or more OSC Arguments\n */\nexport default class Message {\n /**\n * Create a Message instance\n * @param {array|string} args Address\n * @param {...*} args OSC Atomic Data Types\n *\n * @example\n * const message = new Message(['test', 'path'], 50, 100.52, 'test')\n *\n * @example\n * const message = new Message('/test/path', 51.2)\n */\n constructor(...args) {\n /**\n * @type {number} offset\n * @private\n */\n this.offset = 0\n /** @type {string} address */\n this.address = ''\n /** @type {string} types */\n this.types = ''\n /** @type {array} args */\n this.args = []\n\n if (args.length > 0) {\n if (!(isString(args[0]) || isArray(args[0]))) {\n throw new Error('OSC Message constructor first argument (address) must be a string or array')\n }\n\n this.address = prepareAddress(args.shift())\n this.types = args.map(item => typeTag(item)).join('')\n this.args = args\n }\n }\n\n /**\n * Add an OSC Atomic Data Type to the list of elements\n * @param {*} item\n */\n add(item) {\n if (!item) {\n throw new Error('OSC Message needs a valid OSC Atomic Data Type')\n }\n\n this.args.push(item)\n this.types += typeTag(item)\n }\n\n /**\n * Interpret the Message as packed binary data\n * @return {Uint8Array} Packed binary data\n */\n pack() {\n if (this.address.length === 0 || this.address[0] !== '/') {\n throw new Error('OSC Message has an invalid address')\n }\n\n const encoder = new Helper()\n\n // OSC Address Pattern and Type string\n encoder.add(new AtomicString(this.address))\n encoder.add(new AtomicString(`,${this.types}`))\n\n // followed by zero or more OSC Arguments\n if (this.args.length > 0) {\n let argument\n\n this.args.forEach((value) => {\n if (isInt(value)) {\n argument = new AtomicInt32(value)\n } else if (isFloat(value)) {\n argument = new AtomicFloat32(value)\n } else if (isString(value)) {\n argument = new AtomicString(value)\n } else if (isBlob(value)) {\n argument = new AtomicBlob(value)\n } else {\n throw new Error('OSC Message found unknown argument type')\n }\n\n encoder.add(argument)\n })\n }\n\n return encoder.merge()\n }\n\n /**\n * Unpack binary data to read a Message\n * @param {DataView} dataView The DataView holding the binary representation of a Message\n * @param {number} [initialOffset=0] Offset of DataView before unpacking\n * @return {number} Offset after unpacking\n */\n unpack(dataView, initialOffset = 0) {\n if (!(dataView instanceof DataView)) {\n throw new Error('OSC Message expects an instance of type DataView.')\n }\n\n // read address pattern\n const address = new AtomicString()\n address.unpack(dataView, initialOffset)\n\n // read type string\n const types = new AtomicString()\n types.unpack(dataView, address.offset)\n\n if (address.value.length === 0 || address.value[0] !== '/') {\n throw new Error('OSC Message found malformed or missing address string')\n }\n\n if (types.value.length === 0 && types.value[0] !== ',') {\n throw new Error('OSC Message found malformed or missing type string')\n }\n\n let { offset } = types\n let next\n let type\n\n const args = []\n\n // read message arguments (OSC Atomic Data Types)\n for (let i = 1; i < types.value.length; i += 1) {\n type = types.value[i]\n\n if (type === 'i') {\n next = new AtomicInt32()\n } else if (type === 'f') {\n next = new AtomicFloat32()\n } else if (type === 's') {\n next = new AtomicString()\n } else if (type === 'b') {\n next = new AtomicBlob()\n } else {\n throw new Error('OSC Message found non-standard argument type')\n }\n\n offset = next.unpack(dataView, offset)\n args.push(next.value)\n }\n\n this.offset = offset\n this.address = address.value\n this.types = types.value\n this.args = args\n\n return this.offset\n }\n}\n","import { isInt, isDate, isUndefined } from '../common/utils'\n\nimport Atomic from '../atomic'\n\n/** 70 years in seconds */\nexport const SECONDS_70_YEARS = 2208988800\n/** 2^32 */\nexport const TWO_POWER_32 = 4294967296\n\n/**\n * Timetag helper class for representing NTP timestamps\n * and conversion between them and javascript representation\n */\nexport class Timetag {\n /**\n * Create a Timetag instance\n * @param {number} [seconds=0] Initial NTP *seconds* value\n * @param {number} [fractions=0] Initial NTP *fractions* value\n */\n constructor(seconds = 0, fractions = 0) {\n if (!(isInt(seconds) && isInt(fractions))) {\n throw new Error('OSC Timetag constructor expects values of type integer number')\n }\n\n /** @type {number} seconds */\n this.seconds = seconds\n /** @type {number} fractions */\n this.fractions = fractions\n }\n\n /**\n * Converts from NTP to JS representation and back\n * @param {number} [milliseconds] Converts from JS milliseconds to NTP.\n * Leave empty for converting from NTP to JavaScript representation\n * @return {number} Javascript timestamp\n */\n timestamp(milliseconds) {\n let seconds\n\n if (typeof milliseconds === 'number') {\n seconds = milliseconds / 1000\n const rounded = Math.floor(seconds)\n\n this.seconds = rounded + SECONDS_70_YEARS\n this.fractions = Math.round(TWO_POWER_32 * (seconds - rounded))\n\n return milliseconds\n }\n\n seconds = this.seconds - SECONDS_70_YEARS\n return (seconds + Math.round(this.fractions / TWO_POWER_32)) * 1000\n }\n}\n\n/**\n * 64-bit big-endian fixed-point time tag, semantics\n * defined below OSC Atomic Data Type\n */\nexport default class AtomicTimetag extends Atomic {\n /**\n * Create a AtomicTimetag instance\n * @param {number|Timetag|Date} [value] Initial date, leave empty if\n * you want it to be the current date\n */\n constructor(value = Date.now()) {\n let timetag = new Timetag()\n\n if (value instanceof Timetag) {\n timetag = value\n } else if (isInt(value)) {\n timetag.timestamp(value)\n } else if (isDate(value)) {\n timetag.timestamp(value.getTime())\n }\n\n super(timetag)\n }\n\n /**\n * Interpret the given timetag as packed binary data\n * @return {Uint8Array} Packed binary data\n */\n pack() {\n if (isUndefined(this.value)) {\n throw new Error('OSC AtomicTimetag can not be encoded with empty value')\n }\n\n const { seconds, fractions } = this.value\n const data = new Uint8Array(8)\n const dataView = new DataView(data.buffer)\n\n dataView.setInt32(0, seconds, false)\n dataView.setInt32(4, fractions, false)\n\n return data\n }\n\n /**\n * Unpack binary data from DataView and read a timetag\n * @param {DataView} dataView The DataView holding the binary representation of the timetag\n * @param {number} [initialOffset=0] Offset of DataView before unpacking\n * @return {number} Offset after unpacking\n */\n unpack(dataView, initialOffset = 0) {\n if (!(dataView instanceof DataView)) {\n throw new Error('OSC AtomicTimetag expects an instance of type DataView')\n }\n\n const seconds = dataView.getUint32(initialOffset, false)\n const fractions = dataView.getUint32(initialOffset + 4, false)\n\n /** @type {Timetag} value */\n this.value = new Timetag(seconds, fractions)\n /** @type {number} offset */\n this.offset = initialOffset + 8\n\n return this.offset\n }\n}\n","import { isArray, isInt } from './common/utils'\nimport EncodeHelper from './common/helpers'\n\nimport Packet from './packet'\nimport Message from './message'\nimport AtomicString from './atomic/string'\nimport AtomicInt32 from './atomic/int32'\nimport AtomicTimetag from './atomic/timetag'\n\n/** OSC Bundle string */\nexport const BUNDLE_TAG = '#bundle'\n\n/**\n * An OSC Bundle consist of a Timetag and one or many Bundle Elements.\n * The elements are either OSC Messages or more OSC Bundles\n */\nexport default class Bundle {\n /**\n * Create a Bundle instance\n * @param {...*} [args] Timetag and elements. See examples for options\n *\n * @example\n * const bundle = new Bundle(new Date() + 500)\n *\n * @example\n * const message = new Message('/test/path', 51.2)\n * const anotherBundle = new Bundle([message], Date.now() + 1500)\n *\n * @example\n * const message = new Message('/test/path', 51.2)\n * const anotherMessage = new Message('/test/message', 'test', 12)\n * const anotherBundle = new Bundle(message, anotherMessage)\n */\n constructor(...args) {\n /**\n * @type {number} offset\n * @private\n */\n this.offset = 0\n /** @type {AtomicTimetag} timetag */\n this.timetag = new AtomicTimetag()\n /** @type {array} bundleElements */\n this.bundleElements = []\n\n if (args.length > 0) {\n // first argument is an Date or js timestamp (number)\n if (args[0] instanceof Date || isInt(args[0])) {\n this.timetag = new AtomicTimetag(args[0])\n } else if (isArray(args[0])) {\n // first argument is an Array of Bundle elements\n args[0].forEach((item) => {\n this.add(item)\n })\n\n // second argument is an Date or js timestamp (number)\n if (args.length > 1 && (args[1] instanceof Date || isInt(args[0]))) {\n this.timetag = new AtomicTimetag(args[1])\n }\n } else {\n // take all arguments as Bundle elements\n args.forEach((item) => {\n this.add(item)\n })\n }\n }\n }\n\n /**\n * Take a JavaScript timestamp to set the Bundle's timetag\n * @param {number} ms JS timestamp in milliseconds\n *\n * @example\n * const bundle = new Bundle()\n * bundle.timestamp(Date.now() + 5000) // in 5 seconds\n */\n timestamp(ms) {\n if (!isInt(ms)) {\n throw new Error('OSC Bundle needs an integer for setting the timestamp')\n }\n\n this.timetag = new AtomicTimetag(ms)\n }\n\n /**\n * Add a Message or Bundle to the list of elements\n * @param {Bundle|Message} item\n */\n add(item) {\n if (!(item instanceof Message || item instanceof Bundle)) {\n throw new Error('OSC Bundle contains only Messages and Bundles')\n }\n\n this.bundleElements.push(item)\n }\n\n /**\n * Interpret the Bundle as packed binary data\n * @return {Uint8Array} Packed binary data\n */\n pack() {\n const encoder = new EncodeHelper()\n\n // an OSC Bundle consists of the OSC-string \"#bundle\"\n encoder.add(new AtomicString(BUNDLE_TAG))\n\n // followed by an OSC Time Tag\n if (!this.timetag) {\n this.timetag = new AtomicTimetag()\n }\n\n encoder.add(this.timetag)\n\n // followed by zero or more OSC Bundle Elements\n this.bundleElements.forEach((item) => {\n encoder.add(new AtomicInt32(item.pack().byteLength))\n encoder.add(item)\n })\n\n return encoder.merge()\n }\n\n /**\n * Unpack binary data to read a Bundle\n * @param {DataView} dataView The DataView holding the binary representation of a Bundle\n * @param {number} [initialOffset=0] Offset of DataView before unpacking\n * @return {number} Offset after unpacking\n */\n unpack(dataView, initialOffset = 0) {\n if (!(dataView instanceof DataView)) {\n throw new Error('OSC Bundle expects an instance of type DataView')\n }\n\n // read the beginning bundle string\n const head = new AtomicString()\n head.unpack(dataView, initialOffset)\n\n if (head.value !== BUNDLE_TAG) {\n throw new Error('OSC Bundle does not contain a valid #bundle head')\n }\n\n // read the timetag\n const timetag = new AtomicTimetag()\n let offset = timetag.unpack(dataView, head.offset)\n\n // read the bundle elements\n this.bundleElements = []\n\n while (offset < dataView.byteLength) {\n const packet = new Packet()\n const size = new AtomicInt32()\n\n offset = size.unpack(dataView, offset)\n offset = packet.unpack(dataView, offset, this.timetag)\n\n this.bundleElements.push(packet.value)\n }\n\n this.offset = offset\n this.timetag = timetag\n\n return this.offset\n }\n}\n","import Bundle, { BUNDLE_TAG } from './bundle'\nimport Message from './message'\nimport AtomicString from './atomic/string'\n\n/**\n * The unit of transmission of OSC is an OSC Packet. The contents\n * of an OSC packet must be either an OSC Message or an OSC Bundle\n */\nexport default class Packet {\n /**\n * Create a Packet instance holding a Message or Bundle\n * @param {Message|Bundle} [value] Initial Packet value\n */\n constructor(value) {\n if (value && !(value instanceof Message || value instanceof Bundle)) {\n throw new Error('OSC Packet value has to be Message or Bundle')\n }\n\n /** @type {Message|Bundle} value */\n this.value = value\n /**\n * @type {number} offset\n * @private\n */\n this.offset = 0\n }\n\n /**\n * Packs the Packet value. This implementation is more like\n * a wrapper due to OSC specifications, you could also skip the\n * Packet and directly work with the Message or Bundle instance\n * @return {Uint8Array} Packed binary data\n *\n * @example\n * const message = new Message('/test/path', 21.5, 'test')\n * const packet = new Packet(message)\n * const packetBinary = packet.pack() // then send it via udp etc.\n *\n * // or skip the Packet for convenience\n * const messageBinary = message.pack()\n */\n pack() {\n if (!this.value) {\n throw new Error('OSC Packet can not be encoded with empty body')\n }\n\n return this.value.pack()\n }\n\n /**\n * Unpack binary data from DataView to read Messages or Bundles\n * @param {DataView} dataView The DataView holding a binary representation of a Packet\n * @param {number} [initialOffset=0] Offset of DataView before unpacking\n * @return {number} Offset after unpacking\n */\n unpack(dataView, initialOffset = 0) {\n if (!(dataView instanceof DataView)) {\n throw new Error('OSC Packet expects an instance of type DataView')\n }\n\n if (dataView.byteLength % 4 !== 0) {\n throw new Error('OSC Packet byteLength has to be a multiple of four')\n }\n\n const head = new AtomicString()\n head.unpack(dataView, initialOffset)\n\n let item\n\n // check if Packet is a Bundle or a Message\n if (head.value === BUNDLE_TAG) {\n item = new Bundle()\n } else {\n item = new Message()\n }\n\n item.unpack(dataView, initialOffset)\n\n this.offset = item.offset\n this.value = item\n\n return this.offset\n }\n}\n","import { isArray, isString, isInt, isFunction, dataView } from './common/utils'\nimport { prepareAddress, prepareRegExPattern } from './common/helpers'\n\nimport Packet from './packet'\nimport Bundle from './bundle'\nimport Message from './message'\n\n/**\n * Default options\n * @private\n */\nconst defaultOptions = {\n discardLateMessages: false,\n}\n\n/**\n * EventHandler to notify listeners on matching OSC messages and\n * status changes of plugins\n */\nexport default class EventHandler {\n /**\n * Create an EventHandler instance\n * @param {object} options Custom options\n */\n constructor(options) {\n /**\n * @type {object} options\n * @private\n */\n this.options = Object.assign({}, defaultOptions, options)\n /**\n * @type {array} addressHandlers\n * @private\n */\n this.addressHandlers = []\n /**\n * @type {object} eventHandlers\n * @private\n */\n this.eventHandlers = {\n open: [],\n error: [],\n close: [],\n }\n /**\n * @type {number} uuid\n * @private\n */\n this.uuid = 0\n }\n\n /**\n * Internally used method to dispatch OSC Packets. Extracts\n * given Timetags and dispatches them accordingly\n * @param {Packet} packet\n * @return {boolean} Success state\n * @private\n */\n dispatch(packet) {\n if (!(packet instanceof Packet)) {\n throw new Error('OSC EventHander dispatch() accepts only arguments of type Packet')\n }\n\n if (!packet.value) {\n throw new Error('OSC EventHander dispatch() can\\'t read empty Packets')\n }\n\n if (packet.value instanceof Bundle) {\n const bundle = packet.value\n\n return bundle.bundleElements.forEach((bundleItem) => {\n if (bundleItem instanceof Bundle) {\n if (bundle.timetag.value.timestamp() < bundleItem.timetag.value.timestamp()) {\n throw new Error('OSC Bundle timestamp is older than the timestamp of enclosed Bundles')\n }\n return this.dispatch(bundleItem)\n } else if (bundleItem instanceof Message) {\n const message = bundleItem\n return this.notify(\n message.address,\n message,\n bundle.timetag.value.timestamp()\n )\n }\n\n throw new Error('OSC EventHander dispatch() can\\'t dispatch unknown Packet value')\n })\n } else if (packet.value instanceof Message) {\n const message = packet.value\n return this.notify(message.address, message)\n }\n\n throw new Error('OSC EventHander dispatch() can\\'t dispatch unknown Packet value')\n }\n\n /**\n * Internally used method to invoke listener callbacks. Uses regular\n * expression pattern matching for OSC addresses\n * @param {string} name OSC address or event name\n * @param {*} [data] The data of the event\n * @return {boolean} Success state\n * @private\n */\n call(name, data) {\n let success = false\n\n // call event handlers\n if (isString(name) && name in this.eventHandlers) {\n this.eventHandlers[name].forEach((handler) => {\n handler.callback(data)\n success = true\n })\n\n return success\n }\n\n // call address handlers\n const handlerKeys = Object.keys(this.addressHandlers)\n const handlers = this.addressHandlers\n\n handlerKeys.forEach((key) => {\n const regex = new RegExp(prepareRegExPattern(prepareAddress(name)), 'g')\n const test = regex.test(key)\n\n // found a matching address in our callback handlers\n if (test && key.length === regex.lastIndex) {\n handlers[key].forEach((handler) => {\n handler.callback(data)\n success = true\n })\n }\n })\n\n return success\n }\n\n /**\n * Notify the EventHandler of incoming OSC messages or status\n * changes (*open*, *close*, *error*). Handles OSC address patterns\n * and executes timed messages. Use binary arrays when\n * handling directly incoming network data. Packet's or Messages can\n * also be used\n * @param {...*} args\n * The OSC address pattern / event name as string}. For convenience and\n * Plugin API communication you can also use Message or Packet instances\n * or ArrayBuffer, Buffer instances (low-level access). The latter will\n * automatically be unpacked\n * When using a string you can also pass on data as a second argument\n * (any type). All regarding listeners will be notified with this data.\n * As a third argument you can define a javascript timestamp (number or\n * Date instance) for timed notification of the listeners.\n * @return {boolean} Success state of notification\n *\n * @example\n * const socket = dgram.createSocket('udp4')\n * socket.on('message', (message) => {\n * this.notify(message)\n * })\n *\n * @example\n * this.notify('error', error.message)\n *\n * @example\n * const message = new OSC.Message('/test/path', 55)\n * this.notify(message)\n *\n * @example\n * const message = new OSC.Message('/test/path', 55)\n * // override timestamp\n * this.notify(message.address, message, Date.now() + 5000)\n */\n notify(...args) {\n if (args.length === 0) {\n throw new Error('OSC EventHandler can not be called without any argument')\n }\n\n // check for incoming dispatchable OSC data\n if (args[0] instanceof Packet) {\n return this.dispatch(args[0])\n } else if (args[0] instanceof Bundle || args[0] instanceof Message) {\n return this.dispatch(new Packet(args[0]))\n } else if (!isString(args[0])) {\n const packet = new Packet()\n packet.unpack(dataView(args[0]))\n return this.dispatch(packet)\n }\n\n const name = args[0]\n\n // data argument\n let data = null\n\n if (args.length > 1) {\n data = args[1]\n }\n\n // timestamp argument\n let timestamp = null\n\n if (args.length > 2) {\n if (isInt(args[2])) {\n timestamp = args[2]\n } else if (args[2] instanceof Date) {\n timestamp = args[2].getTime()\n } else {\n throw new Error('OSC EventHandler timestamp has to be a number or Date')\n }\n }\n\n // notify now or later\n if (timestamp) {\n const now = Date.now()\n\n // is message outdated?\n if (now > timestamp) {\n if (!this.options.discardLateMessages) {\n return this.call(name, data)\n }\n }\n\n // notify later\n const that = this\n\n setTimeout(() => {\n that.call(name, data)\n }, timestamp - now)\n\n return true\n }\n\n return this.call(name, data)\n }\n\n /**\n * Subscribe to a new address or event you want to listen to\n * @param {string} name The OSC address or event name\n * @param {function} callback Callback function on notification\n * @return {number} Subscription identifier (needed to unsubscribe)\n */\n on(name, callback) {\n if (!(isString(name) || isArray(name))) {\n throw new Error('OSC EventHandler accepts only strings or arrays for address patterns')\n }\n\n if (!isFunction(callback)) {\n throw new Error('OSC EventHandler callback has to be a function')\n }\n\n // get next id\n this.uuid += 1\n\n // prepare handler\n const handler = {\n id: this.uuid,\n callback,\n }\n\n // register event listener\n if (isString(name) && name in this.eventHandlers) {\n this.eventHandlers[name].push(handler)\n return this.uuid\n }\n\n // register address listener\n const address = prepareAddress(name)\n const regex = new RegExp(/[#*\\s[\\],/{}|?]/g)\n\n if (regex.test(address.split('/').join(''))) {\n throw new Error('OSC EventHandler address string contains invalid characters')\n }\n\n if (!(address in this.addressHandlers)) {\n this.addressHandlers[address] = []\n }\n\n this.addressHandlers[address].push(handler)\n\n return this.uuid\n }\n\n /**\n * Unsubscribe listener from event notification or address handler\n * @param {string} name The OSC address or event name\n * @param {number} subscriptionId Subscription id to identify the handler\n * @return {boolean} Success state\n */\n off(name, subscriptionId) {\n if (!(isString(name) || isArray(name))) {\n throw new Error('OSC EventHandler accepts only strings or arrays for address patterns')\n }\n\n if (!isInt(subscriptionId)) {\n throw new Error('OSC EventHandler subscription id has to be a number')\n }\n\n let key\n let haystack\n\n // event or address listener\n if (isString(name) && name in this.eventHandlers) {\n key = name\n haystack = this.eventHandlers\n } else {\n key = prepareAddress(name)\n haystack = this.addressHandlers\n }\n\n // remove the entry\n if (key in haystack) {\n return haystack[key].some((item, index) => {\n if (item.id === subscriptionId) {\n haystack[key].splice(index, 1)\n return true\n }\n\n return false\n })\n }\n\n return false\n }\n}\n","import { isObject, isString, isFunction, isInt } from './common/utils'\n\nimport Packet from './packet'\nimport Bundle from './bundle'\nimport Message from './message'\n\nimport EventHandler from './events'\n\n/**\n * Default options\n * @private\n */\nconst defaultOptions = {\n plugin: null,\n discardLateMessages: false,\n}\n\n/**\n * Status flags\n */\nconst STATUS = {\n IS_NOT_INITIALIZED: -1,\n IS_CONNECTING: 0,\n IS_OPEN: 1,\n IS_CLOSING: 2,\n IS_CLOSED: 3,\n}\n\n/**\n * OSC interface to send OSC Packets and to listen to status-changes and\n * incoming message events. Offers a Plugin API for different network\n * protocols, defaults to a simple Websocket client for OSC communication\n * between a browser js-app and a js-node server\n *\n * @example\n * const osc = new OSC()\n *\n * osc.on('/input/test', (message) => {\n * // print incoming OSC message arguments\n * console.log(message.args)\n * })\n *\n * osc.on('open', () => {\n * const message = new Message('/test/path', 55.12, 'hello')\n * osc.send(message)\n * })\n *\n * osc.open({ host: '192.168.178.115', port: 9012 })\n */\nclass OSC {\n /**\n * Create an OSC instance with given options\n * @param {object} [options] Custom options\n * @param {boolean} [options.discardLateMessages=false] Ignore incoming\n * messages when given timetag lies in the past\n * @param {Plugin} [options.plugin=WebsocketClientPlugin] Add a connection plugin\n * to this interface, defaults to a plugin with Websocket client.\n * Open README.md for further information on how to handle plugins or\n * how to write your own with the Plugin API\n *\n * @example\n * const osc = new OSC() // default options with Websocket client\n *\n * @example\n * const osc = new OSC({ discardLateMessages: true })\n *\n * @example\n * const websocketPlugin = new OSC.WebsocketClientPlugin()\n * const osc = new OSC({ plugin: websocketPlugin })\n */\n constructor(options) {\n if (options && !isObject(options)) {\n throw new Error('OSC options argument has to be an object.')\n }\n\n /**\n * @type {object} options\n * @private\n */\n this.options = Object.assign({}, defaultOptions, options)\n /**\n * @type {EventHandler} eventHandler\n * @private\n */\n this.eventHandler = new EventHandler({\n discardLateMessages: this.options.discardLateMessages,\n })\n\n // pass EventHandler's notify() to plugin\n const { eventHandler } = this\n if (this.options.plugin && this.options.plugin.registerNotify) {\n this.options.plugin.registerNotify((...args) => eventHandler.notify(...args))\n }\n }\n\n /**\n * Listen to a status-change event or incoming OSC message with\n * address pattern matching\n * @param {string} eventName Event name or OSC address pattern\n * @param {function} callback Function which is called on notification\n * @return {number} Subscription id (needed to unsubscribe)\n *\n * @example\n * // will be called when server receives /in!trument/* for example\n * osc.on('/instrument/1', (message) => {\n * console.log(message)\n * })\n *\n * @example\n * // will be called on network socket error\n * osc.on('error', (message) => {\n * console.log(message)\n * })\n */\n on(eventName, callback) {\n if (!(isString(eventName) && isFunction(callback))) {\n throw new Error('OSC on() needs event- or address string and callback function')\n }\n\n return this.eventHandler.on(eventName, callback)\n }\n\n /**\n * Unsubscribe an event listener\n * @param {string} eventName Event name or OSC address pattern\n * @param {number} subscriptionId The subscription id\n * @return {boolean} Success state\n *\n * @example\n * const listenerId = osc.on('error', (message) => {\n * console.log(message)\n * })\n * osc.off('error', listenerId) // unsubscribe from error event\n */\n off(eventName, subscriptionId) {\n if (!(isString(eventName) && isInt(subscriptionId))) {\n throw new Error('OSC off() needs string and number (subscriptionId) to unsubscribe')\n }\n\n return this.eventHandler.off(eventName, subscriptionId)\n }\n\n /**\n * Open network socket with plugin. This method is used by\n * plugins and is not available without (see Plugin API for more information)\n * @param {object} [options] Custom global options for plugin instance\n *\n * @example\n * const osc = new OSC({ plugin: new OSC.DatagramPlugin() })\n * osc.open({ host: '127.0.0.1', port: 8080 })\n */\n open(options) {\n if (options && !isObject(options)) {\n throw new Error('OSC open() options argument needs to be an object')\n }\n\n if (!(this.options.plugin && isFunction(this.options.plugin.open))) {\n throw new Error('OSC Plugin API #open is not implemented!')\n }\n\n return this.options.plugin.open(options)\n }\n\n /**\n * Returns the current status of the connection. See *STATUS* for\n * different possible states. This method is used by plugins\n * and is not available without (see Plugin API for more information)\n * @return {number} Status identifier\n *\n * @example\n * import OSC, { STATUS } from 'osc'\n * const osc = new OSC()\n * if (osc.status() === STATUS.IS_CONNECTING) {\n * // do something\n * }\n */\n status() {\n if (!(this.options.plugin && isFunction(this.options.plugin.status))) {\n throw new Error('OSC Plugin API #status is not implemented!')\n }\n\n return this.options.plugin.status()\n }\n\n /**\n * Close connection. This method is used by plugins and is not\n * available without (see Plugin API for more information)\n */\n close() {\n if (!(this.options.plugin && isFunction(this.options.plugin.close))) {\n throw new Error('OSC Plugin API #close is not implemented!')\n }\n\n return this.options.plugin.close()\n }\n\n /**\n * Send an OSC Packet, Bundle or Message. This method is used by plugins\n * and is not available without (see Plugin API for more information)\n * @param {Packet|Bundle|Message} packet OSC Packet, Bundle or Message instance\n * @param {object} [options] Custom options\n *\n * @example\n * const osc = new OSC({ plugin: new OSC.DatagramPlugin() })\n * osc.open({ host: '127.0.0.1', port: 8080 })\n *\n * const message = new OSC.Message('/test/path', 55.1, 57)\n * osc.send(message)\n *\n * // send message again to custom address\n * osc.send(message, { host: '192.168.178.115', port: 9001 })\n */\n send(packet, options) {\n if (!(this.options.plugin && isFunction(this.options.plugin.send))) {\n throw new Error('OSC Plugin API #send is not implemented!')\n }\n\n if (!(packet instanceof Message || packet instanceof Bundle || packet instanceof Packet)) {\n throw new Error('OSC send() needs Messages, Bundles or Packets')\n }\n\n if (options && !isObject(options)) {\n throw new Error('OSC send() options argument has to be an object')\n }\n\n return this.options.plugin.send(packet.pack(), options)\n }\n}\n\n// expose status flags\nOSC.STATUS = STATUS\n\n// expose OSC classes\nOSC.Packet = Packet\nOSC.Bundle = Bundle\nOSC.Message = Message\n\nexport default OSC\n","import { hasProperty } from '../common/utils'\n\n/**\n * Status flags\n * @private\n */\nconst STATUS = {\n IS_NOT_INITIALIZED: -1,\n IS_CONNECTING: 0,\n IS_OPEN: 1,\n IS_CLOSING: 2,\n IS_CLOSED: 3,\n}\n\n/**\n * Default options\n * @private\n */\nconst defaultOptions = {\n host: 'localhost',\n port: 8080,\n}\n\n/**\n * OSC plugin for a Websocket client running in only browser contexts\n */\nexport default class WebsocketBrowserPlugin {\n /**\n * Create an OSC WebsocketBrowserPlugin instance with given options.\n * Defaults to *localhost:8080* for connecting to a Websocket server\n * @param {object} [options] Custom options\n * @param {string} [options.host='localhost'] Hostname of Websocket server\n * @param {number} [options.port=8080] Port of Websocket server\n *\n * @example\n * const plugin = new OSC.WebsocketBrowserPlugin({ port: 9912 })\n * const osc = new OSC({ plugin: plugin })\n */\n constructor(customOptions) {\n if (!hasProperty('WebSocket')) { // eslint-disable-line no-undef\n throw new Error('WebsocketBrowserPlugin can\\'t find a WebSocket class')\n }\n\n /**\n * @type {object} options\n * @private\n */\n this.options = Object.assign({}, defaultOptions, customOptions)\n\n /**\n * @type {object} socket\n * @private\n */\n this.socket = null\n /**\n * @type {number} socketStatus\n * @private\n */\n this.socketStatus = STATUS.IS_NOT_INITIALIZED\n\n /**\n * @type {function} notify\n * @private\n */\n this.notify = () => {}\n }\n\n /**\n * Internal method to hook into osc library's\n * EventHandler notify method\n * @param {function} fn Notify callback\n * @private\n */\n registerNotify(fn) {\n this.notify = fn\n }\n\n /**\n * Returns the current status of the connection\n * @return {number} Status identifier\n */\n status() {\n return this.socketStatus\n }\n\n /**\n * Connect to a Websocket server. Defaults to global options\n * @param {object} [customOptions] Custom options\n * @param {string} [customOptions.host] Hostname of Websocket server\n * @param {number} [customOptions.port] Port of Websocket server\n */\n open(customOptions = {}) {\n const options = Object.assign({}, this.options, customOptions)\n const { port, host } = options\n\n // close socket when already given\n if (this.socket) {\n this.close()\n }\n\n // create websocket client\n this.socket = new WebSocket(`ws://${host}:${port}`) // eslint-disable-line no-undef\n this.socket.binaryType = 'arraybuffer'\n this.socketStatus = STATUS.IS_CONNECTING\n\n // register events\n this.socket.onopen = () => {\n this.socketStatus = STATUS.IS_OPEN\n this.notify('open')\n }\n\n this.socket.onclose = () => {\n this.socketStatus = STATUS.IS_CLOSED\n this.notify('close')\n }\n\n this.socket.onerror = (error) => {\n this.notify('error', error)\n }\n\n this.socket.onmessage = (message) => {\n this.notify(message.data)\n }\n }\n\n /**\n * Close Websocket\n */\n close() {\n this.socketStatus = STATUS.IS_CLOSING\n this.socket.close()\n }\n\n /**\n * Send an OSC Packet, Bundle or Message to Websocket server\n * @param {Uint8Array} binary Binary representation of OSC Packet\n */\n send(binary) {\n this.socket.send(binary)\n }\n}\n","import OSCBase from '../src/osc'\n\nimport WebsocketBrowserPlugin from '../src/plugin/wsbrowser'\n\nconst defaultOptions = {\n plugin: new WebsocketBrowserPlugin(),\n}\n\nclass OSC extends OSCBase {\n constructor(options) {\n super(Object.assign({}, defaultOptions, options))\n }\n}\n\nOSC.WebsocketBrowserPlugin = WebsocketBrowserPlugin\n\nexport default OSC\n"],"names":["isInt","n","Number","isFloat","isString","isArray","Object","prototype","toString","call","isObject","isFunction","isBlob","Uint8Array","isDate","Date","isUndefined","pad","hasProperty","name","hasOwnProperty","global","window","dataView","obj","buffer","DataView","ArrayBuffer","typeTag","item","Error","prepareAddress","address","join","length","slice","prepareRegExPattern","str","pattern","replace","EncodeHelper","data","byteLength","pack","push","result","offset","forEach","set","Atomic","value","method","initialOffset","AtomicInt32","AtomicFloat32","STR_SLICE_SIZE","STR_ENCODING","charCodesToString","charCodes","Buffer","from","TextDecoder","decode","Int8Array","i","String","fromCharCode","apply","AtomicString","terminated","charCodeAt","charcode","getUint8","AtomicBlob","setInt32","getInt32","Message","types","args","shift","map","encoder","Helper","add","argument","merge","unpack","next","type","SECONDS_70_YEARS","TWO_POWER_32","Timetag","seconds","fractions","milliseconds","rounded","Math","floor","round","AtomicTimetag","now","timetag","timestamp","getTime","getUint32","BUNDLE_TAG","Bundle","bundleElements","ms","head","packet","Packet","size","defaultOptions","EventHandler","options","assign","addressHandlers","eventHandlers","uuid","bundle","bundleItem","dispatch","message","notify","success","handler","callback","handlerKeys","keys","handlers","key","regex","RegExp","test","lastIndex","discardLateMessages","that","split","subscriptionId","haystack","some","index","id","splice","STATUS","OSC","eventHandler","plugin","registerNotify","eventName","on","off","open","status","close","send","WebsocketBrowserPlugin","customOptions","socket","socketStatus","IS_NOT_INITIALIZED","fn","port","host","WebSocket","binaryType","IS_CONNECTING","onopen","IS_OPEN","onclose","IS_CLOSED","onerror","error","onmessage","IS_CLOSING","binary","OSCBase"],"mappings":";;;;;;AAKO,SAASA,KAAT,CAAeC,CAAf,EAAkB;SAChBC,OAAOD,CAAP,MAAcA,CAAd,IAAmBA,IAAI,CAAJ,KAAU,CAApC;;AAQF,AAAO,SAASE,OAAT,CAAiBF,CAAjB,EAAoB;SAClBC,OAAOD,CAAP,MAAcA,CAAd,IAAmBA,IAAI,CAAJ,KAAU,CAApC;;AAQF,AAAO,SAASG,QAAT,CAAkBH,CAAlB,EAAqB;SACnB,OAAOA,CAAP,KAAa,QAApB;;AAQF,AAAO,SAASI,OAAT,CAAiBJ,CAAjB,EAAoB;SAClBK,OAAOC,SAAP,CAAiBC,QAAjB,CAA0BC,IAA1B,CAA+BR,CAA/B,MAAsC,gBAA7C;;AAQF,AAAO,SAASS,QAAT,CAAkBT,CAAlB,EAAqB;SACnBK,OAAOC,SAAP,CAAiBC,QAAjB,CAA0BC,IAA1B,CAA+BR,CAA/B,MAAsC,iBAA7C;;AAQF,AAAO,SAASU,UAAT,CAAoBV,CAApB,EAAuB;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AVuB;WAWlBJ,MAAL,CAAYO,UAAZ,GAAyB,aAAzB;WACKN,YAAL,GAAoBf,SAAOsB,aAA3B;WAGKR,MAAL,CAAYS,MAAZ,GAAqB,YAAM;cACpBR,YAAL,GAAoBf,SAAOwB,OAA3B;cACK7C,MAAL,CAAY,MAAZ;OAFF;WAKKmC,MAAL,CAAYW,OAAZ,GAAsB,YAAM;cACrBV,YAAL,GAAoBf,SAAO0B,SAA3B;cACK/C,MAAL,CAAY,OAAZ;OAFF;WAKKmC,MAAL,CAAYa,OAAZ,GAAsB,UAACC,KAAD,EAAW;cAC1BjD,MAAL,CAAY,OAAZ,EAAqBiD,KAArB;OADF;WAIKd,MAAL,CAAYe,SAAZ,GAAwB,UAACnD,OAAD,EAAa;cAC9BC,MAAL,CAAYD,QAAQlF,IAApB;OADF;;;;4BAQM;WACDuH,YAAL,GAAoBf,SAAO8B,UAA3B;WACKhB,MAAL,CAAYJ,KAAZ;;;;yBAOGqB,QAAQ;WACNjB,MAAL,CAAYH,IAAZ,CAAiBoB,MAAjB;;;;;;ACtIJ,IAAM/D,iBAAiB;UACb,IAAI4C,sBAAJ;CADV;IAIMX;;eACQ/B,OAAZ,EAAqB;;oGACb7G,OAAO8G,MAAP,CAAc,EAAd,EAAkBH,cAAlB,EAAkCE,OAAlC,CADa;;;EADL8D;AAMlB/B,IAAIW,sBAAJ,GAA6BA,sBAA7B,CAEA;;;;"} \ No newline at end of file +{"version":3,"file":"osc.js","sources":["../src/common/utils.js","../src/common/helpers.js","../src/atomic.js","../src/atomic/int32.js","../src/atomic/float32.js","../src/atomic/string.js","../src/atomic/blob.js","../src/message.js","../src/atomic/timetag.js","../src/bundle.js","../src/packet.js","../src/events.js","../src/osc.js","../src/plugin/wsbrowser.js","../entry/osc.browser.js"],"sourcesContent":["/**\n * Check if given object is an integer number\n * @param {*} n\n * @return {boolean}\n */\nexport function isInt(n) {\n return Number(n) === n && n % 1 === 0\n}\n\n/**\n * Check if given object is a float number\n * @param {*} n\n * @return {boolean}\n */\nexport function isFloat(n) {\n return Number(n) === n && n % 1 !== 0\n}\n\n/**\n * Check if given object is a string\n * @param {*} n\n * @return {boolean}\n */\nexport function isString(n) {\n return typeof n === 'string'\n}\n\n/**\n * Check if given object is an array\n * @param {*} n\n * @return {boolean}\n */\nexport function isArray(n) {\n return Object.prototype.toString.call(n) === '[object Array]'\n}\n\n/**\n * Check if given object is an object\n * @param {*} n\n * @return {boolean}\n */\nexport function isObject(n) {\n return Object.prototype.toString.call(n) === '[object Object]'\n}\n\n/**\n * Check if given object is a function\n * @param {*} n\n * @return {boolean}\n */\nexport function isFunction(n) {\n return typeof n === 'function'\n}\n\n/**\n * Check if given object is a Uint8Array\n * @param {*} n\n * @return {boolean}\n */\nexport function isBlob(n) {\n return n instanceof Uint8Array\n}\n\n/**\n * Check if given object is a Date\n * @param {*} n\n * @return {boolean}\n */\nexport function isDate(n) {\n return n instanceof Date\n}\n\n/**\n * Check if given object is undefined\n * @param {*} n\n * @return {boolean}\n */\nexport function isUndefined(n) {\n return typeof n === 'undefined'\n}\n\n/**\n * Return the next multiple of four\n * @param {number} n\n */\nexport function pad(n) {\n return (n + 3) & ~0x03\n}\n\n/**\n * Checks if environment provides a feature\n * @param {string} name Name of needed feature\n * @return {boolean}\n */\nexport function hasProperty(name) {\n return Object.prototype.hasOwnProperty.call(\n (typeof global !== 'undefined' ? global : window), // eslint-disable-line no-undef\n name\n )\n}\n\n/**\n * Wrap binary data in DataView\n * @param {*} obj\n * @return {DataView}\n */\nexport function dataView(obj) {\n if (obj.buffer) {\n return new DataView(obj.buffer)\n } else if (obj instanceof ArrayBuffer) {\n return new DataView(obj)\n }\n\n return new DataView(new Uint8Array(obj))\n}\n","import { isArray, isInt, isFloat, isString, isBlob } from './utils'\n\n/**\n * Checks type of given object and returns the regarding OSC\n * Type tag character\n * @param {*} item Any object\n * @return {string} OSC Type tag character\n */\nexport function typeTag(item) {\n if (isInt(item)) {\n return 'i'\n } else if (isFloat(item)) {\n return 'f'\n } else if (isString(item)) {\n return 's'\n } else if (isBlob(item)) {\n return 'b'\n }\n\n throw new Error('OSC typeTag() found unknown value type')\n}\n\n/**\n * Sanitizes an OSC-ready Address Pattern\n * @param {array|string} obj Address as string or array of strings\n * @return {string} Corrected address string\n *\n * @example\n * // all calls return '/test/path' string:\n * prepareAddress('test/path')\n * prepareAddress('/test/path/')\n * prepareAddress([test, path])\n */\nexport function prepareAddress(obj) {\n let address = ''\n\n if (isArray(obj)) {\n return `/${obj.join('/')}`\n } else if (isString(obj)) {\n address = obj\n\n // remove slash at ending of address\n if (address.length > 1 && address[address.length - 1] === '/') {\n address = address.slice(0, address.length - 1)\n }\n\n // add slash at beginning of address\n if (address.length > 1 && address[0] !== '/') {\n address = `/${address}`\n }\n\n return address\n }\n\n throw new Error('OSC prepareAddress() needs addresses of type array or string')\n}\n\n/**\n * Make an OSC address pattern javascript-regex-ready\n * @param {string} str OSC address pattern\n * @return {string} Javascript RegEx string\n */\nexport function prepareRegExPattern(str) {\n let pattern\n\n if (!(isString(str))) {\n throw new Error('OSC prepareRegExPattern() needs strings')\n }\n\n pattern = str.replace(/\\./g, '\\\\.')\n pattern = pattern.replace(/\\(/g, '\\\\(')\n pattern = pattern.replace(/\\)/g, '\\\\)')\n\n pattern = pattern.replace(/\\{/g, '(')\n pattern = pattern.replace(/\\}/g, ')')\n pattern = pattern.replace(/,/g, '|')\n\n pattern = pattern.replace(/\\[!/g, '[^')\n\n pattern = pattern.replace(/\\?/g, '.')\n pattern = pattern.replace(/\\*/g, '.*')\n\n return pattern\n}\n\n/**\n * Holds a list of items and helps to merge them\n * into a single array of packed binary data\n */\nexport default class EncodeHelper {\n /**\n * Create a new EncodeHelper instance\n */\n constructor() {\n /** @type {array} data */\n this.data = []\n /** @type {number} byteLength */\n this.byteLength = 0\n }\n\n /**\n * Packs an item and adds it to the list\n * @param {*} item Any object\n * @return {EncodeHelper}\n */\n add(item) {\n const buffer = item.pack()\n this.byteLength += buffer.byteLength\n this.data.push(buffer)\n\n return this\n }\n\n /**\n * Merge all added items into one Uint8Array\n * @return {Uint8Array} Merged binary data array of all items\n */\n merge() {\n const result = new Uint8Array(this.byteLength)\n let offset = 0\n\n this.data.forEach((data) => {\n result.set(data, offset)\n offset += data.byteLength\n })\n\n return result\n }\n}\n","import { isUndefined } from './common/utils'\n\n/**\n * Base class for OSC Atomic Data Types\n */\nexport default class Atomic {\n /**\n * Create an Atomic instance\n * @param {*} [value] Initial value of any type\n */\n constructor(value) {\n /** @type {*} value */\n this.value = value\n /** @type {number} offset */\n this.offset = 0\n }\n\n /**\n * Interpret the given value of this entity as packed binary data\n * @param {string} method The DataView method to write to the ArrayBuffer\n * @param {number} byteLength Size of array in bytes\n * @return {Uint8Array} Packed binary data\n */\n pack(method, byteLength) {\n if (!(method && byteLength)) {\n throw new Error('OSC Atomic cant\\'t be packed without given method or byteLength')\n }\n\n const data = new Uint8Array(byteLength)\n const dataView = new DataView(data.buffer)\n\n if (isUndefined(this.value)) {\n throw new Error('OSC Atomic cant\\'t be encoded with empty value')\n }\n\n // use DataView to write to ArrayBuffer\n dataView[method](this.offset, this.value, false)\n\n // always return binary Uint8Array after packing\n return data\n }\n\n /**\n * Unpack binary data from DataView according to the given format\n * @param {DataView} dataView The DataView holding the binary representation of the value\n * @param {string} method The DataView method to read the format from the ArrayBuffer\n * @param {number} byteLength Size of array in bytes\n * @param {number} [initialOffset=0] Offset of DataView before unpacking\n * @return {number} Offset after unpacking\n */\n unpack(dataView, method, byteLength, initialOffset = 0) {\n if (!(dataView && method && byteLength)) {\n throw new Error('OSC Atomic cant\\'t be unpacked without given dataView, method or byteLength')\n }\n\n if (!(dataView instanceof DataView)) {\n throw new Error('OSC Atomic expects an instance of type DataView')\n }\n\n // use DataView to read from ArrayBuffer and add offset\n this.value = dataView[method](initialOffset, false)\n this.offset = initialOffset + byteLength\n\n // always return offset number after unpacking\n return this.offset\n }\n}\n","import { isInt } from '../common/utils'\n\nimport Atomic from '../atomic'\n\n/**\n * 32-bit big-endian two's complement integer OSC Atomic Data Type\n */\nexport default class AtomicInt32 extends Atomic {\n /**\n * Create an AtomicInt32 instance\n * @param {number} [value] Initial integer value\n */\n constructor(value) {\n if (value && !isInt(value)) {\n throw new Error('OSC AtomicInt32 constructor expects value of type number')\n }\n\n super(value)\n }\n\n /**\n * Interpret the given number as packed binary data\n * @return {Uint8Array} Packed binary data\n */\n pack() {\n return super.pack('setInt32', 4)\n }\n\n /**\n * Unpack binary data from DataView and read a Int32 number\n * @param {DataView} dataView The DataView holding the binary representation of the value\n * @param {number} [initialOffset=0] Offset of DataView before unpacking\n * @return {number} Offset after unpacking\n */\n unpack(dataView, initialOffset = 0) {\n return super.unpack(dataView, 'getInt32', 4, initialOffset)\n }\n}\n","import { isFloat } from '../common/utils'\n\nimport Atomic from '../atomic'\n\n/**\n * 32-bit big-endian IEEE 754 floating point number OSC Atomic Data Type\n */\nexport default class AtomicFloat32 extends Atomic {\n /**\n * Create an AtomicFloat32 instance\n * @param {number} [value] Float number\n */\n constructor(value) {\n if (value && !isFloat(value)) {\n throw new Error('OSC AtomicFloat32 constructor expects value of type float')\n }\n\n super(value)\n }\n\n /**\n * Interpret the given number as packed binary data\n * @return {Uint8Array} Packed binary data\n */\n pack() {\n return super.pack('setFloat32', 4)\n }\n\n /**\n * Unpack binary data from DataView and read a Float32 number\n * @param {DataView} dataView The DataView holding the binary representation of the value\n * @param {number} [initialOffset=0] Offset of DataView before unpacking\n * @return {number} Offset after unpacking\n */\n unpack(dataView, initialOffset = 0) {\n return super.unpack(dataView, 'getFloat32', 4, initialOffset)\n }\n}\n","import { pad, isString, isUndefined, hasProperty } from '../common/utils'\n\nimport Atomic from '../atomic'\n\n/** Slice size of large strings for fallback method */\nconst STR_SLICE_SIZE = 65537\n\n/** Text encoding format */\nconst STR_ENCODING = 'utf-8'\n\n/**\n * Helper method to decode a string using different methods depending on environment\n * @param {array} charCodes Array of char codes\n * @return {string} Decoded string\n */\nfunction charCodesToString(charCodes) {\n // Use these methods to be able to convert large strings\n if (hasProperty('Buffer')) {\n return Buffer.from(charCodes).toString(STR_ENCODING)\n } else if (hasProperty('TextDecoder')) {\n return new TextDecoder(STR_ENCODING) // eslint-disable-line no-undef\n .decode(new Int8Array(charCodes))\n }\n\n // Fallback method\n let str = ''\n\n for (let i = 0; i < charCodes.length; i += STR_SLICE_SIZE) {\n str += String.fromCharCode.apply(\n null,\n charCodes.slice(i, i + STR_SLICE_SIZE)\n )\n }\n\n return str\n}\n\n/**\n * A sequence of non-null ASCII characters OSC Atomic Data Type\n */\nexport default class AtomicString extends Atomic {\n /**\n * Create an AtomicString instance\n * @param {string} [value] Initial string value\n */\n constructor(value) {\n if (value && !isString(value)) {\n throw new Error('OSC AtomicString constructor expects value of type string')\n }\n\n super(value)\n }\n\n /**\n * Interpret the given string as packed binary data\n * @return {Uint8Array} Packed binary data\n */\n pack() {\n if (isUndefined(this.value)) {\n throw new Error('OSC AtomicString can not be encoded with empty value')\n }\n\n // add 0-3 null characters for total number of bits a multiple of 32\n const terminated = `${this.value}\\u0000`\n const byteLength = pad(terminated.length)\n\n const buffer = new Uint8Array(byteLength)\n\n for (let i = 0; i < terminated.length; i += 1) {\n buffer[i] = terminated.charCodeAt(i)\n }\n\n return buffer\n }\n\n /**\n * Unpack binary data from DataView and read a string\n * @param {DataView} dataView The DataView holding the binary representation of the string\n * @param {number} [initialOffset=0] Offset of DataView before unpacking\n * @return {number} Offset after unpacking\n */\n unpack(dataView, initialOffset = 0) {\n if (!(dataView instanceof DataView)) {\n throw new Error('OSC AtomicString expects an instance of type DataView')\n }\n\n let offset = initialOffset\n let charcode\n const charCodes = []\n\n for (; offset < dataView.byteLength; offset += 1) {\n charcode = dataView.getUint8(offset)\n\n // check for terminating null character\n if (charcode !== 0) {\n charCodes.push(charcode)\n } else {\n offset += 1\n break\n }\n }\n\n if (offset === dataView.length) {\n throw new Error('OSC AtomicString found a malformed OSC string')\n }\n\n /** @type {number} offset */\n this.offset = pad(offset)\n /** @type {string} value */\n this.value = charCodesToString(charCodes)\n\n return this.offset\n }\n}\n","import { pad, isBlob, isUndefined } from '../common/utils'\n\nimport Atomic from '../atomic'\n\n/**\n * 8-bit bytes of arbitrary binary data OSC Atomic Data Type\n */\nexport default class AtomicBlob extends Atomic {\n /**\n * Create an AtomicBlob instance\n * @param {Uint8Array} [value] Binary data\n */\n constructor(value) {\n if (value && !isBlob(value)) {\n throw new Error('OSC AtomicBlob constructor expects value of type Uint8Array')\n }\n\n super(value)\n }\n\n /**\n * Interpret the given blob as packed binary data\n * @return {Uint8Array} Packed binary data\n */\n pack() {\n if (isUndefined(this.value)) {\n throw new Error('OSC AtomicBlob can not be encoded with empty value')\n }\n\n const byteLength = pad(this.value.byteLength)\n const data = new Uint8Array(byteLength + 4)\n const dataView = new DataView(data.buffer)\n\n // an int32 size count\n dataView.setInt32(0, this.value.byteLength, false)\n // followed by 8-bit bytes of arbitrary binary data\n data.set(this.value, 4)\n\n return data\n }\n\n /**\n * Unpack binary data from DataView and read a blob\n * @param {DataView} dataView The DataView holding the binary representation of the blob\n * @param {number} [initialOffset=0] Offset of DataView before unpacking\n * @return {number} Offset after unpacking\n */\n unpack(dataView, initialOffset = 0) {\n if (!(dataView instanceof DataView)) {\n throw new Error('OSC AtomicBlob expects an instance of type DataView')\n }\n\n const byteLength = dataView.getInt32(initialOffset, false)\n\n /** @type {Uint8Array} value */\n this.value = new Uint8Array(dataView.buffer, initialOffset + 4, byteLength)\n /** @type {number} offset */\n this.offset = pad(initialOffset + 4 + byteLength)\n\n return this.offset\n }\n}\n","import {\n isArray,\n isBlob,\n isFloat,\n isInt,\n isString,\n isUndefined,\n} from './common/utils'\n\nimport Helper, { typeTag, prepareAddress } from './common/helpers'\n\nimport AtomicInt32 from './atomic/int32'\nimport AtomicFloat32 from './atomic/float32'\nimport AtomicString from './atomic/string'\nimport AtomicBlob from './atomic/blob'\n\n/**\n * An OSC message consists of an OSC Address Pattern followed\n * by an OSC Type Tag String followed by zero or more OSC Arguments\n */\nexport default class Message {\n /**\n * Create a Message instance\n * @param {array|string} args Address\n * @param {...*} args OSC Atomic Data Types\n *\n * @example\n * const message = new Message(['test', 'path'], 50, 100.52, 'test')\n *\n * @example\n * const message = new Message('/test/path', 51.2)\n */\n constructor(...args) {\n /**\n * @type {number} offset\n * @private\n */\n this.offset = 0\n /** @type {string} address */\n this.address = ''\n /** @type {string} types */\n this.types = ''\n /** @type {array} args */\n this.args = []\n\n if (args.length > 0) {\n if (!(isString(args[0]) || isArray(args[0]))) {\n throw new Error('OSC Message constructor first argument (address) must be a string or array')\n }\n\n this.address = prepareAddress(args.shift())\n this.types = args.map(item => typeTag(item)).join('')\n this.args = args\n }\n }\n\n /**\n * Add an OSC Atomic Data Type to the list of elements\n * @param {*} item\n */\n add(item) {\n if (isUndefined(item)) {\n throw new Error('OSC Message needs a valid OSC Atomic Data Type')\n }\n\n this.args.push(item)\n this.types += typeTag(item)\n }\n\n /**\n * Interpret the Message as packed binary data\n * @return {Uint8Array} Packed binary data\n */\n pack() {\n if (this.address.length === 0 || this.address[0] !== '/') {\n throw new Error('OSC Message has an invalid address')\n }\n\n const encoder = new Helper()\n\n // OSC Address Pattern and Type string\n encoder.add(new AtomicString(this.address))\n encoder.add(new AtomicString(`,${this.types}`))\n\n // followed by zero or more OSC Arguments\n if (this.args.length > 0) {\n let argument\n\n this.args.forEach((value) => {\n if (isInt(value)) {\n argument = new AtomicInt32(value)\n } else if (isFloat(value)) {\n argument = new AtomicFloat32(value)\n } else if (isString(value)) {\n argument = new AtomicString(value)\n } else if (isBlob(value)) {\n argument = new AtomicBlob(value)\n } else {\n throw new Error('OSC Message found unknown argument type')\n }\n\n encoder.add(argument)\n })\n }\n\n return encoder.merge()\n }\n\n /**\n * Unpack binary data to read a Message\n * @param {DataView} dataView The DataView holding the binary representation of a Message\n * @param {number} [initialOffset=0] Offset of DataView before unpacking\n * @return {number} Offset after unpacking\n */\n unpack(dataView, initialOffset = 0) {\n if (!(dataView instanceof DataView)) {\n throw new Error('OSC Message expects an instance of type DataView.')\n }\n\n // read address pattern\n const address = new AtomicString()\n address.unpack(dataView, initialOffset)\n\n // read type string\n const types = new AtomicString()\n types.unpack(dataView, address.offset)\n\n if (address.value.length === 0 || address.value[0] !== '/') {\n throw new Error('OSC Message found malformed or missing address string')\n }\n\n if (types.value.length === 0 && types.value[0] !== ',') {\n throw new Error('OSC Message found malformed or missing type string')\n }\n\n let { offset } = types\n let next\n let type\n\n const args = []\n\n // read message arguments (OSC Atomic Data Types)\n for (let i = 1; i < types.value.length; i += 1) {\n type = types.value[i]\n\n if (type === 'i') {\n next = new AtomicInt32()\n } else if (type === 'f') {\n next = new AtomicFloat32()\n } else if (type === 's') {\n next = new AtomicString()\n } else if (type === 'b') {\n next = new AtomicBlob()\n } else {\n throw new Error('OSC Message found non-standard argument type')\n }\n\n offset = next.unpack(dataView, offset)\n args.push(next.value)\n }\n\n this.offset = offset\n this.address = address.value\n this.types = types.value\n this.args = args\n\n return this.offset\n }\n}\n","import { isInt, isDate, isUndefined } from '../common/utils'\n\nimport Atomic from '../atomic'\n\n/** 70 years in seconds */\nexport const SECONDS_70_YEARS = 2208988800\n/** 2^32 */\nexport const TWO_POWER_32 = 4294967296\n\n/**\n * Timetag helper class for representing NTP timestamps\n * and conversion between them and javascript representation\n */\nexport class Timetag {\n /**\n * Create a Timetag instance\n * @param {number} [seconds=0] Initial NTP *seconds* value\n * @param {number} [fractions=0] Initial NTP *fractions* value\n */\n constructor(seconds = 0, fractions = 0) {\n if (!(isInt(seconds) && isInt(fractions))) {\n throw new Error('OSC Timetag constructor expects values of type integer number')\n }\n\n /** @type {number} seconds */\n this.seconds = seconds\n /** @type {number} fractions */\n this.fractions = fractions\n }\n\n /**\n * Converts from NTP to JS representation and back\n * @param {number} [milliseconds] Converts from JS milliseconds to NTP.\n * Leave empty for converting from NTP to JavaScript representation\n * @return {number} Javascript timestamp\n */\n timestamp(milliseconds) {\n let seconds\n\n if (typeof milliseconds === 'number') {\n seconds = milliseconds / 1000\n const rounded = Math.floor(seconds)\n\n this.seconds = rounded + SECONDS_70_YEARS\n this.fractions = Math.round(TWO_POWER_32 * (seconds - rounded))\n\n return milliseconds\n }\n\n seconds = this.seconds - SECONDS_70_YEARS\n return (seconds + Math.round(this.fractions / TWO_POWER_32)) * 1000\n }\n}\n\n/**\n * 64-bit big-endian fixed-point time tag, semantics\n * defined below OSC Atomic Data Type\n */\nexport default class AtomicTimetag extends Atomic {\n /**\n * Create a AtomicTimetag instance\n * @param {number|Timetag|Date} [value] Initial date, leave empty if\n * you want it to be the current date\n */\n constructor(value = Date.now()) {\n let timetag = new Timetag()\n\n if (value instanceof Timetag) {\n timetag = value\n } else if (isInt(value)) {\n timetag.timestamp(value)\n } else if (isDate(value)) {\n timetag.timestamp(value.getTime())\n }\n\n super(timetag)\n }\n\n /**\n * Interpret the given timetag as packed binary data\n * @return {Uint8Array} Packed binary data\n */\n pack() {\n if (isUndefined(this.value)) {\n throw new Error('OSC AtomicTimetag can not be encoded with empty value')\n }\n\n const { seconds, fractions } = this.value\n const data = new Uint8Array(8)\n const dataView = new DataView(data.buffer)\n\n dataView.setInt32(0, seconds, false)\n dataView.setInt32(4, fractions, false)\n\n return data\n }\n\n /**\n * Unpack binary data from DataView and read a timetag\n * @param {DataView} dataView The DataView holding the binary representation of the timetag\n * @param {number} [initialOffset=0] Offset of DataView before unpacking\n * @return {number} Offset after unpacking\n */\n unpack(dataView, initialOffset = 0) {\n if (!(dataView instanceof DataView)) {\n throw new Error('OSC AtomicTimetag expects an instance of type DataView')\n }\n\n const seconds = dataView.getUint32(initialOffset, false)\n const fractions = dataView.getUint32(initialOffset + 4, false)\n\n /** @type {Timetag} value */\n this.value = new Timetag(seconds, fractions)\n /** @type {number} offset */\n this.offset = initialOffset + 8\n\n return this.offset\n }\n}\n","import { isArray, isInt } from './common/utils'\nimport EncodeHelper from './common/helpers'\n\nimport Packet from './packet'\nimport Message from './message'\nimport AtomicString from './atomic/string'\nimport AtomicInt32 from './atomic/int32'\nimport AtomicTimetag from './atomic/timetag'\n\n/** OSC Bundle string */\nexport const BUNDLE_TAG = '#bundle'\n\n/**\n * An OSC Bundle consist of a Timetag and one or many Bundle Elements.\n * The elements are either OSC Messages or more OSC Bundles\n */\nexport default class Bundle {\n /**\n * Create a Bundle instance\n * @param {...*} [args] Timetag and elements. See examples for options\n *\n * @example\n * const bundle = new Bundle(new Date() + 500)\n *\n * @example\n * const message = new Message('/test/path', 51.2)\n * const anotherBundle = new Bundle([message], Date.now() + 1500)\n *\n * @example\n * const message = new Message('/test/path', 51.2)\n * const anotherMessage = new Message('/test/message', 'test', 12)\n * const anotherBundle = new Bundle(message, anotherMessage)\n */\n constructor(...args) {\n /**\n * @type {number} offset\n * @private\n */\n this.offset = 0\n /** @type {AtomicTimetag} timetag */\n this.timetag = new AtomicTimetag()\n /** @type {array} bundleElements */\n this.bundleElements = []\n\n if (args.length > 0) {\n // first argument is an Date or js timestamp (number)\n if (args[0] instanceof Date || isInt(args[0])) {\n this.timetag = new AtomicTimetag(args[0])\n } else if (isArray(args[0])) {\n // first argument is an Array of Bundle elements\n args[0].forEach((item) => {\n this.add(item)\n })\n\n // second argument is an Date or js timestamp (number)\n if (args.length > 1 && (args[1] instanceof Date || isInt(args[0]))) {\n this.timetag = new AtomicTimetag(args[1])\n }\n } else {\n // take all arguments as Bundle elements\n args.forEach((item) => {\n this.add(item)\n })\n }\n }\n }\n\n /**\n * Take a JavaScript timestamp to set the Bundle's timetag\n * @param {number} ms JS timestamp in milliseconds\n *\n * @example\n * const bundle = new Bundle()\n * bundle.timestamp(Date.now() + 5000) // in 5 seconds\n */\n timestamp(ms) {\n if (!isInt(ms)) {\n throw new Error('OSC Bundle needs an integer for setting the timestamp')\n }\n\n this.timetag = new AtomicTimetag(ms)\n }\n\n /**\n * Add a Message or Bundle to the list of elements\n * @param {Bundle|Message} item\n */\n add(item) {\n if (!(item instanceof Message || item instanceof Bundle)) {\n throw new Error('OSC Bundle contains only Messages and Bundles')\n }\n\n this.bundleElements.push(item)\n }\n\n /**\n * Interpret the Bundle as packed binary data\n * @return {Uint8Array} Packed binary data\n */\n pack() {\n const encoder = new EncodeHelper()\n\n // an OSC Bundle consists of the OSC-string \"#bundle\"\n encoder.add(new AtomicString(BUNDLE_TAG))\n\n // followed by an OSC Time Tag\n if (!this.timetag) {\n this.timetag = new AtomicTimetag()\n }\n\n encoder.add(this.timetag)\n\n // followed by zero or more OSC Bundle Elements\n this.bundleElements.forEach((item) => {\n encoder.add(new AtomicInt32(item.pack().byteLength))\n encoder.add(item)\n })\n\n return encoder.merge()\n }\n\n /**\n * Unpack binary data to read a Bundle\n * @param {DataView} dataView The DataView holding the binary representation of a Bundle\n * @param {number} [initialOffset=0] Offset of DataView before unpacking\n * @return {number} Offset after unpacking\n */\n unpack(dataView, initialOffset = 0) {\n if (!(dataView instanceof DataView)) {\n throw new Error('OSC Bundle expects an instance of type DataView')\n }\n\n // read the beginning bundle string\n const head = new AtomicString()\n head.unpack(dataView, initialOffset)\n\n if (head.value !== BUNDLE_TAG) {\n throw new Error('OSC Bundle does not contain a valid #bundle head')\n }\n\n // read the timetag\n const timetag = new AtomicTimetag()\n let offset = timetag.unpack(dataView, head.offset)\n\n // read the bundle elements\n this.bundleElements = []\n\n while (offset < dataView.byteLength) {\n const packet = new Packet()\n const size = new AtomicInt32()\n\n offset = size.unpack(dataView, offset)\n offset = packet.unpack(dataView, offset, this.timetag)\n\n this.bundleElements.push(packet.value)\n }\n\n this.offset = offset\n this.timetag = timetag\n\n return this.offset\n }\n}\n","import Bundle, { BUNDLE_TAG } from './bundle'\nimport Message from './message'\nimport AtomicString from './atomic/string'\n\n/**\n * The unit of transmission of OSC is an OSC Packet. The contents\n * of an OSC packet must be either an OSC Message or an OSC Bundle\n */\nexport default class Packet {\n /**\n * Create a Packet instance holding a Message or Bundle\n * @param {Message|Bundle} [value] Initial Packet value\n */\n constructor(value) {\n if (value && !(value instanceof Message || value instanceof Bundle)) {\n throw new Error('OSC Packet value has to be Message or Bundle')\n }\n\n /** @type {Message|Bundle} value */\n this.value = value\n /**\n * @type {number} offset\n * @private\n */\n this.offset = 0\n }\n\n /**\n * Packs the Packet value. This implementation is more like\n * a wrapper due to OSC specifications, you could also skip the\n * Packet and directly work with the Message or Bundle instance\n * @return {Uint8Array} Packed binary data\n *\n * @example\n * const message = new Message('/test/path', 21.5, 'test')\n * const packet = new Packet(message)\n * const packetBinary = packet.pack() // then send it via udp etc.\n *\n * // or skip the Packet for convenience\n * const messageBinary = message.pack()\n */\n pack() {\n if (!this.value) {\n throw new Error('OSC Packet can not be encoded with empty body')\n }\n\n return this.value.pack()\n }\n\n /**\n * Unpack binary data from DataView to read Messages or Bundles\n * @param {DataView} dataView The DataView holding a binary representation of a Packet\n * @param {number} [initialOffset=0] Offset of DataView before unpacking\n * @return {number} Offset after unpacking\n */\n unpack(dataView, initialOffset = 0) {\n if (!(dataView instanceof DataView)) {\n throw new Error('OSC Packet expects an instance of type DataView')\n }\n\n if (dataView.byteLength % 4 !== 0) {\n throw new Error('OSC Packet byteLength has to be a multiple of four')\n }\n\n const head = new AtomicString()\n head.unpack(dataView, initialOffset)\n\n let item\n\n // check if Packet is a Bundle or a Message\n if (head.value === BUNDLE_TAG) {\n item = new Bundle()\n } else {\n item = new Message()\n }\n\n item.unpack(dataView, initialOffset)\n\n this.offset = item.offset\n this.value = item\n\n return this.offset\n }\n}\n","import { isArray, isString, isInt, isFunction, dataView } from './common/utils'\nimport { prepareAddress, prepareRegExPattern } from './common/helpers'\n\nimport Packet from './packet'\nimport Bundle from './bundle'\nimport Message from './message'\n\n/**\n * Default options\n * @private\n */\nconst defaultOptions = {\n discardLateMessages: false,\n}\n\n/**\n * EventHandler to notify listeners on matching OSC messages and\n * status changes of plugins\n */\nexport default class EventHandler {\n /**\n * Create an EventHandler instance\n * @param {object} options Custom options\n */\n constructor(options) {\n /**\n * @type {object} options\n * @private\n */\n this.options = Object.assign({}, defaultOptions, options)\n /**\n * @type {array} addressHandlers\n * @private\n */\n this.addressHandlers = []\n /**\n * @type {object} eventHandlers\n * @private\n */\n this.eventHandlers = {\n open: [],\n error: [],\n close: [],\n }\n /**\n * @type {number} uuid\n * @private\n */\n this.uuid = 0\n }\n\n /**\n * Internally used method to dispatch OSC Packets. Extracts\n * given Timetags and dispatches them accordingly\n * @param {Packet} packet\n * @return {boolean} Success state\n * @private\n */\n dispatch(packet) {\n if (!(packet instanceof Packet)) {\n throw new Error('OSC EventHander dispatch() accepts only arguments of type Packet')\n }\n\n if (!packet.value) {\n throw new Error('OSC EventHander dispatch() can\\'t read empty Packets')\n }\n\n if (packet.value instanceof Bundle) {\n const bundle = packet.value\n\n return bundle.bundleElements.forEach((bundleItem) => {\n if (bundleItem instanceof Bundle) {\n if (bundle.timetag.value.timestamp() < bundleItem.timetag.value.timestamp()) {\n throw new Error('OSC Bundle timestamp is older than the timestamp of enclosed Bundles')\n }\n return this.dispatch(bundleItem)\n } else if (bundleItem instanceof Message) {\n const message = bundleItem\n return this.notify(\n message.address,\n message,\n bundle.timetag.value.timestamp()\n )\n }\n\n throw new Error('OSC EventHander dispatch() can\\'t dispatch unknown Packet value')\n })\n } else if (packet.value instanceof Message) {\n const message = packet.value\n return this.notify(message.address, message)\n }\n\n throw new Error('OSC EventHander dispatch() can\\'t dispatch unknown Packet value')\n }\n\n /**\n * Internally used method to invoke listener callbacks. Uses regular\n * expression pattern matching for OSC addresses\n * @param {string} name OSC address or event name\n * @param {*} [data] The data of the event\n * @return {boolean} Success state\n * @private\n */\n call(name, data) {\n let success = false\n\n // call event handlers\n if (isString(name) && name in this.eventHandlers) {\n this.eventHandlers[name].forEach((handler) => {\n handler.callback(data)\n success = true\n })\n\n return success\n }\n\n // call address handlers\n const handlerKeys = Object.keys(this.addressHandlers)\n const handlers = this.addressHandlers\n\n handlerKeys.forEach((key) => {\n const regex = new RegExp(prepareRegExPattern(prepareAddress(name)), 'g')\n const test = regex.test(key)\n\n // found a matching address in our callback handlers\n if (test && key.length === regex.lastIndex) {\n handlers[key].forEach((handler) => {\n handler.callback(data)\n success = true\n })\n }\n })\n\n return success\n }\n\n /**\n * Notify the EventHandler of incoming OSC messages or status\n * changes (*open*, *close*, *error*). Handles OSC address patterns\n * and executes timed messages. Use binary arrays when\n * handling directly incoming network data. Packet's or Messages can\n * also be used\n * @param {...*} args\n * The OSC address pattern / event name as string}. For convenience and\n * Plugin API communication you can also use Message or Packet instances\n * or ArrayBuffer, Buffer instances (low-level access). The latter will\n * automatically be unpacked\n * When using a string you can also pass on data as a second argument\n * (any type). All regarding listeners will be notified with this data.\n * As a third argument you can define a javascript timestamp (number or\n * Date instance) for timed notification of the listeners.\n * @return {boolean} Success state of notification\n *\n * @example\n * const socket = dgram.createSocket('udp4')\n * socket.on('message', (message) => {\n * this.notify(message)\n * })\n *\n * @example\n * this.notify('error', error.message)\n *\n * @example\n * const message = new OSC.Message('/test/path', 55)\n * this.notify(message)\n *\n * @example\n * const message = new OSC.Message('/test/path', 55)\n * // override timestamp\n * this.notify(message.address, message, Date.now() + 5000)\n */\n notify(...args) {\n if (args.length === 0) {\n throw new Error('OSC EventHandler can not be called without any argument')\n }\n\n // check for incoming dispatchable OSC data\n if (args[0] instanceof Packet) {\n return this.dispatch(args[0])\n } else if (args[0] instanceof Bundle || args[0] instanceof Message) {\n return this.dispatch(new Packet(args[0]))\n } else if (!isString(args[0])) {\n const packet = new Packet()\n packet.unpack(dataView(args[0]))\n return this.dispatch(packet)\n }\n\n const name = args[0]\n\n // data argument\n let data = null\n\n if (args.length > 1) {\n data = args[1]\n }\n\n // timestamp argument\n let timestamp = null\n\n if (args.length > 2) {\n if (isInt(args[2])) {\n timestamp = args[2]\n } else if (args[2] instanceof Date) {\n timestamp = args[2].getTime()\n } else {\n throw new Error('OSC EventHandler timestamp has to be a number or Date')\n }\n }\n\n // notify now or later\n if (timestamp) {\n const now = Date.now()\n\n // is message outdated?\n if (now > timestamp) {\n if (!this.options.discardLateMessages) {\n return this.call(name, data)\n }\n }\n\n // notify later\n const that = this\n\n setTimeout(() => {\n that.call(name, data)\n }, timestamp - now)\n\n return true\n }\n\n return this.call(name, data)\n }\n\n /**\n * Subscribe to a new address or event you want to listen to\n * @param {string} name The OSC address or event name\n * @param {function} callback Callback function on notification\n * @return {number} Subscription identifier (needed to unsubscribe)\n */\n on(name, callback) {\n if (!(isString(name) || isArray(name))) {\n throw new Error('OSC EventHandler accepts only strings or arrays for address patterns')\n }\n\n if (!isFunction(callback)) {\n throw new Error('OSC EventHandler callback has to be a function')\n }\n\n // get next id\n this.uuid += 1\n\n // prepare handler\n const handler = {\n id: this.uuid,\n callback,\n }\n\n // register event listener\n if (isString(name) && name in this.eventHandlers) {\n this.eventHandlers[name].push(handler)\n return this.uuid\n }\n\n // register address listener\n const address = prepareAddress(name)\n const regex = new RegExp(/[#*\\s[\\],/{}|?]/g)\n\n if (regex.test(address.split('/').join(''))) {\n throw new Error('OSC EventHandler address string contains invalid characters')\n }\n\n if (!(address in this.addressHandlers)) {\n this.addressHandlers[address] = []\n }\n\n this.addressHandlers[address].push(handler)\n\n return this.uuid\n }\n\n /**\n * Unsubscribe listener from event notification or address handler\n * @param {string} name The OSC address or event name\n * @param {number} subscriptionId Subscription id to identify the handler\n * @return {boolean} Success state\n */\n off(name, subscriptionId) {\n if (!(isString(name) || isArray(name))) {\n throw new Error('OSC EventHandler accepts only strings or arrays for address patterns')\n }\n\n if (!isInt(subscriptionId)) {\n throw new Error('OSC EventHandler subscription id has to be a number')\n }\n\n let key\n let haystack\n\n // event or address listener\n if (isString(name) && name in this.eventHandlers) {\n key = name\n haystack = this.eventHandlers\n } else {\n key = prepareAddress(name)\n haystack = this.addressHandlers\n }\n\n // remove the entry\n if (key in haystack) {\n return haystack[key].some((item, index) => {\n if (item.id === subscriptionId) {\n haystack[key].splice(index, 1)\n return true\n }\n\n return false\n })\n }\n\n return false\n }\n}\n","import { isObject, isString, isFunction, isInt } from './common/utils'\n\nimport Packet from './packet'\nimport Bundle from './bundle'\nimport Message from './message'\n\nimport EventHandler from './events'\n\n/**\n * Default options\n * @private\n */\nconst defaultOptions = {\n plugin: null,\n discardLateMessages: false,\n}\n\n/**\n * Status flags\n */\nconst STATUS = {\n IS_NOT_INITIALIZED: -1,\n IS_CONNECTING: 0,\n IS_OPEN: 1,\n IS_CLOSING: 2,\n IS_CLOSED: 3,\n}\n\n/**\n * OSC interface to send OSC Packets and to listen to status-changes and\n * incoming message events. Offers a Plugin API for different network\n * protocols, defaults to a simple Websocket client for OSC communication\n * between a browser js-app and a js-node server\n *\n * @example\n * const osc = new OSC()\n *\n * osc.on('/input/test', (message) => {\n * // print incoming OSC message arguments\n * console.log(message.args)\n * })\n *\n * osc.on('open', () => {\n * const message = new Message('/test/path', 55.12, 'hello')\n * osc.send(message)\n * })\n *\n * osc.open({ host: '192.168.178.115', port: 9012 })\n */\nclass OSC {\n /**\n * Create an OSC instance with given options\n * @param {object} [options] Custom options\n * @param {boolean} [options.discardLateMessages=false] Ignore incoming\n * messages when given timetag lies in the past\n * @param {Plugin} [options.plugin=WebsocketClientPlugin] Add a connection plugin\n * to this interface, defaults to a plugin with Websocket client.\n * Open README.md for further information on how to handle plugins or\n * how to write your own with the Plugin API\n *\n * @example\n * const osc = new OSC() // default options with Websocket client\n *\n * @example\n * const osc = new OSC({ discardLateMessages: true })\n *\n * @example\n * const websocketPlugin = new OSC.WebsocketClientPlugin()\n * const osc = new OSC({ plugin: websocketPlugin })\n */\n constructor(options) {\n if (options && !isObject(options)) {\n throw new Error('OSC options argument has to be an object.')\n }\n\n /**\n * @type {object} options\n * @private\n */\n this.options = Object.assign({}, defaultOptions, options)\n /**\n * @type {EventHandler} eventHandler\n * @private\n */\n this.eventHandler = new EventHandler({\n discardLateMessages: this.options.discardLateMessages,\n })\n\n // pass EventHandler's notify() to plugin\n const { eventHandler } = this\n if (this.options.plugin && this.options.plugin.registerNotify) {\n this.options.plugin.registerNotify((...args) => eventHandler.notify(...args))\n }\n }\n\n /**\n * Listen to a status-change event or incoming OSC message with\n * address pattern matching\n * @param {string} eventName Event name or OSC address pattern\n * @param {function} callback Function which is called on notification\n * @return {number} Subscription id (needed to unsubscribe)\n *\n * @example\n * // will be called when server receives /in!trument/* for example\n * osc.on('/instrument/1', (message) => {\n * console.log(message)\n * })\n *\n * @example\n * // will be called on network socket error\n * osc.on('error', (message) => {\n * console.log(message)\n * })\n */\n on(eventName, callback) {\n if (!(isString(eventName) && isFunction(callback))) {\n throw new Error('OSC on() needs event- or address string and callback function')\n }\n\n return this.eventHandler.on(eventName, callback)\n }\n\n /**\n * Unsubscribe an event listener\n * @param {string} eventName Event name or OSC address pattern\n * @param {number} subscriptionId The subscription id\n * @return {boolean} Success state\n *\n * @example\n * const listenerId = osc.on('error', (message) => {\n * console.log(message)\n * })\n * osc.off('error', listenerId) // unsubscribe from error event\n */\n off(eventName, subscriptionId) {\n if (!(isString(eventName) && isInt(subscriptionId))) {\n throw new Error('OSC off() needs string and number (subscriptionId) to unsubscribe')\n }\n\n return this.eventHandler.off(eventName, subscriptionId)\n }\n\n /**\n * Open network socket with plugin. This method is used by\n * plugins and is not available without (see Plugin API for more information)\n * @param {object} [options] Custom global options for plugin instance\n *\n * @example\n * const osc = new OSC({ plugin: new OSC.DatagramPlugin() })\n * osc.open({ host: '127.0.0.1', port: 8080 })\n */\n open(options) {\n if (options && !isObject(options)) {\n throw new Error('OSC open() options argument needs to be an object')\n }\n\n if (!(this.options.plugin && isFunction(this.options.plugin.open))) {\n throw new Error('OSC Plugin API #open is not implemented!')\n }\n\n return this.options.plugin.open(options)\n }\n\n /**\n * Returns the current status of the connection. See *STATUS* for\n * different possible states. This method is used by plugins\n * and is not available without (see Plugin API for more information)\n * @return {number} Status identifier\n *\n * @example\n * import OSC, { STATUS } from 'osc'\n * const osc = new OSC()\n * if (osc.status() === STATUS.IS_CONNECTING) {\n * // do something\n * }\n */\n status() {\n if (!(this.options.plugin && isFunction(this.options.plugin.status))) {\n throw new Error('OSC Plugin API #status is not implemented!')\n }\n\n return this.options.plugin.status()\n }\n\n /**\n * Close connection. This method is used by plugins and is not\n * available without (see Plugin API for more information)\n */\n close() {\n if (!(this.options.plugin && isFunction(this.options.plugin.close))) {\n throw new Error('OSC Plugin API #close is not implemented!')\n }\n\n return this.options.plugin.close()\n }\n\n /**\n * Send an OSC Packet, Bundle or Message. This method is used by plugins\n * and is not available without (see Plugin API for more information)\n * @param {Packet|Bundle|Message} packet OSC Packet, Bundle or Message instance\n * @param {object} [options] Custom options\n *\n * @example\n * const osc = new OSC({ plugin: new OSC.DatagramPlugin() })\n * osc.open({ host: '127.0.0.1', port: 8080 })\n *\n * const message = new OSC.Message('/test/path', 55.1, 57)\n * osc.send(message)\n *\n * // send message again to custom address\n * osc.send(message, { host: '192.168.178.115', port: 9001 })\n */\n send(packet, options) {\n if (!(this.options.plugin && isFunction(this.options.plugin.send))) {\n throw new Error('OSC Plugin API #send is not implemented!')\n }\n\n if (!(packet instanceof Message || packet instanceof Bundle || packet instanceof Packet)) {\n throw new Error('OSC send() needs Messages, Bundles or Packets')\n }\n\n if (options && !isObject(options)) {\n throw new Error('OSC send() options argument has to be an object')\n }\n\n return this.options.plugin.send(packet.pack(), options)\n }\n}\n\n// expose status flags\nOSC.STATUS = STATUS\n\n// expose OSC classes\nOSC.Packet = Packet\nOSC.Bundle = Bundle\nOSC.Message = Message\n\nexport default OSC\n","import { hasProperty } from '../common/utils'\n\n/**\n * Status flags\n * @private\n */\nconst STATUS = {\n IS_NOT_INITIALIZED: -1,\n IS_CONNECTING: 0,\n IS_OPEN: 1,\n IS_CLOSING: 2,\n IS_CLOSED: 3,\n}\n\n/**\n * Default options\n * @private\n */\nconst defaultOptions = {\n host: 'localhost',\n port: 8080,\n}\n\n/**\n * OSC plugin for a Websocket client running in only browser contexts\n */\nexport default class WebsocketBrowserPlugin {\n /**\n * Create an OSC WebsocketBrowserPlugin instance with given options.\n * Defaults to *localhost:8080* for connecting to a Websocket server\n * @param {object} [options] Custom options\n * @param {string} [options.host='localhost'] Hostname of Websocket server\n * @param {number} [options.port=8080] Port of Websocket server\n *\n * @example\n * const plugin = new OSC.WebsocketBrowserPlugin({ port: 9912 })\n * const osc = new OSC({ plugin: plugin })\n */\n constructor(customOptions) {\n if (!hasProperty('WebSocket')) { // eslint-disable-line no-undef\n throw new Error('WebsocketBrowserPlugin can\\'t find a WebSocket class')\n }\n\n /**\n * @type {object} options\n * @private\n */\n this.options = Object.assign({}, defaultOptions, customOptions)\n\n /**\n * @type {object} socket\n * @private\n */\n this.socket = null\n /**\n * @type {number} socketStatus\n * @private\n */\n this.socketStatus = STATUS.IS_NOT_INITIALIZED\n\n /**\n * @type {function} notify\n * @private\n */\n this.notify = () => {}\n }\n\n /**\n * Internal method to hook into osc library's\n * EventHandler notify method\n * @param {function} fn Notify callback\n * @private\n */\n registerNotify(fn) {\n this.notify = fn\n }\n\n /**\n * Returns the current status of the connection\n * @return {number} Status identifier\n */\n status() {\n return this.socketStatus\n }\n\n /**\n * Connect to a Websocket server. Defaults to global options\n * @param {object} [customOptions] Custom options\n * @param {string} [customOptions.host] Hostname of Websocket server\n * @param {number} [customOptions.port] Port of Websocket server\n */\n open(customOptions = {}) {\n const options = Object.assign({}, this.options, customOptions)\n const { port, host } = options\n\n // close socket when already given\n if (this.socket) {\n this.close()\n }\n\n // create websocket client\n this.socket = new WebSocket(`ws://${host}:${port}`) // eslint-disable-line no-undef\n this.socket.binaryType = 'arraybuffer'\n this.socketStatus = STATUS.IS_CONNECTING\n\n // register events\n this.socket.onopen = () => {\n this.socketStatus = STATUS.IS_OPEN\n this.notify('open')\n }\n\n this.socket.onclose = () => {\n this.socketStatus = STATUS.IS_CLOSED\n this.notify('close')\n }\n\n this.socket.onerror = (error) => {\n this.notify('error', error)\n }\n\n this.socket.onmessage = (message) => {\n this.notify(message.data)\n }\n }\n\n /**\n * Close Websocket\n */\n close() {\n this.socketStatus = STATUS.IS_CLOSING\n this.socket.close()\n }\n\n /**\n * Send an OSC Packet, Bundle or Message to Websocket server\n * @param {Uint8Array} binary Binary representation of OSC Packet\n */\n send(binary) {\n this.socket.send(binary)\n }\n}\n","import OSCBase from '../src/osc'\n\nimport WebsocketBrowserPlugin from '../src/plugin/wsbrowser'\n\nconst defaultOptions = {\n plugin: new WebsocketBrowserPlugin(),\n}\n\nclass OSC extends OSCBase {\n constructor(options) {\n super(Object.assign({}, defaultOptions, options))\n }\n}\n\nOSC.WebsocketBrowserPlugin = WebsocketBrowserPlugin\n\nexport default OSC\n"],"names":["isInt","n","Number","isFloat","isString","isArray","Object","prototype","toString","call","isObject","isFunction","isBlob","Uint8Array","isDate","Date","isUndefined","pad","hasProperty","name","hasOwnProperty","global","window","dataView","obj","buffer","DataView","ArrayBuffer","typeTag","item","Error","prepareAddress","address","join","length","slice","prepareRegExPattern","str","pattern","replace","EncodeHelper","data","byteLength","pack","push","result","offset","forEach","set","Atomic","value","method","initialOffset","AtomicInt32","AtomicFloat32","STR_SLICE_SIZE","STR_ENCODING","charCodesToString","charCodes","Buffer","from","TextDecoder","decode","Int8Array","i","String","fromCharCode","apply","AtomicString","terminated","charCodeAt","charcode","getUint8","AtomicBlob","setInt32","getInt32","Message","types","args","shift","map","encoder","Helper","add","argument","merge","unpack","next","type","SECONDS_70_YEARS","TWO_POWER_32","Timetag","seconds","fractions","milliseconds","rounded","Math","floor","round","AtomicTimetag","now","timetag","timestamp","getTime","getUint32","BUNDLE_TAG","Bundle","bundleElements","ms","head","packet","Packet","size","defaultOptions","EventHandler","options","assign","addressHandlers","eventHandlers","uuid","bundle","bundleItem","dispatch","message","notify","success","handler","callback","handlerKeys","keys","handlers","key","regex","RegExp","test","lastIndex","discardLateMessages","that","split","subscriptionId","haystack","some","index","id","splice","STATUS","OSC","eventHandler","plugin","registerNotify","eventName","on","off","open","status","close","send","WebsocketBrowserPlugin","customOptions","socket","socketStatus","IS_NOT_INITIALIZED","fn","port","host","WebSocket","binaryType","IS_CONNECTING","onopen","IS_OPEN","onclose","IS_CLOSED","onerror","error","onmessage","IS_CLOSING","binary","OSCBase"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,QAAQ;WACNjB,MAAL,CAAYH,IAAZ,CAAiBoB,MAAjB;;;;;;ACtIJ,IAAM/D,iBAAiB;UACb,IAAI4C,sBAAJ;CADV;IAIMX;;eACQ/B,OAAZ,EAAqB;;oGACb7G,OAAO8G,MAAP,CAAc,EAAd,EAAkBH,cAAlB,EAAkCE,OAAlC,CADa;;;EADL8D;AAMlB/B,IAAIW,sBAAJ,GAA6BA,sBAA7B,CAEA;;;;"} \ No newline at end of file diff --git a/dist/osc.min.js b/dist/osc.min.js index 3c9d182..4c94535 100644 --- a/dist/osc.min.js +++ b/dist/osc.min.js @@ -1 +1 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.OSC=e()}(this,function(){"use strict";function t(t){return Number(t)===t&&t%1==0}function e(t){return Number(t)===t&&t%1!=0}function n(t){return"string"==typeof t}function r(t){return"[object Array]"===Object.prototype.toString.call(t)}function i(t){return"[object Object]"===Object.prototype.toString.call(t)}function o(t){return"function"==typeof t}function s(t){return t instanceof Uint8Array}function a(t){return t instanceof Date}function u(t){return void 0===t}function c(t){return t+3&-4}function f(t){return Object.prototype.hasOwnProperty.call("undefined"!=typeof global?global:window,t)}function h(t){return t.buffer?new DataView(t.buffer):t instanceof ArrayBuffer?new DataView(t):new DataView(new Uint8Array(t))}function l(r){if(t(r))return"i";if(e(r))return"f";if(n(r))return"s";if(s(r))return"b";throw new Error("OSC typeTag() found unknown value type")}function p(t){var e="";if(r(t))return"/"+t.join("/");if(n(t))return(e=t).length>1&&"/"===e[e.length-1]&&(e=e.slice(0,e.length-1)),e.length>1&&"/"!==e[0]&&(e="/"+e),e;throw new Error("OSC prepareAddress() needs addresses of type array or string")}function d(t){var e=void 0;if(!n(t))throw new Error("OSC prepareRegExPattern() needs strings");return e=t.replace(/\./g,"\\."),e=e.replace(/\(/g,"\\("),e=e.replace(/\)/g,"\\)"),e=e.replace(/\{/g,"("),e=e.replace(/\}/g,")"),e=e.replace(/,/g,"|"),e=e.replace(/\[!/g,"[^"),e=e.replace(/\?/g,"."),e=e.replace(/\*/g,".*")}function w(t){if(f("Buffer"))return Buffer.from(t).toString(_);if(f("TextDecoder"))return new TextDecoder(_).decode(new Int8Array(t));for(var e="",n=0;n3&&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}}]),t}(),E=function(e){function n(e){if(v(this,n),e&&!t(e))throw new Error("OSC AtomicInt32 constructor expects value of type number");return k(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,e))}return b(n,O),g(n,[{key:"pack",value:function(){return y(n.prototype.__proto__||Object.getPrototypeOf(n.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 y(n.prototype.__proto__||Object.getPrototypeOf(n.prototype),"unpack",this).call(this,t,"getInt32",4,e)}}]),n}(),S=function(t){function n(t){if(v(this,n),t&&!e(t))throw new Error("OSC AtomicFloat32 constructor expects value of type float");return k(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,t))}return b(n,O),g(n,[{key:"pack",value:function(){return y(n.prototype.__proto__||Object.getPrototypeOf(n.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 y(n.prototype.__proto__||Object.getPrototypeOf(n.prototype),"unpack",this).call(this,t,"getFloat32",4,e)}}]),n}(),C=65537,_="utf-8",I=function(t){function e(t){if(v(this,e),t&&!n(t))throw new Error("OSC AtomicString constructor expects value of type string");return k(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t))}return b(e,O),g(e,[{key:"pack",value:function(){if(u(this.value))throw new Error("OSC AtomicString can not be encoded with empty value");for(var t=this.value+"\0",e=c(t.length),n=new Uint8Array(e),r=0;r1&&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=e,r=void 0,i=[];n1&&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=c(e+4+n),this.offset}}]),e}(),P=function(){function i(){v(this,i),this.offset=0,this.address="",this.types="",this.args=[];for(var t=arguments.length,e=Array(t),o=0;o0){if(!n(e[0])&&!r(e[0]))throw new Error("OSC Message constructor first argument (address) must be a string or array");this.address=p(e.shift()),this.types=e.map(function(t){return l(t)}).join(""),this.args=e}}return g(i,[{key:"add",value:function(t){if(!t)throw new Error("OSC Message needs a valid OSC Atomic Data Type");this.args.push(t),this.types+=l(t)}},{key:"pack",value:function(){if(0===this.address.length||"/"!==this.address[0])throw new Error("OSC Message has an invalid address");var r=new m;if(r.add(new I(this.address)),r.add(new I(","+this.types)),this.args.length>0){var i=void 0;this.args.forEach(function(o){if(t(o))i=new E(o);else if(e(o))i=new S(o);else if(n(o))i=new I(o);else{if(!s(o))throw new Error("OSC Message found unknown argument type");i=new A(o)}r.add(i)})}return r.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 i=r.offset,o=void 0,s=void 0,a=[],u=1;u0&&void 0!==arguments[0]?arguments[0]:0,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(v(this,e),!t(n)||!t(r))throw new Error("OSC Timetag constructor expects values of type integer number");this.seconds=n,this.fractions=r}return g(e,[{key:"timestamp",value:function(t){var e=void 0;if("number"==typeof t){e=t/1e3;var n=Math.floor(e);return this.seconds=n+2208988800,this.fractions=Math.round(4294967296*(e-n)),t}return 1e3*((e=this.seconds-2208988800)+Math.round(this.fractions/4294967296))}}]),e}(),j=function(e){function n(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Date.now();v(this,n);var r=new D;return e instanceof D?r=e:t(e)?r.timestamp(e):a(e)&&r.timestamp(e.getTime()),k(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,r))}return b(n,O),g(n,[{key:"pack",value:function(){if(u(this.value))throw new Error("OSC AtomicTimetag can not be encoded with empty value");var t=this.value,e=t.seconds,n=t.fractions,r=new Uint8Array(8),i=new DataView(r.buffer);return i.setInt32(0,e,!1),i.setInt32(4,n,!1),r}},{key:"unpack",value:function(t){var e=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 D(n,r),this.offset=e+8,this.offset}}]),n}(),H=function(){function e(){var n=this;v(this,e),this.offset=0,this.timetag=new j,this.bundleElements=[];for(var i=arguments.length,o=Array(i),s=0;s0&&(o[0]instanceof Date||t(o[0])?this.timetag=new j(o[0]):r(o[0])?(o[0].forEach(function(t){n.add(t)}),o.length>1&&(o[1]instanceof Date||t(o[0]))&&(this.timetag=new j(o[1]))):o.forEach(function(t){n.add(t)}))}return g(e,[{key:"timestamp",value:function(e){if(!t(e))throw new Error("OSC Bundle needs an integer for setting the timestamp");this.timetag=new j(e)}},{key:"add",value:function(t){if(!(t instanceof P||t instanceof e))throw new Error("OSC Bundle contains only Messages and Bundles");this.bundleElements.push(t)}},{key:"pack",value:function(){var t=new m;return t.add(new I("#bundle")),this.timetag||(this.timetag=new j),t.add(this.timetag),this.bundleElements.forEach(function(e){t.add(new E(e.pack().byteLength)),t.add(e)}),t.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 Bundle expects an instance of type DataView");var n=new I;if(n.unpack(t,e),"#bundle"!==n.value)throw new Error("OSC Bundle does not contain a valid #bundle head");var r=new j,i=r.unpack(t,n.offset);for(this.bundleElements=[];i1&&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=new I;n.unpack(t,e);var r=void 0;return(r="#bundle"===n.value?new H:new P).unpack(t,e),this.offset=r.offset,this.value=r,this.offset}}]),t}(),N={discardLateMessages:!1},T=function(){function e(t){v(this,e),this.options=Object.assign({},N,t),this.addressHandlers=[],this.eventHandlers={open:[],error:[],close:[]},this.uuid=0}return g(e,[{key:"dispatch",value:function(t){var e=this;if(!(t instanceof L))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 H){var n=t.value;return n.bundleElements.forEach(function(t){if(t instanceof H){if(n.timetag.value.timestamp()1&&(a=r[1]);var u=null;if(r.length>2)if(t(r[2]))u=r[2];else{if(!(r[2]instanceof Date))throw new Error("OSC EventHandler timestamp has to be a number or Date");u=r[2].getTime()}if(u){var c=Date.now();if(c>u&&!this.options.discardLateMessages)return this.call(s,a);var f=this;return setTimeout(function(){f.call(s,a)},u-c),!0}return this.call(s,a)}},{key:"on",value:function(t,e){if(!n(t)&&!r(t))throw new Error("OSC EventHandler accepts only strings or arrays for address patterns");if(!o(e))throw new Error("OSC EventHandler callback has to be a function");this.uuid+=1;var i={id:this.uuid,callback:e};if(n(t)&&t in this.eventHandlers)return this.eventHandlers[t].push(i),this.uuid;var s=p(t);if(new RegExp(/[#*\s[\],/{}|?]/g).test(s.split("/").join("")))throw new Error("OSC EventHandler address string contains invalid characters");return s in this.addressHandlers||(this.addressHandlers[s]=[]),this.addressHandlers[s].push(i),this.uuid}},{key:"off",value:function(e,i){if(!n(e)&&!r(e))throw new Error("OSC EventHandler accepts only strings or arrays for address patterns");if(!t(i))throw new Error("OSC EventHandler subscription id has to be a number");var o=void 0,s=void 0;return n(e)&&e in this.eventHandlers?(o=e,s=this.eventHandlers):(o=p(e),s=this.addressHandlers),o in s&&s[o].some(function(t,e){return t.id===i&&(s[o].splice(e,1),!0)})}}]),e}(),x={plugin:null,discardLateMessages:!1},V={IS_NOT_INITIALIZED:-1,IS_CONNECTING:0,IS_OPEN:1,IS_CLOSING:2,IS_CLOSED:3},M=function(){function e(t){if(v(this,e),t&&!i(t))throw new Error("OSC options argument has to be an object.");this.options=Object.assign({},x,t),this.eventHandler=new T({discardLateMessages:this.options.discardLateMessages});var n=this.eventHandler;this.options.plugin&&this.options.plugin.registerNotify&&this.options.plugin.registerNotify(function(){return n.notify.apply(n,arguments)})}return g(e,[{key:"on",value:function(t,e){if(!n(t)||!o(e))throw new Error("OSC on() needs event- or address string and callback function");return this.eventHandler.on(t,e)}},{key:"off",value:function(e,r){if(!n(e)||!t(r))throw new Error("OSC off() needs string and number (subscriptionId) to unsubscribe");return this.eventHandler.off(e,r)}},{key:"open",value:function(t){if(t&&!i(t))throw new Error("OSC open() options argument needs to be an object");if(!this.options.plugin||!o(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||!o(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||!o(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||!o(this.options.plugin.send))throw new Error("OSC Plugin API #send is not implemented!");if(!(t instanceof P||t instanceof H||t instanceof L))throw new Error("OSC send() needs Messages, Bundles or Packets");if(e&&!i(e))throw new Error("OSC send() options argument has to be an object");return this.options.plugin.send(t.pack(),e)}}]),e}();M.STATUS=V,M.Packet=L,M.Bundle=H,M.Message=P;var B={IS_NOT_INITIALIZED:-1,IS_CONNECTING:0,IS_OPEN:1,IS_CLOSING:2,IS_CLOSED:3},U={host:"localhost",port:8080},G=function(){function t(e){if(v(this,t),!f("WebSocket"))throw new Error("WebsocketBrowserPlugin can't find a WebSocket class");this.options=Object.assign({},U,e),this.socket=null,this.socketStatus=B.IS_NOT_INITIALIZED,this.notify=function(){}}return g(t,[{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=Object.assign({},this.options,e),r=n.port,i=n.host;this.socket&&this.close(),this.socket=new WebSocket("ws://"+i+":"+r),this.socket.binaryType="arraybuffer",this.socketStatus=B.IS_CONNECTING,this.socket.onopen=function(){t.socketStatus=B.IS_OPEN,t.notify("open")},this.socket.onclose=function(){t.socketStatus=B.IS_CLOSED,t.notify("close")},this.socket.onerror=function(e){t.notify("error",e)},this.socket.onmessage=function(e){t.notify(e.data)}}},{key:"close",value:function(){this.socketStatus=B.IS_CLOSING,this.socket.close()}},{key:"send",value:function(t){this.socket.send(t)}}]),t}(),W={plugin:new G},F=function(t){function e(t){return v(this,e),k(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,Object.assign({},W,t)))}return b(e,M),e}();return F.WebsocketBrowserPlugin=G,F}); +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.OSC=e()}(this,function(){"use strict";function t(t){return Number(t)===t&&t%1==0}function e(t){return Number(t)===t&&t%1!=0}function n(t){return"string"==typeof t}function r(t){return"[object Array]"===Object.prototype.toString.call(t)}function i(t){return"[object Object]"===Object.prototype.toString.call(t)}function o(t){return"function"==typeof t}function s(t){return t instanceof Uint8Array}function a(t){return t instanceof Date}function u(t){return void 0===t}function c(t){return t+3&-4}function f(t){return Object.prototype.hasOwnProperty.call("undefined"!=typeof global?global:window,t)}function h(t){return t.buffer?new DataView(t.buffer):t instanceof ArrayBuffer?new DataView(t):new DataView(new Uint8Array(t))}function l(r){if(t(r))return"i";if(e(r))return"f";if(n(r))return"s";if(s(r))return"b";throw new Error("OSC typeTag() found unknown value type")}function p(t){var e="";if(r(t))return"/"+t.join("/");if(n(t))return(e=t).length>1&&"/"===e[e.length-1]&&(e=e.slice(0,e.length-1)),e.length>1&&"/"!==e[0]&&(e="/"+e),e;throw new Error("OSC prepareAddress() needs addresses of type array or string")}function d(t){var e=void 0;if(!n(t))throw new Error("OSC prepareRegExPattern() needs strings");return e=t.replace(/\./g,"\\."),e=e.replace(/\(/g,"\\("),e=e.replace(/\)/g,"\\)"),e=e.replace(/\{/g,"("),e=e.replace(/\}/g,")"),e=e.replace(/,/g,"|"),e=e.replace(/\[!/g,"[^"),e=e.replace(/\?/g,"."),e=e.replace(/\*/g,".*")}function w(t){if(f("Buffer"))return Buffer.from(t).toString(_);if(f("TextDecoder"))return new TextDecoder(_).decode(new Int8Array(t));for(var e="",n=0;n3&&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}}]),t}(),E=function(e){function n(e){if(v(this,n),e&&!t(e))throw new Error("OSC AtomicInt32 constructor expects value of type number");return k(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,e))}return b(n,O),g(n,[{key:"pack",value:function(){return y(n.prototype.__proto__||Object.getPrototypeOf(n.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 y(n.prototype.__proto__||Object.getPrototypeOf(n.prototype),"unpack",this).call(this,t,"getInt32",4,e)}}]),n}(),S=function(t){function n(t){if(v(this,n),t&&!e(t))throw new Error("OSC AtomicFloat32 constructor expects value of type float");return k(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,t))}return b(n,O),g(n,[{key:"pack",value:function(){return y(n.prototype.__proto__||Object.getPrototypeOf(n.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 y(n.prototype.__proto__||Object.getPrototypeOf(n.prototype),"unpack",this).call(this,t,"getFloat32",4,e)}}]),n}(),C=65537,_="utf-8",I=function(t){function e(t){if(v(this,e),t&&!n(t))throw new Error("OSC AtomicString constructor expects value of type string");return k(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t))}return b(e,O),g(e,[{key:"pack",value:function(){if(u(this.value))throw new Error("OSC AtomicString can not be encoded with empty value");for(var t=this.value+"\0",e=c(t.length),n=new Uint8Array(e),r=0;r1&&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=e,r=void 0,i=[];n1&&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=c(e+4+n),this.offset}}]),e}(),P=function(){function i(){v(this,i),this.offset=0,this.address="",this.types="",this.args=[];for(var t=arguments.length,e=Array(t),o=0;o0){if(!n(e[0])&&!r(e[0]))throw new Error("OSC Message constructor first argument (address) must be a string or array");this.address=p(e.shift()),this.types=e.map(function(t){return l(t)}).join(""),this.args=e}}return g(i,[{key:"add",value:function(t){if(u(t))throw new Error("OSC Message needs a valid OSC Atomic Data Type");this.args.push(t),this.types+=l(t)}},{key:"pack",value:function(){if(0===this.address.length||"/"!==this.address[0])throw new Error("OSC Message has an invalid address");var r=new m;if(r.add(new I(this.address)),r.add(new I(","+this.types)),this.args.length>0){var i=void 0;this.args.forEach(function(o){if(t(o))i=new E(o);else if(e(o))i=new S(o);else if(n(o))i=new I(o);else{if(!s(o))throw new Error("OSC Message found unknown argument type");i=new A(o)}r.add(i)})}return r.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 i=r.offset,o=void 0,s=void 0,a=[],u=1;u0&&void 0!==arguments[0]?arguments[0]:0,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(v(this,e),!t(n)||!t(r))throw new Error("OSC Timetag constructor expects values of type integer number");this.seconds=n,this.fractions=r}return g(e,[{key:"timestamp",value:function(t){var e=void 0;if("number"==typeof t){e=t/1e3;var n=Math.floor(e);return this.seconds=n+2208988800,this.fractions=Math.round(4294967296*(e-n)),t}return 1e3*((e=this.seconds-2208988800)+Math.round(this.fractions/4294967296))}}]),e}(),j=function(e){function n(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Date.now();v(this,n);var r=new D;return e instanceof D?r=e:t(e)?r.timestamp(e):a(e)&&r.timestamp(e.getTime()),k(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,r))}return b(n,O),g(n,[{key:"pack",value:function(){if(u(this.value))throw new Error("OSC AtomicTimetag can not be encoded with empty value");var t=this.value,e=t.seconds,n=t.fractions,r=new Uint8Array(8),i=new DataView(r.buffer);return i.setInt32(0,e,!1),i.setInt32(4,n,!1),r}},{key:"unpack",value:function(t){var e=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 D(n,r),this.offset=e+8,this.offset}}]),n}(),H=function(){function e(){var n=this;v(this,e),this.offset=0,this.timetag=new j,this.bundleElements=[];for(var i=arguments.length,o=Array(i),s=0;s0&&(o[0]instanceof Date||t(o[0])?this.timetag=new j(o[0]):r(o[0])?(o[0].forEach(function(t){n.add(t)}),o.length>1&&(o[1]instanceof Date||t(o[0]))&&(this.timetag=new j(o[1]))):o.forEach(function(t){n.add(t)}))}return g(e,[{key:"timestamp",value:function(e){if(!t(e))throw new Error("OSC Bundle needs an integer for setting the timestamp");this.timetag=new j(e)}},{key:"add",value:function(t){if(!(t instanceof P||t instanceof e))throw new Error("OSC Bundle contains only Messages and Bundles");this.bundleElements.push(t)}},{key:"pack",value:function(){var t=new m;return t.add(new I("#bundle")),this.timetag||(this.timetag=new j),t.add(this.timetag),this.bundleElements.forEach(function(e){t.add(new E(e.pack().byteLength)),t.add(e)}),t.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 Bundle expects an instance of type DataView");var n=new I;if(n.unpack(t,e),"#bundle"!==n.value)throw new Error("OSC Bundle does not contain a valid #bundle head");var r=new j,i=r.unpack(t,n.offset);for(this.bundleElements=[];i1&&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=new I;n.unpack(t,e);var r=void 0;return(r="#bundle"===n.value?new H:new P).unpack(t,e),this.offset=r.offset,this.value=r,this.offset}}]),t}(),N={discardLateMessages:!1},T=function(){function e(t){v(this,e),this.options=Object.assign({},N,t),this.addressHandlers=[],this.eventHandlers={open:[],error:[],close:[]},this.uuid=0}return g(e,[{key:"dispatch",value:function(t){var e=this;if(!(t instanceof L))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 H){var n=t.value;return n.bundleElements.forEach(function(t){if(t instanceof H){if(n.timetag.value.timestamp()1&&(a=r[1]);var u=null;if(r.length>2)if(t(r[2]))u=r[2];else{if(!(r[2]instanceof Date))throw new Error("OSC EventHandler timestamp has to be a number or Date");u=r[2].getTime()}if(u){var c=Date.now();if(c>u&&!this.options.discardLateMessages)return this.call(s,a);var f=this;return setTimeout(function(){f.call(s,a)},u-c),!0}return this.call(s,a)}},{key:"on",value:function(t,e){if(!n(t)&&!r(t))throw new Error("OSC EventHandler accepts only strings or arrays for address patterns");if(!o(e))throw new Error("OSC EventHandler callback has to be a function");this.uuid+=1;var i={id:this.uuid,callback:e};if(n(t)&&t in this.eventHandlers)return this.eventHandlers[t].push(i),this.uuid;var s=p(t);if(new RegExp(/[#*\s[\],/{}|?]/g).test(s.split("/").join("")))throw new Error("OSC EventHandler address string contains invalid characters");return s in this.addressHandlers||(this.addressHandlers[s]=[]),this.addressHandlers[s].push(i),this.uuid}},{key:"off",value:function(e,i){if(!n(e)&&!r(e))throw new Error("OSC EventHandler accepts only strings or arrays for address patterns");if(!t(i))throw new Error("OSC EventHandler subscription id has to be a number");var o=void 0,s=void 0;return n(e)&&e in this.eventHandlers?(o=e,s=this.eventHandlers):(o=p(e),s=this.addressHandlers),o in s&&s[o].some(function(t,e){return t.id===i&&(s[o].splice(e,1),!0)})}}]),e}(),x={plugin:null,discardLateMessages:!1},V={IS_NOT_INITIALIZED:-1,IS_CONNECTING:0,IS_OPEN:1,IS_CLOSING:2,IS_CLOSED:3},M=function(){function e(t){if(v(this,e),t&&!i(t))throw new Error("OSC options argument has to be an object.");this.options=Object.assign({},x,t),this.eventHandler=new T({discardLateMessages:this.options.discardLateMessages});var n=this.eventHandler;this.options.plugin&&this.options.plugin.registerNotify&&this.options.plugin.registerNotify(function(){return n.notify.apply(n,arguments)})}return g(e,[{key:"on",value:function(t,e){if(!n(t)||!o(e))throw new Error("OSC on() needs event- or address string and callback function");return this.eventHandler.on(t,e)}},{key:"off",value:function(e,r){if(!n(e)||!t(r))throw new Error("OSC off() needs string and number (subscriptionId) to unsubscribe");return this.eventHandler.off(e,r)}},{key:"open",value:function(t){if(t&&!i(t))throw new Error("OSC open() options argument needs to be an object");if(!this.options.plugin||!o(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||!o(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||!o(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||!o(this.options.plugin.send))throw new Error("OSC Plugin API #send is not implemented!");if(!(t instanceof P||t instanceof H||t instanceof L))throw new Error("OSC send() needs Messages, Bundles or Packets");if(e&&!i(e))throw new Error("OSC send() options argument has to be an object");return this.options.plugin.send(t.pack(),e)}}]),e}();M.STATUS=V,M.Packet=L,M.Bundle=H,M.Message=P;var B={IS_NOT_INITIALIZED:-1,IS_CONNECTING:0,IS_OPEN:1,IS_CLOSING:2,IS_CLOSED:3},U={host:"localhost",port:8080},G=function(){function t(e){if(v(this,t),!f("WebSocket"))throw new Error("WebsocketBrowserPlugin can't find a WebSocket class");this.options=Object.assign({},U,e),this.socket=null,this.socketStatus=B.IS_NOT_INITIALIZED,this.notify=function(){}}return g(t,[{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=Object.assign({},this.options,e),r=n.port,i=n.host;this.socket&&this.close(),this.socket=new WebSocket("ws://"+i+":"+r),this.socket.binaryType="arraybuffer",this.socketStatus=B.IS_CONNECTING,this.socket.onopen=function(){t.socketStatus=B.IS_OPEN,t.notify("open")},this.socket.onclose=function(){t.socketStatus=B.IS_CLOSED,t.notify("close")},this.socket.onerror=function(e){t.notify("error",e)},this.socket.onmessage=function(e){t.notify(e.data)}}},{key:"close",value:function(){this.socketStatus=B.IS_CLOSING,this.socket.close()}},{key:"send",value:function(t){this.socket.send(t)}}]),t}(),W={plugin:new G},F=function(t){function e(t){return v(this,e),k(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,Object.assign({},W,t)))}return b(e,M),e}();return F.WebsocketBrowserPlugin=G,F}); diff --git a/lib/osc.browser.js b/lib/osc.browser.js index 048e885..f66046a 100644 --- a/lib/osc.browser.js +++ b/lib/osc.browser.js @@ -425,7 +425,7 @@ var Message = function () { createClass(Message, [{ key: 'add', value: function add(item) { - if (!item) { + if (isUndefined(item)) { throw new Error('OSC Message needs a valid OSC Atomic Data Type'); } this.args.push(item); diff --git a/lib/osc.js b/lib/osc.js index d7987b6..3f85a0b 100644 --- a/lib/osc.js +++ b/lib/osc.js @@ -425,7 +425,7 @@ var Message = function () { createClass(Message, [{ key: 'add', value: function add(item) { - if (!item) { + if (isUndefined(item)) { throw new Error('OSC Message needs a valid OSC Atomic Data Type'); } this.args.push(item); diff --git a/src/message.js b/src/message.js index 2405007..10b38b0 100644 --- a/src/message.js +++ b/src/message.js @@ -1,4 +1,12 @@ -import { isString, isArray, isInt, isFloat, isBlob } from './common/utils' +import { + isArray, + isBlob, + isFloat, + isInt, + isString, + isUndefined, +} from './common/utils' + import Helper, { typeTag, prepareAddress } from './common/helpers' import AtomicInt32 from './atomic/int32' @@ -51,7 +59,7 @@ export default class Message { * @param {*} item */ add(item) { - if (!item) { + if (isUndefined(item)) { throw new Error('OSC Message needs a valid OSC Atomic Data Type') }