Skip to content

Commit 5512153

Browse files
committed
Simplify recording state tracking, fix start_time handling
The recording state tracking was unnecessarily complicated in order to handle the case where a recording start (or stop) was received while the recording was already started (or stopped). None of the other recording bothers handling this, and the conditions can be made easier to read by removing this logic. To simplify the tracking of last screenshare as content, I'm not reading it directly from the screenshare_content_events array instead of trying to keep a separate variable in sync. Code has been added to handle the special case of the start_time (recording segment start timestamp) happening after a recording start event and screenshare as content event have been received. In this case, it needs to emit an event corresponding to the current screenshare as content state at the 0 timestamp.
1 parent 668cd27 commit 5512153

1 file changed

Lines changed: 42 additions & 13 deletions

File tree

  • record-and-playback/core/lib/recordandplayback/generators

record-and-playback/core/lib/recordandplayback/generators/events.rb

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,15 @@ def self.screenshare_has_audio?(events, deskshare_dir)
11671167
return false
11681168
end
11691169

1170+
# Get a list of times when the "screenshare as content" flag is changed
1171+
#
1172+
# The returned times account for recording start/stop events, and have timestamps relative to the start of the
1173+
# recording.
1174+
#
1175+
# @param events [Nokogiri::XML::Document] The parsed events.xml document
1176+
# @param start_time [Integer] The recording segment start timestamp (ms)
1177+
# @param end_time [Integer] The recording segment end timestamp (ms)
1178+
# @return [Array<Hash>] An array of events, each with a timestamp and the screenshareAsContent flag
11701179
def self.get_screenshare_as_content_events(events, start_time, end_time)
11711180
BigBlueButton.logger.info('Getting Screenshare as Content Events')
11721181

@@ -1180,37 +1189,57 @@ def self.get_screenshare_as_content_events(events, start_time, end_time)
11801189
record = events.at_xpath('/recording/event[@eventname="RecordStatusEvent"]').nil?
11811190

11821191
screenshare_content_events = []
1183-
last_screenshare_as_content = nil
11841192

11851193
events.xpath('/recording/event').each do |event|
11861194
timestamp = event[:timestamp].to_i - initial_timestamp
11871195
break if timestamp >= end_time
11881196

11891197
case [event[:module], event[:eventname]]
11901198
when %w[PARTICIPANT SetScreenshareAsContentEvent]
1191-
last_screenshare_as_content = event.at_xpath('screenshareAsContent')&.text == "true"
1192-
next if timestamp < start_time || !record
1199+
screenshare_as_content = event.at_xpath('screenshareAsContent')&.content == 'true'
11931200

1194-
screenshareAsContent = event.at_xpath('screenshareAsContent')&.text == "true"
1201+
# Don't emit events during unrecorded sections of the meeting. An event will be emitted when recording resumes
1202+
next unless timestamp >= start_time && record
1203+
# Don't emit an event if the previous event has the same state
1204+
next if screenshare_content_events.dig(-1, :screenshareAsContent) == screenshare_as_content
11951205

11961206
screenshare_content_events << {
11971207
timestamp: timestamp - offset,
1198-
screenshareAsContent: screenshareAsContent,
1208+
screenshareAsContent: screenshare_as_content,
11991209
}
12001210
when %w[PARTICIPANT RecordStatusEvent]
1201-
is_recording = event.at_xpath('status').content == 'true'
1202-
next if timestamp < start_time
1203-
1204-
if is_recording && !record # Recording resumed
1211+
record = event.at_xpath('status').content == 'true'
1212+
if record
1213+
# Recording resumed; update offset to account for the timestamp jump
12051214
offset += timestamp - last_stop_timestamp
1215+
1216+
# Don't emit an event if it's prior to the segment start time
1217+
next unless timestamp >= start_time
1218+
# Don't emit an event if the previous event has the same state
1219+
next if screenshare_content_events.dig(-1, :screenshareAsContent) == screenshare_as_content
1220+
12061221
screenshare_content_events << {
12071222
timestamp: timestamp - offset,
1208-
screenshareAsContent: last_screenshare_as_content,
1209-
} if !last_screenshare_as_content.nil?
1210-
elsif !is_recording && record # Recording paused
1223+
screenshareAsContent: screenshare_as_content,
1224+
}
1225+
else
1226+
# Recording paused
12111227
last_stop_timestamp = timestamp
12121228
end
1213-
record = is_recording
1229+
else
1230+
# Handle the case of start_time being inside a recording segment - need to add an event corresponding to
1231+
# whatever the state happened to be when start_time was reached
1232+
1233+
# Don't emit an event during unrecorded sections of the meeting, or if one has already been emitted.
1234+
next unless timestamp >= start_time && record && screenshare_content_events.empty?
1235+
1236+
# Don't emit an event if we haven't seen a SetScreenshareAsContentEvent yet
1237+
next if screenshare_as_content.nil?
1238+
1239+
screenshare_content_events << {
1240+
timestamp: 0,
1241+
screenshareAsContent: screenshare_as_content,
1242+
}
12141243
end
12151244
end
12161245
screenshare_content_events

0 commit comments

Comments
 (0)