@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.
- package/dist/common/errors/webex-errors.js +5 -29
- package/dist/common/errors/webex-errors.js.map +1 -1
- package/dist/constants.js +15 -74
- package/dist/constants.js.map +1 -1
- package/dist/media/index.js +68 -213
- package/dist/media/index.js.map +1 -1
- package/dist/media/internal-media-core-wrapper.js +22 -0
- package/dist/media/internal-media-core-wrapper.js.map +1 -0
- package/dist/media/properties.js +20 -25
- package/dist/media/properties.js.map +1 -1
- package/dist/media/util.js +0 -27
- package/dist/media/util.js.map +1 -1
- package/dist/meeting/index.js +694 -432
- package/dist/meeting/index.js.map +1 -1
- package/dist/meeting/request.js +1 -0
- package/dist/meeting/request.js.map +1 -1
- package/dist/meeting/util.js +3 -44
- package/dist/meeting/util.js.map +1 -1
- package/dist/meetings/index.js +64 -5
- package/dist/meetings/index.js.map +1 -1
- package/dist/meetings/util.js +24 -1
- package/dist/meetings/util.js.map +1 -1
- package/dist/members/index.js +68 -0
- package/dist/members/index.js.map +1 -1
- package/dist/multistream/mediaRequestManager.js +132 -0
- package/dist/multistream/mediaRequestManager.js.map +1 -0
- package/dist/multistream/multistreamMedia.js +116 -0
- package/dist/multistream/multistreamMedia.js.map +1 -0
- package/dist/multistream/receiveSlot.js +209 -0
- package/dist/multistream/receiveSlot.js.map +1 -0
- package/dist/multistream/receiveSlotManager.js +195 -0
- package/dist/multistream/receiveSlotManager.js.map +1 -0
- package/dist/multistream/remoteMedia.js +284 -0
- package/dist/multistream/remoteMedia.js.map +1 -0
- package/dist/multistream/remoteMediaGroup.js +243 -0
- package/dist/multistream/remoteMediaGroup.js.map +1 -0
- package/dist/multistream/remoteMediaManager.js +1113 -0
- package/dist/multistream/remoteMediaManager.js.map +1 -0
- package/dist/reconnection-manager/index.js +109 -130
- package/dist/reconnection-manager/index.js.map +1 -1
- package/dist/roap/index.js +57 -240
- package/dist/roap/index.js.map +1 -1
- package/dist/roap/request.js +2 -114
- package/dist/roap/request.js.map +1 -1
- package/dist/roap/turnDiscovery.js +11 -5
- package/dist/roap/turnDiscovery.js.map +1 -1
- package/dist/statsAnalyzer/global.js +2 -0
- package/dist/statsAnalyzer/global.js.map +1 -1
- package/dist/statsAnalyzer/index.js +39 -36
- package/dist/statsAnalyzer/index.js.map +1 -1
- package/package.json +20 -19
- package/src/common/errors/webex-errors.js +0 -18
- package/src/constants.ts +139 -180
- package/src/media/index.js +60 -194
- package/src/media/internal-media-core-wrapper.ts +9 -0
- package/src/media/properties.js +19 -25
- package/src/media/util.js +0 -22
- package/src/meeting/index.js +565 -320
- package/src/meeting/request.js +1 -0
- package/src/meeting/util.js +3 -46
- package/src/meetings/index.js +30 -1
- package/src/meetings/util.js +23 -2
- package/src/members/index.js +48 -0
- package/src/multistream/mediaRequestManager.ts +164 -0
- package/src/multistream/multistreamMedia.ts +92 -0
- package/src/multistream/receiveSlot.ts +141 -0
- package/src/multistream/receiveSlotManager.ts +142 -0
- package/src/multistream/remoteMedia.ts +219 -0
- package/src/multistream/remoteMediaGroup.ts +224 -0
- package/src/multistream/remoteMediaManager.ts +911 -0
- package/src/reconnection-manager/index.js +40 -53
- package/src/roap/index.js +47 -207
- package/src/roap/request.js +1 -72
- package/src/roap/turnDiscovery.ts +12 -6
- package/src/statsAnalyzer/global.js +2 -0
- package/src/statsAnalyzer/index.js +32 -46
- package/test/integration/spec/journey.js +1 -1
- package/test/unit/spec/media/index.ts +223 -0
- package/test/unit/spec/media/properties.ts +73 -82
- package/test/unit/spec/meeting/effectsState.js +1 -3
- package/test/unit/spec/meeting/index.js +420 -228
- package/test/unit/spec/meeting/muteState.js +7 -0
- package/test/unit/spec/meeting/utils.js +61 -2
- package/test/unit/spec/meetings/index.js +0 -4
- package/test/unit/spec/members/index.js +164 -2
- package/test/unit/spec/multistream/mediaRequestManager.ts +511 -0
- package/test/unit/spec/multistream/receiveSlot.ts +104 -0
- package/test/unit/spec/multistream/receiveSlotManager.ts +173 -0
- package/test/unit/spec/multistream/remoteMedia.ts +217 -0
- package/test/unit/spec/multistream/remoteMediaGroup.ts +396 -0
- package/test/unit/spec/multistream/remoteMediaManager.ts +1251 -0
- package/test/unit/spec/roap/index.ts +63 -35
- package/test/unit/spec/stats-analyzer/index.js +19 -22
- package/dist/peer-connection-manager/index.js +0 -794
- package/dist/peer-connection-manager/index.js.map +0 -1
- package/dist/roap/collection.js +0 -73
- package/dist/roap/collection.js.map +0 -1
- package/dist/roap/handler.js +0 -337
- package/dist/roap/handler.js.map +0 -1
- package/dist/roap/state.js +0 -164
- package/dist/roap/state.js.map +0 -1
- package/dist/roap/util.js +0 -102
- package/dist/roap/util.js.map +0 -1
- package/src/peer-connection-manager/index.js +0 -723
- package/src/roap/collection.js +0 -63
- package/src/roap/handler.js +0 -252
- package/src/roap/state.js +0 -149
- package/src/roap/util.js +0 -93
- package/test/unit/spec/peerconnection-manager/index.js +0 -188
- package/test/unit/spec/peerconnection-manager/utils.js +0 -48
- package/test/unit/spec/roap/util.js +0 -30
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/* eslint-disable import/prefer-default-export */
|
|
2
|
+
import {MediaConnection as MC} from '@webex/internal-media-core';
|
|
3
|
+
|
|
4
|
+
import LoggerProxy from '../common/logs/logger-proxy';
|
|
5
|
+
import Meeting from '../meeting';
|
|
6
|
+
|
|
7
|
+
import {CSI, ReceiveSlot} from './receiveSlot';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Manages all receive slots used by a meeting. WMCE receive slots cannot be ever deleted,
|
|
11
|
+
* so this manager has a pool in order to re-use the slots that were released earlier.
|
|
12
|
+
*/
|
|
13
|
+
export class ReceiveSlotManager {
|
|
14
|
+
private allocatedSlots: {[key in MC.MediaType]: ReceiveSlot[]};
|
|
15
|
+
|
|
16
|
+
private freeSlots: {[key in MC.MediaType]: ReceiveSlot[]};
|
|
17
|
+
|
|
18
|
+
private meeting: Meeting;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Constructor
|
|
22
|
+
* @param {Meeting} meeting
|
|
23
|
+
*/
|
|
24
|
+
constructor(meeting) {
|
|
25
|
+
this.allocatedSlots = {
|
|
26
|
+
[MC.MediaType.AudioMain]: [],
|
|
27
|
+
[MC.MediaType.VideoMain]: [],
|
|
28
|
+
[MC.MediaType.AudioSlides]: [],
|
|
29
|
+
[MC.MediaType.VideoSlides]: [],
|
|
30
|
+
};
|
|
31
|
+
this.freeSlots = {
|
|
32
|
+
[MC.MediaType.AudioMain]: [],
|
|
33
|
+
[MC.MediaType.VideoMain]: [],
|
|
34
|
+
[MC.MediaType.AudioSlides]: [],
|
|
35
|
+
[MC.MediaType.VideoSlides]: [],
|
|
36
|
+
};
|
|
37
|
+
this.meeting = meeting;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Creates a new receive slot or returns one from the existing pool of free slots
|
|
42
|
+
*
|
|
43
|
+
* @param {MC.MediaType} mediaType
|
|
44
|
+
* @returns {Promise<ReceiveSlot>}
|
|
45
|
+
*/
|
|
46
|
+
async allocateSlot(mediaType: MC.MediaType): Promise<ReceiveSlot> {
|
|
47
|
+
if (!this.meeting?.mediaProperties?.webrtcMediaConnection) {
|
|
48
|
+
return Promise.reject(new Error('Webrtc media connection is missing'));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// try to use one of the free ones
|
|
52
|
+
const availableSlot = this.freeSlots[mediaType].pop();
|
|
53
|
+
|
|
54
|
+
if (availableSlot) {
|
|
55
|
+
this.allocatedSlots[mediaType].push(availableSlot);
|
|
56
|
+
|
|
57
|
+
LoggerProxy.logger.log(`receive slot re-used: ${availableSlot.id}`);
|
|
58
|
+
|
|
59
|
+
return availableSlot;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// we have to create a new one
|
|
63
|
+
const wcmeReceiveSlot =
|
|
64
|
+
await this.meeting.mediaProperties.webrtcMediaConnection.createReceiveSlot(mediaType);
|
|
65
|
+
|
|
66
|
+
const receiveSlot = new ReceiveSlot(
|
|
67
|
+
mediaType,
|
|
68
|
+
wcmeReceiveSlot,
|
|
69
|
+
(csi: CSI) => this.meeting.members.findMemberByCsi(csi)?.id
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
this.allocatedSlots[mediaType].push(receiveSlot);
|
|
73
|
+
LoggerProxy.logger.log(`new receive slot allocated: ${receiveSlot.id}`);
|
|
74
|
+
|
|
75
|
+
return receiveSlot;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Releases the slot back to the pool so it can be re-used by others in the future
|
|
80
|
+
* @param {ReceiveSlot} slot
|
|
81
|
+
*/
|
|
82
|
+
releaseSlot(slot: ReceiveSlot) {
|
|
83
|
+
const idx = this.allocatedSlots[slot.mediaType].findIndex(
|
|
84
|
+
(allocatedSlot) => allocatedSlot === slot
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
if (idx >= 0) {
|
|
88
|
+
this.allocatedSlots[slot.mediaType].splice(idx, 1);
|
|
89
|
+
this.freeSlots[slot.mediaType].push(slot);
|
|
90
|
+
LoggerProxy.logger.log(`receive slot released: ${slot.id}`);
|
|
91
|
+
} else {
|
|
92
|
+
LoggerProxy.logger.warn(
|
|
93
|
+
'ReceiveSlotManager#releaseSlot --> trying to release a slot that is not managed by this ReceiveSlotManager'
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Resets the slot manager - this method should be called when the media connection is torn down
|
|
100
|
+
*/
|
|
101
|
+
reset() {
|
|
102
|
+
this.allocatedSlots = {
|
|
103
|
+
[MC.MediaType.AudioMain]: [],
|
|
104
|
+
[MC.MediaType.VideoMain]: [],
|
|
105
|
+
[MC.MediaType.AudioSlides]: [],
|
|
106
|
+
[MC.MediaType.VideoSlides]: [],
|
|
107
|
+
};
|
|
108
|
+
this.freeSlots = {
|
|
109
|
+
[MC.MediaType.AudioMain]: [],
|
|
110
|
+
[MC.MediaType.VideoMain]: [],
|
|
111
|
+
[MC.MediaType.AudioSlides]: [],
|
|
112
|
+
[MC.MediaType.VideoSlides]: [],
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Returns statistics about the managed slots
|
|
118
|
+
*
|
|
119
|
+
* @returns {Object}
|
|
120
|
+
*/
|
|
121
|
+
getStats() {
|
|
122
|
+
const numAllocatedSlots = {};
|
|
123
|
+
const numFreeSlots = {};
|
|
124
|
+
|
|
125
|
+
Object.keys(this.allocatedSlots).forEach((key) => {
|
|
126
|
+
if (this.allocatedSlots[key].length > 0) {
|
|
127
|
+
numAllocatedSlots[key] = this.allocatedSlots[key].length;
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
Object.keys(this.freeSlots).forEach((key) => {
|
|
132
|
+
if (this.freeSlots[key].length > 0) {
|
|
133
|
+
numFreeSlots[key] = this.freeSlots[key].length;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
numAllocatedSlots,
|
|
139
|
+
numFreeSlots,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/* eslint-disable valid-jsdoc */
|
|
2
|
+
import LoggerProxy from '../common/logs/logger-proxy';
|
|
3
|
+
import EventsScope from '../common/events/events-scope';
|
|
4
|
+
|
|
5
|
+
import {MediaRequestId, MediaRequestManager} from './mediaRequestManager';
|
|
6
|
+
import {CSI, ReceiveSlot, ReceiveSlotEvents} from './receiveSlot';
|
|
7
|
+
|
|
8
|
+
export const RemoteMediaEvents = {
|
|
9
|
+
SourceUpdate: ReceiveSlotEvents.SourceUpdate,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type RemoteVideoResolution =
|
|
13
|
+
| 'thumbnail' // the smallest possible resolution, 90p or less
|
|
14
|
+
| 'very small' // 180p or less
|
|
15
|
+
| 'small' // 360p or less
|
|
16
|
+
| 'medium' // 720p or less
|
|
17
|
+
| 'large' // 1080p or less
|
|
18
|
+
| 'best'; // highest possible resolution
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Converts pane size into h264 maxFs
|
|
22
|
+
* @param {PaneSize} paneSize
|
|
23
|
+
* @returns {number}
|
|
24
|
+
*/
|
|
25
|
+
export function getMaxFs(paneSize: RemoteVideoResolution): number {
|
|
26
|
+
let maxFs;
|
|
27
|
+
|
|
28
|
+
switch (paneSize) {
|
|
29
|
+
case 'thumbnail':
|
|
30
|
+
maxFs = 60;
|
|
31
|
+
break;
|
|
32
|
+
case 'very small':
|
|
33
|
+
maxFs = 240;
|
|
34
|
+
break;
|
|
35
|
+
case 'small':
|
|
36
|
+
maxFs = 920;
|
|
37
|
+
break;
|
|
38
|
+
case 'medium':
|
|
39
|
+
maxFs = 3600;
|
|
40
|
+
break;
|
|
41
|
+
case 'large':
|
|
42
|
+
maxFs = 8192;
|
|
43
|
+
break;
|
|
44
|
+
case 'best':
|
|
45
|
+
maxFs = 8192; // for now 'best' is 1080p, so same as 'large'
|
|
46
|
+
break;
|
|
47
|
+
default:
|
|
48
|
+
LoggerProxy.logger.warn(
|
|
49
|
+
`RemoteMedia#getMaxFs --> unsupported paneSize: ${paneSize}, using "medium" instead`
|
|
50
|
+
);
|
|
51
|
+
maxFs = 3600;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return maxFs;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
type Options = {
|
|
58
|
+
resolution?: RemoteVideoResolution; // applies only to groups of type MC.MediaType.VideoMain and MC.MediaType.VideoSlides
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export type RemoteMediaId = string;
|
|
62
|
+
|
|
63
|
+
let remoteMediaCounter = 0;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Class representing a remote audio/video stream.
|
|
67
|
+
*
|
|
68
|
+
* Internally it is associated with a specific receive slot
|
|
69
|
+
* and a media request for it.
|
|
70
|
+
*/
|
|
71
|
+
export class RemoteMedia extends EventsScope {
|
|
72
|
+
private receiveSlot?: ReceiveSlot;
|
|
73
|
+
|
|
74
|
+
private readonly mediaRequestManager: MediaRequestManager;
|
|
75
|
+
|
|
76
|
+
private readonly options: Options;
|
|
77
|
+
|
|
78
|
+
private mediaRequestId?: MediaRequestId;
|
|
79
|
+
|
|
80
|
+
public readonly id: RemoteMediaId;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Constructs RemoteMedia instance
|
|
84
|
+
*
|
|
85
|
+
* @param receiveSlot
|
|
86
|
+
* @param mediaRequestManager
|
|
87
|
+
* @param options
|
|
88
|
+
*/
|
|
89
|
+
constructor(
|
|
90
|
+
receiveSlot: ReceiveSlot,
|
|
91
|
+
mediaRequestManager: MediaRequestManager,
|
|
92
|
+
options?: Options
|
|
93
|
+
) {
|
|
94
|
+
super();
|
|
95
|
+
remoteMediaCounter += 1;
|
|
96
|
+
this.receiveSlot = receiveSlot;
|
|
97
|
+
this.mediaRequestManager = mediaRequestManager;
|
|
98
|
+
this.options = options || {};
|
|
99
|
+
this.setupEventListeners();
|
|
100
|
+
this.id = `RM${remoteMediaCounter}-${this.receiveSlot.id}`;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Invalidates the remote media by clearing the reference to a receive slot and
|
|
105
|
+
* cancelling the media request.
|
|
106
|
+
* After this call the remote media is unusable.
|
|
107
|
+
*
|
|
108
|
+
* @param {boolean} commit - whether to commit the cancellation of the media request
|
|
109
|
+
* @internal
|
|
110
|
+
*/
|
|
111
|
+
public stop(commit: boolean = true) {
|
|
112
|
+
this.cancelMediaRequest(commit);
|
|
113
|
+
this.receiveSlot?.removeAllListeners();
|
|
114
|
+
this.receiveSlot = undefined;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Sends a new media request. This method can only be used for receiver-selected policy,
|
|
119
|
+
* because only in that policy we have a 1-1 relationship between RemoteMedia and MediaRequest
|
|
120
|
+
* and the request id is then stored in this RemoteMedia instance.
|
|
121
|
+
* For active-speaker policy, the same request is shared among many RemoteMedia instances,
|
|
122
|
+
* so it's managed through RemoteMediaGroup
|
|
123
|
+
*
|
|
124
|
+
* @internal
|
|
125
|
+
*/
|
|
126
|
+
public sendMediaRequest(csi: CSI, commit: boolean) {
|
|
127
|
+
if (this.mediaRequestId) {
|
|
128
|
+
this.cancelMediaRequest(false);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (!this.receiveSlot) {
|
|
132
|
+
throw new Error('sendMediaRequest() called on an invalidated RemoteMedia instance');
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
this.mediaRequestId = this.mediaRequestManager.addRequest(
|
|
136
|
+
{
|
|
137
|
+
policyInfo: {
|
|
138
|
+
policy: 'receiver-selected',
|
|
139
|
+
csi,
|
|
140
|
+
},
|
|
141
|
+
receiveSlots: [this.receiveSlot],
|
|
142
|
+
codecInfo: this.options.resolution && {
|
|
143
|
+
codec: 'h264',
|
|
144
|
+
maxFs: getMaxFs(this.options.resolution),
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
commit
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* @internal
|
|
153
|
+
*/
|
|
154
|
+
public cancelMediaRequest(commit: boolean) {
|
|
155
|
+
if (this.mediaRequestId) {
|
|
156
|
+
this.mediaRequestManager.cancelRequest(this.mediaRequestId, commit);
|
|
157
|
+
this.mediaRequestId = undefined;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* registers event listeners on the receive slot and forwards all the events
|
|
163
|
+
*/
|
|
164
|
+
private setupEventListeners() {
|
|
165
|
+
if (this.receiveSlot) {
|
|
166
|
+
const scope = {
|
|
167
|
+
file: 'meeting/remoteMedia',
|
|
168
|
+
function: 'setupEventListeners',
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
this.receiveSlot.on(ReceiveSlotEvents.SourceUpdate, (data) => {
|
|
172
|
+
this.emit(scope, RemoteMediaEvents.SourceUpdate, data);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Getter for mediaType
|
|
179
|
+
*/
|
|
180
|
+
public get mediaType() {
|
|
181
|
+
return this.receiveSlot?.mediaType;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Getter for memberId
|
|
186
|
+
*/
|
|
187
|
+
public get memberId() {
|
|
188
|
+
return this.receiveSlot?.memberId;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Getter for csi
|
|
193
|
+
*/
|
|
194
|
+
public get csi() {
|
|
195
|
+
return this.receiveSlot?.csi;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Getter for source state
|
|
200
|
+
*/
|
|
201
|
+
public get sourceState() {
|
|
202
|
+
return this.receiveSlot?.sourceState;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Getter for remote media stream
|
|
207
|
+
*/
|
|
208
|
+
public get stream() {
|
|
209
|
+
return this.receiveSlot?.stream;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* @internal
|
|
214
|
+
* @returns {ReceiveSlot}
|
|
215
|
+
*/
|
|
216
|
+
public getUnderlyingReceiveSlot() {
|
|
217
|
+
return this.receiveSlot;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/* eslint-disable valid-jsdoc */
|
|
2
|
+
/* eslint-disable require-jsdoc */
|
|
3
|
+
/* eslint-disable import/prefer-default-export */
|
|
4
|
+
import LoggerProxy from '../common/logs/logger-proxy';
|
|
5
|
+
|
|
6
|
+
import {getMaxFs, RemoteMedia, RemoteVideoResolution} from './remoteMedia';
|
|
7
|
+
import {MediaRequestId, MediaRequestManager} from './mediaRequestManager';
|
|
8
|
+
import {CSI, ReceiveSlot} from './receiveSlot';
|
|
9
|
+
|
|
10
|
+
type Options = {
|
|
11
|
+
resolution?: RemoteVideoResolution; // applies only to groups of type MC.MediaType.VideoMain and MC.MediaType.VideoSlides
|
|
12
|
+
preferLiveVideo?: boolean; // applies only to groups of type MC.MediaType.VideoMain and MC.MediaType.VideoSlides
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export class RemoteMediaGroup {
|
|
16
|
+
private mediaRequestManager: MediaRequestManager;
|
|
17
|
+
|
|
18
|
+
private priority: number;
|
|
19
|
+
|
|
20
|
+
private options: Options;
|
|
21
|
+
|
|
22
|
+
private unpinnedRemoteMedia: RemoteMedia[];
|
|
23
|
+
|
|
24
|
+
private mediaRequestId?: MediaRequestId; // id of the "active-speaker" media request id
|
|
25
|
+
|
|
26
|
+
private pinnedRemoteMedia: RemoteMedia[];
|
|
27
|
+
|
|
28
|
+
constructor(
|
|
29
|
+
mediaRequestManager: MediaRequestManager,
|
|
30
|
+
receiveSlots: ReceiveSlot[],
|
|
31
|
+
priority: number,
|
|
32
|
+
commitMediaRequest: boolean,
|
|
33
|
+
options: Options = {}
|
|
34
|
+
) {
|
|
35
|
+
this.mediaRequestManager = mediaRequestManager;
|
|
36
|
+
this.priority = priority;
|
|
37
|
+
this.options = options;
|
|
38
|
+
|
|
39
|
+
this.unpinnedRemoteMedia = receiveSlots.map(
|
|
40
|
+
(slot) =>
|
|
41
|
+
new RemoteMedia(slot, this.mediaRequestManager, {
|
|
42
|
+
resolution: this.options.resolution,
|
|
43
|
+
})
|
|
44
|
+
);
|
|
45
|
+
this.pinnedRemoteMedia = [];
|
|
46
|
+
|
|
47
|
+
this.sendActiveSpeakerMediaRequest(commitMediaRequest);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Gets the array of remote media elements from the group
|
|
52
|
+
*
|
|
53
|
+
* @param {string} filter - 'all' (default) returns both pinned and unpinned
|
|
54
|
+
* @returns {Array<RemoteMedia>}
|
|
55
|
+
*/
|
|
56
|
+
public getRemoteMedia(filter: 'all' | 'pinned' | 'unpinned' = 'all') {
|
|
57
|
+
if (filter === 'unpinned') {
|
|
58
|
+
// return a shallow copy so that the client cannot modify this.unpinnedRemoteMedia array
|
|
59
|
+
return [...this.unpinnedRemoteMedia];
|
|
60
|
+
}
|
|
61
|
+
if (filter === 'pinned') {
|
|
62
|
+
// return a shallow copy so that the client cannot modify this.pinnedRemoteMedia array
|
|
63
|
+
return [...this.pinnedRemoteMedia];
|
|
64
|
+
}
|
|
65
|
+
return [...this.unpinnedRemoteMedia, ...this.pinnedRemoteMedia];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Pins a specific remote media instance to a specfic CSI, so the media will
|
|
70
|
+
* no longer come from active speaker, but from that CSI.
|
|
71
|
+
* If no CSI is given, the current CSI value is used.
|
|
72
|
+
*
|
|
73
|
+
*/
|
|
74
|
+
public pin(remoteMedia: RemoteMedia, csi?: CSI): void {
|
|
75
|
+
// if csi is not specified, use the current one
|
|
76
|
+
const targetCsi = csi || remoteMedia.csi;
|
|
77
|
+
|
|
78
|
+
if (!targetCsi) {
|
|
79
|
+
throw new Error(
|
|
80
|
+
`failed to pin a remote media object ${remoteMedia.id}, because it has no CSI set and no CSI value was given`
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (this.pinnedRemoteMedia.indexOf(remoteMedia) >= 0) {
|
|
85
|
+
if (targetCsi === remoteMedia.csi) {
|
|
86
|
+
// remote media already pinned to target CSI, nothing to do
|
|
87
|
+
LoggerProxy.logger.log(
|
|
88
|
+
`RemoteMediaGroup#pin --> remote media ${remoteMedia.id} already pinned`
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
} else {
|
|
94
|
+
const idx = this.unpinnedRemoteMedia.indexOf(remoteMedia);
|
|
95
|
+
|
|
96
|
+
if (idx < 0) {
|
|
97
|
+
throw new Error(
|
|
98
|
+
`failed to pin a remote media object ${remoteMedia.id}, because it is not found in this remote media group`
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
this.unpinnedRemoteMedia.splice(idx, 1);
|
|
103
|
+
this.pinnedRemoteMedia.push(remoteMedia);
|
|
104
|
+
|
|
105
|
+
this.cancelActiveSpeakerMediaRequest(false);
|
|
106
|
+
this.sendActiveSpeakerMediaRequest(false);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
remoteMedia.sendMediaRequest(targetCsi, false);
|
|
110
|
+
this.mediaRequestManager.commit();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Unpins a remote media instance, so that it will again provide media from active speakers
|
|
115
|
+
*
|
|
116
|
+
*/
|
|
117
|
+
public unpin(remoteMedia: RemoteMedia) {
|
|
118
|
+
if (this.unpinnedRemoteMedia.indexOf(remoteMedia) >= 0) {
|
|
119
|
+
LoggerProxy.logger.log(
|
|
120
|
+
`RemoteMediaGroup#pin --> remote media ${remoteMedia.id} already unpinned`
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const idx = this.pinnedRemoteMedia.indexOf(remoteMedia);
|
|
126
|
+
|
|
127
|
+
if (idx < 0) {
|
|
128
|
+
throw new Error(
|
|
129
|
+
`failed to unpin a remote media object ${remoteMedia.id}, because it is not found in this remote media group`
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
this.pinnedRemoteMedia.splice(idx, 1);
|
|
134
|
+
this.unpinnedRemoteMedia.push(remoteMedia);
|
|
135
|
+
|
|
136
|
+
remoteMedia.cancelMediaRequest(false);
|
|
137
|
+
this.cancelActiveSpeakerMediaRequest(false);
|
|
138
|
+
this.sendActiveSpeakerMediaRequest(false);
|
|
139
|
+
this.mediaRequestManager.commit();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
public isPinned(remoteMedia: RemoteMedia) {
|
|
143
|
+
if (this.unpinnedRemoteMedia.indexOf(remoteMedia) >= 0) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
if (this.pinnedRemoteMedia.indexOf(remoteMedia) >= 0) {
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
throw new Error(`remote media object ${remoteMedia.id} not found in the group`);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
private sendActiveSpeakerMediaRequest(commit: boolean) {
|
|
154
|
+
this.cancelActiveSpeakerMediaRequest(false);
|
|
155
|
+
|
|
156
|
+
this.mediaRequestId = this.mediaRequestManager.addRequest(
|
|
157
|
+
{
|
|
158
|
+
policyInfo: {
|
|
159
|
+
policy: 'active-speaker',
|
|
160
|
+
priority: this.priority,
|
|
161
|
+
crossPriorityDuplication: false,
|
|
162
|
+
crossPolicyDuplication: false,
|
|
163
|
+
preferLiveVideo: !!this.options?.preferLiveVideo,
|
|
164
|
+
},
|
|
165
|
+
receiveSlots: this.unpinnedRemoteMedia.map((remoteMedia) =>
|
|
166
|
+
remoteMedia.getUnderlyingReceiveSlot()
|
|
167
|
+
) as ReceiveSlot[],
|
|
168
|
+
codecInfo: this.options.resolution && {
|
|
169
|
+
codec: 'h264',
|
|
170
|
+
maxFs: getMaxFs(this.options.resolution),
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
commit
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
private cancelActiveSpeakerMediaRequest(commit: boolean) {
|
|
178
|
+
if (this.mediaRequestId) {
|
|
179
|
+
this.mediaRequestManager.cancelRequest(this.mediaRequestId, commit);
|
|
180
|
+
this.mediaRequestId = undefined;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Invalidates the remote media group by clearing the references to the receive slots
|
|
186
|
+
* used by all remote media from that group and cancelling all media requests.
|
|
187
|
+
* After this call the remote media group is unusable.
|
|
188
|
+
*
|
|
189
|
+
* @param{boolean} commit whether to commit the cancellation of media requests
|
|
190
|
+
* @internal
|
|
191
|
+
*/
|
|
192
|
+
public stop(commit: boolean = true) {
|
|
193
|
+
this.unpinnedRemoteMedia.forEach((remoteMedia) => remoteMedia.stop(false));
|
|
194
|
+
this.pinnedRemoteMedia.forEach((remoteMedia) => remoteMedia.stop(false));
|
|
195
|
+
this.cancelActiveSpeakerMediaRequest(false);
|
|
196
|
+
|
|
197
|
+
if (commit) {
|
|
198
|
+
this.mediaRequestManager.commit();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Checks if a given RemoteMedia instance belongs to this group.
|
|
204
|
+
*
|
|
205
|
+
* @param remoteMedia RemoteMedia instance to check
|
|
206
|
+
* @param filter controls which remote media from the group to check
|
|
207
|
+
* @returns true if remote media is found
|
|
208
|
+
*/
|
|
209
|
+
public includes(
|
|
210
|
+
remoteMedia: RemoteMedia,
|
|
211
|
+
filter: 'all' | 'pinned' | 'unpinned' = 'all'
|
|
212
|
+
): boolean {
|
|
213
|
+
if (filter === 'pinned') {
|
|
214
|
+
return this.pinnedRemoteMedia.includes(remoteMedia);
|
|
215
|
+
}
|
|
216
|
+
if (filter === 'unpinned') {
|
|
217
|
+
return this.unpinnedRemoteMedia.includes(remoteMedia);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return (
|
|
221
|
+
this.unpinnedRemoteMedia.includes(remoteMedia) || this.pinnedRemoteMedia.includes(remoteMedia)
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
}
|