From 910dd71b816393bcd21febf33a025ff77d951d86 Mon Sep 17 00:00:00 2001 From: Lance Cooper Date: Mon, 20 Oct 2014 17:56:54 +0200 Subject: [PATCH] Use room document from Welcome rather than synthesizing a response. --- doc/CHANNELING-API.txt | 3 +- .../channelling_api_test.go | 4 ++ static/js/directives/buddylist.js | 2 +- static/js/directives/chat.js | 4 +- static/js/directives/page.js | 2 +- static/js/directives/roombar.js | 2 +- static/js/directives/title.js | 2 +- static/js/mediastream/api.js | 3 +- static/js/services/rooms.js | 60 +++++++++---------- 9 files changed, 42 insertions(+), 40 deletions(-) diff --git a/doc/CHANNELING-API.txt b/doc/CHANNELING-API.txt index 6eb7f96f..e170b865 100644 --- a/doc/CHANNELING-API.txt +++ b/doc/CHANNELING-API.txt @@ -164,7 +164,8 @@ Special purpose documents for channling Hello document is to be send by the client after connection was established. If an Iid is provided, a Welcome document will be returned if joining the room with the given Id succeeds. Otherwise an Error document with one of the - error codes listed below will be returned. + error codes listed below will be returned. Note that any previous room will + have been left regardless of whether the response is successful. Keys under Hello: diff --git a/src/app/spreed-webrtc-server/channelling_api_test.go b/src/app/spreed-webrtc-server/channelling_api_test.go index 0fe0e507..9594aae7 100644 --- a/src/app/spreed-webrtc-server/channelling_api_test.go +++ b/src/app/spreed-webrtc-server/channelling_api_test.go @@ -189,4 +189,8 @@ func Test_ChannellingAPI_OnIncoming_HelloMessageWithAnIid_RespondsWithAnErrorIfT if err.Type != "Error" { t.Error("Message did not have the correct type") } + + if code := "default_room_disabled"; err.Code != code { + t.Errorf("Expected error code to be %v, but was %v", code, err.Code) + } } diff --git a/static/js/directives/buddylist.js b/static/js/directives/buddylist.js index 1c73eb85..12102743 100644 --- a/static/js/directives/buddylist.js +++ b/static/js/directives/buddylist.js @@ -45,7 +45,7 @@ define(['underscore', 'text!partials/buddylist.html'], function(_, template) { updateBuddyListVisibility(); }); - $scope.$on("room.joined", function(ev, room) { + $scope.$on("room.joined", function(ev) { inRoom = true; updateBuddyListVisibility(); }); diff --git a/static/js/directives/chat.js b/static/js/directives/chat.js index cae72dee..cf91d08c 100644 --- a/static/js/directives/chat.js +++ b/static/js/directives/chat.js @@ -551,8 +551,8 @@ define(['underscore', 'text!partials/chat.html', 'text!partials/chatroom.html'], noenable: true, noactivate: true }); - scope.currentRoomName = room.name; - var msg = $("").text(translation._("You are now in room %s ...", room.name)); + scope.currentRoomName = room.Name; + var msg = $("").text(translation._("You are now in room %s ...", room.Name)); subscope.$broadcast("display", null, $("").append(msg)); }); diff --git a/static/js/directives/page.js b/static/js/directives/page.js index e24261b5..8967021a 100644 --- a/static/js/directives/page.js +++ b/static/js/directives/page.js @@ -26,7 +26,7 @@ define(['text!partials/page.html', 'text!partials/page/welcome.html'], function( var link = function($scope, $element, attrs) { $scope.randomRoom = rooms.randomRoom; - $scope.$on("room.joined", function(event, name) { + $scope.$on("room.joined", function(event) { $scope.page = null; }); diff --git a/static/js/directives/roombar.js b/static/js/directives/roombar.js index 37bc4f0b..29041fb5 100644 --- a/static/js/directives/roombar.js +++ b/static/js/directives/roombar.js @@ -48,7 +48,7 @@ define(['underscore', 'text!partials/roombar.html'], function(_, template) { }; $scope.$on("room.joined", function(ev, room) { - $scope.currentRoomName = $scope.newRoomName = room.name; + $scope.currentRoomName = $scope.newRoomName = room.Name; }); $scope.$on("room.left", function(ev) { diff --git a/static/js/directives/title.js b/static/js/directives/title.js index e05b7f17..be72f29a 100644 --- a/static/js/directives/title.js +++ b/static/js/directives/title.js @@ -31,7 +31,7 @@ define([], function() { }; $scope.$on("room.joined", function(ev, room) { - updateTitle(room.name); + updateTitle(room.Name); }); $scope.$on("room.left", function(ev) { diff --git a/static/js/mediastream/api.js b/static/js/mediastream/api.js index 84284144..b43cde35 100644 --- a/static/js/mediastream/api.js +++ b/static/js/mediastream/api.js @@ -235,9 +235,10 @@ define(['jquery', 'underscore', 'ua-parser'], function($, _, uaparser) { var that = this; var onResponse = function(event, type, data) { + console.log("Got response to Hello", data); if (type === "Welcome") { if (success) { - success({name: name}); + success(data.Room); } that.e.triggerHandler("received.users", [data.Users]); } else { diff --git a/static/js/services/rooms.js b/static/js/services/rooms.js index 4ae837fc..84f68203 100644 --- a/static/js/services/rooms.js +++ b/static/js/services/rooms.js @@ -29,6 +29,7 @@ define([ var joinFailed = function(error) { console.log("error", error, "while joining room"); + setCurrentRoom(null); rooms.randomRoom(); }; @@ -38,7 +39,7 @@ define([ return; } - if (!connector.connected || requestedRoomName !== currentRoom) { + if (!connector.connected || !currentRoom || requestedRoomName !== currentRoom.Name) { if (requestedRoomName !== "" || globalContext.Cfg.DefaultRoomEnabled) { console.log("Joining room", requestedRoomName); requestedRoomName = requestedRoomName ? requestedRoomName : ""; @@ -51,25 +52,20 @@ define([ } }; - // Cache events, to avoid ui flicker during quick room changes. - var nextRoom = null; var setCurrentRoom = function(room) { - nextRoom = room; - - $timeout(function() { - if (nextRoom !== currentRoom) { - var priorRoom = currentRoom; - currentRoom = nextRoom; - if (priorRoom) { - console.log("Left room", priorRoom.name); - $rootScope.$broadcast("room.left", priorRoom); - } - if (currentRoom) { - console.log("Joined room", currentRoom.name); - $rootScope.$broadcast("room.joined", currentRoom); - } - } - }, 100); + if (room === currentRoom) { + return; + } + var priorRoom = currentRoom; + currentRoom = room; + if (priorRoom) { + console.log("Left room", priorRoom.Name); + $rootScope.$broadcast("room.left", priorRoom); + } + if (currentRoom) { + console.log("Joined room", currentRoom.Name); + $rootScope.$broadcast("room.joined", currentRoom); + } }; connector.e.on("close error", function() { @@ -99,7 +95,7 @@ define([ var rooms = { inDefaultRoom: function() { - return (currentRoom !== null ? currentRoom.name : requestedRoomName) === ""; + return (currentRoom !== null ? currentRoom.Name : requestedRoomName) === ""; }, randomRoom: function() { $http({ @@ -110,17 +106,17 @@ define([ 'Content-Type': 'application/x-www-form-urlencoded' } }). - success(function(data, status) { - console.info("Retrieved random room data", data); - if (!data.name) { - data.name = ""; - } - $rootScope.$broadcast('room.random', {name: data.name}); - }). - error(function() { - console.error("Failed to retrieve random room data."); - $rootScope.$broadcast('room.random', {}); - }); + success(function(data, status) { + console.info("Retrieved random room data", data); + if (!data.name) { + data.name = ""; + } + $rootScope.$broadcast('room.random', {name: data.name}); + }). + error(function() { + console.error("Failed to retrieve random room data."); + $rootScope.$broadcast('room.random', {}); + }); }, joinByName: function(name, replace) { name = $window.encodeURIComponent(name); @@ -137,7 +133,7 @@ define([ return name; }, link: function(room) { - var name = room ? room.name : null; + var name = room ? room.Name : null; if (!name) { name = ""; }