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