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. 10
      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

10
static/js/directives/chat.js

@ -545,15 +545,17 @@ define(['underscore', 'text!partials/chat.html', 'text!partials/chatroom.html'], @@ -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 = $("<span>").text(translation._("You are now in room %s ...", room.Name));
subscope.$broadcast("display", null, $("<i>").append(msg));
if (scope.currentRoomName != room.Name) {
var msg = $("<span>").text(translation._("You are now in room %s ...", room.Name));
subscope.$broadcast("display", null, $("<i>").append(msg));
scope.currentRoomName = room.Name;
}
});
scope.$on("room.left", function(event) {

2
static/js/directives/roombar.js

@ -47,7 +47,7 @@ define(['underscore', 'text!partials/roombar.html'], function(_, template) { @@ -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;
});

4
static/js/directives/socialshare.js

@ -46,11 +46,11 @@ define(['jquery', 'text!partials/socialshare.html'], function($, template) { @@ -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;
});

2
static/js/directives/title.js

@ -30,7 +30,7 @@ define([], function() { @@ -30,7 +30,7 @@ define([], function() {
}
};
$scope.$on("room.joined", function(ev, room) {
$scope.$on("room.updated", function(ev, room) {
updateTitle(room.Name);
});

20
static/js/mediastream/api.js

@ -208,6 +208,9 @@ define(['jquery', 'underscore', 'ua-parser'], function($, _, uaparser) { @@ -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) { @@ -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) { @@ -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 = {

16
static/js/services/rooms.js

@ -22,7 +22,7 @@ define([ @@ -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([ @@ -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([ @@ -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([ @@ -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;
}
};

Loading…
Cancel
Save