Skip to content

fix(recording): add presentation minimized events + screenshare as content fixes - #23924

Merged
antobinary merged 7 commits into
bigbluebutton:v3.0.x-developfrom
germanocaumo:quick-swap-recording
May 5, 2026
Merged

antobinary merged 7 commits into
bigbluebutton:v3.0.x-developfrom
germanocaumo:quick-swap-recording

Conversation

@germanocaumo

@germanocaumo germanocaumo commented Sep 17, 2025 •

Copy link
Copy Markdown
Contributor

What does this PR do?

  • Include the info when presentation is minimized by presenter with push layout to layout.xml so it can be used in playback:
<?xml version="1.0" encoding="UTF-8"?>
<recording id="layout_swap_events">
  <event timestamp="0.0" show_screenshare="false" show_presentation="true"/>
  <event timestamp="10.8" show_screenshare="true" show_presentation="true"/>
  <event timestamp="22.5" show_screenshare="false" show_presentation="true"/>
  <event timestamp="30.4" show_screenshare="true" show_presentation="true"/>
  <event timestamp="43.0" show_screenshare="true" show_presentation="false"/>
  <event timestamp="45.6" show_screenshare="true" show_presentation="true"/>
  <event timestamp="47.1" show_screenshare="true" show_presentation="false"/>
  <event timestamp="48.5" show_screenshare="true" show_presentation="true"/>
</recording>
  • Only consider swap/layout events inside recordings.
  • Move logic to extract events to events.rb so it can be reused by other formats
  • Add slides swaps to shapes.svg when quick swap occur so playback can show the slides and thumbnails when screenshare is on for the entire recording.
    • In this case, previously only the screenshare was shown.

To be used with bigbluebutton/bbb-playback#331

@coderabbitai

coderabbitai Bot commented Sep 17, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

A new generic helper get_events(events, start_time, end_time, target_module, target_eventname, compare_keys = nil) was added to generalize time‑anchored extraction of state-change events. Existing get_screenshare_as_content_events now accepts start_time and end_time and delegates to get_events. A new get_layout_broadcasted_events(events, start_time, end_time) was added. presentation.rb replaces process_swap_events with process_layout_events, merges layout and screenshare events, and emits unified layout-aware events using explicit meeting start/end bounds and raw event timestamps.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Publisher as presentation.rb
  participant EventsGen as events.rb:get_events
  participant RecStream as /recording/event stream
  participant Emitter as Event Emitter

  Note over EventsGen,RecStream: Time-anchored, window-bounded extraction (generic)
  Publisher->>EventsGen: request events (events, start_time, end_time, target, eventname)
  RecStream->>EventsGen: iterate recording events (RecordStatusEvent, LayoutBroadcastedEvent, SetScreenshareAsContentEvent, ...)
  EventsGen->>EventsGen: compute initial timestamp, normalize times, handle pause/resume offsets
  EventsGen->>EventsGen: filter, dedupe (compare_keys), anchor to offset, constrain to [start,end]
  EventsGen-->>Publisher: return filtered, time-normalized events
  Publisher->>Publisher: merge layout + screenshare events, sort, build unified attributes
  Publisher->>Emitter: emit layout_swap events with timestamp (ms→s) and show_* flags
Loading
sequenceDiagram
  autonumber
  participant Process as process_layout_events
  participant Stream as Event Stream
  participant State as Slide/Deskshare State

  Note over Process,Stream: Per-event handling of screenshare/presentation state
  Stream->>Process: SetScreenshareAsContentEvent (screenshareAsContent)
  alt include_deskshare = false
    Process->>State: disable deskshare
    Process->>State: mark slide changed
  else include_deskhare = true
    Process->>State: enable deskshare with screenshareAsContent
    Process->>State: mark slide changed
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

  • Files to inspect closely:
    • record-and-playback/core/lib/recordandplayback/generators/events.rb — correctness of get_events anchoring, pause/resume offset handling, deduplication (compare_keys), and new get_layout_broadcasted_events plumbing.
    • record-and-playback/presentation/scripts/publish/presentation.rb — integration of process_layout_events, merging/sorting of layout and screenshare events, and use of raw timestamps.
    • All call sites for get_screenshare_as_content_events / any callers updated to the new signature to avoid API mismatches.
🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ⚠️ Warning The title describes "presentation minimized events + screenshare as content fixes" but the actual changes focus on generic event extraction refactoring, layout event processing, and screenshare-as-content handling within bounded time windows. The "presentation minimized events" mentioned in the title does not appear in the actual changeset based on the raw summary. Update the title to accurately reflect the main changes: consider something like "refactor(recording): generalize event extraction with time-bounded windows" or "fix(recording): add time-bounded screenshare and layout event extraction"
✅ Passed checks (1 passed)
Check name Status Explanation
Description check ✅ Passed The pull request description clearly relates to the changeset: it explains the purpose of extracting event handling logic, tracking presentation/screenshare state, and ensuring events are bounded by recording times.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (5)
record-and-playback/core/lib/recordandplayback/generators/events.rb (3)

412-437: Annotate start events with source to enable correct pairing.

Mark SetScreenshareAsContentEvent-derived starts as :content and real starts as :stream so the matcher can avoid cross-pairing.

-      events.xpath('/recording/event[@module="Deskshare" or (@module="bbb-webrtc-sfu" and @eventname="StartWebRTCDesktopShareEvent") or @eventname="SetScreenshareAsContentEvent"]').each do |start_event|
+      events.xpath('/recording/event[@module="Deskshare" or (@module="bbb-webrtc-sfu" and @eventname="StartWebRTCDesktopShareEvent") or @eventname="SetScreenshareAsContentEvent"]').each do |start_event|
+        source = :stream
         case start_event['eventname']
         when 'DeskshareStartedEvent'
           filename = start_event.at_xpath('file').text
           filename = File.basename(filename)
         when 'StartWebRTCDesktopShareEvent'
           uri = start_event.at_xpath('filename').text
           filename = File.basename(uri)
         when 'SetScreenshareAsContentEvent'
           screenshare_as_content = start_event.at_xpath('screenshareAsContent')&.text == "true"
           if screenshare_as_content && !active_deskshare_video.nil?
             filename = active_deskshare_video
+            source = :content
           else
             next
           end
         else
           next
         end
 
         start_events << {
           start_timestamp: start_event['timestamp'].to_i,
-          stream: filename
+          stream: filename,
+          source: source,
         }
         active_deskshare_video = filename

Also applies to: 421-428


444-466: Track classic Deskshare starts and tag stop events with source.

Without capturing DeskshareStartedEvent here, SetScreenshareAsContentEvent with false won't emit a stop for legacy deskshare. Also tag stop events with :source.

-      events.xpath('/recording/event[@module="Deskshare" or (@module="bbb-webrtc-sfu" and (@eventname="StopWebRTCDesktopShareEvent" or @eventname="StartWebRTCDesktopShareEvent")) or @eventname="SetScreenshareAsContentEvent"]').each do |event|
+      events.xpath('/recording/event[@module="Deskshare" or (@module="bbb-webrtc-sfu" and (@eventname="StopWebRTCDesktopShareEvent" or @eventname="StartWebRTCDesktopShareEvent")) or @eventname="SetScreenshareAsContentEvent"]').each do |event|
+        source = :stream
         case event['eventname']
