@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
|
@@ -1,723 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
// We need to figure out how to pass a webex logger instance to these util files
|
|
3
|
-
|
|
4
|
-
/* globals RTCSessionDescription */
|
|
5
|
-
|
|
6
|
-
import window from 'global/window';
|
|
7
|
-
import sdpTransform from 'sdp-transform'; // https://github.com/clux/sdp-transform
|
|
8
|
-
|
|
9
|
-
import Metrics from '../metrics';
|
|
10
|
-
import LoggerProxy from '../common/logs/logger-proxy';
|
|
11
|
-
import StaticConfig from '../common/config';
|
|
12
|
-
import {
|
|
13
|
-
COMPLETE,
|
|
14
|
-
GATHERING,
|
|
15
|
-
AUDIO,
|
|
16
|
-
SDP,
|
|
17
|
-
ICE_STATE,
|
|
18
|
-
CONNECTION_STATE,
|
|
19
|
-
NETWORK_STATUS,
|
|
20
|
-
PEER_CONNECTION_STATE,
|
|
21
|
-
OFFER,
|
|
22
|
-
QUALITY_LEVELS,
|
|
23
|
-
REMOTE_VIDEO_CONSTRAINTS
|
|
24
|
-
} from '../constants';
|
|
25
|
-
import BEHAVIORAL_METRICS from '../metrics/constants';
|
|
26
|
-
import {error, eventType} from '../metrics/config';
|
|
27
|
-
import MediaError from '../common/errors/media';
|
|
28
|
-
import ParameterError from '../common/errors/parameter';
|
|
29
|
-
import {InvalidSdpError} from '../common/errors/webex-errors';
|
|
30
|
-
import BrowserDetection from '../common/browser-detection';
|
|
31
|
-
|
|
32
|
-
import PeerConnectionUtils from './util';
|
|
33
|
-
|
|
34
|
-
const {isBrowser} = BrowserDetection();
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* @export
|
|
38
|
-
* @public
|
|
39
|
-
*/
|
|
40
|
-
const pc = {};
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* munges the bandwidth limit into the sdp
|
|
44
|
-
* @param {String} sdpLines
|
|
45
|
-
* @param {Number} index
|
|
46
|
-
* @returns {String}
|
|
47
|
-
*/
|
|
48
|
-
const insertBandwidthLimit = (sdpLines, index) => {
|
|
49
|
-
// eslint-disable-next-line no-warning-comments
|
|
50
|
-
// TODO convert to sdp parser
|
|
51
|
-
let limit;
|
|
52
|
-
let periodicKeyFrame = '';
|
|
53
|
-
|
|
54
|
-
if (sdpLines[index].search(AUDIO) !== -1) {
|
|
55
|
-
limit = StaticConfig.meetings.bandwidth.audio;
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
limit = StaticConfig.meetings.bandwidth.video;
|
|
59
|
-
periodicKeyFrame = SDP.PERIODIC_KEYFRAME;
|
|
60
|
-
sdpLines.splice(index + 2, 0, periodicKeyFrame);
|
|
61
|
-
}
|
|
62
|
-
sdpLines.splice(index + 1, 0, `${SDP.B_LINE}:${limit}`);
|
|
63
|
-
|
|
64
|
-
return sdpLines;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* needed for calliope max-fs
|
|
69
|
-
* @param {String} sdp
|
|
70
|
-
* @param {String} [level=QUALITY_LEVELS.HIGH] quality level for max-fs
|
|
71
|
-
* @returns {String}
|
|
72
|
-
*/
|
|
73
|
-
const setRemoteVideoConstraints = (sdp, level = QUALITY_LEVELS.HIGH) => {
|
|
74
|
-
const maxFs = REMOTE_VIDEO_CONSTRAINTS.MAX_FS[level];
|
|
75
|
-
|
|
76
|
-
if (!maxFs) {
|
|
77
|
-
throw new ParameterError(`setRemoteVideoConstraints: unable to set max framesize, value for level "${level}" is not defined`);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const modifiedSdp = PeerConnectionUtils.adjustH264Profile(sdp, maxFs);
|
|
81
|
-
|
|
82
|
-
return modifiedSdp;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const setStartBitrateOnRemoteSdp = (sdp) => {
|
|
87
|
-
if (StaticConfig.meetings.bandwidth.startBitrate) {
|
|
88
|
-
sdp = sdp.replace(/(\na=fmtp:(\d+).*profile-level-id=.*)/gi, `$1;x-google-start-bitrate=${StaticConfig.meetings.bandwidth.startBitrate}`);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return sdp;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* checks that sdp has h264 codec in it
|
|
96
|
-
* @param {String} sdp
|
|
97
|
-
* @returns {boolean}
|
|
98
|
-
*/
|
|
99
|
-
const checkH264Support = (sdp) => {
|
|
100
|
-
// eslint-disable-next-line no-warning-comments
|
|
101
|
-
// TODO convert to sdp parser to read rtp.codec
|
|
102
|
-
const videoPresent = sdp.match(/\nm=video.*/g);
|
|
103
|
-
const h264Present = sdp.match(/\na=rtpmap:\d+\sH264.*/g);
|
|
104
|
-
|
|
105
|
-
if (videoPresent) {
|
|
106
|
-
return !!h264Present;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return true;
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* validates the sdp, checks port, candidates, and ice info
|
|
114
|
-
* @param {String} sdp
|
|
115
|
-
* @returns {String}
|
|
116
|
-
*/
|
|
117
|
-
const isSdpInvalid = (sdp) => {
|
|
118
|
-
const parsedSdp = sdpTransform.parse(sdp);
|
|
119
|
-
|
|
120
|
-
for (const mediaLine of parsedSdp.media) {
|
|
121
|
-
if (!mediaLine.candidates || mediaLine.candidates?.length === 0) {
|
|
122
|
-
LoggerProxy.logger.error('PeerConnectionManager:index#isSdpInvalid --> iceCandidate: Ice candidate never completed');
|
|
123
|
-
|
|
124
|
-
return 'iceCandidate: Ice gathering never completed';
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (SDP.BAD_MEDIA_PORTS.includes(mediaLine.port)) {
|
|
128
|
-
LoggerProxy.logger.error('PeerConnectionManager:index#isSdpInvalid --> iceCandidate: Found invalid port number for the ice candidate');
|
|
129
|
-
|
|
130
|
-
return 'iceCandidate: Found invalid port number for the ice candidate';
|
|
131
|
-
}
|
|
132
|
-
if (!mediaLine.icePwd || !mediaLine.iceUfrag) {
|
|
133
|
-
LoggerProxy.logger.error('PeerConnectionManager:index#isSdpInvalid --> iceCandidate: ice ufrag and password not found');
|
|
134
|
-
|
|
135
|
-
return 'iceCandidate: ice ufrag and password not found';
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return '';
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* munges the bandwidth into the sdp
|
|
144
|
-
* @param {String} sdp
|
|
145
|
-
* @returns {String}
|
|
146
|
-
*/
|
|
147
|
-
const limitBandwidth = (sdp) => {
|
|
148
|
-
// TODO convert to sdp parser
|
|
149
|
-
let offerSdp = sdp;
|
|
150
|
-
let sdpLines = offerSdp.split(SDP.CARRIAGE_RETURN);
|
|
151
|
-
|
|
152
|
-
for (let i = 0; i < sdpLines.length; i += 1) {
|
|
153
|
-
if (sdpLines[i].search(SDP.M_LINE) !== -1) {
|
|
154
|
-
sdpLines = insertBandwidthLimit(sdpLines, i);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
offerSdp = sdpLines.join(SDP.CARRIAGE_RETURN);
|
|
158
|
-
|
|
159
|
-
return offerSdp;
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* makes sure the screen pc sdp has content:slides for server
|
|
164
|
-
* @param {RTCPeerConnection} screenPc
|
|
165
|
-
* @returns {RTCPeerConnection}
|
|
166
|
-
*/
|
|
167
|
-
pc.setContentSlides = (screenPc) => {
|
|
168
|
-
if (screenPc && screenPc.sdp) {
|
|
169
|
-
screenPc.sdp += `${SDP.A_CONTENT_SLIDES}${SDP.CARRIAGE_RETURN}`;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
return screenPc;
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* handles ice trickling and establishes ICE connection onto peer connection object
|
|
177
|
-
* @param {Object} peerConnection
|
|
178
|
-
* @param {Object} options
|
|
179
|
-
* @param {String} options.remoteQualityLevel
|
|
180
|
-
* @returns {Promise.RTCPeerConnection}
|
|
181
|
-
*/
|
|
182
|
-
pc.iceCandidate = (peerConnection, {remoteQualityLevel}) =>
|
|
183
|
-
new Promise((resolve, reject) => {
|
|
184
|
-
const now = Date.now();
|
|
185
|
-
const doneGatheringIceCandidate = () => {
|
|
186
|
-
const miliseconds = parseInt(Math.abs(Date.now() - now), 4);
|
|
187
|
-
|
|
188
|
-
peerConnection.sdp = limitBandwidth(peerConnection.localDescription.sdp);
|
|
189
|
-
peerConnection.sdp = PeerConnectionUtils.convertCLineToIpv4(peerConnection.sdp);
|
|
190
|
-
peerConnection.sdp = setRemoteVideoConstraints(peerConnection.sdp, remoteQualityLevel);
|
|
191
|
-
|
|
192
|
-
const invalidSdpPresent = isSdpInvalid(peerConnection.sdp);
|
|
193
|
-
|
|
194
|
-
if (invalidSdpPresent) {
|
|
195
|
-
LoggerProxy.logger.error('PeerConnectionManager:index#iceCandidate --> SDP not valid after waiting.');
|
|
196
|
-
reject(new InvalidSdpError(invalidSdpPresent));
|
|
197
|
-
}
|
|
198
|
-
LoggerProxy.logger.log(`PeerConnectionManager:index#iceCandidate --> Time to gather ice candidate ${miliseconds} miliseconds`);
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
resolve();
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
// If ice has already been gathered
|
|
205
|
-
if (peerConnection.iceGatheringState === COMPLETE) {
|
|
206
|
-
doneGatheringIceCandidate();
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
peerConnection.onIceGatheringStateChange = () => {
|
|
210
|
-
if (peerConnection.iceGatheringState === COMPLETE) {
|
|
211
|
-
doneGatheringIceCandidate(peerConnection);
|
|
212
|
-
}
|
|
213
|
-
if (peerConnection.iceGatheringState === GATHERING) {
|
|
214
|
-
LoggerProxy.logger.log('PeerConnectionManager:index#onIceGatheringStateChange --> Ice state changed to gathering');
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
peerConnection.onicecandidate = (evt) => {
|
|
219
|
-
if (evt.candidate === null) {
|
|
220
|
-
doneGatheringIceCandidate(peerConnection);
|
|
221
|
-
}
|
|
222
|
-
else {
|
|
223
|
-
LoggerProxy.logger.log(`PeerConnectionManager:index#onicecandidate --> Candidate ${evt.candidate?.type} ${evt.candidate?.protocol} ${evt.candidate?.address}:${evt.candidate?.port}`);
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
peerConnection.onicecandidateerror = (event) => {
|
|
228
|
-
// we can often get ICE candidate errors (for example when failing to communicate with a TURN server)
|
|
229
|
-
// they don't mean that the whole ICE connection will fail, so it's OK to ignore them
|
|
230
|
-
LoggerProxy.logger.error('PeerConnectionManager:index#onicecandidateerror --> ignoring ice error:', event);
|
|
231
|
-
};
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* swapping tracks
|
|
236
|
-
* @param {Object} peerConnection
|
|
237
|
-
* @param {Object} track
|
|
238
|
-
* @returns {undefined}
|
|
239
|
-
*/
|
|
240
|
-
pc.replaceTrack = (peerConnection, track) => {
|
|
241
|
-
try {
|
|
242
|
-
const senders = peerConnection.getSenders();
|
|
243
|
-
|
|
244
|
-
if (senders.length > 0) {
|
|
245
|
-
senders.forEach((sender) => {
|
|
246
|
-
if (sender.track && sender.track.kind === track.kind) {
|
|
247
|
-
sender.replaceTrack(track);
|
|
248
|
-
}
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
catch (err) {
|
|
253
|
-
LoggerProxy.logger.error(`PeerConnectionManager:index#replaceTrack --> Error replacing track, ${err}`);
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
* adding streams to peerConnection
|
|
259
|
-
* @param {Object} peerConnection
|
|
260
|
-
* @param {Object} stream
|
|
261
|
-
* @returns {undefined}
|
|
262
|
-
*/
|
|
263
|
-
pc.addStream = (peerConnection, stream) => {
|
|
264
|
-
try {
|
|
265
|
-
if (stream && !isBrowser('edge')) {
|
|
266
|
-
const tracksPresent = peerConnection.getSenders && peerConnection.getSenders().find((sender) => sender.track != null);
|
|
267
|
-
|
|
268
|
-
if (tracksPresent) {
|
|
269
|
-
stream.getTracks().forEach((track) => {
|
|
270
|
-
pc.replaceTrack(peerConnection, track);
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
275
|
-
stream.getTracks().forEach((track) => {
|
|
276
|
-
peerConnection.addTrack(track, stream);
|
|
277
|
-
});
|
|
278
|
-
// // TODO : may come back disable addTracks for chrome they are moving back to addStream
|
|
279
|
-
// // https://bugs.chromium.org/p/chromium/issues/detail?id=764414
|
|
280
|
-
// // https://bugs.chromium.org/p/chromium/issues/detail?id=738918#c7
|
|
281
|
-
// peerConnection.addStream(stream);
|
|
282
|
-
}
|
|
283
|
-
else if (isBrowser('edge')) {
|
|
284
|
-
peerConnection.addStream(stream);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
catch (err) {
|
|
288
|
-
LoggerProxy.logger.error(`PeerConnectionManager:index#addStream --> Error adding stream, error: ${error}`);
|
|
289
|
-
}
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
/**
|
|
293
|
-
* setting the remote description
|
|
294
|
-
* @param {Object} peerConnection
|
|
295
|
-
* @param {String} typeStr
|
|
296
|
-
* @param {String} remoteSdp
|
|
297
|
-
* @param {String} meetingId
|
|
298
|
-
* @returns {undefined}
|
|
299
|
-
*/
|
|
300
|
-
pc.setRemoteSessionDetails = (
|
|
301
|
-
peerConnection,
|
|
302
|
-
typeStr,
|
|
303
|
-
remoteSdp,
|
|
304
|
-
meetingId,
|
|
305
|
-
) => {
|
|
306
|
-
LoggerProxy.logger.log(`PeerConnectionManager:index#setRemoteSessionDetails --> Setting the remote description type: ${typeStr}State: ${peerConnection.signalingState}`);
|
|
307
|
-
let sdp = remoteSdp;
|
|
308
|
-
|
|
309
|
-
// making sure that the remoteDescription is only set when there is a answer for offer
|
|
310
|
-
// or there is a offer from the server
|
|
311
|
-
|
|
312
|
-
if (!sdp) {
|
|
313
|
-
Metrics.postEvent({
|
|
314
|
-
event: eventType.REMOTE_SDP_RECEIVED,
|
|
315
|
-
meetingId,
|
|
316
|
-
data: {
|
|
317
|
-
canProceed: false,
|
|
318
|
-
errors: [Metrics.generateErrorPayload(2001, true,
|
|
319
|
-
error.name.MEDIA_ENGINE, 'missing remoteSdp')]
|
|
320
|
-
}
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
if (peerConnection.signalingState === SDP.HAVE_LOCAL_OFFER || (peerConnection.signalingState === SDP.STABLE && typeStr === SDP.OFFER)) {
|
|
324
|
-
sdp = setStartBitrateOnRemoteSdp(sdp);
|
|
325
|
-
|
|
326
|
-
if (!peerConnection.enableExtmap) {
|
|
327
|
-
sdp = sdp.replace(/\na=extmap.*/g, '');
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
// remove any xtls candidates
|
|
331
|
-
sdp = sdp.replace(/^a=candidate:.*xTLS.*\r\n/gim, '');
|
|
332
|
-
|
|
333
|
-
return peerConnection.setRemoteDescription(
|
|
334
|
-
new window.RTCSessionDescription({
|
|
335
|
-
type: typeStr,
|
|
336
|
-
sdp
|
|
337
|
-
})
|
|
338
|
-
)
|
|
339
|
-
.then(() => {
|
|
340
|
-
if (peerConnection.signalingState === SDP.STABLE) {
|
|
341
|
-
Metrics.postEvent({
|
|
342
|
-
event: eventType.REMOTE_SDP_RECEIVED,
|
|
343
|
-
meetingId
|
|
344
|
-
});
|
|
345
|
-
}
|
|
346
|
-
})
|
|
347
|
-
.catch((error) => {
|
|
348
|
-
LoggerProxy.logger.error(`Peer-connection-manager:index#setRemoteDescription --> ${error} missing remotesdp`);
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
const metricName = BEHAVIORAL_METRICS.PEERCONNECTION_FAILURE;
|
|
352
|
-
const data = {
|
|
353
|
-
correlation_id: meetingId,
|
|
354
|
-
reason: error.message,
|
|
355
|
-
stack: error.stack
|
|
356
|
-
};
|
|
357
|
-
const metadata = {
|
|
358
|
-
type: error.name
|
|
359
|
-
};
|
|
360
|
-
|
|
361
|
-
Metrics.sendBehavioralMetric(metricName, data, metadata);
|
|
362
|
-
|
|
363
|
-
return Metrics.postEvent({
|
|
364
|
-
event: eventType.REMOTE_SDP_RECEIVED,
|
|
365
|
-
meetingId,
|
|
366
|
-
data: {
|
|
367
|
-
canProceed: false,
|
|
368
|
-
errors: [Metrics.generateErrorPayload(2001, true,
|
|
369
|
-
error.name.MEDIA_ENGINE, 'missing remoteSdp')]
|
|
370
|
-
}
|
|
371
|
-
});
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
return Promise.reject(new MediaError('PeerConnection in wrong state'));
|
|
376
|
-
};
|
|
377
|
-
|
|
378
|
-
/**
|
|
379
|
-
* Create offer with a valid parameter
|
|
380
|
-
* @param {Object} peerConnection
|
|
381
|
-
* @param {Object} meetingProperties
|
|
382
|
-
* @param {string} meetingProperties.meetingId
|
|
383
|
-
* @param {string} meetingProperties.remoteQualityLevel LOW|MEDIUM|HIGH
|
|
384
|
-
* @param {string} meetingProperties.enableRtx
|
|
385
|
-
* @param {string} meetingProperties.enableExtmap
|
|
386
|
-
* @returns {RTCPeerConnection}
|
|
387
|
-
*/
|
|
388
|
-
pc.createOffer = (peerConnection, {
|
|
389
|
-
meetingId,
|
|
390
|
-
remoteQualityLevel,
|
|
391
|
-
enableRtx,
|
|
392
|
-
enableExtmap
|
|
393
|
-
}) => {
|
|
394
|
-
LoggerProxy.logger.log('PeerConnectionManager:index#createOffer --> creating a new offer');
|
|
395
|
-
|
|
396
|
-
// saving the extMap State to use in setRemoteDescription
|
|
397
|
-
|
|
398
|
-
peerConnection.enableExtmap = enableExtmap;
|
|
399
|
-
|
|
400
|
-
return peerConnection
|
|
401
|
-
.createOffer()
|
|
402
|
-
.then((description) => {
|
|
403
|
-
// bug https://bugs.chromium.org/p/chromium/issues/detail?id=1020642
|
|
404
|
-
// chrome currently generates RTX line irrespective of whether the server side supports it
|
|
405
|
-
// we are removing apt as well because its associated with rtx line
|
|
406
|
-
|
|
407
|
-
if (!enableRtx) {
|
|
408
|
-
description.sdp = description.sdp.replace(/\r\na=rtpmap:\d+ rtx\/\d+/g, '');
|
|
409
|
-
description.sdp = description.sdp.replace(/\r\na=fmtp:\d+ apt=\d+/g, '');
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
return peerConnection.setLocalDescription(description);
|
|
413
|
-
})
|
|
414
|
-
.then(() => pc.iceCandidate(peerConnection, {remoteQualityLevel}))
|
|
415
|
-
.then(() => {
|
|
416
|
-
if (!checkH264Support(peerConnection.sdp)) {
|
|
417
|
-
throw new MediaError('openH264 is downloading please Wait. Upload logs if not working on second try');
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
if (!enableExtmap) {
|
|
421
|
-
peerConnection.sdp = peerConnection.sdp.replace(/\na=extmap.*/g, '');
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
pc.setContentSlides(peerConnection);
|
|
425
|
-
|
|
426
|
-
Metrics.postEvent({
|
|
427
|
-
event: eventType.LOCAL_SDP_GENERATED,
|
|
428
|
-
meetingId
|
|
429
|
-
});
|
|
430
|
-
|
|
431
|
-
return peerConnection;
|
|
432
|
-
})
|
|
433
|
-
.catch((error) => {
|
|
434
|
-
LoggerProxy.logger.error(`Peer-connection-manager:index#createOffer --> ${error}`);
|
|
435
|
-
if (error instanceof InvalidSdpError) {
|
|
436
|
-
Metrics.sendBehavioralMetric(
|
|
437
|
-
BEHAVIORAL_METRICS.INVALID_ICE_CANDIDATE,
|
|
438
|
-
{
|
|
439
|
-
correlation_id: meetingId,
|
|
440
|
-
code: error.code,
|
|
441
|
-
reason: error.message
|
|
442
|
-
}
|
|
443
|
-
);
|
|
444
|
-
}
|
|
445
|
-
else {
|
|
446
|
-
const metricName = BEHAVIORAL_METRICS.PEERCONNECTION_FAILURE;
|
|
447
|
-
const data = {
|
|
448
|
-
correlation_id: meetingId,
|
|
449
|
-
reason: error.message,
|
|
450
|
-
stack: error.stack
|
|
451
|
-
};
|
|
452
|
-
const metadata = {
|
|
453
|
-
type: error.name
|
|
454
|
-
};
|
|
455
|
-
|
|
456
|
-
Metrics.sendBehavioralMetric(metricName, data, metadata);
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
Metrics.postEvent({
|
|
460
|
-
event: eventType.LOCAL_SDP_GENERATED,
|
|
461
|
-
meetingId,
|
|
462
|
-
data: {
|
|
463
|
-
canProceed: false,
|
|
464
|
-
errors: [
|
|
465
|
-
Metrics.generateErrorPayload(2001, true,
|
|
466
|
-
error.name.MEDIA_ENGINE)]
|
|
467
|
-
}
|
|
468
|
-
});
|
|
469
|
-
pc.close(peerConnection);
|
|
470
|
-
throw error;
|
|
471
|
-
});
|
|
472
|
-
};
|
|
473
|
-
|
|
474
|
-
/**
|
|
475
|
-
* rollBack local description in peerconnection
|
|
476
|
-
* @param {Object} peerConnection
|
|
477
|
-
* @returns {Promise.RTCPeerConnection}
|
|
478
|
-
*/
|
|
479
|
-
pc.rollBackLocalDescription = (peerConnection) => peerConnection
|
|
480
|
-
.setLocalDescription(new RTCSessionDescription({type: SDP.ROLLBACK}))
|
|
481
|
-
.then(() => peerConnection)
|
|
482
|
-
.catch((err) => {
|
|
483
|
-
LoggerProxy.logger.error(`Peer-connection-manager:index#setLocalDescription --> ${err} `);
|
|
484
|
-
|
|
485
|
-
return Promise.error(err);
|
|
486
|
-
});
|
|
487
|
-
|
|
488
|
-
/**
|
|
489
|
-
* @param {Object} params {
|
|
490
|
-
* @param {Boolean} params.offerToReceiveAudio
|
|
491
|
-
* @param {Boolean} params.offerToReceiveVideo
|
|
492
|
-
* @param {string} params.offerSdp
|
|
493
|
-
* @param {MediaStream} params.stream
|
|
494
|
-
* @param {Object} meetingProperties
|
|
495
|
-
* @param {string} meetingProperties.meetingId
|
|
496
|
-
* @param {string} meetingProperties.remoteQualityLevel LOW|MEDIUM|HIGH
|
|
497
|
-
* @returns {Promise.<Array>} [MediaSDP, ScreenSDP]
|
|
498
|
-
*/
|
|
499
|
-
pc.updatePeerConnection = (params, {meetingId, remoteQualityLevel}) => {
|
|
500
|
-
LoggerProxy.logger.log(`PeerConnectionManager:index#updatePeerConnection --> updating the peerConnection with params: ${params}`);
|
|
501
|
-
|
|
502
|
-
const {peerConnection, offerSdp} = params;
|
|
503
|
-
|
|
504
|
-
return pc.createAnswer({
|
|
505
|
-
peerConnection,
|
|
506
|
-
offerSdp: offerSdp[0]
|
|
507
|
-
}, {meetingId, remoteQualityLevel}).then((peerconnection) => {
|
|
508
|
-
// The content slides should also be set when we are sending inactive
|
|
509
|
-
pc.setContentSlides(peerconnection);
|
|
510
|
-
|
|
511
|
-
return Promise.resolve([peerconnection.sdp]);
|
|
512
|
-
});
|
|
513
|
-
};
|
|
514
|
-
|
|
515
|
-
/**
|
|
516
|
-
* @param {Object} params
|
|
517
|
-
* @param {Object} params.peerConnection
|
|
518
|
-
* @param {Object} params.sdpConstraints
|
|
519
|
-
* @param {Object} meetingProperties
|
|
520
|
-
* @param {string} meetingProperties.meetingId
|
|
521
|
-
* @param {string} meetingProperties.remoteQualityLevel LOW|MEDIUM|HIGH
|
|
522
|
-
* @returns {RTCPeerConnection} peerConnection
|
|
523
|
-
*/
|
|
524
|
-
pc.createAnswer = (params, {meetingId, remoteQualityLevel}) => {
|
|
525
|
-
const {peerConnection} = params;
|
|
526
|
-
|
|
527
|
-
// TODO: Some times to many mercury event comes at the same time
|
|
528
|
-
// Need to maintain state of peerconnection
|
|
529
|
-
if (peerConnection.signalingState === SDP.HAVE_REMOTE_OFFER) {
|
|
530
|
-
return Promise.resolve(peerConnection);
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
return pc.setRemoteSessionDetails(peerConnection, OFFER, params.offerSdp, meetingId)
|
|
534
|
-
.then(() => peerConnection.createAnswer(params.sdpConstraints))
|
|
535
|
-
.then((answer) =>
|
|
536
|
-
|
|
537
|
-
peerConnection.setLocalDescription(answer))
|
|
538
|
-
.then(() => pc.iceCandidate(peerConnection, {remoteQualityLevel}))
|
|
539
|
-
.then(() => {
|
|
540
|
-
peerConnection.sdp = limitBandwidth(peerConnection.localDescription.sdp);
|
|
541
|
-
peerConnection.sdp = PeerConnectionUtils.convertCLineToIpv4(peerConnection.sdp);
|
|
542
|
-
peerConnection.sdp = setRemoteVideoConstraints(peerConnection.sdp, remoteQualityLevel);
|
|
543
|
-
|
|
544
|
-
if (!checkH264Support(peerConnection.sdp)) {
|
|
545
|
-
throw new MediaError('openH264 is downloading please Wait. Upload logs if not working on second try');
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
return peerConnection;
|
|
549
|
-
})
|
|
550
|
-
.catch((error) => {
|
|
551
|
-
if (error instanceof InvalidSdpError) {
|
|
552
|
-
Metrics.sendBehavioralMetric(
|
|
553
|
-
BEHAVIORAL_METRICS.INVALID_ICE_CANDIDATE,
|
|
554
|
-
{
|
|
555
|
-
correlation_id: meetingId
|
|
556
|
-
}
|
|
557
|
-
);
|
|
558
|
-
}
|
|
559
|
-
else {
|
|
560
|
-
const metricName = BEHAVIORAL_METRICS.PEERCONNECTION_FAILURE;
|
|
561
|
-
const data = {
|
|
562
|
-
correlation_id: meetingId,
|
|
563
|
-
reason: error.message,
|
|
564
|
-
stack: error.stack
|
|
565
|
-
};
|
|
566
|
-
const metadata = {
|
|
567
|
-
type: error.name
|
|
568
|
-
};
|
|
569
|
-
|
|
570
|
-
Metrics.sendBehavioralMetric(metricName, data, metadata);
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
LoggerProxy.logger.error(`PeerConnectionManager:index#setRemoteSessionDetails --> Error creating remote session, error: ${error}`);
|
|
574
|
-
});
|
|
575
|
-
};
|
|
576
|
-
|
|
577
|
-
/**
|
|
578
|
-
* shut down the peer connection
|
|
579
|
-
* @param {Object} peerConnection
|
|
580
|
-
* @returns {undefined}
|
|
581
|
-
*/
|
|
582
|
-
pc.close = (peerConnection) => {
|
|
583
|
-
// peerConnection.close() fails on firefox on network changes and gives a Dom exception
|
|
584
|
-
// To avoid this we have added a try catch block.
|
|
585
|
-
// Please refer to https://bugzilla.mozilla.org/show_bug.cgi?id=1274407 for more information
|
|
586
|
-
LoggerProxy.logger.log('PeerConnectionManager:index#close --> pc: close() -> attempting to close the peer connection');
|
|
587
|
-
|
|
588
|
-
if (peerConnection && peerConnection.connectionState === PEER_CONNECTION_STATE.CLOSED) {
|
|
589
|
-
LoggerProxy.logger.log('PeerConnectionManager:index#close --> pc: close() -> connection already closed');
|
|
590
|
-
|
|
591
|
-
return Promise.resolve();
|
|
592
|
-
}
|
|
593
|
-
LoggerProxy.logger.log('PeerConnectionManager:index#close --> pc: close() -> closing the mediaPeerConnection');
|
|
594
|
-
|
|
595
|
-
return Promise.resolve()
|
|
596
|
-
.then(() => {
|
|
597
|
-
if (peerConnection && peerConnection.close) {
|
|
598
|
-
peerConnection.close();
|
|
599
|
-
}
|
|
600
|
-
});
|
|
601
|
-
};
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
pc.setPeerConnectionEvents = (meeting) => {
|
|
605
|
-
// In case ICE fail
|
|
606
|
-
const {peerConnection} = meeting.mediaProperties;
|
|
607
|
-
|
|
608
|
-
const connectionFailed = () => {
|
|
609
|
-
if (meeting.reconnectionManager.iceState.resolve) {
|
|
610
|
-
// DISCONNECTED state triggers first then it goes to FAILED STATE
|
|
611
|
-
// sometimes the failed state can happen before 10 seconds (Which is the timer for the reconnect for ice disconnect)
|
|
612
|
-
meeting.reconnectionManager.iceState.resolve();
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
meeting.reconnect({networkDisconnect: true});
|
|
616
|
-
Metrics.postEvent({
|
|
617
|
-
event: eventType.ICE_END,
|
|
618
|
-
meeting,
|
|
619
|
-
data: {
|
|
620
|
-
canProceed: false,
|
|
621
|
-
errors: [
|
|
622
|
-
Metrics.generateErrorPayload(
|
|
623
|
-
2004, false, error.name.MEDIA_ENGINE
|
|
624
|
-
)]
|
|
625
|
-
}
|
|
626
|
-
});
|
|
627
|
-
|
|
628
|
-
meeting.uploadLogs({
|
|
629
|
-
file: 'peer-connection-manager/index',
|
|
630
|
-
function: 'connectionFailed'
|
|
631
|
-
});
|
|
632
|
-
|
|
633
|
-
Metrics.sendBehavioralMetric(
|
|
634
|
-
BEHAVIORAL_METRICS.CONNECTION_FAILURE,
|
|
635
|
-
{
|
|
636
|
-
correlation_id: meeting.correlationId,
|
|
637
|
-
locus_id: meeting.locusId
|
|
638
|
-
}
|
|
639
|
-
);
|
|
640
|
-
};
|
|
641
|
-
|
|
642
|
-
peerConnection.oniceconnectionstatechange = () => {
|
|
643
|
-
LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE CHANGE.');
|
|
644
|
-
switch (peerConnection.iceConnectionState) {
|
|
645
|
-
case ICE_STATE.CHECKING:
|
|
646
|
-
LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE CHECKING.');
|
|
647
|
-
Metrics.postEvent({event: eventType.ICE_START, meeting});
|
|
648
|
-
break;
|
|
649
|
-
case ICE_STATE.COMPLETED:
|
|
650
|
-
LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE COMPLETED.');
|
|
651
|
-
break;
|
|
652
|
-
case ICE_STATE.CONNECTED:
|
|
653
|
-
// Ice connection state goes to connected when both client and server sends STUN packets and
|
|
654
|
-
// Established connected between them. Firefox does not trigger COMPLETED and only trigger CONNECTED
|
|
655
|
-
Metrics.postEvent({event: eventType.ICE_END, meeting});
|
|
656
|
-
Metrics.sendBehavioralMetric(
|
|
657
|
-
BEHAVIORAL_METRICS.CONNECTION_SUCCESS,
|
|
658
|
-
{
|
|
659
|
-
correlation_id: meeting.correlationId,
|
|
660
|
-
locus_id: meeting.locusId
|
|
661
|
-
}
|
|
662
|
-
);
|
|
663
|
-
meeting.setNetworkStatus(NETWORK_STATUS.CONNECTED);
|
|
664
|
-
meeting.reconnectionManager.iceReconnected();
|
|
665
|
-
LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE CONNECTED.');
|
|
666
|
-
break;
|
|
667
|
-
case ICE_STATE.CLOSED:
|
|
668
|
-
LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE CLOSED.');
|
|
669
|
-
break;
|
|
670
|
-
case ICE_STATE.DISCONNECTED:
|
|
671
|
-
meeting.setNetworkStatus(NETWORK_STATUS.DISCONNECTED);
|
|
672
|
-
meeting.reconnectionManager.waitForIceReconnect()
|
|
673
|
-
.catch(() => {
|
|
674
|
-
LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE DISCONNECTED. Automatic Reconnection Timed Out.');
|
|
675
|
-
|
|
676
|
-
connectionFailed();
|
|
677
|
-
});
|
|
678
|
-
LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE DISCONNECTED.');
|
|
679
|
-
break;
|
|
680
|
-
case ICE_STATE.FAILED:
|
|
681
|
-
LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE FAILED.');
|
|
682
|
-
// notify of ice failure
|
|
683
|
-
// Ice failure is the only indicator currently for identifying the actual connection drop
|
|
684
|
-
// Firefox takes sometime 10-15 seconds to go to failed state
|
|
685
|
-
connectionFailed();
|
|
686
|
-
break;
|
|
687
|
-
default:
|
|
688
|
-
break;
|
|
689
|
-
}
|
|
690
|
-
};
|
|
691
|
-
|
|
692
|
-
peerConnection.onconnectionstatechange = () => {
|
|
693
|
-
LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> CONNECTION STATE CHANGE.');
|
|
694
|
-
switch (peerConnection.connectionState) {
|
|
695
|
-
case CONNECTION_STATE.NEW:
|
|
696
|
-
LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> CONNECTION STATE NEW.');
|
|
697
|
-
break;
|
|
698
|
-
case CONNECTION_STATE.CONNECTING:
|
|
699
|
-
LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> CONNECTION STATE CONNECTING.');
|
|
700
|
-
break;
|
|
701
|
-
case CONNECTION_STATE.CONNECTED:
|
|
702
|
-
LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> CONNECTION STATE CONNECTED.');
|
|
703
|
-
break;
|
|
704
|
-
case CONNECTION_STATE.CLOSED:
|
|
705
|
-
LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> CONNECTION STATE CLOSED.');
|
|
706
|
-
break;
|
|
707
|
-
case CONNECTION_STATE.DISCONNECTED:
|
|
708
|
-
LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> CONNECTION STATE DISCONNECTED.');
|
|
709
|
-
break;
|
|
710
|
-
case CONNECTION_STATE.FAILED:
|
|
711
|
-
LoggerProxy.logger.info('PeerConnectionManager:index#setPeerConnectionEvents --> CONNECTION STATE FAILED.');
|
|
712
|
-
// Special case happens only on chrome where there is no ICE FAILED event
|
|
713
|
-
// only CONNECTION FAILED event gets triggered
|
|
714
|
-
|
|
715
|
-
connectionFailed();
|
|
716
|
-
break;
|
|
717
|
-
default:
|
|
718
|
-
break;
|
|
719
|
-
}
|
|
720
|
-
};
|
|
721
|
-
};
|
|
722
|
-
|
|
723
|
-
export default pc;
|