set state for AudioManager when joining or leaving audio

This commit is contained in:
Matthew Marangoni 2017-06-16 13:22:17 -07:00
parent 6dd71a3ee0
commit 12d42aaecb
2 changed files with 55 additions and 46 deletions

View File

@ -2,98 +2,7 @@ import BaseAudioBridge from '../bridge/base';
import VertoBridge from '../bridge/verto';
import SIPBridge from '../bridge/sip';
// manages audio calls and audio bridges
export default class AudioManager {
constructor(userData) {
const MEDIA_CONFIG = Meteor.settings.public.media;
const audioBridge = MEDIA_CONFIG.useSIPAudio
? new SIPBridge(userData)
: new VertoBridge(userData);
if (!(audioBridge instanceof BaseAudioBridge)) {
throw 'Audio Bridge not compatible';
}
this.bridge = audioBridge;
this.isListenOnly = false;
this.microphoneLockEnforced = userData.microphoneLockEnforced;
this.currentState = this.CallStates.init;
callbackToAudioBridge = function (audio) {
switch (audio.status) {
case 'failed':
let audioFailed = new CustomEvent('bbb.webrtc.failed', {
status: 'Failed', });
window.dispatchEvent(audioFailed);
break;
case 'mediafail':
let mediaFailed = new CustomEvent('bbb.webrtc.mediaFailed', {
status: 'MediaFailed', });
window.dispatchEvent(mediaFailed);
break;
case 'mediasuccess':
case 'started':
let connected = new CustomEvent('bbb.webrtc.connected', {
status: 'started', });
window.dispatchEvent(connected);
break;
}
};
}
exitAudio() {
this.bridge.exitAudio(this.isListenOnly);
}
joinAudio(listenOnly) {
if (listenOnly || this.microphoneLockEnforced) {
this.isListenOnly = true;
this.bridge.joinListenOnly(callbackToAudioBridge);
} else {
this.bridge.joinMicrophone(callbackToAudioBridge);
}
}
transferToConference() {
// TODO: transfer from initialized state
// TODO: transfer from echo test to conference
// this.bridge.transferToConference();
}
webRTCCallFailed(inEchoTest, errorcode, cause) {
if (this.currentState !== this.CallStates.reconecting) {
this.currentState = this.CallStates.reconecting;
}
}
getMicId() {
// Placeholder, will get the microphone ID for switching input device
// this.bridge.getMicId();
}
setMicId() {
// Placeholder, will set the microphone ID for switching input device
// this.bridge.setMicId();
}
getSpeakerId() {
// Placeholder, will get the speaker ID for switching output device
// this.bridge.getSpeakerId();
}
setSpeakerId() {
// Placeholder, will set the speaker ID for switching output device
// this.bridge.setSpeakerId();
}
getActiveMic() {
// Placeholder, will detect active input hardware
// this.bridge.getActiveMic();
}
}
AudioManager.CallStates = class {
CallStates = class {
static get init() {
return "initialized state";
}
@ -134,3 +43,100 @@ AudioManager.CallStates = class {
return "reconecting";
}
};
// manages audio calls and audio bridges
export default class AudioManager {
constructor(userData) {
const MEDIA_CONFIG = Meteor.settings.public.media;
const audioBridge = MEDIA_CONFIG.useSIPAudio
? new SIPBridge(userData)
: new VertoBridge(userData);
if (!(audioBridge instanceof BaseAudioBridge)) {
throw 'Audio Bridge not compatible';
}
this.bridge = audioBridge;
this.isListenOnly = false;
this.microphoneLockEnforced = userData.microphoneLockEnforced;
this.callStates = new CallStates();
console.log(this.callStates);
this.currentState = this.callStates.init;
callbackToAudioBridge = function (audio) {
switch (audio.status) {
case 'failed':
let audioFailed = new CustomEvent('bbb.webrtc.failed', {
status: 'Failed', });
window.dispatchEvent(audioFailed);
break;
case 'mediafail':
let mediaFailed = new CustomEvent('bbb.webrtc.mediaFailed', {
status: 'MediaFailed', });
window.dispatchEvent(mediaFailed);
break;
case 'mediasuccess':
case 'started':
let connected = new CustomEvent('bbb.webrtc.connected', {
status: 'started', });
window.dispatchEvent(connected);
break;
}
};
}
exitAudio() {
this.bridge.exitAudio(this.isListenOnly);
this.currentState = this.callStates.init;
}
joinAudio(listenOnly) {
if (listenOnly || this.microphoneLockEnforced) {
this.isListenOnly = true;
this.bridge.joinListenOnly(callbackToAudioBridge);
this.currentState = this.callStates.inListenOnly;
} else {
this.bridge.joinMicrophone(callbackToAudioBridge);
this.currentState = this.callStates.inConference;
}
console.log("CURRENT STATE: " + this.currentState);
}
transferToConference() {
// TODO: transfer from initialized state
// TODO: transfer from echo test to conference
// this.bridge.transferToConference();
}
webRTCCallFailed(inEchoTest, errorcode, cause) {
if (this.currentState !== this.CallStates.reconecting) {
this.currentState = this.CallStates.reconecting;
}
}
getMicId() {
// Placeholder, will get the microphone ID for switching input device
// this.bridge.getMicId();
}
setMicId() {
// Placeholder, will set the microphone ID for switching input device
// this.bridge.setMicId();
}
getSpeakerId() {
// Placeholder, will get the speaker ID for switching output device
// this.bridge.getSpeakerId();
}
setSpeakerId() {
// Placeholder, will set the speaker ID for switching output device
// this.bridge.setSpeakerId();
}
getActiveMic() {
// Placeholder, will detect active input hardware
// this.bridge.getActiveMic();
}
}

View File

@ -3,6 +3,7 @@ import { createContainer } from 'meteor/react-meteor-data';
import Button from '/imports/ui/components/button/component';
import { withRouter } from 'react-router';
import { defineMessages, injectIntl } from 'react-intl';
import AudioManager from '/imports/api/audio/client/manager';
const intlMessages = defineMessages({
joinAudio: {
@ -26,6 +27,8 @@ class JoinAudioOptions extends React.Component {
} = this.props;
if (isInAudio || isInListenOnly) {
// if (AudioManager.currentState == AudioManager.callStates.inConference ||
// AudioManager.currentState == AudioManager.callStates.inListenOnly) {
return (
<Button
onClick={handleCloseAudio}