+        when 'DeskshareStartedEvent'
+          filename = event.at_xpath('file').text
+          filename = File.basename(filename)
+          active_deskshare_video = filename
+          next
         when 'DeskshareStoppedEvent'
           filename = event.at_xpath('file').text
           filename = File.basename(filename)
         when 'StopWebRTCDesktopShareEvent'
           uri = event.at_xpath('filename').text
           filename = File.basename(uri)
         # just used to get the filename to be set when ScreenshareAsContentEvent is used
         when 'StartWebRTCDesktopShareEvent'
           uri = event.at_xpath('filename').text
           filename = File.basename(uri)
           active_deskshare_video = filename
           next
         when 'SetScreenshareAsContentEvent'
           screenshare_as_content = event.at_xpath('screenshareAsContent')&.text == "true"
           if !screenshare_as_content && !active_deskshare_video.nil?
             filename = active_deskshare_video
+            source = :content
           else
             next
           end
         else
           next
         end
 
         stop_events << {
-          stop_timestamp: event['timestamp'].to_i,
-          stream: filename
+          stop_timestamp: event['timestamp'].to_i,
+          stream: filename,
+          source: source,
         }

Also applies to: 471-474


524-541: Guard clause/readability nit for SetScreenshareAsContentEvent handling.

Minor: use guard clauses to reduce nesting.

-        when 'SetScreenshareAsContentEvent'
-          screenshare_as_content = event.at_xpath('screenshareAsContent')&.text == "true"
-          if screenshare_as_content && !active_deskshare_video.nil?
+        when 'SetScreenshareAsContentEvent'
+          screenshare_as_content = event.at_xpath('screenshareAsContent')&.text == "true"
+          next unless (!active_deskshare_video.nil?) # nothing to render without an active file
+          if screenshare_as_content
             video_start_timestamp = videos[active_deskshare_video][:timestamp]
             deskshare_edl << {
               :timestamp => timestamp,
               :areas => {
                 :deskshare => [
                   { :filename => active_deskshare_video, :timestamp => timestamp - video_start_timestamp }
                 ]
               }
             }
           elsif !screenshare_as_content
             deskshare_edl << {
               :timestamp => timestamp,
               :areas => { :deskshare => [] }
             }
           end
record-and-playback/presentation/scripts/publish/presentation.rb (2)

960-970: Emit pan/zoom events on quick swap to keep viewBox/cursor consistent.

When deskshare toggles via SetScreenshareAsContentEvent, panzooms.xml and cursor events won’t update unless panzoom_changed is true. Set it to ensure correct viewBox and cursor mapping at swap boundaries.

     when 'SetScreenshareAsContentEvent'
       if @presentation_props['include_deskshare']
         screenshareAsContent = event.at_xpath('screenshareAsContent')&.text == "true"
         if !screenshareAsContent
           deskshare = false
-          slide_changed = true
+          slide_changed = true
+          panzoom_changed = true
         else
-          deskshare = slide_changed = true
+          deskshare = true
+          slide_changed = true
+          panzoom_changed = true
         end
       end

951-959: Also mark pan/zoom changed on deskshare start/stop.

Symmetry with quick swap: ensure viewBox updates when screenshare starts/stops without quick swap.

     when 'DeskshareStartedEvent', 'StartWebRTCDesktopShareEvent'
-      deskshare = slide_changed = true if @presentation_props['include_deskshare']
+      if @presentation_props['include_deskshare']
+        deskshare = true
+        slide_changed = true
+        panzoom_changed = true
+      end
 
     when 'DeskshareStoppedEvent', 'StopWebRTCDesktopShareEvent'
       if @presentation_props['include_deskshare']
         deskshare = false
         slide_changed = true
+        panzoom_changed = true
       end
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ed612d3 and 2f23acd.

📒 Files selected for processing (2)
  • record-and-playback/core/lib/recordandplayback/generators/events.rb (9 hunks)
  • record-and-playback/presentation/scripts/publish/presentation.rb (1 hunks)
🧰 Additional context used
🪛 RuboCop (1.76.1)
record-and-playback/presentation/scripts/publish/presentation.rb

[convention] 962-962: Prefer single-quoted strings when you don't need string interpolation or special symbols.

(Style/StringLiterals)

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

[convention] 413-413: Line is too long. [202/128]

(Layout/LineLength)


[convention] 422-422: Prefer single-quoted strings when you don't need string interpolation or special symbols.

(Style/StringLiterals)


[convention] 423-423: Use a guard clause (next unless screenshare_as_content && !active_deskshare_video.nil?) instead of wrapping the code inside a conditional expression.

(Style/GuardClause)


[convention] 438-438: Space between { and | missing.

(Layout/SpaceInsideBlockBraces)


[convention] 438-438: Space missing inside }.

(Layout/SpaceInsideBlockBraces)


[convention] 442-442: Prefer single-quoted strings when you don't need string interpolation or special symbols.

(Style/StringLiterals)


[convention] 445-445: Line is too long. [242/128]

(Layout/LineLength)


[convention] 460-460: Prefer single-quoted strings when you don't need string interpolation or special symbols.

(Style/StringLiterals)


[convention] 461-461: Use a guard clause (next unless !screenshare_as_content && !active_deskshare_video.nil?) instead of wrapping the code inside a conditional expression.

(Style/GuardClause)


[convention] 489-489: Use the new Ruby 1.9 hash syntax.

(Style/HashSyntax)


[convention] 490-490: Use the new Ruby 1.9 hash syntax.

(Style/HashSyntax)


[convention] 490-490: Put a comma after the last item of a multiline hash.

(Style/TrailingCommaInHashLiteral)


[convention] 490-490: Use the new Ruby 1.9 hash syntax.

(Style/HashSyntax)


[convention] 493-493: Line is too long. [244/128]

(Layout/LineLength)


[convention] 513-513: Use the new Ruby 1.9 hash syntax.

(Style/HashSyntax)


[convention] 524-524: Prefer single-quoted strings when you don't need string interpolation or special symbols.

(Style/StringLiterals)


[convention] 528-528: Use the new Ruby 1.9 hash syntax.

(Style/HashSyntax)


[convention] 529-529: Use the new Ruby 1.9 hash syntax.

(Style/HashSyntax)


[convention] 530-530: Use the new Ruby 1.9 hash syntax.

(Style/HashSyntax)


[convention] 531-531: Put a comma after the last item of a multiline array.

(Style/TrailingCommaInArrayLiteral)


[convention] 531-531: Use the new Ruby 1.9 hash syntax.

(Style/HashSyntax)


[convention] 531-531: Use the new Ruby 1.9 hash syntax.

(Style/HashSyntax)


[convention] 532-532: Put a comma after the last item of a multiline hash.

(Style/TrailingCommaInHashLiteral)


[convention] 533-533: Put a comma after the last item of a multiline hash.

(Style/TrailingCommaInHashLiteral)


