turned the audio services into classes

This commit is contained in:
Anton Georgiev 2017-03-30 13:57:05 -04:00
parent 6de1c470a1
commit afcb365ac6
9 changed files with 250 additions and 227 deletions

View File

@ -0,0 +1,14 @@
export default class BaseAudioService {
constructor() {
}
exitAudio () {
}
joinListenOnly() {
}
joinMicrophone() {
}
}

View File

@ -0,0 +1,29 @@
import { callServer } from '/imports/ui/services/api';
import VertoBridge from './verto';
import SIPBridge from './sip';
import BaseAudioService from './base';
const MEDIA_CONFIG = Meteor.settings.public.media;
export default class AudioAPI extends BaseAudioService {
constructor() {
super();
this.audioBridge = undefined;
this.audioBridge = MEDIA_CONFIG.useSIPAudio ? new SIPBridge() : new VertoBridge();
}
exitAudio (afterExitCall = () => {}) {
this.audioBridge.exitAudio();
}
joinListenOnly() {
callServer('listenOnlyRequestToggle', true);
this.audioBridge.joinListenOnly();
}
joinMicrophone() {
this.audioBridge.joinMicrophone();
}
};

View File

@ -0,0 +1,138 @@
import Users from '/imports/api/users';
import Meetings from '/imports/api/meetings';
import Auth from '/imports/ui/services/auth';
import BaseAudioService from './base';
import {callServer} from '/imports/ui/services/api';
import { getVoiceBridge } from '/imports/ui/components/audio/service';
const APP_CONFIG = Meteor.settings.public.app;
const MEDIA_CONFIG = Meteor.settings.public.media;
let triedHangup = false;
export default class SIPService extends BaseAudioService {
constructor() {
super();
}
// TODO this should be done outside the file (via callback?)
_amIListenOnly() {
const userId = Auth.userID;
return Users.findOne({ userId }).user.listenOnly;
}
joinListenOnly() {
callServer('listenOnlyRequestToggle', true);
this._joinVoiceCallSIP({ isListenOnly: true });
}
joinMicrophone() {
this._joinVoiceCallSIP({ isListenOnly: false });
}
// Periodically check the status of the WebRTC call, when a call has been established attempt to
// hangup, retry if a call is in progress, send the leave voice conference message to BBB
exitAudio(afterExitCall = () => {}) {
// To be called when the hangup is initiated
const hangupCallback = function () {
console.log('Exiting Voice Conference');
};
// Checks periodically until a call is established so we can successfully end the call
// clean state
triedHangup = false;
// function to initiate call
const checkToHangupCall = ((context, afterExitCall = () => {}) => {
// if an attempt to hang up the call is made when the current session is not yet finished,
// the request has no effect
// keep track in the session if we haven't tried a hangup
if (window.getCallStatus() != null && !triedHangup) {
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()) {
callServer('listenOnlyRequestToggle', false);
}
window.webrtc_hangup(hangupCallback);
// we have hung up, prevent retries
triedHangup = true;
if (afterExitCall) {
afterExitCall(this, APP_CONFIG.listenOnly);
}
} else {
console.log('RETRYING hangup on WebRTC call in ' +
`${MEDIA_CONFIG.WebRTCHangupRetryInterval} ms`);
// try again periodically
setTimeout(checkToHangupCall, MEDIA_CONFIG.WebRTCHangupRetryInterval);
}
})
// automatically run function
(this, afterExitCall);
return false;
}
// join the conference. If listen only send the request to the server
_joinVoiceCallSIP(options) {
const extension = getVoiceBridge();
console.log(options);
// create voice call params
const joinCallback = function (message) {
console.log('Beginning WebRTC Conference Call');
};
window.BBB = {};
window.BBB.getMyUserInfo = function (callback) {
const uid = Auth.userID;
const result = {
myUserID: uid,
myUsername: Users.findOne({ userId: uid }).user.name,
myInternalUserID: uid,
myAvatarURL: null,
myRole: 'getMyRole',
amIPresenter: 'false',
voiceBridge: extension,
dialNumber: null,
};
return callback(result);
};
const m = Meetings.findOne();
const st = {
stun: m.stuns,
turn: m.turns,
};
callIntoConference(extension, 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;
}
}, options.isListenOnly, st);
}
}

