@reactoo/watchtogether-sdk-js 2.5.18 → 2.5.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * @reactoo/watchtogether-sdk-js
3
- * @version 2.5.18
3
+ * @version 2.5.19
4
4
  */
5
5
  (function webpackUniversalModuleDefinition(root, factory) {
6
6
  if(typeof exports === 'object' && typeof module === 'object')
@@ -5407,7 +5407,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _mod
5407
5407
  /***/ (function(__webpack_module__, __webpack_exports__, __webpack_require__) {
5408
5408
 
5409
5409
  "use strict";
5410
- eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"JsonPatchError\", function() { return JsonPatchError; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"deepClone\", function() { return deepClone; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"getValueByPointer\", function() { return getValueByPointer; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"applyOperation\", function() { return applyOperation; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"applyPatch\", function() { return applyPatch; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"applyReducer\", function() { return applyReducer; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"validator\", function() { return validator; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"validate\", function() { return validate; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"_areEquals\", function() { return _areEquals; });\n/* harmony import */ var _helpers_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./helpers.mjs */ \"./node_modules/fast-json-patch/module/helpers.mjs\");\n\nvar JsonPatchError = _helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"PatchError\"];\nvar deepClone = _helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"_deepClone\"];\n/* We use a Javascript hash to store each\n function. Each hash entry (property) uses\n the operation identifiers specified in rfc6902.\n In this way, we can map each patch operation\n to its dedicated function in efficient way.\n */\n/* The operations applicable to an object */\nvar objOps = {\n add: function (obj, key, document) {\n obj[key] = this.value;\n return { newDocument: document };\n },\n remove: function (obj, key, document) {\n var removed = obj[key];\n delete obj[key];\n return { newDocument: document, removed: removed };\n },\n replace: function (obj, key, document) {\n var removed = obj[key];\n obj[key] = this.value;\n return { newDocument: document, removed: removed };\n },\n move: function (obj, key, document) {\n /* in case move target overwrites an existing value,\n return the removed value, this can be taxing performance-wise,\n and is potentially unneeded */\n var removed = getValueByPointer(document, this.path);\n if (removed) {\n removed = Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"_deepClone\"])(removed);\n }\n var originalValue = applyOperation(document, { op: \"remove\", path: this.from }).removed;\n applyOperation(document, { op: \"add\", path: this.path, value: originalValue });\n return { newDocument: document, removed: removed };\n },\n copy: function (obj, key, document) {\n var valueToCopy = getValueByPointer(document, this.from);\n // enforce copy by value so further operations don't affect source (see issue #177)\n applyOperation(document, { op: \"add\", path: this.path, value: Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"_deepClone\"])(valueToCopy) });\n return { newDocument: document };\n },\n test: function (obj, key, document) {\n return { newDocument: document, test: _areEquals(obj[key], this.value) };\n },\n _get: function (obj, key, document) {\n this.value = obj[key];\n return { newDocument: document };\n }\n};\n/* The operations applicable to an array. Many are the same as for the object */\nvar arrOps = {\n add: function (arr, i, document) {\n if (Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"isInteger\"])(i)) {\n arr.splice(i, 0, this.value);\n }\n else { // array props\n arr[i] = this.value;\n }\n // this may be needed when using '-' in an array\n return { newDocument: document, index: i };\n },\n remove: function (arr, i, document) {\n var removedList = arr.splice(i, 1);\n return { newDocument: document, removed: removedList[0] };\n },\n replace: function (arr, i, document) {\n var removed = arr[i];\n arr[i] = this.value;\n return { newDocument: document, removed: removed };\n },\n move: objOps.move,\n copy: objOps.copy,\n test: objOps.test,\n _get: objOps._get\n};\n/**\n * Retrieves a value from a JSON document by a JSON pointer.\n * Returns the value.\n *\n * @param document The document to get the value from\n * @param pointer an escaped JSON pointer\n * @return The retrieved value\n */\nfunction getValueByPointer(document, pointer) {\n if (pointer == '') {\n return document;\n }\n var getOriginalDestination = { op: \"_get\", path: pointer };\n applyOperation(document, getOriginalDestination);\n return getOriginalDestination.value;\n}\n/**\n * Apply a single JSON Patch Operation on a JSON document.\n * Returns the {newDocument, result} of the operation.\n * It modifies the `document` and `operation` objects - it gets the values by reference.\n * If you would like to avoid touching your values, clone them:\n * `jsonpatch.applyOperation(document, jsonpatch._deepClone(operation))`.\n *\n * @param document The document to patch\n * @param operation The operation to apply\n * @param validateOperation `false` is without validation, `true` to use default jsonpatch's validation, or you can pass a `validateOperation` callback to be used for validation.\n * @param mutateDocument Whether to mutate the original document or clone it before applying\n * @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.\n * @return `{newDocument, result}` after the operation\n */\nfunction applyOperation(document, operation, validateOperation, mutateDocument, banPrototypeModifications, index) {\n if (validateOperation === void 0) { validateOperation = false; }\n if (mutateDocument === void 0) { mutateDocument = true; }\n if (banPrototypeModifications === void 0) { banPrototypeModifications = true; }\n if (index === void 0) { index = 0; }\n if (validateOperation) {\n if (typeof validateOperation == 'function') {\n validateOperation(operation, 0, document, operation.path);\n }\n else {\n validator(operation, 0);\n }\n }\n /* ROOT OPERATIONS */\n if (operation.path === \"\") {\n var returnValue = { newDocument: document };\n if (operation.op === 'add') {\n returnValue.newDocument = operation.value;\n return returnValue;\n }\n else if (operation.op === 'replace') {\n returnValue.newDocument = operation.value;\n returnValue.removed = document; //document we removed\n return returnValue;\n }\n else if (operation.op === 'move' || operation.op === 'copy') { // it's a move or copy to root\n returnValue.newDocument = getValueByPointer(document, operation.from); // get the value by json-pointer in `from` field\n if (operation.op === 'move') { // report removed item\n returnValue.removed = document;\n }\n return returnValue;\n }\n else if (operation.op === 'test') {\n returnValue.test = _areEquals(document, operation.value);\n if (returnValue.test === false) {\n throw new JsonPatchError(\"Test operation failed\", 'TEST_OPERATION_FAILED', index, operation, document);\n }\n returnValue.newDocument = document;\n return returnValue;\n }\n else if (operation.op === 'remove') { // a remove on root\n returnValue.removed = document;\n returnValue.newDocument = null;\n return returnValue;\n }\n else if (operation.op === '_get') {\n operation.value = document;\n return returnValue;\n }\n else { /* bad operation */\n if (validateOperation) {\n throw new JsonPatchError('Operation `op` property is not one of operations defined in RFC-6902', 'OPERATION_OP_INVALID', index, operation, document);\n }\n else {\n return returnValue;\n }\n }\n } /* END ROOT OPERATIONS */\n else {\n if (!mutateDocument) {\n document = Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"_deepClone\"])(document);\n }\n var path = operation.path || \"\";\n var keys = path.split('/');\n var obj = document;\n var t = 1; //skip empty element - http://jsperf.com/to-shift-or-not-to-shift\n var len = keys.length;\n var existingPathFragment = undefined;\n var key = void 0;\n var validateFunction = void 0;\n if (typeof validateOperation == 'function') {\n validateFunction = validateOperation;\n }\n else {\n validateFunction = validator;\n }\n while (true) {\n key = keys[t];\n if (key && key.indexOf('~') != -1) {\n key = Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"unescapePathComponent\"])(key);\n }\n if (banPrototypeModifications && key == '__proto__') {\n throw new TypeError('JSON-Patch: modifying `__proto__` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README');\n }\n if (validateOperation) {\n if (existingPathFragment === undefined) {\n if (obj[key] === undefined) {\n existingPathFragment = keys.slice(0, t).join('/');\n }\n else if (t == len - 1) {\n existingPathFragment = operation.path;\n }\n if (existingPathFragment !== undefined) {\n validateFunction(operation, 0, document, existingPathFragment);\n }\n }\n }\n t++;\n if (Array.isArray(obj)) {\n if (key === '-') {\n key = obj.length;\n }\n else {\n if (validateOperation && !Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"isInteger\"])(key)) {\n throw new JsonPatchError(\"Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index\", \"OPERATION_PATH_ILLEGAL_ARRAY_INDEX\", index, operation, document);\n } // only parse key when it's an integer for `arr.prop` to work\n else if (Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"isInteger\"])(key)) {\n key = ~~key;\n }\n }\n if (t >= len) {\n if (validateOperation && operation.op === \"add\" && key > obj.length) {\n throw new JsonPatchError(\"The specified index MUST NOT be greater than the number of elements in the array\", \"OPERATION_VALUE_OUT_OF_BOUNDS\", index, operation, document);\n }\n var returnValue = arrOps[operation.op].call(operation, obj, key, document); // Apply patch\n if (returnValue.test === false) {\n throw new JsonPatchError(\"Test operation failed\", 'TEST_OPERATION_FAILED', index, operation, document);\n }\n return returnValue;\n }\n }\n else {\n if (t >= len) {\n var returnValue = objOps[operation.op].call(operation, obj, key, document); // Apply patch\n if (returnValue.test === false) {\n throw new JsonPatchError(\"Test operation failed\", 'TEST_OPERATION_FAILED', index, operation, document);\n }\n return returnValue;\n }\n }\n obj = obj[key];\n // If we have more keys in the path, but the next value isn't a non-null object,\n // throw an OPERATION_PATH_UNRESOLVABLE error instead of iterating again.\n if (validateOperation && t < len && (!obj || typeof obj !== \"object\")) {\n throw new JsonPatchError('Cannot perform operation at the desired path', 'OPERATION_PATH_UNRESOLVABLE', index, operation, document);\n }\n }\n }\n}\n/**\n * Apply a full JSON Patch array on a JSON document.\n * Returns the {newDocument, result} of the patch.\n * It modifies the `document` object and `patch` - it gets the values by reference.\n * If you would like to avoid touching your values, clone them:\n * `jsonpatch.applyPatch(document, jsonpatch._deepClone(patch))`.\n *\n * @param document The document to patch\n * @param patch The patch to apply\n * @param validateOperation `false` is without validation, `true` to use default jsonpatch's validation, or you can pass a `validateOperation` callback to be used for validation.\n * @param mutateDocument Whether to mutate the original document or clone it before applying\n * @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.\n * @return An array of `{newDocument, result}` after the patch\n */\nfunction applyPatch(document, patch, validateOperation, mutateDocument, banPrototypeModifications) {\n if (mutateDocument === void 0) { mutateDocument = true; }\n if (banPrototypeModifications === void 0) { banPrototypeModifications = true; }\n if (validateOperation) {\n if (!Array.isArray(patch)) {\n throw new JsonPatchError('Patch sequence must be an array', 'SEQUENCE_NOT_AN_ARRAY');\n }\n }\n if (!mutateDocument) {\n document = Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"_deepClone\"])(document);\n }\n var results = new Array(patch.length);\n for (var i = 0, length_1 = patch.length; i < length_1; i++) {\n // we don't need to pass mutateDocument argument because if it was true, we already deep cloned the object, we'll just pass `true`\n results[i] = applyOperation(document, patch[i], validateOperation, true, banPrototypeModifications, i);\n document = results[i].newDocument; // in case root was replaced\n }\n results.newDocument = document;\n return results;\n}\n/**\n * Apply a single JSON Patch Operation on a JSON document.\n * Returns the updated document.\n * Suitable as a reducer.\n *\n * @param document The document to patch\n * @param operation The operation to apply\n * @return The updated document\n */\nfunction applyReducer(document, operation, index) {\n var operationResult = applyOperation(document, operation);\n if (operationResult.test === false) { // failed test\n throw new JsonPatchError(\"Test operation failed\", 'TEST_OPERATION_FAILED', index, operation, document);\n }\n return operationResult.newDocument;\n}\n/**\n * Validates a single operation. Called from `jsonpatch.validate`. Throws `JsonPatchError` in case of an error.\n * @param {object} operation - operation object (patch)\n * @param {number} index - index of operation in the sequence\n * @param {object} [document] - object where the operation is supposed to be applied\n * @param {string} [existingPathFragment] - comes along with `document`\n */\nfunction validator(operation, index, document, existingPathFragment) {\n if (typeof operation !== 'object' || operation === null || Array.isArray(operation)) {\n throw new JsonPatchError('Operation is not an object', 'OPERATION_NOT_AN_OBJECT', index, operation, document);\n }\n else if (!objOps[operation.op]) {\n throw new JsonPatchError('Operation `op` property is not one of operations defined in RFC-6902', 'OPERATION_OP_INVALID', index, operation, document);\n }\n else if (typeof operation.path !== 'string') {\n throw new JsonPatchError('Operation `path` property is not a string', 'OPERATION_PATH_INVALID', index, operation, document);\n }\n else if (operation.path.indexOf('/') !== 0 && operation.path.length > 0) {\n // paths that aren't empty string should start with \"/\"\n throw new JsonPatchError('Operation `path` property must start with \"/\"', 'OPERATION_PATH_INVALID', index, operation, document);\n }\n else if ((operation.op === 'move' || operation.op === 'copy') && typeof operation.from !== 'string') {\n throw new JsonPatchError('Operation `from` property is not present (applicable in `move` and `copy` operations)', 'OPERATION_FROM_REQUIRED', index, operation, document);\n }\n else if ((operation.op === 'add' || operation.op === 'replace' || operation.op === 'test') && operation.value === undefined) {\n throw new JsonPatchError('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)', 'OPERATION_VALUE_REQUIRED', index, operation, document);\n }\n else if ((operation.op === 'add' || operation.op === 'replace' || operation.op === 'test') && Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"hasUndefined\"])(operation.value)) {\n throw new JsonPatchError('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)', 'OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED', index, operation, document);\n }\n else if (document) {\n if (operation.op == \"add\") {\n var pathLen = operation.path.split(\"/\").length;\n var existingPathLen = existingPathFragment.split(\"/\").length;\n if (pathLen !== existingPathLen + 1 && pathLen !== existingPathLen) {\n throw new JsonPatchError('Cannot perform an `add` operation at the desired path', 'OPERATION_PATH_CANNOT_ADD', index, operation, document);\n }\n }\n else if (operation.op === 'replace' || operation.op === 'remove' || operation.op === '_get') {\n if (operation.path !== existingPathFragment) {\n throw new JsonPatchError('Cannot perform the operation at a path that does not exist', 'OPERATION_PATH_UNRESOLVABLE', index, operation, document);\n }\n }\n else if (operation.op === 'move' || operation.op === 'copy') {\n var existingValue = { op: \"_get\", path: operation.from, value: undefined };\n var error = validate([existingValue], document);\n if (error && error.name === 'OPERATION_PATH_UNRESOLVABLE') {\n throw new JsonPatchError('Cannot perform the operation from a path that does not exist', 'OPERATION_FROM_UNRESOLVABLE', index, operation, document);\n }\n }\n }\n}\n/**\n * Validates a sequence of operations. If `document` parameter is provided, the sequence is additionally validated against the object document.\n * If error is encountered, returns a JsonPatchError object\n * @param sequence\n * @param document\n * @returns {JsonPatchError|undefined}\n */\nfunction validate(sequence, document, externalValidator) {\n try {\n if (!Array.isArray(sequence)) {\n throw new JsonPatchError('Patch sequence must be an array', 'SEQUENCE_NOT_AN_ARRAY');\n }\n if (document) {\n //clone document and sequence so that we can safely try applying operations\n applyPatch(Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"_deepClone\"])(document), Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"_deepClone\"])(sequence), externalValidator || true);\n }\n else {\n externalValidator = externalValidator || validator;\n for (var i = 0; i < sequence.length; i++) {\n externalValidator(sequence[i], i, document, undefined);\n }\n }\n }\n catch (e) {\n if (e instanceof JsonPatchError) {\n return e;\n }\n else {\n throw e;\n }\n }\n}\n// based on https://github.com/epoberezkin/fast-deep-equal\n// MIT License\n// Copyright (c) 2017 Evgeny Poberezkin\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n// The above copyright notice and this permission notice shall be included in all\n// copies or substantial portions of the Software.\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n// SOFTWARE.\nfunction _areEquals(a, b) {\n if (a === b)\n return true;\n if (a && b && typeof a == 'object' && typeof b == 'object') {\n var arrA = Array.isArray(a), arrB = Array.isArray(b), i, length, key;\n if (arrA && arrB) {\n length = a.length;\n if (length != b.length)\n return false;\n for (i = length; i-- !== 0;)\n if (!_areEquals(a[i], b[i]))\n return false;\n return true;\n }\n if (arrA != arrB)\n return false;\n var keys = Object.keys(a);\n length = keys.length;\n if (length !== Object.keys(b).length)\n return false;\n for (i = length; i-- !== 0;)\n if (!b.hasOwnProperty(keys[i]))\n return false;\n for (i = length; i-- !== 0;) {\n key = keys[i];\n if (!_areEquals(a[key], b[key]))\n return false;\n }\n return true;\n }\n return a !== a && b !== b;\n}\n;\n\n\n//# sourceURL=webpack://WatchTogetherSDK/./node_modules/fast-json-patch/module/core.mjs?");
5410
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"JsonPatchError\", function() { return JsonPatchError; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"deepClone\", function() { return deepClone; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"getValueByPointer\", function() { return getValueByPointer; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"applyOperation\", function() { return applyOperation; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"applyPatch\", function() { return applyPatch; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"applyReducer\", function() { return applyReducer; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"validator\", function() { return validator; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"validate\", function() { return validate; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"_areEquals\", function() { return _areEquals; });\n/* harmony import */ var _helpers_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./helpers.mjs */ \"./node_modules/fast-json-patch/module/helpers.mjs\");\n\nvar JsonPatchError = _helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"PatchError\"];\nvar deepClone = _helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"_deepClone\"];\n/* We use a Javascript hash to store each\n function. Each hash entry (property) uses\n the operation identifiers specified in rfc6902.\n In this way, we can map each patch operation\n to its dedicated function in efficient way.\n */\n/* The operations applicable to an object */\nvar objOps = {\n add: function (obj, key, document) {\n obj[key] = this.value;\n return { newDocument: document };\n },\n remove: function (obj, key, document) {\n var removed = obj[key];\n delete obj[key];\n return { newDocument: document, removed: removed };\n },\n replace: function (obj, key, document) {\n var removed = obj[key];\n obj[key] = this.value;\n return { newDocument: document, removed: removed };\n },\n move: function (obj, key, document) {\n /* in case move target overwrites an existing value,\n return the removed value, this can be taxing performance-wise,\n and is potentially unneeded */\n var removed = getValueByPointer(document, this.path);\n if (removed) {\n removed = Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"_deepClone\"])(removed);\n }\n var originalValue = applyOperation(document, { op: \"remove\", path: this.from }).removed;\n applyOperation(document, { op: \"add\", path: this.path, value: originalValue });\n return { newDocument: document, removed: removed };\n },\n copy: function (obj, key, document) {\n var valueToCopy = getValueByPointer(document, this.from);\n // enforce copy by value so further operations don't affect source (see issue #177)\n applyOperation(document, { op: \"add\", path: this.path, value: Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"_deepClone\"])(valueToCopy) });\n return { newDocument: document };\n },\n test: function (obj, key, document) {\n return { newDocument: document, test: _areEquals(obj[key], this.value) };\n },\n _get: function (obj, key, document) {\n this.value = obj[key];\n return { newDocument: document };\n }\n};\n/* The operations applicable to an array. Many are the same as for the object */\nvar arrOps = {\n add: function (arr, i, document) {\n if (Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"isInteger\"])(i)) {\n arr.splice(i, 0, this.value);\n }\n else { // array props\n arr[i] = this.value;\n }\n // this may be needed when using '-' in an array\n return { newDocument: document, index: i };\n },\n remove: function (arr, i, document) {\n var removedList = arr.splice(i, 1);\n return { newDocument: document, removed: removedList[0] };\n },\n replace: function (arr, i, document) {\n var removed = arr[i];\n arr[i] = this.value;\n return { newDocument: document, removed: removed };\n },\n move: objOps.move,\n copy: objOps.copy,\n test: objOps.test,\n _get: objOps._get\n};\n/**\n * Retrieves a value from a JSON document by a JSON pointer.\n * Returns the value.\n *\n * @param document The document to get the value from\n * @param pointer an escaped JSON pointer\n * @return The retrieved value\n */\nfunction getValueByPointer(document, pointer) {\n if (pointer == '') {\n return document;\n }\n var getOriginalDestination = { op: \"_get\", path: pointer };\n applyOperation(document, getOriginalDestination);\n return getOriginalDestination.value;\n}\n/**\n * Apply a single JSON Patch Operation on a JSON document.\n * Returns the {newDocument, result} of the operation.\n * It modifies the `document` and `operation` objects - it gets the values by reference.\n * If you would like to avoid touching your values, clone them:\n * `jsonpatch.applyOperation(document, jsonpatch._deepClone(operation))`.\n *\n * @param document The document to patch\n * @param operation The operation to apply\n * @param validateOperation `false` is without validation, `true` to use default jsonpatch's validation, or you can pass a `validateOperation` callback to be used for validation.\n * @param mutateDocument Whether to mutate the original document or clone it before applying\n * @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.\n * @return `{newDocument, result}` after the operation\n */\nfunction applyOperation(document, operation, validateOperation, mutateDocument, banPrototypeModifications, index) {\n if (validateOperation === void 0) { validateOperation = false; }\n if (mutateDocument === void 0) { mutateDocument = true; }\n if (banPrototypeModifications === void 0) { banPrototypeModifications = true; }\n if (index === void 0) { index = 0; }\n if (validateOperation) {\n if (typeof validateOperation == 'function') {\n validateOperation(operation, 0, document, operation.path);\n }\n else {\n validator(operation, 0);\n }\n }\n /* ROOT OPERATIONS */\n if (operation.path === \"\") {\n var returnValue = { newDocument: document };\n if (operation.op === 'add') {\n returnValue.newDocument = operation.value;\n return returnValue;\n }\n else if (operation.op === 'replace') {\n returnValue.newDocument = operation.value;\n returnValue.removed = document; //document we removed\n return returnValue;\n }\n else if (operation.op === 'move' || operation.op === 'copy') { // it's a move or copy to root\n returnValue.newDocument = getValueByPointer(document, operation.from); // get the value by json-pointer in `from` field\n if (operation.op === 'move') { // report removed item\n returnValue.removed = document;\n }\n return returnValue;\n }\n else if (operation.op === 'test') {\n returnValue.test = _areEquals(document, operation.value);\n if (returnValue.test === false) {\n throw new JsonPatchError(\"Test operation failed\", 'TEST_OPERATION_FAILED', index, operation, document);\n }\n returnValue.newDocument = document;\n return returnValue;\n }\n else if (operation.op === 'remove') { // a remove on root\n returnValue.removed = document;\n returnValue.newDocument = null;\n return returnValue;\n }\n else if (operation.op === '_get') {\n operation.value = document;\n return returnValue;\n }\n else { /* bad operation */\n if (validateOperation) {\n throw new JsonPatchError('Operation `op` property is not one of operations defined in RFC-6902', 'OPERATION_OP_INVALID', index, operation, document);\n }\n else {\n return returnValue;\n }\n }\n } /* END ROOT OPERATIONS */\n else {\n if (!mutateDocument) {\n document = Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"_deepClone\"])(document);\n }\n var path = operation.path || \"\";\n var keys = path.split('/');\n var obj = document;\n var t = 1; //skip empty element - http://jsperf.com/to-shift-or-not-to-shift\n var len = keys.length;\n var existingPathFragment = undefined;\n var key = void 0;\n var validateFunction = void 0;\n if (typeof validateOperation == 'function') {\n validateFunction = validateOperation;\n }\n else {\n validateFunction = validator;\n }\n while (true) {\n key = keys[t];\n if (key && key.indexOf('~') != -1) {\n key = Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"unescapePathComponent\"])(key);\n }\n if (banPrototypeModifications &&\n (key == '__proto__' ||\n (key == 'prototype' && t > 0 && keys[t - 1] == 'constructor'))) {\n throw new TypeError('JSON-Patch: modifying `__proto__` or `constructor/prototype` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README');\n }\n if (validateOperation) {\n if (existingPathFragment === undefined) {\n if (obj[key] === undefined) {\n existingPathFragment = keys.slice(0, t).join('/');\n }\n else if (t == len - 1) {\n existingPathFragment = operation.path;\n }\n if (existingPathFragment !== undefined) {\n validateFunction(operation, 0, document, existingPathFragment);\n }\n }\n }\n t++;\n if (Array.isArray(obj)) {\n if (key === '-') {\n key = obj.length;\n }\n else {\n if (validateOperation && !Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"isInteger\"])(key)) {\n throw new JsonPatchError(\"Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index\", \"OPERATION_PATH_ILLEGAL_ARRAY_INDEX\", index, operation, document);\n } // only parse key when it's an integer for `arr.prop` to work\n else if (Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"isInteger\"])(key)) {\n key = ~~key;\n }\n }\n if (t >= len) {\n if (validateOperation && operation.op === \"add\" && key > obj.length) {\n throw new JsonPatchError(\"The specified index MUST NOT be greater than the number of elements in the array\", \"OPERATION_VALUE_OUT_OF_BOUNDS\", index, operation, document);\n }\n var returnValue = arrOps[operation.op].call(operation, obj, key, document); // Apply patch\n if (returnValue.test === false) {\n throw new JsonPatchError(\"Test operation failed\", 'TEST_OPERATION_FAILED', index, operation, document);\n }\n return returnValue;\n }\n }\n else {\n if (t >= len) {\n var returnValue = objOps[operation.op].call(operation, obj, key, document); // Apply patch\n if (returnValue.test === false) {\n throw new JsonPatchError(\"Test operation failed\", 'TEST_OPERATION_FAILED', index, operation, document);\n }\n return returnValue;\n }\n }\n obj = obj[key];\n // If we have more keys in the path, but the next value isn't a non-null object,\n // throw an OPERATION_PATH_UNRESOLVABLE error instead of iterating again.\n if (validateOperation && t < len && (!obj || typeof obj !== \"object\")) {\n throw new JsonPatchError('Cannot perform operation at the desired path', 'OPERATION_PATH_UNRESOLVABLE', index, operation, document);\n }\n }\n }\n}\n/**\n * Apply a full JSON Patch array on a JSON document.\n * Returns the {newDocument, result} of the patch.\n * It modifies the `document` object and `patch` - it gets the values by reference.\n * If you would like to avoid touching your values, clone them:\n * `jsonpatch.applyPatch(document, jsonpatch._deepClone(patch))`.\n *\n * @param document The document to patch\n * @param patch The patch to apply\n * @param validateOperation `false` is without validation, `true` to use default jsonpatch's validation, or you can pass a `validateOperation` callback to be used for validation.\n * @param mutateDocument Whether to mutate the original document or clone it before applying\n * @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.\n * @return An array of `{newDocument, result}` after the patch\n */\nfunction applyPatch(document, patch, validateOperation, mutateDocument, banPrototypeModifications) {\n if (mutateDocument === void 0) { mutateDocument = true; }\n if (banPrototypeModifications === void 0) { banPrototypeModifications = true; }\n if (validateOperation) {\n if (!Array.isArray(patch)) {\n throw new JsonPatchError('Patch sequence must be an array', 'SEQUENCE_NOT_AN_ARRAY');\n }\n }\n if (!mutateDocument) {\n document = Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"_deepClone\"])(document);\n }\n var results = new Array(patch.length);\n for (var i = 0, length_1 = patch.length; i < length_1; i++) {\n // we don't need to pass mutateDocument argument because if it was true, we already deep cloned the object, we'll just pass `true`\n results[i] = applyOperation(document, patch[i], validateOperation, true, banPrototypeModifications, i);\n document = results[i].newDocument; // in case root was replaced\n }\n results.newDocument = document;\n return results;\n}\n/**\n * Apply a single JSON Patch Operation on a JSON document.\n * Returns the updated document.\n * Suitable as a reducer.\n *\n * @param document The document to patch\n * @param operation The operation to apply\n * @return The updated document\n */\nfunction applyReducer(document, operation, index) {\n var operationResult = applyOperation(document, operation);\n if (operationResult.test === false) { // failed test\n throw new JsonPatchError(\"Test operation failed\", 'TEST_OPERATION_FAILED', index, operation, document);\n }\n return operationResult.newDocument;\n}\n/**\n * Validates a single operation. Called from `jsonpatch.validate`. Throws `JsonPatchError` in case of an error.\n * @param {object} operation - operation object (patch)\n * @param {number} index - index of operation in the sequence\n * @param {object} [document] - object where the operation is supposed to be applied\n * @param {string} [existingPathFragment] - comes along with `document`\n */\nfunction validator(operation, index, document, existingPathFragment) {\n if (typeof operation !== 'object' || operation === null || Array.isArray(operation)) {\n throw new JsonPatchError('Operation is not an object', 'OPERATION_NOT_AN_OBJECT', index, operation, document);\n }\n else if (!objOps[operation.op]) {\n throw new JsonPatchError('Operation `op` property is not one of operations defined in RFC-6902', 'OPERATION_OP_INVALID', index, operation, document);\n }\n else if (typeof operation.path !== 'string') {\n throw new JsonPatchError('Operation `path` property is not a string', 'OPERATION_PATH_INVALID', index, operation, document);\n }\n else if (operation.path.indexOf('/') !== 0 && operation.path.length > 0) {\n // paths that aren't empty string should start with \"/\"\n throw new JsonPatchError('Operation `path` property must start with \"/\"', 'OPERATION_PATH_INVALID', index, operation, document);\n }\n else if ((operation.op === 'move' || operation.op === 'copy') && typeof operation.from !== 'string') {\n throw new JsonPatchError('Operation `from` property is not present (applicable in `move` and `copy` operations)', 'OPERATION_FROM_REQUIRED', index, operation, document);\n }\n else if ((operation.op === 'add' || operation.op === 'replace' || operation.op === 'test') && operation.value === undefined) {\n throw new JsonPatchError('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)', 'OPERATION_VALUE_REQUIRED', index, operation, document);\n }\n else if ((operation.op === 'add' || operation.op === 'replace' || operation.op === 'test') && Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"hasUndefined\"])(operation.value)) {\n throw new JsonPatchError('Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)', 'OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED', index, operation, document);\n }\n else if (document) {\n if (operation.op == \"add\") {\n var pathLen = operation.path.split(\"/\").length;\n var existingPathLen = existingPathFragment.split(\"/\").length;\n if (pathLen !== existingPathLen + 1 && pathLen !== existingPathLen) {\n throw new JsonPatchError('Cannot perform an `add` operation at the desired path', 'OPERATION_PATH_CANNOT_ADD', index, operation, document);\n }\n }\n else if (operation.op === 'replace' || operation.op === 'remove' || operation.op === '_get') {\n if (operation.path !== existingPathFragment) {\n throw new JsonPatchError('Cannot perform the operation at a path that does not exist', 'OPERATION_PATH_UNRESOLVABLE', index, operation, document);\n }\n }\n else if (operation.op === 'move' || operation.op === 'copy') {\n var existingValue = { op: \"_get\", path: operation.from, value: undefined };\n var error = validate([existingValue], document);\n if (error && error.name === 'OPERATION_PATH_UNRESOLVABLE') {\n throw new JsonPatchError('Cannot perform the operation from a path that does not exist', 'OPERATION_FROM_UNRESOLVABLE', index, operation, document);\n }\n }\n }\n}\n/**\n * Validates a sequence of operations. If `document` parameter is provided, the sequence is additionally validated against the object document.\n * If error is encountered, returns a JsonPatchError object\n * @param sequence\n * @param document\n * @returns {JsonPatchError|undefined}\n */\nfunction validate(sequence, document, externalValidator) {\n try {\n if (!Array.isArray(sequence)) {\n throw new JsonPatchError('Patch sequence must be an array', 'SEQUENCE_NOT_AN_ARRAY');\n }\n if (document) {\n //clone document and sequence so that we can safely try applying operations\n applyPatch(Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"_deepClone\"])(document), Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"_deepClone\"])(sequence), externalValidator || true);\n }\n else {\n externalValidator = externalValidator || validator;\n for (var i = 0; i < sequence.length; i++) {\n externalValidator(sequence[i], i, document, undefined);\n }\n }\n }\n catch (e) {\n if (e instanceof JsonPatchError) {\n return e;\n }\n else {\n throw e;\n }\n }\n}\n// based on https://github.com/epoberezkin/fast-deep-equal\n// MIT License\n// Copyright (c) 2017 Evgeny Poberezkin\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n// The above copyright notice and this permission notice shall be included in all\n// copies or substantial portions of the Software.\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n// SOFTWARE.\nfunction _areEquals(a, b) {\n if (a === b)\n return true;\n if (a && b && typeof a == 'object' && typeof b == 'object') {\n var arrA = Array.isArray(a), arrB = Array.isArray(b), i, length, key;\n if (arrA && arrB) {\n length = a.length;\n if (length != b.length)\n return false;\n for (i = length; i-- !== 0;)\n if (!_areEquals(a[i], b[i]))\n return false;\n return true;\n }\n if (arrA != arrB)\n return false;\n var keys = Object.keys(a);\n length = keys.length;\n if (length !== Object.keys(b).length)\n return false;\n for (i = length; i-- !== 0;)\n if (!b.hasOwnProperty(keys[i]))\n return false;\n for (i = length; i-- !== 0;) {\n key = keys[i];\n if (!_areEquals(a[key], b[key]))\n return false;\n }\n return true;\n }\n return a !== a && b !== b;\n}\n;\n\n\n//# sourceURL=webpack://WatchTogetherSDK/./node_modules/fast-json-patch/module/core.mjs?");
5411
5411
 
5412
5412
  /***/ }),