[convention] 537-537: Use the new Ruby 1.9 hash syntax.

(Style/HashSyntax)


[convention] 538-538: Use the new Ruby 1.9 hash syntax.

(Style/HashSyntax)


[convention] 538-538: Put a comma after the last item of a multiline hash.

(Style/TrailingCommaInHashLiteral)


[convention] 538-538: Use the new Ruby 1.9 hash syntax.

(Style/HashSyntax)


[convention] 1073-1073: Line is too long. [149/128]

(Layout/LineLength)


[convention] 1102-1102: Prefer single-quoted strings when you don't need string interpolation or special symbols.

(Style/StringLiterals)


[convention] 1104-1104: Prefer single-quoted strings when you don't need string interpolation or special symbols.

(Style/StringLiterals)


[convention] 1107-1107: Prefer single-quoted strings when you don't need string interpolation or special symbols.

(Style/StringLiterals)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build-package (bbb-playback-record)
🔇 Additional comments (1)
record-and-playback/core/lib/recordandplayback/generators/events.rb (1)

1073-1073: Confirm presentation-usage semantics for quick swap.

Returning true on “screenshare unset as content” treats non-content periods as presentation usage. Verify this aligns with analytics/UI expectations and doesn’t regress recordings where no whiteboard/presentation activity occurred.

Also applies to: 1101-1108

Comment on lines 396 to 402
stop = stop_events.find do |s|
s[:stream] == start[:stream] && s[:stop_timestamp] >= start[:start_timestamp]
end
if stop
start[:stop_timestamp] = stop[:stop_timestamp]
stop_events.delete(stop)
else

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Avoid overlapping deskshare intervals: match content-to-content first.

Current matching pairs the earliest stop ≥ start for the same stream, which can overlap intervals when SetScreenshareAsContentEvent toggles exist (e.g., Start → Content ON → Content OFF → Stop). Prefer pairing start/stop by source (content vs. stream) first, then fall back to any stop if none exists.

Apply this diff to prefer same-source matching:

-      start_events.each do |start|
-        stop = stop_events.find do |s|
-          s[:stream] == start[:stream] && s[:stop_timestamp] >= start[:start_timestamp]
-        end
+      start_events.each do |start|
+        # Prefer a stop from the same source (e.g., content-toggle to content-toggle)
+        stop = stop_events.find do |s|
+          s[:stream] == start[:stream] &&
+            s[:stop_timestamp] >= start[:start_timestamp] &&
+            s[:source] == start[:source]
+        end
+        # Fallback: any stop that is ≥ start for the same stream
+        stop ||= stop_events.find do |s|
+          s[:stream] == start[:stream] && s[:stop_timestamp] >= start[:start_timestamp]
+        end
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
stop = stop_events.find do |s|
s[:stream] == start[:stream] && s[:stop_timestamp] >= start[:start_timestamp]
end
if stop
start[:stop_timestamp] = stop[:stop_timestamp]
stop_events.delete(stop)
else
start_events.each do |start|
# Prefer a stop from the same source (e.g., content-toggle to content-toggle)
stop = stop_events.find do |s|
s[:stream] == start[:stream] &&
s[:stop_timestamp] >= start[:start_timestamp] &&
s[:source] == start[:source]
end
# Fallback: any stop that is ≥ start for the same stream
stop ||= stop_events.find do |s|
s[:stream] == start[:stream] && s[:stop_timestamp] >= start[:start_timestamp]
end
if stop
start[:stop_timestamp] = stop[:stop_timestamp]
stop_events.delete(stop)
else
🤖 Prompt for AI Agents
In record-and-playback/core/lib/recordandplayback/generators/events.rb around
lines 396 to 402, the current logic matches a start to the first stop with the
same stream and stop_timestamp >= start_timestamp which can create overlapping
deskshare intervals when SetScreenshareAsContentEvent toggles change the source;
update the matching to first try finding a stop with the same stream AND the
same source/type (i.e., content vs. non-content) with stop_timestamp >=
start_timestamp, and only if that fails fall back to finding any stop for the
same stream with stop_timestamp >= start_timestamp; when a stop is chosen, set
start[:stop_timestamp] = stop[:stop_timestamp] and delete the stop from
stop_events as before.

@antobinary antobinary added this to the Release 3.0 milestone Sep 17, 2025
@antobinary

Copy link
Copy Markdown
Member

Thank you!

@antobinary antobinary assigned antobinary and unassigned antobinary Sep 19, 2025
@antobinary
antobinary self-requested a review September 19, 2025 19:23

@kepstin kepstin left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is implemented at the wrong level in the code, and this is going to cause problems for the dynamic layout work that I'm designing for the video format right now.

The important thing is that the EDL data structures are intended to represent the times when a video is being shared vs. when it is not being shared. The placement of those areas within the video is decided separately.

Keep in mind that the "SetScreenshareAsContentEvent" is actually supposed to swap the positions of the presentation area and screenshare, and in some layouts both areas might be shown at the same time. So the deskshare video must still be added to the EDL regardless of whether the screenshare as content flag is set or not.

At this point I'm not totally sure about how to actually represent this data. I was planning to proceed with having the swap events tracked separately (i.e. in the format generated by the get_screenshare_as_content_events) and then using that in the video renderer to select between one of two different layouts.

@kepstin

kepstin commented Sep 19, 2025 •

Copy link
Copy Markdown
Contributor

FWIW, I do not believe that this magnitude of change is suitable for inclusion in 3.0.

An acceptable change would be fixing the get_screenshare_as_content_events method to correctly take into account recording start/stop times.

@germanocaumo

germanocaumo commented Sep 22, 2025 •

Copy link
Copy Markdown
Contributor Author

@kepstin Hmm ok I see, didn't think about this dynamic layout possibility.
Ok I can fix get_screenshare_as_content_events instead (was doing that initially already), and you do the work in the video render script?

@kepstin

kepstin commented Sep 22, 2025

Copy link
Copy Markdown
Contributor

Yes - I'm hopeful to have something ready on the video renderer fairly soon, although I will be submitting that change only for 3.1 (it depends on some changes made in #23887 )

@germanocaumo germanocaumo changed the title fix(recording): screenshare quick swap in presentation and video formats fix(recording): screenshare quick swap thumbnails in presentation playback Sep 24, 2025

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
record-and-playback/core/lib/recordandplayback/generators/events.rb (1)

1175-1182: Nil-safe chain bug: &. used only on text, not on to_i

event.at_xpath('timestampUTC')&.text.to_i will call to_i on nil when the node is absent, raising NoMethodError. Chain the safe nav through to_i (or provide a fallback).

Apply this diff:

 screenshare_content_events << {
   timestamp: event['timestamp'].to_i,
-  timestampUTC: event.at_xpath('timestampUTC')&.text.to_i,
+  timestampUTC: event.at_xpath('timestampUTC')&.text&.to_i,
   date: event.at_xpath('date')&.text,
   screenshareAsContent: event.at_xpath('screenshareAsContent')&.text == "true"
 }
🧹 Nitpick comments (1)
record-and-playback/presentation/scripts/publish/presentation.rb (1)

