From 7e16f042a59ba791c8543e4cc2f7afe5a09fbc35 Mon Sep 17 00:00:00 2001 From: Josh Date: Thu, 22 Jun 2017 15:15:03 -0400 Subject: [PATCH] add more information to recording ready email --- app/controllers/bbb_controller.rb | 3 ++ app/lib/bbb_api.rb | 3 +- app/mailers/notification_mailer.rb | 1 + .../recording_ready_email.html.erb | 24 +++++++++++++++ config/locales/en-us.yml | 6 ++++ scripts/greenlight_recording_notify.rb | 30 ++++++++++++++++++- 6 files changed, 65 insertions(+), 2 deletions(-) diff --git a/app/controllers/bbb_controller.rb b/app/controllers/bbb_controller.rb index 6cdea5ab..cf7b6b35 100644 --- a/app/controllers/bbb_controller.rb +++ b/app/controllers/bbb_controller.rb @@ -263,6 +263,7 @@ class BbbController < ApplicationController token = event['payload']['metadata'][META_TOKEN] room_id = event['payload']['metadata']['room-id'] record_id = event['payload']['meeting_id'] + duration_data = event['payload']['duration'] # the webhook event doesn't have all the data we need, so we need # to send a getRecordings anyway @@ -271,6 +272,8 @@ class BbbController < ApplicationController rec_info = rec_info[:recordings].first RecordingCreatedJob.perform_later(token, room_id, parse_recording_for_view(rec_info)) + rec_info[:duration] = duration_data.to_json + # send an email to the owner of this recording, if defined if Rails.configuration.mail_notifications owner = User.find_by(encrypted_id: room_id) diff --git a/app/lib/bbb_api.rb b/app/lib/bbb_api.rb index 5b37d072..f68a7897 100644 --- a/app/lib/bbb_api.rb +++ b/app/lib/bbb_api.rb @@ -263,7 +263,8 @@ module BbbApi listed: recording[:listed], playbacks: playbacks, previews: previews, - participants: recording[:participants] + participants: recording[:participants], + duration: recording[:duration] } end diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb index b08b3c02..67843231 100644 --- a/app/mailers/notification_mailer.rb +++ b/app/mailers/notification_mailer.rb @@ -20,6 +20,7 @@ class NotificationMailer < ActionMailer::Base def recording_ready_email(user, rec) @user = user @recording = rec + @duration = JSON.parse(rec[:duration]) @room_url = meeting_room_url(resource: 'rooms', id: user.encrypted_id) # Need this because URL doesn't respect the relative_url_root by default diff --git a/app/views/notification_mailer/recording_ready_email.html.erb b/app/views/notification_mailer/recording_ready_email.html.erb index 29ef3d9c..e70a051d 100644 --- a/app/views/notification_mailer/recording_ready_email.html.erb +++ b/app/views/notification_mailer/recording_ready_email.html.erb @@ -43,6 +43,30 @@ <%= @recording[:participants] %> +
+ + + + + + + + + <% @duration.each do |user| %> + + + + + + + + <% end %> +
<%= t('.user_table.user') %><%= t('.user_table.role') %><%= t('.user_table.join') %><%= t('.user_table.left') %><%= t('.user_table.duration') %>
<%= user[1]['name'] %><%= user[1]['role'].downcase.capitalize %><%= Time.at(user[1]['join'] / 1000).strftime("%H:%M:%S") %><%= Time.at(user[1]['left'] / 1000).strftime("%H:%M:%S") %><%= Time.at(user[1]['duration'] / 1000).utc.strftime("%H:%M:%S") %>
+
+

<%= t('thumbnails') %>:

+ <% @recording[:previews].each do |preview| %> + <%= preview[:alt] %> + <% end %>

<%= t('.phrase2') %>

<%= link_to(@recording[:playbacks][0][:url], @recording[:playbacks][0][:url]) %>

<%= t('.phrase3_html') %>

diff --git a/config/locales/en-us.yml b/config/locales/en-us.yml index 5688c7f4..3016c399 100644 --- a/config/locales/en-us.yml +++ b/config/locales/en-us.yml @@ -141,6 +141,12 @@ en-US: length_value: "%{value} minutes" started: Started users: Users + user_table: + user: User + role: Role + join: Join + left: Leave + duration: Duration participants: Users past_recordings: Past Recordings preferences: Preferences diff --git a/scripts/greenlight_recording_notify.rb b/scripts/greenlight_recording_notify.rb index eca57cb1..a17335bb 100755 --- a/scripts/greenlight_recording_notify.rb +++ b/scripts/greenlight_recording_notify.rb @@ -48,6 +48,32 @@ def getParticipantsInfo(events_xml) participants_info end +# Gets the join and leave times for each user, as well as total duration of stay. +def get_duration_info(events_xml) + BigBlueButton.logger.info("Task: Getting duration information.") + doc = Nokogiri::XML(File.open(events_xml)) + user_data = {} + first_event_time = BigBlueButton::Events.first_event_timestamp(events_xml) + timestamp = doc.at_xpath('/recording')['meeting_id'].split('-')[1].to_i + joinEvents = doc.xpath('/recording/event[@module="PARTICIPANT" and @eventname="ParticipantJoinEvent"]') + leftEvents = doc.xpath('/recording/event[@module="PARTICIPANT" and @eventname="ParticipantLeftEvent"]') + # This should never occur, but just in case. + return {'error' => 'inequal number of join/left events.'} if joinEvents.length != leftEvents.length + joinEvents.each do |join| + uID = join.xpath('externalUserId').text + user_data[uID] = {} + user_data[uID]['name'] = join.xpath('name').text + user_data[uID]['join'] = join['timestamp'].to_i - first_event_time + timestamp + user_data[uID]['role'] = join.xpath('role').text + end + leftEvents.each do |left| + uID = left.xpath('userId').text.split('_')[0] + user_data[uID]['left'] = left['timestamp'].to_i - first_event_time + timestamp + user_data[uID]['duration'] = user_data[uID]['left'] - user_data[uID]['join'] + end + user_data +end + logger = Logger.new("/var/log/bigbluebutton/post_process.log", 'weekly') logger.level = Logger::INFO BigBlueButton.logger = logger @@ -69,6 +95,7 @@ begin BigBlueButton.logger.info("Making callback for recording ready notification") participants_info = getParticipantsInfo(events_xml) + duration_info = get_duration_info(events_xml) props = JavaProperties::Properties.new("/var/lib/tomcat7/webapps/bigbluebutton/WEB-INF/classes/bigbluebutton.properties") secret = props[:securitySalt] @@ -81,7 +108,8 @@ begin "payload":{ "metadata": meeting_metadata, "meeting_id": meeting_id, - "participants": participants_info + "participants": participants_info, + "duration": duration_info } } payload = {