View File

@ -0,0 +1,58 @@
import Users from '/imports/api/users';
import Auth from '/imports/ui/services/auth';
import { getVoiceBridge } from '/imports/ui/components/audio/service';
import BaseAudioService from './base';
export default class VertoService extends BaseAudioService {
constructor() {
super();
}
createVertoUserName() {
const uid = Auth.userID;
const uName = Users.findOne({ userId: uid }).user.name;
const conferenceUsername = 'FreeSWITCH User - ' + encodeURIComponent(uName);
return conferenceUsername;
}
exitAudio() {
window.vertoExitAudio();
}
joinListenOnly() {
window.vertoJoinListenOnly(
'remote-media',
getVoiceBridge(),
this.createVertoUserName(),
null,
);
}
joinMicrophone() {
window.vertoJoinMicrophone(
'remote-media',
getVoiceBridge(),
this.createVertoUserName(),
null,
);
}
vertoWatchVideo() {
window.vertoWatchVideo(
'deskshareVideo',
getVoiceBridge(),
this.createVertoUserName(),
null,
);
}
shareVertoScreen() {
vertoManager.shareScreen(
'deskshareVideo',
getVoiceBridge(),
this.createVertoUserName(),
null,
);
}
}

View File

@ -1,29 +0,0 @@
import { callServer } from '/imports/ui/services/api';
import VertoBridge from './verto-bridge';
import SIPBridge from './sip-bridge';
const MEDIA_CONFIG = Meteor.settings.public.media;
// pick between SIP or Verto
let audioBridge = undefined;
audioBridge = MEDIA_CONFIG.useSIPAudio ? SIPBridge : VertoBridge;
function exitAudio(afterExitCall = () => {}) {
audioBridge.exitAudio();
}
function joinListenOnly() {
callServer('listenOnlyRequestToggle', true);
audioBridge.joinListenOnly();
}
function joinMicrophone() {
audioBridge.joinMicrophone();
}
export {
joinListenOnly,
joinMicrophone,
exitAudio,
};

View File

@ -1,135 +0,0 @@
import Users from '/imports/api/users';
import Meetings from '/imports/api/meetings';
import Auth from '/imports/ui/services/auth';
import {callServer} from '/imports/ui/services/api';
import { getVoiceBridge } from '/imports/ui/components/audio/service';
const APP_CONFIG = Meteor.settings.public.app;
const MEDIA_CONFIG = Meteor.settings.public.media;
let triedHangup = false;
// TODO this should be done outside the file (via callback?)
function _amIListenOnly() {
const uid = Auth.userID;
return Users.findOne({ userId: uid }).user.listenOnly;
}
// Periodically check the status of the WebRTC call, when a call has been established attempt to
// hangup, retry if a call is in progress, send the leave voice conference message to BBB
function exitAudio(afterExitCall = () => {}) {
// To be called when the hangup is initiated
const hangupCallback = function () {
console.log('Exiting Voice Conference');
};
// Checks periodically until a call is established so we can successfully end the call
// clean state
triedHangup = false;
// function to initiate call
const checkToHangupCall = ((context, afterExitCall = () => {}) => {
// if an attempt to hang up the call is made when the current session is not yet finished,
// the request has no effect
// keep track in the session if we haven't tried a hangup
if (window.getCallStatus() != null && !triedHangup) {
console.log('Attempting to hangup on WebRTC call');
// notify BBB-apps we are leaving the call call if we are listen only
if (_amIListenOnly()) {
callServer('listenOnlyRequestToggle', false);
}
window.webrtc_hangup(hangupCallback);
// we have hung up, prevent retries
triedHangup = true;
if (afterExitCall) {
afterExitCall(this, APP_CONFIG.listenOnly);
}
} else {
console.log('RETRYING hangup on WebRTC call in ' +
`${MEDIA_CONFIG.WebRTCHangupRetryInterval} ms`);
// try again periodically
setTimeout(checkToHangupCall, MEDIA_CONFIG.WebRTCHangupRetryInterval);
}
})
// automatically run function
(this, afterExitCall);
return false;
}
// join the conference. If listen only send the request to the server
function _joinVoiceCallSIP(options) {
const extension = getVoiceBridge();
console.log(options);
// create voice call params
const joinCallback = function (message) {
console.log('Beginning WebRTC Conference Call');
};
window.BBB = {};
window.BBB.getMyUserInfo = function (callback) {
const uid = Auth.userID;
const result = {
myUserID: uid,
myUsername: Users.findOne({ userId: uid }).user.name,
myInternalUserID: uid,
myAvatarURL: null,
myRole: 'getMyRole',
amIPresenter: 'false',
voiceBridge: extension,
dialNumber: null,
};
return callback(result);
};
const m = Meetings.findOne();
const st = {
stun: m.stuns,
turn: m.turns,
};
callIntoConference(extension, 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;
}
}, options.isListenOnly, st);
}
function joinListenOnly() {
callServer('listenOnlyRequestToggle', true);
_joinVoiceCallSIP({ isListenOnly: true });
}
function joinMicrophone() {
_joinVoiceCallSIP({ isListenOnly: false });
}
export default {
joinListenOnly,
joinMicrophone,
exitAudio,
};

