Merge webrtc-reconnect into bigbluebutton/master

Conflicts:
	bigbluebutton-client/resources/prod/lib/bbb_webrtc_bridge_sip.js
	bigbluebutton-client/src/org/bigbluebutton/main/model/users/AutoReconnect.as
	bigbluebutton-client/src/org/bigbluebutton/modules/phone/managers/WebRTCCallManager.as
This commit is contained in:
Felipe Cecagno 2016-01-12 15:27:01 -02:00
commit d98bee07cf
6 changed files with 78 additions and 22 deletions

View File

@ -495,6 +495,9 @@ trait UsersApp {
usersModel.getUser(msg.userId) match {
case Some(user) => {
// this is used to restore the mute state on reconnect
val previouslyMuted = user.voiceUser.muted
val vu = new VoiceUser(msg.voiceUserId, msg.userId, msg.callerIdName,
msg.callerIdNum, joined = true, locked = false,
msg.muted, msg.talking, msg.listenOnly)
@ -504,10 +507,10 @@ trait UsersApp {
log.info("User joined voice. meetingId=" + mProps.meetingID + " userId=" + user.userID + " user=" + nu)
outGW.send(new UserJoinedVoice(mProps.meetingID, mProps.recorded, mProps.voiceBridge, nu))
if (meetingModel.isMeetingMuted()) {
if (meetingModel.isMeetingMuted() || previouslyMuted) {
outGW.send(new MuteVoiceUser(mProps.meetingID, mProps.recorded,
nu.userID, nu.userID, mProps.voiceBridge,
nu.voiceUser.userId, meetingModel.isMeetingMuted()))
nu.voiceUser.userId, true))
}
startRecordingVoiceConference()

View File

@ -80,6 +80,9 @@ bbb.webrtcWarning.failedError.1011 = Error 1011: ICE gathering timeout
bbb.webrtcWarning.failedError.unknown = Error {0}: Unknown error code
bbb.webrtcWarning.failedError.mediamissing = Could not get your microphone for a WebRTC call
bbb.webrtcWarning.failedError.endedunexpectedly = The WebRTC echo test ended unexpectedly
bbb.webrtcWarning.connection.dropped = WebRTC connection dropped
bbb.webrtcWarning.connection.reconnecting = Attempting to reconnect
bbb.webrtcWarning.connection.reestablished = WebRTC connection re-established
bbb.mainToolbar.helpBtn = Help
bbb.mainToolbar.logoutBtn = Logout
bbb.mainToolbar.logoutBtn.toolTip = Log Out

View File

@ -80,6 +80,9 @@ bbb.webrtcWarning.failedError.1010 = Erro 1010\: Negociação ICE expirou
bbb.webrtcWarning.failedError.unknown = Erro {0}\: Código de erro desconhecido
bbb.webrtcWarning.failedError.mediamissing = Não foi possível acessar seu microfone para a chamada WebRTC
bbb.webrtcWarning.failedError.endedunexpectedly = O teste de eco WebRTC terminou inesperadamente
bbb.webrtcWarning.connection.dropped = Falha na conexão WebRTC
bbb.webrtcWarning.connection.reconnecting = Reconectando
bbb.webrtcWarning.connection.reestablished = Conexão WebRTC restabelecida
bbb.mainToolbar.helpBtn = Ajuda
bbb.mainToolbar.logoutBtn = Sair
bbb.mainToolbar.logoutBtn.toolTip = Sair da sessão

View File

@ -80,6 +80,10 @@ function callIntoConference(voiceBridge, callback, isListenOnly) {
function joinWebRTCVoiceConference() {
console.log("Joining to the voice conference directly");
inEchoTest = false;
// set proper callbacks to previously created user agent
if(userAgent) {
setUserAgentListeners(webRTCCallback);
}
callIntoConference(conferenceVoiceBridge, webRTCCallback);
}
@ -184,10 +188,18 @@ function createUAWithStuns(username, server, callback, stunsConfig, makeCallFunc
uaConnected = false;
userAgent = new SIP.UA(configuration);
setUserAgentListeners(callback, makeCallFunc);
userAgent.start();
};
function setUserAgentListeners(callback, makeCallFunc) {
console.log("reseting UA callbacks");
userAgent.off('connected');
userAgent.on('connected', function() {
uaConnected = true;
makeCallFunc();
});
userAgent.off('disconnected');
userAgent.on('disconnected', function() {
if (userAgent) {
if (userAgent != null) {
@ -203,8 +215,6 @@ function createUAWithStuns(username, server, callback, stunsConfig, makeCallFunc
}
}
});
userAgent.start();
};
function getUserMicMedia(getUserMicMediaSuccess, getUserMicMediaFailure) {

View File

@ -31,11 +31,13 @@ package org.bigbluebutton.main.model.users
private var _backoff:Number = 2000;
private var _reconnectCallback:Function;
private var _reconnectParameters:Array;
private var _attempt:Number;
public function onDisconnect(callback:Function, parameters:Array):void {
LOGGER.debug("onDisconnect, parameters={0}", [parameters.toString()]);
_reconnectCallback = callback;
_reconnectParameters = parameters;
_attempt = 0;
attemptReconnect(0);
}
@ -45,14 +47,19 @@ package org.bigbluebutton.main.model.users
}
private function attemptReconnect(backoff:Number):void {
LOGGER.debug("attemptReconnect backoff={0}", [backoff]);
_attempt++;
LOGGER.debug("attemptReconnect backoff={0}, attempt={1}", [backoff, _attempt]);
var retryTimer:Timer = new Timer(backoff, 1);
retryTimer.addEventListener(TimerEvent.TIMER, function():void {
LOGGER.debug("Reconnecting");
LOGGER.debug("Reconnecting");
_reconnectCallback.apply(null, _reconnectParameters);
});
retryTimer.start();
if (_backoff < 16000) _backoff = Math.max(backoff, 500) *2;
}
public function get attempts():Number {
return _attempt;
}
}
}

View File

@ -16,6 +16,7 @@ package org.bigbluebutton.modules.phone.managers
import org.bigbluebutton.main.api.JSAPI;
import org.bigbluebutton.main.api.JSLog;
import org.bigbluebutton.main.events.ClientStatusEvent;
import org.bigbluebutton.main.model.users.AutoReconnect;
import org.bigbluebutton.modules.phone.PhoneModel;
import org.bigbluebutton.modules.phone.PhoneOptions;
import org.bigbluebutton.modules.phone.events.AudioSelectionWindowEvent;
@ -32,6 +33,7 @@ package org.bigbluebutton.modules.phone.managers
public class WebRTCCallManager
{
private static const LOGGER:ILogger = getClassLogger(WebRTCCallManager);
private const MAX_RETRIES:Number = 5;
private var browserType:String = "unknown";
private var browserVersion:int = 0;
@ -42,6 +44,9 @@ package org.bigbluebutton.modules.phone.managers
private var options:PhoneOptions;
private var model:WebRTCModel = PhoneModel.getInstance().webRTCModel;
private var reconnect:AutoReconnect = new AutoReconnect();
private var reconnecting:Boolean = false;
public function WebRTCCallManager() {
var browserInfo:Array = JSAPI.getInstance().getBrowserInfo();
@ -127,7 +132,12 @@ package org.bigbluebutton.modules.phone.managers
LOGGER.debug("setting state to IN_CONFERENCE");
model.state = Constants.IN_CONFERENCE;
dispatcher.dispatchEvent(new WebRTCJoinedVoiceConferenceEvent());
if(reconnecting) {
dispatcher.dispatchEvent(new ClientStatusEvent(ClientStatusEvent.SUCCESS_MESSAGE_EVENT,
ResourceUtil.getInstance().getString("bbb.webrtcWarning.connection.reestablished"),
ResourceUtil.getInstance().getString("bbb.webrtcWarning.connection.reestablished")));
reconnecting = false;
}
}
public function handleWebRTCCallEndedEvent():void {
@ -216,22 +226,42 @@ package org.bigbluebutton.modules.phone.managers
var errorString:String;
model.state = Constants.INITED;
if (event.errorCode == 1004) {
errorString = ResourceUtil.getInstance().getString("bbb.webrtcWarning.failedError." + event.errorCode, [event.cause]);
} else {
errorString = ResourceUtil.getInstance().getString("bbb.webrtcWarning.failedError." + event.errorCode);
if(!reconnecting) {
LOGGER.debug("WebRTC call failed, attempting reconnection");
reconnecting = true;
dispatcher.dispatchEvent(new ClientStatusEvent(ClientStatusEvent.WARNING_MESSAGE_EVENT,
ResourceUtil.getInstance().getString("bbb.webrtcWarning.connection.dropped"),
ResourceUtil.getInstance().getString("bbb.webrtcWarning.connection.reconnecting")));
reconnect.onDisconnect(joinVoiceConference, []);
}
if (!errorString) {
errorString = ResourceUtil.getInstance().getString("bbb.webrtcWarning.failedError.unknown", [event.errorCode]);
else {
LOGGER.debug("WebRTC call reconnection failed");
if( reconnect.attempts < MAX_RETRIES ) {
LOGGER.debug("Retrying, attempt " + reconnect.attempts);
reconnect.onConnectionAttemptFailed();
}
else {
LOGGER.debug("Giving up");
reconnecting = false;
if (event.errorCode == 1004) {
errorString = ResourceUtil.getInstance().getString("bbb.webrtcWarning.failedError." + event.errorCode, [event.cause]);
} else {
errorString = ResourceUtil.getInstance().getString("bbb.webrtcWarning.failedError." + event.errorCode);
}
if (!errorString) {
errorString = ResourceUtil.getInstance().getString("bbb.webrtcWarning.failedError.unknown", [event.errorCode]);
}
var logData:Object = new Object();
logData.user = UsersUtil.getUserData();
logData.user.reason = errorString;
LOGGER.info(jsonXify(logData));
sendWebRTCAlert(ResourceUtil.getInstance().getString("bbb.webrtcWarning.title"), ResourceUtil.getInstance().getString("bbb.webrtcWarning.message", [errorString]), errorString);
}
}
var logData:Object = new Object();
logData.user = UsersUtil.getUserData();
logData.user.reason = errorString;
LOGGER.info(jsonXify(logData));
sendWebRTCAlert(ResourceUtil.getInstance().getString("bbb.webrtcWarning.title"), ResourceUtil.getInstance().getString("bbb.webrtcWarning.message", [errorString]), errorString);
}
public function handleWebRTCMediaFailedEvent():void {
@ -279,4 +309,4 @@ package org.bigbluebutton.modules.phone.managers
dispatcher.dispatchEvent(new ClientStatusEvent(ClientStatusEvent.FAIL_MESSAGE_EVENT, title, error));
}
}
}
}