diff --git a/static/js/directives/chat.js b/static/js/directives/chat.js index cf91d08c..dcbf0a06 100644 --- a/static/js/directives/chat.js +++ b/static/js/directives/chat.js @@ -545,15 +545,17 @@ define(['underscore', 'text!partials/chat.html', 'text!partials/chatroom.html'], scope.layout.chatMaximized = false; }); - scope.$on("room.joined", function(event, room) { + scope.$on("room.updated", function(event, room) { var subscope = scope.showGroupRoom(null, { restore: true, noenable: true, noactivate: true }); - scope.currentRoomName = room.Name; - var msg = $("").text(translation._("You are now in room %s ...", room.Name)); - subscope.$broadcast("display", null, $("").append(msg)); + if (scope.currentRoomName != room.Name) { + var msg = $("").text(translation._("You are now in room %s ...", room.Name)); + subscope.$broadcast("display", null, $("").append(msg)); + scope.currentRoomName = room.Name; + } }); scope.$on("room.left", function(event) { diff --git a/static/js/directives/roombar.js b/static/js/directives/roombar.js index 29041fb5..872375cf 100644 --- a/static/js/directives/roombar.js +++ b/static/js/directives/roombar.js @@ -47,7 +47,7 @@ define(['underscore', 'text!partials/roombar.html'], function(_, template) { $scope.save(); }; - $scope.$on("room.joined", function(ev, room) { + $scope.$on("room.updated", function(ev, room) { $scope.currentRoomName = $scope.newRoomName = room.Name; }); diff --git a/static/js/directives/socialshare.js b/static/js/directives/socialshare.js index 99765570..e38a71b3 100644 --- a/static/js/directives/socialshare.js +++ b/static/js/directives/socialshare.js @@ -46,11 +46,11 @@ define(['jquery', 'text!partials/socialshare.html'], function($, template) { template: template, replace: true, link: function($scope, $element, $attr) { - $scope.$on("room.joined", function(ev, room) { + $scope.$on("room.updated", function(ev, room) { $scope.roomlink = rooms.link(room); }); - $scope.$on("room.left", function(ev, name) { + $scope.$on("room.left", function(ev) { $scope.roomlink = null; }); diff --git a/static/js/directives/title.js b/static/js/directives/title.js index be72f29a..c35ecc69 100644 --- a/static/js/directives/title.js +++ b/static/js/directives/title.js @@ -30,7 +30,7 @@ define([], function() { } }; - $scope.$on("room.joined", function(ev, room) { + $scope.$on("room.updated", function(ev, room) { updateTitle(room.Name); }); diff --git a/static/js/mediastream/api.js b/static/js/mediastream/api.js index b43cde35..5e6b3deb 100644 --- a/static/js/mediastream/api.js +++ b/static/js/mediastream/api.js @@ -208,6 +208,9 @@ define(['jquery', 'underscore', 'ua-parser'], function($, _, uaparser) { // Do nothing. //console.log("Alive response received."); break; + case "Room": + this.e.triggerHandler("received.room", [data]); + break; default: console.log("Unhandled type received:", dataType, data); break; @@ -235,11 +238,11 @@ 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(data.Room); } + that.e.triggerHandler("received.room", [data.Room]); that.e.triggerHandler("received.users", [data.Users]); } else { if (fault) { @@ -287,6 +290,21 @@ define(['jquery', 'underscore', 'ua-parser'], function($, _, uaparser) { } + Api.prototype.requestRoomUpdate = function(room, success, fault) { + var onResponse = function(event, type, data) { + if (type === "Room") { + if (success) { + success(data); + } + } else { + if (fault) { + fault(data); + } + } + }; + this.request("Room", room, onResponse, true); + }; + Api.prototype.requestUsers = function() { var data = { diff --git a/static/js/services/rooms.js b/static/js/services/rooms.js index 84f68203..a5557d73 100644 --- a/static/js/services/rooms.js +++ b/static/js/services/rooms.js @@ -22,7 +22,7 @@ define([ 'jquery' ], function($) { - return ["$window", "$location", "$timeout", "$route", "$rootScope", "$http", "globalContext", "safeApply", "connector", "api", "restURL", function($window, $location, $timeout, $route, $rootScope, $http, globalContext, safeApply, connector, api, restURL) { + return ["$window", "$location", "$timeout", "$q", "$route", "$rootScope", "$http", "globalContext", "safeApply", "connector", "api", "restURL", function($window, $location, $timeout, $q, $route, $rootScope, $http, globalContext, safeApply, connector, api, restURL) { var url = restURL.api("rooms"); var requestedRoomName = ""; var currentRoom = null; @@ -60,11 +60,11 @@ define([ currentRoom = room; if (priorRoom) { console.log("Left room", priorRoom.Name); - $rootScope.$broadcast("room.left", priorRoom); + $rootScope.$broadcast("room.left", priorRoom.Name); } if (currentRoom) { console.log("Joined room", currentRoom.Name); - $rootScope.$broadcast("room.joined", currentRoom); + $rootScope.$broadcast("room.joined", currentRoom.Name); } }; @@ -76,6 +76,11 @@ define([ joinRequestedRoom(); }); + api.e.on("received.room", function(event, room) { + currentRoom = room; + $rootScope.$broadcast("room.updated", currentRoom); + }); + $rootScope.$on("$locationChangeSuccess", function(event) { var roomName; if ($route.current) { @@ -138,6 +143,11 @@ define([ name = ""; } return restURL.room(name); + }, + update: function(room) { + var response = $q.defer(); + api.requestRoomUpdate(room, response.resolve, response.reject); + return response.promise; } };