clean active_meetings.js

This commit is contained in:
Josh 2017-06-08 10:43:06 -04:00
parent 42f0c14b49
commit 31f0e0a3e9
1 changed files with 50 additions and 31 deletions

View File

@ -1,35 +1,24 @@
// Handles action cable events from bbb-webhooks and initial population of active meetings. // BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
//
// Copyright (c) 2016 BigBlueButton Inc. and by respective authors (see below).
//
// This program is free software; you can redistribute it and/or modify it under the
// terms of the GNU Lesser General Public License as published by the Free Software
// Foundation; either version 3.0 of the License, or (at your option) any later
// version.
//
// BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
// PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along
// with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
// Handles live updating and initial population of the previous meetings and active meetings lists on
// the landing page using custom Actioncable events.
MEETINGS = {} MEETINGS = {}
LOADING_DELAY = 1250 // milliseconds.
// Only need to register for logged in users.
if($('body').data('current-user')){
App.messages = App.cable.subscriptions.create('RefreshMeetingsChannel', {
received: function(data) {
console.log('Recieved ' + data['method'] + ' action for ' + data['meeting'] + '.')
if(isPreviouslyJoined(data['meeting'])){
if(data['method'] == 'create'){
// Create an empty meeting.
MEETINGS[data['meeting']] = {'name': data['meeting'],
'participants': 0,
'moderators': 0}
renderActiveMeeting(MEETINGS[data['meeting']])
updatePreviousMeetings();
} else if(data['method'] == 'destroy'){
removeActiveMeeting(MEETINGS[data['meeting']])
PreviousMeetings.append([data['meeting']])
delete MEETINGS[data['meeting']]
} else if(data['method'] == 'join'){
handleUser(data, 1)
updateMeetingText(MEETINGS[data['meeting']])
} else if(data['method'] == 'leave'){
handleUser(data, -1)
}
}
}
});
}
updatePreviousMeetings = function(){ updatePreviousMeetings = function(){
$("ul.previously-joined li").each(function(idx, li) { $("ul.previously-joined li").each(function(idx, li) {
@ -128,4 +117,34 @@ joinMeeting = function(meeting_name){
} }
} }
if($('body').data('current-user')){ console.log('Populating active meetings.'); setTimeout(initialPopulate, 1250); } // Only need to register for logged in users.
if($('body').data('current-user')){
App.messages = App.cable.subscriptions.create('RefreshMeetingsChannel', {
received: function(data) {
console.log('Recieved ' + data['method'] + ' action for ' + data['meeting'] + '.')
if(isPreviouslyJoined(data['meeting'])){
if(data['method'] == 'create'){
// Create an empty meeting.
MEETINGS[data['meeting']] = {'name': data['meeting'],
'participants': 0,
'moderators': 0}
renderActiveMeeting(MEETINGS[data['meeting']])
updatePreviousMeetings();
} else if(data['method'] == 'destroy'){
removeActiveMeeting(MEETINGS[data['meeting']])
PreviousMeetings.append([data['meeting']])
delete MEETINGS[data['meeting']]
} else if(data['method'] == 'join'){
handleUser(data, 1)
updateMeetingText(MEETINGS[data['meeting']])
} else if(data['method'] == 'leave'){
handleUser(data, -1)
}
}
}
});
console.log('Populating active meetings.');
setTimeout(initialPopulate, LOADING_DELAY);
}