@webex/plugin-meetings 3.0.0-beta.1 → 3.0.0-beta.2

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.
Files changed (111) hide show
  1. package/dist/common/errors/webex-errors.js +5 -29
  2. package/dist/common/errors/webex-errors.js.map +1 -1
  3. package/dist/constants.js +15 -74
  4. package/dist/constants.js.map +1 -1
  5. package/dist/media/index.js +68 -213
  6. package/dist/media/index.js.map +1 -1
  7. package/dist/media/internal-media-core-wrapper.js +22 -0
  8. package/dist/media/internal-media-core-wrapper.js.map +1 -0
  9. package/dist/media/properties.js +20 -25
  10. package/dist/media/properties.js.map +1 -1
  11. package/dist/media/util.js +0 -27
  12. package/dist/media/util.js.map +1 -1
  13. package/dist/meeting/index.js +694 -432
  14. package/dist/meeting/index.js.map +1 -1
  15. package/dist/meeting/request.js +1 -0
  16. package/dist/meeting/request.js.map +1 -1
  17. package/dist/meeting/util.js +3 -44
  18. package/dist/meeting/util.js.map +1 -1
  19. package/dist/meetings/index.js +64 -5
  20. package/dist/meetings/index.js.map +1 -1
  21. package/dist/meetings/util.js +24 -1
  22. package/dist/meetings/util.js.map +1 -1
  23. package/dist/members/index.js +68 -0
  24. package/dist/members/index.js.map +1 -1
  25. package/dist/multistream/mediaRequestManager.js +132 -0
  26. package/dist/multistream/mediaRequestManager.js.map +1 -0
  27. package/dist/multistream/multistreamMedia.js +116 -0
  28. package/dist/multistream/multistreamMedia.js.map +1 -0
  29. package/dist/multistream/receiveSlot.js +209 -0
  30. package/dist/multistream/receiveSlot.js.map +1 -0
  31. package/dist/multistream/receiveSlotManager.js +195 -0
  32. package/dist/multistream/receiveSlotManager.js.map +1 -0
  33. package/dist/multistream/remoteMedia.js +284 -0
  34. package/dist/multistream/remoteMedia.js.map +1 -0
  35. package/dist/multistream/remoteMediaGroup.js +243 -0
  36. package/dist/multistream/remoteMediaGroup.js.map +1 -0
  37. package/dist/multistream/remoteMediaManager.js +1113 -0
  38. package/dist/multistream/remoteMediaManager.js.map +1 -0
  39. package/dist/reconnection-manager/index.js +109 -130
  40. package/dist/reconnection-manager/index.js.map +1 -1
  41. package/dist/roap/index.js +57 -240
  42. package/dist/roap/index.js.map +1 -1
  43. package/dist/roap/request.js +2 -114
  44. package/dist/roap/request.js.map +1 -1
  45. package/dist/roap/turnDiscovery.js +11 -5
  46. package/dist/roap/turnDiscovery.js.map +1 -1
  47. package/dist/statsAnalyzer/global.js +2 -0
  48. package/dist/statsAnalyzer/global.js.map +1 -1
  49. package/dist/statsAnalyzer/index.js +39 -36
  50. package/dist/statsAnalyzer/index.js.map +1 -1
  51. package/package.json +20 -19
  52. package/src/common/errors/webex-errors.js +0 -18
  53. package/src/constants.ts +139 -180
  54. package/src/media/index.js +60 -194
  55. package/src/media/internal-media-core-wrapper.ts +9 -0
  56. package/src/media/properties.js +19 -25
  57. package/src/media/util.js +0 -22
  58. package/src/meeting/index.js +565 -320
  59. package/src/meeting/request.js +1 -0
  60. package/src/meeting/util.js +3 -46
  61. package/src/meetings/index.js +30 -1
  62. package/src/meetings/util.js +23 -2
  63. package/src/members/index.js +48 -0
  64. package/src/multistream/mediaRequestManager.ts +164 -0
  65. package/src/multistream/multistreamMedia.ts +92 -0
  66. package/src/multistream/receiveSlot.ts +141 -0
  67. package/src/multistream/receiveSlotManager.ts +142 -0
  68. package/src/multistream/remoteMedia.ts +219 -0
  69. package/src/multistream/remoteMediaGroup.ts +224 -0
  70. package/src/multistream/remoteMediaManager.ts +911 -0
  71. package/src/reconnection-manager/index.js +40 -53
  72. package/src/roap/index.js +47 -207
  73. package/src/roap/request.js +1 -72
  74. package/src/roap/turnDiscovery.ts +12 -6
  75. package/src/statsAnalyzer/global.js +2 -0
  76. package/src/statsAnalyzer/index.js +32 -46
  77. package/test/integration/spec/journey.js +1 -1
  78. package/test/unit/spec/media/index.ts +223 -0
  79. package/test/unit/spec/media/properties.ts +73 -82
  80. package/test/unit/spec/meeting/effectsState.js +1 -3
  81. package/test/unit/spec/meeting/index.js +420 -228
  82. package/test/unit/spec/meeting/muteState.js +7 -0
  83. package/test/unit/spec/meeting/utils.js +61 -2
  84. package/test/unit/spec/meetings/index.js +0 -4
  85. package/test/unit/spec/members/index.js +164 -2
  86. package/test/unit/spec/multistream/mediaRequestManager.ts +511 -0
  87. package/test/unit/spec/multistream/receiveSlot.ts +104 -0
  88. package/test/unit/spec/multistream/receiveSlotManager.ts +173 -0
  89. package/test/unit/spec/multistream/remoteMedia.ts +217 -0
  90. package/test/unit/spec/multistream/remoteMediaGroup.ts +396 -0
  91. package/test/unit/spec/multistream/remoteMediaManager.ts +1251 -0
  92. package/test/unit/spec/roap/index.ts +63 -35
  93. package/test/unit/spec/stats-analyzer/index.js +19 -22
  94. package/dist/peer-connection-manager/index.js +0 -794
  95. package/dist/peer-connection-manager/index.js.map +0 -1
  96. package/dist/roap/collection.js +0 -73
  97. package/dist/roap/collection.js.map +0 -1
  98. package/dist/roap/handler.js +0 -337
  99. package/dist/roap/handler.js.map +0 -1
  100. package/dist/roap/state.js +0 -164
  101. package/dist/roap/state.js.map +0 -1
  102. package/dist/roap/util.js +0 -102
  103. package/dist/roap/util.js.map +0 -1
  104. package/src/peer-connection-manager/index.js +0 -723
  105. package/src/roap/collection.js +0 -63
  106. package/src/roap/handler.js +0 -252
  107. package/src/roap/state.js +0 -149
  108. package/src/roap/util.js +0 -93
  109. package/test/unit/spec/peerconnection-manager/index.js +0 -188
  110. package/test/unit/spec/peerconnection-manager/utils.js +0 -48
  111. package/test/unit/spec/roap/util.js +0 -30
