class BBBEvents::Recording
Attributes
duration[RW]
files[RW]
finish[RW]
meeting_id[RW]
metadata[RW]
start[RW]
timestamp[RW]
Public Class Methods
new(events_xml)
click to toggle source
# File lib/bbbevents/recording.rb, line 14 def initialize(events_xml) filename = File.basename(events_xml) raise "#{filename} is not a file or does not exist." unless File.file?(events_xml) raw_recording_data = Hash.from_xml(File.read(events_xml)) raise "#{filename} is not a valid xml file (unable to parse)." if raw_recording_data.nil? raise "#{filename} is missing recording key." unless raw_recording_data.key?("recording") recording_data = raw_recording_data["recording"] events = recording_data["event"] events = [events] unless events.is_a?(Array) @metadata = recording_data["metadata"] @meeting_id = recording_data["metadata"]["meetingId"] internal_meeting_id = recording_data["meeting"]["id"] @timestamp = extract_timestamp(internal_meeting_id) @first_event = events.first["timestamp"].to_i @last_event = events.last["timestamp"].to_i @start = Time.at(@timestamp / 1000) @finish = Time.at(timestamp_conversion(@last_event)) @duration = (@finish - @start).to_i @attendees = {} @polls = {} @files = [] # Map to look up external user id (for @data[:attendees]) from the # internal user id in most recording events @externalUserId = {} process_events(events) @attendees.values.each do |att| att.leaves << @finish if att.joins.length > att.leaves.length att.duration = total_duration(att) end end
Public Instance Methods
attendees()
click to toggle source
Take only the values since we no longer need to index.
# File lib/bbbevents/recording.rb, line 58 def attendees @attendees.values end
create_csv(filepath)
click to toggle source
Export recording data to a CSV file.
# File lib/bbbevents/recording.rb, line 88 def create_csv(filepath) CSV.open(filepath, "wb") do |csv| csv << CSV_HEADER.map(&:capitalize) + (1..polls.length).map { |i| "Poll #{i}" } @attendees.each do |id, att| csv << att.csv_row + polls.map { |poll| poll.votes[id] || NO_VOTE_SYMBOL } end end end
moderators()
click to toggle source
Retrieve a list of all the moderators.
# File lib/bbbevents/recording.rb, line 63 def moderators attendees.select(&:moderator?) end
polls()
click to toggle source
Take only the values since we no longer need to index.
# File lib/bbbevents/recording.rb, line 73 def polls @polls.values end
published_polls()
click to toggle source
Retrieve a list of published polls.
# File lib/bbbevents/recording.rb, line 78 def published_polls polls.select(&:published?) end
to_h()
click to toggle source
# File lib/bbbevents/recording.rb, line 97 def to_h # Transform any CamelCase keys to snake_case. @metadata.deep_transform_keys! do |key| k = key.to_s.underscore rescue key k.to_sym rescue key end { metadata: @metadata, meeting_id: @meeting_id, duration: @duration, start: @start, finish: @finish, attendees: attendees.map(&:to_h), files: @files, polls: polls.map(&:to_h) } end
to_json()
click to toggle source
# File lib/bbbevents/recording.rb, line 116 def to_json to_h.to_json end
unpublished_polls()
click to toggle source
Retrieve a list of unpublished polls.
# File lib/bbbevents/recording.rb, line 83 def unpublished_polls polls.reject(&:published?) end
viewers()
click to toggle source
Retrieve a list of all the viewers.
# File lib/bbbevents/recording.rb, line 68 def viewers attendees.reject(&:moderator?) end
Private Instance Methods
extract_timestamp(meeting_id)
click to toggle source
Extracts the timestamp from a meeting id.
# File lib/bbbevents/recording.rb, line 131 def extract_timestamp(meeting_id) meeting_id.split("-").last.to_i end
process_events(events)
click to toggle source
Process all the events in the events.xml file.
# File lib/bbbevents/recording.rb, line 123 def process_events(events) events.each do |e| event = e["eventname"].underscore send(event, e) if RECORDABLE_EVENTS.include?(event) end end
timestamp_conversion(base)
click to toggle source
Converts the BigBlueButton timestamps to proper time.
# File lib/bbbevents/recording.rb, line 136 def timestamp_conversion(base) (base.to_i - @first_event + @timestamp) / 1000 end
total_duration(att)
click to toggle source
Calculates an attendee's duration.
# File lib/bbbevents/recording.rb, line 141 def total_duration(att) return 0 unless att.joins.length == att.leaves.length total = 0 att.joins.length.times do |i| total += att.leaves[i] - att.joins[i] end total end