recording async update

This commit is contained in:
Zachary Chai 2016-10-31 17:39:22 -04:00
parent db9d06b72f
commit e400bf41e8
11 changed files with 100 additions and 13 deletions

View File

@ -0,0 +1,26 @@
(function() {
var initRooms = function() {
App.messages = App.cable.subscriptions.create({
channel: 'RecordingUpdatesChannel',
username: window.location.pathname.split('/').pop()
},
{
received: function(data) {
var btn = $("#recordings").find(".recording-update:disabled");
btn.data('published', data.published);
btn.find('i').removeClass(getPublishClass(!data.published));
btn.find('i').addClass(getPublishClass(data.published));
btn.prop("disabled", false);
}
});
};
$(document).on("turbolinks:load", function() {
if ($("body[data-controller=landing]").get(0)) {
if ($("body[data-action=rooms]").get(0)) {
initRooms();
}
}
});
}).call(this);

View File

@ -112,9 +112,9 @@
if (type === 'display') { if (type === 'display') {
var roomName = window.location.pathname.split('/').pop(); var roomName = window.location.pathname.split('/').pop();
var published = row.published; var published = row.published;
var eye = (published) ? 'eye' : 'eye-slash' var eye = getPublishClass(published);
return '<button type="button" class="btn btn-default recording-update" data-id="'+data+'" data-room="'+roomName+'" data-published="'+published+'">' + return '<button type="button" class="btn btn-default recording-update" data-id="'+data+'" data-room="'+roomName+'" data-published="'+published+'">' +
'<i class="fa fa-'+eye+'" aria-hidden="true"></i></button> ' + '<i class="fa '+eye+'" aria-hidden="true"></i></button> ' +
'<button type="button" class="btn btn-default recording-delete" data-id="'+data+'" data-room="'+roomName+'">' + '<button type="button" class="btn btn-default recording-delete" data-id="'+data+'" data-room="'+roomName+'">' +
'<i class="fa fa-trash-o" aria-hidden="true"></i></button>'; '<i class="fa fa-trash-o" aria-hidden="true"></i></button>';
} }
@ -128,12 +128,15 @@
var room = $(this).data('room'); var room = $(this).data('room');
var id = $(this).data('id'); var id = $(this).data('id');
var published = $(this).data('published'); var published = $(this).data('published');
$(this).prop("disabled", true);
$.ajax({ $.ajax({
method: 'PATCH', method: 'PATCH',
url: '/rooms/'+room+'/recordings/'+id, url: '/rooms/'+room+'/recordings/'+id,
data: {published: (!published).toString()} data: {published: (!published).toString()}
}).done(function(data) { }).done(function(data) {
$(this).prop("disabled", true);
}).fail(function(data) {
$(this).prop("disabled", false);
}); });
}); });

View File

