@reactoo/watchtogether-sdk-js 2.4.34 → 2.4.41

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.4.34
3
+ * @version 2.4.41
4
4
  */
5
5
  (function webpackUniversalModuleDefinition(root, factory) {
6
6
  if(typeof exports === 'object' && typeof module === 'object')
@@ -9229,7 +9229,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n\n\nfunction _toConsumableArr
9229
9229
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
9230
9230
 
9231
9231
  "use strict";
9232
- eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _modules_wt_utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../modules/wt-utils */ \"./src/modules/wt-utils.js\");\n/* harmony import */ var _modules_wt_emitter__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../modules/wt-emitter */ \"./src/modules/wt-emitter.js\");\n/* harmony import */ var _modules_sync_modules_sync_hls__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../modules/sync-modules/sync-hls */ \"./src/modules/sync-modules/sync-hls.js\");\n/* harmony import */ var _modules_sync_modules_sync_hls_vod__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../modules/sync-modules/sync-hls-vod */ \"./src/modules/sync-modules/sync-hls-vod.js\");\n/* harmony import */ var _modules_sync_modules_sync_native_hls_vod__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../modules/sync-modules/sync-native-hls-vod */ \"./src/modules/sync-modules/sync-native-hls-vod.js\");\n/* harmony import */ var _modules_sync_modules_sync_native_hls__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../modules/sync-modules/sync-native-hls */ \"./src/modules/sync-modules/sync-native-hls.js\");\n/* harmony import */ var _modules_sync_modules_sync_shaka_dash__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../modules/sync-modules/sync-shaka-dash */ \"./src/modules/sync-modules/sync-shaka-dash.js\");\n/* harmony import */ var _modules_sync_modules_sync_shaka_dash_vod__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../modules/sync-modules/sync-shaka-dash-vod */ \"./src/modules/sync-modules/sync-shaka-dash-vod.js\");\n/* harmony import */ var _modules_sync_modules_sync_dash__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../modules/sync-modules/sync-dash */ \"./src/modules/sync-modules/sync-dash.js\");\n/* harmony import */ var _modules_sync_modules_sync_dash_vod__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../modules/sync-modules/sync-dash-vod */ \"./src/modules/sync-modules/sync-dash-vod.js\");\n/* harmony import */ var _modules_sync_modules_sync_doris__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../modules/sync-modules/sync-doris */ \"./src/modules/sync-modules/sync-doris.js\");\n/* harmony import */ var _modules_sync_modules_sync_disabled__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../modules/sync-modules/sync-disabled */ \"./src/modules/sync-modules/sync-disabled.js\");\n/* harmony import */ var _modules_sync_modules_sync_dazn_dash__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ../modules/sync-modules/sync-dazn-dash */ \"./src/modules/sync-modules/sync-dazn-dash.js\");\n/* harmony import */ var _modules_sync_modules_sync_universal__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ../modules/sync-modules/sync-universal */ \"./src/modules/sync-modules/sync-universal.js\");\n\n\nfunction ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (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 = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { 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 _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 _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 _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }\n\nfunction _nonIterableSpread() { throw new TypeError(\"Invalid attempt to spread 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 _iterableToArray(iter) { if (typeof Symbol !== \"undefined\" && iter[Symbol.iterator] != null || iter[\"@@iterator\"] != null) return Array.from(iter); }\n\nfunction _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }\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\n\n // SYNCHRONISATION MODULES\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nvar roomSession = function roomSession(_ref, room, wt) {\n var _this4 = this;\n\n var roomId = _ref.roomId,\n pinHash = _ref.pinHash,\n isTalkback = _ref.isTalkback,\n isMonitor = _ref.isMonitor,\n isInstructor = _ref.isInstructor;\n var publicCustomEvents = ['changePlayerSource', 'chatMessage', 'userUpdate', 'reconnecting', 'connecting', 'remoteMuted', 'scaling'];\n\n var addEvents = function addEvents(events) {\n publicCustomEvents = [].concat(_toConsumableArray(publicCustomEvents), _toConsumableArray(events));\n };\n\n var removeEvents = function removeEvents(events) {\n publicCustomEvents = publicCustomEvents.filter(function (ev) {\n return events.indexOf(ev) === -1;\n });\n };\n\n var emitter = Object(_modules_wt_emitter__WEBPACK_IMPORTED_MODULE_1__[\"default\"])();\n\n var alpTimeoutId = null;\n var publishRetry = 0;\n var maxPublishRetry = 3;\n\n var ___; // return object\n\n\n room.on('addLocalParticipant', function () {\n // TODO: this timeout is a hotfix and should be sorted differently\n // At some random case we don't get message back if we don't wait\n clearTimeout(alpTimeoutId);\n alpTimeoutId = setTimeout(function () {\n ___.__requestMuteStatus();\n }, 1000);\n });\n room.on('localMuted', function (_ref2) {\n var type = _ref2.type,\n value = _ref2.value;\n\n ___.sendSystemMessage('remote_muted', {\n type: type,\n value: value\n });\n });\n room.on('data', function (data) {\n ___.__parseDataEvents(data);\n });\n return ___ = {\n syncModule: null,\n playerInterface: null,\n destroy: function destroy() {\n var _this = this;\n\n clearTimeout(alpTimeoutId);\n this.detachPlayer();\n return wt.room.destroySession(room.constructId).finally(function () {\n _this.$clear();\n });\n },\n iceRestart: function iceRestart() {\n return room._iceRestart(room.handleId);\n },\n connect: function connect() {\n var _this2 = this;\n\n emitter.emit('connecting', true);\n clearTimeout(alpTimeoutId);\n return Promise.all([wt.room.__joinRoom({\n roomId: roomId,\n pinHash: pinHash,\n isTalkback: isTalkback,\n isMonitor: isMonitor,\n isInstructor: isInstructor\n }), wt.user.getUserSelf()]).then(function (_ref3) {\n var _ref4 = _slicedToArray(_ref3, 2),\n roomData = _ref4[0],\n userData = _ref4[1];\n\n return Promise.all([roomData, userData, _this2.setRoomVars()]);\n }).then(function (_ref5) {\n var _ref6 = _slicedToArray(_ref5, 3),\n roomData = _ref6[0],\n userData = _ref6[1],\n _ = _ref6[2];\n\n return room.connect(roomData.data.roomId, roomData.data.pin, roomData.data.href, roomData.data.iceServers, roomData.data.accessToken, isMonitor || isInstructor || isTalkback ? roomData.data.userId : userData.data._id, roomData.data.webrtcVersion, roomData.data.bitrate ? parseInt(roomData.data.bitrate) : 0, isMonitor, roomData.data.recordingFilename);\n }).finally(function () {\n emitter.emit('connecting', false);\n });\n },\n disconnect: function disconnect(dontWaitForResponses) {\n clearTimeout(alpTimeoutId);\n return room.disconnect(dontWaitForResponses);\n },\n //TODO: refactor restart method\n restart: function restart(reason) {\n var _this3 = this;\n\n var forceCurrentStream = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;\n var isObserver = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;\n emitter.emit('reconnecting', true);\n room.isRestarting = true;\n var wasPublished = room._isPublished;\n\n var handle = room._getHandle(room.handleId);\n\n var stream = null;\n\n if (handle && handle.webrtcStuff && (wasPublished || forceCurrentStream)) {\n stream = handle.webrtcStuff.stream;\n }\n\n return this.disconnect().then(function () {\n return Object(_modules_wt_utils__WEBPACK_IMPORTED_MODULE_0__[\"wait\"])(1000);\n }) //TODO: remove 1000ms wait by waiting for proper events from janus\n .then(function () {\n return _this3.connect();\n }).then(function () {\n if (isObserver) {\n return _this3.publishLocal(null, {\n getStreamIfEmpty: false,\n unpublishFirst: true\n });\n } else if (stream) {\n return _this3.publishLocal(stream);\n } else return Promise.resolve();\n }).then(function () {\n room.isRestarting = false;\n emitter.emit('reconnecting', false);\n return 1;\n }).catch(function (error) {\n room.isRestarting = false;\n emitter.emit('reconnecting', false);\n emitter.emit('error', {\n type: 'error',\n id: 26,\n message: 'reconnecting failed',\n data: error\n });\n return Promise.reject(0);\n });\n },\n getStats: function getStats() {\n var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;\n return room._getStats(type);\n },\n getRoomParticipants: function getRoomParticipants() {\n return room._participants;\n },\n __parseDataEvents: function __parseDataEvents() {\n var msg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n\n if (msg.videoroom === 'message') {\n if (msg.action === 'pending_shutdown' || msg.action === 'shutting_down') {\n emitter.emit('scaling');\n this.restart('scaling'); // current videoroom was reassigned to a different WebRTC instance\n } else if (msg.action === 'force_restart') {\n this.restart('force');\n } else if (msg.action === 'user_update_displayname' || msg.action === 'user_update_avatar' || msg.action === 'user_update_customattributes' || msg.action === 'user_update_privateattributes') {\n emitter.emit('userUpdate', msg.text);\n } else if (msg.action === 'observer_connecting' || msg.action === 'talkback_connecting' || msg.action === 'instructor_connecting') {\n this.setRoomVars(null, msg.action === 'observer_connecting').catch(function (e) {\n room._log('Setting observers failed, this will cause issues', e);\n });\n } else if (msg.action === 'bitrate_changed') {\n this.setBitrateCap(msg.text);\n } else if (msg.user_action === 'chat_message') {\n emitter.emit('chatMessage', msg);\n } else if (msg.user_action === 'remote_muted') {\n if (msg.from !== room.userId) {\n emitter.emit('remoteMuted', _objectSpread({\n userId: msg.from\n }, msg.text && JSON.parse(msg.text)));\n }\n } else if (msg.user_action === 'remote_muted_request') {\n if (msg.from !== room.userId) {\n this.__sendMuteStatus();\n }\n }\n }\n },\n renderPlayer: function renderPlayer(playerWrapper, fullscreenElement, roomId) {\n this.syncModule = Object(_modules_sync_modules_sync_universal__WEBPACK_IMPORTED_MODULE_13__[\"default\"])({\n room: room,\n wt: wt,\n roomSession: this,\n emitter: emitter\n });\n this.playerInterface = wt.__privates.playerFactory(playerWrapper, fullscreenElement, this.syncModule.getHandlers(), {\n roomId: roomId\n });\n this.syncModule.initialize({\n playerInterface: this.playerInterface\n });\n },\n attachPlayer: function attachPlayer(type, inputs) {\n this.detachPlayer();\n\n if (type === 'hlsjs') {\n this.syncModule = Object(_modules_sync_modules_sync_hls__WEBPACK_IMPORTED_MODULE_2__[\"default\"])({\n room: room,\n wt: wt,\n roomSession: this,\n emitter: emitter\n });\n\n if (this.syncModule.__events) {\n addEvents(this.syncModule.__events);\n }\n\n this.syncModule.initialize(inputs);\n } else if (type === 'hlsjs-vod') {\n this.syncModule = Object(_modules_sync_modules_sync_hls_vod__WEBPACK_IMPORTED_MODULE_3__[\"default\"])({\n room: room,\n wt: wt,\n roomSession: this,\n emitter: emitter\n });\n\n if (this.syncModule.__events) {\n addEvents(this.syncModule.__events);\n }\n\n this.syncModule.initialize(inputs);\n } else if (type === 'hlsnative-vod') {\n this.syncModule = Object(_modules_sync_modules_sync_native_hls_vod__WEBPACK_IMPORTED_MODULE_4__[\"default\"])({\n room: room,\n wt: wt,\n roomSession: this,\n emitter: emitter\n });\n\n if (this.syncModule.__events) {\n addEvents(this.syncModule.__events);\n }\n\n this.syncModule.initialize(inputs);\n } else if (type === 'hlsnative') {\n this.syncModule = Object(_modules_sync_modules_sync_native_hls__WEBPACK_IMPORTED_MODULE_5__[\"default\"])({\n room: room,\n wt: wt,\n roomSession: this,\n emitter: emitter\n });\n\n if (this.syncModule.__events) {\n addEvents(this.syncModule.__events);\n }\n\n this.syncModule.initialize(inputs);\n } else if (type === 'shaka-dash-vod') {\n this.syncModule = Object(_modules_sync_modules_sync_shaka_dash_vod__WEBPACK_IMPORTED_MODULE_7__[\"default\"])({\n room: room,\n wt: wt,\n roomSession: this,\n emitter: emitter\n });\n\n if (this.syncModule.__events) {\n addEvents(this.syncModule.__events);\n }\n\n this.syncModule.initialize(inputs);\n } else if (type === 'shaka-dash') {\n this.syncModule = Object(_modules_sync_modules_sync_shaka_dash__WEBPACK_IMPORTED_MODULE_6__[\"default\"])({\n room: room,\n wt: wt,\n roomSession: this,\n emitter: emitter\n });\n\n if (this.syncModule.__events) {\n addEvents(this.syncModule.__events);\n }\n\n this.syncModule.initialize(inputs);\n } else if (type === 'dashjs') {\n this.syncModule = Object(_modules_sync_modules_sync_dash__WEBPACK_IMPORTED_MODULE_8__[\"default\"])({\n room: room,\n wt: wt,\n roomSession: this,\n emitter: emitter\n });\n\n if (this.syncModule.__events) {\n addEvents(this.syncModule.__events);\n }\n\n this.syncModule.initialize(inputs);\n } else if (type === 'dashjs-vod') {\n this.syncModule = Object(_modules_sync_modules_sync_dash_vod__WEBPACK_IMPORTED_MODULE_9__[\"default\"])({\n room: room,\n wt: wt,\n roomSession: this,\n emitter: emitter\n });\n\n if (this.syncModule.__events) {\n addEvents(this.syncModule.__events);\n }\n\n this.syncModule.initialize(inputs);\n } else if (type === 'doris') {\n this.syncModule = Object(_modules_sync_modules_sync_doris__WEBPACK_IMPORTED_MODULE_10__[\"default\"])({\n room: room,\n wt: wt,\n roomSession: this,\n emitter: emitter\n });\n\n if (this.syncModule.__events) {\n addEvents(this.syncModule.__events);\n }\n\n this.syncModule.initialize(inputs);\n } else if (type === 'dazn-dash') {\n this.syncModule = Object(_modules_sync_modules_sync_dazn_dash__WEBPACK_IMPORTED_MODULE_12__[\"default\"])({\n room: room,\n wt: wt,\n roomSession: this,\n emitter: emitter\n });\n\n if (this.syncModule.__events) {\n addEvents(this.syncModule.__events);\n }\n\n this.syncModule.initialize(inputs);\n } else if (type === 'disabled') {\n this.syncModule = Object(_modules_sync_modules_sync_disabled__WEBPACK_IMPORTED_MODULE_11__[\"default\"])({\n room: room,\n wt: wt,\n roomSession: this,\n emitter: emitter\n });\n\n if (this.syncModule.__events) {\n addEvents(this.syncModule.__events);\n }\n\n this.syncModule.initialize(inputs);\n } else {\n room._log('Synchronisation type not recognised');\n }\n },\n detachPlayer: function detachPlayer() {\n if (this.syncModule) {\n this.playerInterface = null;\n this.syncModule.destroy();\n\n if (this.syncModule.__events) {\n removeEvents(this.syncModule.__events);\n }\n\n this.syncModule = null;\n }\n },\n setRoomVars: function setRoomVars() {\n var observerIds = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];\n var emit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;\n return wt.room.getRoomById(roomId, pinHash).then(function (r) {\n var _r$data$classroom;\n\n if (emit) {\n // emiting \"fake\" playerSource event\n //TODO: somehow push into sync modules instead\n emitter.emit('changePlayerSource', r.data.wtChannelId, true);\n } // setting observers userId's so we can ignore them when creating participant\n\n\n room.setObserverIds(r.data.allowedObservers);\n room.setTalkbackIds(r.data.allowedTalkbacks);\n room.setInstructorId((_r$data$classroom = r.data.classroom) === null || _r$data$classroom === void 0 ? void 0 : _r$data$classroom.instructorUserId);\n });\n },\n publishLocal: function publishLocal() {\n var stream = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;\n\n var _ref7 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},\n _ref7$keepAudio = _ref7.keepAudio,\n keepAudio = _ref7$keepAudio === void 0 ? false : _ref7$keepAudio,\n _ref7$keepVideo = _ref7.keepVideo,\n keepVideo = _ref7$keepVideo === void 0 ? false : _ref7$keepVideo,\n _ref7$getStreamIfEmpt = _ref7.getStreamIfEmpty,\n getStreamIfEmpty = _ref7$getStreamIfEmpt === void 0 ? true : _ref7$getStreamIfEmpt,\n _ref7$askVideo = _ref7.askVideo,\n askVideo = _ref7$askVideo === void 0 ? true : _ref7$askVideo;\n\n return stream || !getStreamIfEmpty ? room.publishLocal(stream, {\n keepAudio: keepAudio,\n keepVideo: keepVideo\n }) : wt.utils.getUserStream(askVideo).then(function (stream) {\n return room.publishLocal(stream);\n });\n },\n unpublishLocal: function unpublishLocal() {\n return room.unpublishLocal();\n },\n toggleAudio: function toggleAudio(value) {\n return room.toggleAudio(value);\n },\n toggleVideo: function toggleVideo() {\n return room.toggleVideo();\n },\n setBitrateCap: function setBitrateCap(bitrate) {\n if (isInstructor) {\n return;\n }\n\n return room.sendMessage(room.handleId, {\n \"body\": {\n \"request\": \"configure\",\n \"bitrate\": parseInt(bitrate)\n }\n }).catch(function (e) {\n return null;\n });\n },\n switchChannel: function switchChannel(channelId) {\n return room.sendMessage(room.handleId, {\n body: {\n request: \"sync_source_set\",\n room: room.roomId,\n timestamp: new Date().getTime(),\n wt_channel_id: channelId,\n fragment: \"0\",\n fragment_pos: 0\n }\n });\n },\n sendSystemMessage: function sendSystemMessage(action) {\n var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n var to = arguments.length > 2 ? arguments[2] : undefined;\n var set_master = arguments.length > 3 ? arguments[3] : undefined;\n return room.sendMessage(room.handleId, {\n body: _objectSpread(_objectSpread({\n action: action,\n request: \"message\",\n room: room.roomId,\n timestamp: new Date().getTime(),\n text: JSON.stringify(value)\n }, to && Array.isArray(to) ? {\n tos: to\n } : {\n to: to\n }), set_master && {\n set_master: set_master\n })\n });\n },\n sendChatMessage: function sendChatMessage(text, to) {\n return room.sendMessage(room.handleId, {\n body: _objectSpread({\n action: \"chat_message\",\n request: \"message\",\n room: room.roomId,\n timestamp: new Date().getTime(),\n text: text\n }, to && Array.isArray(to) ? {\n tos: to\n } : {\n to: to\n })\n });\n },\n __requestMuteStatus: function __requestMuteStatus() {\n this.sendSystemMessage('remote_muted_request');\n },\n __sendMuteStatus: function __sendMuteStatus() {\n this.sendSystemMessage('remote_muted', {\n type: 'video',\n value: room.isVideoMuted\n });\n this.sendSystemMessage('remote_muted', {\n type: 'audio',\n value: room.isAudioMuted\n });\n },\n $on: function $on(key, callback, that) {\n emitter.on(key, callback, that || _this4);\n room.on(key, callback, that || _this4);\n },\n $off: function $off(key, callback, that) {\n emitter.on(key, callback, that || _this4);\n room.on(key, callback, that || _this4);\n },\n $clear: function $clear() {\n room.clear();\n emitter.clear();\n }\n };\n};\n\n/* harmony default export */ __webpack_exports__[\"default\"] = (roomSession);\n\n//# sourceURL=webpack://WatchTogetherSDK/./src/models/room-session.js?");
9232
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _modules_wt_utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../modules/wt-utils */ \"./src/modules/wt-utils.js\");\n/* harmony import */ var _modules_wt_emitter__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../modules/wt-emitter */ \"./src/modules/wt-emitter.js\");\n/* harmony import */ var _modules_sync_modules_sync_hls__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../modules/sync-modules/sync-hls */ \"./src/modules/sync-modules/sync-hls.js\");\n/* harmony import */ var _modules_sync_modules_sync_hls_vod__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../modules/sync-modules/sync-hls-vod */ \"./src/modules/sync-modules/sync-hls-vod.js\");\n/* harmony import */ var _modules_sync_modules_sync_native_hls_vod__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../modules/sync-modules/sync-native-hls-vod */ \"./src/modules/sync-modules/sync-native-hls-vod.js\");\n/* harmony import */ var _modules_sync_modules_sync_native_hls__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../modules/sync-modules/sync-native-hls */ \"./src/modules/sync-modules/sync-native-hls.js\");\n/* harmony import */ var _modules_sync_modules_sync_shaka_dash__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../modules/sync-modules/sync-shaka-dash */ \"./src/modules/sync-modules/sync-shaka-dash.js\");\n/* harmony import */ var _modules_sync_modules_sync_shaka_dash_vod__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../modules/sync-modules/sync-shaka-dash-vod */ \"./src/modules/sync-modules/sync-shaka-dash-vod.js\");\n/* harmony import */ var _modules_sync_modules_sync_dash__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../modules/sync-modules/sync-dash */ \"./src/modules/sync-modules/sync-dash.js\");\n/* harmony import */ var _modules_sync_modules_sync_dash_vod__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../modules/sync-modules/sync-dash-vod */ \"./src/modules/sync-modules/sync-dash-vod.js\");\n/* harmony import */ var _modules_sync_modules_sync_doris__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../modules/sync-modules/sync-doris */ \"./src/modules/sync-modules/sync-doris.js\");\n/* harmony import */ var _modules_sync_modules_sync_disabled__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../modules/sync-modules/sync-disabled */ \"./src/modules/sync-modules/sync-disabled.js\");\n/* harmony import */ var _modules_sync_modules_sync_dazn_dash__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ../modules/sync-modules/sync-dazn-dash */ \"./src/modules/sync-modules/sync-dazn-dash.js\");\n/* harmony import */ var _modules_sync_modules_sync_universal__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ../modules/sync-modules/sync-universal */ \"./src/modules/sync-modules/sync-universal.js\");\n\n\nfunction ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (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 = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { 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 _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 _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 _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }\n\nfunction _nonIterableSpread() { throw new TypeError(\"Invalid attempt to spread 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 _iterableToArray(iter) { if (typeof Symbol !== \"undefined\" && iter[Symbol.iterator] != null || iter[\"@@iterator\"] != null) return Array.from(iter); }\n\nfunction _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }\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\n\n // SYNCHRONISATION MODULES\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nvar roomSession = function roomSession(_ref, room, wt) {\n var _this4 = this;\n\n var roomId = _ref.roomId,\n pinHash = _ref.pinHash,\n isTalkback = _ref.isTalkback,\n isMonitor = _ref.isMonitor,\n isInstructor = _ref.isInstructor;\n var publicCustomEvents = ['changePlayerSource', 'chatMessage', 'userUpdate', 'reconnecting', 'connecting', 'remoteMuted', 'scaling'];\n\n var addEvents = function addEvents(events) {\n publicCustomEvents = [].concat(_toConsumableArray(publicCustomEvents), _toConsumableArray(events));\n };\n\n var removeEvents = function removeEvents(events) {\n publicCustomEvents = publicCustomEvents.filter(function (ev) {\n return events.indexOf(ev) === -1;\n });\n };\n\n var emitter = Object(_modules_wt_emitter__WEBPACK_IMPORTED_MODULE_1__[\"default\"])();\n\n var alpTimeoutId = null;\n\n var ___; // return object\n\n\n room.on('addLocalParticipant', function () {\n // TODO: this timeout is a hotfix and should be sorted differently\n // At some random case we don't get message back if we don't wait\n clearTimeout(alpTimeoutId);\n alpTimeoutId = setTimeout(function () {\n ___.__requestMuteStatus();\n }, 1000);\n });\n room.on('localMuted', function (_ref2) {\n var type = _ref2.type,\n value = _ref2.value;\n\n ___.sendSystemMessage('remote_muted', {\n type: type,\n value: value\n });\n });\n room.on('data', function (data) {\n ___.__parseDataEvents(data);\n });\n return ___ = {\n syncModule: null,\n playerInterface: null,\n destroy: function destroy() {\n var _this = this;\n\n clearTimeout(alpTimeoutId);\n this.detachPlayer();\n return wt.room.destroySession(room.constructId).finally(function () {\n _this.$clear();\n });\n },\n iceRestart: function iceRestart() {\n return room._iceRestart(room.handleId);\n },\n connect: function connect() {\n var _this2 = this;\n\n emitter.emit('connecting', true);\n clearTimeout(alpTimeoutId);\n return Promise.all([wt.room.__joinRoom({\n roomId: roomId,\n pinHash: pinHash,\n isTalkback: isTalkback,\n isMonitor: isMonitor,\n isInstructor: isInstructor\n }), wt.user.getUserSelf()]).then(function (_ref3) {\n var _ref4 = _slicedToArray(_ref3, 2),\n roomData = _ref4[0],\n userData = _ref4[1];\n\n return Promise.all([roomData, userData, _this2.setRoomVars()]);\n }).then(function (_ref5) {\n var _ref6 = _slicedToArray(_ref5, 3),\n roomData = _ref6[0],\n userData = _ref6[1],\n _ = _ref6[2];\n\n return room.connect(roomData.data.roomId, roomData.data.pin, roomData.data.href, roomData.data.iceServers, roomData.data.accessToken, isMonitor || isInstructor || isTalkback ? roomData.data.userId : userData.data._id, roomData.data.webrtcVersion, roomData.data.bitrate ? parseInt(roomData.data.bitrate) : 0, isMonitor, roomData.data.recordingFilename);\n }).finally(function () {\n emitter.emit('connecting', false);\n });\n },\n disconnect: function disconnect(dontWaitForResponses) {\n clearTimeout(alpTimeoutId);\n return room.disconnect(dontWaitForResponses);\n },\n //TODO: refactor restart method\n restart: function restart(reason) {\n var _this3 = this;\n\n var forceCurrentStream = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;\n var isObserver = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;\n emitter.emit('reconnecting', true);\n room.isRestarting = true;\n var wasPublished = room._isPublished;\n\n var handle = room._getHandle(room.handleId);\n\n var stream = null;\n\n if (handle && handle.webrtcStuff && (wasPublished || forceCurrentStream)) {\n stream = handle.webrtcStuff.stream;\n }\n\n return this.disconnect().then(function () {\n return Object(_modules_wt_utils__WEBPACK_IMPORTED_MODULE_0__[\"wait\"])(1000);\n }) //TODO: remove 1000ms wait by waiting for proper events from janus\n .then(function () {\n return _this3.connect();\n }).then(function () {\n if (isObserver) {\n return _this3.publishLocal(null, {\n getStreamIfEmpty: false,\n unpublishFirst: true\n });\n } else if (stream) {\n return _this3.publishLocal(stream);\n } else return Promise.resolve();\n }).then(function () {\n room.isRestarting = false;\n emitter.emit('reconnecting', false);\n return 1;\n }).catch(function (error) {\n room.isRestarting = false;\n emitter.emit('reconnecting', false);\n emitter.emit('error', {\n type: 'error',\n id: 26,\n message: 'reconnecting failed',\n data: error\n });\n return Promise.reject(0);\n });\n },\n getStats: function getStats() {\n var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;\n return room._getStats(type);\n },\n getRoomParticipants: function getRoomParticipants() {\n return room._participants;\n },\n __parseDataEvents: function __parseDataEvents() {\n var msg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n\n if (msg.videoroom === 'message') {\n if (msg.action === 'pending_shutdown' || msg.action === 'shutting_down') {\n emitter.emit('scaling');\n this.restart('scaling'); // current videoroom was reassigned to a different WebRTC instance\n } else if (msg.action === 'force_restart') {\n this.restart('force');\n } else if (msg.action === 'user_update_displayname' || msg.action === 'user_update_avatar' || msg.action === 'user_update_customattributes' || msg.action === 'user_update_privateattributes') {\n emitter.emit('userUpdate', msg.text);\n } else if (msg.action === 'observer_connecting' || msg.action === 'talkback_connecting' || msg.action === 'instructor_connecting') {\n this.setRoomVars(null, msg.action === 'observer_connecting').catch(function (e) {\n room._log('Setting observers failed, this will cause issues', e);\n });\n } else if (msg.action === 'bitrate_changed') {\n this.setBitrateCap(msg.text);\n } else if (msg.user_action === 'chat_message') {\n emitter.emit('chatMessage', msg);\n } else if (msg.user_action === 'remote_muted') {\n if (msg.from !== room.userId) {\n emitter.emit('remoteMuted', _objectSpread({\n userId: msg.from\n }, msg.text && JSON.parse(msg.text)));\n }\n } else if (msg.user_action === 'remote_muted_request') {\n if (msg.from !== room.userId) {\n this.__sendMuteStatus();\n }\n }\n }\n },\n renderPlayer: function renderPlayer(playerWrapper, fullscreenElement, roomId) {\n this.syncModule = Object(_modules_sync_modules_sync_universal__WEBPACK_IMPORTED_MODULE_13__[\"default\"])({\n room: room,\n wt: wt,\n roomSession: this,\n emitter: emitter\n });\n this.playerInterface = wt.__privates.playerFactory(playerWrapper, fullscreenElement, this.syncModule.getHandlers(), {\n roomId: roomId\n });\n this.syncModule.initialize({\n playerInterface: this.playerInterface\n });\n },\n attachPlayer: function attachPlayer(type, inputs) {\n this.detachPlayer();\n\n if (type === 'hlsjs') {\n this.syncModule = Object(_modules_sync_modules_sync_hls__WEBPACK_IMPORTED_MODULE_2__[\"default\"])({\n room: room,\n wt: wt,\n roomSession: this,\n emitter: emitter\n });\n\n if (this.syncModule.__events) {\n addEvents(this.syncModule.__events);\n }\n\n this.syncModule.initialize(inputs);\n } else if (type === 'hlsjs-vod') {\n this.syncModule = Object(_modules_sync_modules_sync_hls_vod__WEBPACK_IMPORTED_MODULE_3__[\"default\"])({\n room: room,\n wt: wt,\n roomSession: this,\n emitter: emitter\n });\n\n if (this.syncModule.__events) {\n addEvents(this.syncModule.__events);\n }\n\n this.syncModule.initialize(inputs);\n } else if (type === 'hlsnative-vod') {\n this.syncModule = Object(_modules_sync_modules_sync_native_hls_vod__WEBPACK_IMPORTED_MODULE_4__[\"default\"])({\n room: room,\n wt: wt,\n roomSession: this,\n emitter: emitter\n });\n\n if (this.syncModule.__events) {\n addEvents(this.syncModule.__events);\n }\n\n this.syncModule.initialize(inputs);\n } else if (type === 'hlsnative') {\n this.syncModule = Object(_modules_sync_modules_sync_native_hls__WEBPACK_IMPORTED_MODULE_5__[\"default\"])({\n room: room,\n wt: wt,\n roomSession: this,\n emitter: emitter\n });\n\n if (this.syncModule.__events) {\n addEvents(this.syncModule.__events);\n }\n\n this.syncModule.initialize(inputs);\n } else if (type === 'shaka-dash-vod') {\n this.syncModule = Object(_modules_sync_modules_sync_shaka_dash_vod__WEBPACK_IMPORTED_MODULE_7__[\"default\"])({\n room: room,\n wt: wt,\n roomSession: this,\n emitter: emitter\n });\n\n if (this.syncModule.__events) {\n addEvents(this.syncModule.__events);\n }\n\n this.syncModule.initialize(inputs);\n } else if (type === 'shaka-dash') {\n this.syncModule = Object(_modules_sync_modules_sync_shaka_dash__WEBPACK_IMPORTED_MODULE_6__[\"default\"])({\n room: room,\n wt: wt,\n roomSession: this,\n emitter: emitter\n });\n\n if (this.syncModule.__events) {\n addEvents(this.syncModule.__events);\n }\n\n this.syncModule.initialize(inputs);\n } else if (type === 'dashjs') {\n this.syncModule = Object(_modules_sync_modules_sync_dash__WEBPACK_IMPORTED_MODULE_8__[\"default\"])({\n room: room,\n wt: wt,\n roomSession: this,\n emitter: emitter\n });\n\n if (this.syncModule.__events) {\n addEvents(this.syncModule.__events);\n }\n\n this.syncModule.initialize(inputs);\n } else if (type === 'dashjs-vod') {\n this.syncModule = Object(_modules_sync_modules_sync_dash_vod__WEBPACK_IMPORTED_MODULE_9__[\"default\"])({\n room: room,\n wt: wt,\n roomSession: this,\n emitter: emitter\n });\n\n if (this.syncModule.__events) {\n addEvents(this.syncModule.__events);\n }\n\n this.syncModule.initialize(inputs);\n } else if (type === 'doris') {\n this.syncModule = Object(_modules_sync_modules_sync_doris__WEBPACK_IMPORTED_MODULE_10__[\"default\"])({\n room: room,\n wt: wt,\n roomSession: this,\n emitter: emitter\n });\n\n if (this.syncModule.__events) {\n addEvents(this.syncModule.__events);\n }\n\n this.syncModule.initialize(inputs);\n } else if (type === 'dazn-dash') {\n this.syncModule = Object(_modules_sync_modules_sync_dazn_dash__WEBPACK_IMPORTED_MODULE_12__[\"default\"])({\n room: room,\n wt: wt,\n roomSession: this,\n emitter: emitter\n });\n\n if (this.syncModule.__events) {\n addEvents(this.syncModule.__events);\n }\n\n this.syncModule.initialize(inputs);\n } else if (type === 'disabled') {\n this.syncModule = Object(_modules_sync_modules_sync_disabled__WEBPACK_IMPORTED_MODULE_11__[\"default\"])({\n room: room,\n wt: wt,\n roomSession: this,\n emitter: emitter\n });\n\n if (this.syncModule.__events) {\n addEvents(this.syncModule.__events);\n }\n\n this.syncModule.initialize(inputs);\n } else {\n room._log('Synchronisation type not recognised');\n }\n },\n detachPlayer: function detachPlayer() {\n if (this.syncModule) {\n this.playerInterface = null;\n this.syncModule.destroy();\n\n if (this.syncModule.__events) {\n removeEvents(this.syncModule.__events);\n }\n\n this.syncModule = null;\n }\n },\n setRoomVars: function setRoomVars() {\n var observerIds = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];\n var emit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;\n return wt.room.getRoomById(roomId, pinHash).then(function (r) {\n var _r$data$classroom;\n\n if (emit) {\n // emiting \"fake\" playerSource event\n //TODO: somehow push into sync modules instead\n emitter.emit('changePlayerSource', r.data.wtChannelId, true);\n } // setting observers userId's so we can ignore them when creating participant\n\n\n room.setObserverIds(r.data.allowedObservers);\n room.setTalkbackIds(r.data.allowedTalkbacks);\n room.setInstructorId((_r$data$classroom = r.data.classroom) === null || _r$data$classroom === void 0 ? void 0 : _r$data$classroom.instructorUserId);\n });\n },\n publishLocal: function publishLocal() {\n var stream = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;\n\n var _ref7 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},\n _ref7$keepAudio = _ref7.keepAudio,\n keepAudio = _ref7$keepAudio === void 0 ? false : _ref7$keepAudio,\n _ref7$keepVideo = _ref7.keepVideo,\n keepVideo = _ref7$keepVideo === void 0 ? false : _ref7$keepVideo,\n _ref7$getStreamIfEmpt = _ref7.getStreamIfEmpty,\n getStreamIfEmpty = _ref7$getStreamIfEmpt === void 0 ? true : _ref7$getStreamIfEmpt,\n _ref7$askVideo = _ref7.askVideo,\n askVideo = _ref7$askVideo === void 0 ? true : _ref7$askVideo;\n\n return stream || !getStreamIfEmpty ? room.publishLocal(stream, {\n keepAudio: keepAudio,\n keepVideo: keepVideo\n }) : wt.utils.getUserStream(askVideo).then(function (stream) {\n return room.publishLocal(stream);\n });\n },\n unpublishLocal: function unpublishLocal() {\n return room.unpublishLocal();\n },\n toggleAudio: function toggleAudio(value) {\n return room.toggleAudio(value);\n },\n toggleVideo: function toggleVideo() {\n return room.toggleVideo();\n },\n setBitrateCap: function setBitrateCap(bitrate) {\n if (isInstructor) {\n return;\n }\n\n return room.sendMessage(room.handleId, {\n \"body\": {\n \"request\": \"configure\",\n \"bitrate\": parseInt(bitrate)\n }\n }).catch(function (e) {\n return null;\n });\n },\n switchChannel: function switchChannel(channelId) {\n return room.sendMessage(room.handleId, {\n body: {\n request: \"sync_source_set\",\n room: room.roomId,\n timestamp: new Date().getTime(),\n wt_channel_id: channelId,\n fragment: \"0\",\n fragment_pos: 0\n }\n });\n },\n sendSystemMessage: function sendSystemMessage(action) {\n var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n var to = arguments.length > 2 ? arguments[2] : undefined;\n var set_master = arguments.length > 3 ? arguments[3] : undefined;\n return room.sendMessage(room.handleId, {\n body: _objectSpread(_objectSpread({\n action: action,\n request: \"message\",\n room: room.roomId,\n timestamp: new Date().getTime(),\n text: JSON.stringify(value)\n }, to && Array.isArray(to) ? {\n tos: to\n } : {\n to: to\n }), set_master && {\n set_master: set_master\n })\n });\n },\n sendChatMessage: function sendChatMessage(text, to) {\n return room.sendMessage(room.handleId, {\n body: _objectSpread({\n action: \"chat_message\",\n request: \"message\",\n room: room.roomId,\n timestamp: new Date().getTime(),\n text: text\n }, to && Array.isArray(to) ? {\n tos: to\n } : {\n to: to\n })\n });\n },\n __requestMuteStatus: function __requestMuteStatus() {\n this.sendSystemMessage('remote_muted_request');\n },\n __sendMuteStatus: function __sendMuteStatus() {\n this.sendSystemMessage('remote_muted', {\n type: 'video',\n value: room.isVideoMuted\n });\n this.sendSystemMessage('remote_muted', {\n type: 'audio',\n value: room.isAudioMuted\n });\n },\n $on: function $on(key, callback, that) {\n emitter.on(key, callback, that || _this4);\n room.on(key, callback, that || _this4);\n },\n $off: function $off(key, callback, that) {\n emitter.on(key, callback, that || _this4);\n room.on(key, callback, that || _this4);\n },\n $clear: function $clear() {\n room.clear();\n emitter.clear();\n }\n };\n};\n\n/* harmony default export */ __webpack_exports__[\"default\"] = (roomSession);\n\n//# sourceURL=webpack://WatchTogetherSDK/./src/models/room-session.js?");
9233
9233
 
