|
1 | 1 | import {assert} from '@webex/test-helper-chai'; |
2 | 2 | import sinon from 'sinon'; |
| 3 | +import {CapabilityState, WebCapabilities} from '@webex/web-capabilities'; |
3 | 4 |
|
| 5 | +import Trigger from '@webex/plugin-meetings/src/common/events/trigger-proxy'; |
| 6 | +import LoggerProxy from '@webex/plugin-meetings/src/common/logs/logger-proxy'; |
4 | 7 | import MeetingsUtil from '@webex/plugin-meetings/src/meetings/util'; |
| 8 | +import {EVENT_TRIGGERS} from '@webex/plugin-meetings/src/constants'; |
| 9 | + |
| 10 | +const originalCheckH264Support = MeetingsUtil.checkH264Support; |
5 | 11 | import Metrics from '@webex/plugin-meetings/src/metrics'; |
6 | 12 | import BEHAVIORAL_METRICS from '@webex/plugin-meetings/src/metrics/constants'; |
7 | 13 |
|
@@ -350,4 +356,78 @@ describe('plugin-meetings', () => { |
350 | 356 | assert.equal(correlationId, false); |
351 | 357 | }); |
352 | 358 | }); |
| 359 | + |
| 360 | + describe('#checkH264Support', () => { |
| 361 | + let isCapableOfReceivingVideoCodecStub; |
| 362 | + let triggerStub; |
| 363 | + let loggerErrorStub; |
| 364 | + |
| 365 | + beforeEach(() => { |
| 366 | + MeetingsUtil.checkH264Support = originalCheckH264Support; |
| 367 | + isCapableOfReceivingVideoCodecStub = sinon.stub( |
| 368 | + WebCapabilities, |
| 369 | + 'isCapableOfReceivingVideoCodec' |
| 370 | + ); |
| 371 | + triggerStub = sinon.stub(Trigger, 'trigger'); |
| 372 | + loggerErrorStub = sinon.stub(LoggerProxy.logger, 'error'); |
| 373 | + }); |
| 374 | + |
| 375 | + it('returns immediately without codec check when disableNotifications is true', async () => { |
| 376 | + await MeetingsUtil.checkH264Support.call({}, {disableNotifications: true}); |
| 377 | + |
| 378 | + assert.notCalled(isCapableOfReceivingVideoCodecStub); |
| 379 | + assert.notCalled(triggerStub); |
| 380 | + }); |
| 381 | + |
| 382 | + it('triggers MEDIA_CODEC_LOADED when H.264 is capable', async () => { |
| 383 | + isCapableOfReceivingVideoCodecStub.returns(CapabilityState.CAPABLE); |
| 384 | + |
| 385 | + await MeetingsUtil.checkH264Support.call({}); |
| 386 | + |
| 387 | + assert.calledWith(isCapableOfReceivingVideoCodecStub, 'video/H264'); |
| 388 | + assert.calledWith( |
| 389 | + triggerStub, |
| 390 | + {}, |
| 391 | + {file: 'meetings/util', function: 'checkH264Support'}, |
| 392 | + EVENT_TRIGGERS.MEDIA_CODEC_LOADED |
| 393 | + ); |
| 394 | + }); |
| 395 | + |
| 396 | + it('triggers MEDIA_CODEC_MISSING and schedules retry when H.264 is not capable', async () => { |
| 397 | + const clock = sinon.useFakeTimers(); |
| 398 | + isCapableOfReceivingVideoCodecStub.returns(CapabilityState.NOT_CAPABLE); |
| 399 | + |
| 400 | + await MeetingsUtil.checkH264Support.call({}); |
| 401 | + |
| 402 | + assert.calledWith( |
| 403 | + triggerStub, |
| 404 | + {}, |
| 405 | + {file: 'meetings/util', function: 'checkH264Support'}, |
| 406 | + EVENT_TRIGGERS.MEDIA_CODEC_MISSING |
| 407 | + ); |
| 408 | + triggerStub.resetHistory(); |
| 409 | + isCapableOfReceivingVideoCodecStub.resetHistory(); |
| 410 | + |
| 411 | + await clock.tick(5000); |
| 412 | + |
| 413 | + assert.called(isCapableOfReceivingVideoCodecStub); |
| 414 | + clock.restore(); |
| 415 | + }); |
| 416 | + |
| 417 | + it('logs error and stops retrying when past maxDuration', async () => { |
| 418 | + const clock = sinon.useFakeTimers(); |
| 419 | + isCapableOfReceivingVideoCodecStub.returns(CapabilityState.NOT_CAPABLE); |
| 420 | + |
| 421 | + const firstCheckTime = 1; |
| 422 | + await clock.tick(firstCheckTime); |
| 423 | + await MeetingsUtil.checkH264Support.call({}, {firstChecked: firstCheckTime}); |
| 424 | + await clock.tick(300000); |
| 425 | + |
| 426 | + assert.calledWith( |
| 427 | + loggerErrorStub, |
| 428 | + 'Meetings:util#checkH264Support --> Timed out waiting for H264 codec to load.' |
| 429 | + ); |
| 430 | + clock.restore(); |
| 431 | + }); |
| 432 | + }); |
353 | 433 | }); |
0 commit comments