feat: added trackById and JADM playback sample observer#44
Conversation
📝 WalkthroughWalkthroughThis 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. ChangesTrack resolution and playback observer management
🎯 2 (Simple) | ⏱️ ~12 minutes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
android/src/main/java/com/oney/WebRTCModule/WebRTCModuleOptions.java (1)
81-84: ⚡ Quick winDon’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
📒 Files selected for processing (4)
android/src/main/java/com/oney/WebRTCModule/WebRTCModule.javaandroid/src/main/java/com/oney/WebRTCModule/WebRTCModuleOptions.javaios/RCTWebRTC/WebRTCModule.hios/RCTWebRTC/WebRTCModule.m
| private final List<JavaAudioDeviceModule.PlaybackSamplesReadyCallback> playbackSamplesObservers = | ||
| new CopyOnWriteArrayList<>(); | ||
|
|
||
| public void addPlaybackSamplesObserver(JavaAudioDeviceModule.PlaybackSamplesReadyCallback observer) { | ||
| playbackSamplesObservers.add(observer); | ||
| } |
There was a problem hiding this comment.
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.
| 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.
Summary by CodeRabbit