clean active_meetings.js and landing.js

This commit is contained in:
Josh 2017-07-14 13:21:02 -04:00
parent 5f2a561922
commit 42bf2b1e54
3 changed files with 42 additions and 34 deletions

View File

@ -21,15 +21,17 @@ var MEETINGS = {}
var WAITING = {} var WAITING = {}
var LOADING_DELAY = 1750 // milliseconds. var LOADING_DELAY = 1750 // milliseconds.
// Updates the previous meetings section.
var updatePreviousMeetings = function(){ var updatePreviousMeetings = function(){
$("ul.previously-joined li").each(function(idx, li) { $("ul.previously-joined li").each(function(idx, li) {
previous_meeting = $(li); var previous_meeting = $(li);
if(Object.keys(MEETINGS).indexOf(previous_meeting.text()) > -1){ if(Object.keys(MEETINGS).indexOf(previous_meeting.text()) > -1){
previous_meeting.remove() previous_meeting.remove()
} }
}); });
} }
// Adds a user to a meeting.
var addUser = function(data){ var addUser = function(data){
if(data['role'] == 'MODERATOR'){ if(data['role'] == 'MODERATOR'){
MEETINGS[data['meeting']]['moderators'].push(data['user']) MEETINGS[data['meeting']]['moderators'].push(data['user'])
@ -39,6 +41,7 @@ var addUser = function(data){
updateMeetingText(MEETINGS[data['meeting']]) updateMeetingText(MEETINGS[data['meeting']])
} }
// Removes a user from a meeting.
var removeUser = function(data){ var removeUser = function(data){
if(data['role'] == 'MODERATOR'){ if(data['role'] == 'MODERATOR'){
MEETINGS[data['meeting']]['moderators'].splice(MEETINGS[data['meeting']]['moderators'].indexOf(data['user']), 1); MEETINGS[data['meeting']]['moderators'].splice(MEETINGS[data['meeting']]['moderators'].indexOf(data['user']), 1);
@ -48,21 +51,26 @@ var removeUser = function(data){
updateMeetingText(MEETINGS[data['meeting']]) updateMeetingText(MEETINGS[data['meeting']])
} }
// Updates the display text for an active meeting.
var updateMeetingText = function(m){ var updateMeetingText = function(m){
// If a meeting has a moderators property, it is running.
var body;
if(m.hasOwnProperty('moderators')){ if(m.hasOwnProperty('moderators')){
var list; var list;
if(m['moderators'].length + m['participants'].length == 0){ if(m['moderators'].length + m['participants'].length == 0){
list = '(empty)' list = '(empty)'
} else { } else {
list = m['moderators'].join('(mod), ') + (m['moderators'].length > 0 ? '(mod)' : '') + list = m['moderators'].join('(mod), ') + (m['moderators'].length > 0 ? '(mod)' : '') +
(m['participants'].length > 0 && m['moderators'].length != 0 ? ', ' : '') + m['participants'].join(', ') (m['participants'].length > 0 && m['moderators'].length != 0 ? ', ' : '') + m['participants'].join(', ')
} }
var body = '<a>' + m['name'] + '</a><i>: ' + list + '</i>' body = '<a>' + m['name'] + '</a><i>: ' + list + '</i>'
// Otherwise it hasn't started (users waiting the join).
} else { } else {
var body = '<a>' + m['name'] + '</a><i> (not yet started): ' + body = '<a>' + m['name'] + '</a><i> (not yet started): ' +
m['users'].join(', ') + '</i>' m['users'].join(', ') + '</i>'
} }
// If the item doesn't exist, add it and set up join meeting event.
if($('#' + m['name'].replace(' ', '_')).length == 0){ if($('#' + m['name'].replace(' ', '_')).length == 0){
var meeting_item = $('<li id = ' + m['name'].replace(' ', '_') + '>' + body + '</li>') var meeting_item = $('<li id = ' + m['name'].replace(' ', '_') + '>' + body + '</li>')
$('.actives').append(meeting_item); $('.actives').append(meeting_item);
@ -71,11 +79,13 @@ var updateMeetingText = function(m){
meeting_item.click(function(){ meeting_item.click(function(){
joinMeeting(m['name']); joinMeeting(m['name']);
}); });
// Otherwise, just change the body.
} else { } else {
$('#' + m['name'].replace(' ', '_')).html(body) $('#' + m['name'].replace(' ', '_')).html(body)
} }
} }
// Initially populates the active meetings when the page loads using the API.
var initialPopulate = function(){ var initialPopulate = function(){
// Only populate on room resources. // Only populate on room resources.
var chopped = window.location.href.split('/') var chopped = window.location.href.split('/')
@ -95,9 +105,6 @@ var initialPopulate = function(){
if(meetings[i]['metadata']['room-id'] != $('body').data('current-user')) { continue; } if(meetings[i]['metadata']['room-id'] != $('body').data('current-user')) { continue; }
var name = meetings[i]['meetingName'] var name = meetings[i]['meetingName']
var participants = []
var moderators = []
var attendees; var attendees;
if(meetings[i]['attendees']['attendee'] instanceof Array){ if(meetings[i]['attendees']['attendee'] instanceof Array){
attendees = meetings[i]['attendees']['attendee'] attendees = meetings[i]['attendees']['attendee']
@ -105,6 +112,9 @@ var initialPopulate = function(){
attendees = [meetings[i]['attendees']['attendee']] attendees = [meetings[i]['attendees']['attendee']]
} }
var participants = []
var moderators = []
jQuery.each(attendees, function(i, attendee){ jQuery.each(attendees, function(i, attendee){
// The API doesn't return a empty array when empty, just undefined. // The API doesn't return a empty array when empty, just undefined.
if(attendee != undefined){ if(attendee != undefined){
@ -131,22 +141,19 @@ var initialPopulate = function(){
updatePreviousMeetings(); updatePreviousMeetings();
$('.hidden-list').show(); $('.hidden-list').show();
$('.active-spinner').hide(); $('.active-spinner').hide();
}).error(function(){
console.log('Not on a page to load meetings.')
return true;
}); });
} }
// Checks if a meeting has been prveiously joined by the user.
var isPreviouslyJoined = function(meeting){ var isPreviouslyJoined = function(meeting){
joinedMeetings = localStorage.getItem('joinedRooms-' + $('body').data('current-user')); var joinedMeetings = localStorage.getItem('joinedRooms-' + $('body').data('current-user'));
if (joinedMeetings == '' || joinedMeetings == null){ return false; } if (joinedMeetings == '' || joinedMeetings == null){ return false; }
return joinedMeetings.split(',').indexOf(meeting) >= 0 return joinedMeetings.split(',').indexOf(meeting) >= 0
} }
// Removes an active meeting.
var removeActiveMeeting = function(meeting){ var removeActiveMeeting = function(meeting){
if(meeting){ if(meeting){ $('#' + meeting['name'].replace(' ', '_')).remove() }
$('#' + meeting['name'].replace(' ', '_')).remove()
}
} }
// Directly join a meeting from active meetings. // Directly join a meeting from active meetings.
@ -177,13 +184,16 @@ $(document).on('turbolinks:load', function(){
if($('body').data('current-user')){ if($('body').data('current-user')){
MEETINGS = {} MEETINGS = {}
// Ensure actives is empty.
$('.actives').empty(); $('.actives').empty();
if(!App.messages){ if(!App.messages){
// Setup actioncable.
App.messages = App.cable.subscriptions.create('RefreshMeetingsChannel', { App.messages = App.cable.subscriptions.create('RefreshMeetingsChannel', {
received: function(data) { received: function(data) {
console.log('Recieved ' + data['method'] + ' action for ' + data['meeting'] + ' with room id ' + data['room'] + '.') console.log('Recieved ' + data['method'] + ' action for ' + data['meeting'] + ' with room id ' + data['room'] + '.')
if(isPreviouslyJoined(data['meeting']) && data['room'] == $('body').data('current-user')){ if(isPreviouslyJoined(data['meeting']) && data['room'] == $('body').data('current-user')){
// Handle webhook event.
if(data['method'] == 'create'){ if(data['method'] == 'create'){
// Create an empty meeting. // Create an empty meeting.
MEETINGS[data['meeting']] = {'name': data['meeting'], MEETINGS[data['meeting']] = {'name': data['meeting'],
@ -224,6 +234,7 @@ $(document).on('turbolinks:load', function(){
} }
console.log('Populating active meetings.'); console.log('Populating active meetings.');
// Short delay to hide the previous meetings population.
setTimeout(initialPopulate, LOADING_DELAY); setTimeout(initialPopulate, LOADING_DELAY);
} }
}); });

View File

@ -40,7 +40,7 @@
} }
// setup event handlers // setup event handlers
$('.center-panel-wrapper').on ('click', '.meeting-join', function (event) { $('.center-panel-wrapper').on ('click', '.meeting-join', function () {
var name = $('.meeting-user-name').val(); var name = $('.meeting-user-name').val();
Meeting.getInstance().setUserName(name); Meeting.getInstance().setUserName(name);
Meeting.getInstance().setMeetingId($(".page-wrapper").data('id')); Meeting.getInstance().setMeetingId($(".page-wrapper").data('id'));
@ -56,7 +56,7 @@
$(location).attr("href", data.response.join_url); $(location).attr("href", data.response.join_url);
} }
}); });
jqxhr.fail(function(xhr, status, error) { jqxhr.fail(function() {
console.info("meeting join failed"); console.info("meeting join failed");
}); });
} else { } else {
@ -69,11 +69,11 @@
} }
}); });
$('.center-panel-wrapper').on ('click', '.meeting-start', function (event) { $('.center-panel-wrapper').on ('click', '.meeting-start', function () {
Turbolinks.visit($('.meeting-url').val()); Turbolinks.visit($('.meeting-url').val());
}); });
$('.center-panel-wrapper').on ('input', '.meeting-user-name', function (event) { $('.center-panel-wrapper').on ('input', '.meeting-user-name', function () {
if ($(this).val() === '') { if ($(this).val() === '') {
$(this).parent().addClass('has-error') $(this).parent().addClass('has-error')
} else { } else {
@ -95,20 +95,17 @@
} }
}); });
$('.center-panel-wrapper').on ('click', '.meeting-end', function (event) { $('.center-panel-wrapper').on ('click', '.meeting-end', function () {
var jqxhr = Meeting.getInstance().endMeeting(); var jqxhr = Meeting.getInstance().endMeeting();
var btn = $(this); var btn = $(this);
btn.prop("disabled", true); btn.prop("disabled", true);
jqxhr.done(function(data) { jqxhr.fail(function() {
});
jqxhr.fail(function(xhr, status, error) {
console.info("meeting end failed"); console.info("meeting end failed");
}); });
}); });
$('.center-panel-wrapper').on ('click', '.meeting-url-copy', function (event) { $('.center-panel-wrapper').on ('click', '.meeting-url-copy', function () {
meetingURLInput = $('.meeting-url'); var meetingURLInput = $('.meeting-url');
// copy URL // copy URL
meetingURLInput.select(); meetingURLInput.select();
@ -135,7 +132,7 @@
}); });
// button used to send invitations to the meeting (i.e. "mailto:" link) // button used to send invitations to the meeting (i.e. "mailto:" link)
$('.center-panel-wrapper').on('click', '.meeting-invite', function (event) { $('.center-panel-wrapper').on('click', '.meeting-invite', function () {
var meetingURL = Meeting.getInstance().getURL(); var meetingURL = Meeting.getInstance().getURL();
var subject = $(this).data("invite-subject"); var subject = $(this).data("invite-subject");
var body = $(this).data("invite-body").replace("&&URL&&", meetingURL); var body = $(this).data("invite-body").replace("&&URL&&", meetingURL);
@ -143,16 +140,16 @@
window.open(mailto); window.open(mailto);
}); });
$('.center-panel-wrapper').on('mouseleave', '.meeting-url-copy', function (event, msg) { $('.center-panel-wrapper').on('mouseleave', '.meeting-url-copy', function () {
$(this).blur(); $(this).blur();
}); });
$('.center-panel-wrapper').on('focus', '.meeting-url', function (event, msg) { $('.center-panel-wrapper').on('focus', '.meeting-url', function () {
$(this).select(); $(this).select();
}); });
// only allow ctrl commands // only allow ctrl commands
$('.center-panel-wrapper').on('keydown', '.meeting-url', function (event, msg) { $('.center-panel-wrapper').on('keydown', '.meeting-url', function (event) {
if(!event.ctrlKey) { if(!event.ctrlKey) {
event.preventDefault(); event.preventDefault();
} }
@ -164,7 +161,7 @@
container: 'body' container: 'body'
}; };
$(document).tooltip(options); $(document).tooltip(options);
var options = { options = {
selector: '.bottom-tooltip', selector: '.bottom-tooltip',
container: 'body', container: 'body',
placement: 'bottom' placement: 'bottom'
@ -183,7 +180,7 @@
var initIndex = function() { var initIndex = function() {
$('.center-panel-wrapper').on('input', '.meeting-name', function (event, msg) { $('.center-panel-wrapper').on('input', '.meeting-name', function () {
var newId = $(this).val(); var newId = $(this).val();
Meeting.getInstance().setMeetingId(newId); Meeting.getInstance().setMeetingId(newId);
$(".page-wrapper.meetings").data('id', newId); $(".page-wrapper.meetings").data('id', newId);
@ -207,7 +204,7 @@
displayRoomURL(); displayRoomURL();
var roomAdmin = $('.page-wrapper.rooms').data('admin-id'); var roomAdmin = $('.page-wrapper.rooms').data('admin-id');
$('.center-panel-wrapper').on('input', '.meeting-name', function (event, msg) { $('.center-panel-wrapper').on('input', '.meeting-name', function () {
var newId = $(this).val(); var newId = $(this).val();
Meeting.getInstance().setMeetingId(newId); Meeting.getInstance().setMeetingId(newId);
$('.meeting-url').val(Meeting.getInstance().getURL()); $('.meeting-url').val(Meeting.getInstance().getURL());

View File

@ -41,7 +41,7 @@ class LandingController < ApplicationController
end end
def guest def guest
# If someone tries to aceess the guest landing when guest access is enabled, just send them to root. # If someone tries to access the guest landing when guest access is enabled, just send them to root.
redirect_to root_url unless Rails.configuration.disable_guest_access redirect_to root_url unless Rails.configuration.disable_guest_access
end end