9234
9234
  /***/ }),
9235
9235
 
@@ -9241,7 +9241,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _mod
9241
9241
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
9242
9242
 
9243
9243
  "use strict";
9244
- eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _room_session__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./room-session */ \"./src/models/room-session.js\");\n/* harmony import */ var _streaming_session__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./streaming-session */ \"./src/models/streaming-session.js\");\n\n\nfunction _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }\n\nfunction _nonIterableSpread() { throw new TypeError(\"Invalid attempt to spread 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 _iterableToArray(iter) { if (typeof Symbol !== \"undefined\" && iter[Symbol.iterator] != null || iter[\"@@iterator\"] != null) return Array.from(iter); }\n\nfunction _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }\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 ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (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 = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { 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\n\n\n\nvar room = function room() {\n var _this = this;\n\n return {\n //TODO: should have own model\n integration: function integration() {\n var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.system.integration({\n type: _this.__instanceType\n }, {\n requestBody: _objectSpread({}, data),\n requestInterceptor: function requestInterceptor(req) {\n if (!req.headers) {\n req.headers = {};\n }\n\n req.headers['Authorization'] = 'Bearer ' + localStorage.getItem('rwt_idToken');\n return req;\n }\n });\n });\n },\n getAnalytics: function getAnalytics() {\n var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.system.getAnalytics(_objectSpread({\n instanceType: _this.__instanceType\n }, data));\n });\n },\n sendChatMessage: function sendChatMessage(_ref) {\n var roomId = _ref.roomId,\n message = _ref.message,\n options = _ref.options,\n senderUserId = _ref.senderUserId;\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.wt.sendRoomMessage({}, {\n requestBody: {\n roomId: roomId,\n message: message,\n options: options,\n senderUserId: senderUserId\n }\n });\n });\n },\n createRoom: function createRoom() {\n var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n title = _ref2.title,\n description = _ref2.description,\n isPublic = _ref2.isPublic,\n isListed = _ref2.isListed,\n isStudioLayout = _ref2.isStudioLayout,\n allowedParticipants = _ref2.allowedParticipants,\n wtChannelId = _ref2.wtChannelId,\n isHd = _ref2.isHd,\n disableSync = _ref2.disableSync,\n reduceRoomControls = _ref2.reduceRoomControls,\n muteParticipantOnJoin = _ref2.muteParticipantOnJoin,\n hasStudioChat = _ref2.hasStudioChat,\n maxParticipants = _ref2.maxParticipants,\n customAttributes = _ref2.customAttributes;\n\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.wt.createRoom({}, {\n requestBody: {\n title: title,\n description: description,\n isPublic: isPublic,\n isListed: isListed,\n isStudioLayout: isStudioLayout,\n instanceType: _this.__instanceType,\n allowedParticipants: allowedParticipants,\n wtChannelId: wtChannelId,\n isHd: isHd,\n disableSync: disableSync,\n reduceRoomControls: reduceRoomControls,\n muteParticipantOnJoin: muteParticipantOnJoin,\n hasStudioChat: hasStudioChat,\n maxParticipants: maxParticipants,\n customAttributes: customAttributes\n }\n });\n });\n },\n updateRoom: function updateRoom() {\n var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n roomId = _ref3.roomId,\n title = _ref3.title,\n description = _ref3.description,\n isPublic = _ref3.isPublic,\n isListed = _ref3.isListed,\n allowedParticipants = _ref3.allowedParticipants,\n recordings = _ref3.recordings,\n slug = _ref3.slug,\n password = _ref3.password,\n maxParticipants = _ref3.maxParticipants,\n _ref3$setInstanceType = _ref3.setInstanceType,\n setInstanceType = _ref3$setInstanceType === void 0 ? false : _ref3$setInstanceType,\n wtChannelId = _ref3.wtChannelId,\n isHd = _ref3.isHd,\n isStudioLayout = _ref3.isStudioLayout,\n hasStudioChat = _ref3.hasStudioChat,\n reduceRoomControls = _ref3.reduceRoomControls,\n muteParticipantOnJoin = _ref3.muteParticipantOnJoin,\n disableSync = _ref3.disableSync,\n defaultRegion = _ref3.defaultRegion,\n customAttributes = _ref3.customAttributes,\n dotAttribute = _ref3.dotAttribute;\n\n var _da = dotAttribute ? Array.isArray(dotAttribute) ? dotAttribute.reduce(function (p, cv) {\n return (p[cv.name] = cv.value) && p || p;\n }, {}) : _defineProperty({}, dotAttribute.name, dotAttribute.value) : {};\n\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.wt.updateRoom({\n id: roomId\n }, {\n requestBody: _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, _da), {}, {\n title: title,\n description: description,\n slug: slug,\n password: password,\n isPublic: isPublic,\n isListed: isListed,\n isHd: isHd,\n isStudioLayout: isStudioLayout,\n hasStudioChat: hasStudioChat,\n maxParticipants: maxParticipants,\n reduceRoomControls: reduceRoomControls,\n muteParticipantOnJoin: muteParticipantOnJoin,\n disableSync: disableSync,\n defaultRegion: defaultRegion,\n customAttributes: customAttributes,\n wtChannelId: wtChannelId\n }, setInstanceType && {\n instanceType: setInstanceType === true ? _this.__instanceType : setInstanceType\n }), allowedParticipants && {\n allowedParticipants: allowedParticipants\n }), recordings && {\n recordings: recordings\n })\n });\n });\n },\n deleteRoom: function deleteRoom(roomId) {\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.wt.deleteRoom({\n id: roomId\n });\n });\n },\n leaveRoom: function leaveRoom(roomId) {\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.wt.leave({\n roomId: roomId\n });\n });\n },\n updateLayout: function updateLayout(_ref5) {\n var roomId = _ref5.roomId,\n operation = _ref5.operation,\n name = _ref5.name,\n attributeName = _ref5.attributeName,\n value = _ref5.value,\n target = _ref5.target;\n //operation : clearLayouts, setLayout, setLayouts, unsetLayout, setName, setTarget, setStyle, setAttribute, unsetAttribute,'sendMessage'\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.wt.updateLayout({}, {\n requestBody: {\n roomId: roomId,\n operation: operation,\n name: name,\n attributeName: attributeName,\n value: value,\n target: target\n }\n });\n });\n },\n getInviteUrl: function getInviteUrl(roomId, domain, url) {\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.wt.invite({}, {\n requestBody: {\n roomId: roomId,\n domain: domain || location.host,\n url: url || location.href\n }\n });\n });\n },\n getRoomsList: function getRoomsList() {\n var _ref6 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n _ref6$type = _ref6.type,\n type = _ref6$type === void 0 ? 'participant' : _ref6$type,\n _ref6$activeOnly = _ref6.activeOnly,\n activeOnly = _ref6$activeOnly === void 0 ? null : _ref6$activeOnly,\n _ref6$instanceType = _ref6.instanceType,\n instanceType = _ref6$instanceType === void 0 ? _this.__instanceType : _ref6$instanceType,\n _ref6$size = _ref6.size,\n size = _ref6$size === void 0 ? 20 : _ref6$size,\n _ref6$startKey = _ref6.startKey,\n startKey = _ref6$startKey === void 0 ? null : _ref6$startKey,\n _ref6$includeWtEventM = _ref6.includeWtEventModels,\n includeWtEventModels = _ref6$includeWtEventM === void 0 ? false : _ref6$includeWtEventM,\n _ref6$demo = _ref6.demo,\n demo = _ref6$demo === void 0 ? false : _ref6$demo,\n _ref6$viewType = _ref6.viewType,\n viewType = _ref6$viewType === void 0 ? 'list' : _ref6$viewType,\n _ref6$wtChannelId = _ref6.wtChannelId,\n wtChannelId = _ref6$wtChannelId === void 0 ? undefined : _ref6$wtChannelId;\n\n var apiParams = _objectSpread(_objectSpread(_objectSpread({\n type: type,\n instanceType: instanceType,\n size: size,\n includeWtEventModels: includeWtEventModels,\n demo: demo,\n viewType: viewType\n }, wtChannelId && {\n wtChannelId: wtChannelId\n }), activeOnly && {\n activeOnly: activeOnly\n }), startKey && {\n startKey: startKey\n });\n\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.wt.getRoomList(apiParams);\n });\n },\n setUser: function setUser(_ref7) {\n var userId = _ref7.userId,\n roomId = _ref7.roomId,\n flag = _ref7.flag,\n timestamp = _ref7.timestamp,\n option = _ref7.option;\n //leave, kick, ban, unban, approve, report\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.wt.setUser({\n userId: userId,\n roomId: roomId,\n flag: flag,\n timestamp: timestamp,\n option: option\n });\n });\n },\n getRoomById: function getRoomById(id) {\n var pinHash = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;\n var showPublic = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;\n var demo = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.wt.getRoom({\n id: id,\n pinHash: pinHash,\n \"public\": showPublic,\n demo: demo\n });\n });\n },\n getRoomBySlug: function getRoomBySlug(slug) {\n var password = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;\n var showPublic = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;\n var demo = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.wt.getRoom({\n slug: slug,\n password: password,\n \"public\": showPublic,\n demo: demo\n });\n });\n },\n roomRecorder: function roomRecorder() {\n var _ref8 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n roomId = _ref8.roomId,\n _ref8$operation = _ref8.operation,\n operation = _ref8$operation === void 0 ? 'get' : _ref8$operation,\n config = _ref8.config;\n\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.wt.recordRoom({}, {\n requestBody: {\n roomId: roomId,\n operation: operation,\n config: config\n }\n });\n });\n },\n __joinRoom: function __joinRoom() {\n var _ref9 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n roomId = _ref9.roomId,\n pinHash = _ref9.pinHash,\n _ref9$instanceType = _ref9.instanceType,\n instanceType = _ref9$instanceType === void 0 ? _this.__instanceType : _ref9$instanceType,\n _ref9$isTalkback = _ref9.isTalkback,\n isTalkback = _ref9$isTalkback === void 0 ? undefined : _ref9$isTalkback,\n _ref9$isMonitor = _ref9.isMonitor,\n isMonitor = _ref9$isMonitor === void 0 ? undefined : _ref9$isMonitor,\n _ref9$isInstructor = _ref9.isInstructor,\n isInstructor = _ref9$isInstructor === void 0 ? undefined : _ref9$isInstructor,\n _ref9$customBearer = _ref9.customBearer,\n customBearer = _ref9$customBearer === void 0 ? undefined : _ref9$customBearer;\n\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.wt.join({\n roomId: roomId,\n pinHash: pinHash,\n instanceType: instanceType,\n isTalkback: isTalkback,\n isMonitor: isMonitor,\n isInstructor: isInstructor,\n platform: _this.browser === 'firefox' ? 'web-firefox' : 'web'\n }, _objectSpread({}, customBearer ? {\n requestInterceptor: function requestInterceptor(req) {\n if (!req.headers) {\n req.headers = {};\n }\n\n req.headers['Authorization'] = customBearer;\n return req;\n }\n } : {}));\n });\n },\n __isThisSafariSupported: function __isThisSafariSupported() {\n return _this.__privates.room.safariVp8;\n },\n createStreamingSession: function createStreamingSession() {\n var _ref10 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n roomId = _ref10.roomId,\n pinHash = _ref10.pinHash,\n streamId = _ref10.streamId,\n href = _ref10.href,\n iceServers = _ref10.iceServers,\n accessToken = _ref10.accessToken;\n\n return _this.__privates.room.isReady.then(function (lib) {\n return _streaming_session__WEBPACK_IMPORTED_MODULE_1__[\"default\"].call(_this, {\n roomId: roomId,\n pinHash: pinHash,\n streamId: streamId,\n href: href,\n iceServers: iceServers,\n accessToken: accessToken\n }, lib.createSession('streaming'), _this);\n });\n },\n createSession: function createSession(_ref11) {\n var roomId = _ref11.roomId,\n pinHash = _ref11.pinHash,\n isTalkback = _ref11.isTalkback,\n isMonitor = _ref11.isMonitor,\n isInstructor = _ref11.isInstructor,\n options = _ref11.options;\n return _this.__privates.room.isReady.then(function (lib) {\n return _room_session__WEBPACK_IMPORTED_MODULE_0__[\"default\"].call(_this, {\n roomId: roomId,\n pinHash: pinHash,\n isTalkback: isTalkback,\n isMonitor: isMonitor,\n isInstructor: isInstructor\n }, lib.createSession('reactooroom', options), _this);\n });\n },\n destroySession: function destroySession(constructId) {\n return _this.__privates.room.closeSessionByConstructId(constructId);\n },\n queue: function queue() {\n var _ref12 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n roomId = _ref12.roomId,\n operation = _ref12.operation,\n userId = _ref12.userId;\n\n //Enum: \"status\" \"join\" \"approve\" \"reject\" \"block\" \"unblock\"\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.wt.queue({}, {\n requestBody: {\n roomId: roomId,\n operation: operation,\n userId: userId\n }\n });\n });\n },\n getDefaultRegions: function getDefaultRegions() {\n return _this.__privates.auth.__client.then(function (client) {\n var _client$spec, _client$spec$componen, _client$spec$componen2, _client$spec$componen3, _client$spec$componen4, _client$spec$componen5;\n\n return _toConsumableArray(((_client$spec = client.spec) === null || _client$spec === void 0 ? void 0 : (_client$spec$componen = _client$spec.components) === null || _client$spec$componen === void 0 ? void 0 : (_client$spec$componen2 = _client$spec$componen.schemas) === null || _client$spec$componen2 === void 0 ? void 0 : (_client$spec$componen3 = _client$spec$componen2.WtRoom) === null || _client$spec$componen3 === void 0 ? void 0 : (_client$spec$componen4 = _client$spec$componen3.properties) === null || _client$spec$componen4 === void 0 ? void 0 : (_client$spec$componen5 = _client$spec$componen4.defaultRegion) === null || _client$spec$componen5 === void 0 ? void 0 : _client$spec$componen5.enum) || ['']);\n });\n }\n };\n};\n\n/* harmony default export */ __webpack_exports__[\"default\"] = (room);\n\n//# sourceURL=webpack://WatchTogetherSDK/./src/models/room.js?");
9244
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _room_session__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./room-session */ \"./src/models/room-session.js\");\n/* harmony import */ var _streaming_session__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./streaming-session */ \"./src/models/streaming-session.js\");\n\n\nfunction _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }\n\nfunction _nonIterableSpread() { throw new TypeError(\"Invalid attempt to spread 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 _iterableToArray(iter) { if (typeof Symbol !== \"undefined\" && iter[Symbol.iterator] != null || iter[\"@@iterator\"] != null) return Array.from(iter); }\n\nfunction _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }\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 ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (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 = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { 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\n\n\n\nvar room = function room() {\n var _this = this;\n\n return {\n //TODO: should have own model\n integration: function integration() {\n var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.system.integration({\n type: _this.__instanceType\n }, {\n requestBody: _objectSpread({}, data),\n requestInterceptor: function requestInterceptor(req) {\n if (!req.headers) {\n req.headers = {};\n }\n\n req.headers['Authorization'] = 'Bearer ' + localStorage.getItem('rwt_idToken');\n return req;\n }\n });\n });\n },\n getAnalytics: function getAnalytics() {\n var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.system.getAnalytics(_objectSpread({\n instanceType: _this.__instanceType\n }, data));\n });\n },\n sendChatMessage: function sendChatMessage(_ref) {\n var roomId = _ref.roomId,\n message = _ref.message,\n options = _ref.options,\n senderUserId = _ref.senderUserId;\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.wt.sendRoomMessage({}, {\n requestBody: {\n roomId: roomId,\n message: message,\n options: options,\n senderUserId: senderUserId\n }\n });\n });\n },\n createRoom: function createRoom() {\n var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n title = _ref2.title,\n description = _ref2.description,\n isPublic = _ref2.isPublic,\n isListed = _ref2.isListed,\n isStudioLayout = _ref2.isStudioLayout,\n allowedParticipants = _ref2.allowedParticipants,\n wtChannelId = _ref2.wtChannelId,\n isHd = _ref2.isHd,\n disableSync = _ref2.disableSync,\n reduceRoomControls = _ref2.reduceRoomControls,\n muteParticipantOnJoin = _ref2.muteParticipantOnJoin,\n hasStudioChat = _ref2.hasStudioChat,\n maxParticipants = _ref2.maxParticipants,\n customAttributes = _ref2.customAttributes;\n\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.wt.createRoom({}, {\n requestBody: {\n title: title,\n description: description,\n isPublic: isPublic,\n isListed: isListed,\n isStudioLayout: isStudioLayout,\n instanceType: _this.__instanceType,\n allowedParticipants: allowedParticipants,\n wtChannelId: wtChannelId,\n isHd: isHd,\n disableSync: disableSync,\n reduceRoomControls: reduceRoomControls,\n muteParticipantOnJoin: muteParticipantOnJoin,\n hasStudioChat: hasStudioChat,\n maxParticipants: maxParticipants,\n customAttributes: customAttributes\n }\n });\n });\n },\n updateRoom: function updateRoom() {\n var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n roomId = _ref3.roomId,\n title = _ref3.title,\n description = _ref3.description,\n isPublic = _ref3.isPublic,\n isListed = _ref3.isListed,\n allowedParticipants = _ref3.allowedParticipants,\n recordings = _ref3.recordings,\n slug = _ref3.slug,\n password = _ref3.password,\n maxParticipants = _ref3.maxParticipants,\n _ref3$setInstanceType = _ref3.setInstanceType,\n setInstanceType = _ref3$setInstanceType === void 0 ? false : _ref3$setInstanceType,\n wtChannelId = _ref3.wtChannelId,\n isHd = _ref3.isHd,\n isStudioLayout = _ref3.isStudioLayout,\n hasStudioChat = _ref3.hasStudioChat,\n reduceRoomControls = _ref3.reduceRoomControls,\n muteParticipantOnJoin = _ref3.muteParticipantOnJoin,\n disableSync = _ref3.disableSync,\n defaultRegion = _ref3.defaultRegion,\n customAttributes = _ref3.customAttributes,\n dotAttribute = _ref3.dotAttribute;\n\n var _da = dotAttribute ? Array.isArray(dotAttribute) ? dotAttribute.reduce(function (p, cv) {\n return (p[cv.name] = cv.value) && p || p;\n }, {}) : _defineProperty({}, dotAttribute.name, dotAttribute.value) : {};\n\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.wt.updateRoom({\n id: roomId\n }, {\n requestBody: _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, _da), {}, {\n title: title,\n description: description,\n slug: slug,\n password: password,\n isPublic: isPublic,\n isListed: isListed,\n isHd: isHd,\n isStudioLayout: isStudioLayout,\n hasStudioChat: hasStudioChat,\n maxParticipants: maxParticipants,\n reduceRoomControls: reduceRoomControls,\n muteParticipantOnJoin: muteParticipantOnJoin,\n disableSync: disableSync,\n defaultRegion: defaultRegion,\n customAttributes: customAttributes,\n wtChannelId: wtChannelId\n }, setInstanceType && {\n instanceType: setInstanceType === true ? _this.__instanceType : setInstanceType\n }), allowedParticipants && {\n allowedParticipants: allowedParticipants\n }), recordings && {\n recordings: recordings\n })\n });\n });\n },\n deleteRoom: function deleteRoom(roomId) {\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.wt.deleteRoom({\n id: roomId\n });\n });\n },\n leaveRoom: function leaveRoom(roomId) {\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.wt.leave({\n roomId: roomId\n });\n });\n },\n updateLayout: function updateLayout(_ref5) {\n var roomId = _ref5.roomId,\n operation = _ref5.operation,\n name = _ref5.name,\n attributeName = _ref5.attributeName,\n value = _ref5.value,\n target = _ref5.target;\n //operation : clearLayouts, setLayout, setLayouts, unsetLayout, setName, setTarget, setStyle, setAttribute, unsetAttribute,'sendMessage'\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.wt.updateLayout({}, {\n requestBody: {\n roomId: roomId,\n operation: operation,\n name: name,\n attributeName: attributeName,\n value: value,\n target: target\n }\n });\n });\n },\n getInviteUrl: function getInviteUrl(roomId, domain, url) {\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.wt.invite({}, {\n requestBody: {\n roomId: roomId,\n domain: domain || location.host,\n url: url || location.href\n }\n });\n });\n },\n getRoomChatList: function getRoomChatList() {\n var _ref6 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n roomId = _ref6.roomId,\n _ref6$type = _ref6.type,\n type = _ref6$type === void 0 ? \"normal\" : _ref6$type,\n _ref6$size = _ref6.size,\n size = _ref6$size === void 0 ? 50 : _ref6$size,\n _ref6$startKey = _ref6.startKey,\n startKey = _ref6$startKey === void 0 ? null : _ref6$startKey;\n\n var apiParams = _objectSpread({\n roomId: roomId,\n type: type,\n size: size\n }, startKey && {\n startKey: startKey\n });\n\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.wt.getRoomChatList(apiParams);\n });\n },\n getRoomsList: function getRoomsList() {\n var _ref7 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n _ref7$type = _ref7.type,\n type = _ref7$type === void 0 ? 'participant' : _ref7$type,\n _ref7$activeOnly = _ref7.activeOnly,\n activeOnly = _ref7$activeOnly === void 0 ? null : _ref7$activeOnly,\n _ref7$instanceType = _ref7.instanceType,\n instanceType = _ref7$instanceType === void 0 ? _this.__instanceType : _ref7$instanceType,\n _ref7$size = _ref7.size,\n size = _ref7$size === void 0 ? 20 : _ref7$size,\n _ref7$startKey = _ref7.startKey,\n startKey = _ref7$startKey === void 0 ? null : _ref7$startKey,\n _ref7$includeWtEventM = _ref7.includeWtEventModels,\n includeWtEventModels = _ref7$includeWtEventM === void 0 ? false : _ref7$includeWtEventM,\n _ref7$demo = _ref7.demo,\n demo = _ref7$demo === void 0 ? false : _ref7$demo,\n _ref7$viewType = _ref7.viewType,\n viewType = _ref7$viewType === void 0 ? 'list' : _ref7$viewType,\n _ref7$wtChannelId = _ref7.wtChannelId,\n wtChannelId = _ref7$wtChannelId === void 0 ? undefined : _ref7$wtChannelId;\n\n var apiParams = _objectSpread(_objectSpread(_objectSpread({\n type: type,\n instanceType: instanceType,\n size: size,\n includeWtEventModels: includeWtEventModels,\n demo: demo,\n viewType: viewType\n }, wtChannelId && {\n wtChannelId: wtChannelId\n }), activeOnly && {\n activeOnly: activeOnly\n }), startKey && {\n startKey: startKey\n });\n\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.wt.getRoomList(apiParams);\n });\n },\n setUser: function setUser(_ref8) {\n var messageId = _ref8.messageId,\n userId = _ref8.userId,\n roomId = _ref8.roomId,\n flag = _ref8.flag,\n timestamp = _ref8.timestamp,\n option = _ref8.option;\n //leave, kick, ban, unban, approve, report\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.wt.setUser({\n messageId: messageId,\n userId: userId,\n roomId: roomId,\n flag: flag,\n timestamp: timestamp,\n option: option\n });\n });\n },\n getRoomById: function getRoomById(id) {\n var pinHash = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;\n var showPublic = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;\n var demo = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.wt.getRoom({\n id: id,\n pinHash: pinHash,\n \"public\": showPublic,\n demo: demo\n });\n });\n },\n getRoomBySlug: function getRoomBySlug(slug) {\n var password = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;\n var showPublic = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;\n var demo = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.wt.getRoom({\n slug: slug,\n password: password,\n \"public\": showPublic,\n demo: demo\n });\n });\n },\n roomRecorder: function roomRecorder() {\n var _ref9 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n roomId = _ref9.roomId,\n _ref9$operation = _ref9.operation,\n operation = _ref9$operation === void 0 ? 'get' : _ref9$operation,\n config = _ref9.config;\n\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.wt.recordRoom({}, {\n requestBody: {\n roomId: roomId,\n operation: operation,\n config: config\n }\n });\n });\n },\n __joinRoom: function __joinRoom() {\n var _ref10 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n roomId = _ref10.roomId,\n pinHash = _ref10.pinHash,\n _ref10$instanceType = _ref10.instanceType,\n instanceType = _ref10$instanceType === void 0 ? _this.__instanceType : _ref10$instanceType,\n _ref10$isTalkback = _ref10.isTalkback,\n isTalkback = _ref10$isTalkback === void 0 ? undefined : _ref10$isTalkback,\n _ref10$isMonitor = _ref10.isMonitor,\n isMonitor = _ref10$isMonitor === void 0 ? undefined : _ref10$isMonitor,\n _ref10$isInstructor = _ref10.isInstructor,\n isInstructor = _ref10$isInstructor === void 0 ? undefined : _ref10$isInstructor,\n _ref10$customBearer = _ref10.customBearer,\n customBearer = _ref10$customBearer === void 0 ? undefined : _ref10$customBearer;\n\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.wt.join({\n roomId: roomId,\n pinHash: pinHash,\n instanceType: instanceType,\n isTalkback: isTalkback,\n isMonitor: isMonitor,\n isInstructor: isInstructor,\n platform: _this.browser === 'firefox' ? 'web-firefox' : 'web'\n }, _objectSpread({}, customBearer ? {\n requestInterceptor: function requestInterceptor(req) {\n if (!req.headers) {\n req.headers = {};\n }\n\n req.headers['Authorization'] = customBearer;\n return req;\n }\n } : {}));\n });\n },\n __isThisSafariSupported: function __isThisSafariSupported() {\n return _this.__privates.room.safariVp8;\n },\n createStreamingSession: function createStreamingSession() {\n var _ref11 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n roomId = _ref11.roomId,\n pinHash = _ref11.pinHash,\n streamId = _ref11.streamId,\n href = _ref11.href,\n iceServers = _ref11.iceServers,\n accessToken = _ref11.accessToken;\n\n return _this.__privates.room.isReady.then(function (lib) {\n return _streaming_session__WEBPACK_IMPORTED_MODULE_1__[\"default\"].call(_this, {\n roomId: roomId,\n pinHash: pinHash,\n streamId: streamId,\n href: href,\n iceServers: iceServers,\n accessToken: accessToken\n }, lib.createSession('streaming'), _this);\n });\n },\n createSession: function createSession(_ref12) {\n var roomId = _ref12.roomId,\n pinHash = _ref12.pinHash,\n isTalkback = _ref12.isTalkback,\n isMonitor = _ref12.isMonitor,\n isInstructor = _ref12.isInstructor,\n options = _ref12.options;\n return _this.__privates.room.isReady.then(function (lib) {\n return _room_session__WEBPACK_IMPORTED_MODULE_0__[\"default\"].call(_this, {\n roomId: roomId,\n pinHash: pinHash,\n isTalkback: isTalkback,\n isMonitor: isMonitor,\n isInstructor: isInstructor\n }, lib.createSession('reactooroom', options), _this);\n });\n },\n destroySession: function destroySession(constructId) {\n return _this.__privates.room.closeSessionByConstructId(constructId);\n },\n queue: function queue() {\n var _ref13 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n roomId = _ref13.roomId,\n operation = _ref13.operation,\n userId = _ref13.userId;\n\n //Enum: \"status\" \"join\" \"approve\" \"reject\" \"block\" \"unblock\"\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.wt.queue({}, {\n requestBody: {\n roomId: roomId,\n operation: operation,\n userId: userId\n }\n });\n });\n },\n getDefaultRegions: function getDefaultRegions() {\n return _this.__privates.auth.__client.then(function (client) {\n var _client$spec, _client$spec$componen, _client$spec$componen2, _client$spec$componen3, _client$spec$componen4, _client$spec$componen5;\n\n return _toConsumableArray(((_client$spec = client.spec) === null || _client$spec === void 0 ? void 0 : (_client$spec$componen = _client$spec.components) === null || _client$spec$componen === void 0 ? void 0 : (_client$spec$componen2 = _client$spec$componen.schemas) === null || _client$spec$componen2 === void 0 ? void 0 : (_client$spec$componen3 = _client$spec$componen2.WtRoom) === null || _client$spec$componen3 === void 0 ? void 0 : (_client$spec$componen4 = _client$spec$componen3.properties) === null || _client$spec$componen4 === void 0 ? void 0 : (_client$spec$componen5 = _client$spec$componen4.defaultRegion) === null || _client$spec$componen5 === void 0 ? void 0 : _client$spec$componen5.enum) || ['']);\n });\n }\n };\n};\n\n/* harmony default export */ __webpack_exports__[\"default\"] = (room);\n\n//# sourceURL=webpack://WatchTogetherSDK/./src/models/room.js?");
9245
9245
 