View File

@ -1,58 +0,0 @@
import Users from '/imports/api/users';
import Auth from '/imports/ui/services/auth';
import { getVoiceBridge } from '/imports/ui/components/audio/service';
function createVertoUserName() {
const uid = Auth.userID;
const uName = Users.findOne({ userId: uid }).user.name;
const conferenceUsername = 'FreeSWITCH User - ' + encodeURIComponent(uName);
return conferenceUsername;
}
function exitAudio() {
window.vertoExitAudio();
}
function joinListenOnly() {
window.vertoJoinListenOnly(
'remote-media',
getVoiceBridge(),
createVertoUserName(),
null,
);
}
function joinMicrophone() {
window.vertoJoinMicrophone(
'remote-media',
getVoiceBridge(),
createVertoUserName(),
null,
);
}
function vertoWatchVideo() {
window.vertoWatchVideo(
'deskshareVideo',
getVoiceBridge(),
createVertoUserName(),
null,
);
}
function shareVertoScreen() {
vertoManager.shareScreen(
'deskshareVideo',
getVoiceBridge(),
createVertoUserName(),
null,
);
}
export default {
joinListenOnly,
joinMicrophone,
exitAudio,
vertoWatchVideo,
shareVertoScreen,
};

View File

@ -3,8 +3,7 @@ import AudioModal from './audio-modal/component';
import Meetings from '/imports/api/meetings';
import { showModal } from '/imports/ui/components/app/service';
import { joinListenOnly, joinMicrophone,
exitAudio } from '/imports/api/audio/client/main';
import AudioAPI from '/imports/api/audio/client/bridge'
const handleJoinAudio = () => {
const handleJoinListenOnly = () => joinListenOnly();
@ -15,6 +14,11 @@ const getVoiceBridge = () => {
return Meetings.findOne({}).voiceConf;
} ;
const audioAPI = new AudioAPI();
let exitAudio = () => audioAPI.exitAudio();
let joinListenOnly = () => audioAPI.joinListenOnly();
let joinMicrophone = () => audioAPI.joinMicrophone();
export {
handleJoinAudio,
getVoiceBridge,

View File

@ -1,7 +1,9 @@
import Deskshare from '/imports/api/deskshare';
import {createVertoUserName, watchVertoVideo} from '/imports/api/audio/client/verto-bridge';
import VertoAPI from '/imports/api/audio/client/bridge/verto';
import Auth from '/imports/ui/services/auth';
const vertoAPI = new VertoAPI();
// when the meeting information has been updated check to see if it was
// desksharing. If it has changed either trigger a call to receive video
// and display it, or end the call and hide the video
@ -28,12 +30,12 @@ function videoIsBroadcasting() {
// if remote deskshare has been ended disconnect and hide the video stream
function presenterDeskshareHasEnded() {
// exitVoiceCall();
// vertoAPI.exitVoiceCall();
};
// if remote deskshare has been started connect and display the video stream
function presenterDeskshareHasStarted() {
vertoWatchVideo();
vertoAPI.vertoWatchVideo();
};
export {