forked from External/greenlight
recording async update
This commit is contained in:
parent
db9d06b72f
commit
e400bf41e8
|
@ -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);
|
|
@ -112,9 +112,9 @@
|
|||
if (type === 'display') {
|
||||
var roomName = window.location.pathname.split('/').pop();
|
||||
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+'">' +
|
||||
'<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+'">' +
|
||||
'<i class="fa fa-trash-o" aria-hidden="true"></i></button>';
|
||||
}
|
||||
|
@ -128,12 +128,15 @@
|
|||
var room = $(this).data('room');
|
||||
var id = $(this).data('id');
|
||||
var published = $(this).data('published');
|
||||
$(this).prop("disabled", true);
|
||||
$.ajax({
|
||||
method: 'PATCH',
|
||||
url: '/rooms/'+room+'/recordings/'+id,
|
||||
data: {published: (!published).toString()}
|
||||
}).done(function(data) {
|
||||
$(this).prop("disabled", true);
|
||||
|
||||
}).fail(function(data) {
|
||||
$(this).prop("disabled", false);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -4,6 +4,12 @@ $.ajaxSetup({
|
|||
}
|
||||
});
|
||||
|
||||
var PUBLISHED_CLASSES = ['fa-eye-slash', 'fa-eye']
|
||||
|
||||
var getPublishClass = function(published) {
|
||||
return PUBLISHED_CLASSES[+published];
|
||||
}
|
||||
|
||||
var meetingInstance = null;
|
||||
class Meeting {
|
||||
constructor(url, name) {
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class RecordingUpdatesChannel < ApplicationCable::Channel
|
||||
def subscribed
|
||||
stream_from "#{params[:username]}_recording_updates_channel"
|
||||
end
|
||||
end
|
|
@ -1,4 +1,5 @@
|
|||
class BbbController < ApplicationController
|
||||
include BbbApi
|
||||
|
||||
before_action :authorize_owner_recording, only: [:update_recordings, :delete_recordings]
|
||||
|
||||
|
@ -20,7 +21,7 @@ class BbbController < ApplicationController
|
|||
end
|
||||
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[:name],
|
||||
options
|
||||
|
@ -42,19 +43,22 @@ class BbbController < ApplicationController
|
|||
render head(:not_found) && return
|
||||
end
|
||||
|
||||
bbb_res = helpers.bbb_get_recordings user.username
|
||||
bbb_res = bbb_get_recordings user.username
|
||||
render_bbb_response bbb_res, bbb_res[:recordings]
|
||||
end
|
||||
|
||||
# PATCH /rooms/:id/recordings/:record_id
|
||||
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
|
||||
end
|
||||
|
||||
# DELETE /rooms/:id/recordings/:record_id
|
||||
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
|
||||
end
|
||||
|
||||
|
@ -68,9 +72,10 @@ class BbbController < ApplicationController
|
|||
render head(:unauthorized) && return
|
||||
end
|
||||
|
||||
recordings = helpers.bbb_get_recordings(params[:id])[:recordings]
|
||||
recordings = bbb_get_recordings(params[:id])[:recordings]
|
||||
recordings.each do |recording|
|
||||
if recording[:recordID] == params[:record_id]
|
||||
@user = user
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
|
@ -1,4 +1,4 @@
|
|||
module BbbHelper
|
||||
module BbbApi
|
||||
def bbb_endpoint
|
||||
Rails.application.secrets[:bbb_endpoint]
|
||||
end
|
||||
|
@ -67,9 +67,15 @@ module BbbHelper
|
|||
end
|
||||
end
|
||||
|
||||
def bbb_get_recordings(meeting_token)
|
||||
meeting_id = (Digest::SHA1.hexdigest(Rails.application.secrets[:secret_key_base]+meeting_token)).to_s
|
||||
bbb_safe_execute :get_recordings, meetingID: meeting_id
|
||||
def bbb_get_recordings(meeting_id, record_id=nil)
|
||||
options={}
|
||||
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
|
||||
|
||||
def bbb_update_recordings(id, published)
|
|
@ -11,6 +11,9 @@ unless @response.blank?
|
|||
json.end_time recording[:endTime]
|
||||
json.published recording[:published]
|
||||
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.type playback[:type]
|
||||
json.url playback[:url]
|
||||
|
|
|
@ -31,11 +31,13 @@ Rails.application.configure do
|
|||
|
||||
config.action_mailer.perform_caching = false
|
||||
|
||||
config.active_job.queue_adapter = :async
|
||||
|
||||
# action cable socket URI
|
||||
config.action_cable.url = "ws://localhost/cable"
|
||||
|
||||
# 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.
|
||||
config.active_support.deprecation = :log
|
||||
|
|
|
@ -55,6 +55,8 @@ Rails.application.configure do
|
|||
# Use a real queuing backend for Active Job (and separate queues per environment)
|
||||
# config.active_job.queue_adapter = :resque
|
||||
# config.active_job.queue_name_prefix = "greenlight_#{Rails.env}"
|
||||
config.active_job.queue_adapter = :async
|
||||
|
||||
config.action_mailer.perform_caching = false
|
||||
|
||||
# Ignore bad email addresses and do not raise email delivery errors.
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
require 'test_helper'
|
||||
|
||||
class RecordingUpdatesJobTest < ActiveJob::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
Loading…
Reference in New Issue