Skip to content

feat: added trackById and JADM playback sample observer#44

Merged
greenfrvr merged 1 commit into
masterfrom
loopback-recordings
Jun 5, 2026
Merged

feat: added trackById and JADM playback sample observer#44
greenfrvr merged 1 commit into
masterfrom
loopback-recordings

Conversation

@greenfrvr

@greenfrvr greenfrvr commented Jun 4, 2026

Copy link
Copy Markdown

Summary by CodeRabbit

  • New Features
    • Added track retrieval functionality to look up media tracks by unique identifier across platforms
    • Introduced multi-observer callback support for playback sample notifications during audio device operation

@greenfrvr greenfrvr self-assigned this Jun 4, 2026
@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds track-by-ID lookup across Android and iOS, plus a playback-samples observer pattern for Android audio integration. The observer system lets multiple consumers subscribe to audio samples via thread-safe registration/removal. Track lookup scans local tracks first, then iterates peer connections to resolve receivers or senders by ID.

Changes

Track resolution and playback observer management

Layer / File(s) Summary
Android playback observer mechanism
android/src/main/java/com/oney/WebRTCModule/WebRTCModuleOptions.java, android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java
WebRTCModuleOptions imports collection types and introduces a CopyOnWriteArrayList-backed observer list with add, remove, and get methods for JavaAudioDeviceModule.PlaybackSamplesReadyCallback. WebRTCModule integrates a playback callback that safely iterates all registered observers, catching exceptions per observer to prevent audio device thread failures.
Android track lookup by ID
android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java
getTrackById(String trackId) method checks local tracks first, then scans all peer connections to find a receiver track matching the given ID, returning null if no match is found or ID is null.
iOS track lookup by ID
ios/RCTWebRTC/WebRTCModule.h, ios/RCTWebRTC/WebRTCModule.m
Declares and implements trackForId: with identical semantics: validates the ID, queries local tracks, then searches all peer connections' receivers and senders for a matching track ID, returning nil if not found.

🎯 2 (Simple) | ⏱️ ~12 minutes


🐰 A track by any ID, now you can find,
And samples broadcast to observers' mind,
Thread-safe and swift across platforms wide,
Audio streaming with rabbit pride! 🎙️

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the two main additions: getTrackById method and playback sample observer support for JavaAudioDeviceModule.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch loopback-recordings

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

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 (1)
android/src/main/java/com/oney/WebRTCModule/WebRTCModuleOptions.java (1)

81-84: ⚡ Quick win

Don’t expose mutable observer storage directly.

At Line 82, returning the live mutable list lets external callers bypass invariants enforced by add/remove. Return an unmodifiable view instead.

Suggested fix
 import java.nio.ByteBuffer;