@@ -0,0 +1,1113 @@
1
+ "use strict";
2
+
3
+ var _Reflect$construct = require("@babel/runtime-corejs2/core-js/reflect/construct");
4
+
5
+ var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
6
+
7
+ var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
8
+
9
+ _Object$defineProperty(exports, "__esModule", {
10
+ value: true
11
+ });
12
+
13
+ exports.RemoteMediaManager = exports.Event = exports.DefaultConfiguration = void 0;
14
+
15
+ var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs2/regenerator"));
16
+
17
+ var _stringify = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/json/stringify"));
18
+
19
+ var _values = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/values"));
20
+
21
+ var _entries = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/entries"));
22
+
23
+ var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
24
+
25
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/slicedToArray"));
26
+
27
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/toConsumableArray"));
28
+
29
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/asyncToGenerator"));
30
+
31
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/classCallCheck"));
32
+
33
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/createClass"));
34
+
35
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/assertThisInitialized"));
36
+
37
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/inherits"));
38
+
39
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/possibleConstructorReturn"));
40
+
41
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/getPrototypeOf"));
42
+
43
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
44
+
45
+ var _remove2 = _interopRequireDefault(require("lodash/remove"));
46
+
47
+ var _cloneDeep2 = _interopRequireDefault(require("lodash/cloneDeep"));
48
+
49
+ var _internalMediaCore = require("@webex/internal-media-core");
50
+
51
+ var _loggerProxy = _interopRequireDefault(require("../common/logs/logger-proxy"));
52
+
53
+ var _eventsScope = _interopRequireDefault(require("../common/events/events-scope"));
54
+
55
+ var _remoteMedia = require("./remoteMedia");
56
+
57
+ var _remoteMediaGroup = require("./remoteMediaGroup");
58
+
59
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = _Reflect$construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
60
+
61
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct) return false; if (_Reflect$construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
62
+
63
+ /* Predefined layouts: */
64
+ // An "all equal" grid, with size up to 3 x 3 = 9:
65
+ var AllEqualLayout = {
66
+ screenShareVideo: {
67
+ size: null
68
+ },
69
+ activeSpeakerVideoPaneGroups: [{
70
+ id: 'main',
71
+ numPanes: 9,
72
+ size: 'best',
73
+ priority: 255
74
+ }]
75
+ }; // A layout with just a single remote active speaker video pane:
76
+
77
+ var SingleLayout = {
78
+ screenShareVideo: {
79
+ size: null
80
+ },
81
+ activeSpeakerVideoPaneGroups: [{
82
+ id: 'main',
83
+ numPanes: 1,
84
+ size: 'best',
85
+ priority: 255
86
+ }]
87
+ }; // A layout with 1 big pane for the highest priority active speaker and 5 small panes for other active speakers:
88
+
89
+ var OnePlusFiveLayout = {
90
+ screenShareVideo: {
91
+ size: null
92
+ },
93
+ activeSpeakerVideoPaneGroups: [{
94
+ id: 'mainBigOne',
95
+ numPanes: 1,
96
+ size: 'large',
97
+ priority: 255
98
+ }, {
99
+ id: 'secondarySetOfSmallPanes',
100
+ numPanes: 5,
101
+ size: 'very small',
102
+ priority: 254
103
+ }]
104
+ }; // A layout with 2 big panes for 2 main active speakers and a strip of 6 small panes for other active speakers:
105
+
106
+ var TwoMainPlusSixSmallLayout = {
107
+ screenShareVideo: {
108
+ size: null
109
+ },
110
+ activeSpeakerVideoPaneGroups: [{
111
+ id: 'mainGroupWith2BigPanes',
112
+ numPanes: 2,
113
+ size: 'large',
114
+ priority: 255
115
+ }, {
116
+ id: 'secondaryGroupOfSmallPanes',
117
+ numPanes: 6,
118
+ size: 'small',
119
+ priority: 254
120
+ }]
121
+ }; // A strip of 8 small video panes (thumbnails) displayed at the top of a remote screenshare:
122
+
123
+ var RemoteScreenShareWithSmallThumbnailsLayout = {
124
+ screenShareVideo: {
125
+ size: 'best'
126
+ },
127
+ activeSpeakerVideoPaneGroups: [{
128
+ id: 'thumbnails',
129
+ numPanes: 8,
130
+ size: 'thumbnail',
131
+ priority: 255
132
+ }]
133
+ }; // A staged layout with 4 pre-selected meeting participants in the main 2x2 grid and 6 small panes for other active speakers at the top:
134
+
135
+ var Stage2x2With6ThumbnailsLayout = {
136
+ screenShareVideo: {
137
+ size: null
138
+ },
139
+ activeSpeakerVideoPaneGroups: [{
140
+ id: 'thumbnails',
141
+ numPanes: 6,
142
+ size: 'thumbnail',
143
+ priority: 255
144
+ }],
145
+ memberVideoPanes: [{
146
+ id: 'stage-1',
147
+ size: 'medium',
148
+ csi: undefined
149
+ }, {
150
+ id: 'stage-2',
151
+ size: 'medium',
152
+ csi: undefined
153
+ }, {
154
+ id: 'stage-3',
155
+ size: 'medium',
156
+ csi: undefined
157
+ }, {
158
+ id: 'stage-4',
159
+ size: 'medium',
160
+ csi: undefined
161
+ }]
162
+ };
163
+ /**
164
+ * Default configuration:
165
+ * - uses 3 audio streams
166
+ * - prefers active speakers with live video (e.g. are not audio only or video muted) over active speakers without live video
167
+ * - has a few layouts defined, including 1 that contains remote screen share (ScreenShareView)
168
+ */
169
+
170
+ var DefaultConfiguration = {
171
+ audio: {
172
+ numOfActiveSpeakerStreams: 3
173
+ },
174
+ video: {
175
+ preferLiveVideo: true,
176
+ initialLayoutId: 'AllEqual',
177
+ layouts: {
178
+ AllEqual: AllEqualLayout,
179
+ OnePlusFive: OnePlusFiveLayout,
180
+ Single: SingleLayout,
181
+ Stage: Stage2x2With6ThumbnailsLayout,
182
+ ScreenShareView: RemoteScreenShareWithSmallThumbnailsLayout
183
+ }
184
+ },
185
+ screenShare: {
186
+ audio: true,
187
+ video: true
188
+ }
189
+ };
190
+ exports.DefaultConfiguration = DefaultConfiguration;
191
+ var Event;
192
+ exports.Event = Event;
193
+
194
+ (function (Event) {
195
+ Event["AudioCreated"] = "AudioCreated";
196
+ Event["ScreenShareAudioCreated"] = "ScreenShareCreated";
197
+ Event["VideoLayoutChanged"] = "VideoLayoutChanged";
198
+ })(Event || (exports.Event = Event = {}));
199
+
200
+ /**
201
+ * A helper class that manages all remote audio/video streams in order to achieve a predefined set of layouts.
202
+ * It also creates a fixed number of audio streams and these don't change during the meeting.
203
+ *
204
+ * Things that RemoteMediaManager does:
205
+ * - owns the receive slots (creates them when needed, and re-uses them when switching layouts)
206
+ * - constructs appropriate RemoteMedia and RemoteMediaGroup objects and sends appropriate mediaRequests
207
+ */
208
+ var RemoteMediaManager = /*#__PURE__*/function (_EventsScope) {
209
+ (0, _inherits2.default)(RemoteMediaManager, _EventsScope);
210
+
211
+ var _super = _createSuper(RemoteMediaManager);
212
+
213
+ /**
214
+ * Constructor
215
+ *
216
+ * @param {ReceiveSlotManager} receiveSlotManager
217
+ * @param {{audio: MediaRequestManager, video: mediaRequestManagers}} mediaRequestManagers
218
+ * @param {Configuration} config Configuration describing what video layouts to use during the meeting
219
+ */
220
+ function RemoteMediaManager(receiveSlotManager, mediaRequestManagers) {
221
+ var _this;
222
+
223
+ var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DefaultConfiguration;
224
+ (0, _classCallCheck2.default)(this, RemoteMediaManager);
225
+ _this = _super.call(this);
226
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "config", void 0);
227
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "started", void 0);
228
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "receiveSlotManager", void 0);
229
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "mediaRequestManagers", void 0);
230
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "currentLayout", void 0);
231
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "slots", void 0);
232
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "media", void 0);
233
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "receiveSlotAllocations", void 0);
234
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "currentLayoutId", void 0);
235
+ _this.started = false;
236
+ _this.config = config;
237
+ _this.receiveSlotManager = receiveSlotManager;
238
+ _this.mediaRequestManagers = mediaRequestManagers;
239
+ _this.media = {
240
+ audio: undefined,
241
+ video: {
242
+ activeSpeakerGroups: {},
243
+ memberPanes: {}
244
+ }
245
+ };
246
+
247
+ _this.checkConfigValidity();
248
+
249
+ _this.slots = {
250
+ audio: [],
251
+ screenShareAudio: undefined,
252
+ screenShareVideo: undefined,
253
+ video: {
254
+ unused: [],
255
+ activeSpeaker: [],
256
+ receiverSelected: []
257
+ }
258
+ };
259
+ _this.receiveSlotAllocations = {
260
+ activeSpeaker: {},
261
+ receiverSelected: {}
262
+ };
263
+
264
+ _loggerProxy.default.logger.log("RemoteMediaManager#constructor --> RemoteMediaManager created with config: ".concat((0, _stringify.default)(_this.config)));
265
+
266
+ return _this;
267
+ }
268
+ /**
269
+ * Checks if configuration is valid, throws an error if it's not
270
+ */
271
+
272
+
273
+ (0, _createClass2.default)(RemoteMediaManager, [{
274
+ key: "checkConfigValidity",
275
+ value: function checkConfigValidity() {
276
+ if (!(this.config.video.initialLayoutId in this.config.video.layouts)) {
277
+ throw new Error("invalid config: initialLayoutId \"".concat(this.config.video.initialLayoutId, "\" doesn't match any of the layouts"));
278
+ } // check if each layout is valid
279
+
280
+
281
+ (0, _values.default)(this.config.video.layouts).forEach(function (layout) {
282
+ var _layout$activeSpeaker, _layout$memberVideoPa;
283
+
284
+ var groupIds = {};
285
+ var paneIds = {};
286
+ var groupPriorites = {};
287
+ (_layout$activeSpeaker = layout.activeSpeakerVideoPaneGroups) === null || _layout$activeSpeaker === void 0 ? void 0 : _layout$activeSpeaker.forEach(function (group) {
288
+ if (groupIds[group.id]) {
289
+ throw new Error("invalid config: duplicate active speaker video pane group id: ".concat(group.id));
290
+ }
291
+
292
+ groupIds[group.id] = true;
293
+
294
+ if (groupPriorites[group.priority]) {
295
+ throw new Error("invalid config: multiple active speaker video pane groups have same priority: ".concat(group.priority));
296
+ }
297
+
298
+ groupPriorites[group.priority] = true;
299
+ });
300
+ (_layout$memberVideoPa = layout.memberVideoPanes) === null || _layout$memberVideoPa === void 0 ? void 0 : _layout$memberVideoPa.forEach(function (pane) {
301
+ if (paneIds[pane.id]) {
302
+ throw new Error("invalid config: duplicate member video pane id: ".concat(pane.id));
303
+ }
304
+
305
+ paneIds[pane.id] = true;
306
+ });
307
+ });
308
+ }
309
+ /**
310
+ * Starts the RemoteMediaManager.
311
+ *
312
+ * @returns {Promise}
313
+ */
314
+
315
+ }, {
316
+ key: "start",
317
+ value: function () {
318
+ var _start = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
319
+ return _regenerator.default.wrap(function _callee$(_context) {
320
+ while (1) {
321
+ switch (_context.prev = _context.next) {
322
+ case 0:
323
+ if (!this.started) {
324
+ _context.next = 2;
325
+ break;
326
+ }
327
+
328
+ throw new Error('start() failure: already started');
329
+
330
+ case 2:
331
+ this.started = true;
332
+ _context.next = 5;
333
+ return this.createAudioMedia();
334
+
335
+ case 5:
336
+ _context.next = 7;
337
+ return this.preallocateVideoReceiveSlots();
338
+
339
+ case 7:
340
+ _context.next = 9;
341
+ return this.setLayout(this.config.video.initialLayoutId);
342
+
343
+ case 9:
344
+ case "end":
345
+ return _context.stop();
346
+ }
347
+ }
348
+ }, _callee, this);
349
+ }));
350
+
351
+ function start() {
352
+ return _start.apply(this, arguments);
353
+ }
354
+
355
+ return start;
356
+ }()
357
+ /**
358
+ * Releases all the used resources (like allocated receive slots). This function needs
359
+ * to be called when we leave the meeting, etc.
360
+ */
361
+
362
+ }, {
363
+ key: "stop",
364
+ value: function stop() {
365
+ var _this2 = this,
366
+ _this$slots$video$unu,
367
+ _this$slots$video$unu2;
368
+
369
+ // invalidate all remoteMedia objects
370
+ this.invalidateCurrentRemoteMedia({
371
+ audio: true,
372
+ video: true,
373
+ commit: true
374
+ }); // release all audio receive slots
375
+
376
+ this.slots.audio.forEach(function (slot) {
377
+ return _this2.receiveSlotManager.releaseSlot(slot);
378
+ });
379
+ this.slots.audio.length = 0; // todo: screenshare slots... (SPARK-377812)
380
+
381
+ this.receiveSlotAllocations = {
382
+ activeSpeaker: {},
383
+ receiverSelected: {}
384
+ };
385
+
386
+ (_this$slots$video$unu = this.slots.video.unused).push.apply(_this$slots$video$unu, (0, _toConsumableArray2.default)(this.slots.video.activeSpeaker));
387
+
388
+ this.slots.video.activeSpeaker.length = 0;
389
+
390
+ (_this$slots$video$unu2 = this.slots.video.unused).push.apply(_this$slots$video$unu2, (0, _toConsumableArray2.default)(this.slots.video.receiverSelected));
391
+
392
+ this.slots.video.receiverSelected.length = 0;
393
+ this.releaseUnusedVideoSlots();
394
+ this.currentLayout = undefined;
395
+ this.currentLayoutId = undefined;
396
+ this.started = false;
397
+ }
398
+ /**
399
+ * Returns the total number of main video panes required for a given layout
400
+ *
401
+ * @param {VideoLayout} layout
402
+ * @returns {number}
403
+ */
404
+
405
+ }, {
406
+ key: "getRequiredNumVideoSlotsForLayout",
407
+ value: function getRequiredNumVideoSlotsForLayout(layout) {
408
+ var _layout$activeSpeaker2, _layout$memberVideoPa2;
409
+
410
+ if (!layout) {
411
+ return 0;
412
+ }
413
+
414
+ var activeSpeakerCount = ((_layout$activeSpeaker2 = layout.activeSpeakerVideoPaneGroups) === null || _layout$activeSpeaker2 === void 0 ? void 0 : _layout$activeSpeaker2.reduce(function (sum, paneGroup) {
415
+ return sum + paneGroup.numPanes;
416
+ }, 0)) || 0;
417
+ var receiverSelectedCount = ((_layout$memberVideoPa2 = layout.memberVideoPanes) === null || _layout$memberVideoPa2 === void 0 ? void 0 : _layout$memberVideoPa2.length) || 0;
418
+ return activeSpeakerCount + receiverSelectedCount;
419
+ }
420
+ /**
421
+ * Allocates the maximum number of panes that any of the configured layouts will require.
422
+ * We do this at the beginning, because it's more efficient (much faster) then allocating receive slots
423
+ * later, after the SDP exchange was done.
424
+ */
425
+
426
+ }, {
427
+ key: "preallocateVideoReceiveSlots",
428
+ value: function () {
429
+ var _preallocateVideoReceiveSlots = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
430
+ var _this3 = this;
431
+
432
+ var maxNumVideoPanesRequired;
433
+ return _regenerator.default.wrap(function _callee2$(_context2) {
434
+ while (1) {
435
+ switch (_context2.prev = _context2.next) {
436
+ case 0:
437
+ maxNumVideoPanesRequired = (0, _values.default)(this.config.video.layouts).reduce(function (maxValue, layout) {
438
+ return Math.max(maxValue, _this3.getRequiredNumVideoSlotsForLayout(layout));
439
+ }, 0);
440
+
441
+ case 1:
442
+ if (!(this.slots.video.unused.length < maxNumVideoPanesRequired)) {
443
+ _context2.next = 9;
444
+ break;
445
+ }
446
+
447
+ _context2.t0 = this.slots.video.unused;
448
+ _context2.next = 5;
449
+ return this.receiveSlotManager.allocateSlot(_internalMediaCore.MediaConnection.MediaType.VideoMain);
450
+
451
+ case 5:
452
+ _context2.t1 = _context2.sent;
453
+
454
+ _context2.t0.push.call(_context2.t0, _context2.t1);
455
+
456
+ _context2.next = 1;
457
+ break;
458
+
459
+ case 9:
460
+ case "end":
461
+ return _context2.stop();
462
+ }
463
+ }
464
+ }, _callee2, this);
465
+ }));
466
+
467
+ function preallocateVideoReceiveSlots() {
468
+ return _preallocateVideoReceiveSlots.apply(this, arguments);
469
+ }
470
+
471
+ return preallocateVideoReceiveSlots;
472
+ }()
473
+ /**
474
+ * Changes the layout (triggers Event.VideoLayoutChanged)
475
+ *
476
+ * @param {LayoutId} layoutId new layout id
477
+ * @returns {Promise}
478
+ */
479
+
480
+ }, {
481
+ key: "setLayout",
482
+ value: function () {
483
+ var _setLayout = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(layoutId) {
484
+ return _regenerator.default.wrap(function _callee3$(_context3) {
485
+ while (1) {
486
+ switch (_context3.prev = _context3.next) {
487
+ case 0:
488
+ if (layoutId in this.config.video.layouts) {
489
+ _context3.next = 2;
490
+ break;
491
+ }
492
+
493
+ throw new Error("invalid layoutId: \"".concat(layoutId, "\" doesn't match any of the configured layouts"));
494
+
495
+ case 2:
496
+ if (this.started) {
497
+ _context3.next = 4;
498
+ break;
499
+ }
500
+
501
+ throw new Error('setLayout() called before start()');
502
+
503
+ case 4:
504
+ this.currentLayoutId = layoutId;
505
+ this.currentLayout = (0, _cloneDeep2.default)(this.config.video.layouts[this.currentLayoutId]);
506
+ _context3.next = 8;
507
+ return this.updateVideoReceiveSlots();
508
+
509
+ case 8:
510
+ this.updateVideoRemoteMediaObjects();
511
+ this.emitVideoLayoutChangedEvent();
512
+
513
+ case 10:
514
+ case "end":
515
+ return _context3.stop();
516
+ }
517
+ }
518
+ }, _callee3, this);
519
+ }));
520
+
521
+ function setLayout(_x) {
522
+ return _setLayout.apply(this, arguments);
523
+ }
524
+
525
+ return setLayout;
526
+ }()
527
+ /**
528
+ * Returns the currently selected layout id
529
+ *
530
+ * @returns {LayoutId}
531
+ */
532
+
533
+ }, {
534
+ key: "getLayoutId",
535
+ value: function getLayoutId() {
536
+ return this.currentLayoutId;
537
+ }
538
+ /**
539
+ * Creates the audio slots
540
+ */
541
+
542
+ }, {
543
+ key: "createAudioMedia",
544
+ value: function () {
545
+ var _createAudioMedia = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4() {
546
+ var i, slot;
547
+ return _regenerator.default.wrap(function _callee4$(_context4) {
548
+ while (1) {
549
+ switch (_context4.prev = _context4.next) {
550
+ case 0:
551
+ i = 0;
552
+
553
+ case 1:
554
+ if (!(i < this.config.audio.numOfActiveSpeakerStreams)) {
555
+ _context4.next = 9;
556
+ break;
557
+ }
558
+
559
+ _context4.next = 4;
560
+ return this.receiveSlotManager.allocateSlot(_internalMediaCore.MediaConnection.MediaType.AudioMain);
561
+
562
+ case 4:
563
+ slot = _context4.sent;
564
+ this.slots.audio.push(slot);
565
+
566
+ case 6:
567
+ i += 1;
568
+ _context4.next = 1;
569
+ break;
570
+
571
+ case 9:
572
+ // create a remote media group
573
+ this.media.audio = new _remoteMediaGroup.RemoteMediaGroup(this.mediaRequestManagers.audio, this.slots.audio, 255, true);
574
+ this.emit({
575
+ file: 'multistream/remoteMediaManager',
576
+ function: 'createAudioMedia'
577
+ }, Event.AudioCreated, this.media.audio);
578
+
579
+ case 11:
580
+ case "end":
581
+ return _context4.stop();
582
+ }
583
+ }
584
+ }, _callee4, this);
585
+ }));
586
+
587
+ function createAudioMedia() {
588
+ return _createAudioMedia.apply(this, arguments);
589
+ }
590
+
591
+ return createAudioMedia;
592
+ }()
593
+ /**
594
+ * Goes over all receiver-selected slots and keeps only the ones that are required by a given layout,
595
+ * the rest are all moved to the "unused" list
596
+ */
597
+
598
+ }, {
599
+ key: "trimReceiverSelectedSlots",
600
+ value: function trimReceiverSelectedSlots() {
601
+ var _this$currentLayout, _this$currentLayout$m, _this$slots$video$unu3;
602
+
603
+ var requiredCsis = {}; // fill requiredCsis with all the CSIs that the given layout requires
604
+
605
+ (_this$currentLayout = this.currentLayout) === null || _this$currentLayout === void 0 ? void 0 : (_this$currentLayout$m = _this$currentLayout.memberVideoPanes) === null || _this$currentLayout$m === void 0 ? void 0 : _this$currentLayout$m.forEach(function (memberVideoPane) {
606
+ if (memberVideoPane.csi !== undefined) {
607
+ requiredCsis[memberVideoPane.csi] = true;
608
+ }
609
+ });
610
+
611
+ var isCsiNeededByCurrentLayout = function isCsiNeededByCurrentLayout(csi) {
612
+ if (csi === undefined) {
613
+ return false;
614
+ }
615
+
616
+ return !!requiredCsis[csi];
617
+ }; // keep receiverSelected slots that match our new requiredCsis, move the rest of receiverSelected slots to unused
618
+
619
+
620
+ var notNeededReceiverSelectedSlots = (0, _remove2.default)(this.slots.video.receiverSelected, function (slot) {
621
+ return isCsiNeededByCurrentLayout(slot.csi) === false;
622
+ });
623
+
624
+ (_this$slots$video$unu3 = this.slots.video.unused).push.apply(_this$slots$video$unu3, (0, _toConsumableArray2.default)(notNeededReceiverSelectedSlots));
625
+ }
626
+ /**
627
+ * Releases all the "unused" video slots.
628
+ */
629
+
630
+ }, {
631
+ key: "releaseUnusedVideoSlots",
632
+ value: function releaseUnusedVideoSlots() {
633
+ var _this4 = this;
634
+
635
+ this.slots.video.unused.forEach(function (slot) {
636
+ return _this4.receiveSlotManager.releaseSlot(slot);
637
+ });
638
+ this.slots.video.unused.length = 0;
639
+ }
640
+ /**
641
+ * Allocates receive slots to all video panes in the current selected layout
642
+ */
643
+
644
+ }, {
645
+ key: "allocateSlotsToVideoPaneGroups",
646
+ value: function allocateSlotsToVideoPaneGroups() {
647
+ var _this$currentLayout2,
648
+ _this$currentLayout2$,
649
+ _this5 = this,
650
+ _this$currentLayout3,
651
+ _this$currentLayout3$;
652
+
653
+ this.receiveSlotAllocations = {
654
+ activeSpeaker: {},
655
+ receiverSelected: {}
656
+ };
657
+ (_this$currentLayout2 = this.currentLayout) === null || _this$currentLayout2 === void 0 ? void 0 : (_this$currentLayout2$ = _this$currentLayout2.activeSpeakerVideoPaneGroups) === null || _this$currentLayout2$ === void 0 ? void 0 : _this$currentLayout2$.forEach(function (group) {
658
+ _this5.receiveSlotAllocations.activeSpeaker[group.id] = {
659
+ slots: []
660
+ };
661
+
662
+ for (var paneIndex = 0; paneIndex < group.numPanes; paneIndex += 1) {
663
+ // allocate a slot from the "unused" list
664
+ var freeSlot = _this5.slots.video.unused.pop();
665
+
666
+ if (freeSlot) {
667
+ _this5.slots.video.activeSpeaker.push(freeSlot);
668
+
669
+ _this5.receiveSlotAllocations.activeSpeaker[group.id].slots.push(freeSlot);
670
+ }
671
+ }
672
+ });
673
+ (_this$currentLayout3 = this.currentLayout) === null || _this$currentLayout3 === void 0 ? void 0 : (_this$currentLayout3$ = _this$currentLayout3.memberVideoPanes) === null || _this$currentLayout3$ === void 0 ? void 0 : _this$currentLayout3$.forEach(function (memberPane) {
674
+ // check if there is existing slot for this csi
675
+ var existingSlot = _this5.slots.video.receiverSelected.find(function (slot) {
676
+ return slot.csi === memberPane.csi;
677
+ });
678
+
679
+ var isExistingSlotAlreadyAllocated = (0, _values.default)(_this5.receiveSlotAllocations.receiverSelected).includes(existingSlot);
680
+
681
+ if (memberPane.csi !== undefined && existingSlot && !isExistingSlotAlreadyAllocated) {
682
+ // found it, so use it
683
+ _this5.receiveSlotAllocations.receiverSelected[memberPane.id] = existingSlot;
684
+ } else {
685
+ // allocate a slot from the "unused" list
686
+ var freeSlot = _this5.slots.video.unused.pop();
687
+
688
+ if (freeSlot) {
689
+ _this5.slots.video.receiverSelected.push(freeSlot);
690
+
691
+ _this5.receiveSlotAllocations.receiverSelected[memberPane.id] = freeSlot;
692
+ }
693
+ }
694
+ });
695
+ }
696
+ /**
697
+ * Makes sure we have the right number of receive slots created for the current layout
698
+ * and allocates them to the right video panes / pane groups
699
+ *
700
+ * @returns {Promise}
701
+ */
702
+
703
+ }, {
704
+ key: "updateVideoReceiveSlots",
705
+ value: function () {
706
+ var _updateVideoReceiveSlots = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5() {
707
+ var _this$slots$video$unu4;
708
+
709
+ var requiredNumSlots, totalNumSlots, numSlotsToCreate;
710
+ return _regenerator.default.wrap(function _callee5$(_context5) {
711
+ while (1) {
712
+ switch (_context5.prev = _context5.next) {
713
+ case 0:
714
+ requiredNumSlots = this.getRequiredNumVideoSlotsForLayout(this.currentLayout);
715
+ totalNumSlots = this.slots.video.unused.length + this.slots.video.activeSpeaker.length + this.slots.video.receiverSelected.length; // ensure we have enough total slots for current layout
716
+
717
+ if (!(totalNumSlots < requiredNumSlots)) {
718
+ _context5.next = 13;
719
+ break;
720
+ }
721
+
722
+ numSlotsToCreate = requiredNumSlots - totalNumSlots;
723
+
724
+ case 4:
725
+ if (!(numSlotsToCreate > 0)) {
726
+ _context5.next = 13;
727
+ break;
728
+ }
729
+
730
+ _context5.t0 = this.slots.video.unused;
731
+ _context5.next = 8;
732
+ return this.receiveSlotManager.allocateSlot(_internalMediaCore.MediaConnection.MediaType.VideoMain);
733
+
734
+ case 8:
735
+ _context5.t1 = _context5.sent;
736
+
737
+ _context5.t0.push.call(_context5.t0, _context5.t1);
738
+
739
+ numSlotsToCreate -= 1;
740
+ _context5.next = 4;
741
+ break;
742
+
743
+ case 13:
744
+ // move all no longer needed receiver-selected slots to "unused"
745
+ this.trimReceiverSelectedSlots(); // move all active speaker slots to "unused"
746
+
747
+ (_this$slots$video$unu4 = this.slots.video.unused).push.apply(_this$slots$video$unu4, (0, _toConsumableArray2.default)(this.slots.video.activeSpeaker));
748
+
749
+ this.slots.video.activeSpeaker.length = 0; // allocate the slots to the right panes / pane groups
750
+
751
+ this.allocateSlotsToVideoPaneGroups();
752
+
753
+ _loggerProxy.default.logger.log("RemoteMediaManager#updateVideoReceiveSlots --> receive slots updated: unused=".concat(this.slots.video.unused.length, ", activeSpeaker=").concat(this.slots.video.activeSpeaker.length, ", receiverSelected=").concat(this.slots.video.receiverSelected.length)); // If this is the initial layout, there may be some "unused" slots left because of the preallocation
754
+ // done in this.preallocateVideoReceiveSlots(), so release them now
755
+
756
+
757
+ this.releaseUnusedVideoSlots();
758
+
759
+ case 19:
760
+ case "end":
761
+ return _context5.stop();
762
+ }
763
+ }
764
+ }, _callee5, this);
765
+ }));
766
+
767
+ function updateVideoReceiveSlots() {
768
+ return _updateVideoReceiveSlots.apply(this, arguments);
769
+ }
770
+
771
+ return updateVideoReceiveSlots;
772
+ }()
773
+ /**
774
+ * Creates new RemoteMedia and RemoteMediaGroup objects for the current layout
775
+ * and sends the media requests for all of them.
776
+ */
777
+
778
+ }, {
779
+ key: "updateVideoRemoteMediaObjects",
780
+ value: function updateVideoRemoteMediaObjects() {
781
+ var _this6 = this;
782
+
783
+ // invalidate all the previous remote media objects and cancel their media requests
784
+ this.invalidateCurrentRemoteMedia({
785
+ audio: false,
786
+ video: true,
787
+ commit: false
788
+ }); // create new remoteMediaGroup objects
789
+
790
+ this.media.video.activeSpeakerGroups = {};
791
+ this.media.video.memberPanes = {};
792
+
793
+ var _loop = function _loop() {
794
+ var _this6$currentLayout, _this6$currentLayout$;
795
+
796
+ var _Object$entries$_i = (0, _slicedToArray2.default)(_Object$entries[_i], 2),
797
+ groupId = _Object$entries$_i[0],
798
+ group = _Object$entries$_i[1];
799
+
800
+ var paneGroupInCurrentLayout = (_this6$currentLayout = _this6.currentLayout) === null || _this6$currentLayout === void 0 ? void 0 : (_this6$currentLayout$ = _this6$currentLayout.activeSpeakerVideoPaneGroups) === null || _this6$currentLayout$ === void 0 ? void 0 : _this6$currentLayout$.find(function (groupInLayout) {
801
+ return groupInLayout.id === groupId;
802
+ });
803
+
804
+ if (paneGroupInCurrentLayout) {
805
+ var mediaGroup = new _remoteMediaGroup.RemoteMediaGroup(_this6.mediaRequestManagers.video, group.slots, paneGroupInCurrentLayout.priority, false, {
806
+ preferLiveVideo: _this6.config.video.preferLiveVideo,
807
+ resolution: paneGroupInCurrentLayout.size
808
+ });
809
+ _this6.media.video.activeSpeakerGroups[groupId] = mediaGroup;
810
+ } else {
811
+ // this should never happen, because this.receiveSlotAllocations are created based on current layout configuration
812
+ _loggerProxy.default.logger.warn("a group id ".concat(groupId, " from this.receiveSlotAllocations.activeSpeaker cannot be found in the current layout configuration"));
813
+ }
814
+ };
815
+
816
+ for (var _i = 0, _Object$entries = (0, _entries.default)(this.receiveSlotAllocations.activeSpeaker); _i < _Object$entries.length; _i++) {
817
+ _loop();
818
+ } // create new remoteMedia objects
819
+
820
+
821
+ var _loop2 = function _loop2() {
822
+ var _this6$currentLayout2, _this6$currentLayout3;
823
+
824
+ var _Object$entries3$_i = (0, _slicedToArray2.default)(_Object$entries3[_i2], 2),
825
+ paneId = _Object$entries3$_i[0],
826
+ slot = _Object$entries3$_i[1];
827
+
828
+ var paneInCurrentLayout = (_this6$currentLayout2 = _this6.currentLayout) === null || _this6$currentLayout2 === void 0 ? void 0 : (_this6$currentLayout3 = _this6$currentLayout2.memberVideoPanes) === null || _this6$currentLayout3 === void 0 ? void 0 : _this6$currentLayout3.find(function (paneInLayout) {
829
+ return paneInLayout.id === paneId;
830
+ });
831
+
832
+ if (paneInCurrentLayout) {
833
+ var remoteMedia = new _remoteMedia.RemoteMedia(slot, _this6.mediaRequestManagers.video, {
834
+ resolution: paneInCurrentLayout.size
835
+ });
836
+
837
+ if (paneInCurrentLayout.csi) {
838
+ remoteMedia.sendMediaRequest(paneInCurrentLayout.csi, false);
839
+ }
840
+
841
+ _this6.media.video.memberPanes[paneId] = remoteMedia;
842
+ } else {
843
+ // this should never happen, because this.receiveSlotAllocations are created based on current layout configuration
844
+ _loggerProxy.default.logger.warn("a pane id ".concat(paneId, " from this.receiveSlotAllocations.receiverSelected cannot be found in the current layout configuration"));
845
+ }
846
+ };
847
+
848
+ for (var _i2 = 0, _Object$entries3 = (0, _entries.default)(this.receiveSlotAllocations.receiverSelected); _i2 < _Object$entries3.length; _i2++) {
849
+ _loop2();
850
+ } // todo: screenshare (SPARK-377812)
851
+
852
+
853
+ this.mediaRequestManagers.video.commit();
854
+ }
855
+ /**
856
+ * Invalidates all remote media objects belonging to currently selected layout
857
+ */
858
+
859
+ }, {
860
+ key: "invalidateCurrentRemoteMedia",
861
+ value: function invalidateCurrentRemoteMedia(options) {
862
+ var audio = options.audio,
863
+ video = options.video,
864
+ commit = options.commit;
865
+
866
+ if (audio && this.media.audio) {
867
+ this.media.audio.stop(commit);
868
+ }
869
+
870
+ if (video) {
871
+ (0, _values.default)(this.media.video.activeSpeakerGroups).forEach(function (remoteMediaGroup) {
872
+ remoteMediaGroup.stop(false);
873
+ });
874
+ (0, _values.default)(this.media.video.memberPanes).forEach(function (remoteMedia) {
875
+ remoteMedia.stop(false);
876
+ });
877
+
878
+ if (commit) {
879
+ this.mediaRequestManagers.video.commit();
880
+ }
881
+ }
882
+ }
883
+ /** emits Event.VideoLayoutChanged */
884
+
885
+ }, {
886
+ key: "emitVideoLayoutChangedEvent",
887
+ value: function emitVideoLayoutChangedEvent() {
888
+ // todo: at this point the receive slots might still be showing a participant from previous layout, we should
889
+ // wait for our media requests to be fullfilled, but there is no API for that right now (we could wait for source updates
890
+ // but in some cases they might never come, or would need to always make sure to use a new set of receiver slots)
891
+ // for now it's fine to have it like this, we will re-evaluate if it needs improving after more testing
892
+ this.emit({
893
+ file: 'multistream/remoteMediaManager',
894
+ function: 'emitVideoLayoutChangedEvent'
895
+ }, Event.VideoLayoutChanged, {
896
+ layoutId: this.currentLayoutId,
897
+ activeSpeakerVideoPanes: this.media.video.activeSpeakerGroups,
898
+ memberVideoPanes: this.media.video.memberPanes,
899
+ screenShareVideo: undefined // todo: screen share (SPARK-377812)
900
+
901
+ });
902
+ }
903
+ /**
904
+ * Sets a new CSI on a given remote media object
905
+ *
906
+ * @param {RemoteMedia} remoteMedia remote Media object to modify
907
+ * @param {CSI} csi new CSI value, can be null if we want to stop receiving media
908
+ */
909
+
910
+ }, {
911
+ key: "setRemoteVideoCsi",
912
+ value: function setRemoteVideoCsi(remoteMedia, csi) {
913
+ if (!(0, _values.default)(this.media.video.memberPanes).includes(remoteMedia)) {
914
+ throw new Error('remoteMedia not found');
915
+ }
916
+
917
+ if (csi) {
918
+ remoteMedia.sendMediaRequest(csi, true);
919
+ } else {
920
+ remoteMedia.cancelMediaRequest(true);
921
+ }
922
+ }
923
+ /**
924
+ * Adds a new member video pane to the currently selected layout.
925
+ *
926
+ * Changes to the layout are lost after a layout change.
927
+ *
928
+ * @param {MemberVideoPane} newPane
929
+ * @returns {Promise<RemoteMedia>}
930
+ */
931
+
932
+ }, {
933
+ key: "addMemberVideoPane",
934
+ value: function () {
935
+ var _addMemberVideoPane = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(newPane) {
936
+ var _this$currentLayout4;
937
+
938
+ var receiveSlot, remoteMedia;
939
+ return _regenerator.default.wrap(function _callee6$(_context6) {
940
+ while (1) {
941
+ switch (_context6.prev = _context6.next) {
942
+ case 0:
943
+ if (this.currentLayout) {
944
+ _context6.next = 2;
945
+ break;
946
+ }
947
+
948
+ throw new Error('There is no current layout selected, call start() first');
949
+
950
+ case 2:
951
+ if (!((_this$currentLayout4 = this.currentLayout) !== null && _this$currentLayout4 !== void 0 && _this$currentLayout4.memberVideoPanes)) {
952
+ this.currentLayout.memberVideoPanes = [];
953
+ }
954
+
955
+ if (!(newPane.id in this.currentLayout.memberVideoPanes)) {
956
+ _context6.next = 5;
957
+ break;
958
+ }
959
+
960
+ throw new Error("duplicate pane id ".concat(newPane.id, " - this pane already exists in current layout's memberVideoPanes"));
961
+
962
+ case 5:
963
+ this.currentLayout.memberVideoPanes.push(newPane);
964
+ _context6.next = 8;
965
+ return this.receiveSlotManager.allocateSlot(_internalMediaCore.MediaConnection.MediaType.VideoMain);
966
+
967
+ case 8:
968
+ receiveSlot = _context6.sent;
969
+ this.slots.video.receiverSelected.push(receiveSlot);
970
+ remoteMedia = new _remoteMedia.RemoteMedia(receiveSlot, this.mediaRequestManagers.video, {
971
+ resolution: newPane.size
972
+ });
973
+
974
+ if (newPane.csi) {
975
+ remoteMedia.sendMediaRequest(newPane.csi, true);
976
+ }
977
+
978
+ this.media.video.memberPanes[newPane.id] = remoteMedia;
979
+ return _context6.abrupt("return", remoteMedia);
980
+
981
+ case 14:
982
+ case "end":
983
+ return _context6.stop();
984
+ }
985
+ }
986
+ }, _callee6, this);
987
+ }));
988
+
989
+ function addMemberVideoPane(_x2) {
990
+ return _addMemberVideoPane.apply(this, arguments);
991
+ }
992
+
993
+ return addMemberVideoPane;
994
+ }()
995
+ /**
996
+ * Removes a member video pane from the currently selected layout.
997
+ *
998
+ * Changes to the layout are lost after a layout change.
999
+ *
1000
+ * @param {PaneId} paneId pane id of the pane to remove
1001
+ * @returns {Promise<void>}
1002
+ */
1003
+
1004
+ }, {
1005
+ key: "removeMemberVideoPane",
1006
+ value: function removeMemberVideoPane(paneId) {
1007
+ var _this$currentLayout$m2, _this$currentLayout$m3;
1008
+
1009
+ if (!this.currentLayout) {
1010
+ return _promise.default.reject(new Error('There is no current layout selected, call start() first'));
1011
+ }
1012
+
1013
+ if (!((_this$currentLayout$m2 = this.currentLayout.memberVideoPanes) !== null && _this$currentLayout$m2 !== void 0 && _this$currentLayout$m2.find(function (pane) {
1014
+ return pane.id === paneId;
1015
+ }))) {
1016
+ // pane id doesn't exist, so nothing to do
1017
+ _loggerProxy.default.logger.log("RemoteMediaManager#removeMemberVideoPane --> removeMemberVideoPane() called for a non-existent paneId: ".concat(paneId, " (pane not found in currentLayout.memberVideoPanes)"));
1018
+
1019
+ return _promise.default.resolve();
1020
+ }
1021
+
1022
+ if (!this.media.video.memberPanes[paneId]) {
1023
+ // pane id doesn't exist, so nothing to do
1024
+ _loggerProxy.default.logger.log("RemoteMediaManager#removeMemberVideoPane --> removeMemberVideoPane() called for a non-existent paneId: ".concat(paneId, " (pane not found in this.media.video.memberPanes)"));
1025
+
1026
+ return _promise.default.resolve();
1027
+ }
1028
+
1029
+ var remoteMedia = this.media.video.memberPanes[paneId];
1030
+ var receiveSlot = remoteMedia.getUnderlyingReceiveSlot();
1031
+
1032
+ if (receiveSlot) {
1033
+ this.receiveSlotManager.releaseSlot(receiveSlot);
1034
+ var index = this.slots.video.receiverSelected.indexOf(receiveSlot);
1035
+
1036
+ if (index >= 0) {
1037
+ this.slots.video.receiverSelected.splice(index, 1);
1038
+ }
1039
+ }
1040
+
1041
+ remoteMedia.stop();
1042
+ delete this.media.video.memberPanes[paneId];
1043
+ (_this$currentLayout$m3 = this.currentLayout.memberVideoPanes) === null || _this$currentLayout$m3 === void 0 ? true : delete _this$currentLayout$m3[paneId];
1044
+ return _promise.default.resolve();
1045
+ }
1046
+ /**
1047
+ * Pins an active speaker remote media object to the given CSI value. From that moment
1048
+ * onwards the remote media will only play audio/video from that specific CSI until
1049
+ * unpinActiveSpeakerVideoPane() is called or current layout is changed.
1050
+ *
1051
+ * @param {RemoteMedia} remoteMedia remote media object reference
1052
+ * @param {CSI} csi CSI value to pin to, if undefined, then current CSI value is used
1053
+ */
1054
+
1055
+ }, {
1056
+ key: "pinActiveSpeakerVideoPane",
1057
+ value: function pinActiveSpeakerVideoPane(remoteMedia, csi) {
1058
+ var remoteMediaGroup = (0, _values.default)(this.media.video.activeSpeakerGroups).find(function (group) {
1059
+ return group.includes(remoteMedia, 'unpinned');
1060
+ });
1061
+
1062
+ if (!remoteMediaGroup) {
1063
+ throw new Error('remoteMedia not found among the unpinned remote media from any active speaker group');
1064
+ }
1065
+
1066
+ remoteMediaGroup.pin(remoteMedia, csi);
1067
+ }
1068
+ /**
1069
+ * Unpins a remote media object from the fixed CSI value it was pinned to.
1070
+ *
1071
+ * @param {RemoteMedia} remoteMedia remote media object reference
1072
+ */
1073
+
1074
+ }, {
1075
+ key: "unpinActiveSpeakerVideoPane",
1076
+ value: function unpinActiveSpeakerVideoPane(remoteMedia) {
1077
+ var remoteMediaGroup = (0, _values.default)(this.media.video.activeSpeakerGroups).find(function (group) {
1078
+ return group.includes(remoteMedia, 'pinned');
1079
+ });
1080
+
1081
+ if (!remoteMediaGroup) {
1082
+ throw new Error('remoteMedia not found among the pinned remote media from any active speaker group');
1083
+ }
1084
+
1085
+ remoteMediaGroup.unpin(remoteMedia);
1086
+ }
1087
+ /**
1088
+ * Returns true if a given remote media object belongs to an active speaker group and has been pinned.
1089
+ * Throws an error if the remote media object doesn't belong to any active speaker remote media group.
1090
+ *
1091
+ * @param {RemoteMedia} remoteMedia remote media object
1092
+ * @returns {boolean}
1093
+ */
1094
+
1095
+ }, {
1096
+ key: "isPinned",
1097
+ value: function isPinned(remoteMedia) {
1098
+ var remoteMediaGroup = (0, _values.default)(this.media.video.activeSpeakerGroups).find(function (group) {
1099
+ return group.includes(remoteMedia);
1100
+ });
1101
+
1102
+ if (!remoteMediaGroup) {
1103
+ throw new Error('remoteMedia not found among any remote media (pinned or unpinned) from any active speaker group');
1104
+ }
1105
+
1106
+ return remoteMediaGroup.isPinned(remoteMedia);
1107
+ }
1108
+ }]);
1109
+ return RemoteMediaManager;
1110
+ }(_eventsScope.default);
1111
+
1112
+ exports.RemoteMediaManager = RemoteMediaManager;
1113
+ //# sourceMappingURL=remoteMediaManager.js.map