9246
9246
  /***/ }),
9247
9247
 
@@ -9265,7 +9265,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n\n\nfunction _slicedToArray(a
9265
9265
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
9266
9266
 
9267
9267
  "use strict";
9268
- eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _modules_wt_utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../modules/wt-utils */ \"./src/modules/wt-utils.js\");\n/* harmony import */ var serialize_error__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! serialize-error */ \"./node_modules/serialize-error/index.js\");\n/* harmony import */ var serialize_error__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(serialize_error__WEBPACK_IMPORTED_MODULE_1__);\n\n\nfunction _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }\n\nfunction _nonIterableSpread() { throw new TypeError(\"Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\"); }\n\nfunction _iterableToArray(iter) { if (typeof Symbol !== \"undefined\" && iter[Symbol.iterator] != null || iter[\"@@iterator\"] != null) return Array.from(iter); }\n\nfunction _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }\n\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); if (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 = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { 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\n\n\n\nvar user = function user() {\n var _this = this;\n\n return {\n updateUserSelf: function updateUserSelf() {\n var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.user.updateMyself(_objectSpread({}, data.lastRoomId && {\n lastRoomId: data.lastRoomId\n }), {\n requestBody: _objectSpread({}, data)\n });\n });\n },\n updateUser: function updateUser() {\n var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.user.updateUser(_objectSpread({}, data), {\n requestBody: _objectSpread({}, data)\n });\n });\n },\n uploadAvatar: function uploadAvatar(file, lastRoomId) {\n var id = Object(_modules_wt_utils__WEBPACK_IMPORTED_MODULE_0__[\"generateUUID\"])();\n return _this.__privates.auth.__client.then(function (client) {\n return Promise.all([client, client.apis.user.initiateMyAvatarUpload({\n id: id\n })]);\n }).then(function (_ref) {\n var _ref2 = _slicedToArray(_ref, 2),\n client = _ref2[0],\n response = _ref2[1];\n\n return Promise.all([client, client.http({\n url: response.data.signedUrl,\n method: response.data.httpMethod,\n headers: {\n \"Content-Type\": file.type\n },\n body: file\n })]);\n }).then(function (_ref3) {\n var _ref4 = _slicedToArray(_ref3, 2),\n client = _ref4[0],\n response = _ref4[1];\n\n return client.apis.user.publishMyAvatar({\n id: id,\n lastRoomId: lastRoomId\n });\n });\n },\n uploadReaction: function uploadReaction(files) {\n var id = Object(_modules_wt_utils__WEBPACK_IMPORTED_MODULE_0__[\"generateUUID\"])();\n return _this.__privates.auth.__client.then(function (client) {\n return Promise.all([client, client.apis.reaction.initiateReactionUpload({\n id: id,\n segmentCount: files.length || 0\n })]);\n }).then(function (_ref5) {\n var _ref6 = _slicedToArray(_ref5, 2),\n client = _ref6[0],\n response = _ref6[1];\n\n return Promise.all([client].concat(_toConsumableArray(response.data.signedUrlSegments.map(function (url, index) {\n return client.http({\n url: url,\n method: response.data.httpMethod,\n headers: {\n \"Content-Type\": files[index].type\n },\n body: files[index]\n });\n }))));\n }).then(function (_ref7) {\n var _ref8 = _slicedToArray(_ref7, 1),\n client = _ref8[0];\n\n return client.apis.reaction.processReaction({\n id: id,\n type: 'concat'\n });\n }).then(function (response) {\n return response.data.key;\n });\n },\n uploadVideo: function uploadVideo(roomId, files) {\n var privateAttributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};\n var id = Object(_modules_wt_utils__WEBPACK_IMPORTED_MODULE_0__[\"generateUUID\"])();\n return _this.__privates.auth.__client.then(function (client) {\n return Promise.all([client, client.apis.video.initiateVideoUpload({\n id: id,\n segmentCount: files.length || 0\n })]);\n }).then(function (_ref9) {\n var _ref10 = _slicedToArray(_ref9, 2),\n client = _ref10[0],\n response = _ref10[1];\n\n return Promise.all([client, response.data.signedUrlSegments.reduce(function (acc, url, index) {\n return acc.then(function () {\n return client.http({\n url: url,\n method: response.data.httpMethod,\n headers: {\n \"Content-Type\": files[index].type\n },\n body: files[index]\n });\n });\n }, Promise.resolve())]);\n }).then(function (_ref11) {\n var _ref12 = _slicedToArray(_ref11, 1),\n client = _ref12[0];\n\n return client.apis.video.publishVideo({\n _id: id,\n roomId: roomId\n }, {\n requestBody: {\n _id: id,\n roomId: roomId,\n privateAttributes: privateAttributes\n }\n });\n });\n },\n getReactionById: function getReactionById(id) {\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.reaction.getReactionById({\n id: id\n });\n });\n },\n getReactions: function getReactions() {\n var _ref13 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n userId = _ref13.userId,\n roomId = _ref13.roomId,\n type = _ref13.type,\n size = _ref13.size,\n startKey = _ref13.startKey,\n _ref13$includeUserMod = _ref13.includeUserModels,\n includeUserModels = _ref13$includeUserMod === void 0 ? false : _ref13$includeUserMod;\n\n var apiParams = _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, roomId && {\n roomId: roomId\n }), userId && {\n userId: userId\n }), size && {\n size: size\n }), startKey && {\n startKey: startKey\n }), {}, {\n includeUserModels: includeUserModels,\n type: type\n });\n\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.reaction.getReactions(apiParams);\n });\n },\n getVideoById: function getVideoById(id) {\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.video.getVideoById({\n id: id\n });\n });\n },\n getVideos: function getVideos() {\n var _ref14 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n roomId = _ref14.roomId,\n userId = _ref14.userId,\n type = _ref14.type,\n size = _ref14.size,\n startKey = _ref14.startKey,\n _ref14$includeUserMod = _ref14.includeUserModels,\n includeUserModels = _ref14$includeUserMod === void 0 ? false : _ref14$includeUserMod,\n includeRoomQueueStatus = _ref14.includeRoomQueueStatus;\n\n var apiParams = _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, roomId && {\n roomId: roomId\n }), userId && {\n userId: userId\n }), size && {\n size: size\n }), startKey && {\n startKey: startKey\n }), includeRoomQueueStatus && {\n includeRoomQueueStatus: includeRoomQueueStatus\n }), {}, {\n includeUserModels: includeUserModels,\n type: type\n });\n\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.video.getVideos(apiParams);\n });\n },\n getUserSelf: function getUserSelf() {\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.user.getUserMyself();\n });\n },\n getUserById: function getUserById(id) {\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.user.getUserById({\n id: id\n });\n });\n },\n getUsersByIds: function getUsersByIds() {\n var _ref15 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n _ref15$ids = _ref15.ids,\n ids = _ref15$ids === void 0 ? [] : _ref15$ids,\n _ref15$size = _ref15.size,\n size = _ref15$size === void 0 ? null : _ref15$size,\n _ref15$startKey = _ref15.startKey,\n startKey = _ref15$startKey === void 0 ? null : _ref15$startKey;\n\n var apiParams = _objectSpread(_objectSpread(_objectSpread({\n type: 'ids'\n }, size && {\n size: size\n }), ids && {\n ids: ids.join(',')\n }), startKey && {\n startKey: startKey\n });\n\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.user.getUsers(apiParams);\n });\n },\n getUsers: function getUsers() {\n var _ref16 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n type = _ref16.type,\n userId = _ref16.userId,\n roomId = _ref16.roomId,\n _ref16$size = _ref16.size,\n size = _ref16$size === void 0 ? 20 : _ref16$size,\n _ref16$startKey = _ref16.startKey,\n startKey = _ref16$startKey === void 0 ? null : _ref16$startKey;\n\n var apiParams = _objectSpread(_objectSpread(_objectSpread({\n type: type,\n size: size\n }, roomId && {\n roomId: roomId\n }), userId && {\n userId: userId\n }), startKey && {\n startKey: startKey\n });\n\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.user.getUsers(apiParams);\n });\n },\n //TODO: should have own model\n track: function track() {\n var _ref17 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n _ref17$eventType = _ref17.eventType,\n eventType = _ref17$eventType === void 0 ? 'ERROR' : _ref17$eventType,\n message = _ref17.message;\n\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.wt.track({}, {\n requestBody: {\n \"eventType\": eventType,\n \"appType\": \"web\",\n \"deviceType\": \"desktop\".concat(navigator.maxTouchPoints ? '/touchy' : ''),\n \"os\": navigator.platform,\n \"browser\": navigator.userAgent,\n \"domain\": location.host,\n \"url\": location.href,\n \"message\": Object(serialize_error__WEBPACK_IMPORTED_MODULE_1__[\"serializeError\"])(message)\n }\n });\n });\n },\n getTranslation: function getTranslation() {\n var _ref18 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n _ref18$namespace = _ref18.namespace,\n namespace = _ref18$namespace === void 0 ? 'wt' : _ref18$namespace;\n\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.system.getTranslation({\n namespace: namespace\n });\n });\n },\n getConfig: function getConfig() {\n var _ref19 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n _ref19$instanceType = _ref19.instanceType,\n instanceType = _ref19$instanceType === void 0 ? _this.__instanceType : _ref19$instanceType,\n _ref19$domain = _ref19.domain,\n domain = _ref19$domain === void 0 ? location.hostname : _ref19$domain;\n\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.system.getConfig({\n instanceType: instanceType,\n domain: domain\n });\n });\n },\n getIntegrationPublic: function getIntegrationPublic(type) {\n var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.system.integrationPublic({\n type: type\n }, {\n requestBody: _objectSpread({}, data)\n });\n });\n },\n updateConfig: function updateConfig() {\n var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.wt.updateConfig({\n id: data.instanceType || _this.__instanceType\n }, {\n requestBody: _objectSpread({}, data)\n });\n });\n },\n admin: function admin() {\n var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.wt.admin({}, {\n requestBody: _objectSpread({\n instanceType: _this.__instanceType\n }, data)\n });\n });\n },\n analytics: function analytics() {\n var _ref20 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n action = _ref20.action,\n _ref20$startKey = _ref20.startKey,\n startKey = _ref20$startKey === void 0 ? null : _ref20$startKey,\n _ref20$limit = _ref20.limit,\n limit = _ref20$limit === void 0 ? 20 : _ref20$limit;\n\n var apiParams = _objectSpread({\n action: action,\n limit: limit\n }, startKey && {\n startKey: startKey\n });\n\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.wt.analytics({}, {\n requestBody: _objectSpread({\n instanceType: _this.__instanceType\n }, apiParams)\n });\n });\n }\n };\n};\n\n/* harmony default export */ __webpack_exports__[\"default\"] = (user);\n\n//# sourceURL=webpack://WatchTogetherSDK/./src/models/user.js?");
9268
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _modules_wt_utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../modules/wt-utils */ \"./src/modules/wt-utils.js\");\n/* harmony import */ var serialize_error__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! serialize-error */ \"./node_modules/serialize-error/index.js\");\n/* harmony import */ var serialize_error__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(serialize_error__WEBPACK_IMPORTED_MODULE_1__);\n\n\nfunction _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }\n\nfunction _nonIterableSpread() { throw new TypeError(\"Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\"); }\n\nfunction _iterableToArray(iter) { if (typeof Symbol !== \"undefined\" && iter[Symbol.iterator] != null || iter[\"@@iterator\"] != null) return Array.from(iter); }\n\nfunction _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }\n\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); if (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 = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { 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\n\n\n\nvar user = function user() {\n var _this = this;\n\n return {\n updateUserSelf: function updateUserSelf() {\n var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.user.updateMyself(_objectSpread({}, data.lastRoomId && {\n lastRoomId: data.lastRoomId\n }), {\n requestBody: _objectSpread({}, data)\n });\n });\n },\n updateUser: function updateUser() {\n var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.user.updateUser(_objectSpread({}, data), {\n requestBody: _objectSpread({}, data)\n });\n });\n },\n uploadAvatar: function uploadAvatar(file, lastRoomId) {\n var id = Object(_modules_wt_utils__WEBPACK_IMPORTED_MODULE_0__[\"generateUUID\"])();\n return _this.__privates.auth.__client.then(function (client) {\n return Promise.all([client, client.apis.user.initiateMyAvatarUpload({\n id: id\n })]);\n }).then(function (_ref) {\n var _ref2 = _slicedToArray(_ref, 2),\n client = _ref2[0],\n response = _ref2[1];\n\n return Promise.all([client, client.http({\n url: response.data.signedUrl,\n method: response.data.httpMethod,\n headers: {\n \"Content-Type\": file.type\n },\n body: file\n })]);\n }).then(function (_ref3) {\n var _ref4 = _slicedToArray(_ref3, 2),\n client = _ref4[0],\n response = _ref4[1];\n\n return client.apis.user.publishMyAvatar({\n id: id,\n lastRoomId: lastRoomId\n });\n });\n },\n uploadReaction: function uploadReaction(files) {\n var id = Object(_modules_wt_utils__WEBPACK_IMPORTED_MODULE_0__[\"generateUUID\"])();\n return _this.__privates.auth.__client.then(function (client) {\n return Promise.all([client, client.apis.reaction.initiateReactionUpload({\n id: id,\n segmentCount: files.length || 0\n })]);\n }).then(function (_ref5) {\n var _ref6 = _slicedToArray(_ref5, 2),\n client = _ref6[0],\n response = _ref6[1];\n\n return Promise.all([client].concat(_toConsumableArray(response.data.signedUrlSegments.map(function (url, index) {\n return client.http({\n url: url,\n method: response.data.httpMethod,\n headers: {\n \"Content-Type\": files[index].type\n },\n body: files[index]\n });\n }))));\n }).then(function (_ref7) {\n var _ref8 = _slicedToArray(_ref7, 1),\n client = _ref8[0];\n\n return client.apis.reaction.processReaction({\n id: id,\n type: 'concat'\n });\n }).then(function (response) {\n return response.data.key;\n });\n },\n uploadVideo: function uploadVideo(roomId, files) {\n var privateAttributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};\n var id = Object(_modules_wt_utils__WEBPACK_IMPORTED_MODULE_0__[\"generateUUID\"])();\n return _this.__privates.auth.__client.then(function (client) {\n return Promise.all([client, client.apis.video.initiateVideoUpload({\n id: id,\n segmentCount: files.length || 0\n })]);\n }).then(function (_ref9) {\n var _ref10 = _slicedToArray(_ref9, 2),\n client = _ref10[0],\n response = _ref10[1];\n\n return Promise.all([client, response.data.signedUrlSegments.reduce(function (acc, url, index) {\n return acc.then(function () {\n return client.http({\n url: url,\n method: response.data.httpMethod,\n headers: {\n \"Content-Type\": files[index].type\n },\n body: files[index]\n });\n });\n }, Promise.resolve())]);\n }).then(function (_ref11) {\n var _ref12 = _slicedToArray(_ref11, 1),\n client = _ref12[0];\n\n return client.apis.video.publishVideo({\n _id: id,\n roomId: roomId\n }, {\n requestBody: {\n _id: id,\n roomId: roomId,\n privateAttributes: privateAttributes\n }\n });\n });\n },\n getReactionById: function getReactionById(id) {\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.reaction.getReactionById({\n id: id\n });\n });\n },\n getReactions: function getReactions() {\n var _ref13 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n userId = _ref13.userId,\n roomId = _ref13.roomId,\n type = _ref13.type,\n size = _ref13.size,\n startKey = _ref13.startKey,\n _ref13$includeUserMod = _ref13.includeUserModels,\n includeUserModels = _ref13$includeUserMod === void 0 ? false : _ref13$includeUserMod;\n\n var apiParams = _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, roomId && {\n roomId: roomId\n }), userId && {\n userId: userId\n }), size && {\n size: size\n }), startKey && {\n startKey: startKey\n }), {}, {\n includeUserModels: includeUserModels,\n type: type\n });\n\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.reaction.getReactions(apiParams);\n });\n },\n getVideoById: function getVideoById(id) {\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.video.getVideoById({\n id: id\n });\n });\n },\n getVideos: function getVideos() {\n var _ref14 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n roomId = _ref14.roomId,\n userId = _ref14.userId,\n type = _ref14.type,\n size = _ref14.size,\n startKey = _ref14.startKey,\n _ref14$includeUserMod = _ref14.includeUserModels,\n includeUserModels = _ref14$includeUserMod === void 0 ? false : _ref14$includeUserMod,\n includeRoomQueueStatus = _ref14.includeRoomQueueStatus;\n\n var apiParams = _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, roomId && {\n roomId: roomId\n }), userId && {\n userId: userId\n }), size && {\n size: size\n }), startKey && {\n startKey: startKey\n }), includeRoomQueueStatus && {\n includeRoomQueueStatus: includeRoomQueueStatus\n }), {}, {\n includeUserModels: includeUserModels,\n type: type\n });\n\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.video.getVideos(apiParams);\n });\n },\n getUserSelf: function getUserSelf() {\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.user.getUserMyself();\n });\n },\n getUserById: function getUserById(id) {\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.user.getUserById({\n id: id\n });\n });\n },\n getUsersByIds: function getUsersByIds() {\n var _ref15 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n _ref15$ids = _ref15.ids,\n ids = _ref15$ids === void 0 ? [] : _ref15$ids,\n _ref15$size = _ref15.size,\n size = _ref15$size === void 0 ? null : _ref15$size,\n _ref15$startKey = _ref15.startKey,\n startKey = _ref15$startKey === void 0 ? null : _ref15$startKey;\n\n var apiParams = _objectSpread(_objectSpread(_objectSpread({\n type: 'ids'\n }, size && {\n size: size\n }), ids && {\n ids: ids.join(',')\n }), startKey && {\n startKey: startKey\n });\n\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.user.getUsers(apiParams);\n });\n },\n getUsers: function getUsers() {\n var _ref16 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n type = _ref16.type,\n userId = _ref16.userId,\n roomId = _ref16.roomId,\n _ref16$size = _ref16.size,\n size = _ref16$size === void 0 ? 20 : _ref16$size,\n _ref16$startKey = _ref16.startKey,\n startKey = _ref16$startKey === void 0 ? null : _ref16$startKey;\n\n var apiParams = _objectSpread(_objectSpread(_objectSpread({\n type: type,\n size: size\n }, roomId && {\n roomId: roomId\n }), userId && {\n userId: userId\n }), startKey && {\n startKey: startKey\n });\n\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.user.getUsers(apiParams);\n });\n },\n //TODO: should have own model\n track: function track() {\n var _ref17 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n _ref17$eventType = _ref17.eventType,\n eventType = _ref17$eventType === void 0 ? 'ERROR' : _ref17$eventType,\n message = _ref17.message;\n\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.wt.track({}, {\n requestBody: {\n \"eventType\": eventType,\n \"appType\": \"web\",\n \"deviceType\": \"desktop\".concat(navigator.maxTouchPoints ? '/touch' : ''),\n \"os\": navigator.platform,\n \"browser\": navigator.userAgent,\n \"domain\": location.host,\n \"url\": location.href,\n \"message\": Object(serialize_error__WEBPACK_IMPORTED_MODULE_1__[\"serializeError\"])(message)\n }\n });\n });\n },\n getTranslation: function getTranslation() {\n var _ref18 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n _ref18$namespace = _ref18.namespace,\n namespace = _ref18$namespace === void 0 ? 'wt' : _ref18$namespace;\n\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.system.getTranslation({\n namespace: namespace\n });\n });\n },\n getConfig: function getConfig() {\n var _ref19 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n _ref19$instanceType = _ref19.instanceType,\n instanceType = _ref19$instanceType === void 0 ? _this.__instanceType : _ref19$instanceType,\n _ref19$domain = _ref19.domain,\n domain = _ref19$domain === void 0 ? location.hostname : _ref19$domain;\n\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.system.getConfig({\n instanceType: instanceType,\n domain: domain\n });\n });\n },\n getIntegrationPublic: function getIntegrationPublic(type) {\n var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.system.integrationPublic({\n type: type\n }, {\n requestBody: _objectSpread({}, data)\n });\n });\n },\n updateConfig: function updateConfig() {\n var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.wt.updateConfig({\n id: data.instanceType || _this.__instanceType\n }, {\n requestBody: _objectSpread({}, data)\n });\n });\n },\n admin: function admin() {\n var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.wt.admin({}, {\n requestBody: _objectSpread({\n instanceType: _this.__instanceType\n }, data)\n });\n });\n },\n analytics: function analytics() {\n var _ref20 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},\n action = _ref20.action,\n _ref20$startKey = _ref20.startKey,\n startKey = _ref20$startKey === void 0 ? null : _ref20$startKey,\n _ref20$limit = _ref20.limit,\n limit = _ref20$limit === void 0 ? 20 : _ref20$limit;\n\n var apiParams = _objectSpread({\n action: action,\n limit: limit\n }, startKey && {\n startKey: startKey\n });\n\n return _this.__privates.auth.__client.then(function (client) {\n return client.apis.wt.analytics({}, {\n requestBody: _objectSpread({\n instanceType: _this.__instanceType\n }, apiParams)\n });\n });\n }\n };\n};\n\n/* harmony default export */ __webpack_exports__[\"default\"] = (user);\n\n//# sourceURL=webpack://WatchTogetherSDK/./src/models/user.js?");
9269
9269
 