960-970: Handle SetScreenshareAsContentEvent: OK, but align string style with RuboCop

Logic matches existing deskshare toggles. RuboCop prefers single quotes where interpolation isn’t needed.

Apply this diff:

-      if @presentation_props['include_deskshare']
-        screenshareAsContent = event.at_xpath('screenshareAsContent')&.text == "true"
+      if @presentation_props['include_deskshare']
+        screenshareAsContent = event.at_xpath('screenshareAsContent')&.text == 'true'
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2f23acd and 2cbd9b1.

📒 Files selected for processing (2)
  • record-and-playback/core/lib/recordandplayback/generators/events.rb (1 hunks)
  • record-and-playback/presentation/scripts/publish/presentation.rb (2 hunks)
🧰 Additional context used
🪛 RuboCop (1.80.2)
record-and-playback/presentation/scripts/publish/presentation.rb

[convention] 962-962: Prefer single-quoted strings when you don't need string interpolation or special symbols.

(Style/StringLiterals)


[convention] 1333-1333: Avoid comma after the last parameter of a method call.

(Style/TrailingCommaInArguments)


[convention] 1343-1343: Avoid comma after the last parameter of a method call.

(Style/TrailingCommaInArguments)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build-package (bbb-playback-record)
🔇 Additional comments (1)
record-and-playback/core/lib/recordandplayback/generators/events.rb (1)

1183-1183: Deterministic ordering: good addition

Sorting screenshare-as-content events by timestamp removes ordering nondeterminism and aligns with per-segment emission.

Comment on lines +1327 to +1347
@rec_events.each do |re|
# consider the last swap event before the current recording start
last_event_before_start = swap_events.select { |e| e[:timestamp].to_i < re[:start_timestamp] }.last
if last_event_before_start && last_event_before_start[:timestamp].to_i < re[:stop_timestamp]
@layout_swap_xml.event(
timestamp: (translate_timestamp(last_event_before_start[:timestamp].to_f) / 1000).round(1),
show_screenshare: last_event_before_start[:screenshareAsContent],
)
end

swap_events.each do |event|
timestamp = event[:timestamp].to_i
next unless (timestamp >= re[:start_timestamp]) && (timestamp <= re[:stop_timestamp])

@layout_swap_xml.event(
timestamp: (translate_timestamp(event[:timestamp].to_f) / 1000).round(1),
show_screenshare: event[:screenshareAsContent],
)
end
end
end

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Avoid duplicate swap event at recording segment start and drop trailing commas

  • If there’s a swap event exactly at re[:start_timestamp] and a prior swap state, both get translated to the same output timestamp, producing duplicate entries. Emit the prior state only when it adds information (i.e., there’s no event at the exact start, or it differs from the first in‑segment state).
  • Remove trailing commas per RuboCop’s Style/TrailingCommaInArguments.

Apply this diff:

-  @layout_swap_xml.recording('id' => 'layout_swap_events') do
-    @rec_events.each do |re|
-      # consider the last swap event before the current recording start
-      last_event_before_start = swap_events.select { |e| e[:timestamp].to_i < re[:start_timestamp] }.last
-      if last_event_before_start && last_event_before_start[:timestamp].to_i < re[:stop_timestamp]
-        @layout_swap_xml.event(
-          timestamp: (translate_timestamp(last_event_before_start[:timestamp].to_f) / 1000).round(1),
-          show_screenshare: last_event_before_start[:screenshareAsContent],
-        )
-      end
-
-      swap_events.each do |event|
-        timestamp = event[:timestamp].to_i
-        next unless (timestamp >= re[:start_timestamp]) && (timestamp <= re[:stop_timestamp])
-
-        @layout_swap_xml.event(
-          timestamp: (translate_timestamp(event[:timestamp].to_f) / 1000).round(1),
-          show_screenshare: event[:screenshareAsContent],
-        )
-      end
-    end
-  end
+  @layout_swap_xml.recording('id' => 'layout_swap_events') do
+    @rec_events.each do |re|
+      # last swap before segment start
+      last_before = swap_events.select { |e| e[:timestamp].to_i < re[:start_timestamp] }.last
+      # first swap within segment
+      first_in_seg = swap_events.find { |e| (t = e[:timestamp].to_i) >= re[:start_timestamp] && t <= re[:stop_timestamp] }
+
+      if last_before &&
+         (first_in_seg.nil? ||
+          first_in_seg[:timestamp].to_i > re[:start_timestamp] ||
+          first_in_seg[:screenshareAsContent] != last_before[:screenshareAsContent])
+        @layout_swap_xml.event(
+          timestamp: (translate_timestamp(last_before[:timestamp].to_f) / 1000).round(1),
+          show_screenshare: last_before[:screenshareAsContent]
+        )
+      end
+
+      swap_events.each do |event|
+        timestamp = event[:timestamp].to_i
+        next unless (timestamp >= re[:start_timestamp]) && (timestamp <= re[:stop_timestamp])
+
+        @layout_swap_xml.event(
+          timestamp: (translate_timestamp(event[:timestamp].to_f) / 1000).round(1),
+          show_screenshare: event[:screenshareAsContent]
+        )
+      end
+    end
+  end
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@rec_events.each do |re|
# consider the last swap event before the current recording start
last_event_before_start = swap_events.select { |e| e[:timestamp].to_i < re[:start_timestamp] }.last
if last_event_before_start && last_event_before_start[:timestamp].to_i < re[:stop_timestamp]
@layout_swap_xml.event(
timestamp: (translate_timestamp(last_event_before_start[:timestamp].to_f) / 1000).round(1),
show_screenshare: last_event_before_start[:screenshareAsContent],
)
end
swap_events.each do |event|
timestamp = event[:timestamp].to_i
next unless (timestamp >= re[:start_timestamp]) && (timestamp <= re[:stop_timestamp])
@layout_swap_xml.event(
timestamp: (translate_timestamp(event[:timestamp].to_f) / 1000).round(1),
show_screenshare: event[:screenshareAsContent],
)
end
end
end
@layout_swap_xml.recording('id' => 'layout_swap_events') do
@rec_events.each do |re|
# last swap before segment start
last_before = swap_events.select { |e| e[:timestamp].to_i < re[:start_timestamp] }.last
# first swap within segment
first_in_seg = swap_events.find { |e| (t = e[:timestamp].to_i) >= re[:start_timestamp] && t <= re[:stop_timestamp] }
if last_before &&
(first_in_seg.nil? ||
first_in_seg[:timestamp].to_i > re[:start_timestamp] ||
first_in_seg[:screenshareAsContent] != last_before[:screenshareAsContent])
@layout_swap_xml.event(
timestamp: (translate_timestamp(last_before[:timestamp].to_f) / 1000).round(1),
show_screenshare: last_before[:screenshareAsContent]
)
end
swap_events.each do |event|
timestamp = event[:timestamp].to_i
next unless (timestamp >= re[:start_timestamp]) && (timestamp <= re[:stop_timestamp])
@layout_swap_xml.event(
timestamp: (translate_timestamp(event[:timestamp].to_f) / 1000).round(1),
show_screenshare: event[:screenshareAsContent]
)
end
end
end
🧰 Tools
🪛 RuboCop (1.80.2)

