Skip to content

Commit

Permalink
Add setRemoteAudioPlayback functionality for android (#708)
Browse files Browse the repository at this point in the history
* Feature: Add setRemoteAudioPlayback to android

* remove unnecessary  return
  • Loading branch information
lucashe1997 authored Jun 20, 2023
1 parent 4f50a30 commit 90982ee
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,20 @@ public void toggleRemoteAudio(boolean enabled) {
}
}

public void setRemoteAudioPlayback(String participant, boolean enabled) {
if (room != null) {
for (RemoteParticipant rp : room.getRemoteParticipants()) {
if (rp.getSid().equals(participant)) {
for (AudioTrackPublication at : rp.getAudioTracks()) {
if (at.getAudioTrack() != null) {
((RemoteAudioTrack) at.getAudioTrack()).enablePlayback(enabled);
}
}
}
}
}
}

public void publishLocalVideo(boolean enabled) {
if (localParticipant != null && localVideoTrack != null) {
if (enabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class CustomTwilioVideoViewManager extends SimpleViewManager<CustomTwilio
private static final int SEND_STRING = 12;
private static final int PUBLISH_VIDEO = 13;
private static final int PUBLISH_AUDIO = 14;
private static final int SET_REMOTE_AUDIO_PLAYBACK = 15;

@Override
public String getName() {
Expand Down Expand Up @@ -143,6 +144,11 @@ public void receiveCommand(CustomTwilioVideoView view, int commandId, @Nullable
case PUBLISH_AUDIO:
view.publishLocalAudio(args.getBoolean(0));
break;
case SET_REMOTE_AUDIO_PLAYBACK:
String participantSid = args.getString(0);
Boolean enabled = args.getBoolean(1);
view.setRemoteAudioPlayback(participantSid, enabled);
break;
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/TwilioVideo.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ const nativeEvents = {
sendString: 12,
publishVideo: 13,
publishAudio: 14,
setRemoteAudioPlayback: 15,
};

class CustomTwilioVideoView extends Component {
Expand Down Expand Up @@ -247,6 +248,13 @@ class CustomTwilioVideoView extends Component {
return Promise.resolve(enabled);
}

setRemoteAudioPlayback({ participantSid, enabled }) {
this.runCommand(nativeEvents.setRemoteAudioPlayback, [
participantSid,
enabled,
]);
}

getStats() {
this.runCommand(nativeEvents.getStats, []);
}
Expand Down

0 comments on commit 90982ee

Please sign in to comment.