5413
5413
 
@@ -5419,7 +5419,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) *
5419
5419
  /***/ (function(__webpack_module__, __webpack_exports__, __webpack_require__) {
5420
5420
 
5421
5421
  "use strict";
5422
- eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"unobserve\", function() { return unobserve; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"observe\", function() { return observe; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"generate\", function() { return generate; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"compare\", function() { return compare; });\n/* harmony import */ var _helpers_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./helpers.mjs */ \"./node_modules/fast-json-patch/module/helpers.mjs\");\n/* harmony import */ var _core_mjs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./core.mjs */ \"./node_modules/fast-json-patch/module/core.mjs\");\n/*!\n * https://github.com/Starcounter-Jack/JSON-Patch\n * (c) 2017 Joachim Wester\n * MIT license\n */\n\n\nvar beforeDict = new WeakMap();\nvar Mirror = /** @class */ (function () {\n function Mirror(obj) {\n this.observers = new Map();\n this.obj = obj;\n }\n return Mirror;\n}());\nvar ObserverInfo = /** @class */ (function () {\n function ObserverInfo(callback, observer) {\n this.callback = callback;\n this.observer = observer;\n }\n return ObserverInfo;\n}());\nfunction getMirror(obj) {\n return beforeDict.get(obj);\n}\nfunction getObserverFromMirror(mirror, callback) {\n return mirror.observers.get(callback);\n}\nfunction removeObserverFromMirror(mirror, observer) {\n mirror.observers.delete(observer.callback);\n}\n/**\n * Detach an observer from an object\n */\nfunction unobserve(root, observer) {\n observer.unobserve();\n}\n/**\n * Observes changes made to an object, which can then be retrieved using generate\n */\nfunction observe(obj, callback) {\n var patches = [];\n var observer;\n var mirror = getMirror(obj);\n if (!mirror) {\n mirror = new Mirror(obj);\n beforeDict.set(obj, mirror);\n }\n else {\n var observerInfo = getObserverFromMirror(mirror, callback);\n observer = observerInfo && observerInfo.observer;\n }\n if (observer) {\n return observer;\n }\n observer = {};\n mirror.value = Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"_deepClone\"])(obj);\n if (callback) {\n observer.callback = callback;\n observer.next = null;\n var dirtyCheck = function () {\n generate(observer);\n };\n var fastCheck = function () {\n clearTimeout(observer.next);\n observer.next = setTimeout(dirtyCheck);\n };\n if (typeof window !== 'undefined') { //not Node\n window.addEventListener('mouseup', fastCheck);\n window.addEventListener('keyup', fastCheck);\n window.addEventListener('mousedown', fastCheck);\n window.addEventListener('keydown', fastCheck);\n window.addEventListener('change', fastCheck);\n }\n }\n observer.patches = patches;\n observer.object = obj;\n observer.unobserve = function () {\n generate(observer);\n clearTimeout(observer.next);\n removeObserverFromMirror(mirror, observer);\n if (typeof window !== 'undefined') {\n window.removeEventListener('mouseup', fastCheck);\n window.removeEventListener('keyup', fastCheck);\n window.removeEventListener('mousedown', fastCheck);\n window.removeEventListener('keydown', fastCheck);\n window.removeEventListener('change', fastCheck);\n }\n };\n mirror.observers.set(callback, new ObserverInfo(callback, observer));\n return observer;\n}\n/**\n * Generate an array of patches from an observer\n */\nfunction generate(observer, invertible) {\n if (invertible === void 0) { invertible = false; }\n var mirror = beforeDict.get(observer.object);\n _generate(mirror.value, observer.object, observer.patches, \"\", invertible);\n if (observer.patches.length) {\n Object(_core_mjs__WEBPACK_IMPORTED_MODULE_1__[\"applyPatch\"])(mirror.value, observer.patches);\n }\n var temp = observer.patches;\n if (temp.length > 0) {\n observer.patches = [];\n if (observer.callback) {\n observer.callback(temp);\n }\n }\n return temp;\n}\n// Dirty check if obj is different from mirror, generate patches and update mirror\nfunction _generate(mirror, obj, patches, path, invertible) {\n if (obj === mirror) {\n return;\n }\n if (typeof obj.toJSON === \"function\") {\n obj = obj.toJSON();\n }\n var newKeys = Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"_objectKeys\"])(obj);\n var oldKeys = Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"_objectKeys\"])(mirror);\n var changed = false;\n var deleted = false;\n //if ever \"move\" operation is implemented here, make sure this test runs OK: \"should not generate the same patch twice (move)\"\n for (var t = oldKeys.length - 1; t >= 0; t--) {\n var key = oldKeys[t];\n var oldVal = mirror[key];\n if (Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"hasOwnProperty\"])(obj, key) && !(obj[key] === undefined && oldVal !== undefined && Array.isArray(obj) === false)) {\n var newVal = obj[key];\n if (typeof oldVal == \"object\" && oldVal != null && typeof newVal == \"object\" && newVal != null && Array.isArray(oldVal) === Array.isArray(newVal)) {\n _generate(oldVal, newVal, patches, path + \"/\" + Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"escapePathComponent\"])(key), invertible);\n }\n else {\n if (oldVal !== newVal) {\n changed = true;\n if (invertible) {\n patches.push({ op: \"test\", path: path + \"/\" + Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"escapePathComponent\"])(key), value: Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"_deepClone\"])(oldVal) });\n }\n patches.push({ op: \"replace\", path: path + \"/\" + Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"escapePathComponent\"])(key), value: Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"_deepClone\"])(newVal) });\n }\n }\n }\n else if (Array.isArray(mirror) === Array.isArray(obj)) {\n if (invertible) {\n patches.push({ op: \"test\", path: path + \"/\" + Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"escapePathComponent\"])(key), value: Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"_deepClone\"])(oldVal) });\n }\n patches.push({ op: \"remove\", path: path + \"/\" + Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"escapePathComponent\"])(key) });\n deleted = true; // property has been deleted\n }\n else {\n if (invertible) {\n patches.push({ op: \"test\", path: path, value: mirror });\n }\n patches.push({ op: \"replace\", path: path, value: obj });\n changed = true;\n }\n }\n if (!deleted && newKeys.length == oldKeys.length) {\n return;\n }\n for (var t = 0; t < newKeys.length; t++) {\n var key = newKeys[t];\n if (!Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"hasOwnProperty\"])(mirror, key) && obj[key] !== undefined) {\n patches.push({ op: \"add\", path: path + \"/\" + Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"escapePathComponent\"])(key), value: Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"_deepClone\"])(obj[key]) });\n }\n }\n}\n/**\n * Create an array of patches from the differences in two objects\n */\nfunction compare(tree1, tree2, invertible) {\n if (invertible === void 0) { invertible = false; }\n var patches = [];\n _generate(tree1, tree2, patches, '', invertible);\n return patches;\n}\n\n\n//# sourceURL=webpack://WatchTogetherSDK/./node_modules/fast-json-patch/module/duplex.mjs?");
5422
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"unobserve\", function() { return unobserve; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"observe\", function() { return observe; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"generate\", function() { return generate; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"compare\", function() { return compare; });\n/* harmony import */ var _helpers_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./helpers.mjs */ \"./node_modules/fast-json-patch/module/helpers.mjs\");\n/* harmony import */ var _core_mjs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./core.mjs */ \"./node_modules/fast-json-patch/module/core.mjs\");\n/*!\n * https://github.com/Starcounter-Jack/JSON-Patch\n * (c) 2017-2021 Joachim Wester\n * MIT license\n */\n\n\nvar beforeDict = new WeakMap();\nvar Mirror = /** @class */ (function () {\n function Mirror(obj) {\n this.observers = new Map();\n this.obj = obj;\n }\n return Mirror;\n}());\nvar ObserverInfo = /** @class */ (function () {\n function ObserverInfo(callback, observer) {\n this.callback = callback;\n this.observer = observer;\n }\n return ObserverInfo;\n}());\nfunction getMirror(obj) {\n return beforeDict.get(obj);\n}\nfunction getObserverFromMirror(mirror, callback) {\n return mirror.observers.get(callback);\n}\nfunction removeObserverFromMirror(mirror, observer) {\n mirror.observers.delete(observer.callback);\n}\n/**\n * Detach an observer from an object\n */\nfunction unobserve(root, observer) {\n observer.unobserve();\n}\n/**\n * Observes changes made to an object, which can then be retrieved using generate\n */\nfunction observe(obj, callback) {\n var patches = [];\n var observer;\n var mirror = getMirror(obj);\n if (!mirror) {\n mirror = new Mirror(obj);\n beforeDict.set(obj, mirror);\n }\n else {\n var observerInfo = getObserverFromMirror(mirror, callback);\n observer = observerInfo && observerInfo.observer;\n }\n if (observer) {\n return observer;\n }\n observer = {};\n mirror.value = Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"_deepClone\"])(obj);\n if (callback) {\n observer.callback = callback;\n observer.next = null;\n var dirtyCheck = function () {\n generate(observer);\n };\n var fastCheck = function () {\n clearTimeout(observer.next);\n observer.next = setTimeout(dirtyCheck);\n };\n if (typeof window !== 'undefined') { //not Node\n window.addEventListener('mouseup', fastCheck);\n window.addEventListener('keyup', fastCheck);\n window.addEventListener('mousedown', fastCheck);\n window.addEventListener('keydown', fastCheck);\n window.addEventListener('change', fastCheck);\n }\n }\n observer.patches = patches;\n observer.object = obj;\n observer.unobserve = function () {\n generate(observer);\n clearTimeout(observer.next);\n removeObserverFromMirror(mirror, observer);\n if (typeof window !== 'undefined') {\n window.removeEventListener('mouseup', fastCheck);\n window.removeEventListener('keyup', fastCheck);\n window.removeEventListener('mousedown', fastCheck);\n window.removeEventListener('keydown', fastCheck);\n window.removeEventListener('change', fastCheck);\n }\n };\n mirror.observers.set(callback, new ObserverInfo(callback, observer));\n return observer;\n}\n/**\n * Generate an array of patches from an observer\n */\nfunction generate(observer, invertible) {\n if (invertible === void 0) { invertible = false; }\n var mirror = beforeDict.get(observer.object);\n _generate(mirror.value, observer.object, observer.patches, \"\", invertible);\n if (observer.patches.length) {\n Object(_core_mjs__WEBPACK_IMPORTED_MODULE_1__[\"applyPatch\"])(mirror.value, observer.patches);\n }\n var temp = observer.patches;\n if (temp.length > 0) {\n observer.patches = [];\n if (observer.callback) {\n observer.callback(temp);\n }\n }\n return temp;\n}\n// Dirty check if obj is different from mirror, generate patches and update mirror\nfunction _generate(mirror, obj, patches, path, invertible) {\n if (obj === mirror) {\n return;\n }\n if (typeof obj.toJSON === \"function\") {\n obj = obj.toJSON();\n }\n var newKeys = Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"_objectKeys\"])(obj);\n var oldKeys = Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"_objectKeys\"])(mirror);\n var changed = false;\n var deleted = false;\n //if ever \"move\" operation is implemented here, make sure this test runs OK: \"should not generate the same patch twice (move)\"\n for (var t = oldKeys.length - 1; t >= 0; t--) {\n var key = oldKeys[t];\n var oldVal = mirror[key];\n if (Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"hasOwnProperty\"])(obj, key) && !(obj[key] === undefined && oldVal !== undefined && Array.isArray(obj) === false)) {\n var newVal = obj[key];\n if (typeof oldVal == \"object\" && oldVal != null && typeof newVal == \"object\" && newVal != null && Array.isArray(oldVal) === Array.isArray(newVal)) {\n _generate(oldVal, newVal, patches, path + \"/\" + Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"escapePathComponent\"])(key), invertible);\n }\n else {\n if (oldVal !== newVal) {\n changed = true;\n if (invertible) {\n patches.push({ op: \"test\", path: path + \"/\" + Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"escapePathComponent\"])(key), value: Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"_deepClone\"])(oldVal) });\n }\n patches.push({ op: \"replace\", path: path + \"/\" + Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"escapePathComponent\"])(key), value: Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"_deepClone\"])(newVal) });\n }\n }\n }\n else if (Array.isArray(mirror) === Array.isArray(obj)) {\n if (invertible) {\n patches.push({ op: \"test\", path: path + \"/\" + Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"escapePathComponent\"])(key), value: Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"_deepClone\"])(oldVal) });\n }\n patches.push({ op: \"remove\", path: path + \"/\" + Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"escapePathComponent\"])(key) });\n deleted = true; // property has been deleted\n }\n else {\n if (invertible) {\n patches.push({ op: \"test\", path: path, value: mirror });\n }\n patches.push({ op: \"replace\", path: path, value: obj });\n changed = true;\n }\n }\n if (!deleted && newKeys.length == oldKeys.length) {\n return;\n }\n for (var t = 0; t < newKeys.length; t++) {\n var key = newKeys[t];\n if (!Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"hasOwnProperty\"])(mirror, key) && obj[key] !== undefined) {\n patches.push({ op: \"add\", path: path + \"/\" + Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"escapePathComponent\"])(key), value: Object(_helpers_mjs__WEBPACK_IMPORTED_MODULE_0__[\"_deepClone\"])(obj[key]) });\n }\n }\n}\n/**\n * Create an array of patches from the differences in two objects\n */\nfunction compare(tree1, tree2, invertible) {\n if (invertible === void 0) { invertible = false; }\n var patches = [];\n _generate(tree1, tree2, patches, '', invertible);\n return patches;\n}\n\n\n//# sourceURL=webpack://WatchTogetherSDK/./node_modules/fast-json-patch/module/duplex.mjs?");
5423
5423
 
5424
5424
  /***/ }),
5425
5425
 