9270
9270
  /***/ }),
9271
9271
 
@@ -9481,7 +9481,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var aws_
9481
9481
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
9482
9482
 
9483
9483
  "use strict";
9484
- 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); if (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 = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { 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); return Constructor; }\n\n// Watch together janus webrtc library\n\n\n\n\nvar Room = /*#__PURE__*/function () {\n function Room(enableDebugFlag) {\n _classCallCheck(this, Room);\n\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.initialized = false;\n this.log = Room.noop;\n this.enableDebugFlag = enableDebugFlag;\n\n if (enableDebugFlag) {\n this.enableDebug();\n } // Let's get it started\n\n\n this.isReady = this.initialize();\n }\n\n _createClass(Room, [{\n key: \"initialize\",\n value: function initialize() {\n var _this = this;\n\n return new Promise(function (resolve, reject) {\n if (_this.initialized) {\n resolve(_this);\n }\n\n if (!Room.isWebrtcSupported()) {\n reject({\n type: 'error',\n id: 0,\n message: 'WebRTC is not supported on this platform',\n data: null\n });\n }\n\n Room.testSafariVp8().then(function (isVP8) {\n _this.setExitListeners();\n\n _this.safariVp8 = isVP8;\n _this.initialized = true;\n return webrtc_adapter__WEBPACK_IMPORTED_MODULE_0__[\"default\"].browserDetails.browser !== 'safari' || _this.safariVp8 //&& 'MediaSource' in window\n ? resolve(_this) : reject({\n type: 'error',\n id: 0,\n message: 'This browser is not supported',\n data: null\n });\n });\n });\n }\n }, {\n key: \"createSession\",\n value: function createSession() {\n var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'reactooroom';\n var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n var session = new RoomSession(this.enableDebugFlag, type, options);\n this.sessions.push(session);\n return session;\n }\n }, {\n key: \"closeSessionByConstructId\",\n value: function closeSessionByConstructId(constructId) {\n var _this2 = this;\n\n var sessionIndex = this.sessions.findIndex(function (session) {\n return session.constructId === constructId;\n });\n\n if (sessionIndex > -1) {\n return this.sessions[sessionIndex].destroy().then(function () {\n _this2.sessions.splice(sessionIndex, 1);\n\n return true;\n });\n }\n\n return Promise.resolve();\n }\n }, {\n key: \"closeSessionBySessionId\",\n value: function closeSessionBySessionId(sessionId) {\n var _this3 = this;\n\n var sessionIndex = this.sessions.findIndex(function (session) {\n return session.sessionId === sessionId;\n });\n\n if (sessionIndex > -1) {\n return this.sessions[sessionIndex].destroy().then(function () {\n _this3.sessions.splice(sessionIndex, 1);\n\n return true;\n });\n }\n\n return Promise.resolve();\n }\n }, {\n key: \"closeSessions\",\n value: function closeSessions() {\n var _this4 = this;\n\n this.sessions.forEach(function (session) {\n return session.destroy().catch(function (e) {\n return _this4.log(e);\n });\n });\n this.sessions.length = 0;\n }\n }, {\n key: \"setExitListeners\",\n value: function setExitListeners() {\n var _this5 = this;\n\n window.addEventListener('pagehide', function (event) {\n if (!event.persisted) {\n _this5.closeSessions();\n }\n });\n window.addEventListener('beforeunload', function () {\n _this5.closeSessions();\n });\n }\n }, {\n key: \"enableDebug\",\n value: function enableDebug() {\n this.log = console.log.bind(console);\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: \"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 }\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 key: \"noop\",\n value: function noop() {}\n }]);\n\n return Room;\n}();\n\nvar RoomSession = /*#__PURE__*/function () {\n function RoomSession(enableDebugFlag) {\n var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'reactooroom';\n var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {\n classroomObserverSubscribeToInstructor: false,\n classroomInstructorSubscribeToParticipants: false,\n safariBugHotfixEnabled: true\n };\n\n _classCallCheck(this, RoomSession);\n\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;\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; //this.pluginName = this.#sessionTypes[type];\n\n Object.assign(this, Object(_wt_emitter__WEBPACK_IMPORTED_MODULE_1__[\"default\"])());\n this.id = null;\n this.privateId = null;\n this.constructId = Room.randomString(16);\n this.sessionId = null;\n this.handleId = null;\n this.ws = null;\n this.isRestarting = false; // 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._log = RoomSession.noop;\n\n if (enableDebugFlag) {\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: \"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 _this6 = 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 = Room.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 _this6.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 _this6.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 (_this6.ws && _this6.ws.readyState === 1) {\n _this6.ws.send(JSON.stringify(requestData));\n }\n\n resolve();\n } else {\n if (_this6.ws && _this6.ws.readyState === 1) {\n _this6.ws.addEventListener('message', parseResponse);\n\n timeouId = setTimeout(function () {\n _this6.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 _this6.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 _this7 = this;\n\n if (this.disconnectingPromise || this.connectingPromise) {\n return;\n }\n\n if (this._retries < this._maxRetries) {\n setTimeout(function () {\n _this7._retries++;\n\n _this7._reconnect().catch(function (e) {\n _this7.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 _this8 = this;\n\n this._send({\n \"janus\": \"keepalive\"\n }).then(function (json) {\n if (json[\"janus\"] !== 'ack') {\n _this8.emit('error', {\n type: 'warning',\n id: 5,\n message: 'keepalive response suspicious',\n data: json[\"janus\"]\n });\n }\n }).catch(function (e) {\n _this8.emit('error', {\n type: 'warning',\n id: 6,\n message: 'keepalive dead',\n data: e\n });\n\n _this8._connectionClosed();\n });\n\n this._keepAliveId = setTimeout(function () {\n _this8._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 _this9 = 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 _this9._log('Remote userId: ', userId);\n\n var isClassroom = allowedInstructor !== null;\n var subscribeCondition = void 0;\n var subCondition = false;\n\n if (!isClassroom) {\n subscribeCondition = allowedObservers.indexOf(userId) === -1 && allowedTalkback.indexOf(_this9.userId) === -1;\n } else {\n // instructor -> everyone but observer\n if (_this9.options.classroomInstructorSubscribeToParticipants) {\n subCondition = _this9.userId === allowedInstructor && allowedObservers.indexOf(userId) === -1;\n }\n\n if (_this9.options.classroomObserverSubscribeToInstructor) {\n /*\n \t\t\tmonitor/talkback -> all but talkback\n \tobserver -> all but instructor and talkback\n \tinstructor -> no one\n \tparticipant -> only instructor, observer and talkback\n \t\n \t1st line -> Im not monitor/talkback and im not observer and im not instructor and user to subscribe is instructor or observer or talkback\n \t2nd line -> Im monitor/talkback and im not instructor and user connecting is not talkback\n \t3rd line -> Im observer and im not instructor and user connecting is not talkback\n \t\n */\n subscribeCondition = subCondition || !_this9.isMonitor && allowedObservers.indexOf(_this9.userId) === -1 && _this9.userId !== allowedInstructor && (userId === allowedInstructor || allowedObservers.indexOf(userId) > -1 || allowedTalkback.indexOf(userId) > -1) || _this9.isMonitor && _this9.userId !== allowedInstructor && allowedTalkback.indexOf(userId) === -1 || allowedObservers.indexOf(_this9.userId) > -1 && _this9.userId !== allowedInstructor && allowedTalkback.indexOf(userId) === -1;\n } else {\n /*\n \t\t\t\t\t\tmonitor/talkback -> all but talkback\n \tobserver -> all but instructor and talkback\n \tinstructor -> no one\n \tparticipant -> only instructor, observer and talkback\n \t\n \t1st line -> Im not monitor/talkback and im not observer and im not instructor and user to subscribe is instructor or observer or talkback\n \t2nd line -> Im monitor/talkback and im not instructor and user connecting is not talkback\n \t3rd line -> Im observer and im not instructor and user connecting is not instructor and its not talkback\n \t\n */\n subscribeCondition = subCondition || !_this9.isMonitor && allowedObservers.indexOf(_this9.userId) === -1 && _this9.userId !== allowedInstructor && (userId === allowedInstructor || allowedObservers.indexOf(userId) > -1 || allowedTalkback.indexOf(userId) > -1) || _this9.isMonitor && _this9.userId !== allowedInstructor && allowedTalkback.indexOf(userId) === -1 || allowedObservers.indexOf(_this9.userId) > -1 && _this9.userId !== allowedInstructor && userId !== allowedInstructor && allowedTalkback.indexOf(userId) === -1;\n }\n }\n\n if (subscribeCondition) {\n _this9._log('Creating user: ', userId);\n\n _this9._createParticipant(userId, id).then(function (handle) {\n return _this9.sendMessage(handle.handleId, {\n body: {\n \"request\": \"join\",\n \"room\": _this9.roomId,\n \"ptype\": \"subscriber\",\n \"feed\": id,\n \"private_id\": _this9.privateId,\n pin: _this9.pin\n }\n });\n }).catch(function (err) {\n _this9.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 _this9._log('Remote userId: ', userId);\n\n var isClassroom = allowedInstructor !== null;\n var subscribeCondition = void 0;\n var subCondition = false;\n\n if (!isClassroom) {\n subscribeCondition = allowedObservers.indexOf(userId) === -1 && allowedTalkback.indexOf(_this9.userId) === -1;\n } else {\n // instructor -> everyone but observer\n if (_this9.options.classroomInstructorSubscribeToParticipants) {\n subCondition = _this9.userId === allowedInstructor && allowedObservers.indexOf(userId) === -1;\n }\n\n if (_this9.options.classroomObserverSubscribeToInstructor) {\n /*\n \t\t\tmonitor/talkback -> all but talkback\n \tobserver -> all but instructor and talkback\n \tinstructor -> no one\n \tparticipant -> only instructor, observer and talkback\n \t\n \t1st line -> Im not monitor/talkback and im not observer and im not instructor and user to subscribe is instructor or observer or talkback\n \t2nd line -> Im monitor/talkback and im not instructor and user connecting is not talkback\n \t3rd line -> Im observer and im not instructor and user connecting is not talkback\n \t\n */\n subscribeCondition = subCondition || !_this9.isMonitor && allowedObservers.indexOf(_this9.userId) === -1 && _this9.userId !== allowedInstructor && (userId === allowedInstructor || allowedObservers.indexOf(userId) > -1 || allowedTalkback.indexOf(userId) > -1) || _this9.isMonitor && _this9.userId !== allowedInstructor && allowedTalkback.indexOf(userId) === -1 || allowedObservers.indexOf(_this9.userId) > -1 && _this9.userId !== allowedInstructor && allowedTalkback.indexOf(userId) === -1;\n } else {\n /*\n \t\t\t\t\t\tmonitor/talkback -> all but talkback\n \tobserver -> all but instructor and talkback\n \tinstructor -> no one\n \tparticipant -> only instructor, observer and talkback\n \t\n \t1st line -> Im not monitor/talkback and im not observer and im not instructor and user to subscribe is instructor or observer or talkback\n \t2nd line -> Im monitor/talkback and im not instructor and user connecting is not talkback\n \t3rd line -> Im observer and im not instructor and user connecting is not instructor and its not talkback\n \t\n */\n subscribeCondition = subCondition || !_this9.isMonitor && allowedObservers.indexOf(_this9.userId) === -1 && _this9.userId !== allowedInstructor && (userId === allowedInstructor || allowedObservers.indexOf(userId) > -1 || allowedTalkback.indexOf(userId) > -1) || _this9.isMonitor && _this9.userId !== allowedInstructor && allowedTalkback.indexOf(userId) === -1 || allowedObservers.indexOf(_this9.userId) > -1 && _this9.userId !== allowedInstructor && userId !== allowedInstructor && allowedTalkback.indexOf(userId) === -1;\n }\n }\n\n if (subscribeCondition) {\n _this9._log('Creating user: ', userId);\n\n _this9._createParticipant(userId, id).then(function (handle) {\n return _this9.sendMessage(handle.handleId, {\n body: {\n \"request\": \"join\",\n \"room\": _this9.roomId,\n \"ptype\": \"subscriber\",\n \"feed\": id,\n \"private_id\": _this9.privateId,\n pin: _this9.pin\n }\n });\n }).catch(function (err) {\n _this9.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 _this9.emit('error', err);\n });\n } else if (this.sessiontype === 'streaming') {\n this._publishRemote(this.handleId, jsep).catch(function (err) {\n _this9.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 (e) {\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 var _allowedTalkback = this._talkbackIds || [];\n\n var _allowedObservers = this._observerIds || [];\n\n var eventName = 'addRemoteParticipant';\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 this.emit(eventName, {\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 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 _this9.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 //TODO: find a better way\n if (!this.disconnectingPromise) {\n this._log('silent data event error');\n\n this.emit('error', {\n type: this.handleId === handleId ? 'error' : 'warning',\n id: 9,\n message: 'data event error',\n data: [handleId, data]\n });\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 _this10 = 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 ? _this10._send({\n \"janus\": \"detach\",\n \"handle_id\": handleId\n }, true) : Promise.resolve();\n }).finally(function () {\n try {\n if (handle.webrtcStuff.stream && !_this10.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 (removeHandle) {\n var handleIndex = _this10._participants.findIndex(function (p) {\n return p.handleId === handleId;\n });\n\n _this10._participants.splice(handleIndex, 1);\n }\n\n if (handleId === _this10.handleId) {\n _this10._isDataChannelOpen = false;\n _this10._isPublished = false;\n\n _this10.emit('published', {\n status: false,\n hasStream: false\n });\n\n _this10.emit('removeLocalParticipant', {\n id: handleId,\n userId: handle.userId\n });\n } else {\n var allowedTalkback = _this10._talkbackIds || [];\n var allowedObservers = _this10._observerIds || [];\n var allowedInstructor = _this10._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 _this10.emit(eventName, {\n id: handleId,\n userId: handle.userId\n });\n }\n\n return true;\n });\n }\n }, {\n key: \"_createParticipant\",\n value: function _createParticipant() {\n var _this11 = 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 _this11._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 _this12 = 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 (r) {\n _this12._hasJoined = false;\n\n _this12.emit('joined', false);\n }) : Promise.resolve();\n } // internal reconnect\n\n }, {\n key: \"_reconnect\",\n value: function _reconnect() {\n var _this13 = 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 _this13.emit('joining', 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._send({\n \"janus\": \"claim\"\n }).then(function (json) {\n _this13.sessionId = json[\"session_id\"] ? json[\"session_id\"] : json.data[\"id\"];\n\n _this13._startKeepAlive();\n\n _this13.connectingPromise = null;\n\n _this13.emit('joining', false);\n\n _this13._retries = 0;\n resolve(json);\n }).catch(function (error) {\n _this13.connectingPromise = null;\n\n _this13.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 _this13.ws.onerror = function (e) {\n _this13.connectingPromise = null;\n\n _this13.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 _this14 = 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 _this14.emit('joining', true);\n\n _this14.ws = new WebSocket(_this14.server, 'janus-protocol');\n _this14.__connectionClosedBoundFn = _this14._connectionClosed.bind(_this14);\n _this14.__handleWsEventsBoundFn = _this14._handleWsEvents.bind(_this14);\n\n _this14.ws.addEventListener('close', _this14.__connectionClosedBoundFn);\n\n _this14.ws.addEventListener('message', _this14.__handleWsEventsBoundFn);\n\n _this14.ws.onopen = function () {\n _this14._retries = 0;\n\n _this14._send({\n \"janus\": \"create\"\n }).then(function (json) {\n _this14.sessionId = json[\"session_id\"] ? json[\"session_id\"] : json.data[\"id\"];\n\n _this14._startKeepAlive();\n\n return 1;\n }).then(function () {\n return _this14._createParticipant(userId);\n }).then(function (handle) {\n _this14.handleId = handle.handleId;\n return 1;\n }).then(function () {\n return _this14._joinRoom(roomId, pin, userId);\n }).then(function () {\n _this14.connectingPromise = null;\n\n _this14.emit('joining', false);\n\n resolve(_this14);\n }).catch(function (error) {\n _this14.connectingPromise = null;\n\n _this14.emit('joining', false);\n\n reject({\n type: 'error',\n id: 13,\n message: 'connection error',\n data: error\n });\n });\n };\n\n _this14.ws.onerror = function (e) {\n _this14.connectingPromise = null;\n\n _this14.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 _this15 = this;\n\n var dontWaitForResponses = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;\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 _this15._removeParticipant(p.handleId);\n })).finally(function () {\n _this15._wipeListeners();\n\n _this15._send({\n \"janus\": \"destroy\"\n }, true);\n\n if (_this15.ws && _this15.ws.readyState === 1) {\n _this15.ws.close();\n }\n\n _this15.sessionId = null; //TODO: Just in case something crashed along the way\n\n _this15._isPublished = false;\n _this15._hasJoined = false;\n\n _this15.emit('published', {\n status: false,\n hasStream: false\n });\n\n _this15.emit('joined', false);\n\n _this15.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 _this16 = 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 _this16.emit('streamStarting', true);\n\n _this16.ws = new WebSocket(_this16.server, 'janus-protocol');\n _this16.__connectionClosedBoundFn = _this16._connectionClosed.bind(_this16);\n _this16.__handleWsEventsBoundFn = _this16._handleWsEvents.bind(_this16);\n\n _this16.ws.addEventListener('close', _this16.__connectionClosedBoundFn);\n\n _this16.ws.addEventListener('message', _this16.__handleWsEventsBoundFn);\n\n _this16.ws.onopen = function () {\n _this16._retries = 0;\n\n _this16._send({\n \"janus\": \"create\"\n }).then(function (json) {\n _this16.sessionId = json[\"session_id\"] ? json[\"session_id\"] : json.data[\"id\"];\n\n _this16._startKeepAlive();\n\n return 1;\n }).then(function () {\n return _this16._createParticipant(userId);\n }).then(function (handle) {\n _this16.handleId = handle.handleId;\n return 1;\n }).then(function () {\n return _this16._watchStream(streamId);\n }).then(function () {\n _this16.connectingPromise = null;\n\n _this16.emit('streamStarting', false);\n\n resolve(_this16);\n }).catch(function (error) {\n _this16.connectingPromise = null;\n\n _this16.emit('streamStarting', false);\n\n reject({\n type: 'error',\n id: 13,\n message: 'connection error',\n data: error\n });\n });\n };\n\n _this16.ws.onerror = function (e) {\n _this16.connectingPromise = null;\n\n _this16.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 _this17 = 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 _this17._removeParticipant(_this17.handleId);\n }).finally(function () {\n _this17._wipeListeners();\n\n _this17._send({\n \"janus\": \"destroy\"\n }, true);\n\n if (_this17.ws && _this17.ws.readyState === 1) {\n _this17.ws.close();\n }\n\n _this17.sessionId = null;\n _this17._isStreaming = false;\n\n _this17.emit('streaming', false); // last event\n\n\n _this17.emit('disconnect');\n\n _this17.disconnectingPromise = null;\n return Promise.resolve('Disconnected');\n });\n return this.disconnectingPromise;\n }\n }, {\n key: \"destroy\",\n value: function destroy() {\n var _this18 = this;\n\n var dontWaitForResponses = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;\n\n if (this.sessiontype === 'reactooroom') {\n return this.disconnect(dontWaitForResponses).then(function () {\n _this18.clear();\n\n return true;\n });\n } else if (this.sessiontype === 'streaming') {\n return this.stopStream(dontWaitForResponses).then(function () {\n _this18.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 _this19 = 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 _this19._iceRestart(handleId);\n }\n\n _this19.emit('connectionState', [handleId, handleId === _this19.handleId, config.pc.connectionState]);\n };\n\n config.pc.oniceconnectionstatechange = function () {\n if (config.pc.iceConnectionState === 'failed') {\n _this19._iceRestart(handleId);\n }\n\n _this19.emit('iceState', [handleId, handleId === _this19.handleId, config.pc.iceConnectionState]);\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 _this19._sendTrickleCandidate(handleId, {\n \"completed\": true\n }).catch(function (e) {\n _this19.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 _this19._sendTrickleCandidate(handleId, candidate).catch(function (e) {\n _this19.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 var allowedTalkback = _this19._talkbackIds || [];\n var allowedObservers = _this19._observerIds || [];\n var allowedInstructor = _this19._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 _this19._log(eventName, 'ontrack');\n\n _this19.emit(eventName, {\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 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 var allowedTalkback = _this19._talkbackIds || [];\n var allowedObservers = _this19._observerIds || [];\n var allowedInstructor = _this19._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 _this19._log(eventName, 'onended');\n\n if (config.stream) {\n config.stream && config.stream.removeTrack(ev.target);\n\n _this19.emit(eventName, {\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 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 _this19._log('remoteTrackMuted', 'onmute');\n\n _this19.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 _this19._log('remoteTrackMuted', 'onunmute');\n\n _this19.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 _this19._handleDataEvents(handleId, 'message', event.data);\n };\n\n var onDataChannelStateChange = function onDataChannelStateChange(event) {\n _this19._handleDataEvents(handleId, 'state', config.dataChannel.readyState);\n };\n\n var onDataChannelError = function onDataChannelError(error) {\n _this19._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: 16,\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 _this20 = 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 _this20.sendMessage(handleId, {\n body: _objectSpread({\n \"request\": \"configure\",\n \"audio\": hasAudio,\n \"video\": hasVideo,\n \"data\": true\n }, _this20.recordingFilename ? {\n filename: _this20.recordingFilename\n } : {}),\n jsep: jsep\n });\n }).then(function (r) {\n config.isIceRestarting = false;\n\n _this20._log('ICE restart success');\n }).catch(function (e) {\n config.isIceRestarting = false;\n\n _this20.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: 17,\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 _this21 = this;\n\n var handle = this._getHandle(handleId);\n\n if (!handle) {\n return Promise.reject({\n type: 'warning',\n id: 18,\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 _this21._createAO('answer', handleId, false, [false, true, false, true]).then(function (_jsep) {\n if (!_jsep) {\n _this21.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 _this21.sendMessage(handleId, {\n \"body\": _objectSpread(_objectSpread({\n \"request\": \"start\"\n }, _this21.roomId && {\n \"room\": _this21.roomId\n }), _this21.pin && {\n pin: _this21.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 _this22 = 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 _this22.sendMessage(_this22.handleId, {\n body: _objectSpread({\n \"request\": \"configure\",\n \"audio\": hasAudio,\n \"video\": hasVideo,\n \"data\": true\n }, _this22.recordingFilename ? {\n filename: _this22.recordingFilename\n } : {}),\n jsep: jsep\n });\n }).then(function (r) {\n if (_this22._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 _this22.off('dataChannel', __, _this22);\n\n resolve(_this22);\n }\n };\n\n var ___ = setTimeout(function () {\n _this22.off('dataChannel', __, _this22);\n\n reject({\n type: 'error',\n id: 27,\n message: 'Data channel did not open',\n data: null\n });\n }, 5000);\n\n _this22.on('dataChannel', __, _this22);\n });\n }\n }).then(function (r) {\n _this22._isPublished = true;\n\n _this22.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 _this22.emit('published', {\n status: true,\n hasStream: !!config.stream\n });\n\n _this22.emit('publishing', false);\n\n _this22.emit('localHasVideo', hasVideo);\n\n _this22.emit('localHasAudio', hasAudio);\n\n _this22.emit('localMuted', {\n type: 'video',\n value: isVideoMuted\n });\n\n _this22.emit('localMuted', {\n type: 'audio',\n value: isAudioMuted\n });\n\n return r;\n }).catch(function (e) {\n _this22.emit('publishing', false);\n\n return Promise.reject(e);\n });\n }\n }, {\n key: \"unpublishLocal\",\n value: function unpublishLocal() {\n var _this23 = 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 _this23._isPublished = false;\n\n _this23.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.options.safariBugHotfixEnabled && webrtc_adapter__WEBPACK_IMPORTED_MODULE_0__[\"default\"].browserDetails.browser === 'safari') {\n this.isVideoMuted = !this.isVideoMuted;\n } else 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() {} //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 // #sessionTypes = {\n // 'reactooroom': 'janus.plugin.reactooroom',\n // 'streaming': 'janus.plugin.streaming'\n // };\n\n }, {\n key: \"sessionTypes\",\n value: function sessionTypes() {\n return {\n 'reactooroom': 'janus.plugin.reactooroom',\n 'streaming': 'janus.plugin.streaming'\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/* harmony default export */ __webpack_exports__[\"default\"] = (Room);\n\n//# sourceURL=webpack://WatchTogetherSDK/./src/modules/wt-room.js?");
9484
+ 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); if (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 = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { 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); return Constructor; }\n\n// Watch together janus webrtc library\n\n\n\n\nvar Room = /*#__PURE__*/function () {\n function Room(enableDebugFlag) {\n _classCallCheck(this, Room);\n\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.initialized = false;\n this.log = Room.noop;\n this.enableDebugFlag = enableDebugFlag;\n\n if (enableDebugFlag) {\n this.enableDebug();\n } // Let's get it started\n\n\n this.isReady = this.initialize();\n }\n\n _createClass(Room, [{\n key: \"initialize\",\n value: function initialize() {\n var _this = this;\n\n return new Promise(function (resolve, reject) {\n if (_this.initialized) {\n resolve(_this);\n }\n\n if (!Room.isWebrtcSupported()) {\n reject({\n type: 'error',\n id: 0,\n message: 'WebRTC is not supported on this platform',\n data: null\n });\n }\n\n Room.testSafariVp8().then(function (isVP8) {\n _this.setExitListeners();\n\n _this.safariVp8 = isVP8;\n _this.initialized = true;\n return webrtc_adapter__WEBPACK_IMPORTED_MODULE_0__[\"default\"].browserDetails.browser !== 'safari' || _this.safariVp8 //&& 'MediaSource' in window\n ? resolve(_this) : reject({\n type: 'error',\n id: 0,\n message: 'This browser is not supported',\n data: null\n });\n });\n });\n }\n }, {\n key: \"createSession\",\n value: function createSession() {\n var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'reactooroom';\n var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n var session = new RoomSession(this.enableDebugFlag, type, options);\n this.sessions.push(session);\n return session;\n }\n }, {\n key: \"closeSessionByConstructId\",\n value: function closeSessionByConstructId(constructId) {\n var _this2 = this;\n\n var sessionIndex = this.sessions.findIndex(function (session) {\n return session.constructId === constructId;\n });\n\n if (sessionIndex > -1) {\n return this.sessions[sessionIndex].destroy().then(function () {\n _this2.sessions.splice(sessionIndex, 1);\n\n return true;\n });\n }\n\n return Promise.resolve();\n }\n }, {\n key: \"closeSessionBySessionId\",\n value: function closeSessionBySessionId(sessionId) {\n var _this3 = this;\n\n var sessionIndex = this.sessions.findIndex(function (session) {\n return session.sessionId === sessionId;\n });\n\n if (sessionIndex > -1) {\n return this.sessions[sessionIndex].destroy().then(function () {\n _this3.sessions.splice(sessionIndex, 1);\n\n return true;\n });\n }\n\n return Promise.resolve();\n }\n }, {\n key: \"closeSessions\",\n value: function closeSessions() {\n var _this4 = this;\n\n this.sessions.forEach(function (session) {\n return session.destroy().catch(function (e) {\n return _this4.log(e);\n });\n });\n this.sessions.length = 0;\n }\n }, {\n key: \"setExitListeners\",\n value: function setExitListeners() {\n var _this5 = this;\n\n window.addEventListener('pagehide', function (event) {\n if (!event.persisted) {\n _this5.closeSessions();\n }\n });\n window.addEventListener('beforeunload', function () {\n _this5.closeSessions();\n });\n }\n }, {\n key: \"enableDebug\",\n value: function enableDebug() {\n this.log = console.log.bind(console);\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: \"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 }\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 key: \"noop\",\n value: function noop() {}\n }]);\n\n return Room;\n}();\n\nvar RoomSession = /*#__PURE__*/function () {\n function RoomSession(enableDebugFlag) {\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 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;\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 = _objectSpread(_objectSpread({}, {\n classroomObserverSubscribeToInstructor: false,\n classroomInstructorSubscribeToParticipants: false,\n safariBugHotfixEnabled: webrtc_adapter__WEBPACK_IMPORTED_MODULE_0__[\"default\"].browserDetails.browser === 'safari' && webrtc_adapter__WEBPACK_IMPORTED_MODULE_0__[\"default\"].browserDetails.version < 605\n }), {}, {\n options: options\n }); //this.pluginName = this.#sessionTypes[type];\n\n Object.assign(this, Object(_wt_emitter__WEBPACK_IMPORTED_MODULE_1__[\"default\"])());\n this.id = null;\n this.privateId = null;\n this.constructId = Room.randomString(16);\n this.sessionId = null;\n this.handleId = null;\n this.ws = null;\n this.isRestarting = false; // 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._log = RoomSession.noop;\n\n if (enableDebugFlag) {\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: \"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 _this6 = 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 = Room.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 _this6.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 _this6.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 (_this6.ws && _this6.ws.readyState === 1) {\n _this6.ws.send(JSON.stringify(requestData));\n }\n\n resolve();\n } else {\n if (_this6.ws && _this6.ws.readyState === 1) {\n _this6.ws.addEventListener('message', parseResponse);\n\n timeouId = setTimeout(function () {\n _this6.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 _this6.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 _this7 = this;\n\n if (this.disconnectingPromise || this.connectingPromise) {\n return;\n }\n\n if (this._retries < this._maxRetries) {\n setTimeout(function () {\n _this7._retries++;\n\n _this7._reconnect().catch(function (e) {\n _this7.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 _this8 = this;\n\n this._send({\n \"janus\": \"keepalive\"\n }).then(function (json) {\n if (json[\"janus\"] !== 'ack') {\n _this8.emit('error', {\n type: 'warning',\n id: 5,\n message: 'keepalive response suspicious',\n data: json[\"janus\"]\n });\n }\n }).catch(function (e) {\n _this8.emit('error', {\n type: 'warning',\n id: 6,\n message: 'keepalive dead',\n data: e\n });\n\n _this8._connectionClosed();\n });\n\n this._keepAliveId = setTimeout(function () {\n _this8._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 _this9 = 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 _this9._log('Remote userId: ', userId);\n\n var isClassroom = allowedInstructor !== null;\n var subscribeCondition = void 0;\n var subCondition = false;\n\n if (!isClassroom) {\n subscribeCondition = allowedObservers.indexOf(userId) === -1 && allowedTalkback.indexOf(_this9.userId) === -1;\n } else {\n // instructor -> everyone but observer\n if (_this9.options.classroomInstructorSubscribeToParticipants) {\n subCondition = _this9.userId === allowedInstructor && allowedObservers.indexOf(userId) === -1;\n }\n\n if (_this9.options.classroomObserverSubscribeToInstructor) {\n /*\n \t\t\tmonitor/talkback -> all but talkback\n \tobserver -> all but instructor and talkback\n \tinstructor -> no one\n \tparticipant -> only instructor, observer and talkback\n \t\n \t1st line -> Im not monitor/talkback and im not observer and im not instructor and user to subscribe is instructor or observer or talkback\n \t2nd line -> Im monitor/talkback and im not instructor and user connecting is not talkback\n \t3rd line -> Im observer and im not instructor and user connecting is not talkback\n \t\n */\n subscribeCondition = subCondition || !_this9.isMonitor && allowedObservers.indexOf(_this9.userId) === -1 && _this9.userId !== allowedInstructor && (userId === allowedInstructor || allowedObservers.indexOf(userId) > -1 || allowedTalkback.indexOf(userId) > -1) || _this9.isMonitor && _this9.userId !== allowedInstructor && allowedTalkback.indexOf(userId) === -1 || allowedObservers.indexOf(_this9.userId) > -1 && _this9.userId !== allowedInstructor && allowedTalkback.indexOf(userId) === -1;\n } else {\n /*\n \t\t\t\t\t\tmonitor/talkback -> all but talkback\n \tobserver -> all but instructor and talkback\n \tinstructor -> no one\n \tparticipant -> only instructor, observer and talkback\n \t\n \t1st line -> Im not monitor/talkback and im not observer and im not instructor and user to subscribe is instructor or observer or talkback\n \t2nd line -> Im monitor/talkback and im not instructor and user connecting is not talkback\n \t3rd line -> Im observer and im not instructor and user connecting is not instructor and its not talkback\n \t\n */\n subscribeCondition = subCondition || !_this9.isMonitor && allowedObservers.indexOf(_this9.userId) === -1 && _this9.userId !== allowedInstructor && (userId === allowedInstructor || allowedObservers.indexOf(userId) > -1 || allowedTalkback.indexOf(userId) > -1) || _this9.isMonitor && _this9.userId !== allowedInstructor && allowedTalkback.indexOf(userId) === -1 || allowedObservers.indexOf(_this9.userId) > -1 && _this9.userId !== allowedInstructor && userId !== allowedInstructor && allowedTalkback.indexOf(userId) === -1;\n }\n }\n\n if (subscribeCondition) {\n _this9._log('Creating user: ', userId);\n\n _this9._createParticipant(userId, id).then(function (handle) {\n return _this9.sendMessage(handle.handleId, {\n body: {\n \"request\": \"join\",\n \"room\": _this9.roomId,\n \"ptype\": \"subscriber\",\n \"feed\": id,\n \"private_id\": _this9.privateId,\n pin: _this9.pin\n }\n });\n }).catch(function (err) {\n _this9.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 _this9._log('Remote userId: ', userId);\n\n var isClassroom = allowedInstructor !== null;\n var subscribeCondition = void 0;\n var subCondition = false;\n\n if (!isClassroom) {\n subscribeCondition = allowedObservers.indexOf(userId) === -1 && allowedTalkback.indexOf(_this9.userId) === -1;\n } else {\n // instructor -> everyone but observer\n if (_this9.options.classroomInstructorSubscribeToParticipants) {\n subCondition = _this9.userId === allowedInstructor && allowedObservers.indexOf(userId) === -1;\n }\n\n if (_this9.options.classroomObserverSubscribeToInstructor) {\n /*\n \t\t\tmonitor/talkback -> all but talkback\n \tobserver -> all but instructor and talkback\n \tinstructor -> no one\n \tparticipant -> only instructor, observer and talkback\n \t\n \t1st line -> Im not monitor/talkback and im not observer and im not instructor and user to subscribe is instructor or observer or talkback\n \t2nd line -> Im monitor/talkback and im not instructor and user connecting is not talkback\n \t3rd line -> Im observer and im not instructor and user connecting is not talkback\n \t\n */\n subscribeCondition = subCondition || !_this9.isMonitor && allowedObservers.indexOf(_this9.userId) === -1 && _this9.userId !== allowedInstructor && (userId === allowedInstructor || allowedObservers.indexOf(userId) > -1 || allowedTalkback.indexOf(userId) > -1) || _this9.isMonitor && _this9.userId !== allowedInstructor && allowedTalkback.indexOf(userId) === -1 || allowedObservers.indexOf(_this9.userId) > -1 && _this9.userId !== allowedInstructor && allowedTalkback.indexOf(userId) === -1;\n } else {\n /*\n \t\t\t\t\t\tmonitor/talkback -> all but talkback\n \tobserver -> all but instructor and talkback\n \tinstructor -> no one\n \tparticipant -> only instructor, observer and talkback\n \t\n \t1st line -> Im not monitor/talkback and im not observer and im not instructor and user to subscribe is instructor or observer or talkback\n \t2nd line -> Im monitor/talkback and im not instructor and user connecting is not talkback\n \t3rd line -> Im observer and im not instructor and user connecting is not instructor and its not talkback\n \t\n */\n subscribeCondition = subCondition || !_this9.isMonitor && allowedObservers.indexOf(_this9.userId) === -1 && _this9.userId !== allowedInstructor && (userId === allowedInstructor || allowedObservers.indexOf(userId) > -1 || allowedTalkback.indexOf(userId) > -1) || _this9.isMonitor && _this9.userId !== allowedInstructor && allowedTalkback.indexOf(userId) === -1 || allowedObservers.indexOf(_this9.userId) > -1 && _this9.userId !== allowedInstructor && userId !== allowedInstructor && allowedTalkback.indexOf(userId) === -1;\n }\n }\n\n if (subscribeCondition) {\n _this9._log('Creating user: ', userId);\n\n _this9._createParticipant(userId, id).then(function (handle) {\n return _this9.sendMessage(handle.handleId, {\n body: {\n \"request\": \"join\",\n \"room\": _this9.roomId,\n \"ptype\": \"subscriber\",\n \"feed\": id,\n \"private_id\": _this9.privateId,\n pin: _this9.pin\n }\n });\n }).catch(function (err) {\n _this9.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 _this9.emit('error', err);\n });\n } else if (this.sessiontype === 'streaming') {\n this._publishRemote(this.handleId, jsep).catch(function (err) {\n _this9.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 (e) {\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 var _allowedTalkback = this._talkbackIds || [];\n\n var _allowedObservers = this._observerIds || [];\n\n var eventName = 'addRemoteParticipant';\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 this.emit(eventName, {\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 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 _this9.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 //TODO: find a better way\n if (!this.disconnectingPromise) {\n this._log('silent data event error');\n\n this.emit('error', {\n type: this.handleId === handleId ? 'error' : 'warning',\n id: 9,\n message: 'data event error',\n data: [handleId, data]\n });\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 _this10 = 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 ? _this10._send({\n \"janus\": \"detach\",\n \"handle_id\": handleId\n }, true) : Promise.resolve();\n }).finally(function () {\n try {\n if (handle.webrtcStuff.stream && !_this10.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 (removeHandle) {\n var handleIndex = _this10._participants.findIndex(function (p) {\n return p.handleId === handleId;\n });\n\n _this10._participants.splice(handleIndex, 1);\n }\n\n if (handleId === _this10.handleId) {\n _this10._isDataChannelOpen = false;\n _this10._isPublished = false;\n\n _this10.emit('published', {\n status: false,\n hasStream: false\n });\n\n _this10.emit('removeLocalParticipant', {\n id: handleId,\n userId: handle.userId\n });\n } else {\n var allowedTalkback = _this10._talkbackIds || [];\n var allowedObservers = _this10._observerIds || [];\n var allowedInstructor = _this10._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 _this10.emit(eventName, {\n id: handleId,\n userId: handle.userId\n });\n }\n\n return true;\n });\n }\n }, {\n key: \"_createParticipant\",\n value: function _createParticipant() {\n var _this11 = 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 _this11._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 _this12 = 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 (r) {\n _this12._hasJoined = false;\n\n _this12.emit('joined', false);\n }) : Promise.resolve();\n } // internal reconnect\n\n }, {\n key: \"_reconnect\",\n value: function _reconnect() {\n var _this13 = 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 _this13.emit('joining', 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._send({\n \"janus\": \"claim\"\n }).then(function (json) {\n _this13.sessionId = json[\"session_id\"] ? json[\"session_id\"] : json.data[\"id\"];\n\n _this13._startKeepAlive();\n\n _this13.connectingPromise = null;\n\n _this13.emit('joining', false);\n\n _this13._retries = 0;\n resolve(json);\n }).catch(function (error) {\n _this13.connectingPromise = null;\n\n _this13.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 _this13.ws.onerror = function (e) {\n _this13.connectingPromise = null;\n\n _this13.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 _this14 = 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 _this14.emit('joining', true);\n\n _this14.ws = new WebSocket(_this14.server, 'janus-protocol');\n _this14.__connectionClosedBoundFn = _this14._connectionClosed.bind(_this14);\n _this14.__handleWsEventsBoundFn = _this14._handleWsEvents.bind(_this14);\n\n _this14.ws.addEventListener('close', _this14.__connectionClosedBoundFn);\n\n _this14.ws.addEventListener('message', _this14.__handleWsEventsBoundFn);\n\n _this14.ws.onopen = function () {\n _this14._retries = 0;\n\n _this14._send({\n \"janus\": \"create\"\n }).then(function (json) {\n _this14.sessionId = json[\"session_id\"] ? json[\"session_id\"] : json.data[\"id\"];\n\n _this14._startKeepAlive();\n\n return 1;\n }).then(function () {\n return _this14._createParticipant(userId);\n }).then(function (handle) {\n _this14.handleId = handle.handleId;\n return 1;\n }).then(function () {\n return _this14._joinRoom(roomId, pin, userId);\n }).then(function () {\n _this14.connectingPromise = null;\n\n _this14.emit('joining', false);\n\n resolve(_this14);\n }).catch(function (error) {\n _this14.connectingPromise = null;\n\n _this14.emit('joining', false);\n\n reject({\n type: 'error',\n id: 13,\n message: 'connection error',\n data: error\n });\n });\n };\n\n _this14.ws.onerror = function (e) {\n _this14.connectingPromise = null;\n\n _this14.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 _this15 = this;\n\n var dontWaitForResponses = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;\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 _this15._removeParticipant(p.handleId);\n })).finally(function () {\n _this15._wipeListeners();\n\n _this15._send({\n \"janus\": \"destroy\"\n }, true);\n\n if (_this15.ws && _this15.ws.readyState === 1) {\n _this15.ws.close();\n }\n\n _this15.sessionId = null; //TODO: Just in case something crashed along the way\n\n _this15._isPublished = false;\n _this15._hasJoined = false;\n\n _this15.emit('published', {\n status: false,\n hasStream: false\n });\n\n _this15.emit('joined', false);\n\n _this15.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 _this16 = 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 _this16.emit('streamStarting', true);\n\n _this16.ws = new WebSocket(_this16.server, 'janus-protocol');\n _this16.__connectionClosedBoundFn = _this16._connectionClosed.bind(_this16);\n _this16.__handleWsEventsBoundFn = _this16._handleWsEvents.bind(_this16);\n\n _this16.ws.addEventListener('close', _this16.__connectionClosedBoundFn);\n\n _this16.ws.addEventListener('message', _this16.__handleWsEventsBoundFn);\n\n _this16.ws.onopen = function () {\n _this16._retries = 0;\n\n _this16._send({\n \"janus\": \"create\"\n }).then(function (json) {\n _this16.sessionId = json[\"session_id\"] ? json[\"session_id\"] : json.data[\"id\"];\n\n _this16._startKeepAlive();\n\n return 1;\n }).then(function () {\n return _this16._createParticipant(userId);\n }).then(function (handle) {\n _this16.handleId = handle.handleId;\n return 1;\n }).then(function () {\n return _this16._watchStream(streamId);\n }).then(function () {\n _this16.connectingPromise = null;\n\n _this16.emit('streamStarting', false);\n\n resolve(_this16);\n }).catch(function (error) {\n _this16.connectingPromise = null;\n\n _this16.emit('streamStarting', false);\n\n reject({\n type: 'error',\n id: 13,\n message: 'connection error',\n data: error\n });\n });\n };\n\n _this16.ws.onerror = function (e) {\n _this16.connectingPromise = null;\n\n _this16.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 _this17 = 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 _this17._removeParticipant(_this17.handleId);\n }).finally(function () {\n _this17._wipeListeners();\n\n _this17._send({\n \"janus\": \"destroy\"\n }, true);\n\n if (_this17.ws && _this17.ws.readyState === 1) {\n _this17.ws.close();\n }\n\n _this17.sessionId = null;\n _this17._isStreaming = false;\n\n _this17.emit('streaming', false); // last event\n\n\n _this17.emit('disconnect');\n\n _this17.disconnectingPromise = null;\n return Promise.resolve('Disconnected');\n });\n return this.disconnectingPromise;\n }\n }, {\n key: \"destroy\",\n value: function destroy() {\n var _this18 = this;\n\n var dontWaitForResponses = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;\n\n if (this.sessiontype === 'reactooroom') {\n return this.disconnect(dontWaitForResponses).then(function () {\n _this18.clear();\n\n return true;\n });\n } else if (this.sessiontype === 'streaming') {\n return this.stopStream(dontWaitForResponses).then(function () {\n _this18.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 _this19 = 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 _this19._iceRestart(handleId);\n }\n\n _this19.emit('connectionState', [handleId, handleId === _this19.handleId, config.pc.connectionState]);\n };\n\n config.pc.oniceconnectionstatechange = function () {\n if (config.pc.iceConnectionState === 'failed') {\n _this19._iceRestart(handleId);\n }\n\n _this19.emit('iceState', [handleId, handleId === _this19.handleId, config.pc.iceConnectionState]);\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 _this19._sendTrickleCandidate(handleId, {\n \"completed\": true\n }).catch(function (e) {\n _this19.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 _this19._sendTrickleCandidate(handleId, candidate).catch(function (e) {\n _this19.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 var allowedTalkback = _this19._talkbackIds || [];\n var allowedObservers = _this19._observerIds || [];\n var allowedInstructor = _this19._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 _this19._log(eventName, 'ontrack');\n\n _this19.emit(eventName, {\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 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 var allowedTalkback = _this19._talkbackIds || [];\n var allowedObservers = _this19._observerIds || [];\n var allowedInstructor = _this19._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 _this19._log(eventName, 'onended');\n\n if (config.stream) {\n config.stream && config.stream.removeTrack(ev.target);\n\n _this19.emit(eventName, {\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 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 _this19._log('remoteTrackMuted', 'onmute');\n\n _this19.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 _this19._log('remoteTrackMuted', 'onunmute');\n\n _this19.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 _this19._handleDataEvents(handleId, 'message', event.data);\n };\n\n var onDataChannelStateChange = function onDataChannelStateChange(event) {\n _this19._handleDataEvents(handleId, 'state', config.dataChannel.readyState);\n };\n\n var onDataChannelError = function onDataChannelError(error) {\n _this19._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: 16,\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 _this20 = 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 _this20.sendMessage(handleId, {\n body: _objectSpread({\n \"request\": \"configure\",\n \"audio\": hasAudio,\n \"video\": hasVideo,\n \"data\": true\n }, _this20.recordingFilename ? {\n filename: _this20.recordingFilename\n } : {}),\n jsep: jsep\n });\n }).then(function (r) {\n config.isIceRestarting = false;\n\n _this20._log('ICE restart success');\n }).catch(function (e) {\n config.isIceRestarting = false;\n\n _this20.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: 17,\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 _this21 = this;\n\n var handle = this._getHandle(handleId);\n\n if (!handle) {\n return Promise.reject({\n type: 'warning',\n id: 18,\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 _this21._createAO('answer', handleId, false, [false, true, false, true]).then(function (_jsep) {\n if (!_jsep) {\n _this21.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 _this21.sendMessage(handleId, {\n \"body\": _objectSpread(_objectSpread({\n \"request\": \"start\"\n }, _this21.roomId && {\n \"room\": _this21.roomId\n }), _this21.pin && {\n pin: _this21.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 _this22 = 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 _this22.sendMessage(_this22.handleId, {\n body: _objectSpread({\n \"request\": \"configure\",\n \"audio\": hasAudio,\n \"video\": hasVideo,\n \"data\": true\n }, _this22.recordingFilename ? {\n filename: _this22.recordingFilename\n } : {}),\n jsep: jsep\n });\n }).then(function (r) {\n if (_this22._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 _this22.off('dataChannel', __, _this22);\n\n resolve(_this22);\n }\n };\n\n var ___ = setTimeout(function () {\n _this22.off('dataChannel', __, _this22);\n\n reject({\n type: 'error',\n id: 27,\n message: 'Data channel did not open',\n data: null\n });\n }, 5000);\n\n _this22.on('dataChannel', __, _this22);\n });\n }\n }).then(function (r) {\n _this22._isPublished = true;\n\n _this22.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 _this22.emit('published', {\n status: true,\n hasStream: !!config.stream\n });\n\n _this22.emit('publishing', false);\n\n _this22.emit('localHasVideo', hasVideo);\n\n _this22.emit('localHasAudio', hasAudio);\n\n _this22.emit('localMuted', {\n type: 'video',\n value: isVideoMuted\n });\n\n _this22.emit('localMuted', {\n type: 'audio',\n value: isAudioMuted\n });\n\n return r;\n }).catch(function (e) {\n _this22.emit('publishing', false);\n\n return Promise.reject(e);\n });\n }\n }, {\n key: \"unpublishLocal\",\n value: function unpublishLocal() {\n var _this23 = 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 _this23._isPublished = false;\n\n _this23.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.options.safariBugHotfixEnabled) {\n this.isVideoMuted = !this.isVideoMuted;\n } else 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() {} //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 // #sessionTypes = {\n // 'reactooroom': 'janus.plugin.reactooroom',\n // 'streaming': 'janus.plugin.streaming'\n // };\n\n }, {\n key: \"sessionTypes\",\n value: function sessionTypes() {\n return {\n 'reactooroom': 'janus.plugin.reactooroom',\n 'streaming': 'janus.plugin.streaming'\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/* harmony default export */ __webpack_exports__[\"default\"] = (Room);\n\n//# sourceURL=webpack://WatchTogetherSDK/./src/modules/wt-room.js?");
9485
9485
 
9486
9486
  /***/ }),
9487
9487