|
1 | 1 | import { globalThis, document } from './polyfills'; |
2 | 2 | import { MediaController, MediaErrorDialog } from 'media-chrome'; |
3 | 3 | import { Attributes as MediaControllerAttributes } from 'media-chrome/dist/media-container.js'; |
4 | | -import { MediaUIAttributes } from 'media-chrome/dist/constants.js'; |
| 4 | +import { MediaStateChangeEvents, MediaUIAttributes, MediaUIEvents } from 'media-chrome/dist/constants.js'; |
5 | 5 | import 'media-chrome/dist/experimental/index.js'; |
6 | 6 | import { MediaThemeElement } from 'media-chrome/dist/media-theme-element.js'; |
7 | 7 | import MuxVideoElement, { MediaError, Attributes as MuxVideoAttributes } from '@mux/mux-video'; |
@@ -809,6 +809,40 @@ class MuxPlayerElement extends VideoApiElement implements MuxPlayerElement { |
809 | 809 | this.#render({ [toPropName(attrName)]: newValue }); |
810 | 810 | } |
811 | 811 |
|
| 812 | + async requestFullscreen(_options?: FullscreenOptions) { |
| 813 | + if (!this.mediaController || this.mediaController.hasAttribute(MediaUIAttributes.MEDIA_IS_FULLSCREEN)) { |
| 814 | + return; |
| 815 | + } |
| 816 | + this.mediaController?.dispatchEvent( |
| 817 | + new globalThis.CustomEvent(MediaUIEvents.MEDIA_ENTER_FULLSCREEN_REQUEST, { |
| 818 | + composed: true, |
| 819 | + bubbles: true, |
| 820 | + }) |
| 821 | + ); |
| 822 | + return new Promise<void>((resolve, _reject) => { |
| 823 | + this.mediaController?.addEventListener(MediaStateChangeEvents.MEDIA_IS_FULLSCREEN, () => resolve(), { |
| 824 | + once: true, |
| 825 | + }); |
| 826 | + }); |
| 827 | + } |
| 828 | + |
| 829 | + async exitFullscreen() { |
| 830 | + if (!this.mediaController || !this.mediaController.hasAttribute(MediaUIAttributes.MEDIA_IS_FULLSCREEN)) { |
| 831 | + return; |
| 832 | + } |
| 833 | + this.mediaController?.dispatchEvent( |
| 834 | + new globalThis.CustomEvent(MediaUIEvents.MEDIA_EXIT_FULLSCREEN_REQUEST, { |
| 835 | + composed: true, |
| 836 | + bubbles: true, |
| 837 | + }) |
| 838 | + ); |
| 839 | + return new Promise<void>((resolve, _reject) => { |
| 840 | + this.mediaController?.addEventListener(MediaStateChangeEvents.MEDIA_IS_FULLSCREEN, () => resolve(), { |
| 841 | + once: true, |
| 842 | + }); |
| 843 | + }); |
| 844 | + } |
| 845 | + |
812 | 846 | get preferCmcd() { |
813 | 847 | return (this.getAttribute(MuxVideoAttributes.PREFER_CMCD) as ValueOf<CmcdTypes>) ?? undefined; |
814 | 848 | } |
|
0 commit comments