Merge branch 'master' into webhooks

This commit is contained in:
Joshua Arts
2017-06-14 09:08:33 -04:00
committed by GitHub
16 changed files with 264 additions and 6 deletions

View File

@ -37,6 +37,18 @@ class @Recordings
COLUMN[c] = i++
constructor: ->
recordingsObject = this
canUpload = {}
# Determine which recordings can be uploaded to Youtube.
$.ajax({
method: 'GET',
async: false,
url: recordingsObject.getRecordingsURL() + '/can_upload'
}).success((res_data) ->
canUpload = res_data
)
# configure the datatable for recordings
this.table = $('#recordings').dataTable({
data: [],
@ -131,6 +143,14 @@ class @Recordings
trigger = recordingActions.find('.recording-update-trigger')
trigger.removeClass(classes.join(' '))
trigger.addClass(cls)
upload_btn = recordingActions.find('.cloud-upload')
if canUpload[row.id]
upload_btn.attr('data-popover-body', '.mail_youtube_popover')
else
upload_btn.attr('data-popover-body', '.mail_popover')
return recordingActions.html()
return data
}
@ -151,6 +171,22 @@ class @Recordings
options.title = I18n.play_recording
$('#recordings').tooltip(options)
options.selector = '.youtube-tooltip'
options.title = I18n.upload_youtube
$('#recordings').tooltip(options)
options.selector = '.upload-tooltip'
options.title = I18n.share
$('#recordings').tooltip(options)
options.selector = '.mail-tooltip'
options.title = I18n.mail_recording
$('#recordings').tooltip(options)
options.selector = '.disabled-tooltip'
options.title = I18n.youtube_disabled
$('#recordings').tooltip(options)
$(document).one "turbolinks:before-cache", =>
@getTable().api().clear().draw().destroy()
@ -229,6 +265,7 @@ class @Recordings
setupActionHandlers: ->
table_api = this.table.api()
recordingsObject = this
selectedUpload = null
@getTable().on 'click', '.recording-update', (event) ->
btn = $(this)
@ -273,12 +310,73 @@ class @Recordings
showAlert(I18n.recording_deleted, 4000);
)
@getTable().on 'click', '.upload-button', (event) ->
btn = $(this)
row = table_api.row($(this).closest('tr')).data()
url = recordingsObject.getRecordingsURL()
id = row.id
title = $('#video-title').val()
privacy_status = $('input[name=privacy_status]:checked').val()
if title == ''
title = row.name
$.ajax({
method: 'POST',
url: url+'/'+id
data: {video_title: title, privacy_status: privacy_status}
success: () ->
cloud = selectedUpload.find('.cloud-blue')
check = selectedUpload.find('.green-check')
spinner = selectedUpload.find('.load-spinner')
spinner.hide()
check.show()
setTimeout ( ->
cloud.show()
check.hide()
), 4000
})
selectedUpload.find('.cloud-blue').hide()
selectedUpload.find('.load-spinner').show()
@getTable().on 'click', '.mail-recording', (event) ->
btn = $(this)
row = table_api.row($(this).closest('tr')).data()
url = recordingsObject.getRecordingsURL()
id = row.id
# Take the username from the header.
username = $('#title-header').text().replace('Welcome ', '').trim()
recording_url = row.playbacks[0].url
webcams_url = getHostName(recording_url) + '/presentation/' + id + '/video/webcams.webm'
subject = username + I18n.recording_mail_subject
body = I18n.recording_mail_body + "\n\n" + recording_url + "\n\n" + I18n.email_footer_1 + "\n" + I18n.email_footer_2
mailto = "mailto:?subject=" + encodeURIComponent(subject) + "&body=" + encodeURIComponent(body);
window.open(mailto);
@getTable().on 'click', '.youtube-upload', (event) ->
row = table_api.row($(this).closest('tr')).data()
$('#video-title').attr('value', row.name)
@getTable().on 'click', '.cloud-upload', (event) ->
selectedUpload = $(this)
@getTable().on 'draw.dt', (event) ->
$('time[data-time-ago]').timeago();
getTable: ->
@table
getHostName = (url) ->
parser = document.createElement('a');
parser.href = url;
parser.origin;
getRecordingsURL: ->
if $(".page-wrapper.rooms").data('main-room')
base_url = Meeting.buildRootURL()+'/'+$('body').data('resource')+'/'+Meeting.getInstance().getAdminId()

View File

@ -94,3 +94,23 @@
width: 100%;
text-align: center;
}
.youtube-red {
color: red;
}
.cloud-blue {
color: cornflowerblue;
}
.green-check {
color: limegreen;
}
.top-buffer {
margin-top: 8px;
}
.tooltip-wrapper {
display: inline-block;
}

View File

