Skip to content
This repository was archived by the owner on Mar 29, 2025. It is now read-only.

Commit 1e1644c

Browse files
author
Arthur Jolivet
committed
CCSA-44 Add support for PIP Controls
Chromium-only for now (Chrome 91+, Edge 91+) Documentation: https://w3c.github.io/mediasession Live demo: https://googlechrome.github.io/samples/media-session/video-conferencing.html
1 parent bd5d7d3 commit 1e1644c

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

frontend/src/app/VoxeetConference.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,62 @@ class VoxeetConference extends Component {
9898
}
9999
let accessToken, refreshToken;
100100

101+
if ('mediaSession' in navigator) {
102+
/////////////////////////////////////////////////////////////////////////
103+
/// PIP Controls (Chromium-only: Chrome 91+, Edge 91+)
104+
///
105+
/// Documentation: https://w3c.github.io/mediasession
106+
/// Notes: These actions are not supported yet on Media Session GMC UI
107+
/////////////////////////////////////////////////////////////////////////
108+
109+
let isMicrophoneActive = constraints.audio;
110+
let isCameraActive = constraints.video;
111+
const enablePipActions = navigator.mediaSession
112+
&& navigator.mediaSession.setActionHandler
113+
&& navigator.mediaSession.setMicrophoneActive
114+
&& navigator.mediaSession.setCameraActive
115+
&& document.exitPictureInPicture;
116+
117+
if (enablePipActions) {
118+
console.log("Pip actions are available!")
119+
navigator.mediaSession.setMicrophoneActive(isMicrophoneActive);
120+
navigator.mediaSession.setCameraActive(isCameraActive);
121+
122+
try {
123+
navigator.mediaSession.setActionHandler('togglemicrophone', () => {
124+
isMicrophoneActive = !isMicrophoneActive;
125+
//FIXME: Use react component like Buttons.ToggleMicrophoneButton.toggle() instead of query selector
126+
document.querySelector('[data-for=toggle-mute]').click()
127+
navigator.mediaSession.setMicrophoneActive(isMicrophoneActive);
128+
});
129+
} catch(error) {
130+
console.warn('"togglemicrophone" media session action is not supported.');
131+
}
132+
133+
try {
134+
navigator.mediaSession.setActionHandler('togglecamera', () => {
135+
isCameraActive = !isCameraActive;
136+
//FIXME: Use react component like Buttons.ToggleVideoButton.toggle() instead of query selector
137+
document.querySelector('[data-for=toggle-video]').click()
138+
navigator.mediaSession.setCameraActive(isCameraActive);
139+
});
140+
} catch(error) {
141+
console.warn('"togglecamera" media session action is not supported.');
142+
}
143+
144+
try {
145+
navigator.mediaSession.setActionHandler("hangup", () => {
146+
document.exitPictureInPicture();
147+
navigator.mediaSession.playbackState = "none";
148+
//FIXME: Use react component like Buttons.HangupButton.leave() instead of query selector
149+
document.querySelector('[data-for=leave]').click()
150+
});
151+
} catch (error) {
152+
console.warn('"hangup" media session action is not supported.');
153+
}
154+
}
155+
}
156+
101157
const doRefreshToken = () => {
102158
return axios.get(`${AUTH_SERVER}/api/token`, {}).then((response) => {
103159
accessToken = response.data.access_token;

0 commit comments

Comments
 (0)