@@ -5431,7 +5431,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) *
5431
5431
  /***/ (function(__webpack_module__, __webpack_exports__, __webpack_require__) {
5432
5432
 
5433
5433
  "use strict";
5434
- eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"hasOwnProperty\", function() { return hasOwnProperty; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"_objectKeys\", function() { return _objectKeys; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"_deepClone\", function() { return _deepClone; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"isInteger\", function() { return isInteger; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"escapePathComponent\", function() { return escapePathComponent; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"unescapePathComponent\", function() { return unescapePathComponent; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"_getPathRecursive\", function() { return _getPathRecursive; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"getPath\", function() { return getPath; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"hasUndefined\", function() { return hasUndefined; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"PatchError\", function() { return PatchError; });\n/*!\n * https://github.com/Starcounter-Jack/JSON-Patch\n * (c) 2017 Joachim Wester\n * MIT license\n */\nvar __extends = (undefined && undefined.__extends) || (function () {\n var extendStatics = function (d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\n return extendStatics(d, b);\n };\n return function (d, b) {\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nvar _hasOwnProperty = Object.prototype.hasOwnProperty;\nfunction hasOwnProperty(obj, key) {\n return _hasOwnProperty.call(obj, key);\n}\nfunction _objectKeys(obj) {\n if (Array.isArray(obj)) {\n var keys = new Array(obj.length);\n for (var k = 0; k < keys.length; k++) {\n keys[k] = \"\" + k;\n }\n return keys;\n }\n if (Object.keys) {\n return Object.keys(obj);\n }\n var keys = [];\n for (var i in obj) {\n if (hasOwnProperty(obj, i)) {\n keys.push(i);\n }\n }\n return keys;\n}\n;\n/**\n* Deeply clone the object.\n* https://jsperf.com/deep-copy-vs-json-stringify-json-parse/25 (recursiveDeepCopy)\n* @param {any} obj value to clone\n* @return {any} cloned obj\n*/\nfunction _deepClone(obj) {\n switch (typeof obj) {\n case \"object\":\n return JSON.parse(JSON.stringify(obj)); //Faster than ES5 clone - http://jsperf.com/deep-cloning-of-objects/5\n case \"undefined\":\n return null; //this is how JSON.stringify behaves for array items\n default:\n return obj; //no need to clone primitives\n }\n}\n//3x faster than cached /^\\d+$/.test(str)\nfunction isInteger(str) {\n var i = 0;\n var len = str.length;\n var charCode;\n while (i < len) {\n charCode = str.charCodeAt(i);\n if (charCode >= 48 && charCode <= 57) {\n i++;\n continue;\n }\n return false;\n }\n return true;\n}\n/**\n* Escapes a json pointer path\n* @param path The raw pointer\n* @return the Escaped path\n*/\nfunction escapePathComponent(path) {\n if (path.indexOf('/') === -1 && path.indexOf('~') === -1)\n return path;\n return path.replace(/~/g, '~0').replace(/\\//g, '~1');\n}\n/**\n * Unescapes a json pointer path\n * @param path The escaped pointer\n * @return The unescaped path\n */\nfunction unescapePathComponent(path) {\n return path.replace(/~1/g, '/').replace(/~0/g, '~');\n}\nfunction _getPathRecursive(root, obj) {\n var found;\n for (var key in root) {\n if (hasOwnProperty(root, key)) {\n if (root[key] === obj) {\n return escapePathComponent(key) + '/';\n }\n else if (typeof root[key] === 'object') {\n found = _getPathRecursive(root[key], obj);\n if (found != '') {\n return escapePathComponent(key) + '/' + found;\n }\n }\n }\n }\n return '';\n}\nfunction getPath(root, obj) {\n if (root === obj) {\n return '/';\n }\n var path = _getPathRecursive(root, obj);\n if (path === '') {\n throw new Error(\"Object not found in root\");\n }\n return '/' + path;\n}\n/**\n* Recursively checks whether an object has any undefined values inside.\n*/\nfunction hasUndefined(obj) {\n if (obj === undefined) {\n return true;\n }\n if (obj) {\n if (Array.isArray(obj)) {\n for (var i = 0, len = obj.length; i < len; i++) {\n if (hasUndefined(obj[i])) {\n return true;\n }\n }\n }\n else if (typeof obj === \"object\") {\n var objKeys = _objectKeys(obj);\n var objKeysLength = objKeys.length;\n for (var i = 0; i < objKeysLength; i++) {\n if (hasUndefined(obj[objKeys[i]])) {\n return true;\n }\n }\n }\n }\n return false;\n}\nfunction patchErrorMessageFormatter(message, args) {\n var messageParts = [message];\n for (var key in args) {\n var value = typeof args[key] === 'object' ? JSON.stringify(args[key], null, 2) : args[key]; // pretty print\n if (typeof value !== 'undefined') {\n messageParts.push(key + \": \" + value);\n }\n }\n return messageParts.join('\\n');\n}\nvar PatchError = /** @class */ (function (_super) {\n __extends(PatchError, _super);\n function PatchError(message, name, index, operation, tree) {\n var _newTarget = this.constructor;\n var _this = _super.call(this, patchErrorMessageFormatter(message, { name: name, index: index, operation: operation, tree: tree })) || this;\n _this.name = name;\n _this.index = index;\n _this.operation = operation;\n _this.tree = tree;\n Object.setPrototypeOf(_this, _newTarget.prototype); // restore prototype chain, see https://stackoverflow.com/a/48342359\n _this.message = patchErrorMessageFormatter(message, { name: name, index: index, operation: operation, tree: tree });\n return _this;\n }\n return PatchError;\n}(Error));\n\n\n\n//# sourceURL=webpack://WatchTogetherSDK/./node_modules/fast-json-patch/module/helpers.mjs?");
5434
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"hasOwnProperty\", function() { return hasOwnProperty; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"_objectKeys\", function() { return _objectKeys; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"_deepClone\", function() { return _deepClone; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"isInteger\", function() { return isInteger; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"escapePathComponent\", function() { return escapePathComponent; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"unescapePathComponent\", function() { return unescapePathComponent; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"_getPathRecursive\", function() { return _getPathRecursive; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"getPath\", function() { return getPath; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"hasUndefined\", function() { return hasUndefined; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"PatchError\", function() { return PatchError; });\n/*!\n * https://github.com/Starcounter-Jack/JSON-Patch\n * (c) 2017-2022 Joachim Wester\n * MIT licensed\n */\nvar __extends = (undefined && undefined.__extends) || (function () {\n var extendStatics = function (d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\n return extendStatics(d, b);\n };\n return function (d, b) {\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nvar _hasOwnProperty = Object.prototype.hasOwnProperty;\nfunction hasOwnProperty(obj, key) {\n return _hasOwnProperty.call(obj, key);\n}\nfunction _objectKeys(obj) {\n if (Array.isArray(obj)) {\n var keys_1 = new Array(obj.length);\n for (var k = 0; k < keys_1.length; k++) {\n keys_1[k] = \"\" + k;\n }\n return keys_1;\n }\n if (Object.keys) {\n return Object.keys(obj);\n }\n var keys = [];\n for (var i in obj) {\n if (hasOwnProperty(obj, i)) {\n keys.push(i);\n }\n }\n return keys;\n}\n;\n/**\n* Deeply clone the object.\n* https://jsperf.com/deep-copy-vs-json-stringify-json-parse/25 (recursiveDeepCopy)\n* @param {any} obj value to clone\n* @return {any} cloned obj\n*/\nfunction _deepClone(obj) {\n switch (typeof obj) {\n case \"object\":\n return JSON.parse(JSON.stringify(obj)); //Faster than ES5 clone - http://jsperf.com/deep-cloning-of-objects/5\n case \"undefined\":\n return null; //this is how JSON.stringify behaves for array items\n default:\n return obj; //no need to clone primitives\n }\n}\n//3x faster than cached /^\\d+$/.test(str)\nfunction isInteger(str) {\n var i = 0;\n var len = str.length;\n var charCode;\n while (i < len) {\n charCode = str.charCodeAt(i);\n if (charCode >= 48 && charCode <= 57) {\n i++;\n continue;\n }\n return false;\n }\n return true;\n}\n/**\n* Escapes a json pointer path\n* @param path The raw pointer\n* @return the Escaped path\n*/\nfunction escapePathComponent(path) {\n if (path.indexOf('/') === -1 && path.indexOf('~') === -1)\n return path;\n return path.replace(/~/g, '~0').replace(/\\//g, '~1');\n}\n/**\n * Unescapes a json pointer path\n * @param path The escaped pointer\n * @return The unescaped path\n */\nfunction unescapePathComponent(path) {\n return path.replace(/~1/g, '/').replace(/~0/g, '~');\n}\nfunction _getPathRecursive(root, obj) {\n var found;\n for (var key in root) {\n if (hasOwnProperty(root, key)) {\n if (root[key] === obj) {\n return escapePathComponent(key) + '/';\n }\n else if (typeof root[key] === 'object') {\n found = _getPathRecursive(root[key], obj);\n if (found != '') {\n return escapePathComponent(key) + '/' + found;\n }\n }\n }\n }\n return '';\n}\nfunction getPath(root, obj) {\n if (root === obj) {\n return '/';\n }\n var path = _getPathRecursive(root, obj);\n if (path === '') {\n throw new Error(\"Object not found in root\");\n }\n return \"/\" + path;\n}\n/**\n* Recursively checks whether an object has any undefined values inside.\n*/\nfunction hasUndefined(obj) {\n if (obj === undefined) {\n return true;\n }\n if (obj) {\n if (Array.isArray(obj)) {\n for (var i_1 = 0, len = obj.length; i_1 < len; i_1++) {\n if (hasUndefined(obj[i_1])) {\n return true;\n }\n }\n }\n else if (typeof obj === \"object\") {\n var objKeys = _objectKeys(obj);\n var objKeysLength = objKeys.length;\n for (var i = 0; i < objKeysLength; i++) {\n if (hasUndefined(obj[objKeys[i]])) {\n return true;\n }\n }\n }\n }\n return false;\n}\nfunction patchErrorMessageFormatter(message, args) {\n var messageParts = [message];\n for (var key in args) {\n var value = typeof args[key] === 'object' ? JSON.stringify(args[key], null, 2) : args[key]; // pretty print\n if (typeof value !== 'undefined') {\n messageParts.push(key + \": \" + value);\n }\n }\n return messageParts.join('\\n');\n}\nvar PatchError = /** @class */ (function (_super) {\n __extends(PatchError, _super);\n function PatchError(message, name, index, operation, tree) {\n var _newTarget = this.constructor;\n var _this = _super.call(this, patchErrorMessageFormatter(message, { name: name, index: index, operation: operation, tree: tree })) || this;\n _this.name = name;\n _this.index = index;\n _this.operation = operation;\n _this.tree = tree;\n Object.setPrototypeOf(_this, _newTarget.prototype); // restore prototype chain, see https://stackoverflow.com/a/48342359\n _this.message = patchErrorMessageFormatter(message, { name: name, index: index, operation: operation, tree: tree });\n return _this;\n }\n return PatchError;\n}(Error));\n\n\n\n//# sourceURL=webpack://WatchTogetherSDK/./node_modules/fast-json-patch/module/helpers.mjs?");
5435
5435
 
5436
5436
  /***/ }),
5437
5437
 
@@ -8570,7 +8570,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var aws_
8570
8570
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
8571
8571
 
8572
8572
  "use strict";
