first attempt to use an auto-reconnection handler, still not working properly

This commit is contained in:
Felipe Cecagno 2015-03-19 11:54:08 -03:00
parent 423ffdeffa
commit 867e9b9b36
7 changed files with 680 additions and 495 deletions

View File

@ -0,0 +1,55 @@
/**
* BigBlueButton open source conferencing system - http://www.bigbluebutton.org/
*
* Copyright (c) 2012 BigBlueButton Inc. and by respective authors (see below).
*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation; either version 3.0 of the License, or (at your option) any later
* version.
*
* BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
*
*/
package org.bigbluebutton.main.model.users
{
import flash.events.TimerEvent;
import flash.utils.Timer;
public class AutoReconnect
{
public static const LOG:String = "AutoReconnect - ";
private var _backoff:Number = 2000;
private var _reconnectCallback:Function;
private var _reconnectParameters:Array;
public function onDisconnect(callback:Function, ...parameters):void {
trace(LOG + "onDisconnect, parameters=" + parameters.toString());
_reconnectCallback = callback;
_reconnectParameters = parameters;
attemptReconnect(1000);
}
public function onConnectionAttemptFailed():void {
trace(LOG + "onConnectionAttemptFailed");
attemptReconnect(_backoff);
}
private function attemptReconnect(backoff:Number):void{
trace(LOG + "attemptReconnect backoff=" + backoff);
var retryTimer:Timer = new Timer(backoff, 1);
retryTimer.addEventListener(TimerEvent.TIMER, function():void {
trace(LOG + "Reconnecting");
_reconnectCallback.apply(null, _reconnectParameters);
});
retryTimer.start();
if (_backoff < 16000) _backoff = backoff *2;
}
}
}

View File

@ -30,6 +30,7 @@ package org.bigbluebutton.main.model.users
import org.bigbluebutton.core.UsersUtil;
import org.bigbluebutton.core.services.BandwidthMonitor;
import org.bigbluebutton.main.api.JSLog;
import org.bigbluebutton.main.events.ClientStatusEvent;
import org.bigbluebutton.main.events.InvalidAuthTokenEvent;
import org.bigbluebutton.main.model.ConferenceParameters;
import org.bigbluebutton.main.model.users.events.ConnectionFailedEvent;
@ -60,6 +61,8 @@ package org.bigbluebutton.main.model.users
private var _messageListeners:Array = new Array();
private var authenticated: Boolean = false;
private var reconnect:AutoReconnect = new AutoReconnect();
private var reconnecting:Boolean = false;
public function NetConnectionDelegate():void
{
@ -158,6 +161,10 @@ package org.bigbluebutton.main.model.users
trace(LOG + "*** handleValidateAuthTokenTimedOut. valid=[ " + tokenValid + "] **** \n");
dispatcher.dispatchEvent(new InvalidAuthTokenEvent());
}
if (reconnecting) {
onReconnect();
reconnecting = false;
}
}
private function handleValidateAuthTokenReply(msg: Object):void {
@ -173,6 +180,30 @@ package org.bigbluebutton.main.model.users
trace(LOG + "*** handleValidateAuthTokenReply. valid=[ " + tokenValid + "] **** \n");
dispatcher.dispatchEvent(new InvalidAuthTokenEvent());
}
if (reconnecting) {
onReconnect();
reconnecting = false;
}
}
private function onReconnect():void {
if (authenticated) {
onReconnectSuccess();
} else {
onReconnectFailed();
}
}
private function onReconnectSuccess():void {
dispatcher.dispatchEvent(new ClientStatusEvent(ClientStatusEvent.SUCCESS_MESSAGE_EVENT,
"Connection reestablished",
"Main connection has been reestablished successfully"));
}
private function onReconnectFailed():void {
dispatcher.dispatchEvent(new ClientStatusEvent(ClientStatusEvent.FAIL_MESSAGE_EVENT,
"Connection failed",
"It was not possible to reestablish the main connection"));
}
private function sendConnectionSuccessEvent(userid:String):void{
@ -367,8 +398,20 @@ package org.bigbluebutton.main.model.users
logData.reason = reason;
logData.user = UsersUtil.getUserData();
JSLog.warn("User disconnected from BBB App.", logData);
var e:ConnectionFailedEvent = new ConnectionFailedEvent(reason);
dispatcher.dispatchEvent(e);
if (reconnecting) {
reconnect.onConnectionAttemptFailed();
} else {
dispatcher.dispatchEvent(new ClientStatusEvent(ClientStatusEvent.WARNING_MESSAGE_EVENT,
"Main connection dropped",
"Attempting to reconnect"));
reconnecting = true;
authenticated = false;
reconnect.onDisconnect(connect, _conferenceParameters, tried_tunneling);
}
//var e:ConnectionFailedEvent = new ConnectionFailedEvent(reason);
//dispatcher.dispatchEvent(e);
}
}
@ -377,15 +420,6 @@ package org.bigbluebutton.main.model.users
dispatcher.dispatchEvent(e);
}
private function attemptReconnect(backoff:Number):void{
var retryTimer:Timer = new Timer(backoff, 1);
retryTimer.addEventListener(TimerEvent.TIMER, function():void{
connect(_conferenceParameters, tried_tunneling);
});
retryTimer.start();
if (this.backoff < 16000) this.backoff = backoff *2;
}
public function onBWCheck(... rest):Number {
return 0;
}

