Browse Source

Support handling room updates in web client.

pull/112/head
Lance Cooper 11 years ago committed by Simon Eisenmann
parent
commit
5e14b3b5d2
  1. 6
      static/js/directives/chat.js
  2. 2
      static/js/directives/roombar.js
  3. 4
      static/js/directives/socialshare.js
  4. 2
      static/js/directives/title.js
  5. 20
      static/js/mediastream/api.js
  6. 16
      static/js/services/rooms.js

6
static/js/directives/chat.js

@ -545,15 +545,17 @@ define(['underscore', 'text!partials/chat.html', 'text!partials/chatroom.html'],
scope.layout.chatMaximized = false; scope.layout.chatMaximized = false;
}); });
scope.$on("room.joined", function(event, room) { scope.$on("room.updated", function(event, room) {
var subscope = scope.showGroupRoom(null, { var subscope = scope.showGroupRoom(null, {
restore: true, restore: true,
noenable: true, noenable: true,
noactivate: true noactivate: true
}); });
scope.currentRoomName = room.Name; if (scope.currentRoomName != room.Name) {
var msg = $("<span>").text(translation._("You are now in room %s ...", room.Name)); var msg = $("<span>").text(translation._("You are now in room %s ...", room.Name));
subscope.$broadcast("display", null, $("<i>").append(msg)); subscope.$broadcast("display", null, $("<i>").append(msg));
scope.currentRoomName = room.Name;
}
}); });
scope.$on("room.left", function(event) { scope.$on("room.left", function(event) {

2
static/js/directives/roombar.js

@ -47,7 +47,7 @@ define(['underscore', 'text!partials/roombar.html'], function(_, template) {
$scope.save(); $scope.save();
}; };
$scope.$on("room.joined", function(ev, room) { $scope.$on("room.updated", function(ev, room) {
$scope.currentRoomName = $scope.newRoomName = room.Name; $scope.currentRoomName = $scope.newRoomName = room.Name;
}); });

4
static/js/directives/socialshare.js

@ -46,11 +46,11 @@ define(['jquery', 'text!partials/socialshare.html'], function($, template) {
template: template, template: template,
replace: true, replace: true,
link: function($scope, $element, $attr) { 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.roomlink = rooms.link(room);
}); });
$scope.$on("room.left", function(ev, name) { $scope.$on("room.left", function(ev) {
$scope.roomlink = null; $scope.roomlink = null;
}); });

2
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); updateTitle(room.Name);
}); });

20
static/js/mediastream/api.js

@ -208,6 +208,9 @@ define(['jquery', 'underscore', 'ua-parser'], function($, _, uaparser) {
// Do nothing. // Do nothing.
//console.log("Alive response received."); //console.log("Alive response received.");
break; break;
case "Room":
this.e.triggerHandler("received.room", [data]);
break;
default: default:
console.log("Unhandled type received:", dataType, data); console.log("Unhandled type received:", dataType, data);
break; break;
@ -235,11 +238,11 @@ define(['jquery', 'underscore', 'ua-parser'], function($, _, uaparser) {
var that = this; var that = this;
var onResponse = function(event, type, data) { var onResponse = function(event, type, data) {
console.log("Got response to Hello", data);
if (type === "Welcome") { if (type === "Welcome") {
if (success) { if (success) {
success(data.Room); success(data.Room);
} }
that.e.triggerHandler("received.room", [data.Room]);
that.e.triggerHandler("received.users", [data.Users]); that.e.triggerHandler("received.users", [data.Users]);
} else { } else {
if (fault) { 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() { Api.prototype.requestUsers = function() {
var data = { var data = {

16
static/js/services/rooms.js

@ -22,7 +22,7 @@ define([
'jquery' 'jquery'
], function($) { ], 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 url = restURL.api("rooms");
var requestedRoomName = ""; var requestedRoomName = "";
var currentRoom = null; var currentRoom = null;
@ -60,11 +60,11 @@ define([
currentRoom = room; currentRoom = room;
if (priorRoom) { if (priorRoom) {
console.log("Left room", priorRoom.Name); console.log("Left room", priorRoom.Name);
$rootScope.$broadcast("room.left", priorRoom); $rootScope.$broadcast("room.left", priorRoom.Name);
} }
if (currentRoom) { if (currentRoom) {
console.log("Joined room", currentRoom.Name); console.log("Joined room", currentRoom.Name);
$rootScope.$broadcast("room.joined", currentRoom); $rootScope.$broadcast("room.joined", currentRoom.Name);
} }
}; };
@ -76,6 +76,11 @@ define([
joinRequestedRoom(); joinRequestedRoom();
}); });
api.e.on("received.room", function(event, room) {
currentRoom = room;
$rootScope.$broadcast("room.updated", currentRoom);
});
$rootScope.$on("$locationChangeSuccess", function(event) { $rootScope.$on("$locationChangeSuccess", function(event) {
var roomName; var roomName;
if ($route.current) { if ($route.current) {
@ -138,6 +143,11 @@ define([
name = ""; name = "";
} }
return restURL.room(name); return restURL.room(name);
},
update: function(room) {
var response = $q.defer();
api.requestRoomUpdate(room, response.resolve, response.reject);
return response.promise;
} }
}; };

Loading…
Cancel
Save