8573
- eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var webrtc_adapter__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! webrtc-adapter */ \"./node_modules/webrtc-adapter/src/js/adapter_core.js\");\n/* harmony import */ var _wt_emitter__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./wt-emitter */ \"./src/modules/wt-emitter.js\");\n/* harmony import */ var _wt_utils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./wt-utils */ \"./src/modules/wt-utils.js\");\nfunction _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }\n\nfunction _nonIterableRest() { throw new TypeError(\"Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\"); }\n\nfunction _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === \"string\") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === \"Object\" && o.constructor) n = o.constructor.name; if (n === \"Map\" || n === \"Set\") return Array.from(o); if (n === \"Arguments\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }\n\nfunction _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }\n\nfunction _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== \"undefined\" && arr[Symbol.iterator] || arr[\"@@iterator\"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"] != null) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; }\n\nfunction _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }\n\nfunction ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }\n\nfunction _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }\n\nfunction _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, \"prototype\", { writable: false }); return Constructor; }\n\n// Watch together janus webrtc library\n\n\n\n\nvar Room = /*#__PURE__*/function () {\n function Room(debug) {\n var _this = this;\n\n _classCallCheck(this, Room);\n\n this.debug = debug;\n this.sessions = [];\n this.safariVp8 = false;\n this.browser = webrtc_adapter__WEBPACK_IMPORTED_MODULE_0__[\"default\"].browserDetails.browser;\n this.browserDetails = webrtc_adapter__WEBPACK_IMPORTED_MODULE_0__[\"default\"].browserDetails;\n this.webrtcSupported = Room.isWebrtcSupported();\n this.safariVp8TestPromise = Room.testSafariVp8();\n this.safariVp8 = null;\n this.safariVp8TestPromise.then(function (safariVp8) {\n _this.safariVp8 = safariVp8;\n }); // Let's get it started\n\n this.whenInitialized = this.initialize();\n }\n\n _createClass(Room, [{\n key: \"initialize\",\n value: function initialize() {\n var _this2 = this;\n\n return this.safariVp8TestPromise.then(function () {\n return _this2;\n });\n }\n }, {\n key: \"createSession\",\n value: function createSession() {\n var constructId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;\n var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'reactooroom';\n var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};\n return new RoomSession(constructId, type, _objectSpread({\n debug: this.debug\n }, options));\n }\n }], [{\n key: \"testSafariVp8\",\n value: function testSafariVp8() {\n return new Promise(function (resolve) {\n if (webrtc_adapter__WEBPACK_IMPORTED_MODULE_0__[\"default\"].browserDetails.browser === 'safari' && webrtc_adapter__WEBPACK_IMPORTED_MODULE_0__[\"default\"].browserDetails.version >= 605) {\n if (RTCRtpSender && RTCRtpSender.getCapabilities && RTCRtpSender.getCapabilities(\"video\") && RTCRtpSender.getCapabilities(\"video\").codecs && RTCRtpSender.getCapabilities(\"video\").codecs.length) {\n var isVp8 = false;\n\n for (var i in RTCRtpSender.getCapabilities(\"video\").codecs) {\n var codec = RTCRtpSender.getCapabilities(\"video\").codecs[i];\n\n if (codec && codec.mimeType && codec.mimeType.toLowerCase() === \"video/vp8\") {\n isVp8 = true;\n break;\n }\n }\n\n resolve(isVp8);\n } else {\n // We do it in a very ugly way, as there's no alternative...\n // We create a PeerConnection to see if VP8 is in an offer\n var testpc = new RTCPeerConnection({}, {});\n testpc.createOffer({\n offerToReceiveVideo: true\n }).then(function (offer) {\n var result = offer.sdp.indexOf(\"VP8\") !== -1;\n testpc.close();\n testpc = null;\n resolve(result);\n });\n }\n } else resolve(false);\n });\n }\n }, {\n key: \"isWebrtcSupported\",\n value: function isWebrtcSupported() {\n return window.RTCPeerConnection !== undefined && window.RTCPeerConnection !== null && navigator.mediaDevices !== undefined && navigator.mediaDevices !== null && navigator.mediaDevices.getUserMedia !== undefined && navigator.mediaDevices.getUserMedia !== null;\n }\n }]);\n\n return Room;\n}();\n\nvar RoomSession = /*#__PURE__*/function () {\n function RoomSession() {\n var constructId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;\n var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'reactooroom';\n var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};\n\n _classCallCheck(this, RoomSession);\n\n Object.assign(this, Object(_wt_emitter__WEBPACK_IMPORTED_MODULE_1__[\"default\"])());\n this.server = null;\n this.iceServers = null;\n this.token = null;\n this.roomId = null;\n this.streamId = null;\n this.pin = null;\n this.userId = null;\n this.sessiontype = type;\n this.initialBitrate = 0; //TODO: remove this\n\n this.isMonitor = false; // currently used just for classroom context so monitor user only subscribes to participants and not trainer (for other monitor this flag is not necessary)\n\n this.recordingFilename = null;\n this.pluginName = RoomSession.sessionTypes[type];\n this.options = options;\n this.id = null;\n this.privateId = null;\n this.constructId = constructId || RoomSession.randomString(16);\n this.sessionId = null;\n this.handleId = null;\n this.ws = null;\n this.isRestarting = false; //TODO: do it better\n // double click prevention\n\n this.connectingPromise = null;\n this.disconnectingPromise = null;\n this._ipv6Support = false;\n this._retries = 0;\n this._maxRetries = 3;\n this._keepAliveId = null;\n this._participants = [];\n this._observerIds = [];\n this._talkbackIds = [];\n this._instuctorId = null;\n this._hasJoined = false;\n this._isStreaming = false;\n this._isPublished = false;\n this._isDataChannelOpen = false;\n this.isAudioMuted = false;\n this.isVideoMuted = false;\n this.isVideoEnabled = false;\n this.isAudioEnabed = false;\n this.isUnifiedPlan = RoomSession.checkUnifiedPlan();\n this.subscriptionRules = _objectSpread(_objectSpread({}, RoomSession.subscriptionRules), this.options.subscriptionRules || {});\n this._log = RoomSession.noop;\n\n if (this.options.debug) {\n this._enableDebug();\n }\n } // Check if this browser supports Unified Plan and transceivers\n // Based on https://codepen.io/anon/pen/ZqLwWV?editors=0010\n\n\n _createClass(RoomSession, [{\n key: \"_participantShouldSubscribe\",\n value: function _participantShouldSubscribe(userId) {\n var allowedObservers = this._observerIds || [];\n var allowedTalkback = this._talkbackIds || [];\n var allowedInstructor = this._instuctorId || null;\n var localUserRole = 'participant';\n\n if (this.isMonitor) {\n localUserRole = 'monitor';\n } else if (allowedObservers.indexOf(this.userId) > -1) {\n localUserRole = 'observer';\n } else if (allowedTalkback.indexOf(this.userId) > -1) {\n localUserRole = 'talkback';\n } else if (this.userId === allowedInstructor) {\n localUserRole = 'instructor';\n }\n\n var remoteUserRole = 'participant';\n\n if (allowedObservers.indexOf(userId) > -1) {\n remoteUserRole = 'observer';\n } else if (allowedTalkback.indexOf(userId) > -1) {\n remoteUserRole = 'talkback';\n } else if (userId === allowedInstructor) {\n remoteUserRole = 'instructor';\n }\n\n var mode = allowedInstructor !== null ? 'videoWall' : 'watchTogether';\n return this.subscriptionRules[localUserRole][mode].indexOf(remoteUserRole) > -1;\n }\n }, {\n key: \"_getAddParticipantEventName\",\n value: function _getAddParticipantEventName(handleId) {\n var handle = this._getHandle(handleId);\n\n if (!handle) {\n this.emit('error', {\n type: 'warning',\n id: 15,\n message: 'id non-existent',\n data: [handleId, 'getParticipantEventName']\n });\n }\n\n var allowedTalkback = this._talkbackIds || [];\n var allowedObservers = this._observerIds || [];\n var allowedInstructor = this._instuctorId || null;\n var eventName = 'addRemoteParticipant';\n\n if (handle.userId === allowedInstructor) {\n eventName = 'addRemoteInstructor';\n }\n\n if (allowedTalkback.indexOf(handle.userId) > -1) {\n eventName = 'addRemoteTalkback';\n }\n\n if (allowedObservers.indexOf(handle.userId) > -1) {\n eventName = 'addRemoteObserver';\n }\n\n return eventName;\n }\n }, {\n key: \"_getRemoveParticipantEventName\",\n value: function _getRemoveParticipantEventName(handleId) {\n var handle = this._getHandle(handleId);\n\n if (!handle) {\n this.emit('error', {\n type: 'warning',\n id: 15,\n message: 'id non-existent',\n data: [handleId, 'getParticipantEventName']\n });\n }\n\n var allowedTalkback = this._talkbackIds || [];\n var allowedObservers = this._observerIds || [];\n var allowedInstructor = this._instuctorId || null;\n var eventName = 'removeRemoteParticipant';\n\n if (handle.userId === allowedInstructor) {\n eventName = 'removeRemoteInstructor';\n }\n\n if (allowedTalkback.indexOf(handle.userId) > -1) {\n eventName = 'removeRemoteTalkback';\n }\n\n if (allowedObservers.indexOf(handle.userId) > -1) {\n eventName = 'removeRemoteObserver';\n }\n\n return eventName;\n }\n }, {\n key: \"sendMessage\",\n value: function sendMessage(handleId) {\n var message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {\n body: 'Example Body'\n };\n var dontWait = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;\n var dontResolveOnAck = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;\n return this._send(_objectSpread({\n \"janus\": \"message\",\n \"handle_id\": handleId\n }, message), dontWait, dontResolveOnAck).then(function (json) {\n if (json && json[\"janus\"] === \"success\") {\n var plugindata = json[\"plugindata\"] || {};\n var data = plugindata[\"data\"];\n return Promise.resolve(data);\n }\n\n return Promise.resolve();\n }).catch(function (json) {\n if (json && json[\"error\"]) {\n return Promise.reject({\n type: 'warning',\n id: 1,\n message: 'sendMessage failed',\n data: json[\"error\"]\n });\n } else {\n return Promise.reject({\n type: 'warning',\n id: 1,\n message: 'sendMessage failed',\n data: json\n });\n }\n });\n }\n }, {\n key: \"_send\",\n value: function _send() {\n var _this3 = this;\n\n var request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n var ignoreResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;\n var dontResolveOnAck = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;\n var transaction = RoomSession.randomString(12);\n\n var requestData = _objectSpread(_objectSpread({}, request), {}, {\n transaction: transaction,\n token: this.token\n }, this.sessionId && {\n 'session_id': this.sessionId\n } || {});\n\n var timeouId = null;\n return new Promise(function (resolve, reject) {\n var parseResponse = function parseResponse(event) {\n var json = JSON.parse(event.data);\n var r_transaction = json['transaction'];\n\n if (r_transaction === transaction && (!dontResolveOnAck || json['janus'] !== 'ack')) {\n clearTimeout(timeouId);\n\n _this3.ws.removeEventListener('message', parseResponse);\n\n if (json['janus'] === 'error') {\n var _json$error;\n\n if ((json === null || json === void 0 ? void 0 : (_json$error = json.error) === null || _json$error === void 0 ? void 0 : _json$error.code) == 403) {\n _this3.disconnect(true);\n }\n\n reject({\n type: 'error',\n id: 2,\n message: 'send failed',\n data: json,\n requestData: requestData\n });\n } else {\n resolve(json);\n }\n }\n };\n\n if (ignoreResponse) {\n if (_this3.ws && _this3.ws.readyState === 1) {\n _this3.ws.send(JSON.stringify(requestData));\n }\n\n resolve();\n } else {\n if (_this3.ws && _this3.ws.readyState === 1) {\n _this3.ws.addEventListener('message', parseResponse);\n\n timeouId = setTimeout(function () {\n _this3.ws.removeEventListener('message', parseResponse);\n\n reject({\n type: 'error',\n id: 3,\n message: 'send timeout',\n data: requestData\n });\n }, 10000);\n\n _this3.ws.send(JSON.stringify(requestData));\n } else {\n reject({\n type: 'warning',\n id: 29,\n message: 'No connection to WebSockets',\n data: requestData\n });\n }\n }\n });\n }\n }, {\n key: \"_connectionClosed\",\n value: function _connectionClosed() {\n var _this4 = this;\n\n if (this.disconnectingPromise || this.connectingPromise) {\n return;\n }\n\n if (this._retries < this._maxRetries) {\n setTimeout(function () {\n _this4._retries++;\n\n _this4._reconnect().catch(function (e) {\n _this4.emit('error', e);\n });\n }, 3000 * this._retries);\n } else {\n if (this.sessiontype === 'reactooroom') {\n this.disconnect(true);\n } else if (this.sessiontype === 'streaming') {\n this.stopStream();\n }\n\n this.emit('error', {\n type: 'error',\n id: 4,\n message: 'Lost connection to WebSockets',\n data: null\n });\n }\n }\n }, {\n key: \"_wipeListeners\",\n value: function _wipeListeners() {\n if (this.ws) {\n this.ws.removeEventListener('close', this.__connectionClosedBoundFn);\n this.ws.removeEventListener('message', this.__handleWsEventsBoundFn);\n }\n }\n }, {\n key: \"_startKeepAlive\",\n value: function _startKeepAlive() {\n var _this5 = this;\n\n this._send({\n \"janus\": \"keepalive\"\n }).then(function (json) {\n if (json[\"janus\"] !== 'ack') {\n _this5.emit('error', {\n type: 'warning',\n id: 5,\n message: 'keepalive response suspicious',\n data: json[\"janus\"]\n });\n }\n }).catch(function (e) {\n _this5.emit('error', {\n type: 'warning',\n id: 6,\n message: 'keepalive dead',\n data: e\n });\n\n _this5._connectionClosed();\n });\n\n this._keepAliveId = setTimeout(function () {\n _this5._startKeepAlive();\n }, 30000);\n }\n }, {\n key: \"_stopKeepAlive\",\n value: function _stopKeepAlive() {\n clearTimeout(this._keepAliveId);\n }\n }, {\n key: \"_handleWsEvents\",\n value: function _handleWsEvents(event) {\n var _this6 = this;\n\n var json = JSON.parse(event.data);\n var sender = json[\"sender\"];\n var type = json[\"janus\"];\n\n var handle = this._getHandle(sender);\n\n if (!handle) {\n return;\n }\n\n if (type === \"trickle\") {\n var candidate = json[\"candidate\"];\n var config = handle.webrtcStuff;\n\n if (config.pc && config.remoteSdp) {\n if (!candidate || candidate.completed === true) {\n config.pc.addIceCandidate(null);\n } else {\n config.pc.addIceCandidate(candidate);\n }\n } else {\n if (!config.candidates) {\n config.candidates = [];\n }\n\n config.candidates.push(candidate);\n }\n } else if (type === \"webrtcup\") {//none universal\n } else if (type === \"hangup\") {\n this._log('hangup on', handle.handleId);\n\n this._removeParticipant(handle.handleId, null, false);\n } else if (type === \"detached\") {\n this._log('detached on', handle.handleId);\n\n this._removeParticipant(handle.handleId, null, true);\n } else if (type === \"media\") {\n this._log('Media event:', handle.handleId, json[\"type\"], json[\"receiving\"]);\n } else if (type === \"slowlink\") {\n this._log('Slowlink', handle.handleId, json[\"uplink\"], json[\"nacks\"]);\n } else if (type === \"event\") {//none universal\n } else if (type === 'timeout') {\n this.ws.close(3504, \"Gateway timeout\");\n } else if (type === 'success' || type === 'error') {// we're capturing those elsewhere\n } else {\n this._log(\"Unknown event: \".concat(type, \" on session: \").concat(this.sessionId));\n } // LOCAL\n\n\n if (sender === this.handleId) {\n if (type === \"event\") {\n var plugindata = json[\"plugindata\"] || {};\n var msg = plugindata[\"data\"] || {};\n var jsep = json[\"jsep\"];\n var result = msg[\"result\"] || null;\n\n var _event = msg[\"videoroom\"] || null;\n\n var list = msg[\"publishers\"] || {};\n var leaving = msg[\"leaving\"]; //let joining = msg[\"joining\"];\n\n var unpublished = msg[\"unpublished\"];\n var error = msg[\"error\"];\n var allowedObservers = this._observerIds || [];\n var allowedTalkback = this._talkbackIds || [];\n var allowedInstructor = this._instuctorId || null;\n\n if (_event === \"joined\") {\n this.id = msg[\"id\"];\n this.privateId = msg[\"private_id\"];\n this._hasJoined = true;\n this.emit('joined', true);\n\n this._log('We have successfully joined Room');\n\n var _loop = function _loop(f) {\n var userId = list[f][\"display\"];\n var streams = list[f][\"streams\"] || [];\n var id = list[f][\"id\"];\n\n for (var i in streams) {\n streams[i][\"id\"] = id;\n streams[i][\"display\"] = userId;\n }\n\n _this6._log('Remote userId: ', userId);\n\n if (_this6._participantShouldSubscribe(userId)) {\n _this6._log('Creating user: ', userId);\n\n _this6._createParticipant(userId, id).then(function (handle) {\n return _this6.sendMessage(handle.handleId, {\n body: {\n \"request\": \"join\",\n \"room\": _this6.roomId,\n \"ptype\": \"subscriber\",\n \"feed\": id,\n \"private_id\": _this6.privateId,\n pin: _this6.pin\n }\n });\n }).catch(function (err) {\n _this6.emit('error', err);\n });\n }\n };\n\n for (var f in list) {\n _loop(f);\n }\n } else if (_event === \"event\") {\n if (msg[\"streams\"] !== undefined && msg[\"streams\"] !== null) {\n this._log('Got my own streams back', msg[\"streams\"]);\n }\n\n var _loop2 = function _loop2(_f) {\n var userId = list[_f][\"display\"];\n var streams = list[_f][\"streams\"] || [];\n var id = list[_f][\"id\"];\n\n for (var i in streams) {\n streams[i][\"id\"] = id;\n streams[i][\"display\"] = userId;\n }\n\n _this6._log('Remote userId: ', userId);\n\n if (_this6._participantShouldSubscribe(userId)) {\n _this6._log('Creating user: ', userId);\n\n _this6._createParticipant(userId, id).then(function (handle) {\n return _this6.sendMessage(handle.handleId, {\n body: {\n \"request\": \"join\",\n \"room\": _this6.roomId,\n \"ptype\": \"subscriber\",\n \"feed\": id,\n \"private_id\": _this6.privateId,\n pin: _this6.pin\n }\n });\n }).catch(function (err) {\n _this6.emit('error', err);\n });\n }\n };\n\n for (var _f in list) {\n _loop2(_f);\n }\n\n if (leaving === 'ok') {\n this._log('leaving', this.handleId, 'this is us');\n\n this._removeParticipant(this.handleId);\n\n if (msg['reason'] === 'kicked') {\n this.emit('kicked');\n this.disconnect().catch(function () {});\n }\n } else if (leaving) {\n this._log('leaving', leaving);\n\n this._removeParticipant(null, leaving);\n }\n\n if (unpublished === 'ok') {\n this._log('unpublished', this.handleId, 'this is us');\n\n this._removeParticipant(this.handleId, null, false); // we do just hangup\n\n } else if (unpublished) {\n this._log('unpublished', unpublished);\n\n this._removeParticipant(null, unpublished, true); // we do hangup and detach\n\n }\n\n if (error) {\n this.emit('error', {\n type: 'error',\n id: 7,\n message: 'local participant error',\n data: [sender, msg]\n });\n }\n } // Streaming related\n else if (result && result[\"status\"]) {\n this.emit('streamingStatus', result[\"status\"]);\n\n if (result[\"status\"] === 'stopped') {\n this.stopStream();\n }\n\n if (result[\"status\"] === 'started') {\n this.emit('streaming', true);\n this._isStreaming = true;\n }\n }\n\n if (jsep !== undefined && jsep !== null) {\n if (this.sessiontype === 'reactooroom') {\n this._webrtcPeer(this.handleId, jsep).catch(function (err) {\n _this6.emit('error', err);\n });\n } else if (this.sessiontype === 'streaming') {\n this._publishRemote(this.handleId, jsep).catch(function (err) {\n _this6.emit('error', err);\n });\n }\n }\n } else if (type === \"webrtcup\") {\n this._log('Configuring bitrate: ' + this.initialBitrate);\n\n if (this.initialBitrate > 0) {\n this.sendMessage(this.handleId, {\n \"body\": {\n \"request\": \"configure\",\n \"bitrate\": this.initialBitrate\n }\n }).catch(function () {\n return null;\n });\n }\n }\n } //REMOTE\n else {\n var _plugindata = json[\"plugindata\"] || {};\n\n var _msg = _plugindata[\"data\"] || {};\n\n var _jsep2 = json[\"jsep\"];\n var _event2 = _msg[\"videoroom\"];\n var _error = _msg[\"error\"];\n\n if (_event2 === \"attached\") {\n this._log('Remote have successfully joined Room', _msg);\n\n this.emit(this._getAddParticipantEventName(handle.handleId), {\n tid: Object(_wt_utils__WEBPACK_IMPORTED_MODULE_2__[\"generateUUID\"])(),\n id: handle.handleId,\n userId: handle.userId,\n stream: null,\n track: null,\n adding: false,\n constructId: this.constructId,\n metaData: this.options.metaData,\n hasAudioTrack: false,\n hasVideoTrack: false\n });\n }\n\n if (_error) {\n this.emit('error', {\n type: 'warning',\n id: 8,\n message: 'remote participant error',\n data: [sender, _msg]\n });\n }\n\n if (_jsep2) {\n this._publishRemote(handle.handleId, _jsep2).catch(function (err) {\n _this6.emit('error', err);\n });\n }\n }\n }\n }, {\n key: \"_handleDataEvents\",\n value: function _handleDataEvents(handleId, type, data) {\n var handle = this._getHandle(handleId);\n\n if (type === 'state') {\n this._log(\" - Data channel status - \", \"UID: \".concat(handleId), \"STATUS: \".concat(data), \"ME: \".concat(handleId === this.handleId));\n\n if (handle) {\n var config = handle.webrtcStuff;\n config.dataChannelOpen = data === 'open';\n }\n\n if (handleId === this.handleId) {\n this._isDataChannelOpen = data === 'open';\n this.emit('dataChannel', data === 'open');\n }\n }\n\n if (type === 'error') {\n this.emit('error', {\n type: 'warning',\n id: 9,\n message: 'data event warning',\n data: [handleId, data]\n });\n\n if (handle) {\n var _config = handle.webrtcStuff;\n _config.dataChannelOpen = false;\n }\n\n if (handleId === this.handleId) {\n this._isDataChannelOpen = false;\n this.emit('dataChannel', false);\n }\n }\n\n if (handleId === this.handleId && type === 'message') {\n var d = null;\n\n try {\n d = JSON.parse(data);\n } catch (e) {\n this.emit('error', {\n type: 'warning',\n id: 10,\n message: 'data message parse error',\n data: [handleId, e]\n });\n return;\n }\n\n this.emit('data', d);\n }\n } //removeHandle === true -> hangup, detach, removeHandle === false -> hangup\n\n }, {\n key: \"_removeParticipant\",\n value: function _removeParticipant(handleId, rfid) {\n var _this7 = this;\n\n var removeHandle = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;\n\n var handle = this._getHandle(handleId, rfid);\n\n if (!handle) {\n return Promise.resolve();\n } else {\n handleId = handle.handleId;\n }\n\n return this._send({\n \"janus\": \"hangup\",\n \"handle_id\": handleId\n }, true).then(function () {\n return removeHandle ? _this7._send({\n \"janus\": \"detach\",\n \"handle_id\": handleId\n }, true) : Promise.resolve();\n }).finally(function () {\n try {\n if (handle.webrtcStuff.stream && !_this7.isRestarting) {\n handle.webrtcStuff.stream.getTracks().forEach(function (track) {\n return track.stop();\n });\n }\n } catch (e) {// Do nothing\n }\n\n handle.webrtcStuff.stream = null;\n\n if (handle.webrtcStuff.dataChannel) {\n handle.webrtcStuff.dataChannel.onmessage = null;\n handle.webrtcStuff.dataChannel.onopen = null;\n handle.webrtcStuff.dataChannel.onclose = null;\n handle.webrtcStuff.dataChannel.onerror = null;\n }\n\n if (handle.webrtcStuff.pc) {\n handle.webrtcStuff.pc.onicecandidate = null;\n handle.webrtcStuff.pc.ontrack = null;\n handle.webrtcStuff.pc.ondatachannel = null;\n handle.webrtcStuff.pc.onconnectionstatechange = null;\n handle.webrtcStuff.pc.oniceconnectionstatechange = null;\n }\n\n try {\n handle.webrtcStuff.pc.close();\n } catch (e) {}\n\n handle.webrtcStuff = {\n stream: null,\n mySdp: null,\n mediaConstraints: null,\n pc: null,\n dataChannelOpen: false,\n dataChannel: null,\n dtmfSender: null,\n trickle: true,\n iceDone: false\n };\n\n if (handleId === _this7.handleId) {\n _this7._isDataChannelOpen = false;\n _this7._isPublished = false;\n\n _this7.emit('published', {\n status: false,\n hasStream: false\n });\n\n _this7.emit('removeLocalParticipant', {\n id: handleId,\n userId: handle.userId\n });\n } else {\n _this7.emit(_this7._getRemoveParticipantEventName(handleId), {\n id: handleId,\n userId: handle.userId\n });\n }\n\n if (removeHandle) {\n var handleIndex = _this7._participants.findIndex(function (p) {\n return p.handleId === handleId;\n });\n\n _this7._participants.splice(handleIndex, 1);\n }\n\n return true;\n });\n }\n }, {\n key: \"_createParticipant\",\n value: function _createParticipant() {\n var _this8 = this;\n\n var userId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;\n var rfid = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;\n return this._send({\n \"janus\": \"attach\",\n \"plugin\": this.pluginName\n }).then(function (json) {\n var handleId = json.data[\"id\"];\n var handle = {\n handleId: handleId,\n rfid: rfid,\n userId: userId,\n webrtcStuff: {\n stream: null,\n mySdp: null,\n mediaConstraints: null,\n pc: null,\n dataChannelOpen: false,\n dataChannel: null,\n dtmfSender: null,\n trickle: true,\n iceDone: false,\n isIceRestarting: false\n }\n };\n\n _this8._participants.push(handle);\n\n return handle;\n });\n }\n }, {\n key: \"_joinRoom\",\n value: function _joinRoom(roomId, pin, userId) {\n return this.sendMessage(this.handleId, {\n body: {\n \"request\": \"join\",\n \"room\": roomId,\n \"pin\": pin,\n \"ptype\": \"publisher\",\n \"display\": userId\n }\n }, false, true);\n }\n }, {\n key: \"_watchStream\",\n value: function _watchStream(id) {\n return this.sendMessage(this.handleId, {\n body: {\n \"request\": \"watch\",\n id: parseInt(id)\n }\n }, false, true);\n }\n }, {\n key: \"_leaveRoom\",\n value: function _leaveRoom() {\n var _this9 = this;\n\n var dontWait = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;\n return this._hasJoined ? this.sendMessage(this.handleId, {\n body: {\n \"request\": \"leave\"\n }\n }, dontWait).finally(function () {\n _this9._hasJoined = false;\n\n _this9.emit('joined', false);\n }) : Promise.resolve();\n } // internal reconnect\n\n }, {\n key: \"_reconnect\",\n value: function _reconnect() {\n var _this10 = this;\n\n if (this.connectingPromise) {\n return this.connectingPromise;\n }\n\n if (this.ws) {\n this._wipeListeners();\n\n if (this.ws.readyState === 1) {\n this.ws.close();\n }\n }\n\n this._stopKeepAlive();\n\n this.connectingPromise = new Promise(function (resolve, reject) {\n _this10.emit('joining', true);\n\n _this10.ws = new WebSocket(_this10.server, 'janus-protocol');\n _this10.__connectionClosedBoundFn = _this10._connectionClosed.bind(_this10);\n _this10.__handleWsEventsBoundFn = _this10._handleWsEvents.bind(_this10);\n\n _this10.ws.addEventListener('close', _this10.__connectionClosedBoundFn);\n\n _this10.ws.addEventListener('message', _this10.__handleWsEventsBoundFn);\n\n _this10.ws.onopen = function () {\n _this10._send({\n \"janus\": \"claim\"\n }).then(function (json) {\n _this10.sessionId = json[\"session_id\"] ? json[\"session_id\"] : json.data[\"id\"];\n\n _this10._startKeepAlive();\n\n _this10.connectingPromise = null;\n\n _this10.emit('joining', false);\n\n _this10._retries = 0;\n resolve(json);\n }).catch(function (error) {\n _this10.connectingPromise = null;\n\n _this10.emit('joining', false);\n\n reject({\n type: 'error',\n id: 11,\n message: 'reconnection error',\n data: error\n });\n });\n }; // this is called before 'close' event callback so it doesn't break reconnect loop\n\n\n _this10.ws.onerror = function (e) {\n _this10.connectingPromise = null;\n\n _this10.emit('joining', false);\n\n reject({\n type: 'warning',\n id: 12,\n message: 'ws reconnection error',\n data: e\n });\n };\n });\n return this.connectingPromise;\n }\n }, {\n key: \"connect\",\n value: function connect(roomId, pin, server, iceServers, token, userId) {\n var _this11 = this;\n\n var webrtcVersion = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 0;\n var initialBitrate = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : 0;\n var isMonitor = arguments.length > 8 ? arguments[8] : undefined;\n var recordingFilename = arguments.length > 9 ? arguments[9] : undefined;\n\n if (this.connectingPromise) {\n return this.connectingPromise;\n }\n\n this.emit('joined', false);\n\n if (this.ws) {\n this._wipeListeners();\n }\n\n this._stopKeepAlive();\n\n this.disconnectingPromise = null;\n this.sessionId = null;\n this.server = server;\n this.iceServers = iceServers;\n this.token = token;\n this.roomId = roomId;\n this.pin = pin;\n this.userId = userId;\n this.initialBitrate = initialBitrate;\n this.isMonitor = isMonitor;\n this.recordingFilename = recordingFilename;\n this.disconnectingPromise = null;\n this.connectingPromise = new Promise(function (resolve, reject) {\n _this11.emit('joining', true);\n\n _this11.ws = new WebSocket(_this11.server, 'janus-protocol');\n _this11.__connectionClosedBoundFn = _this11._connectionClosed.bind(_this11);\n _this11.__handleWsEventsBoundFn = _this11._handleWsEvents.bind(_this11);\n\n _this11.ws.addEventListener('close', _this11.__connectionClosedBoundFn);\n\n _this11.ws.addEventListener('message', _this11.__handleWsEventsBoundFn);\n\n _this11.ws.onopen = function () {\n _this11._retries = 0;\n\n _this11._send({\n \"janus\": \"create\"\n }).then(function (json) {\n _this11.sessionId = json[\"session_id\"] ? json[\"session_id\"] : json.data[\"id\"];\n\n _this11._startKeepAlive();\n\n return 1;\n }).then(function () {\n return _this11._createParticipant(userId);\n }).then(function (handle) {\n _this11.handleId = handle.handleId;\n return 1;\n }).then(function () {\n return _this11._joinRoom(roomId, pin, userId);\n }).then(function () {\n _this11.connectingPromise = null;\n\n _this11.emit('joining', false);\n\n resolve(_this11);\n }).catch(function (error) {\n _this11.connectingPromise = null;\n\n _this11.emit('joining', false);\n\n reject({\n type: 'error',\n id: 13,\n message: 'connection error',\n data: error\n });\n });\n };\n\n _this11.ws.onerror = function (e) {\n _this11.connectingPromise = null;\n\n _this11.emit('joining', false);\n\n reject({\n type: 'error',\n id: 14,\n message: 'ws connection error',\n data: e\n });\n };\n });\n return this.connectingPromise;\n }\n }, {\n key: \"disconnect\",\n value: function disconnect() {\n var _this12 = this;\n\n if (this.disconnectingPromise) {\n return this.disconnectingPromise;\n }\n\n this._stopKeepAlive();\n\n this.disconnectingPromise = Promise.all(this._participants.map(function (p) {\n return _this12._removeParticipant(p.handleId);\n })).finally(function () {\n _this12._wipeListeners();\n\n if (_this12.ws && _this12.ws.readyState === 1) {\n _this12._send({\n \"janus\": \"destroy\"\n }, true);\n\n _this12.ws.close();\n }\n\n _this12.sessionId = null; //TODO: Just in case something crashed along the way\n\n _this12._isPublished = false;\n _this12._hasJoined = false;\n\n _this12.emit('published', {\n status: false,\n hasStream: false\n });\n\n _this12.emit('joined', false);\n\n _this12.emit('disconnect');\n\n return Promise.resolve('Disconnected');\n });\n return this.disconnectingPromise;\n }\n }, {\n key: \"startStream\",\n value: function startStream(streamId, server, iceServers, token, userId) {\n var _this13 = this;\n\n if (this.connectingPromise) {\n return this.connectingPromise;\n }\n\n this.emit('streaming', false);\n\n if (this.ws) {\n this._wipeListeners();\n }\n\n this._stopKeepAlive();\n\n this.disconnectingPromise = null;\n this.sessionId = null;\n this.server = server;\n this.iceServers = iceServers;\n this.token = token;\n this.streamId = streamId;\n this.userId = userId;\n this.connectingPromise = new Promise(function (resolve, reject) {\n _this13.emit('streamStarting', true);\n\n _this13.ws = new WebSocket(_this13.server, 'janus-protocol');\n _this13.__connectionClosedBoundFn = _this13._connectionClosed.bind(_this13);\n _this13.__handleWsEventsBoundFn = _this13._handleWsEvents.bind(_this13);\n\n _this13.ws.addEventListener('close', _this13.__connectionClosedBoundFn);\n\n _this13.ws.addEventListener('message', _this13.__handleWsEventsBoundFn);\n\n _this13.ws.onopen = function () {\n _this13._retries = 0;\n\n _this13._send({\n \"janus\": \"create\"\n }).then(function (json) {\n _this13.sessionId = json[\"session_id\"] ? json[\"session_id\"] : json.data[\"id\"];\n\n _this13._startKeepAlive();\n\n return 1;\n }).then(function () {\n return _this13._createParticipant(userId);\n }).then(function (handle) {\n _this13.handleId = handle.handleId;\n return 1;\n }).then(function () {\n return _this13._watchStream(streamId);\n }).then(function () {\n _this13.connectingPromise = null;\n\n _this13.emit('streamStarting', false);\n\n resolve(_this13);\n }).catch(function (error) {\n _this13.connectingPromise = null;\n\n _this13.emit('streamStarting', false);\n\n reject({\n type: 'error',\n id: 13,\n message: 'connection error',\n data: error\n });\n });\n };\n\n _this13.ws.onerror = function (e) {\n _this13.connectingPromise = null;\n\n _this13.emit('streamStarting', false);\n\n reject({\n type: 'error',\n id: 14,\n message: 'ws connection error',\n data: e\n });\n };\n });\n return this.connectingPromise;\n }\n }, {\n key: \"stopStream\",\n value: function stopStream() {\n var _this14 = this;\n\n if (this.disconnectingPromise) {\n return this.disconnectingPromise;\n }\n\n this._stopKeepAlive();\n\n this.disconnectingPromise = this.sendMessage(this.handleId, {\n body: {\n \"request\": \"stop\"\n }\n }, false, true).then(function () {\n return _this14._removeParticipant(_this14.handleId);\n }).finally(function () {\n _this14._wipeListeners();\n\n _this14._send({\n \"janus\": \"destroy\"\n }, true);\n\n if (_this14.ws && _this14.ws.readyState === 1) {\n _this14.ws.close();\n }\n\n _this14.sessionId = null;\n _this14._isStreaming = false;\n\n _this14.emit('streaming', false); // last event\n\n\n _this14.emit('disconnect');\n\n _this14.disconnectingPromise = null;\n return Promise.resolve('Disconnected');\n });\n return this.disconnectingPromise;\n }\n }, {\n key: \"destroy\",\n value: function destroy() {\n var _this15 = this;\n\n if (this.sessiontype === 'reactooroom') {\n return this.disconnect().then(function () {\n _this15.clear();\n\n return true;\n });\n } else if (this.sessiontype === 'streaming') {\n return this.stopStream().then(function () {\n _this15.clear();\n\n return true;\n });\n }\n }\n }, {\n key: \"_enableDebug\",\n value: function _enableDebug() {\n this._log = console.log.bind(console);\n }\n }, {\n key: \"_getHandle\",\n value: function _getHandle(handleId) {\n var rfid = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;\n return this._participants.find(function (p) {\n return p.handleId === handleId || rfid && p.rfid === rfid;\n });\n }\n }, {\n key: \"_getStats\",\n value: function _getStats() {\n var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;\n return Promise.all(this._participants.map(function (participant) {\n var mediaTrack = null;\n\n if (type === 'video') {\n mediaTrack = participant.webrtcStuff && participant.webrtcStuff.stream && participant.webrtcStuff.stream.getVideoTracks().length && participant.webrtcStuff.stream.getVideoTracks()[0];\n } else if (type === 'audio') {\n mediaTrack = participant.webrtcStuff && participant.webrtcStuff.stream && participant.webrtcStuff.stream.getAudioTracks().length && participant.webrtcStuff.stream.getAudioTracks()[0];\n }\n\n return participant.webrtcStuff && participant.webrtcStuff.pc && participant.webrtcStuff.pc.getStats(mediaTrack).then(function (r) {\n return {\n handle: participant,\n stats: r\n };\n }).catch(function (e) {\n return Promise.resolve({\n handle: participant,\n stats: e\n });\n });\n }));\n }\n }, {\n key: \"_sendTrickleCandidate\",\n value: function _sendTrickleCandidate(handleId, candidate) {\n return this._send({\n \"janus\": \"trickle\",\n \"candidate\": candidate,\n \"handle_id\": handleId\n });\n }\n }, {\n key: \"_webrtc\",\n value: function _webrtc(handleId) {\n var _this16 = this;\n\n var enableOntrack = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;\n\n var handle = this._getHandle(handleId);\n\n if (!handle) {\n this.emit('error', {\n type: 'warning',\n id: 15,\n message: 'id non-existent',\n data: [handleId, 'create rtc connection']\n });\n }\n\n var config = handle.webrtcStuff;\n\n if (!config.pc) {\n var pc_config = {\n \"iceServers\": this.iceServers,\n \"iceTransportPolicy\": 'all',\n \"bundlePolicy\": undefined\n };\n pc_config[\"sdpSemantics\"] = this.isUnifiedPlan ? \"unified-plan\" : \"plan-b\";\n var pc_constraints = {\n \"optional\": [{\n \"DtlsSrtpKeyAgreement\": true\n }]\n };\n\n if (this._ipv6Support === true) {\n pc_constraints.optional.push({\n \"googIPv6\": true\n });\n }\n\n if (webrtc_adapter__WEBPACK_IMPORTED_MODULE_0__[\"default\"].browserDetails.browser === \"edge\") {\n // This is Edge, enable BUNDLE explicitly\n pc_config.bundlePolicy = \"max-bundle\";\n }\n\n this._log('new RTCPeerConnection', pc_config, pc_constraints);\n\n config.pc = new RTCPeerConnection(pc_config, pc_constraints);\n\n config.pc.onconnectionstatechange = function () {\n if (config.pc.connectionState === 'failed') {\n _this16._iceRestart(handleId);\n }\n\n _this16.emit('connectionState', [handleId, handleId === _this16.handleId, config.pc.connectionState]);\n\n if (handleId !== _this16.handleId && config.pc.connectionState === 'connected') {\n _this16.emit(_this16._getAddParticipantEventName(handle.handleId), {\n tid: Object(_wt_utils__WEBPACK_IMPORTED_MODULE_2__[\"generateUUID\"])(),\n id: handle.handleId,\n userId: handle.userId,\n stream: config.stream,\n optional: true,\n constructId: _this16.constructId,\n metaData: _this16.options.metaData,\n adding: true,\n hasAudioTrack: !!(config.stream && config.stream.getAudioTracks().length),\n hasVideoTrack: !!(config.stream && config.stream.getVideoTracks().length)\n });\n }\n };\n\n config.pc.oniceconnectionstatechange = function () {\n if (config.pc.iceConnectionState === 'failed') {\n _this16._iceRestart(handleId);\n }\n\n _this16.emit('iceState', [handleId, handleId === _this16.handleId, config.pc.iceConnectionState]);\n\n if (handleId !== _this16.handleId && (config.pc.iceConnectionState === 'completed' || config.pc.iceConnectionState === 'connected')) {\n _this16.emit(_this16._getAddParticipantEventName(handle.handleId), {\n tid: Object(_wt_utils__WEBPACK_IMPORTED_MODULE_2__[\"generateUUID\"])(),\n id: handle.handleId,\n userId: handle.userId,\n stream: config.stream,\n optional: true,\n constructId: _this16.constructId,\n metaData: _this16.options.metaData,\n adding: true,\n hasAudioTrack: !!(config.stream && config.stream.getAudioTracks().length),\n hasVideoTrack: !!(config.stream && config.stream.getVideoTracks().length)\n });\n }\n };\n\n config.pc.onicecandidate = function (event) {\n if (event.candidate == null || webrtc_adapter__WEBPACK_IMPORTED_MODULE_0__[\"default\"].browserDetails.browser === 'edge' && event.candidate.candidate.indexOf('endOfCandidates') > 0) {\n config.iceDone = true;\n\n _this16._sendTrickleCandidate(handleId, {\n \"completed\": true\n }).catch(function (e) {\n _this16.emit('error', e);\n });\n } else {\n // JSON.stringify doesn't work on some WebRTC objects anymore\n // See https://code.google.com/p/chromium/issues/detail?id=467366\n var candidate = {\n \"candidate\": event.candidate.candidate,\n \"sdpMid\": event.candidate.sdpMid,\n \"sdpMLineIndex\": event.candidate.sdpMLineIndex\n };\n\n _this16._sendTrickleCandidate(handleId, candidate).catch(function (e) {\n _this16.emit('error', e);\n });\n }\n };\n\n if (enableOntrack) {\n config.pc.ontrack = function (event) {\n // if(!event.streams)\n // return;\n //config.stream = event.streams[0];\n if (!config.stream) {\n config.stream = new MediaStream();\n }\n\n if (event.track) {\n config.stream.addTrack(event.track);\n\n _this16.emit(_this16._getAddParticipantEventName(handle.handleId), {\n tid: Object(_wt_utils__WEBPACK_IMPORTED_MODULE_2__[\"generateUUID\"])(),\n id: handle.handleId,\n userId: handle.userId,\n stream: config.stream,\n track: event.track,\n constructId: _this16.constructId,\n metaData: _this16.options.metaData,\n adding: true,\n hasAudioTrack: !!(config.stream && config.stream.getAudioTracks().length),\n hasVideoTrack: !!(config.stream && config.stream.getVideoTracks().length)\n });\n\n if (event.track.onended) return;\n\n event.track.onended = function (ev) {\n if (config.stream) {\n config.stream && config.stream.removeTrack(ev.target);\n\n _this16.emit(_this16._getAddParticipantEventName(handle.handleId), {\n tid: Object(_wt_utils__WEBPACK_IMPORTED_MODULE_2__[\"generateUUID\"])(),\n id: handle.handleId,\n userId: handle.userId,\n stream: config.stream,\n track: ev.target,\n constructId: _this16.constructId,\n metaData: _this16.options.metaData,\n adding: false,\n hasAudioTrack: !!(config.stream && config.stream.getAudioTracks().length),\n hasVideoTrack: !!(config.stream && config.stream.getVideoTracks().length)\n });\n }\n };\n\n event.track.onmute = function (ev) {\n _this16._log('remoteTrackMuted', 'onmute');\n\n _this16.emit('remoteTrackMuted', {\n id: handle.handleId,\n userId: handle.userId,\n stream: config.stream,\n kind: ev.target.kind,\n track: ev.target,\n muted: true\n });\n };\n\n event.track.onunmute = function (ev) {\n _this16._log('remoteTrackMuted', 'onunmute');\n\n _this16.emit('remoteTrackMuted', {\n id: handle.handleId,\n userId: handle.userId,\n stream: config.stream,\n kind: ev.target.kind,\n track: ev.target,\n muted: false\n });\n };\n }\n };\n }\n }\n\n var defaultDataChannelLabel = 'JanusDataChannel';\n\n if (!config.dataChannel || !config.dataChannelOpen) {\n var onDataChannelMessage = function onDataChannelMessage(event) {\n _this16._handleDataEvents(handleId, 'message', event.data);\n };\n\n var onDataChannelStateChange = function onDataChannelStateChange(event) {\n _this16._handleDataEvents(handleId, 'state', config.dataChannel.readyState);\n };\n\n var onDataChannelError = function onDataChannelError(error) {\n _this16._handleDataEvents(handleId, 'error', error);\n }; // Until we implement the proxying of open requests within the Janus core, we open a channel ourselves whatever the case\n\n\n config.dataChannel = config.pc.createDataChannel(defaultDataChannelLabel, {\n ordered: true\n });\n config.dataChannel.onmessage = onDataChannelMessage;\n config.dataChannel.onopen = onDataChannelStateChange;\n config.dataChannel.onclose = onDataChannelStateChange;\n config.dataChannel.onerror = onDataChannelError;\n\n config.pc.ondatachannel = function (event) {\n //TODO: implement this\n console.log('Janus is creating data channel');\n };\n }\n }\n }, {\n key: \"_webrtcPeer\",\n value: function _webrtcPeer(handleId, jsep) {\n var handle = this._getHandle(handleId);\n\n if (!handle) {\n return Promise.reject({\n type: 'warning',\n id: 15,\n message: 'id non-existent',\n data: [handleId, 'rtc peer']\n });\n }\n\n var config = handle.webrtcStuff;\n\n if (jsep !== undefined && jsep !== null) {\n if (config.pc === null) {\n this._log(\"No PeerConnection: if this is an answer, use createAnswer and not _webrtcPeer\");\n\n return Promise.resolve(null);\n }\n\n return config.pc.setRemoteDescription(jsep).then(function () {\n config.remoteSdp = jsep.sdp; // Any trickle candidate we cached?\n\n if (config.candidates && config.candidates.length > 0) {\n for (var i = 0; i < config.candidates.length; i++) {\n var candidate = config.candidates[i];\n\n if (!candidate || candidate.completed === true) {\n config.pc.addIceCandidate(null);\n } else {\n config.pc.addIceCandidate(candidate);\n }\n }\n\n config.candidates = [];\n } // Done\n\n\n return true;\n });\n } else {\n return Promise.reject({\n type: 'warning',\n id: 22,\n message: 'rtc peer',\n data: [handleId, 'invalid jsep']\n });\n }\n }\n }, {\n key: \"_iceRestart\",\n value: function _iceRestart(handleId) {\n var _this17 = this;\n\n var handle = this._getHandle(handleId);\n\n if (!handle) {\n return;\n }\n\n var config = handle.webrtcStuff; // Already restarting;\n\n if (config.isIceRestarting) {\n return;\n }\n\n if (this.handleId === handleId) {\n this._log('Performing local ICE restart');\n\n config.isIceRestarting = true;\n var hasAudio = !!(config.stream && config.stream.getAudioTracks().length > 0);\n var hasVideo = !!(config.stream && config.stream.getVideoTracks().length > 0);\n\n this._createAO('offer', handleId, true, [hasAudio, false, hasVideo, false]).then(function (jsep) {\n if (!jsep) {\n return null;\n }\n\n return _this17.sendMessage(handleId, {\n body: _objectSpread({\n \"request\": \"configure\",\n \"audio\": hasAudio,\n \"video\": hasVideo,\n \"data\": true\n }, _this17.recordingFilename ? {\n filename: _this17.recordingFilename\n } : {}),\n jsep: jsep\n });\n }).then(function (r) {\n config.isIceRestarting = false;\n\n _this17._log('ICE restart success');\n }).catch(function (e) {\n config.isIceRestarting = false;\n\n _this17.emit('warning', {\n type: 'error',\n id: 28,\n message: 'iceRestart failed',\n data: e\n });\n });\n } else {\n this._log('Performing remote ICE restart', handleId);\n\n config.isIceRestarting = true;\n return this.sendMessage(handleId, {\n body: {\n \"request\": \"configure\",\n \"restart\": true\n }\n }).then(function () {\n config.isIceRestarting = false;\n }).catch(function () {\n config.isIceRestarting = false;\n });\n }\n }\n }, {\n key: \"_createAO\",\n value: function _createAO() {\n var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'offer';\n var handleId = arguments.length > 1 ? arguments[1] : undefined;\n var iceRestart = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;\n\n var _ref = arguments.length > 3 ? arguments[3] : undefined,\n _ref2 = _slicedToArray(_ref, 4),\n audioSend = _ref2[0],\n audioRecv = _ref2[1],\n videoSend = _ref2[2],\n videoRecv = _ref2[3];\n\n var handle = this._getHandle(handleId);\n\n if (!handle) {\n return Promise.reject({\n type: 'warning',\n id: 15,\n message: 'id non-existent',\n data: [handleId, 'createAO', type]\n });\n }\n\n var methodName = null;\n\n if (type === 'offer') {\n methodName = 'createOffer';\n } else {\n methodName = 'createAnswer';\n }\n\n var config = handle.webrtcStuff; // https://code.google.com/p/webrtc/issues/detail?id=3508\n\n var mediaConstraints = {};\n\n if (this.isUnifiedPlan) {\n var audioTransceiver = null,\n videoTransceiver = null;\n var transceivers = config.pc.getTransceivers();\n\n if (transceivers && transceivers.length > 0) {\n for (var i in transceivers) {\n var t = transceivers[i];\n\n if (t.sender && t.sender.track && t.sender.track.kind === \"audio\" && t.stopped === false || t.receiver && t.receiver.track && t.receiver.track.kind === \"audio\" && t.stopped === false) {\n if (!audioTransceiver) audioTransceiver = t;\n continue;\n }\n\n if (t.sender && t.sender.track && t.sender.track.kind === \"video\" && t.stopped === false || t.receiver && t.receiver.track && t.receiver.track.kind === \"video\" && t.stopped === false) {\n if (!videoTransceiver) videoTransceiver = t;\n continue;\n }\n }\n } // Handle audio (and related changes, if any)\n\n\n if (!audioSend && !audioRecv) {\n // Audio disabled: have we removed it?\n if (audioTransceiver) {\n if (audioTransceiver.setDirection) {\n audioTransceiver.setDirection(\"inactive\");\n } else {\n audioTransceiver.direction = \"inactive\";\n }\n }\n } else {\n // Take care of audio m-line\n if (audioSend && audioRecv) {\n if (audioTransceiver) {\n if (audioTransceiver.setDirection) {\n audioTransceiver.setDirection(\"sendrecv\");\n } else {\n audioTransceiver.direction = \"sendrecv\";\n }\n }\n } else if (audioSend && !audioRecv) {\n if (audioTransceiver) {\n if (audioTransceiver.setDirection) {\n audioTransceiver.setDirection(\"sendonly\");\n } else {\n audioTransceiver.direction = \"sendonly\";\n }\n }\n } else if (!audioSend && audioRecv) {\n if (audioTransceiver) {\n if (audioTransceiver.setDirection) {\n audioTransceiver.setDirection(\"recvonly\");\n } else {\n audioTransceiver.direction = \"recvonly\";\n }\n } else {\n // In theory, this is the only case where we might not have a transceiver yet\n audioTransceiver = config.pc.addTransceiver(\"audio\", {\n direction: \"recvonly\"\n });\n }\n }\n } // Handle video (and related changes, if any)\n\n\n if (!videoSend && !videoRecv) {\n if (videoTransceiver) {\n if (videoTransceiver.setDirection) {\n videoTransceiver.setDirection(\"inactive\");\n } else {\n videoTransceiver.direction = \"inactive\";\n }\n }\n } else {\n // Take care of video m-line\n if (videoSend && videoRecv) {\n if (videoTransceiver) {\n if (videoTransceiver.setDirection) {\n videoTransceiver.setDirection(\"sendrecv\");\n } else {\n videoTransceiver.direction = \"sendrecv\";\n }\n }\n } else if (videoSend && !videoRecv) {\n if (videoTransceiver) {\n if (videoTransceiver.setDirection) {\n videoTransceiver.setDirection(\"sendonly\");\n } else {\n videoTransceiver.direction = \"sendonly\";\n }\n }\n } else if (!videoSend && videoRecv) {\n if (videoTransceiver) {\n if (videoTransceiver.setDirection) {\n videoTransceiver.setDirection(\"recvonly\");\n } else {\n videoTransceiver.direction = \"recvonly\";\n }\n } else {\n // In theory, this is the only case where we might not have a transceiver yet\n videoTransceiver = config.pc.addTransceiver(\"video\", {\n direction: \"recvonly\"\n });\n }\n }\n }\n } else {\n if (webrtc_adapter__WEBPACK_IMPORTED_MODULE_0__[\"default\"].browserDetails.browser === \"firefox\" || webrtc_adapter__WEBPACK_IMPORTED_MODULE_0__[\"default\"].browserDetails.browser === \"edge\") {\n mediaConstraints = {\n offerToReceiveAudio: audioRecv,\n offerToReceiveVideo: videoRecv\n };\n } else {\n mediaConstraints = {\n mandatory: {\n OfferToReceiveAudio: audioRecv,\n OfferToReceiveVideo: videoRecv\n }\n };\n }\n }\n\n if (iceRestart) {\n mediaConstraints[\"iceRestart\"] = true;\n }\n\n return config.pc[methodName](mediaConstraints).then(function (response) {\n config.mySdp = response.sdp;\n\n var _p = config.pc.setLocalDescription(response).catch(function (e) {\n return Promise.reject({\n type: 'warning',\n id: 24,\n message: 'setLocalDescription',\n data: [handleId, e]\n });\n });\n\n config.mediaConstraints = mediaConstraints;\n\n if (!config.iceDone && !config.trickle) {\n // Don't do anything until we have all candidates\n return Promise.resolve(null);\n } // JSON.stringify doesn't work on some WebRTC objects anymore\n // See https://code.google.com/p/chromium/issues/detail?id=467366\n\n\n var jsep = {\n \"type\": response.type,\n \"sdp\": response.sdp\n };\n return _p.then(function () {\n return jsep;\n });\n }, function (e) {\n return Promise.reject({\n type: 'warning',\n id: 25,\n message: methodName,\n data: [handleId, e]\n });\n });\n }\n }, {\n key: \"_publishRemote\",\n value: function _publishRemote(handleId, jsep) {\n var _this18 = this;\n\n var handle = this._getHandle(handleId);\n\n if (!handle) {\n return Promise.reject({\n type: 'warning',\n id: 15,\n message: 'id non-existent',\n data: [handleId, 'publish remote participant']\n });\n }\n\n this._webrtc(handleId, true);\n\n var config = handle.webrtcStuff;\n\n if (jsep) {\n return config.pc.setRemoteDescription(jsep).then(function () {\n config.remoteSdp = jsep.sdp; // Any trickle candidate we cached?\n\n if (config.candidates && config.candidates.length > 0) {\n for (var i = 0; i < config.candidates.length; i++) {\n var candidate = config.candidates[i];\n\n if (!candidate || candidate.completed === true) {\n // end-of-candidates\n config.pc.addIceCandidate(null);\n } else {\n // New candidate\n config.pc.addIceCandidate(candidate);\n }\n }\n\n config.candidates = [];\n } // Create the answer now\n\n\n return _this18._createAO('answer', handleId, false, [false, true, false, true]).then(function (_jsep) {\n if (!_jsep) {\n _this18.emit('error', {\n type: 'warning',\n id: 19,\n message: 'publish remote participant',\n data: [handleId, 'no jsep']\n });\n\n return Promise.resolve();\n }\n\n return _this18.sendMessage(handleId, {\n \"body\": _objectSpread(_objectSpread({\n \"request\": \"start\"\n }, _this18.roomId && {\n \"room\": _this18.roomId\n }), _this18.pin && {\n pin: _this18.pin\n }),\n \"jsep\": _jsep\n });\n });\n }, function (e) {\n return Promise.reject({\n type: 'warning',\n id: 23,\n message: 'setRemoteDescription',\n data: [handleId, e]\n });\n });\n } else {\n return Promise.resolve();\n }\n } //Public methods\n\n }, {\n key: \"publishLocal\",\n value: function publishLocal(stream) {\n var _this19 = this;\n\n var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},\n _ref3$keepAudio = _ref3.keepAudio,\n keepAudio = _ref3$keepAudio === void 0 ? false : _ref3$keepAudio,\n _ref3$keepVideo = _ref3.keepVideo,\n keepVideo = _ref3$keepVideo === void 0 ? false : _ref3$keepVideo;\n\n this.emit('publishing', true);\n\n var handle = this._getHandle(this.handleId);\n\n if (!handle) {\n return Promise.reject({\n type: 'error',\n id: 21,\n message: 'no local id, connect before publishing',\n data: null\n });\n }\n\n this._webrtc(this.handleId);\n\n var config = handle.webrtcStuff;\n\n if (stream) {\n if (!config.stream) {\n config.stream = stream;\n stream.getTracks().forEach(function (track) {\n config.pc.addTrack(track, stream);\n });\n } else {\n /* UPDATE Audio */\n var replaceAudio = stream.getAudioTracks().length;\n\n if (replaceAudio || !keepAudio) {\n //this will stop existing tracks\n var oldAudioStream = config.stream.getAudioTracks()[0];\n\n if (oldAudioStream) {\n config.stream.removeTrack(oldAudioStream);\n\n try {\n oldAudioStream.stop();\n } catch (e) {\n this._log(e);\n }\n }\n }\n\n if (config.pc.getSenders() && config.pc.getSenders().length) {\n if (replaceAudio && this.isUnifiedPlan) {//using replace\n } else {\n for (var index in config.pc.getSenders()) {\n var s = config.pc.getSenders()[index];\n\n if (s && s.track && s.track.kind === \"audio\") {\n config.pc.removeTrack(s);\n }\n }\n }\n }\n\n if (replaceAudio) {\n config.stream.addTrack(stream.getAudioTracks()[0]);\n var audioTransceiver = null;\n\n if (this.isUnifiedPlan) {\n var transceivers = config.pc.getTransceivers();\n\n if (transceivers && transceivers.length > 0) {\n for (var i in transceivers) {\n var t = transceivers[i];\n\n if (t.sender && t.sender.track && t.sender.track.kind === \"audio\" && t.stopped === false || t.receiver && t.receiver.track && t.receiver.track.kind === \"audio\" && t.stopped === false) {\n audioTransceiver = t;\n break;\n }\n }\n }\n }\n\n if (audioTransceiver && audioTransceiver.sender) {\n audioTransceiver.sender.replaceTrack(stream.getAudioTracks()[0]);\n } else {\n config.pc.addTrack(stream.getAudioTracks()[0], stream);\n }\n }\n /* UPDATE Video */\n\n\n var replaceVideo = stream.getVideoTracks().length;\n\n if (replaceVideo || !keepVideo) {\n var oldVideoStream = config.stream.getVideoTracks()[0];\n\n if (oldVideoStream) {\n config.stream.removeTrack(oldVideoStream);\n\n try {\n oldVideoStream.stop();\n } catch (e) {\n this._log(e);\n }\n }\n }\n\n if (config.pc.getSenders() && config.pc.getSenders().length) {\n if (replaceVideo && this.isUnifiedPlan) {//using replace\n } else {\n for (var _index in config.pc.getSenders()) {\n var _s2 = config.pc.getSenders()[_index];\n\n if (_s2 && _s2.track && _s2.track.kind === \"video\") {\n config.pc.removeTrack(_s2);\n }\n }\n }\n }\n\n if (replaceVideo) {\n config.stream.addTrack(stream.getVideoTracks()[0]);\n var videoTransceiver = null;\n\n if (this.isUnifiedPlan) {\n var _transceivers = config.pc.getTransceivers();\n\n if (_transceivers && _transceivers.length > 0) {\n for (var _i2 in _transceivers) {\n var _t = _transceivers[_i2];\n\n if (_t.sender && _t.sender.track && _t.sender.track.kind === \"video\" && _t.stopped === false || _t.receiver && _t.receiver.track && _t.receiver.track.kind === \"video\" && _t.stopped === false) {\n videoTransceiver = _t;\n break;\n }\n }\n }\n }\n\n if (videoTransceiver && videoTransceiver.sender) {\n //TODO: check if t.stopped === false still gets us videoTransceiver\n videoTransceiver.sender.replaceTrack(stream.getVideoTracks()[0]);\n } else {\n config.pc.addTrack(stream.getVideoTracks()[0], stream);\n }\n }\n }\n }\n\n var hasAudio = !!(stream && stream.getAudioTracks().length > 0);\n var hasVideo = !!(stream && stream.getVideoTracks().length > 0);\n var isAudioMuted = !stream || stream.getAudioTracks().length === 0 || !stream.getAudioTracks()[0].enabled;\n var isVideoMuted = !stream || stream.getVideoTracks().length === 0 || !stream.getVideoTracks()[0].enabled;\n this.isAudioEnabed = hasAudio;\n this.isVideoEnabled = hasVideo;\n this.isAudioMuted = isAudioMuted;\n this.isVideoMuted = isVideoMuted;\n return this._createAO('offer', this.handleId, false, [hasAudio, false, hasVideo, false]).then(function (jsep) {\n if (!jsep) {\n return null;\n } //HOTFIX: Temporary fix for Safari 13\n\n\n if (jsep.sdp && jsep.sdp.indexOf(\"\\r\\na=ice-ufrag\") === -1) {\n jsep.sdp = jsep.sdp.replace(\"\\na=ice-ufrag\", \"\\r\\na=ice-ufrag\");\n }\n\n return _this19.sendMessage(_this19.handleId, {\n body: _objectSpread({\n \"request\": \"configure\",\n \"audio\": hasAudio,\n \"video\": hasVideo,\n \"data\": true\n }, _this19.recordingFilename ? {\n filename: _this19.recordingFilename\n } : {}),\n jsep: jsep\n });\n }).then(function (r) {\n if (_this19._isDataChannelOpen) {\n return Promise.resolve(r);\n } else {\n return new Promise(function (resolve, reject) {\n var __ = function __(val) {\n if (val) {\n clearTimeout(___);\n\n _this19.off('dataChannel', __, _this19);\n\n resolve(_this19);\n }\n };\n\n var ___ = setTimeout(function () {\n _this19.off('dataChannel', __, _this19);\n\n reject({\n type: 'error',\n id: 27,\n message: 'Data channel did not open',\n data: null\n });\n }, 5000);\n\n _this19.on('dataChannel', __, _this19);\n });\n }\n }).then(function (r) {\n _this19._isPublished = true;\n\n _this19.emit('addLocalParticipant', {\n tid: Object(_wt_utils__WEBPACK_IMPORTED_MODULE_2__[\"generateUUID\"])(),\n id: handle.handleId,\n userId: handle.userId,\n stream: config.stream\n });\n\n _this19.emit('published', {\n status: true,\n hasStream: !!config.stream\n });\n\n _this19.emit('publishing', false);\n\n _this19.emit('localHasVideo', hasVideo);\n\n _this19.emit('localHasAudio', hasAudio);\n\n _this19.emit('localMuted', {\n type: 'video',\n value: isVideoMuted\n });\n\n _this19.emit('localMuted', {\n type: 'audio',\n value: isAudioMuted\n });\n\n return r;\n }).catch(function (e) {\n _this19.emit('publishing', false);\n\n return Promise.reject(e);\n });\n }\n }, {\n key: \"unpublishLocal\",\n value: function unpublishLocal() {\n var _this20 = this;\n\n var dontWait = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;\n return this._isPublished ? this.sendMessage(this.handleId, {\n body: {\n \"request\": \"unpublish\"\n }\n }, dontWait).finally(function (r) {\n _this20._isPublished = false;\n\n _this20.emit('published', {\n status: false,\n hasStream: false\n });\n\n return r;\n }) : Promise.resolve();\n }\n }, {\n key: \"toggleAudio\",\n value: function toggleAudio() {\n var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;\n\n var handle = this._getHandle(this.handleId);\n\n if (!handle) {\n return Promise.reject({\n type: 'error',\n id: 21,\n message: 'no local id, connect first',\n data: null\n });\n }\n\n var config = handle.webrtcStuff;\n\n if (this.isUnifiedPlan) {\n var transceiver = config.pc.getTransceivers().find(function (t) {\n return t.sender && t.sender.track && t.receiver.track.kind === \"audio\" && t.stopped === false;\n });\n\n if (transceiver) {\n transceiver.sender.track.enabled = value !== null ? !!value : !transceiver.sender.track.enabled;\n }\n\n this.isAudioMuted = !transceiver || !transceiver.sender.track.enabled;\n } else {\n if (config.stream && config.stream.getAudioTracks().length) {\n config.stream.getAudioTracks()[0].enabled = value !== null ? !!value : !config.stream.getAudioTracks()[0].enabled;\n }\n\n this.isAudioMuted = config.stream.getAudioTracks().length === 0 || !config.stream.getAudioTracks()[0].enabled;\n }\n\n this.emit('localMuted', {\n type: 'audio',\n value: this.isAudioMuted\n });\n }\n }, {\n key: \"toggleVideo\",\n value: function toggleVideo() {\n var handle = this._getHandle(this.handleId);\n\n if (!handle) {\n return Promise.reject({\n type: 'error',\n id: 21,\n message: 'no local id, connect first',\n data: null\n });\n }\n\n var config = handle.webrtcStuff;\n\n if (this.isUnifiedPlan) {\n var transceiver = config.pc.getTransceivers().find(function (t) {\n return t.sender && t.sender.track && t.receiver.track.kind === \"video\" && t.stopped === false;\n });\n\n if (transceiver) {\n transceiver.sender.track.enabled = !transceiver.sender.track.enabled;\n }\n\n this.isVideoMuted = !transceiver || !transceiver.sender.track.enabled;\n } else {\n if (config.stream && config.stream.getVideoTracks().length) {\n config.stream.getVideoTracks()[0].enabled = !config.stream.getVideoTracks()[0].enabled;\n }\n\n this.isVideoMuted = config.stream.getVideoTracks().length === 0 || !config.stream.getVideoTracks()[0].enabled;\n }\n\n this.emit('localMuted', {\n type: 'video',\n value: this.isVideoMuted\n });\n }\n }, {\n key: \"setInstructorId\",\n value: function setInstructorId() {\n var instructorId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;\n this._instuctorId = instructorId;\n this.emit('instructorId', this._instuctorId);\n return this._instuctorId;\n }\n }, {\n key: \"setObserverIds\",\n value: function setObserverIds() {\n var observerIds = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];\n this._observerIds = observerIds;\n this.emit('observerIds', this._observerIds);\n return this._observerIds;\n }\n }, {\n key: \"setTalkbackIds\",\n value: function setTalkbackIds() {\n var talkbackIds = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];\n this._talkbackIds = talkbackIds;\n this.emit('talkbackIds', this._talkbackIds);\n return this._talkbackIds;\n }\n }], [{\n key: \"noop\",\n value: function noop() {}\n }, {\n key: \"randomString\",\n value: function randomString(len) {\n var charSet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';\n var randomString = '';\n\n for (var i = 0; i < len; i++) {\n var randomPoz = Math.floor(Math.random() * charSet.length);\n randomString += charSet.substring(randomPoz, randomPoz + 1);\n }\n\n return randomString;\n } //TODO: solve\n // #eventList = ['error', 'kicked', 'addLocalParticipant', ,'addRemoteInstructor','addRemoteParticipant','addRemoteTalkback', 'addRemoteObserver', 'removeRemoteInstructor', 'removeLocalParticipant', 'removeRemoteParticipant', 'removeRemoteTalkback', 'removeRemoteObserver', 'localMuted', 'localHasVideo', 'localHasAudio', 'data', 'iceState', 'connectionState', 'joined', 'joining', 'dataChannel', 'disconnect', 'observerIds', 'talkbackIds', 'instructorId', 'published', 'publishing', 'remoteTrackMuted', 'streamingStatus', 'streaming', 'streamStarting'];\n //\n\n }, {\n key: \"checkUnifiedPlan\",\n value: function checkUnifiedPlan() {\n var unifiedPlan = false;\n\n if (webrtc_adapter__WEBPACK_IMPORTED_MODULE_0__[\"default\"].browserDetails.browser === 'firefox' && webrtc_adapter__WEBPACK_IMPORTED_MODULE_0__[\"default\"].browserDetails.version >= 59) {\n // Firefox definitely does, starting from version 59\n unifiedPlan = true;\n } else if (webrtc_adapter__WEBPACK_IMPORTED_MODULE_0__[\"default\"].browserDetails.browser === 'chrome' && webrtc_adapter__WEBPACK_IMPORTED_MODULE_0__[\"default\"].browserDetails.version >= 72) {\n // Chrome does, but it's only usable from version 72 on\n unifiedPlan = true;\n } else if (!window.RTCRtpTransceiver || !('currentDirection' in RTCRtpTransceiver.prototype)) {\n // Safari supports addTransceiver() but not Unified Plan when\n // currentDirection is not defined (see codepen above).\n unifiedPlan = false;\n } else {\n // Check if addTransceiver() throws an exception\n var tempPc = new RTCPeerConnection();\n\n try {\n tempPc.addTransceiver('audio');\n unifiedPlan = true;\n } catch (e) {}\n\n tempPc.close();\n }\n\n return unifiedPlan;\n }\n }]);\n\n return RoomSession;\n}();\n\n_defineProperty(RoomSession, \"sessionTypes\", {\n 'reactooroom': 'janus.plugin.reactooroom',\n 'streaming': 'janus.plugin.streaming'\n});\n\n_defineProperty(RoomSession, \"subscriptionRules\", {\n participant: {\n watchTogether: ['participant', 'talkback'],\n videoWall: ['instructor', 'observer', 'talkback']\n },\n monitor: {\n watchTogether: ['participant'],\n videoWall: ['instructor', 'participant']\n },\n talkback: {\n watchTogether: ['participant'],\n videoWall: ['instructor', 'participant']\n },\n observer: {\n watchTogether: ['participant'],\n videoWall: ['participant']\n },\n instructor: {\n watchTogether: [],\n videoWall: []\n }\n});\n\n/* harmony default export */ __webpack_exports__[\"default\"] = (Room);\n\n//# sourceURL=webpack://WatchTogetherSDK/./src/modules/wt-room.js?");
8573
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var webrtc_adapter__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! webrtc-adapter */ \"./node_modules/webrtc-adapter/src/js/adapter_core.js\");\n/* harmony import */ var _wt_emitter__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./wt-emitter */ \"./src/modules/wt-emitter.js\");\n/* harmony import */ var _wt_utils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./wt-utils */ \"./src/modules/wt-utils.js\");\nfunction _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }\n\nfunction _nonIterableRest() { throw new TypeError(\"Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\"); }\n\nfunction _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === \"string\") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === \"Object\" && o.constructor) n = o.constructor.name; if (n === \"Map\" || n === \"Set\") return Array.from(o); if (n === \"Arguments\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }\n\nfunction _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }\n\nfunction _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== \"undefined\" && arr[Symbol.iterator] || arr[\"@@iterator\"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"] != null) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; }\n\nfunction _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }\n\nfunction ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }\n\nfunction _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }\n\nfunction _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, \"prototype\", { writable: false }); return Constructor; }\n\n// Watch together janus webrtc library\n\n\n\n\nvar Room = /*#__PURE__*/function () {\n function Room(debug) {\n var _this = this;\n\n _classCallCheck(this, Room);\n\n this.debug = debug;\n this.sessions = [];\n this.safariVp8 = false;\n this.browser = webrtc_adapter__WEBPACK_IMPORTED_MODULE_0__[\"default\"].browserDetails.browser;\n this.browserDetails = webrtc_adapter__WEBPACK_IMPORTED_MODULE_0__[\"default\"].browserDetails;\n this.webrtcSupported = Room.isWebrtcSupported();\n this.safariVp8TestPromise = Room.testSafariVp8();\n this.safariVp8 = null;\n this.safariVp8TestPromise.then(function (safariVp8) {\n _this.safariVp8 = safariVp8;\n }); // Let's get it started\n\n this.whenInitialized = this.initialize();\n }\n\n _createClass(Room, [{\n key: \"initialize\",\n value: function initialize() {\n var _this2 = this;\n\n return this.safariVp8TestPromise.then(function () {\n return _this2;\n });\n }\n }, {\n key: \"createSession\",\n value: function createSession() {\n var constructId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;\n var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'reactooroom';\n var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};\n return new RoomSession(constructId, type, _objectSpread({\n debug: this.debug\n }, options));\n }\n }], [{\n key: \"testSafariVp8\",\n value: function testSafariVp8() {\n return new Promise(function (resolve) {\n if (webrtc_adapter__WEBPACK_IMPORTED_MODULE_0__[\"default\"].browserDetails.browser === 'safari' && webrtc_adapter__WEBPACK_IMPORTED_MODULE_0__[\"default\"].browserDetails.version >= 605) {\n if (RTCRtpSender && RTCRtpSender.getCapabilities && RTCRtpSender.getCapabilities(\"video\") && RTCRtpSender.getCapabilities(\"video\").codecs && RTCRtpSender.getCapabilities(\"video\").codecs.length) {\n var isVp8 = false;\n\n for (var i in RTCRtpSender.getCapabilities(\"video\").codecs) {\n var codec = RTCRtpSender.getCapabilities(\"video\").codecs[i];\n\n if (codec && codec.mimeType && codec.mimeType.toLowerCase() === \"video/vp8\") {\n isVp8 = true;\n break;\n }\n }\n\n resolve(isVp8);\n } else {\n // We do it in a very ugly way, as there's no alternative...\n // We create a PeerConnection to see if VP8 is in an offer\n var testpc = new RTCPeerConnection({}, {});\n testpc.createOffer({\n offerToReceiveVideo: true\n }).then(function (offer) {\n var result = offer.sdp.indexOf(\"VP8\") !== -1;\n testpc.close();\n testpc = null;\n resolve(result);\n });\n }\n } else resolve(false);\n });\n }\n }, {\n key: \"isWebrtcSupported\",\n value: function isWebrtcSupported() {\n return window.RTCPeerConnection !== undefined && window.RTCPeerConnection !== null && navigator.mediaDevices !== undefined && navigator.mediaDevices !== null && navigator.mediaDevices.getUserMedia !== undefined && navigator.mediaDevices.getUserMedia !== null;\n }\n }]);\n\n return Room;\n}();\n\nvar RoomSession = /*#__PURE__*/function () {\n function RoomSession() {\n var constructId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;\n var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'reactooroom';\n var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};\n\n _classCallCheck(this, RoomSession);\n\n Object.assign(this, Object(_wt_emitter__WEBPACK_IMPORTED_MODULE_1__[\"default\"])());\n this.server = null;\n this.iceServers = null;\n this.token = null;\n this.roomId = null;\n this.streamId = null;\n this.pin = null;\n this.userId = null;\n this.sessiontype = type;\n this.initialBitrate = 0; //TODO: remove this\n\n this.isMonitor = false; // currently used just for classroom context so monitor user only subscribes to participants and not trainer (for other monitor this flag is not necessary)\n\n this.recordingFilename = null;\n this.pluginName = RoomSession.sessionTypes[type];\n this.options = options;\n this.id = null;\n this.privateId = null;\n this.constructId = constructId || RoomSession.randomString(16);\n this.sessionId = null;\n this.handleId = null;\n this.ws = null;\n this.isRestarting = false; //TODO: do it better\n // double click prevention\n\n this.connectingPromise = null;\n this.disconnectingPromise = null;\n this._ipv6Support = false;\n this._retries = 0;\n this._maxRetries = 3;\n this._keepAliveId = null;\n this._participants = [];\n this._observerIds = [];\n this._talkbackIds = [];\n this._instuctorId = null;\n this._hasJoined = false;\n this._isStreaming = false;\n this._isPublished = false;\n this._isDataChannelOpen = false;\n this.isAudioMuted = false;\n this.isVideoMuted = false;\n this.isVideoEnabled = false;\n this.isAudioEnabed = false;\n this.isUnifiedPlan = RoomSession.checkUnifiedPlan();\n this.subscriptionRules = _objectSpread(_objectSpread({}, RoomSession.subscriptionRules), this.options.subscriptionRules || {});\n this._log = RoomSession.noop;\n\n if (this.options.debug) {\n this._enableDebug();\n }\n } // Check if this browser supports Unified Plan and transceivers\n // Based on https://codepen.io/anon/pen/ZqLwWV?editors=0010\n\n\n _createClass(RoomSession, [{\n key: \"_participantShouldSubscribe\",\n value: function _participantShouldSubscribe(userId) {\n var allowedObservers = this._observerIds || [];\n var allowedTalkback = this._talkbackIds || [];\n var allowedInstructor = this._instuctorId || null;\n var localUserRole = 'participant';\n\n if (this.isMonitor) {\n localUserRole = 'monitor';\n } else if (allowedObservers.indexOf(this.userId) > -1) {\n localUserRole = 'observer';\n } else if (allowedTalkback.indexOf(this.userId) > -1) {\n localUserRole = 'talkback';\n } else if (this.userId === allowedInstructor) {\n localUserRole = 'instructor';\n }\n\n var remoteUserRole = 'participant';\n\n if (allowedObservers.indexOf(userId) > -1) {\n remoteUserRole = 'observer';\n } else if (allowedTalkback.indexOf(userId) > -1) {\n remoteUserRole = 'talkback';\n } else if (userId === allowedInstructor) {\n remoteUserRole = 'instructor';\n }\n\n var mode = allowedInstructor !== null ? 'videoWall' : 'watchTogether';\n return this.subscriptionRules[localUserRole][mode].indexOf(remoteUserRole) > -1;\n }\n }, {\n key: \"_getAddParticipantEventName\",\n value: function _getAddParticipantEventName(handleId) {\n var handle = this._getHandle(handleId);\n\n if (!handle) {\n this.emit('error', {\n type: 'warning',\n id: 15,\n message: 'id non-existent',\n data: [handleId, 'getParticipantEventName']\n });\n }\n\n var allowedTalkback = this._talkbackIds || [];\n var allowedObservers = this._observerIds || [];\n var allowedInstructor = this._instuctorId || null;\n var eventName = 'addRemoteParticipant';\n\n if (handle.userId === allowedInstructor) {\n eventName = 'addRemoteInstructor';\n }\n\n if (allowedTalkback.indexOf(handle.userId) > -1) {\n eventName = 'addRemoteTalkback';\n }\n\n if (allowedObservers.indexOf(handle.userId) > -1) {\n eventName = 'addRemoteObserver';\n }\n\n return eventName;\n }\n }, {\n key: \"_getRemoveParticipantEventName\",\n value: function _getRemoveParticipantEventName(handleId) {\n var handle = this._getHandle(handleId);\n\n if (!handle) {\n this.emit('error', {\n type: 'warning',\n id: 15,\n message: 'id non-existent',\n data: [handleId, 'getParticipantEventName']\n });\n }\n\n var allowedTalkback = this._talkbackIds || [];\n var allowedObservers = this._observerIds || [];\n var allowedInstructor = this._instuctorId || null;\n var eventName = 'removeRemoteParticipant';\n\n if (handle.userId === allowedInstructor) {\n eventName = 'removeRemoteInstructor';\n }\n\n if (allowedTalkback.indexOf(handle.userId) > -1) {\n eventName = 'removeRemoteTalkback';\n }\n\n if (allowedObservers.indexOf(handle.userId) > -1) {\n eventName = 'removeRemoteObserver';\n }\n\n return eventName;\n }\n }, {\n key: \"sendMessage\",\n value: function sendMessage(handleId) {\n var message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {\n body: 'Example Body'\n };\n var dontWait = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;\n var dontResolveOnAck = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;\n return this._send(_objectSpread({\n \"janus\": \"message\",\n \"handle_id\": handleId\n }, message), dontWait, dontResolveOnAck).then(function (json) {\n if (json && json[\"janus\"] === \"success\") {\n var plugindata = json[\"plugindata\"] || {};\n var data = plugindata[\"data\"];\n return Promise.resolve(data);\n }\n\n return Promise.resolve();\n }).catch(function (json) {\n if (json && json[\"error\"]) {\n return Promise.reject({\n type: 'warning',\n id: 1,\n message: 'sendMessage failed',\n data: json[\"error\"]\n });\n } else {\n return Promise.reject({\n type: 'warning',\n id: 1,\n message: 'sendMessage failed',\n data: json\n });\n }\n });\n }\n }, {\n key: \"_send\",\n value: function _send() {\n var _this3 = this;\n\n var request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n var ignoreResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;\n var dontResolveOnAck = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;\n var transaction = RoomSession.randomString(12);\n\n var requestData = _objectSpread(_objectSpread({}, request), {}, {\n transaction: transaction,\n token: this.token\n }, this.sessionId && {\n 'session_id': this.sessionId\n } || {});\n\n var timeouId = null;\n return new Promise(function (resolve, reject) {\n var parseResponse = function parseResponse(event) {\n var json = JSON.parse(event.data);\n var r_transaction = json['transaction'];\n\n if (r_transaction === transaction && (!dontResolveOnAck || json['janus'] !== 'ack')) {\n clearTimeout(timeouId);\n\n _this3.ws.removeEventListener('message', parseResponse);\n\n if (json['janus'] === 'error') {\n var _json$error;\n\n if ((json === null || json === void 0 ? void 0 : (_json$error = json.error) === null || _json$error === void 0 ? void 0 : _json$error.code) == 403) {\n _this3.disconnect(true);\n }\n\n reject({\n type: 'error',\n id: 2,\n message: 'send failed',\n data: json,\n requestData: requestData\n });\n } else {\n resolve(json);\n }\n }\n };\n\n if (ignoreResponse) {\n if (_this3.ws && _this3.ws.readyState === 1) {\n _this3.ws.send(JSON.stringify(requestData));\n }\n\n resolve();\n } else {\n if (_this3.ws && _this3.ws.readyState === 1) {\n _this3.ws.addEventListener('message', parseResponse);\n\n timeouId = setTimeout(function () {\n _this3.ws.removeEventListener('message', parseResponse);\n\n reject({\n type: 'error',\n id: 3,\n message: 'send timeout',\n data: requestData\n });\n }, 10000);\n\n _this3.ws.send(JSON.stringify(requestData));\n } else {\n reject({\n type: 'warning',\n id: 29,\n message: 'No connection to WebSockets',\n data: requestData\n });\n }\n }\n });\n }\n }, {\n key: \"_connectionClosed\",\n value: function _connectionClosed() {\n var _this4 = this;\n\n if (this.disconnectingPromise || this.connectingPromise) {\n return;\n }\n\n if (this._retries < this._maxRetries) {\n setTimeout(function () {\n _this4._retries++;\n\n _this4._reconnect().catch(function (e) {\n _this4.emit('error', e);\n });\n }, 3000 * this._retries);\n } else {\n if (this.sessiontype === 'reactooroom') {\n this.disconnect(true);\n } else if (this.sessiontype === 'streaming') {\n this.stopStream();\n }\n\n this.emit('error', {\n type: 'error',\n id: 4,\n message: 'Lost connection to WebSockets',\n data: null\n });\n }\n }\n }, {\n key: \"_wipeListeners\",\n value: function _wipeListeners() {\n if (this.ws) {\n this.ws.removeEventListener('close', this.__connectionClosedBoundFn);\n this.ws.removeEventListener('message', this.__handleWsEventsBoundFn);\n }\n }\n }, {\n key: \"_startKeepAlive\",\n value: function _startKeepAlive() {\n var _this5 = this;\n\n this._send({\n \"janus\": \"keepalive\"\n }).then(function (json) {\n if (json[\"janus\"] !== 'ack') {\n _this5.emit('error', {\n type: 'warning',\n id: 5,\n message: 'keepalive response suspicious',\n data: json[\"janus\"]\n });\n }\n }).catch(function (e) {\n _this5.emit('error', {\n type: 'warning',\n id: 6,\n message: 'keepalive dead',\n data: e\n });\n\n _this5._connectionClosed();\n });\n\n this._keepAliveId = setTimeout(function () {\n _this5._startKeepAlive();\n }, 30000);\n }\n }, {\n key: \"_stopKeepAlive\",\n value: function _stopKeepAlive() {\n clearTimeout(this._keepAliveId);\n }\n }, {\n key: \"_handleWsEvents\",\n value: function _handleWsEvents(event) {\n var _this6 = this;\n\n var json = JSON.parse(event.data);\n var sender = json[\"sender\"];\n var type = json[\"janus\"];\n\n var handle = this._getHandle(sender);\n\n if (!handle) {\n return;\n }\n\n if (type === \"trickle\") {\n var candidate = json[\"candidate\"];\n var config = handle.webrtcStuff;\n\n if (config.pc && config.remoteSdp) {\n if (!candidate || candidate.completed === true) {\n config.pc.addIceCandidate(null);\n } else {\n config.pc.addIceCandidate(candidate);\n }\n } else {\n if (!config.candidates) {\n config.candidates = [];\n }\n\n config.candidates.push(candidate);\n }\n } else if (type === \"webrtcup\") {//none universal\n } else if (type === \"hangup\") {\n this._log('hangup on', handle.handleId);\n\n this._removeParticipant(handle.handleId, null, false);\n } else if (type === \"detached\") {\n this._log('detached on', handle.handleId);\n\n this._removeParticipant(handle.handleId, null, true);\n } else if (type === \"media\") {\n this._log('Media event:', handle.handleId, json[\"type\"], json[\"receiving\"]);\n } else if (type === \"slowlink\") {\n this._log('Slowlink', handle.handleId, json[\"uplink\"], json[\"nacks\"]);\n } else if (type === \"event\") {//none universal\n } else if (type === 'timeout') {\n this.ws.close(3504, \"Gateway timeout\");\n } else if (type === 'success' || type === 'error') {// we're capturing those elsewhere\n } else {\n this._log(\"Unknown event: \".concat(type, \" on session: \").concat(this.sessionId));\n } // LOCAL\n\n\n if (sender === this.handleId) {\n if (type === \"event\") {\n var plugindata = json[\"plugindata\"] || {};\n var msg = plugindata[\"data\"] || {};\n var jsep = json[\"jsep\"];\n var result = msg[\"result\"] || null;\n\n var _event = msg[\"videoroom\"] || null;\n\n var list = msg[\"publishers\"] || {};\n var leaving = msg[\"leaving\"]; //let joining = msg[\"joining\"];\n\n var unpublished = msg[\"unpublished\"];\n var error = msg[\"error\"];\n\n if (_event === \"joined\") {\n this.id = msg[\"id\"];\n this.privateId = msg[\"private_id\"];\n this._hasJoined = true;\n this.emit('joined', true);\n\n this._log('We have successfully joined Room');\n\n var _loop = function _loop(f) {\n var userId = list[f][\"display\"];\n var streams = list[f][\"streams\"] || [];\n var id = list[f][\"id\"];\n\n for (var i in streams) {\n streams[i][\"id\"] = id;\n streams[i][\"display\"] = userId;\n }\n\n _this6._log('Remote userId: ', userId);\n\n if (_this6._participantShouldSubscribe(userId)) {\n _this6._log('Creating user: ', userId);\n\n _this6._createParticipant(userId, id).then(function (handle) {\n return _this6.sendMessage(handle.handleId, {\n body: {\n \"request\": \"join\",\n \"room\": _this6.roomId,\n \"ptype\": \"subscriber\",\n \"feed\": id,\n \"private_id\": _this6.privateId,\n pin: _this6.pin\n }\n });\n }).catch(function (err) {\n _this6.emit('error', err);\n });\n }\n };\n\n for (var f in list) {\n _loop(f);\n }\n } else if (_event === \"event\") {\n if (msg[\"streams\"] !== undefined && msg[\"streams\"] !== null) {\n this._log('Got my own streams back', msg[\"streams\"]);\n }\n\n var _loop2 = function _loop2(_f) {\n var userId = list[_f][\"display\"];\n var streams = list[_f][\"streams\"] || [];\n var id = list[_f][\"id\"];\n\n for (var i in streams) {\n streams[i][\"id\"] = id;\n streams[i][\"display\"] = userId;\n }\n\n _this6._log('Remote userId: ', userId);\n\n if (_this6._participantShouldSubscribe(userId)) {\n _this6._log('Creating user: ', userId);\n\n _this6._createParticipant(userId, id).then(function (handle) {\n return _this6.sendMessage(handle.handleId, {\n body: {\n \"request\": \"join\",\n \"room\": _this6.roomId,\n \"ptype\": \"subscriber\",\n \"feed\": id,\n \"private_id\": _this6.privateId,\n pin: _this6.pin\n }\n });\n }).catch(function (err) {\n _this6.emit('error', err);\n });\n }\n };\n\n for (var _f in list) {\n _loop2(_f);\n }\n\n if (leaving === 'ok') {\n this._log('leaving', this.handleId, 'this is us');\n\n this._removeParticipant(this.handleId);\n\n if (msg['reason'] === 'kicked') {\n this.emit('kicked');\n this.disconnect().catch(function () {});\n }\n } else if (leaving) {\n this._log('leaving', leaving);\n\n this._removeParticipant(null, leaving);\n }\n\n if (unpublished === 'ok') {\n this._log('unpublished', this.handleId, 'this is us');\n\n this._removeParticipant(this.handleId, null, false); // we do just hangup\n\n } else if (unpublished) {\n this._log('unpublished', unpublished);\n\n this._removeParticipant(null, unpublished, true); // we do hangup and detach\n\n }\n\n if (error) {\n this.emit('error', {\n type: 'error',\n id: 7,\n message: 'local participant error',\n data: [sender, msg]\n });\n }\n } // Streaming related\n else if (result && result[\"status\"]) {\n this.emit('streamingStatus', result[\"status\"]);\n\n if (result[\"status\"] === 'stopped') {\n this.stopStream();\n }\n\n if (result[\"status\"] === 'started') {\n this.emit('streaming', true);\n this._isStreaming = true;\n }\n }\n\n if (jsep !== undefined && jsep !== null) {\n if (this.sessiontype === 'reactooroom') {\n this._webrtcPeer(this.handleId, jsep).catch(function (err) {\n _this6.emit('error', err);\n });\n } else if (this.sessiontype === 'streaming') {\n this._publishRemote(this.handleId, jsep).catch(function (err) {\n _this6.emit('error', err);\n });\n }\n }\n } else if (type === \"webrtcup\") {\n this._log('Configuring bitrate: ' + this.initialBitrate);\n\n if (this.initialBitrate > 0) {\n this.sendMessage(this.handleId, {\n \"body\": {\n \"request\": \"configure\",\n \"bitrate\": this.initialBitrate\n }\n }).catch(function () {\n return null;\n });\n }\n }\n } //REMOTE\n else {\n var _plugindata = json[\"plugindata\"] || {};\n\n var _msg = _plugindata[\"data\"] || {};\n\n var _jsep2 = json[\"jsep\"];\n var _event2 = _msg[\"videoroom\"];\n var _error = _msg[\"error\"];\n\n if (_event2 === \"attached\") {\n this._log('Remote have successfully joined Room', _msg);\n\n this.emit(this._getAddParticipantEventName(handle.handleId), {\n tid: Object(_wt_utils__WEBPACK_IMPORTED_MODULE_2__[\"generateUUID\"])(),\n id: handle.handleId,\n userId: handle.userId,\n stream: null,\n track: null,\n adding: false,\n constructId: this.constructId,\n metaData: this.options.metaData,\n hasAudioTrack: false,\n hasVideoTrack: false\n });\n }\n\n if (_error) {\n this.emit('error', {\n type: 'warning',\n id: 8,\n message: 'remote participant error',\n data: [sender, _msg]\n });\n }\n\n if (_jsep2) {\n this._publishRemote(handle.handleId, _jsep2).catch(function (err) {\n _this6.emit('error', err);\n });\n }\n }\n }\n }, {\n key: \"_handleDataEvents\",\n value: function _handleDataEvents(handleId, type, data) {\n var handle = this._getHandle(handleId);\n\n if (type === 'state') {\n this._log(\" - Data channel status - \", \"UID: \".concat(handleId), \"STATUS: \".concat(data), \"ME: \".concat(handleId === this.handleId));\n\n if (handle) {\n var config = handle.webrtcStuff;\n config.dataChannelOpen = data === 'open';\n }\n\n if (handleId === this.handleId) {\n this._isDataChannelOpen = data === 'open';\n this.emit('dataChannel', data === 'open');\n }\n }\n\n if (type === 'error') {\n this.emit('error', {\n type: 'warning',\n id: 9,\n message: 'data event warning',\n data: [handleId, data]\n });\n\n if (handle) {\n var _config = handle.webrtcStuff;\n _config.dataChannelOpen = false;\n }\n\n if (handleId === this.handleId) {\n this._isDataChannelOpen = false;\n this.emit('dataChannel', false);\n }\n }\n\n if (handleId === this.handleId && type === 'message') {\n var d = null;\n\n try {\n d = JSON.parse(data);\n } catch (e) {\n this.emit('error', {\n type: 'warning',\n id: 10,\n message: 'data message parse error',\n data: [handleId, e]\n });\n return;\n }\n\n this.emit('data', d);\n }\n } //removeHandle === true -> hangup, detach, removeHandle === false -> hangup\n\n }, {\n key: \"_removeParticipant\",\n value: function _removeParticipant(handleId, rfid) {\n var _this7 = this;\n\n var removeHandle = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;\n\n var handle = this._getHandle(handleId, rfid);\n\n if (!handle) {\n return Promise.resolve();\n } else {\n handleId = handle.handleId;\n }\n\n return this._send({\n \"janus\": \"hangup\",\n \"handle_id\": handleId\n }, true).then(function () {\n return removeHandle ? _this7._send({\n \"janus\": \"detach\",\n \"handle_id\": handleId\n }, true) : Promise.resolve();\n }).finally(function () {\n try {\n if (handle.webrtcStuff.stream && !_this7.isRestarting) {\n handle.webrtcStuff.stream.getTracks().forEach(function (track) {\n return track.stop();\n });\n }\n } catch (e) {// Do nothing\n }\n\n handle.webrtcStuff.stream = null;\n\n if (handle.webrtcStuff.dataChannel) {\n handle.webrtcStuff.dataChannel.onmessage = null;\n handle.webrtcStuff.dataChannel.onopen = null;\n handle.webrtcStuff.dataChannel.onclose = null;\n handle.webrtcStuff.dataChannel.onerror = null;\n }\n\n if (handle.webrtcStuff.pc) {\n handle.webrtcStuff.pc.onicecandidate = null;\n handle.webrtcStuff.pc.ontrack = null;\n handle.webrtcStuff.pc.ondatachannel = null;\n handle.webrtcStuff.pc.onconnectionstatechange = null;\n handle.webrtcStuff.pc.oniceconnectionstatechange = null;\n }\n\n try {\n handle.webrtcStuff.pc.close();\n } catch (e) {}\n\n handle.webrtcStuff = {\n stream: null,\n mySdp: null,\n mediaConstraints: null,\n pc: null,\n dataChannelOpen: false,\n dataChannel: null,\n dtmfSender: null,\n trickle: true,\n iceDone: false\n };\n\n if (handleId === _this7.handleId) {\n _this7._isDataChannelOpen = false;\n _this7._isPublished = false;\n\n _this7.emit('published', {\n status: false,\n hasStream: false\n });\n\n _this7.emit('removeLocalParticipant', {\n id: handleId,\n userId: handle.userId\n });\n } else {\n _this7.emit(_this7._getRemoveParticipantEventName(handleId), {\n id: handleId,\n userId: handle.userId\n });\n }\n\n if (removeHandle) {\n var handleIndex = _this7._participants.findIndex(function (p) {\n return p.handleId === handleId;\n });\n\n _this7._participants.splice(handleIndex, 1);\n }\n\n return true;\n });\n }\n }, {\n key: \"_createParticipant\",\n value: function _createParticipant() {\n var _this8 = this;\n\n var userId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;\n var rfid = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;\n return this._send({\n \"janus\": \"attach\",\n \"plugin\": this.pluginName\n }).then(function (json) {\n var handleId = json.data[\"id\"];\n var handle = {\n handleId: handleId,\n rfid: rfid,\n userId: userId,\n webrtcStuff: {\n stream: null,\n mySdp: null,\n mediaConstraints: null,\n pc: null,\n dataChannelOpen: false,\n dataChannel: null,\n dtmfSender: null,\n trickle: true,\n iceDone: false,\n isIceRestarting: false\n }\n };\n\n _this8._participants.push(handle);\n\n return handle;\n });\n }\n }, {\n key: \"_joinRoom\",\n value: function _joinRoom(roomId, pin, userId) {\n return this.sendMessage(this.handleId, {\n body: {\n \"request\": \"join\",\n \"room\": roomId,\n \"pin\": pin,\n \"ptype\": \"publisher\",\n \"display\": userId\n }\n }, false, true);\n }\n }, {\n key: \"_watchStream\",\n value: function _watchStream(id) {\n return this.sendMessage(this.handleId, {\n body: {\n \"request\": \"watch\",\n id: parseInt(id)\n }\n }, false, true);\n }\n }, {\n key: \"_leaveRoom\",\n value: function _leaveRoom() {\n var _this9 = this;\n\n var dontWait = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;\n return this._hasJoined ? this.sendMessage(this.handleId, {\n body: {\n \"request\": \"leave\"\n }\n }, dontWait).finally(function () {\n _this9._hasJoined = false;\n\n _this9.emit('joined', false);\n }) : Promise.resolve();\n } // internal reconnect\n\n }, {\n key: \"_reconnect\",\n value: function _reconnect() {\n var _this10 = this;\n\n if (this.connectingPromise) {\n return this.connectingPromise;\n }\n\n if (this.ws) {\n this._wipeListeners();\n\n if (this.ws.readyState === 1) {\n this.ws.close();\n }\n }\n\n this._stopKeepAlive();\n\n this.connectingPromise = new Promise(function (resolve, reject) {\n _this10.emit('joining', true);\n\n _this10.ws = new WebSocket(_this10.server, 'janus-protocol');\n _this10.__connectionClosedBoundFn = _this10._connectionClosed.bind(_this10);\n _this10.__handleWsEventsBoundFn = _this10._handleWsEvents.bind(_this10);\n\n _this10.ws.addEventListener('close', _this10.__connectionClosedBoundFn);\n\n _this10.ws.addEventListener('message', _this10.__handleWsEventsBoundFn);\n\n _this10.ws.onopen = function () {\n _this10._send({\n \"janus\": \"claim\"\n }).then(function (json) {\n _this10.sessionId = json[\"session_id\"] ? json[\"session_id\"] : json.data[\"id\"];\n\n _this10._startKeepAlive();\n\n _this10.connectingPromise = null;\n\n _this10.emit('joining', false);\n\n _this10._retries = 0;\n resolve(json);\n }).catch(function (error) {\n _this10.connectingPromise = null;\n\n _this10.emit('joining', false);\n\n reject({\n type: 'error',\n id: 11,\n message: 'reconnection error',\n data: error\n });\n });\n }; // this is called before 'close' event callback so it doesn't break reconnect loop\n\n\n _this10.ws.onerror = function (e) {\n _this10.connectingPromise = null;\n\n _this10.emit('joining', false);\n\n reject({\n type: 'warning',\n id: 12,\n message: 'ws reconnection error',\n data: e\n });\n };\n });\n return this.connectingPromise;\n }\n }, {\n key: \"connect\",\n value: function connect(roomId, pin, server, iceServers, token, userId) {\n var _this11 = this;\n\n var webrtcVersion = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 0;\n var initialBitrate = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : 0;\n var isMonitor = arguments.length > 8 ? arguments[8] : undefined;\n var recordingFilename = arguments.length > 9 ? arguments[9] : undefined;\n\n if (this.connectingPromise) {\n return this.connectingPromise;\n }\n\n this.emit('joined', false);\n\n if (this.ws) {\n this._wipeListeners();\n }\n\n this._stopKeepAlive();\n\n this.disconnectingPromise = null;\n this.sessionId = null;\n this.server = server;\n this.iceServers = iceServers;\n this.token = token;\n this.roomId = roomId;\n this.pin = pin;\n this.userId = userId;\n this.initialBitrate = initialBitrate;\n this.isMonitor = isMonitor;\n this.recordingFilename = recordingFilename;\n this.disconnectingPromise = null;\n this.connectingPromise = new Promise(function (resolve, reject) {\n _this11.emit('joining', true);\n\n _this11.ws = new WebSocket(_this11.server, 'janus-protocol');\n _this11.__connectionClosedBoundFn = _this11._connectionClosed.bind(_this11);\n _this11.__handleWsEventsBoundFn = _this11._handleWsEvents.bind(_this11);\n\n _this11.ws.addEventListener('close', _this11.__connectionClosedBoundFn);\n\n _this11.ws.addEventListener('message', _this11.__handleWsEventsBoundFn);\n\n _this11.ws.onopen = function () {\n _this11._retries = 0;\n\n _this11._send({\n \"janus\": \"create\"\n }).then(function (json) {\n _this11.sessionId = json[\"session_id\"] ? json[\"session_id\"] : json.data[\"id\"];\n\n _this11._startKeepAlive();\n\n return 1;\n }).then(function () {\n return _this11._createParticipant(userId);\n }).then(function (handle) {\n _this11.handleId = handle.handleId;\n return 1;\n }).then(function () {\n return _this11._joinRoom(roomId, pin, userId);\n }).then(function () {\n _this11.connectingPromise = null;\n\n _this11.emit('joining', false);\n\n resolve(_this11);\n }).catch(function (error) {\n _this11.connectingPromise = null;\n\n _this11.emit('joining', false);\n\n reject({\n type: 'error',\n id: 13,\n message: 'connection error',\n data: error\n });\n });\n };\n\n _this11.ws.onerror = function (e) {\n _this11.connectingPromise = null;\n\n _this11.emit('joining', false);\n\n reject({\n type: 'error',\n id: 14,\n message: 'ws connection error',\n data: e\n });\n };\n });\n return this.connectingPromise;\n }\n }, {\n key: \"disconnect\",\n value: function disconnect() {\n var _this12 = this;\n\n if (this.disconnectingPromise) {\n return this.disconnectingPromise;\n }\n\n this._stopKeepAlive();\n\n this.disconnectingPromise = Promise.all(this._participants.map(function (p) {\n return _this12._removeParticipant(p.handleId);\n })).finally(function () {\n _this12._wipeListeners();\n\n if (_this12.ws && _this12.ws.readyState === 1) {\n _this12._send({\n \"janus\": \"destroy\"\n }, true);\n\n _this12.ws.close();\n }\n\n _this12.sessionId = null; //TODO: Just in case something crashed along the way\n\n _this12._isPublished = false;\n _this12._hasJoined = false;\n\n _this12.emit('published', {\n status: false,\n hasStream: false\n });\n\n _this12.emit('joined', false);\n\n _this12.emit('disconnect');\n\n return Promise.resolve('Disconnected');\n });\n return this.disconnectingPromise;\n }\n }, {\n key: \"startStream\",\n value: function startStream(streamId, server, iceServers, token, userId) {\n var _this13 = this;\n\n if (this.connectingPromise) {\n return this.connectingPromise;\n }\n\n this.emit('streaming', false);\n\n if (this.ws) {\n this._wipeListeners();\n }\n\n this._stopKeepAlive();\n\n this.disconnectingPromise = null;\n this.sessionId = null;\n this.server = server;\n this.iceServers = iceServers;\n this.token = token;\n this.streamId = streamId;\n this.userId = userId;\n this.connectingPromise = new Promise(function (resolve, reject) {\n _this13.emit('streamStarting', true);\n\n _this13.ws = new WebSocket(_this13.server, 'janus-protocol');\n _this13.__connectionClosedBoundFn = _this13._connectionClosed.bind(_this13);\n _this13.__handleWsEventsBoundFn = _this13._handleWsEvents.bind(_this13);\n\n _this13.ws.addEventListener('close', _this13.__connectionClosedBoundFn);\n\n _this13.ws.addEventListener('message', _this13.__handleWsEventsBoundFn);\n\n _this13.ws.onopen = function () {\n _this13._retries = 0;\n\n _this13._send({\n \"janus\": \"create\"\n }).then(function (json) {\n _this13.sessionId = json[\"session_id\"] ? json[\"session_id\"] : json.data[\"id\"];\n\n _this13._startKeepAlive();\n\n return 1;\n }).then(function () {\n return _this13._createParticipant(userId);\n }).then(function (handle) {\n _this13.handleId = handle.handleId;\n return 1;\n }).then(function () {\n return _this13._watchStream(streamId);\n }).then(function () {\n _this13.connectingPromise = null;\n\n _this13.emit('streamStarting', false);\n\n resolve(_this13);\n }).catch(function (error) {\n _this13.connectingPromise = null;\n\n _this13.emit('streamStarting', false);\n\n reject({\n type: 'error',\n id: 13,\n message: 'connection error',\n data: error\n });\n });\n };\n\n _this13.ws.onerror = function (e) {\n _this13.connectingPromise = null;\n\n _this13.emit('streamStarting', false);\n\n reject({\n type: 'error',\n id: 14,\n message: 'ws connection error',\n data: e\n });\n };\n });\n return this.connectingPromise;\n }\n }, {\n key: \"stopStream\",\n value: function stopStream() {\n var _this14 = this;\n\n if (this.disconnectingPromise) {\n return this.disconnectingPromise;\n }\n\n this._stopKeepAlive();\n\n this.disconnectingPromise = this.sendMessage(this.handleId, {\n body: {\n \"request\": \"stop\"\n }\n }, false, true).then(function () {\n return _this14._removeParticipant(_this14.handleId);\n }).finally(function () {\n _this14._wipeListeners();\n\n _this14._send({\n \"janus\": \"destroy\"\n }, true);\n\n if (_this14.ws && _this14.ws.readyState === 1) {\n _this14.ws.close();\n }\n\n _this14.sessionId = null;\n _this14._isStreaming = false;\n\n _this14.emit('streaming', false); // last event\n\n\n _this14.emit('disconnect');\n\n _this14.disconnectingPromise = null;\n return Promise.resolve('Disconnected');\n });\n return this.disconnectingPromise;\n }\n }, {\n key: \"destroy\",\n value: function destroy() {\n var _this15 = this;\n\n if (this.sessiontype === 'reactooroom') {\n return this.disconnect().then(function () {\n _this15.clear();\n\n return true;\n });\n } else if (this.sessiontype === 'streaming') {\n return this.stopStream().then(function () {\n _this15.clear();\n\n return true;\n });\n }\n }\n }, {\n key: \"_enableDebug\",\n value: function _enableDebug() {\n this._log = console.log.bind(console);\n }\n }, {\n key: \"_getHandle\",\n value: function _getHandle(handleId) {\n var rfid = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;\n return this._participants.find(function (p) {\n return p.handleId === handleId || rfid && p.rfid === rfid;\n });\n }\n }, {\n key: \"_getStats\",\n value: function _getStats() {\n var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;\n return Promise.all(this._participants.map(function (participant) {\n var mediaTrack = null;\n\n if (type === 'video') {\n mediaTrack = participant.webrtcStuff && participant.webrtcStuff.stream && participant.webrtcStuff.stream.getVideoTracks().length && participant.webrtcStuff.stream.getVideoTracks()[0];\n } else if (type === 'audio') {\n mediaTrack = participant.webrtcStuff && participant.webrtcStuff.stream && participant.webrtcStuff.stream.getAudioTracks().length && participant.webrtcStuff.stream.getAudioTracks()[0];\n }\n\n return participant.webrtcStuff && participant.webrtcStuff.pc && participant.webrtcStuff.pc.getStats(mediaTrack).then(function (r) {\n return {\n handle: participant,\n stats: r\n };\n }).catch(function (e) {\n return Promise.resolve({\n handle: participant,\n stats: e\n });\n });\n }));\n }\n }, {\n key: \"_sendTrickleCandidate\",\n value: function _sendTrickleCandidate(handleId, candidate) {\n return this._send({\n \"janus\": \"trickle\",\n \"candidate\": candidate,\n \"handle_id\": handleId\n });\n }\n }, {\n key: \"_webrtc\",\n value: function _webrtc(handleId) {\n var _this16 = this;\n\n var enableOntrack = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;\n\n var handle = this._getHandle(handleId);\n\n if (!handle) {\n this.emit('error', {\n type: 'warning',\n id: 15,\n message: 'id non-existent',\n data: [handleId, 'create rtc connection']\n });\n }\n\n var config = handle.webrtcStuff;\n\n if (!config.pc) {\n var pc_config = {\n \"iceServers\": this.iceServers,\n \"iceTransportPolicy\": 'all',\n \"bundlePolicy\": undefined\n };\n pc_config[\"sdpSemantics\"] = this.isUnifiedPlan ? \"unified-plan\" : \"plan-b\";\n var pc_constraints = {\n \"optional\": [{\n \"DtlsSrtpKeyAgreement\": true\n }]\n };\n\n if (this._ipv6Support === true) {\n pc_constraints.optional.push({\n \"googIPv6\": true\n });\n }\n\n if (webrtc_adapter__WEBPACK_IMPORTED_MODULE_0__[\"default\"].browserDetails.browser === \"edge\") {\n // This is Edge, enable BUNDLE explicitly\n pc_config.bundlePolicy = \"max-bundle\";\n }\n\n this._log('new RTCPeerConnection', pc_config, pc_constraints);\n\n config.pc = new RTCPeerConnection(pc_config, pc_constraints);\n\n config.pc.onconnectionstatechange = function () {\n if (config.pc.connectionState === 'failed') {\n _this16._iceRestart(handleId);\n }\n\n _this16.emit('connectionState', [handleId, handleId === _this16.handleId, config.pc.connectionState]);\n\n if (handleId !== _this16.handleId && config.pc.connectionState === 'connected') {\n _this16.emit(_this16._getAddParticipantEventName(handle.handleId), {\n tid: Object(_wt_utils__WEBPACK_IMPORTED_MODULE_2__[\"generateUUID\"])(),\n id: handle.handleId,\n userId: handle.userId,\n stream: config.stream,\n optional: true,\n constructId: _this16.constructId,\n metaData: _this16.options.metaData,\n adding: true,\n hasAudioTrack: !!(config.stream && config.stream.getAudioTracks().length),\n hasVideoTrack: !!(config.stream && config.stream.getVideoTracks().length)\n });\n }\n };\n\n config.pc.oniceconnectionstatechange = function () {\n if (config.pc.iceConnectionState === 'failed') {\n _this16._iceRestart(handleId);\n }\n\n _this16.emit('iceState', [handleId, handleId === _this16.handleId, config.pc.iceConnectionState]);\n\n if (handleId !== _this16.handleId && (config.pc.iceConnectionState === 'completed' || config.pc.iceConnectionState === 'connected')) {\n _this16.emit(_this16._getAddParticipantEventName(handle.handleId), {\n tid: Object(_wt_utils__WEBPACK_IMPORTED_MODULE_2__[\"generateUUID\"])(),\n id: handle.handleId,\n userId: handle.userId,\n stream: config.stream,\n optional: true,\n constructId: _this16.constructId,\n metaData: _this16.options.metaData,\n adding: true,\n hasAudioTrack: !!(config.stream && config.stream.getAudioTracks().length),\n hasVideoTrack: !!(config.stream && config.stream.getVideoTracks().length)\n });\n }\n };\n\n config.pc.onicecandidate = function (event) {\n if (event.candidate == null || webrtc_adapter__WEBPACK_IMPORTED_MODULE_0__[\"default\"].browserDetails.browser === 'edge' && event.candidate.candidate.indexOf('endOfCandidates') > 0) {\n config.iceDone = true;\n\n _this16._sendTrickleCandidate(handleId, {\n \"completed\": true\n }).catch(function (e) {\n _this16.emit('error', e);\n });\n } else {\n // JSON.stringify doesn't work on some WebRTC objects anymore\n // See https://code.google.com/p/chromium/issues/detail?id=467366\n var candidate = {\n \"candidate\": event.candidate.candidate,\n \"sdpMid\": event.candidate.sdpMid,\n \"sdpMLineIndex\": event.candidate.sdpMLineIndex\n };\n\n _this16._sendTrickleCandidate(handleId, candidate).catch(function (e) {\n _this16.emit('error', e);\n });\n }\n };\n\n if (enableOntrack) {\n config.pc.ontrack = function (event) {\n // if(!event.streams)\n // return;\n //config.stream = event.streams[0];\n if (!config.stream) {\n config.stream = new MediaStream();\n }\n\n if (event.track) {\n config.stream.addTrack(event.track);\n\n _this16.emit(_this16._getAddParticipantEventName(handle.handleId), {\n tid: Object(_wt_utils__WEBPACK_IMPORTED_MODULE_2__[\"generateUUID\"])(),\n id: handle.handleId,\n userId: handle.userId,\n stream: config.stream,\n track: event.track,\n constructId: _this16.constructId,\n metaData: _this16.options.metaData,\n adding: true,\n hasAudioTrack: !!(config.stream && config.stream.getAudioTracks().length),\n hasVideoTrack: !!(config.stream && config.stream.getVideoTracks().length)\n });\n\n if (event.track.onended) return;\n\n event.track.onended = function (ev) {\n if (config.stream) {\n config.stream && config.stream.removeTrack(ev.target);\n\n _this16.emit(_this16._getAddParticipantEventName(handle.handleId), {\n tid: Object(_wt_utils__WEBPACK_IMPORTED_MODULE_2__[\"generateUUID\"])(),\n id: handle.handleId,\n userId: handle.userId,\n stream: config.stream,\n track: ev.target,\n constructId: _this16.constructId,\n metaData: _this16.options.metaData,\n adding: false,\n hasAudioTrack: !!(config.stream && config.stream.getAudioTracks().length),\n hasVideoTrack: !!(config.stream && config.stream.getVideoTracks().length)\n });\n }\n };\n\n event.track.onmute = function (ev) {\n _this16._log('remoteTrackMuted', 'onmute');\n\n _this16.emit('remoteTrackMuted', {\n id: handle.handleId,\n userId: handle.userId,\n stream: config.stream,\n kind: ev.target.kind,\n track: ev.target,\n muted: true\n });\n };\n\n event.track.onunmute = function (ev) {\n _this16._log('remoteTrackMuted', 'onunmute');\n\n _this16.emit('remoteTrackMuted', {\n id: handle.handleId,\n userId: handle.userId,\n stream: config.stream,\n kind: ev.target.kind,\n track: ev.target,\n muted: false\n });\n };\n }\n };\n }\n }\n\n var defaultDataChannelLabel = 'JanusDataChannel';\n\n if (!config.dataChannel || !config.dataChannelOpen) {\n var onDataChannelMessage = function onDataChannelMessage(event) {\n _this16._handleDataEvents(handleId, 'message', event.data);\n };\n\n var onDataChannelStateChange = function onDataChannelStateChange(event) {\n _this16._handleDataEvents(handleId, 'state', config.dataChannel.readyState);\n };\n\n var onDataChannelError = function onDataChannelError(error) {\n _this16._handleDataEvents(handleId, 'error', error);\n }; // Until we implement the proxying of open requests within the Janus core, we open a channel ourselves whatever the case\n\n\n config.dataChannel = config.pc.createDataChannel(defaultDataChannelLabel, {\n ordered: true\n });\n config.dataChannel.onmessage = onDataChannelMessage;\n config.dataChannel.onopen = onDataChannelStateChange;\n config.dataChannel.onclose = onDataChannelStateChange;\n config.dataChannel.onerror = onDataChannelError;\n\n config.pc.ondatachannel = function (event) {\n //TODO: implement this\n console.log('Janus is creating data channel');\n };\n }\n }\n }, {\n key: \"_webrtcPeer\",\n value: function _webrtcPeer(handleId, jsep) {\n var handle = this._getHandle(handleId);\n\n if (!handle) {\n return Promise.reject({\n type: 'warning',\n id: 15,\n message: 'id non-existent',\n data: [handleId, 'rtc peer']\n });\n }\n\n var config = handle.webrtcStuff;\n\n if (jsep !== undefined && jsep !== null) {\n if (config.pc === null) {\n this._log(\"No PeerConnection: if this is an answer, use createAnswer and not _webrtcPeer\");\n\n return Promise.resolve(null);\n }\n\n return config.pc.setRemoteDescription(jsep).then(function () {\n config.remoteSdp = jsep.sdp; // Any trickle candidate we cached?\n\n if (config.candidates && config.candidates.length > 0) {\n for (var i = 0; i < config.candidates.length; i++) {\n var candidate = config.candidates[i];\n\n if (!candidate || candidate.completed === true) {\n config.pc.addIceCandidate(null);\n } else {\n config.pc.addIceCandidate(candidate);\n }\n }\n\n config.candidates = [];\n } // Done\n\n\n return true;\n });\n } else {\n return Promise.reject({\n type: 'warning',\n id: 22,\n message: 'rtc peer',\n data: [handleId, 'invalid jsep']\n });\n }\n }\n }, {\n key: \"_iceRestart\",\n value: function _iceRestart(handleId) {\n var _this17 = this;\n\n var handle = this._getHandle(handleId);\n\n if (!handle) {\n return;\n }\n\n var config = handle.webrtcStuff; // Already restarting;\n\n if (config.isIceRestarting) {\n return;\n }\n\n if (this.handleId === handleId) {\n this._log('Performing local ICE restart');\n\n config.isIceRestarting = true;\n var hasAudio = !!(config.stream && config.stream.getAudioTracks().length > 0);\n var hasVideo = !!(config.stream && config.stream.getVideoTracks().length > 0);\n\n this._createAO('offer', handleId, true, [hasAudio, false, hasVideo, false]).then(function (jsep) {\n if (!jsep) {\n return null;\n }\n\n return _this17.sendMessage(handleId, {\n body: _objectSpread({\n \"request\": \"configure\",\n \"audio\": hasAudio,\n \"video\": hasVideo,\n \"data\": true\n }, _this17.recordingFilename ? {\n filename: _this17.recordingFilename\n } : {}),\n jsep: jsep\n });\n }).then(function (r) {\n config.isIceRestarting = false;\n\n _this17._log('ICE restart success');\n }).catch(function (e) {\n config.isIceRestarting = false;\n\n _this17.emit('warning', {\n type: 'error',\n id: 28,\n message: 'iceRestart failed',\n data: e\n });\n });\n } else {\n this._log('Performing remote ICE restart', handleId);\n\n config.isIceRestarting = true;\n return this.sendMessage(handleId, {\n body: {\n \"request\": \"configure\",\n \"restart\": true\n }\n }).then(function () {\n config.isIceRestarting = false;\n }).catch(function () {\n config.isIceRestarting = false;\n });\n }\n }\n }, {\n key: \"_createAO\",\n value: function _createAO() {\n var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'offer';\n var handleId = arguments.length > 1 ? arguments[1] : undefined;\n var iceRestart = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;\n\n var _ref = arguments.length > 3 ? arguments[3] : undefined,\n _ref2 = _slicedToArray(_ref, 4),\n audioSend = _ref2[0],\n audioRecv = _ref2[1],\n videoSend = _ref2[2],\n videoRecv = _ref2[3];\n\n var handle = this._getHandle(handleId);\n\n if (!handle) {\n return Promise.reject({\n type: 'warning',\n id: 15,\n message: 'id non-existent',\n data: [handleId, 'createAO', type]\n });\n }\n\n var methodName = null;\n\n if (type === 'offer') {\n methodName = 'createOffer';\n } else {\n methodName = 'createAnswer';\n }\n\n var config = handle.webrtcStuff; // https://code.google.com/p/webrtc/issues/detail?id=3508\n\n var mediaConstraints = {};\n\n if (this.isUnifiedPlan) {\n var audioTransceiver = null,\n videoTransceiver = null;\n var transceivers = config.pc.getTransceivers();\n\n if (transceivers && transceivers.length > 0) {\n for (var i in transceivers) {\n var t = transceivers[i];\n\n if (t.sender && t.sender.track && t.sender.track.kind === \"audio\" && t.stopped === false || t.receiver && t.receiver.track && t.receiver.track.kind === \"audio\" && t.stopped === false) {\n if (!audioTransceiver) audioTransceiver = t;\n continue;\n }\n\n if (t.sender && t.sender.track && t.sender.track.kind === \"video\" && t.stopped === false || t.receiver && t.receiver.track && t.receiver.track.kind === \"video\" && t.stopped === false) {\n if (!videoTransceiver) videoTransceiver = t;\n continue;\n }\n }\n } // Handle audio (and related changes, if any)\n\n\n if (!audioSend && !audioRecv) {\n // Audio disabled: have we removed it?\n if (audioTransceiver) {\n if (audioTransceiver.setDirection) {\n audioTransceiver.setDirection(\"inactive\");\n } else {\n audioTransceiver.direction = \"inactive\";\n }\n }\n } else {\n // Take care of audio m-line\n if (audioSend && audioRecv) {\n if (audioTransceiver) {\n if (audioTransceiver.setDirection) {\n audioTransceiver.setDirection(\"sendrecv\");\n } else {\n audioTransceiver.direction = \"sendrecv\";\n }\n }\n } else if (audioSend && !audioRecv) {\n if (audioTransceiver) {\n if (audioTransceiver.setDirection) {\n audioTransceiver.setDirection(\"sendonly\");\n } else {\n audioTransceiver.direction = \"sendonly\";\n }\n }\n } else if (!audioSend && audioRecv) {\n if (audioTransceiver) {\n if (audioTransceiver.setDirection) {\n audioTransceiver.setDirection(\"recvonly\");\n } else {\n audioTransceiver.direction = \"recvonly\";\n }\n } else {\n // In theory, this is the only case where we might not have a transceiver yet\n audioTransceiver = config.pc.addTransceiver(\"audio\", {\n direction: \"recvonly\"\n });\n }\n }\n } // Handle video (and related changes, if any)\n\n\n if (!videoSend && !videoRecv) {\n if (videoTransceiver) {\n if (videoTransceiver.setDirection) {\n videoTransceiver.setDirection(\"inactive\");\n } else {\n videoTransceiver.direction = \"inactive\";\n }\n }\n } else {\n // Take care of video m-line\n if (videoSend && videoRecv) {\n if (videoTransceiver) {\n if (videoTransceiver.setDirection) {\n videoTransceiver.setDirection(\"sendrecv\");\n } else {\n videoTransceiver.direction = \"sendrecv\";\n }\n }\n } else if (videoSend && !videoRecv) {\n if (videoTransceiver) {\n if (videoTransceiver.setDirection) {\n videoTransceiver.setDirection(\"sendonly\");\n } else {\n videoTransceiver.direction = \"sendonly\";\n }\n }\n } else if (!videoSend && videoRecv) {\n if (videoTransceiver) {\n if (videoTransceiver.setDirection) {\n videoTransceiver.setDirection(\"recvonly\");\n } else {\n videoTransceiver.direction = \"recvonly\";\n }\n } else {\n // In theory, this is the only case where we might not have a transceiver yet\n videoTransceiver = config.pc.addTransceiver(\"video\", {\n direction: \"recvonly\"\n });\n }\n }\n }\n } else {\n if (webrtc_adapter__WEBPACK_IMPORTED_MODULE_0__[\"default\"].browserDetails.browser === \"firefox\" || webrtc_adapter__WEBPACK_IMPORTED_MODULE_0__[\"default\"].browserDetails.browser === \"edge\") {\n mediaConstraints = {\n offerToReceiveAudio: audioRecv,\n offerToReceiveVideo: videoRecv\n };\n } else {\n mediaConstraints = {\n mandatory: {\n OfferToReceiveAudio: audioRecv,\n OfferToReceiveVideo: videoRecv\n }\n };\n }\n }\n\n if (iceRestart) {\n mediaConstraints[\"iceRestart\"] = true;\n }\n\n return config.pc[methodName](mediaConstraints).then(function (response) {\n config.mySdp = response.sdp;\n\n var _p = config.pc.setLocalDescription(response).catch(function (e) {\n return Promise.reject({\n type: 'warning',\n id: 24,\n message: 'setLocalDescription',\n data: [handleId, e]\n });\n });\n\n config.mediaConstraints = mediaConstraints;\n\n if (!config.iceDone && !config.trickle) {\n // Don't do anything until we have all candidates\n return Promise.resolve(null);\n } // JSON.stringify doesn't work on some WebRTC objects anymore\n // See https://code.google.com/p/chromium/issues/detail?id=467366\n\n\n var jsep = {\n \"type\": response.type,\n \"sdp\": response.sdp\n };\n return _p.then(function () {\n return jsep;\n });\n }, function (e) {\n return Promise.reject({\n type: 'warning',\n id: 25,\n message: methodName,\n data: [handleId, e]\n });\n });\n }\n }, {\n key: \"_publishRemote\",\n value: function _publishRemote(handleId, jsep) {\n var _this18 = this;\n\n var handle = this._getHandle(handleId);\n\n if (!handle) {\n return Promise.reject({\n type: 'warning',\n id: 15,\n message: 'id non-existent',\n data: [handleId, 'publish remote participant']\n });\n }\n\n this._webrtc(handleId, true);\n\n var config = handle.webrtcStuff;\n\n if (jsep) {\n return config.pc.setRemoteDescription(jsep).then(function () {\n config.remoteSdp = jsep.sdp; // Any trickle candidate we cached?\n\n if (config.candidates && config.candidates.length > 0) {\n for (var i = 0; i < config.candidates.length; i++) {\n var candidate = config.candidates[i];\n\n if (!candidate || candidate.completed === true) {\n // end-of-candidates\n config.pc.addIceCandidate(null);\n } else {\n // New candidate\n config.pc.addIceCandidate(candidate);\n }\n }\n\n config.candidates = [];\n } // Create the answer now\n\n\n return _this18._createAO('answer', handleId, false, [false, true, false, true]).then(function (_jsep) {\n if (!_jsep) {\n _this18.emit('error', {\n type: 'warning',\n id: 19,\n message: 'publish remote participant',\n data: [handleId, 'no jsep']\n });\n\n return Promise.resolve();\n }\n\n return _this18.sendMessage(handleId, {\n \"body\": _objectSpread(_objectSpread({\n \"request\": \"start\"\n }, _this18.roomId && {\n \"room\": _this18.roomId\n }), _this18.pin && {\n pin: _this18.pin\n }),\n \"jsep\": _jsep\n });\n });\n }, function (e) {\n return Promise.reject({\n type: 'warning',\n id: 23,\n message: 'setRemoteDescription',\n data: [handleId, e]\n });\n });\n } else {\n return Promise.resolve();\n }\n } //Public methods\n\n }, {\n key: \"publishLocal\",\n value: function publishLocal(stream) {\n var _this19 = this;\n\n var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},\n _ref3$keepAudio = _ref3.keepAudio,\n keepAudio = _ref3$keepAudio === void 0 ? false : _ref3$keepAudio,\n _ref3$keepVideo = _ref3.keepVideo,\n keepVideo = _ref3$keepVideo === void 0 ? false : _ref3$keepVideo;\n\n this.emit('publishing', true);\n\n var handle = this._getHandle(this.handleId);\n\n if (!handle) {\n return Promise.reject({\n type: 'error',\n id: 21,\n message: 'no local id, connect before publishing',\n data: null\n });\n }\n\n this._webrtc(this.handleId);\n\n var config = handle.webrtcStuff;\n\n if (stream) {\n if (!config.stream) {\n config.stream = stream;\n stream.getTracks().forEach(function (track) {\n config.pc.addTrack(track, stream);\n });\n } else {\n /* UPDATE Audio */\n var replaceAudio = stream.getAudioTracks().length;\n\n if (replaceAudio || !keepAudio) {\n //this will stop existing tracks\n var oldAudioStream = config.stream.getAudioTracks()[0];\n\n if (oldAudioStream) {\n config.stream.removeTrack(oldAudioStream);\n\n try {\n oldAudioStream.stop();\n } catch (e) {\n this._log(e);\n }\n }\n }\n\n if (config.pc.getSenders() && config.pc.getSenders().length) {\n if (replaceAudio && this.isUnifiedPlan) {//using replace\n } else {\n for (var index in config.pc.getSenders()) {\n var s = config.pc.getSenders()[index];\n\n if (s && s.track && s.track.kind === \"audio\") {\n config.pc.removeTrack(s);\n }\n }\n }\n }\n\n if (replaceAudio) {\n config.stream.addTrack(stream.getAudioTracks()[0]);\n var audioTransceiver = null;\n\n if (this.isUnifiedPlan) {\n var transceivers = config.pc.getTransceivers();\n\n if (transceivers && transceivers.length > 0) {\n for (var i in transceivers) {\n var t = transceivers[i];\n\n if (t.sender && t.sender.track && t.sender.track.kind === \"audio\" && t.stopped === false || t.receiver && t.receiver.track && t.receiver.track.kind === \"audio\" && t.stopped === false) {\n audioTransceiver = t;\n break;\n }\n }\n }\n }\n\n if (audioTransceiver && audioTransceiver.sender) {\n audioTransceiver.sender.replaceTrack(stream.getAudioTracks()[0]);\n } else {\n config.pc.addTrack(stream.getAudioTracks()[0], stream);\n }\n }\n /* UPDATE Video */\n\n\n var replaceVideo = stream.getVideoTracks().length;\n\n if (replaceVideo || !keepVideo) {\n var oldVideoStream = config.stream.getVideoTracks()[0];\n\n if (oldVideoStream) {\n config.stream.removeTrack(oldVideoStream);\n\n try {\n oldVideoStream.stop();\n } catch (e) {\n this._log(e);\n }\n }\n }\n\n if (config.pc.getSenders() && config.pc.getSenders().length) {\n if (replaceVideo && this.isUnifiedPlan) {//using replace\n } else {\n for (var _index in config.pc.getSenders()) {\n var _s2 = config.pc.getSenders()[_index];\n\n if (_s2 && _s2.track && _s2.track.kind === \"video\") {\n config.pc.removeTrack(_s2);\n }\n }\n }\n }\n\n if (replaceVideo) {\n config.stream.addTrack(stream.getVideoTracks()[0]);\n var videoTransceiver = null;\n\n if (this.isUnifiedPlan) {\n var _transceivers = config.pc.getTransceivers();\n\n if (_transceivers && _transceivers.length > 0) {\n for (var _i2 in _transceivers) {\n var _t = _transceivers[_i2];\n\n if (_t.sender && _t.sender.track && _t.sender.track.kind === \"video\" && _t.stopped === false || _t.receiver && _t.receiver.track && _t.receiver.track.kind === \"video\" && _t.stopped === false) {\n videoTransceiver = _t;\n break;\n }\n }\n }\n }\n\n if (videoTransceiver && videoTransceiver.sender) {\n //TODO: check if t.stopped === false still gets us videoTransceiver\n videoTransceiver.sender.replaceTrack(stream.getVideoTracks()[0]);\n } else {\n config.pc.addTrack(stream.getVideoTracks()[0], stream);\n }\n }\n }\n }\n\n var hasAudio = !!(stream && stream.getAudioTracks().length > 0);\n var hasVideo = !!(stream && stream.getVideoTracks().length > 0);\n var isAudioMuted = !stream || stream.getAudioTracks().length === 0 || !stream.getAudioTracks()[0].enabled;\n var isVideoMuted = !stream || stream.getVideoTracks().length === 0 || !stream.getVideoTracks()[0].enabled;\n this.isAudioEnabed = hasAudio;\n this.isVideoEnabled = hasVideo;\n this.isAudioMuted = isAudioMuted;\n this.isVideoMuted = isVideoMuted;\n return this._createAO('offer', this.handleId, false, [hasAudio, false, hasVideo, false]).then(function (jsep) {\n if (!jsep) {\n return null;\n } //HOTFIX: Temporary fix for Safari 13\n\n\n if (jsep.sdp && jsep.sdp.indexOf(\"\\r\\na=ice-ufrag\") === -1) {\n jsep.sdp = jsep.sdp.replace(\"\\na=ice-ufrag\", \"\\r\\na=ice-ufrag\");\n }\n\n return _this19.sendMessage(_this19.handleId, {\n body: _objectSpread({\n \"request\": \"configure\",\n \"audio\": hasAudio,\n \"video\": hasVideo,\n \"data\": true\n }, _this19.recordingFilename ? {\n filename: _this19.recordingFilename\n } : {}),\n jsep: jsep\n });\n }).then(function (r) {\n if (_this19._isDataChannelOpen) {\n return Promise.resolve(r);\n } else {\n return new Promise(function (resolve, reject) {\n var __ = function __(val) {\n if (val) {\n clearTimeout(___);\n\n _this19.off('dataChannel', __, _this19);\n\n resolve(_this19);\n }\n };\n\n var ___ = setTimeout(function () {\n _this19.off('dataChannel', __, _this19);\n\n reject({\n type: 'error',\n id: 27,\n message: 'Data channel did not open',\n data: null\n });\n }, 5000);\n\n _this19.on('dataChannel', __, _this19);\n });\n }\n }).then(function (r) {\n _this19._isPublished = true;\n\n _this19.emit('addLocalParticipant', {\n tid: Object(_wt_utils__WEBPACK_IMPORTED_MODULE_2__[\"generateUUID\"])(),\n id: handle.handleId,\n userId: handle.userId,\n stream: config.stream\n });\n\n _this19.emit('published', {\n status: true,\n hasStream: !!config.stream\n });\n\n _this19.emit('publishing', false);\n\n _this19.emit('localHasVideo', hasVideo);\n\n _this19.emit('localHasAudio', hasAudio);\n\n _this19.emit('localMuted', {\n type: 'video',\n value: isVideoMuted\n });\n\n _this19.emit('localMuted', {\n type: 'audio',\n value: isAudioMuted\n });\n\n return r;\n }).catch(function (e) {\n _this19.emit('publishing', false);\n\n return Promise.reject(e);\n });\n }\n }, {\n key: \"unpublishLocal\",\n value: function unpublishLocal() {\n var _this20 = this;\n\n var dontWait = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;\n return this._isPublished ? this.sendMessage(this.handleId, {\n body: {\n \"request\": \"unpublish\"\n }\n }, dontWait).finally(function (r) {\n _this20._isPublished = false;\n\n _this20.emit('published', {\n status: false,\n hasStream: false\n });\n\n return r;\n }) : Promise.resolve();\n }\n }, {\n key: \"toggleAudio\",\n value: function toggleAudio() {\n var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;\n\n var handle = this._getHandle(this.handleId);\n\n if (!handle) {\n return Promise.reject({\n type: 'error',\n id: 21,\n message: 'no local id, connect first',\n data: null\n });\n }\n\n var config = handle.webrtcStuff;\n\n if (this.isUnifiedPlan) {\n var transceiver = config.pc.getTransceivers().find(function (t) {\n return t.sender && t.sender.track && t.receiver.track.kind === \"audio\" && t.stopped === false;\n });\n\n if (transceiver) {\n transceiver.sender.track.enabled = value !== null ? !!value : !transceiver.sender.track.enabled;\n }\n\n this.isAudioMuted = !transceiver || !transceiver.sender.track.enabled;\n } else {\n if (config.stream && config.stream.getAudioTracks().length) {\n config.stream.getAudioTracks()[0].enabled = value !== null ? !!value : !config.stream.getAudioTracks()[0].enabled;\n }\n\n this.isAudioMuted = config.stream.getAudioTracks().length === 0 || !config.stream.getAudioTracks()[0].enabled;\n }\n\n this.emit('localMuted', {\n type: 'audio',\n value: this.isAudioMuted\n });\n }\n }, {\n key: \"toggleVideo\",\n value: function toggleVideo() {\n var handle = this._getHandle(this.handleId);\n\n if (!handle) {\n return Promise.reject({\n type: 'error',\n id: 21,\n message: 'no local id, connect first',\n data: null\n });\n }\n\n var config = handle.webrtcStuff;\n\n if (this.isUnifiedPlan) {\n var transceiver = config.pc.getTransceivers().find(function (t) {\n return t.sender && t.sender.track && t.receiver.track.kind === \"video\" && t.stopped === false;\n });\n\n if (transceiver) {\n transceiver.sender.track.enabled = !transceiver.sender.track.enabled;\n }\n\n this.isVideoMuted = !transceiver || !transceiver.sender.track.enabled;\n } else {\n if (config.stream && config.stream.getVideoTracks().length) {\n config.stream.getVideoTracks()[0].enabled = !config.stream.getVideoTracks()[0].enabled;\n }\n\n this.isVideoMuted = config.stream.getVideoTracks().length === 0 || !config.stream.getVideoTracks()[0].enabled;\n }\n\n this.emit('localMuted', {\n type: 'video',\n value: this.isVideoMuted\n });\n }\n }, {\n key: \"setInstructorId\",\n value: function setInstructorId() {\n var instructorId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;\n this._instuctorId = instructorId;\n this.emit('instructorId', this._instuctorId);\n return this._instuctorId;\n }\n }, {\n key: \"setObserverIds\",\n value: function setObserverIds() {\n var observerIds = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];\n this._observerIds = observerIds;\n this.emit('observerIds', this._observerIds);\n return this._observerIds;\n }\n }, {\n key: \"setTalkbackIds\",\n value: function setTalkbackIds() {\n var talkbackIds = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];\n this._talkbackIds = talkbackIds;\n this.emit('talkbackIds', this._talkbackIds);\n return this._talkbackIds;\n }\n }], [{\n key: \"noop\",\n value: function noop() {}\n }, {\n key: \"randomString\",\n value: function randomString(len) {\n var charSet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';\n var randomString = '';\n\n for (var i = 0; i < len; i++) {\n var randomPoz = Math.floor(Math.random() * charSet.length);\n randomString += charSet.substring(randomPoz, randomPoz + 1);\n }\n\n return randomString;\n } //TODO: solve\n // #eventList = ['error', 'kicked', 'addLocalParticipant', ,'addRemoteInstructor','addRemoteParticipant','addRemoteTalkback', 'addRemoteObserver', 'removeRemoteInstructor', 'removeLocalParticipant', 'removeRemoteParticipant', 'removeRemoteTalkback', 'removeRemoteObserver', 'localMuted', 'localHasVideo', 'localHasAudio', 'data', 'iceState', 'connectionState', 'joined', 'joining', 'dataChannel', 'disconnect', 'observerIds', 'talkbackIds', 'instructorId', 'published', 'publishing', 'remoteTrackMuted', 'streamingStatus', 'streaming', 'streamStarting'];\n //\n\n }, {\n key: \"checkUnifiedPlan\",\n value: function checkUnifiedPlan() {\n var unifiedPlan = false;\n\n if (webrtc_adapter__WEBPACK_IMPORTED_MODULE_0__[\"default\"].browserDetails.browser === 'firefox' && webrtc_adapter__WEBPACK_IMPORTED_MODULE_0__[\"default\"].browserDetails.version >= 59) {\n // Firefox definitely does, starting from version 59\n unifiedPlan = true;\n } else if (webrtc_adapter__WEBPACK_IMPORTED_MODULE_0__[\"default\"].browserDetails.browser === 'chrome' && webrtc_adapter__WEBPACK_IMPORTED_MODULE_0__[\"default\"].browserDetails.version >= 72) {\n // Chrome does, but it's only usable from version 72 on\n unifiedPlan = true;\n } else if (!window.RTCRtpTransceiver || !('currentDirection' in RTCRtpTransceiver.prototype)) {\n // Safari supports addTransceiver() but not Unified Plan when\n // currentDirection is not defined (see codepen above).\n unifiedPlan = false;\n } else {\n // Check if addTransceiver() throws an exception\n var tempPc = new RTCPeerConnection();\n\n try {\n tempPc.addTransceiver('audio');\n unifiedPlan = true;\n } catch (e) {}\n\n tempPc.close();\n }\n\n return unifiedPlan;\n }\n }]);\n\n return RoomSession;\n}();\n\n_defineProperty(RoomSession, \"sessionTypes\", {\n 'reactooroom': 'janus.plugin.reactooroom',\n 'streaming': 'janus.plugin.streaming'\n});\n\n_defineProperty(RoomSession, \"subscriptionRules\", {\n participant: {\n watchTogether: ['participant', 'talkback'],\n videoWall: ['instructor', 'observer', 'talkback']\n },\n monitor: {\n watchTogether: ['participant'],\n videoWall: ['instructor', 'participant']\n },\n talkback: {\n watchTogether: ['participant'],\n videoWall: ['instructor', 'participant']\n },\n observer: {\n watchTogether: ['participant'],\n videoWall: ['participant']\n },\n instructor: {\n watchTogether: [],\n videoWall: []\n }\n});\n\n/* harmony default export */ __webpack_exports__[\"default\"] = (Room);\n\n//# sourceURL=webpack://WatchTogetherSDK/./src/modules/wt-room.js?");
8574
8574
 
8575
8575
  /***/ }),
8576
8576