Merge pull request #255 from nextcloud/event-source-join-room

Restart event source when joining a room
This commit is contained in:
Joas Schilling 2017-03-14 11:16:32 +01:00 коммит произвёл GitHub
Родитель 3ae5439e41 7aa694e399
Коммит c29495af9d
1 изменённых файлов: 8 добавлений и 4 удалений

Просмотреть файл

@ -2,6 +2,7 @@
/* global SimpleWebRTC, OC, OCA: false */ /* global SimpleWebRTC, OC, OCA: false */
var webrtc; var webrtc;
var spreedEventSource;
var spreedMappingTable = []; var spreedMappingTable = [];
(function(OCA, OC) { (function(OCA, OC) {
@ -14,14 +15,15 @@ var spreedMappingTable = [];
*/ */
function openEventSource() { function openEventSource() {
// Connect to the messages endpoint and pull for new messages // Connect to the messages endpoint and pull for new messages
var messageEventSource = new OC.EventSource(OC.generateUrl('/apps/spreed/messages')); spreedEventSource = new OC.EventSource(OC.generateUrl('/apps/spreed/messages'));
var previousUsersInRoom = []; var previousUsersInRoom = [];
Array.prototype.diff = function(a) { Array.prototype.diff = function(a) {
return this.filter(function(i) { return this.filter(function(i) {
return a.indexOf(i) < 0; return a.indexOf(i) < 0;
}); });
}; };
messageEventSource.listen('usersInRoom', function(users) {
spreedEventSource.listen('usersInRoom', function(users) {
var currentUsersInRoom = []; var currentUsersInRoom = [];
users.forEach(function(user) { users.forEach(function(user) {
currentUsersInRoom.push(user['sessionId']); currentUsersInRoom.push(user['sessionId']);
@ -48,7 +50,7 @@ var spreedMappingTable = [];
previousUsersInRoom = currentUsersInRoom; previousUsersInRoom = currentUsersInRoom;
}); });
messageEventSource.listen('message', function(message) { spreedEventSource.listen('message', function(message) {
message = JSON.parse(message); message = JSON.parse(message);
var peers = self.webrtc.getPeers(message.from, message.roomType); var peers = self.webrtc.getPeers(message.from, message.roomType);
var peer; var peer;
@ -85,7 +87,7 @@ var spreedMappingTable = [];
}); });
} }
}); });
messageEventSource.listen('__internal__', function(data) { spreedEventSource.listen('__internal__', function(data) {
if (data === 'close') { if (data === 'close') {
console.log('signaling connection closed - will reopen'); console.log('signaling connection closed - will reopen');
setTimeout(openEventSource, 0); setTimeout(openEventSource, 0);
@ -320,6 +322,8 @@ var spreedMappingTable = [];
OCA.SpreedMe.webrtc.on('joinedRoom', function(name) { OCA.SpreedMe.webrtc.on('joinedRoom', function(name) {
$('#app-content').removeClass('icon-loading'); $('#app-content').removeClass('icon-loading');
$('.videoView').removeClass('hidden'); $('.videoView').removeClass('hidden');
spreedEventSource.close();
openEventSource();
OCA.SpreedMe.app.syncAndSetActiveRoom(name); OCA.SpreedMe.app.syncAndSetActiveRoom(name);
}); });