Skip to content

Commit 9b13c31

Browse files
committed
fix(plugin-meetings): replace H.264 codec check with WebCapabilities integration
1 parent 4fbfbe7 commit 9b13c31

File tree

2 files changed

+85
-31
lines changed
  • packages/@webex/plugin-meetings

2 files changed

+85
-31
lines changed

packages/@webex/plugin-meetings/src/meetings/util.ts

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* globals window */
22

3+
import {CapabilityState, WebCapabilities} from '@webex/web-capabilities';
34
import {
45
_CREATED_,
56
_INCOMING_,
@@ -152,32 +153,6 @@ MeetingsUtil.parseDefaultSiteFromMeetingPreferences = (userPreferences) => {
152153
return result;
153154
};
154155

155-
/**
156-
* Will check to see if the H.264 media codec is supported.
157-
* @async
158-
* @private
159-
* @returns {Promise<boolean>}
160-
*/
161-
MeetingsUtil.hasH264Codec = async () => {
162-
let hasCodec = false;
163-
164-
try {
165-
const pc = new window.RTCPeerConnection();
166-
const offer = await pc.createOffer({offerToReceiveVideo: true});
167-
168-
if (offer.sdp.match(/^a=rtpmap:\d+\s+H264\/\d+/m)) {
169-
hasCodec = true;
170-
}
171-
pc.close();
172-
} catch (error) {
173-
LoggerProxy.logger.warn(
174-
'Meetings:util#hasH264Codec --> Error creating peerConnection for H.264 test.'
175-
);
176-
}
177-
178-
return hasCodec;
179-
};
180-
181156
/**
182157
* Notifies the user whether or not the H.264
183158
* codec is present. Will continuously check
@@ -193,22 +168,21 @@ MeetingsUtil.checkH264Support = async function checkH264Support(options: {
193168
firstChecked: number;
194169
disableNotifications: boolean;
195170
}) {
196-
const {hasH264Codec} = MeetingsUtil;
197171
const {firstChecked, disableNotifications} = options || {};
198172
const delay = 5e3; // ms
199173
const maxDuration = 3e5; // ms
200174
const shouldTrigger = firstChecked === undefined;
201175
const shouldStopChecking = firstChecked && Date.now() - firstChecked >= maxDuration;
202176

203-
// Disable notifications and start H.264 download only
204177
if (disableNotifications) {
205-
hasH264Codec();
206-
207178
return;
208179
}
209180

181+
const isH264Available =
182+
WebCapabilities.isCapableOfReceivingVideoCodec('video/H264') === CapabilityState.CAPABLE;
183+
210184
// Codec loaded trigger event notification
211-
if (await hasH264Codec()) {
185+
if (isH264Available) {
212186
Trigger.trigger(
213187
this,
214188
{

packages/@webex/plugin-meetings/test/unit/spec/meetings/utils.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import {assert} from '@webex/test-helper-chai';
22
import sinon from 'sinon';
3+
import {CapabilityState, WebCapabilities} from '@webex/web-capabilities';
34

5+
import Trigger from '@webex/plugin-meetings/src/common/events/trigger-proxy';
6+
import LoggerProxy from '@webex/plugin-meetings/src/common/logs/logger-proxy';
47
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;
511
import Metrics from '@webex/plugin-meetings/src/metrics';
612
import BEHAVIORAL_METRICS from '@webex/plugin-meetings/src/metrics/constants';
713

@@ -350,4 +356,78 @@ describe('plugin-meetings', () => {
350356
assert.equal(correlationId, false);
351357
});
352358
});
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+
});
353433
});

0 commit comments

Comments
 (0)