[convention] 1333-1333: Avoid comma after the last parameter of a method call.

(Style/TrailingCommaInArguments)


[convention] 1343-1343: Avoid comma after the last parameter of a method call.

(Style/TrailingCommaInArguments)

🤖 Prompt for AI Agents
In record-and-playback/presentation/scripts/publish/presentation.rb around lines
1327 to 1347, the code can emit a duplicate layout swap event when there is a
prior swap whose translated timestamp equals a swap event at
re[:start_timestamp], and it also contains trailing commas; change the logic so
you only emit the prior last_event_before_start when there is no in-segment swap
event at exactly re[:start_timestamp] or when that first in-segment event has a
different screenshareAsContent (i.e., compare the prior state to the first
matching swap_events entry and skip emitting the prior if they produce the same
logical state/timestamp), and remove trailing commas from the
@layout_swap_xml.event calls' argument lists to satisfy RuboCop
Style/TrailingCommaInArguments.

@germanocaumo

Copy link
Copy Markdown
Contributor Author

@kepstin can you review again?

@germanocaumo
germanocaumo requested a review from kepstin October 3, 2025 16:24

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
record-and-playback/core/lib/recordandplayback/generators/events.rb (1)

1185-1215: Approve the event loop logic with optional style improvements.

The event scanning and state tracking logic correctly handles:

  • Time windowing with start_time/end_time boundaries
  • Offset adjustment for pause/resume cycles
  • Preservation of last_screenshare_as_content state across recording segments

The logic properly emits events only during active recording periods and maintains 0-based timestamps within the recording window.

Optional style improvements:

Per RuboCop, consider these minor style adjustments:

-          last_screenshare_as_content = event.at_xpath('screenshareAsContent')&.text == "true"
+          last_screenshare_as_content = event.at_xpath('screenshareAsContent')&.text == 'true'

-          screenshareAsContent = event.at_xpath('screenshareAsContent')&.text == "true"
+          screenshareAsContent = event.at_xpath('screenshareAsContent')&.text == 'true'

-            screenshare_content_events << {
-              timestamp: timestamp - offset,
-              screenshareAsContent: last_screenshare_as_content,
-            } if !last_screenshare_as_content.nil?
+            if !last_screenshare_as_content.nil?
+              screenshare_content_events << {
+                timestamp: timestamp - offset,
+                screenshareAsContent: last_screenshare_as_content
+              }
+            end
record-and-playback/presentation/scripts/publish/presentation.rb (2)

960-969: Approve the SetScreenshareAsContentEvent logic with optional simplification.

The event handling correctly toggles deskshare state and marks slide changes. The guard clause using next unless follows the suggested pattern.

Optional simplification:

Since slide_changed is always set to true, the logic can be streamlined:

     when 'SetScreenshareAsContentEvent'
       next unless @presentation_props['include_deskshare']
+
-      screenshare_as_content = event.at_xpath('screenshareAsContent')&.text == "true"
-      if screenshare_as_content
-        deskshare = slide_changed = true
-      else
-        deskshare = false
-        slide_changed = true
-      end
+      screenshare_as_content = event.at_xpath('screenshareAsContent')&.text == 'true'
+      deskshare = screenshare_as_content
+      slide_changed = true

This also addresses the RuboCop hints for empty line after guard clause and single-quoted strings.


1319-1333: Verify initial state handling for screenshare-as-content.

The updated implementation correctly delegates time windowing to get_screenshare_as_content_events and avoids the quadratic translate_timestamp calls. However, please verify the following scenario:

Scenario:

  • Recording starts at timestamp 1000
  • A SetScreenshareAsContentEvent occurs at timestamp 500 (before recording) with screenshareAsContent=true
  • No SetScreenshareAsContentEvent occurs during the recording window

Question:
Should an initial state event be emitted at the recording start (timestamp 1000) to indicate that screenshare-as-content is active? Currently, get_screenshare_as_content_events filters events by timestamp >= start_time, so no event would be emitted in this scenario.

If the playback needs to know the initial state, consider emitting the prior state at segment start when no in-segment event exists.

Optional: Remove trailing comma (RuboCop Style/TrailingCommaInArguments):

       @layout_swap_xml.event(
         timestamp: (event[:timestamp].to_f / 1000.0).round(1),
-        show_screenshare: event[:screenshareAsContent],
+        show_screenshare: event[:screenshareAsContent]
       )
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2cbd9b1 and 668cd27.

