From c28101a73046d6e6610fb99e418af36143472d24 Mon Sep 17 00:00:00 2001 From: Simon Eisenmann Date: Fri, 4 Apr 2014 15:11:24 +0200 Subject: [PATCH] No longer disconnect ongoing calls on websocket disconnnect or error. Instead resurrect state when id still is the same on successfull reconnect. --- .../js/controllers/mediastreamcontroller.js | 28 ++++++++++++++++++- static/js/services/mediastream.js | 8 ------ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/static/js/controllers/mediastreamcontroller.js b/static/js/controllers/mediastreamcontroller.js index 0382c801..10e67cea 100644 --- a/static/js/controllers/mediastreamcontroller.js +++ b/static/js/controllers/mediastreamcontroller.js @@ -154,8 +154,9 @@ define(['underscore', 'bigscreen', 'moment', 'webrtc.adapter'], function(_, BigS } }; - // Cache. + // Data voids. var cache = {}; + var resurrect = null; $scope.update = function(user, noRefresh) { $scope.master = angular.copy(user); @@ -171,6 +172,10 @@ define(['underscore', 'bigscreen', 'moment', 'webrtc.adapter'], function(_, BigS $scope.$emit("status", status); }; + $scope.getStatus = function() { + return $scope.status; + }; + $scope.updateStatus = (function() { return function() { // This is the user status. @@ -387,9 +392,22 @@ define(['underscore', 'bigscreen', 'moment', 'webrtc.adapter'], function(_, BigS mediaStream.api.sendSelf(); }, data.Turn.ttl / 100 * 90 * 1000); } + // Support resurrection shrine. + if (resurrect) { + var resurrection = resurrect; + resurrect = null; + $timeout(function() { + if (resurrection.id === $scope.id) { + console.log("Using resurrection shrine", resurrection); + // Valid resurrection. + $scope.setStatus(resurrection.status); + } + }, 0); + } }); mediaStream.webrtc.e.on("peercall", function(event, peercall) { + // Kill timeout. $timeout.cancel(pickupTimeout); pickupTimeout = null; @@ -466,6 +484,14 @@ define(['underscore', 'bigscreen', 'moment', 'webrtc.adapter'], function(_, BigS var reconnect = function() { if (connected && autoreconnect) { + if (resurrect == null) { + // Storage data at the resurrection shrine. + resurrect = { + status: $scope.getStatus(), + id: $scope.id + } + console.log("Stored data at the resurrection shrine", resurrect); + } reconnecting = false; _.delay(function() { if (autoreconnect && !reconnecting) { diff --git a/static/js/services/mediastream.js b/static/js/services/mediastream.js index dba3cc43..33e2dfb7 100644 --- a/static/js/services/mediastream.js +++ b/static/js/services/mediastream.js @@ -81,14 +81,6 @@ define([ $rootScope.roomlink = null; $rootScope.roomstatus = false; - connector.e.on("closed error", _.bind(function(event, options) { - var opts = $.extend({}, options); - if (!opts.soft) { - // Do not hang up when this is a soft event. - webrtc.doHangup(); - } - }, this)); - var connect = function() { if (ready && cont) { // Inject connector function into scope, so that controllers can pick it up.