Browse Source

Unify room synchronization for users and guests

The main page gives a user access to more than one room, while the
public page only gives a guest access to a single room; guests can not
even query the list of rooms in the backend, so the app sets a room
collection only for users, but not guests. Before, the room model only
supported being part of a room collection, so there was no room model to
be used by the UI for guests. Now, the room model was extended to
support both being part of a room collection and being a standalone
model, and now the signaling can synchronize a single room model too
instead of only a room collection, so the UI can rely on the room model
set as active to be up to date for both users and guests.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
pull/458/head
Daniel Calviño Sánchez 8 years ago
parent
commit
d5a2aed83c
  1. 44
      js/app.js
  2. 17
      js/models/room.js
  3. 25
      js/signaling.js

44
js/app.js

@ -387,38 +387,30 @@
},
syncAndSetActiveRoom: function(token) {
var self = this;
if (oc_current_user) {
this.syncRooms()
.then(function() {
this.syncRooms()
.then(function() {
if (oc_current_user) {
roomChannel.trigger('active', token);
// Disable video when entering a room with more than 5 participants.
self._rooms.forEach(function(room) {
if (room.get('token') === token) {
self.activeRoom = room;
if (Object.keys(room.get('participants')).length > 5) {
self.disableVideo();
}
self.setPageTitle(room.get('displayName'));
}
});
});
} else {
$.ajax({
url: OC.linkToOCS('apps/spreed/api/v1/room', 2) + token,
type: 'GET',
beforeSend: function (request) {
request.setRequestHeader('Accept', 'application/json');
},
success: function(result) {
var data = result.ocs.data;
self.setRoomMessageForGuest(data.participants);
self.setPageTitle(data.displayName);
if (Object.keys(data.participants).length > 5) {
self.disableVideo();
}
} else {
// The public page supports only a single room, so the
// active room is already the room for the given token.
self.setRoomMessageForGuest(self.activeRoom.get('participants'));
}
// Disable video when entering a room with more than 5 participants.
if (Object.keys(self.activeRoom.get('participants')).length > 5) {
self.disableVideo();
}
self.setPageTitle(self.activeRoom.get('displayName'));
});
}
},
setPageTitle: function(title){
if (title) {
@ -573,6 +565,10 @@
});
this._showParticipantList();
} else {
// The token is always defined in the public page.
this.activeRoom = new OCA.SpreedMe.Models.Room({ token: token });
this.signaling.setRoom(this.activeRoom);
}
this.initAudioVideoSettings(configuration);

17
js/models/room.js

@ -26,6 +26,13 @@
OCA.SpreedMe = OCA.SpreedMe || {};
OCA.SpreedMe.Models = OCA.SpreedMe.Models || {};
/**
* Model for rooms.
*
* Room can be used as the model of a RoomCollection or as a standalone
* model. When used as a standalone model the token must be provided in the
* constructor options.
*/
var Room = Backbone.Model.extend({
defaults: {
name: '',
@ -33,6 +40,16 @@
count: 0,
active: false,
lastPing: 0
},
url: function() {
return OC.linkToOCS('apps/spreed/api/v1/room', 2) + this.get('token');
},
parse: function(result) {
// When the model is created by a RoomCollection "Room.parse" will
// be called with the result already parsed by
// "RoomCollection.parse", so the given result is already the
// attributes hash to be set on the model.
return (result.ocs === undefined)? result : result.ocs.data;
}
});

25
js/signaling.js

@ -75,6 +75,20 @@
return this.syncRooms();
};
/**
* Sets a single room to be synced.
*
* If there is a RoomCollection set the synchronization will be performed on
* the RoomCollection instead and the given room will be ignored; setting a
* single room is intended to be used only on public pages.
*
* @param OCA.SpreedMe.Models.Room room the room to sync.
*/
SignalingBase.prototype.setRoom = function(room) {
this.room = room;
return this.syncRooms();
};
SignalingBase.prototype.syncRooms = function() {
var defer = $.Deferred();
if (this.roomCollection && oc_current_user) {
@ -83,6 +97,12 @@
defer.resolve(data);
}
});
} else if (this.room) {
this.room.fetch({
success: function(data) {
defer.resolve(data);
}
});
} else {
defer.resolve([]);
}
@ -263,6 +283,11 @@
return SignalingBase.prototype.setRoomCollection.apply(this, arguments);
};
InternalSignaling.prototype.setRoom = function(/*room*/) {
this._pollForRoomChanges();
return SignalingBase.prototype.setRoom.apply(this, arguments);
};
InternalSignaling.prototype._pollForRoomChanges = function() {
if (this.roomPoller) {
window.clearInterval(this.roomPoller);

Loading…
Cancel
Save