Skip to content

Commit c56b132

Browse files
author
timmydoza
authored
Fix Chrome 92 WebMediaPlayer issue (#562)
* Fix Chrome 92 WebMediaPlayer issue * Fix linter issue
1 parent 356dc2c commit c56b132

File tree

6 files changed

+39
-23
lines changed

6 files changed

+39
-23
lines changed

package-lock.json

+11-21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"strip-color": "^0.1.0",
4040
"ts-node": "^9.1.1",
4141
"twilio": "^3.57.0",
42-
"twilio-video": "^2.14.0",
42+
"twilio-video": "^2.15.3",
4343
"typescript": "^3.8.3"
4444
},
4545
"devDependencies": {

src/components/AudioTrack/AudioTrack.test.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ describe('the AudioTrack component', () => {
3131
expect(document.querySelector('audio')).toBe(null);
3232
});
3333

34+
it('should set the audio elements srcObject to null when the component unmounts', () => {
35+
const { unmount } = render(<AudioTrack track={mockTrack} />);
36+
const audioElement = document.querySelector('audio')!;
37+
unmount();
38+
expect(audioElement.srcObject).toBe(null);
39+
});
40+
3441
describe('with an activeSinkId', () => {
3542
it('should set the sinkId when the component mounts', () => {
3643
mockUseAppState.mockImplementationOnce(() => ({ activeSinkId: 'mock-sink-id' }));

src/components/AudioTrack/AudioTrack.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ export default function AudioTrack({ track }: AudioTrackProps) {
1414
audioEl.current = track.attach();
1515
audioEl.current.setAttribute('data-cy-audio-track-name', track.name);
1616
document.body.appendChild(audioEl.current);
17-
return () => track.detach().forEach(el => el.remove());
17+
return () =>
18+
track.detach().forEach(el => {
19+
el.remove();
20+
21+
// This addresses a Chrome issue where the number of WebMediaPlayers is limited.
22+
// See: https://github.com/twilio/twilio-video.js/issues/1528
23+
el.srcObject = null;
24+
});
1825
}, [track]);
1926

2027
useEffect(() => {

src/components/VideoTrack/VideoTrack.test.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ describe('the VideoTrack component', () => {
5252
expect(mockTrack.detach).toHaveBeenCalledWith(expect.any(window.HTMLVideoElement));
5353
});
5454

55+
it('should set the video elements srcObject to null when the component unmounts', () => {
56+
const { unmount, container } = render(<VideoTrack track={mockTrack} />);
57+
const videoEl = container.querySelector('video')!;
58+
unmount();
59+
expect(videoEl.srcObject).toBe(null);
60+
});
61+
5562
it('should flip the video horizontally if the track is local', () => {
5663
const { container } = render(<VideoTrack track={mockTrack} isLocal />);
5764
expect(container.querySelector('video')!.style.transform).toEqual('rotateY(180deg)');

src/components/VideoTrack/VideoTrack.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ export default function VideoTrack({ track, isLocal, priority }: VideoTrackProps
3131
track.attach(el);
3232
return () => {
3333
track.detach(el);
34+
35+
// This addresses a Chrome issue where the number of WebMediaPlayers is limited.
36+
// See: https://github.com/twilio/twilio-video.js/issues/1528
37+
el.srcObject = null;
38+
3439
if (track.setPriority && priority) {
3540
// Passing `null` to setPriority will set the track's priority to that which it was published with.
3641
track.setPriority(null);

0 commit comments

Comments
 (0)