@ -4,6 +4,12 @@ $.ajaxSetup({
} }
}); });
var PUBLISHED_CLASSES = ['fa-eye-slash', 'fa-eye']
var getPublishClass = function(published) {
return PUBLISHED_CLASSES[+published];
}
var meetingInstance = null; var meetingInstance = null;
class Meeting { class Meeting {
constructor(url, name) { constructor(url, name) {

View File

@ -0,0 +1,5 @@
class RecordingUpdatesChannel < ApplicationCable::Channel
def subscribed
stream_from "#{params[:username]}_recording_updates_channel"
end
end

View File

@ -1,4 +1,5 @@
class BbbController < ApplicationController class BbbController < ApplicationController
include BbbApi
before_action :authorize_owner_recording, only: [:update_recordings, :delete_recordings] before_action :authorize_owner_recording, only: [:update_recordings, :delete_recordings]
@ -20,7 +21,7 @@ class BbbController < ApplicationController
end end
options[:meeting_logout_url] = "#{request.base_url}/#{params[:resource]}/#{params[:id]}" options[:meeting_logout_url] = "#{request.base_url}/#{params[:resource]}/#{params[:id]}"
bbb_res = helpers.bbb_join_url( bbb_res = bbb_join_url(
params[:id], params[:id],
params[:name], params[:name],
options options
@ -42,19 +43,22 @@ class BbbController < ApplicationController
render head(:not_found) && return render head(:not_found) && return
end end
bbb_res = helpers.bbb_get_recordings user.username bbb_res = bbb_get_recordings user.username
render_bbb_response bbb_res, bbb_res[:recordings] render_bbb_response bbb_res, bbb_res[:recordings]
end end
# PATCH /rooms/:id/recordings/:record_id # PATCH /rooms/:id/recordings/:record_id
def update_recordings def update_recordings
bbb_res = helpers.bbb_update_recordings(params[:record_id], params[:published] == 'true') bbb_res = bbb_update_recordings(params[:record_id], params[:published] == 'true')
if bbb_res[:returncode]
RecordingUpdatesJob.perform_later(@user.username, params[:record_id], bbb_res[:published])
end
render_bbb_response bbb_res render_bbb_response bbb_res
end end
# DELETE /rooms/:id/recordings/:record_id # DELETE /rooms/:id/recordings/:record_id
def delete_recordings def delete_recordings
bbb_res = helpers.bbb_delete_recordings(params[:record_id]) bbb_res = bbb_delete_recordings(params[:record_id])
render_bbb_response bbb_res render_bbb_response bbb_res
end end
@ -68,9 +72,10 @@ class BbbController < ApplicationController
render head(:unauthorized) && return render head(:unauthorized) && return
end end
recordings = helpers.bbb_get_recordings(params[:id])[:recordings] recordings = bbb_get_recordings(params[:id])[:recordings]
recordings.each do |recording| recordings.each do |recording|
if recording[:recordID] == params[:record_id] if recording[:recordID] == params[:record_id]
@user = user
return true return true
end end
end end

View File

@ -0,0 +1,22 @@
class RecordingUpdatesJob < ApplicationJob
include BbbApi
queue_as :default
def perform(room, record_id, published)
tries = 0
sleep_time = 2
while tries < 4
bbb_res = bbb_get_recordings(nil, record_id)
if bbb_res[:recordings].first[:published].to_s == published
ActionCable.server.broadcast "#{room}_recording_updates_channel",
published: bbb_res[:recordings].first[:published]
break
end
sleep sleep_time
sleep_time = sleep_time * 2
tries += 1
end
end
end

View File

@ -1,4 +1,4 @@
module BbbHelper module BbbApi
def bbb_endpoint def bbb_endpoint
Rails.application.secrets[:bbb_endpoint] Rails.application.secrets[:bbb_endpoint]
end end
@ -67,9 +67,15 @@ module BbbHelper
end end
end end
def bbb_get_recordings(meeting_token) def bbb_get_recordings(meeting_id, record_id=nil)
meeting_id = (Digest::SHA1.hexdigest(Rails.application.secrets[:secret_key_base]+meeting_token)).to_s options={}
bbb_safe_execute :get_recordings, meetingID: meeting_id if record_id
options[:recordID] = record_id
end
if meeting_id
options[:meetingID] = (Digest::SHA1.hexdigest(Rails.application.secrets[:secret_key_base]+meeting_id)).to_s
end
bbb_safe_execute :get_recordings, options
end end
def bbb_update_recordings(id, published) def bbb_update_recordings(id, published)

View File

@ -11,6 +11,9 @@ unless @response.blank?
json.end_time recording[:endTime] json.end_time recording[:endTime]
json.published recording[:published] json.published recording[:published]
json.playbacks do json.playbacks do
unless recording[:playback][:format].is_a? Array
recording[:playback][:format] = [recording[:playback][:format]]
end
json.array!(recording[:playback][:format]) do |playback| json.array!(recording[:playback][:format]) do |playback|
json.type playback[:type] json.type playback[:type]
json.url playback[:url] json.url playback[:url]

View File

@ -31,11 +31,13 @@ Rails.application.configure do
config.action_mailer.perform_caching = false config.action_mailer.perform_caching = false
config.active_job.queue_adapter = :async
# action cable socket URI # action cable socket URI
config.action_cable.url = "ws://localhost/cable" config.action_cable.url = "ws://localhost/cable"
# allowed action cable origins # allowed action cable origins
Rails.application.config.action_cable.allowed_request_origins = ['http://localhost'] config.action_cable.allowed_request_origins = ['http://localhost']
# Print deprecation notices to the Rails logger. # Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log config.active_support.deprecation = :log

View File

@ -55,6 +55,8 @@ Rails.application.configure do
# Use a real queuing backend for Active Job (and separate queues per environment) # Use a real queuing backend for Active Job (and separate queues per environment)
# config.active_job.queue_adapter = :resque # config.active_job.queue_adapter = :resque
# config.active_job.queue_name_prefix = "greenlight_#{Rails.env}" # config.active_job.queue_name_prefix = "greenlight_#{Rails.env}"
config.active_job.queue_adapter = :async
config.action_mailer.perform_caching = false config.action_mailer.perform_caching = false
# Ignore bad email addresses and do not raise email delivery errors. # Ignore bad email addresses and do not raise email delivery errors.

View File

@ -0,0 +1,7 @@
require 'test_helper'
class RecordingUpdatesJobTest < ActiveJob::TestCase
# test "the truth" do
# assert true
# end
end