📒 Files selected for processing (2)
  • record-and-playback/core/lib/recordandplayback/generators/events.rb (1 hunks)
  • record-and-playback/presentation/scripts/publish/presentation.rb (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
record-and-playback/presentation/scripts/publish/presentation.rb (1)
record-and-playback/core/lib/recordandplayback/generators/events.rb (1)
  • get_screenshare_as_content_events (1170-1217)
🪛 RuboCop (1.81.1)
record-and-playback/presentation/scripts/publish/presentation.rb

[convention] 961-961: Add empty line after guard clause.

(Layout/EmptyLineAfterGuardClause)


[convention] 962-962: Prefer single-quoted strings when you don't need string interpolation or special symbols.

(Style/StringLiterals)

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

[convention] 1191-1191: Prefer single-quoted strings when you don't need string interpolation or special symbols.

(Style/StringLiterals)


[convention] 1194-1194: Prefer single-quoted strings when you don't need string interpolation or special symbols.

(Style/StringLiterals)


[convention] 1206-1209: Favor a normal if-statement over a modifier clause in a multiline statement.

(Style/MultilineIfModifier)


[convention] 1206-1209: Favor unless over if for negative conditions.

(Style/NegatedIf)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build-package (bbb-playback-record)
🔇 Additional comments (2)
record-and-playback/core/lib/recordandplayback/generators/events.rb (2)

1170-1170: LGTM: Method signature updated for segment support.

The addition of start_time and end_time parameters aligns with the pattern used in get_chat_events and supports per-segment recording processing as intended.


1171-1180: LGTM: Time anchoring logic is correct.

The computation of initial_timestamp and adjustment of start_time/end_time to 0-based timestamps is consistent with the pattern used in get_chat_events and correctly handles recordings without status events.

@kepstin

kepstin commented Oct 29, 2025 •

Copy link
Copy Markdown
Contributor

I've pushed an update to this with the following changes:

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 code 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 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.

@germanocaumo I'd appreciate you taking a look through my modified code and testing it to make sure it works as expected.

@germanocaumo

Copy link
Copy Markdown
Contributor Author

@kepstin sorry I'm on vacation, will only be able to test it properly when back 10th

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 668cd27 and 5512153.

📒 Files selected for processing (1)
  • record-and-playback/core/lib/recordandplayback/generators/events.rb (1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2025-09-11T20:23:35.575Z
Learnt from: kepstin
PR: bigbluebutton/bigbluebutton#23887
File: record-and-playback/video/scripts/process/video.rb:117-123
Timestamp: 2025-09-11T20:23:35.575Z
Learning: In BigBlueButton's events.xml files, metadata is stored as attributes on <meta> elements under the <metadata> section, not as child elements. When using Nokogiri to parse events.xml, metadata attributes should be accessed using bracket notation like metadata['attribute-name'], not XPath element lookups.

Applied to files:

  • record-and-playback/core/lib/recordandplayback/generators/events.rb
📚 Learning: 2025-09-11T20:23:35.575Z
Learnt from: kepstin
PR: bigbluebutton/bigbluebutton#23887
File: record-and-playback/video/scripts/process/video.rb:117-123
Timestamp: 2025-09-11T20:23:35.575Z
Learning: In BigBlueButton's events.xml files, metadata is stored as attributes on the <metadata> element (e.g., <metadata bbb-recording-video-preset="720p" meetingName="Demo Meeting"/>). When using Nokogiri to parse events.xml in Ruby, metadata attributes should be accessed using bracket notation like metadata['attribute-name'], not XPath element lookups like metadata.at_xpath('element-name').

Applied to files:

  • record-and-playback/core/lib/recordandplayback/generators/events.rb
📚 Learning: 2025-09-11T20:23:35.575Z
Learnt from: kepstin
PR: bigbluebutton/bigbluebutton#23887
File: record-and-playback/video/scripts/process/video.rb:117-123
Timestamp: 2025-09-11T20:23:35.575Z
Learning: In BigBlueButton's events.xml files, metadata is stored as attributes on the <metadata> element (e.g., <metadata bbb-recording-video-preset="720p" meetingName="Demo"/>). When using Nokogiri to parse events.xml, metadata attributes should be accessed using bracket notation like metadata['attribute-name'], not XPath element lookups.

Applied to files:

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

@sonarqubecloud

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5512153 and 3f5d66f.

📒 Files selected for processing (1)
  • record-and-playback/core/lib/recordandplayback/generators/events.rb (1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2025-09-11T20:23:35.575Z
Learnt from: kepstin
PR: bigbluebutton/bigbluebutton#23887
File: record-and-playback/video/scripts/process/video.rb:117-123
Timestamp: 2025-09-11T20:23:35.575Z
Learning: In BigBlueButton's events.xml files, metadata is stored as attributes on <meta> elements under the <metadata> section, not as child elements. When using Nokogiri to parse events.xml, metadata attributes should be accessed using bracket notation like metadata['attribute-name'], not XPath element lookups.

Applied to files:

  • record-and-playback/core/lib/recordandplayback/generators/events.rb
📚 Learning: 2025-09-11T20:23:35.575Z
Learnt from: kepstin
PR: bigbluebutton/bigbluebutton#23887
File: record-and-playback/video/scripts/process/video.rb:117-123
Timestamp: 2025-09-11T20:23:35.575Z
Learning: In BigBlueButton's events.xml files, metadata is stored as attributes on the <metadata> element (e.g., <metadata bbb-recording-video-preset="720p" meetingName="Demo Meeting"/>). When using Nokogiri to parse events.xml in Ruby, metadata attributes should be accessed using bracket notation like metadata['attribute-name'], not XPath element lookups like metadata.at_xpath('element-name').

Applied to files:

  • record-and-playback/core/lib/recordandplayback/generators/events.rb
📚 Learning: 2025-09-11T20:23:35.575Z
Learnt from: kepstin
PR: bigbluebutton/bigbluebutton#23887
File: record-and-playback/video/scripts/process/video.rb:117-123
Timestamp: 2025-09-11T20:23:35.575Z
Learning: In BigBlueButton's events.xml files, metadata is stored as attributes on the <metadata> element (e.g., <metadata bbb-recording-video-preset="720p" meetingName="Demo"/>). When using Nokogiri to parse events.xml, metadata attributes should be accessed using bracket notation like metadata['attribute-name'], not XPath element lookups.

Applied to files:

  • record-and-playback/core/lib/recordandplayback/generators/events.rb
🔇 Additional comments (2)
record-and-playback/core/lib/recordandplayback/generators/events.rb (2)

1231-1244: The fallback logic for initial event emission only runs for non-critical event types.

This "else" branch correctly handles emitting an initial event at timestamp: 0 when start_time falls mid-segment, but only executes for events that are neither SetScreenshareAsContentEvent nor RecordStatusEvent.

While most recordings contain various event types (chat, participant joins, etc.) that would trigger this branch, edge cases exist where the first event after start_time is a SetScreenshareAsContentEvent or RecordStatusEvent, causing the initial state to be emitted at the wrong timestamp as noted in previous comments.

The logic here is sound for its intended purpose. However, consider adding similar initial-event checks at the beginning of the other two event type handlers to ensure complete coverage.


1210-1229: Similar initial event timing concern applies to recording resume.

When recording resumes (line 1215), the code emits an event to re-establish the current screenshare_as_content state. However, if this is the first event after start_time and screenshare_as_content was set before start_time, the event timing may not correctly reflect the segment start.

The duplicate check on line 1220 correctly handles the case where screenshare_as_content is nil (no state set yet), preventing emission of events with nil state. However, the same initial-event-at-timestamp-0 concern from the SetScreenshareAsContentEvent case applies here.

Consider applying similar logic as suggested for the SetScreenshareAsContentEvent case:

  when %w[PARTICIPANT RecordStatusEvent]
    record = event.at_xpath('status').content == 'true'
    # Don't update timestamps until we're past the segment start time
    next unless timestamp >= start_time

    if record
+     # Emit initial event if this is the first event in the segment and state was set before segment start
+     if screenshare_content_events.empty? && !screenshare_as_content.nil?
+       screenshare_content_events << {
+         timestamp: 0,
+         screenshareAsContent: screenshare_as_content,
+       }
+     end
+
      # Recording resumed; update offset to account for the timestamp jump
      offset += timestamp - last_stop_timestamp

-     # Don't emit an event if the previous event has the same state
-     next if screenshare_content_events.dig(-1, :screenshareAsContent) == screenshare_as_content
-
-     screenshare_content_events << {
-       timestamp: timestamp - offset,
-       screenshareAsContent: screenshare_as_content,
-     }
    else
      # Recording paused
      last_stop_timestamp = timestamp
    end

Likely an incorrect or invalid review comment.

Comment on lines 1186 to 1191
last_stop_timestamp = start_time
offset = start_time
# Recordings without status events are assumed to have been recorded from the beginning
record = events.at_xpath('/recording/event[@eventname="RecordStatusEvent"]').nil?

screenshare_content_events = []

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Initialize screenshare_as_content before the event loop.

The variable screenshare_as_content is assigned within the SetScreenshareAsContentEvent case (line 1199) but is referenced in other branches (lines 1220, 1238) before it might be set. While Ruby's scoping allows this, explicitly initializing it to nil before the loop improves code clarity and prevents potential undefined variable errors.

Apply this diff:

   # Recordings without status events are assumed to have been recorded from the beginning
   record = events.at_xpath('/recording/event[@eventname="RecordStatusEvent"]').nil?
+  screenshare_as_content = nil

   screenshare_content_events = []
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
last_stop_timestamp = start_time
offset = start_time
# Recordings without status events are assumed to have been recorded from the beginning
record = events.at_xpath('/recording/event[@eventname="RecordStatusEvent"]').nil?
screenshare_content_events = []
last_stop_timestamp = start_time
offset = start_time
# Recordings without status events are assumed to have been recorded from the beginning
record = events.at_xpath('/recording/event[@eventname="RecordStatusEvent"]').nil?
screenshare_as_content = nil
screenshare_content_events = []
🤖 Prompt for AI Agents
In record-and-playback/core/lib/recordandplayback/generators/events.rb around
lines 1186 to 1191, the variable screenshare_as_content is assigned inside the
SetScreenshareAsContentEvent branch but referenced in other branches before it
may be set; explicitly initialize screenshare_as_content = nil before the
event-processing loop (e.g., alongside screenshare_content_events
initialization) so it is defined and clear to readers.

record = events.at_xpath('/recording/event[@eventname="RecordStatusEvent"]').nil?

screenshare_content_events = []
last_screenshare_as_content = nil

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing screenshare_as_content initialization here?

@germanocaumo

Copy link
Copy Markdown
Contributor Author

@kepstin It looks good, only seems to be missing the screenshare_as_content variable initialization.

@sonarqubecloud

sonarqubecloud Bot commented Dec 8, 2025

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
record-and-playback/core/lib/recordandplayback/generators/events.rb (1)

1170-1259: Well-designed generic event extraction with proper recording mark handling.

The implementation correctly addresses the concerns from past reviews:

  • current_state is initialized to nil before the loop (line 1195)
  • Offset calculation properly handles recording start/stop events
  • Initial state emission at timestamp 0 when segment starts mid-recording

The else branch (lines 1245-1256) elegantly handles the edge case where start_time falls inside an active recording segment by emitting the prior state at timestamp 0 upon encountering the first event within bounds.

The duplicate state comparison logic (lines 1209-1216 and 1231-1238) could be extracted into a helper:

def self.state_unchanged?(extracted_events, current_state, compare_keys)
  return false unless extracted_events.last
  last_event = extracted_events.last.reject { |k| k == :timestamp }
  if compare_keys
    last_event.slice(*compare_keys) == current_state.slice(*compare_keys)
  else
    last_event == current_state
  end
end

Also, fix trailing whitespace on line 1207.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3f5d66f and da00877.

📒 Files selected for processing (2)
  • record-and-playback/core/lib/recordandplayback/generators/events.rb (1 hunks)
  • record-and-playback/presentation/scripts/publish/presentation.rb (3 hunks)
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2025-09-11T20:23:35.575Z
Learnt from: kepstin
Repo: bigbluebutton/bigbluebutton PR: 23887
File: record-and-playback/video/scripts/process/video.rb:117-123
Timestamp: 2025-09-11T20:23:35.575Z
Learning: In BigBlueButton's events.xml files, metadata is stored as attributes on <meta> elements under the <metadata> section, not as child elements. When using Nokogiri to parse events.xml, metadata attributes should be accessed using bracket notation like metadata['attribute-name'], not XPath element lookups.

Applied to files:

  • record-and-playback/core/lib/recordandplayback/generators/events.rb
📚 Learning: 2025-09-11T20:23:35.575Z
Learnt from: kepstin
Repo: bigbluebutton/bigbluebutton PR: 23887
File: record-and-playback/video/scripts/process/video.rb:117-123
Timestamp: 2025-09-11T20:23:35.575Z
Learning: In BigBlueButton's events.xml files, metadata is stored as attributes on the <metadata> element (e.g., <metadata bbb-recording-video-preset="720p" meetingName="Demo Meeting"/>). When using Nokogiri to parse events.xml in Ruby, metadata attributes should be accessed using bracket notation like metadata['attribute-name'], not XPath element lookups like metadata.at_xpath('element-name').

Applied to files:

  • record-and-playback/core/lib/recordandplayback/generators/events.rb
📚 Learning: 2025-09-11T20:23:35.575Z
Learnt from: kepstin
Repo: bigbluebutton/bigbluebutton PR: 23887
File: record-and-playback/video/scripts/process/video.rb:117-123
Timestamp: 2025-09-11T20:23:35.575Z
Learning: In BigBlueButton's events.xml files, metadata is stored as attributes on the <metadata> element (e.g., <metadata bbb-recording-video-preset="720p" meetingName="Demo"/>). When using Nokogiri to parse events.xml, metadata attributes should be accessed using bracket notation like metadata['attribute-name'], not XPath element lookups.

Applied to files:

  • record-and-playback/core/lib/recordandplayback/generators/events.rb
🧬 Code graph analysis (1)
record-and-playback/presentation/scripts/publish/presentation.rb (2)
akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/users/UsersApp.scala (1)
  • event (92-92)
record-and-playback/core/lib/recordandplayback/generators/events.rb (2)
  • get_screenshare_as_content_events (1261-1267)
  • get_layout_broadcasted_events (1269-1280)
🪛 RuboCop (1.81.7)
record-and-playback/core/lib/recordandplayback/generators/events.rb

[convention] 1207-1207: Trailing whitespace detected.

(Layout/TrailingWhitespace)


[convention] 1212-1212: Modifier form of if makes the line too long.

(Style/IfUnlessModifier)


[convention] 1212-1212: Line is too long. [135/128]

(Layout/LineLength)


[convention] 1214-1214: Convert if nested inside else to elsif.

(Style/IfInsideElse)


[convention] 1230-1230: Add empty line after guard clause.

(Layout/EmptyLineAfterGuardClause)


[convention] 1234-1234: Modifier form of if makes the line too long.

(Style/IfUnlessModifier)


[convention] 1234-1234: Line is too long. [137/128]

(Layout/LineLength)


[convention] 1236-1236: Convert if nested inside else to elsif.

(Style/IfInsideElse)


[convention] 1262-1262: Line is too long. [129/128]

(Layout/LineLength)


[convention] 1264-1264: Put a comma after the last item of a multiline hash.

(Style/TrailingCommaInHashLiteral)


[convention] 1264-1264: Prefer single-quoted strings when you don't need string interpolation or special symbols.

(Style/StringLiterals)


[convention] 1276-1276: Prefer single-quoted strings when you don't need string interpolation or special symbols.

(Style/StringLiterals)


[convention] 1277-1277: Put a comma after the last item of a multiline hash.

(Style/TrailingCommaInHashLiteral)


[convention] 1277-1277: Prefer single-quoted strings when you don't need string interpolation or special symbols.

(Style/StringLiterals)

record-and-playback/presentation/scripts/publish/presentation.rb

[convention] 961-961: Add empty line after guard clause.

(Layout/EmptyLineAfterGuardClause)


[convention] 962-962: Prefer single-quoted strings when you don't need string interpolation or special symbols.

(Style/StringLiterals)


[convention] 1320-1320: Prefer single-quoted strings when you don't need string interpolation or special symbols.

(Style/StringLiterals)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build-package (bbb-playback-record)
🔇 Additional comments (5)
record-and-playback/presentation/scripts/publish/presentation.rb (3)

960-968: LGTM! Clean implementation of SetScreenshareAsContentEvent handling.

The guard clause pattern and logic correctly mirror the existing deskshare event handling. Minor RuboCop suggestions: add an empty line after the guard clause (line 961) and prefer single-quoted strings for "true" (line 962).


1319-1342: Clean refactor using the new event extraction API.

The implementation correctly merges screenshare and layout events, using the updated helpers that handle recording marks and offset calculation. The key-based attribute selection (show_screenshare vs show_presentation) properly distinguishes event types.

One minor consideration: sort_by { |e| e[:timestamp] } is stable in Ruby 2.7+, so events with identical timestamps maintain their relative order from the concatenation. This should be fine for playback.


1509-1509: LGTM!

Call site correctly updated to use the renamed method.

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

1261-1267: LGTM! Clean delegation to the generic helper.

The compare_keys: [:screenshareAsContent] correctly ensures only meaningful state changes are emitted. Minor RuboCop suggestions: prefer single-quoted strings for "true" and consider adding a trailing comma after the last hash item.


1269-1280: LGTM!

The implementation correctly extracts layout event data. Using [:presentationIsOpen] as compare_keys means events are only emitted when presentation visibility changes, while still capturing the full state (focusedCamera, layout, etc.) for each emission.

Note: &.content.to_f is safe—if the element is missing, nil.to_f returns 0.0 in Ruby.

@germanocaumo germanocaumo changed the title fix(recording): screenshare quick swap thumbnails in presentation playback fix(recording): add presentation minimized events + screenshare as content fixes Dec 8, 2025
@kepstin

kepstin commented Jan 28, 2026 •

Copy link
Copy Markdown
Contributor

In the time since this was originally written, I ended up writing basically the same code to do these events for the video processing here:

# Create a video EDL for layout events
#
# This EDL does not have recording marks pre-applied.
#
# This EDL does not actually define any video areas. It only provides conditions, which reflect
# layout changes pushed by the presenter in the meeting.
#
# The :presentation_is_open condition describes whether the "main content area" (which
# typically contains the presentation area, screensharing, or webcam as content) is currently
# visible. If it is not visible, the webcam grid is expected to fill the entire recording area.
# The :screenshare_as_content conditions describes whether the screenshare replaces the
# presentation in the main content area.
#
# @param events [Nokogiri::XML::Document] the events.xml file
# @return [Array<Hash<Symbol, Object>>] the EDL containing layout conditions
def self.create_layout_edl(events)
initial_timestamp = BigBlueButton::Events.first_event_timestamp(events)
final_timestamp = BigBlueButton::Events.last_event_timestamp(events)
# Assume the presentation is open by default for compatibility
presentation_is_open = true
# Assume screenshare as content (screenshare replaces presentation) is true by default for
# compatibility
screenshare_as_content = true
# Initialize the EDL with the default state
layout_edl = [
{
timestamp: 0,
areas: {},
conditions: {
presentation_is_open: presentation_is_open,
screenshare_as_content: screenshare_as_content,
},
},
]
events.xpath('/recording/event').each do |event|
timestamp = event['timestamp'].to_i - initial_timestamp
case [event['module'], event['eventname']]
when %w[PARTICIPANT LayoutBroadcastedEvent]
pio_el = event.at_xpath('presentationIsOpen')
presentation_is_open = pio_el.content.casecmp?('true') if pio_el
when %w[PARTICIPANT SetScreenshareAsContentEvent]
sac_el = event.at_xpath('screenshareAsContent')
screenshare_as_content = sac_el.content.casecmp?('true') if sac_el
else
next
end
# Don't create a new entry if none of the conditions have changed
next if layout_edl.dig(-1, :conditions, :presentation_is_open) == presentation_is_open &&
layout_edl.dig(-1, :conditions, :screenshare_as_content) == screenshare_as_content
layout_edl << {
timestamp: timestamp,
areas: {},
conditions: {
presentation_is_open: presentation_is_open,
screenshare_as_content: screenshare_as_content,
},
}
end

It might be possible to use this code from the presentation processing scripts rather than implement another method which does basically the same thing.

I think the code would look more or less like this:

layout_edl = BigBlueButton::Events.create_layout_edl(events_xml)
layout_edl = BigBlueButton::Events.edl_match_recording_marks_video(layout_edl, events_xml, start_time, stop_time)

Then layout_edl will contain a structure like this:

[
  {
    timestamp: 0
    areas: {},
    conditions: {
      screenshare_as_content: true,
      presentation_is_open: true,
    }
  },
  {
    timestamp: 720000,
    areas: {},
    conditions: {
      screenshare_as_content: false,
      presentation_is_open: true,
    },
    …
  },
]

which should be straightforwards to map to the desired layout.xml structure. Note that timestamp is in milliseconds.

germanocaumo and others added 6 commits January 30, 2026 12:49
…yback

- Only consider swap events inside recordings.
- Add slides swaps to shapes.svg when quick swap occur so playback can show the slides and thumbnails when screenshare is on for the entire recording.
-- In this case, previously only the screenshare was shown.
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.
- Include the info when presentation is minimized by presenter with push layout on:

<?xml version="1.0" encoding="UTF-8"?>
<recording id="layout_swap_events">
  <event timestamp="0.0" show_screenshare="false"/>
  <event timestamp="6.0" show_screenshare="true"/>
  <event timestamp="12.7" show_screenshare="false"/>
  <event timestamp="19.7" show_presentation="true"/>
  <event timestamp="21.6" show_presentation="false"/>
  <event timestamp="24.8" show_presentation="true"/>
  <event timestamp="29.9" show_presentation="false"/>
</recording>
Refactored the layout event building to use the new create_layout_edl.
Xml generated:

<?xml version="1.0" encoding="UTF-8"?>
<recording id="layout_swap_events">
  <event timestamp="0.0" show_screenshare="false" show_presentation="true"/>
  <event timestamp="10.8" show_screenshare="true" show_presentation="true"/>
  <event timestamp="22.5" show_screenshare="false" show_presentation="true"/>
  <event timestamp="30.4" show_screenshare="true" show_presentation="true"/>
  <event timestamp="43.0" show_screenshare="true" show_presentation="false"/>
  <event timestamp="45.6" show_screenshare="true" show_presentation="true"/>
  <event timestamp="47.1" show_screenshare="true" show_presentation="false"/>
  <event timestamp="48.5" show_screenshare="true" show_presentation="true"/>
</recording>
@sonarqubecloud

sonarqubecloud Bot commented Feb 5, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Feb 5, 2026

Copy link
Copy Markdown

✅ Automated tests have passed!

@germanocaumo
germanocaumo requested a review from kepstin February 5, 2026 20:48
@antobinary
antobinary changed the base branch from v3.0.x-release to v3.0.x-develop April 24, 2026 14:51
@antobinary antobinary mentioned this pull request Apr 28, 2026
12 of 17 tasks
@antobinary
antobinary merged commit b0b5b12 into bigbluebutton:v3.0.x-develop May 5, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants