diff --git a/src/components/live/providers/go2rtc/video-rtc.js b/src/components/live/providers/go2rtc/video-rtc.js index 59b6aa3e..0e80f76f 100644 --- a/src/components/live/providers/go2rtc/video-rtc.js +++ b/src/components/live/providers/go2rtc/video-rtc.js @@ -937,7 +937,10 @@ export class VideoRTC extends HTMLElement { video2.src = 'data:video/mp4;base64,' + VideoRTC.btoa(data); }; - this.send({ type: 'mp4', value: this.codecs(this.video.canPlayType) }); + this.send({ + type: 'mp4', + value: this.codecs((type) => this.video.canPlayType(type)), + }); } static btoa(buffer) { diff --git a/tests/components/live/providers/go2rtc.browser.test.ts b/tests/components/live/providers/go2rtc.browser.test.ts index fb8c0d1a..66e2d962 100644 --- a/tests/components/live/providers/go2rtc.browser.test.ts +++ b/tests/components/live/providers/go2rtc.browser.test.ts @@ -1,4 +1,5 @@ import { describe, expect, it } from 'vitest'; +import { mock } from 'vitest-mock-extended'; import type { VideoRTC } from '../../../../src/components/live/providers/go2rtc/video-rtc'; import type { RawAdvancedCameraCardConfig } from '../../../../src/config/types'; @@ -29,4 +30,25 @@ describe('AdvancedCameraCardGo2RTC', () => { const player = await card.waitForSelector(PLAYER_SELECTOR); expect(player.wsURL).toBe('ws://localhost:1984/api/ws?src=office'); }); + + it('should start the modes that follow mp4', async () => { + // See: https://github.com/dermotduffy/advanced-camera-card/issues/2721 + + const card = await mount({ + go2rtc: { + url: 'http://localhost:1984', + stream: 'office', + modes: ['mp4', 'webrtc'], + }, + proxy: { live: false }, + }); + + const player = await card.waitForSelector(PLAYER_SELECTOR); + + const ws = mock(); + player.ws = ws; + + expect(player.onopen()).toEqual(['mp4', 'webrtc']); + expect(ws.send).toHaveBeenCalledWith(expect.stringContaining('"type":"mp4"')); + }); });