diff --git a/static/js/directives/chat.js b/static/js/directives/chat.js index 94da384b..72004311 100644 --- a/static/js/directives/chat.js +++ b/static/js/directives/chat.js @@ -20,7 +20,7 @@ */ define(['underscore', 'text!partials/chat.html', 'text!partials/chatroom.html'], function(_, templateChat, templateChatroom) { - return ["$compile", "safeDisplayName", "mediaStream", "safeApply", "desktopNotify", "translation", "playSound", "fileUpload", "randomGen", "buddyData", function($compile, safeDisplayName, mediaStream, safeApply, desktopNotify, translation, playSound, fileUpload, randomGen, buddyData) { + return ["$compile", "safeDisplayName", "mediaStream", "safeApply", "desktopNotify", "translation", "playSound", "fileUpload", "randomGen", "buddyData", "$timeout", function($compile, safeDisplayName, mediaStream, safeApply, desktopNotify, translation, playSound, fileUpload, randomGen, buddyData, $timeout) { var displayName = safeDisplayName; var group_chat_id = ""; @@ -272,7 +272,11 @@ define(['underscore', 'text!partials/chat.html', 'text!partials/chatroom.html'], controller.visibleRooms.push(id); subscope.index = index; subscope.visible = true; - subscope.minimized = false; + if (options.minimized) { + subscope.minimized = true; + } else { + subscope.minimized = false; + } } } if (options.autofocus && subscope.visible) { @@ -309,10 +313,19 @@ define(['underscore', 'text!partials/chat.html', 'text!partials/chatroom.html'], return; } delete controller.rooms[id]; - subscope.$destroy(); + $timeout(function() { + subscope.$destroy(); + }, 0); }; - // Show default room. - scope.showRoom(group_chat_id, {title: translation._("Group chat")}); + + scope.$on("room", function(event, room) { + if (room) { + scope.showRoom(group_chat_id, {title: translation._("Group chat")}, {restore: true, minimized: true}); + } else { + scope.hideRoom(group_chat_id); + } + }); + }; }; diff --git a/static/js/directives/usability.js b/static/js/directives/usability.js index ee251588..930d5bee 100644 --- a/static/js/directives/usability.js +++ b/static/js/directives/usability.js @@ -24,7 +24,7 @@ define(['jquery', 'underscore', 'text!partials/usability.html'], function($, _, return ["mediaStream", function(mediaStream) { - var controller = ['$scope', "mediaStream", "safeApply", "$rootScope", "$timeout", function($scope, mediaStream, safeApply, $rootScope, $timeout) { + var controller = ['$scope', "mediaStream", "safeApply", "$timeout", function($scope, mediaStream, safeApply, $timeout) { $scope.roomdata = {}; @@ -81,7 +81,7 @@ define(['jquery', 'underscore', 'text!partials/usability.html'], function($, _, if ($scope.connect) { console.log("Connecting ..."); ctrl.setInfo("checking"); - setTimeout(function() { + $timeout(function() { if (pending) { safeApply($scope, function() { ctrl.setInfo("usermedia"); @@ -92,14 +92,14 @@ define(['jquery', 'underscore', 'text!partials/usability.html'], function($, _, } }); - $rootScope.$on("roomStatus", function(event, status) { + $scope.$on("room", function(event, room) { //console.log("roomStatus", status); if (complete) { if (initializer !== null) { $timeout.cancel(initializer); initializer = null; } - ctrl.setInfo(status ? "room" : "noroom"); + ctrl.setInfo(room ? "room" : "noroom"); } }); diff --git a/static/js/services/mediastream.js b/static/js/services/mediastream.js index 930ef2a0..ce69dc5a 100644 --- a/static/js/services/mediastream.js +++ b/static/js/services/mediastream.js @@ -70,6 +70,8 @@ define([ var ready = false; $rootScope.version = version; + $rootScope.roomid = null; + $rootScope.roomstatus = false; connector.e.on("closed error", _.bind(function(event, options) { var opts = $.extend({}, options); @@ -122,6 +124,12 @@ define([ $rootScope.roomid = room; }); + $rootScope.$on("roomStatus", function(event, status) { + $rootScope.roomstatus = status ? true : false; + var room = status ? $rootScope.roomid : null; + $rootScope.$broadcast("room", room); + }); + visibility.afterPrerendering(function() { // Hide loader when we are visible.