-
Notifications
You must be signed in to change notification settings - Fork 395
Expand file tree
/
Copy pathutils.js
More file actions
508 lines (441 loc) · 15.7 KB
/
utils.js
File metadata and controls
508 lines (441 loc) · 15.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
import {assert} from '@webex/test-helper-chai';
import sinon from 'sinon';
import {CapabilityState, WebCapabilities} from '@webex/web-capabilities';
import Trigger from '@webex/plugin-meetings/src/common/events/trigger-proxy';
import LoggerProxy from '@webex/plugin-meetings/src/common/logs/logger-proxy';
import MeetingsUtil from '@webex/plugin-meetings/src/meetings/util';
import {EVENT_TRIGGERS} from '@webex/plugin-meetings/src/constants';
import Metrics from '@webex/plugin-meetings/src/metrics';
import BEHAVIORAL_METRICS from '@webex/plugin-meetings/src/metrics/constants';
describe('plugin-meetings', () => {
beforeEach(() => {
sinon.stub(Metrics, 'sendBehavioralMetric');
});
afterEach(() => {
sinon.restore();
});
describe('Meetings utils function', () => {
describe('#parseDefaultSiteFromMeetingPreferences', () => {
it('should return the default true site from user preferences', () => {
const userPreferences = {
sites: [
{
siteUrl: 'site1-example.webex.com',
default: false,
},
{
siteUrl: 'site2-example.webex.com',
default: false,
},
{
siteUrl: 'go.webex.com',
default: true,
},
{
siteUrl: 'site3-example.webex.com',
default: false,
},
],
};
assert.equal(
MeetingsUtil.parseDefaultSiteFromMeetingPreferences(userPreferences),
'go.webex.com'
);
});
it('should take the first site if none are default', () => {
const userPreferences = {
sites: [
{
siteUrl: 'site1-example.webex.com',
default: false,
},
{
siteUrl: 'site2-example.webex.com',
default: false,
},
{
siteUrl: 'site3-example.webex.com',
default: false,
},
],
};
assert.equal(
MeetingsUtil.parseDefaultSiteFromMeetingPreferences(userPreferences),
'site1-example.webex.com'
);
});
it('should work fine if sites an empty array', () => {
const userPreferences = {
sites: [],
};
assert.equal(MeetingsUtil.parseDefaultSiteFromMeetingPreferences(userPreferences), '');
});
});
describe('#getThisDevice', () => {
it('return null if no devices in self', () => {
const newLocus = {};
assert.equal(MeetingsUtil.getThisDevice(newLocus, '123'), null);
});
it('return null if no matched device in self', () => {
const newLocus = {
self: {
devices: [{state: 'JOINED', url: '456'}]
}
};
assert.equal(MeetingsUtil.getThisDevice(newLocus, '123'), null);
});
it('return the device match with current device', () => {
const newLocus = {
self: {
devices: [{state: 'JOINED', url: '123'}]
}
};
assert.deepEqual(MeetingsUtil.getThisDevice(newLocus, '123'), {state: 'JOINED', url: '123'});
})
});
describe('#isBreakoutLocusDTO', () => {
it('returns false is no breakout in locus.controls', () => {
const newLocus = {
controls: {}
};
assert.equal(MeetingsUtil.isBreakoutLocusDTO(newLocus), false);
});
it('returns is breakout locus DTO if sessionType is BREAKOUT', () => {
const newLocus = {
controls: {
breakout: {
sessionType: 'BREAKOUT',
},
},
};
assert.equal(MeetingsUtil.isBreakoutLocusDTO(newLocus), true);
});
it('returns is not breakout locus DTO if sessionType is MAIN', () => {
const newLocus = {
controls: {
breakout: {
sessionType: 'MAIN',
},
},
};
assert.equal(MeetingsUtil.isBreakoutLocusDTO(newLocus), false);
});
});
describe('#joinedOnThisDevice', () => {
it('return false if no devices in self', () => {
const newLocus = {};
assert.equal(MeetingsUtil.joinedOnThisDevice(null, newLocus, '123'), false);
});
it('return true if joined on this device', () => {
const newLocus = {
self: {
devices: [{state: 'JOINED', correlationId: '111', url: '123'}]
}
};
const meeting = {
correlationId: '111'
};
assert.equal(MeetingsUtil.joinedOnThisDevice(meeting, newLocus, '123'), true);
});
it('return true if selfMoved on this device', () => {
const newLocus = {
self: {
devices: [{state: 'LEFT', reason: 'MOVED', correlationId: '111', url: '123'}]
}
};
const meeting = {
correlationId: '111'
};
assert.equal(MeetingsUtil.joinedOnThisDevice(meeting, newLocus, '123'), true);
});
});
describe("#handleRoapMercury", () => {
let envelope;
let meetingCollection;
let roapMessageReceived;
let handleTurnDiscoveryResponse;
let meeting;
beforeEach(() => {
roapMessageReceived = sinon.stub();
handleTurnDiscoveryResponse = sinon.stub();
meeting = {
id: 'meeting-id',
roapMessageReceived,
roap: {
turnDiscovery: {handleTurnDiscoveryResponse}
}
};
envelope = {
data: {
message:{
seq: "seq",
messageType: 'messageType',
tieBreaker: 'tieBreaker',
errorType: 'errorType',
errorCause: 'errorCause',
sdps: [{id:'sdp-1'}]
},
correlationId: 'correlationId',
eventType: 'locus.message.roap',
}
};
meetingCollection = {
getByKey: () => meeting
};
});
it('it sends the correct behaviour metric', () => {
MeetingsUtil.handleRoapMercury(envelope, meetingCollection);
assert.calledWith(Metrics.sendBehavioralMetric, BEHAVIORAL_METRICS.ROAP_MERCURY_EVENT_RECEIVED, {
correlation_id: 'correlationId',
seq: "seq",
message_type: 'messageType',
error_type: 'errorType',
error_cause: 'errorCause',
})
assert.calledWith(roapMessageReceived, {
seq: "seq",
messageType: 'messageType',
errorType: 'errorType',
tieBreaker: 'tieBreaker',
errorCause: 'errorCause',
sdp: {id:'sdp-1'}
})
});
it('calls handleTurnDiscoveryResponse for TURN_DISCOVERY_RESPONSE', () => {
envelope.data.message.messageType = 'TURN_DISCOVERY_RESPONSE';
delete envelope.data.message.sdps;
MeetingsUtil.handleRoapMercury(envelope, meetingCollection);
assert.calledWith(meeting.roap.turnDiscovery.handleTurnDiscoveryResponse, {
seq: "seq",
messageType: 'TURN_DISCOVERY_RESPONSE',
errorType: 'errorType',
tieBreaker: 'tieBreaker',
errorCause: 'errorCause',
}, 'from mercury')
});
})
});
describe('#isValidBreakoutLocus', () => {
it('returns false if is not breakout locus', () => {
const newLocus = {
controls: {}
};
assert.equal(MeetingsUtil.isValidBreakoutLocus(newLocus), false);
});
it('returns false if fullState is inactive', () => {
const newLocus = {
controls: {
breakout: {
sessionType: 'BREAKOUT',
},
},
fullState: {
state: 'INACTIVE'
}
};
assert.equal(MeetingsUtil.isValidBreakoutLocus(newLocus), false);
});
it('returns false if self is not joined', () => {
const newLocus = {
controls: {
breakout: {
sessionType: 'BREAKOUT',
},
},
fullState: {
state: 'ACTIVE'
},
self: {
state: 'LEFT'
}
};
assert.equal(MeetingsUtil.isValidBreakoutLocus(newLocus), false);
});
it('returns true if self is JOINED and fullState is active', () => {
const newLocus = {
controls: {
breakout: {
sessionType: 'BREAKOUT',
},
},
fullState: {
state: 'ACTIVE'
},
self: {
state: 'JOINED'
}
};
assert.equal(MeetingsUtil.isValidBreakoutLocus(newLocus), true);
});
});
describe('#getMediaServer', () => {
it('returns the contents of o-line lower cased', () => {
const sdp1 = 'v=0\r\no=homer 0 1 IN IP4 23.89.67.81\r\ns=-\r\nc=IN IP4 23.89.67.81\r\nb=TIAS:128000\r\nt=0 0\r\na=ice-lite\r\n'
assert.equal(MeetingsUtil.getMediaServer(sdp1), 'homer');
const sdp2 = 'v=0\r\no=HOMER 0 1 IN IP4 23.89.67.81\r\ns=-\r\nc=IN IP4 23.89.67.81\r\nb=TIAS:128000\r\nt=0 0\r\na=ice-lite\r\n'
assert.equal(MeetingsUtil.getMediaServer(sdp2), 'homer');
});
});
describe('#getCorrelationIdForDevice', () => {
it('should return correlationId if device with matching url is found', () => {
const locusSelf = {
devices: [
{url: 'deviceUrl1', correlationId: 'correlationId1'},
{url: 'deviceUrl2', correlationId: 'correlationId2'},
],
};
const correlationId = MeetingsUtil.getCorrelationIdForDevice('deviceUrl1', locusSelf);
assert.equal(correlationId, 'correlationId1');
});
it('should return false if no device with matching url is found', () => {
const locusSelf = {
devices: [
{url: 'deviceUrl1', correlationId: 'correlationId1'},
{url: 'deviceUrl2', correlationId: 'correlationId2'},
],
};
const correlationId = MeetingsUtil.getCorrelationIdForDevice('deviceUrl3', locusSelf);
assert.equal(correlationId, false);
});
it('should return false if device with matching url has no correlationId', () => {
const locusSelf = {
devices: [{url: 'deviceUrl1'}, {url: 'deviceUrl2', correlationId: 'correlationId2'}],
};
const correlationId = MeetingsUtil.getCorrelationIdForDevice('deviceUrl1', locusSelf);
assert.equal(correlationId, false);
});
it('should return false if locusSelf has no devices', () => {
const locusSelf = {};
const correlationId = MeetingsUtil.getCorrelationIdForDevice('deviceUrl1', locusSelf);
assert.equal(correlationId, false);
});
it('should return false if locusSelf is null or undefined', () => {
let correlationId = MeetingsUtil.getCorrelationIdForDevice('deviceUrl1', null);
assert.equal(correlationId, false);
correlationId = MeetingsUtil.getCorrelationIdForDevice('deviceUrl1', undefined);
assert.equal(correlationId, false);
});
});
describe('#checkH264Support', () => {
let isCapableOfReceivingVideoCodecStub;
let triggerStub;
let loggerErrorStub;
let loggerLogStub;
beforeEach(() => {
isCapableOfReceivingVideoCodecStub = sinon.stub(
WebCapabilities,
'isCapableOfReceivingVideoCodec'
);
triggerStub = sinon.stub(Trigger, 'trigger');
loggerErrorStub = sinon.stub(LoggerProxy.logger, 'error');
loggerLogStub = sinon.stub(LoggerProxy.logger, 'log');
});
it('returns immediately without codec check when disableNotifications is true', async () => {
await MeetingsUtil.checkH264Support.call({}, {disableNotifications: true});
assert.notCalled(isCapableOfReceivingVideoCodecStub);
assert.notCalled(triggerStub);
});
it('triggers MEDIA_CODEC_LOADED when H.264 is capable', async () => {
isCapableOfReceivingVideoCodecStub.returns(CapabilityState.CAPABLE);
await MeetingsUtil.checkH264Support.call({});
assert.calledWith(isCapableOfReceivingVideoCodecStub, 'video/H264');
assert.calledWith(
triggerStub,
{},
{file: 'meetings/util', function: 'checkH264Support'},
EVENT_TRIGGERS.MEDIA_CODEC_LOADED
);
});
it('triggers MEDIA_CODEC_MISSING and schedules retry when H.264 is not capable', async () => {
const clock = sinon.useFakeTimers();
isCapableOfReceivingVideoCodecStub.returns(CapabilityState.NOT_CAPABLE);
await MeetingsUtil.checkH264Support.call({});
assert.calledWith(
triggerStub,
{},
{file: 'meetings/util', function: 'checkH264Support'},
EVENT_TRIGGERS.MEDIA_CODEC_MISSING
);
triggerStub.resetHistory();
isCapableOfReceivingVideoCodecStub.resetHistory();
await clock.tick(5000);
assert.called(isCapableOfReceivingVideoCodecStub);
clock.restore();
});
it('logs error and stops retrying when past maxDuration', async () => {
const clock = sinon.useFakeTimers();
isCapableOfReceivingVideoCodecStub.returns(CapabilityState.NOT_CAPABLE);
const firstCheckTime = 1;
await clock.tick(firstCheckTime);
await MeetingsUtil.checkH264Support.call({}, {firstChecked: firstCheckTime});
await clock.tick(300000);
assert.calledWith(
loggerErrorStub,
'Meetings:util#checkH264Support --> Timed out waiting for H264 codec to load.'
);
clock.restore();
});
it('does not re-trigger MEDIA_CODEC_MISSING on retries when codec remains not capable', async () => {
const clock = sinon.useFakeTimers();
isCapableOfReceivingVideoCodecStub.returns(CapabilityState.NOT_CAPABLE);
await MeetingsUtil.checkH264Support.call({});
const missingTriggerCount = triggerStub.getCalls().filter(
(call) => call.args[2] === EVENT_TRIGGERS.MEDIA_CODEC_MISSING
).length;
assert.equal(missingTriggerCount, 1, 'MEDIA_CODEC_MISSING should be triggered only once');
triggerStub.resetHistory();
await clock.tick(5000);
const missingTriggerCountAfterRetry = triggerStub.getCalls().filter(
(call) => call.args[2] === EVENT_TRIGGERS.MEDIA_CODEC_MISSING
).length;
assert.equal(
missingTriggerCountAfterRetry,
0,
'MEDIA_CODEC_MISSING should not be re-triggered on retry'
);
clock.restore();
});
it('triggers MEDIA_CODEC_LOADED when codec becomes available on retry', async () => {
const clock = sinon.useFakeTimers();
isCapableOfReceivingVideoCodecStub
.onFirstCall()
.returns(CapabilityState.NOT_CAPABLE)
.onSecondCall()
.returns(CapabilityState.CAPABLE);
await MeetingsUtil.checkH264Support.call({});
assert.calledWith(
triggerStub,
{},
{file: 'meetings/util', function: 'checkH264Support'},
EVENT_TRIGGERS.MEDIA_CODEC_MISSING
);
triggerStub.resetHistory();
await clock.tick(5000);
assert.calledWith(
triggerStub,
{},
{file: 'meetings/util', function: 'checkH264Support'},
EVENT_TRIGGERS.MEDIA_CODEC_LOADED
);
clock.restore();
});
it('logs loaded message when H.264 codec is capable', async () => {
isCapableOfReceivingVideoCodecStub.returns(CapabilityState.CAPABLE);
await MeetingsUtil.checkH264Support.call({});
assert.calledWith(
loggerLogStub,
'Meetings:util#checkH264Support --> H264 codec loaded successfully.'
);
});
it('logs missing message when H.264 codec is not capable on first check', async () => {
const clock = sinon.useFakeTimers();
isCapableOfReceivingVideoCodecStub.returns(CapabilityState.NOT_CAPABLE);
await MeetingsUtil.checkH264Support.call({});
assert.calledWith(
loggerLogStub,
'Meetings:util#checkH264Support --> H264 codec is missing.'
);
clock.restore();
});
});
});