@ -170,6 +170,41 @@ class BbbController < ApplicationController
render_bbb_response bbb_res
end
# POST /rooms/:room_id/recordings/:record_id
# POST /rooms/:room_id/:id/recordings/:record_id
def youtube_publish
# If we can't get the client, then they don't have a Youtube account.
begin
client = Yt::Account.new(access_token: current_user.token)
video = client.upload_video(get_webcams_url(params[:record_id]),
title: params[:video_title],
description: t('youtube_description', url: 'https://bigbluebutton.org/'),
privacy_status: params[:privacy_status])
rescue
# In this case, they don't have a youtube channel connected to their account, so prompt to create one.
redirect_to 'https://m.youtube.com/create_channel'
end
end
# GET /rooms/:room_id/recordings/can_upload
def can_upload
upload_data = {}
bbb_get_recordings[:recordings].each{ |recording_data|
next if recording_data[:recordID] == ""
# The recording is uploadable if it contains webcam data and they are logged in thorugh Google.
uploadable = Faraday.head(get_webcams_url(recording_data[:recordID])).status == 200 &&
Rails.application.config.omniauth_google &&
current_user.provider == 'google'
upload_data[recording_data[:recordID]] = uploadable
}
render json: upload_data
end
def get_webcams_url(recording_id)
uri = URI.parse(ENV['BIGBLUEBUTTON_ENDPOINT'])
uri.scheme + '://' + uri.host + '/presentation/' + recording_id + '/video/webcams.webm'
end
private
def load_room!

View File

@ -141,6 +141,7 @@ module BbbApi
end
res[:recordings].each do |recording|
next if recording.key?(:error)
pref_preview = {}
recording[:length] = recording[:playback][:format].is_a?(Hash) ? recording[:playback][:format][:length] : recording[:playback][:format].first[:length]
# create a playbacks attribute on recording for playback formats

View File

@ -26,6 +26,7 @@ class User < ApplicationRecord
user.username = self.send("#{auth_hash['provider']}_username", auth_hash) rescue nil
user.email = self.send("#{auth_hash['provider']}_email", auth_hash) rescue nil
user.name = auth_hash['info']['name']
user.token = auth_hash['credentials']['token'] rescue nil
user.save!
user
end

View File

@ -15,7 +15,7 @@
<% content_for :title do %>
<div class="title">
<h2>
<h2 id = 'title-header'>
<% if admin? && !@meeting_running %>
<%= t('admin_room_title', user: @user.name) %>
<% else %>

View File

@ -55,6 +55,49 @@
<%= t('no') %>
</button>
</div>
<div class="youtube-popover">
<form class = "form-inline">
<div class = "row">
<div class="col-xs-12">
<input type="title" class="form-control" id="video-title" placeholder="<%= t('video_title') %>">
</div>
</div>
<div class = "row top-buffer text-center">
<div class = "col-xs-10 col-xs-offset-1">
<form class="privacy_form">
<label class="radio-inline"><input type="radio" name="privacy_status" value="public" checked><%= t('youtube_privacy_options.public') %> </label>
<label class="radio-inline"><input type="radio" name="privacy_status" value="private"><%= t('youtube_privacy_options.private') %> </label>
<label class="radio-inline"><input type="radio" name="privacy_status" value="unlisted"><%= t('youtube_privacy_options.unlisted') %></label>
</form>
</div>
</div>
<div class="row top-buffer text-center">
<button type="button" class="btn btn-success upload-button centered" data-dismiss="popover">
<%= t('upload') %>
</button>
</div>
</form>
</div>
<div class='mail_youtube_popover'>
<button type="button" class="btn btn-default mail-recording mail-tooltip">
<%= icon('envelope-o') %>
</button>
<button type="button" class="btn btn-default has-popover youtube-upload youtube-tooltip"
data-placement="top" data-popover-body=".youtube-popover"
data-popover-title="<%= t('upload_to_youtube') %>" >
<div class = 'youtube-red'> <%= icon('youtube-play') %> </div>
</button>
</div>
<div class='mail_popover'>
<button type="button" class="btn btn-default mail-recording mail-tooltip fa-2x">
<%= icon('envelope-o') %>
</button>
<div class="tooltip-wrapper disabled disabled-tooltip">
<button type="button" class="btn btn-default" disabled>
<%= icon('youtube-play') %>
</button>
</div>
</div>
<div class="recording-visibility-popover">
<button type="button" class="btn btn-default btn-success recording-update" data-visibility="published">
<%= t('client.published') %>
@ -72,6 +115,12 @@
data-popover-title="<%= t('change_recording_visibility') %>">
<%= icon('eye') %>
</button>
<button type="button" class="btn btn-default has-popover cloud-upload upload-tooltip"
data-placement="top">
<div class = 'cloud-blue'> <%= icon('cloud-upload') %> </div>
<div class = 'green-check' hidden> <%= icon('check') %> </div>
<div class = 'load-spinner fa-spin' hidden> <%= icon('spinner') %> </div>
</button>
<a tabindex="0" role="button" class="btn btn-default has-popover delete-tooltip"
data-placement="top" data-popover-body=".delete-popover-body"
data-popover-title="<%= t('are_you_sure') %>">