pass params via bridge constructor

This commit is contained in:
Anton Georgiev 2017-04-19 11:01:28 -04:00
parent 9152bfbaf9
commit 4c49f68771
4 changed files with 52 additions and 48 deletions

View File

@ -1,10 +1,6 @@
import Users from '/imports/api/users';
import Meetings from '/imports/api/meetings';
import Auth from '/imports/ui/services/auth';
import BaseAudioBridge from './base';
import {callServer} from '/imports/ui/services/api';
import { getVoiceBridge } from '/imports/ui/components/audio/service';
import { callServer } from '/imports/ui/services/api';
const APP_CONFIG = Meteor.settings.public.app;
const MEDIA_CONFIG = Meteor.settings.public.media;
@ -12,14 +8,9 @@ const MEDIA_CONFIG = Meteor.settings.public.media;
let triedHangup = false;
export default class SIPBridge extends BaseAudioBridge {
constructor() {
constructor(userData) {
super();
}
// TODO this should be done outside the file (via callback?)
_amIListenOnly() {
const userId = Auth.userID;
return Users.findOne({ userId }).user.listenOnly;
this.userData = userData;
}
joinListenOnly() {
@ -53,7 +44,7 @@ export default class SIPBridge extends BaseAudioBridge {
console.log('Attempting to hangup on WebRTC call');
// notify BBB-apps we are leaving the call call if we are listen only
if (this._amIListenOnly()) {
if (userData.listenOnly) {
callServer('listenOnlyToggle', false);
}
@ -82,7 +73,7 @@ export default class SIPBridge extends BaseAudioBridge {
// join the conference. If listen only send the request to the server
_joinVoiceCallSIP(options) {
const extension = getVoiceBridge();
const extension = this.userData.voiceBridge;
console.log(options);
// create voice call params
@ -90,13 +81,17 @@ export default class SIPBridge extends BaseAudioBridge {
console.log('Beginning WebRTC Conference Call');
};
const {
userId,
username,
} = this.userData;
window.BBB = {};
window.BBB.getMyUserInfo = function (callback) {
const uid = Auth.userID;
const result = {
myUserID: uid,
myUsername: Users.findOne({ userId: uid }).user.name,
myInternalUserID: uid,
myUserID: userId,
myUsername: username,
myInternalUserID: userId,
myAvatarURL: null,
myRole: 'getMyRole',
amIPresenter: 'false',
@ -106,10 +101,9 @@ export default class SIPBridge extends BaseAudioBridge {
return callback(result);
};
const m = Meetings.findOne();
const st = {
stun: m.stuns,
turn: m.turns,
const stunsAndTurns = {
stun: this.userData.stuns,
turn: this.userData.turns,
};
callIntoConference(extension, function (audio) {
@ -131,6 +125,6 @@ export default class SIPBridge extends BaseAudioBridge {
window.dispatchEvent(connected);
break;
}
}, options.isListenOnly, st);
}, options.isListenOnly, stunsAndTurns);
}
}

View File

@ -1,19 +1,16 @@
import Users from '/imports/api/users';
import Auth from '/imports/ui/services/auth';
import { getVoiceBridge } from '/imports/ui/components/audio/service';
import BaseAudioBridge from './base';
const createVertoUserName = () => {
const userId = Auth.userID;
const uName = Users.findOne({ userId }).user.name;
return 'FreeSWITCH User - ' + encodeURIComponent(uName);
};
export default class VertoBridge extends BaseAudioBridge {
constructor(userId, username) {
constructor(userData) {
super();
const {
username,
voiceBridge,
} = userData;
this.voiceBridge = voiceBridge;
this.vertoUsername = 'FreeSWITCH User - ' + encodeURIComponent(username);
console.log('vertoUsername=' + this.vertoUsername);
}
exitAudio() {
@ -23,8 +20,8 @@ export default class VertoBridge extends BaseAudioBridge {
joinListenOnly() {
window.vertoJoinListenOnly(
'remote-media',
getVoiceBridge(),
createVertoUserName(),
this.voiceBridge,
this.vertoUsername,
null,
);
}
@ -32,8 +29,8 @@ export default class VertoBridge extends BaseAudioBridge {
joinMicrophone() {
window.vertoJoinMicrophone(
'remote-media',
getVoiceBridge(),
createVertoUserName(),
this.voiceBridge,
this.vertoUsername,
null,
);
}

View File

@ -5,14 +5,13 @@ import SIPBridge from '../bridge/sip';
// manages audio calls and audio bridges
export default class AudioManager {
constructor() {
constructor(userData) {
const MEDIA_CONFIG = Meteor.settings.public.media;
const audioBridge = MEDIA_CONFIG.useSIPAudio ? new SIPBridge() : new VertoBridge();
const audioBridge = MEDIA_CONFIG.useSIPAudio ? new SIPBridge(userData) : new VertoBridge(userData);
if (!(audioBridge instanceof BaseAudioBridge)) {
throw 'Audio Bridge not compatible';
}
console.log('audio manager constructor');
this.bridge = audioBridge;
}

View File

@ -1,6 +1,8 @@
import React from 'react';
import AudioModal from './audio-modal/component';
import Meetings from '/imports/api/meetings';
import Users from '/imports/api/users';
import Auth from '/imports/ui/services/auth';
import { showModal } from '/imports/ui/components/app/service';
import AudioManager from '/imports/api/audio/client/manager'
@ -10,16 +12,29 @@ const handleJoinAudio = () => {
return showModal(<AudioModal handleJoinListenOnly={handleJoinListenOnly} />);
};
const getVoiceBridge = () => {
return Meetings.findOne({}).voiceConf;
} ;
let audioManager = undefined;
const init = () => {
audioManager = new AudioManager();
};
const userId = Auth.userID;
const User = Users.findOne({ userId });
const username = User.user.name;
const listenOnly = User.user.listenOnly;
console.log('audioBridge1=', audioManager);
const Meeting = Meetings.findOne(); //TODO test this with Breakouts
const turns = Meeting.turns;
const stuns = Meeting.stuns;
const voiceBridge = Meeting.voiceBridge;
const userData = {
userId,
username,
listenOnly,
turns,
stuns,
voiceBridge,
};
audioManager = new AudioManager(userData);
};
let exitAudio = () => audioManager.exitAudio();
let joinListenOnly = () => audioManager.joinAudio(true);
@ -28,7 +43,6 @@ let joinMicrophone = () => audioManager.joinAudio(false);
export {
init,
handleJoinAudio,
getVoiceBridge,
exitAudio,
joinListenOnly,
joinMicrophone,