@@ -98,6 +98,62 @@ class VoxeetConference extends Component {
98
98
}
99
99
let accessToken , refreshToken ;
100
100
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
+
101
157
const doRefreshToken = ( ) => {
102
158
return axios . get ( `${ AUTH_SERVER } /api/token` , { } ) . then ( ( response ) => {
103
159
accessToken = response . data . access_token ;
0 commit comments