+import java.util.Collections;
 import java.util.List;
 ...
     /** Iteration-safe; returns the live CopyOnWriteArrayList. */
     public List<JavaAudioDeviceModule.PlaybackSamplesReadyCallback> getPlaybackSamplesObservers() {
-        return playbackSamplesObservers;
+        return Collections.unmodifiableList(playbackSamplesObservers);
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@android/src/main/java/com/oney/WebRTCModule/WebRTCModuleOptions.java` around
lines 81 - 84, getPlaybackSamplesObservers currently returns the live mutable
playbackSamplesObservers list which allows external callers to modify observer
storage; change getPlaybackSamplesObservers to return an unmodifiable view
(e.g., Collections.unmodifiableList(playbackSamplesObservers)) so callers can
iterate safely without bypassing the class's add/remove invariants — keep the
internal field playbackSamplesObservers mutable and continue using the existing
add/remove methods to manage observers.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@android/src/main/java/com/oney/WebRTCModule/WebRTCModuleOptions.java`:
- Around line 70-75: The addPlaybackSamplesObserver method currently appends
observers unconditionally which allows nulls and duplicates; update
addPlaybackSamplesObserver(JavaAudioDeviceModule.PlaybackSamplesReadyCallback
observer) to validate observer != null and only add if not already present in
playbackSamplesObservers (use playbackSamplesObservers.contains(observer)) to
make registration idempotent—silently ignore (or log) null/duplicate inputs
rather than adding them; this uses the existing playbackSamplesObservers field
and the JavaAudioDeviceModule.PlaybackSamplesReadyCallback type to locate the
change.

---

Nitpick comments:
In `@android/src/main/java/com/oney/WebRTCModule/WebRTCModuleOptions.java`:
- Around line 81-84: getPlaybackSamplesObservers currently returns the live
mutable playbackSamplesObservers list which allows external callers to modify
observer storage; change getPlaybackSamplesObservers to return an unmodifiable
view (e.g., Collections.unmodifiableList(playbackSamplesObservers)) so callers
can iterate safely without bypassing the class's add/remove invariants — keep
the internal field playbackSamplesObservers mutable and continue using the
existing add/remove methods to manage observers.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2d46417f-a642-4b3b-ab69-a555ab209f99

📥 Commits

Reviewing files that changed from the base of the PR and between 3209a9b and 5287c25.

📒 Files selected for processing (4)
  • android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java
  • android/src/main/java/com/oney/WebRTCModule/WebRTCModuleOptions.java
  • ios/RCTWebRTC/WebRTCModule.h
  • ios/RCTWebRTC/WebRTCModule.m

Comment on lines +70 to +75
private final List<JavaAudioDeviceModule.PlaybackSamplesReadyCallback> playbackSamplesObservers =
new CopyOnWriteArrayList<>();

public void addPlaybackSamplesObserver(JavaAudioDeviceModule.PlaybackSamplesReadyCallback observer) {
playbackSamplesObservers.add(observer);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Enforce non-null, de-duplicated observer registration.

At Line 73, registration appends unconditionally. A null or duplicate observer can lead to repeated callback failures or duplicate sample delivery when WebRTCModule fans out observers. Validate input and make add idempotent.

Suggested fix
 import java.nio.ByteBuffer;
 import java.util.List;
+import java.util.Objects;
 import java.util.concurrent.Callable;
 import java.util.concurrent.CopyOnWriteArrayList;
 ...
-    private final List<JavaAudioDeviceModule.PlaybackSamplesReadyCallback> playbackSamplesObservers =
+    private final CopyOnWriteArrayList<JavaAudioDeviceModule.PlaybackSamplesReadyCallback> playbackSamplesObservers =
             new CopyOnWriteArrayList<>();

     public void addPlaybackSamplesObserver(JavaAudioDeviceModule.PlaybackSamplesReadyCallback observer) {
-        playbackSamplesObservers.add(observer);
+        playbackSamplesObservers.addIfAbsent(Objects.requireNonNull(observer, "observer"));
     }
📝 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
private final List<JavaAudioDeviceModule.PlaybackSamplesReadyCallback> playbackSamplesObservers =
new CopyOnWriteArrayList<>();
public void addPlaybackSamplesObserver(JavaAudioDeviceModule.PlaybackSamplesReadyCallback observer) {
playbackSamplesObservers.add(observer);
}
private final CopyOnWriteArrayList<JavaAudioDeviceModule.PlaybackSamplesReadyCallback> playbackSamplesObservers =
new CopyOnWriteArrayList<>();
public void addPlaybackSamplesObserver(JavaAudioDeviceModule.PlaybackSamplesReadyCallback observer) {
playbackSamplesObservers.addIfAbsent(Objects.requireNonNull(observer, "observer"));
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@android/src/main/java/com/oney/WebRTCModule/WebRTCModuleOptions.java` around
lines 70 - 75, The addPlaybackSamplesObserver method currently appends observers
unconditionally which allows nulls and duplicates; update
addPlaybackSamplesObserver(JavaAudioDeviceModule.PlaybackSamplesReadyCallback
observer) to validate observer != null and only add if not already present in
playbackSamplesObservers (use playbackSamplesObservers.contains(observer)) to
make registration idempotent—silently ignore (or log) null/duplicate inputs
rather than adding them; this uses the existing playbackSamplesObservers field
and the JavaAudioDeviceModule.PlaybackSamplesReadyCallback type to locate the
change.

@greenfrvr greenfrvr merged commit 9aeb7ce into master Jun 5, 2026
4 checks passed
@greenfrvr greenfrvr deleted the loopback-recordings branch June 5, 2026 12:37
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.

2 participants