View File

@ -21,6 +21,7 @@ package org.bigbluebutton.modules.deskshare.services.red5
{
import com.asfusion.mate.events.Dispatcher;
import flash.events.AsyncErrorEvent;
import flash.events.EventDispatcher;
import flash.events.NetStatusEvent;
import flash.events.SecurityErrorEvent;
@ -32,9 +33,12 @@ package org.bigbluebutton.modules.deskshare.services.red5
import flash.utils.Timer;
import mx.events.MetadataEvent;
import mx.utils.ObjectUtil;
import org.bigbluebutton.common.LogUtil;
import org.bigbluebutton.core.UsersUtil;
import org.bigbluebutton.main.events.ClientStatusEvent;
import org.bigbluebutton.main.model.users.AutoReconnect;
import org.bigbluebutton.modules.deskshare.events.AppletStartedEvent;
import org.bigbluebutton.modules.deskshare.events.CursorEvent;
import org.bigbluebutton.modules.deskshare.events.ViewStreamEvent;
@ -54,6 +58,9 @@ package org.bigbluebutton.modules.deskshare.services.red5
private var width:Number;
private var height:Number;
private var room:String;
private var reconnect:AutoReconnect = new AutoReconnect();
private var logoutOnUserCommand:Boolean = false;
private var reconnecting:Boolean = false;
private var dispatcher:Dispatcher = new Dispatcher();
@ -92,6 +99,8 @@ package org.bigbluebutton.modules.deskshare.services.red5
nc.objectEncoding = ObjectEncoding.AMF0;
nc.client = this;
nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR, debugAsyncErrorHandler);
nc.addEventListener(NetStatusEvent.NET_STATUS, debugNetStatusHandler);
nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
@ -113,11 +122,11 @@ package org.bigbluebutton.modules.deskshare.services.red5
nc.connect(getURI(), UsersUtil.getInternalMeetingID());
if (!retry) {
retryTimer = new Timer(connectionTimeout, 1);
retryTimer.addEventListener(TimerEvent.TIMER_COMPLETE, connectTimeoutHandler);
retryTimer.start();
}
//if (!retry) {
// retryTimer = new Timer(connectionTimeout, 1);
// retryTimer.addEventListener(TimerEvent.TIMER_COMPLETE, connectTimeoutHandler);
// retryTimer.start();
//}
}
private function connectTimeoutHandler(e:TimerEvent):void {
@ -182,6 +191,9 @@ package org.bigbluebutton.modules.deskshare.services.red5
switch(event.info.code){
case "NetConnection.Connect.Failed":
if (reconnecting) {
reconnect.onConnectionAttemptFailed();
}
ce.status = ConnectionEvent.FAILED;
dispatcher.dispatchEvent(ce);
@ -189,6 +201,12 @@ package org.bigbluebutton.modules.deskshare.services.red5
case "NetConnection.Connect.Success":
ce.status = ConnectionEvent.SUCCESS;
if (reconnecting) {
dispatcher.dispatchEvent(new ClientStatusEvent(ClientStatusEvent.SUCCESS_MESSAGE_EVENT,
"Connection reestablished",
"Deskshare connection has been reestablished successfully"));
reconnecting = false;
}
dispatcher.dispatchEvent(ce);
connectionSuccessHandler();
break;
@ -201,7 +219,14 @@ package org.bigbluebutton.modules.deskshare.services.red5
case "NetConnection.Connect.Closed":
trace(LOG + "Deskshare connection closed.");
ce.status = ConnectionEvent.CLOSED;
// dispatcher.dispatchEvent(ce);
stopViewing();
if (!logoutOnUserCommand) {
dispatcher.dispatchEvent(new ClientStatusEvent(ClientStatusEvent.WARNING_MESSAGE_EVENT,
"Deskshare connection dropped",
"Attempting to reconnect"));
reconnecting = true;
reconnect.onDisconnect(connect);
}
break;
case "NetConnection.Connect.InvalidApp":
@ -256,6 +281,7 @@ package org.bigbluebutton.modules.deskshare.services.red5
}
public function disconnect():void{
logoutOnUserCommand = true;
if (nc != null) nc.close();
}
@ -264,11 +290,21 @@ package org.bigbluebutton.modules.deskshare.services.red5
var deskSOName:String = room + "-deskSO";
deskSO = SharedObject.getRemote(deskSOName, uri, false);
deskSO.client = this;
deskSO.addEventListener(AsyncErrorEvent.ASYNC_ERROR, debugAsyncErrorHandler);
deskSO.addEventListener(NetStatusEvent.NET_STATUS, debugNetStatusHandler);
deskSO.connect(nc);
checkIfStreamIsPublishing(room);
}
private function debugNetStatusHandler(e:NetStatusEvent):void {
trace(LOG + "netStatusHandler target=" + e.target + " info=" + ObjectUtil.toString(e.info));
}
private function debugAsyncErrorHandler(e:AsyncErrorEvent):void {
trace(LOG + "asyncErrorHandler target=" + e.target + " text=" + e.text);
}
public function getConnection():NetConnection{
return nc;
}

View File

@ -41,6 +41,7 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
import flash.sampler.NewObjectSample;
import flexlib.mdi.events.MDIWindowEvent;
import mx.core.UIComponent;
import mx.utils.ObjectUtil;
import org.bigbluebutton.common.Images;
import org.bigbluebutton.common.LogUtil;
import org.bigbluebutton.core.managers.UserManager;
@ -72,6 +73,8 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
private static const VIDEO_WIDTH_PADDING:int = 7;
private static const VIDEO_HEIGHT_PADDING:int = 65;
public static const LOG:String = "Deskshare::DesktopViewWindow - ";
// The following code block is to deal with a bug in FLexLib
// with MDI windows not responding well to being maximized
private var savedWindowWidth:Number;
@ -178,10 +181,13 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
}
private function onAsyncError(e:AsyncErrorEvent):void{
trace(LOG + "onAsyncError " + e.toString());
LogUtil.debug("VIdeoWindow::asyncerror " + e.toString());
}
private function onNetStatus(e:NetStatusEvent):void{
trace(LOG + "onNetStatus info=" + e.info.text);
switch(e.info.code){
case "NetStream.Play.Start":
LogUtil.debug("NetStream.Publish.Start for broadcast stream " + stream);

View File

@ -24,12 +24,14 @@ package org.bigbluebutton.modules.videoconf.business
import flash.events.IOErrorEvent;
import flash.events.NetStatusEvent;
import flash.events.SecurityErrorEvent;
import flash.events.TimerEvent;
import flash.media.H264Level;
import flash.media.H264Profile;
import flash.media.H264VideoStreamSettings;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.system.Capabilities;
import flash.utils.Timer;
import mx.collections.ArrayCollection;
@ -37,20 +39,30 @@ package org.bigbluebutton.modules.videoconf.business
import org.bigbluebutton.core.BBB;
import org.bigbluebutton.core.UsersUtil;
import org.bigbluebutton.core.managers.UserManager;
import org.bigbluebutton.main.events.ClientStatusEvent;
import org.bigbluebutton.main.model.users.AutoReconnect;
import org.bigbluebutton.main.model.users.BBBUser;
import org.bigbluebutton.main.model.users.events.StreamStartedEvent;
import org.bigbluebutton.modules.videoconf.events.ConnectedEvent;
import org.bigbluebutton.modules.videoconf.events.StartBroadcastEvent;
import org.bigbluebutton.modules.videoconf.events.StopBroadcastEvent;
import org.bigbluebutton.modules.videoconf.model.VideoConfOptions;
public class VideoProxy
{
public static const LOG:String = "VideoProxy - ";
public var videoOptions:VideoConfOptions;
private var nc:NetConnection;
private var ns:NetStream;
private var _url:String;
private var logoutOnUserCommand:Boolean = false;
private var reconnect:AutoReconnect = new AutoReconnect();
private var reconnecting:Boolean = false;
private var dispatcher:Dispatcher = new Dispatcher();
private function parseOptions():void {
videoOptions = new VideoConfOptions();
@ -82,18 +94,44 @@ package org.bigbluebutton.modules.videoconf.business
}
private function onConnectedToVideoApp():void{
var dispatcher:Dispatcher = new Dispatcher();
dispatcher.dispatchEvent(new ConnectedEvent(ConnectedEvent.VIDEO_CONNECTED));
}
private function onNetStatus(event:NetStatusEvent):void{
trace(LOG + "[" + event.info.code + "] for [" + _url + "]");
switch(event.info.code){
case "NetConnection.Connect.Success":
if (reconnecting) {
dispatcher.dispatchEvent(new ClientStatusEvent(ClientStatusEvent.SUCCESS_MESSAGE_EVENT,
"Connection reestablished",
"Video connection has been reestablished successfully"));
reconnecting = false;
}
ns = new NetStream(nc);
onConnectedToVideoApp();
break;
default:
LogUtil.debug("[" + event.info.code + "] for [" + _url + "]");
case "NetConnection.Connect.Closed":
if (!logoutOnUserCommand) {
if (ns != null) {
ns.attachCamera(null);
ns.close();
ns = null;
}
dispatcher.dispatchEvent(new StopBroadcastEvent());
dispatcher.dispatchEvent(new ClientStatusEvent(ClientStatusEvent.WARNING_MESSAGE_EVENT,
"Video connection dropped",
"Attempting to reconnect"));
reconnecting = true;
reconnect.onDisconnect(connect);
}
break;
case "NetConnection.Connect.Failed":
if (reconnecting) {
reconnect.onConnectionAttemptFailed();
}
break;
}
}
@ -177,6 +215,7 @@ package org.bigbluebutton.modules.videoconf.business
}
public function disconnect():void {
logoutOnUserCommand = true;
trace("VideoProxy:: disconnecting from Video application");
stopBroadcasting();
if (nc != null) nc.close();

View File

@ -297,6 +297,10 @@ package org.bigbluebutton.modules.videoconf.maps
}
private function openViewWindowFor(userID:String):void {
if (!proxy.connection.connected) {
return;
}
trace("VideoEventMapDelegate:: [" + me + "] openViewWindowFor:: Opening VIEW window for [" + userID + "] [" + UsersUtil.getUserName(userID) + "]");
var window:VideoWindow = new VideoWindow();
@ -334,7 +338,7 @@ package org.bigbluebutton.modules.videoconf.maps
}
public function startPublishing(e:StartBroadcastEvent):void{
LogUtil.debug("VideoEventMapDelegate:: [" + me + "] startPublishing:: Publishing stream to: " + proxy.connection.uri + "/" + e.stream);
trace("VideoEventMapDelegate:: [" + me + "] startPublishing:: Publishing stream to: " + proxy.connection.uri + "/" + e.stream);
streamName = e.stream;
proxy.startPublishing(e);

View File

@ -64,6 +64,8 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
import org.bigbluebutton.modules.videoconf.events.CloseAllWindowsEvent;
import org.bigbluebutton.modules.videoconf.model.VideoConfOptions;
public static const LOG:String = "VideoWindow - ";
private var ns:NetStream;
private var globalDispatcher:Dispatcher;
@ -172,8 +174,17 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
}
}
private function onConnectionNetStatus(e:NetStatusEvent):void {
trace(LOG + "onNetStatus code=" + e.info.code);
if (e.info.code == "NetConnection.Connect.Closed") {
close();
}
}
public function startVideo(connection:NetConnection, stream:String):void{
connection.addEventListener(NetStatusEvent.NET_STATUS, onConnectionNetStatus);
ns = new NetStream(connection);
ns.addEventListener( NetStatusEvent.NET_STATUS, onNetStatus );
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onAsyncError);