Merge branch 'feat-audiocontext' into develop

master
Håvar Aambø Fosstveit 2019-04-05 14:22:39 +02:00
commit 9013b40143
1 changed files with 29 additions and 10 deletions

View File

@ -87,8 +87,10 @@ export default class RoomClient
// Alert sound // Alert sound
this._soundAlert = new Audio('/sounds/notify.mp3'); this._soundAlert = new Audio('/sounds/notify.mp3');
// AudioContext if (AudioContext)
this._audioContext= null; {
this._audioContext = new AudioContext();
}
// Socket.io peer connection // Socket.io peer connection
this._signalingSocket = null; this._signalingSocket = null;
@ -562,14 +564,32 @@ export default class RoomClient
{ {
logger.debug('muteMic()'); logger.debug('muteMic()');
this._micProducer.pause(); try
{
this._micProducer.pause();
}
catch (error)
{
logger.error('muteMic() | failed: %o', error);
this.notify('An error occured while accessing your microphone.');
}
} }
unmuteMic() unmuteMic()
{ {
logger.debug('unmuteMic()'); logger.debug('unmuteMic()');
this._micProducer.resume(); try
{
this._micProducer.resume();
}
catch (error)
{
logger.error('unmuteMic() | failed: %o', error);
this.notify('An error occured while accessing your microphone.');
}
} }
// Updated consumers based on spotlights // Updated consumers based on spotlights
@ -989,8 +1009,7 @@ export default class RoomClient
logger.debug('resumeAudio()'); logger.debug('resumeAudio()');
try try
{ {
if (AudioContext) await this._audioContext.resume();
await this._audioContext.resume();
store.dispatch( store.dispatch(
stateActions.setAudioSuspended({ audioSuspended: false })); stateActions.setAudioSuspended({ audioSuspended: false }));
@ -998,6 +1017,8 @@ export default class RoomClient
} }
catch (error) catch (error)
{ {
store.dispatch(
stateActions.setAudioSuspended({ audioSuspended: true }));
logger.error('resumeAudioJoin() failed: %o', error); logger.error('resumeAudioJoin() failed: %o', error);
} }
} }
@ -1518,14 +1539,12 @@ export default class RoomClient
} }
}); });
if (AudioContext) if (this._audioContext)
{ {
this._audioContext = new AudioContext();
// We need to provoke user interaction to get permission from browser to start audio // We need to provoke user interaction to get permission from browser to start audio
if (this._audioContext.state === 'suspended') if (this._audioContext.state === 'suspended')
{ {
store.dispatch(stateActions.setAudioSuspended({ audioSuspended: true })); this.resumeAudio();
} }
} }
} }