Skip to content

Commit fabea45

Browse files
authored
Add onParticipantAdded/RemovedAudioTrack on Android (#169)
* Add onParticipantAdded/RemovedAudioTrack on Android * Bugfixes * Another bugfix * Update CustomTwilioVideoView.java
1 parent a38bf9d commit fabea45

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

android/src/main/java/com/twiliorn/library/CustomTwilioVideoView.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,15 @@
7171
import static com.twiliorn.library.CustomTwilioVideoView.Events.ON_CONNECTED;
7272
import static com.twiliorn.library.CustomTwilioVideoView.Events.ON_CONNECT_FAILURE;
7373
import static com.twiliorn.library.CustomTwilioVideoView.Events.ON_DISCONNECTED;
74+
import static com.twiliorn.library.CustomTwilioVideoView.Events.ON_PARTICIPANT_ADDED_AUDIO_TRACK;
7475
import static com.twiliorn.library.CustomTwilioVideoView.Events.ON_PARTICIPANT_ADDED_VIDEO_TRACK;
7576
import static com.twiliorn.library.CustomTwilioVideoView.Events.ON_PARTICIPANT_CONNECTED;
7677
import static com.twiliorn.library.CustomTwilioVideoView.Events.ON_PARTICIPANT_DISABLED_AUDIO_TRACK;
7778
import static com.twiliorn.library.CustomTwilioVideoView.Events.ON_PARTICIPANT_DISABLED_VIDEO_TRACK;
7879
import static com.twiliorn.library.CustomTwilioVideoView.Events.ON_PARTICIPANT_DISCONNECTED;
7980
import static com.twiliorn.library.CustomTwilioVideoView.Events.ON_PARTICIPANT_ENABLED_AUDIO_TRACK;
8081
import static com.twiliorn.library.CustomTwilioVideoView.Events.ON_PARTICIPANT_ENABLED_VIDEO_TRACK;
82+
import static com.twiliorn.library.CustomTwilioVideoView.Events.ON_PARTICIPANT_REMOVED_AUDIO_TRACK;
8183
import static com.twiliorn.library.CustomTwilioVideoView.Events.ON_PARTICIPANT_REMOVED_VIDEO_TRACK;
8284
import static com.twiliorn.library.CustomTwilioVideoView.Events.ON_STATS_RECEIVED;
8385
import static com.twiliorn.library.CustomTwilioVideoView.Events.ON_VIDEO_CHANGED;
@@ -96,6 +98,8 @@ public class CustomTwilioVideoView extends View implements LifecycleEventListene
9698
Events.ON_PARTICIPANT_DISCONNECTED,
9799
Events.ON_PARTICIPANT_ADDED_VIDEO_TRACK,
98100
Events.ON_PARTICIPANT_REMOVED_VIDEO_TRACK,
101+
Events.ON_PARTICIPANT_ADDED_AUDIO_TRACK,
102+
Events.ON_PARTICIPANT_REMOVED_AUDIO_TRACK,
99103
Events.ON_PARTICIPANT_ENABLED_VIDEO_TRACK,
100104
Events.ON_PARTICIPANT_DISABLED_VIDEO_TRACK,
101105
Events.ON_PARTICIPANT_ENABLED_AUDIO_TRACK,
@@ -112,6 +116,8 @@ public class CustomTwilioVideoView extends View implements LifecycleEventListene
112116
String ON_PARTICIPANT_DISCONNECTED = "onRoomParticipantDidDisconnect";
113117
String ON_PARTICIPANT_ADDED_VIDEO_TRACK = "onParticipantAddedVideoTrack";
114118
String ON_PARTICIPANT_REMOVED_VIDEO_TRACK = "onParticipantRemovedVideoTrack";
119+
String ON_PARTICIPANT_ADDED_AUDIO_TRACK = "onParticipantAddedAudioTrack";
120+
String ON_PARTICIPANT_REMOVED_AUDIO_TRACK = "onParticipantRemovedAudioTrack";
115121
String ON_PARTICIPANT_ENABLED_VIDEO_TRACK = "onParticipantEnabledVideoTrack";
116122
String ON_PARTICIPANT_DISABLED_VIDEO_TRACK = "onParticipantDisabledVideoTrack";
117123
String ON_PARTICIPANT_ENABLED_AUDIO_TRACK = "onParticipantEnabledAudioTrack";
@@ -699,12 +705,14 @@ private RemoteParticipant.Listener mediaListener() {
699705
return new RemoteParticipant.Listener() {
700706
@Override
701707
public void onAudioTrackSubscribed(RemoteParticipant participant, RemoteAudioTrackPublication publication, RemoteAudioTrack audioTrack) {
702-
708+
WritableMap event = buildParticipantVideoEvent(participant, publication);
709+
pushEvent(CustomTwilioVideoView.this, ON_PARTICIPANT_ADDED_AUDIO_TRACK, event);
703710
}
704711

705712
@Override
706713
public void onAudioTrackUnsubscribed(RemoteParticipant participant, RemoteAudioTrackPublication publication, RemoteAudioTrack audioTrack) {
707-
714+
WritableMap event = buildParticipantVideoEvent(participant, publication);
715+
pushEvent(CustomTwilioVideoView.this, ON_PARTICIPANT_REMOVED_AUDIO_TRACK, event);
708716
}
709717

710718
@Override

android/src/main/java/com/twiliorn/library/CustomTwilioVideoViewManager.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import static com.twiliorn.library.CustomTwilioVideoView.Events.ON_VIDEO_CHANGED;
2929
import static com.twiliorn.library.CustomTwilioVideoView.Events.ON_PARTICIPANT_ADDED_VIDEO_TRACK;
3030
import static com.twiliorn.library.CustomTwilioVideoView.Events.ON_PARTICIPANT_REMOVED_VIDEO_TRACK;
31+
import static com.twiliorn.library.CustomTwilioVideoView.Events.ON_PARTICIPANT_ADDED_AUDIO_TRACK;
32+
import static com.twiliorn.library.CustomTwilioVideoView.Events.ON_PARTICIPANT_REMOVED_AUDIO_TRACK;
3133
import static com.twiliorn.library.CustomTwilioVideoView.Events.ON_PARTICIPANT_ENABLED_VIDEO_TRACK;
3234
import static com.twiliorn.library.CustomTwilioVideoView.Events.ON_PARTICIPANT_DISABLED_VIDEO_TRACK;
3335
import static com.twiliorn.library.CustomTwilioVideoView.Events.ON_PARTICIPANT_ENABLED_AUDIO_TRACK;
@@ -109,12 +111,14 @@ public Map getExportedCustomDirectEventTypeConstants() {
109111
ON_PARTICIPANT_DISCONNECTED, MapBuilder.of("registrationName", ON_PARTICIPANT_DISCONNECTED),
110112
ON_PARTICIPANT_ADDED_VIDEO_TRACK, MapBuilder.of("registrationName", ON_PARTICIPANT_ADDED_VIDEO_TRACK),
111113
ON_PARTICIPANT_REMOVED_VIDEO_TRACK, MapBuilder.of("registrationName", ON_PARTICIPANT_REMOVED_VIDEO_TRACK),
114+
ON_PARTICIPANT_ADDED_AUDIO_TRACK, MapBuilder.of("registrationName", ON_PARTICIPANT_ADDED_AUDIO_TRACK),
115+
ON_PARTICIPANT_REMOVED_AUDIO_TRACK, MapBuilder.of("registrationName", ON_PARTICIPANT_REMOVED_AUDIO_TRACK)
116+
));
117+
map.putAll(MapBuilder.of(
112118
ON_PARTICIPANT_ENABLED_VIDEO_TRACK, MapBuilder.of("registrationName", ON_PARTICIPANT_ENABLED_VIDEO_TRACK),
113119
ON_PARTICIPANT_DISABLED_VIDEO_TRACK, MapBuilder.of("registrationName", ON_PARTICIPANT_DISABLED_VIDEO_TRACK),
114120
ON_PARTICIPANT_ENABLED_AUDIO_TRACK, MapBuilder.of("registrationName", ON_PARTICIPANT_ENABLED_AUDIO_TRACK),
115-
ON_PARTICIPANT_DISABLED_AUDIO_TRACK, MapBuilder.of("registrationName", ON_PARTICIPANT_DISABLED_AUDIO_TRACK)
116-
));
117-
map.putAll(MapBuilder.of(
121+
ON_PARTICIPANT_DISABLED_AUDIO_TRACK, MapBuilder.of("registrationName", ON_PARTICIPANT_DISABLED_AUDIO_TRACK),
118122
ON_STATS_RECEIVED, MapBuilder.of("registrationName", ON_STATS_RECEIVED)
119123
));
120124

src/TwilioVideo.android.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,20 @@ const propTypes = {
6363
*/
6464
onParticipantRemovedVideoTrack: PropTypes.func,
6565

66+
/**
67+
* Called when a new audio track has been added
68+
*
69+
* @param {{participant, track}}
70+
*/
71+
onParticipantAddedAudioTrack: PropTypes.func,
72+
73+
/**
74+
* Called when a audio track has been removed
75+
*
76+
* @param {{participant, track}}
77+
*/
78+
onParticipantRemovedAudioTrack: PropTypes.func,
79+
6680
/**
6781
* Callback called a participant enters a room.
6882
*/
@@ -172,6 +186,8 @@ class CustomTwilioVideoView extends Component {
172186
'onRoomDidDisconnect',
173187
'onParticipantAddedVideoTrack',
174188
'onParticipantRemovedVideoTrack',
189+
'onParticipantAddedAudioTrack',
190+
'onParticipantRemovedAudioTrack',
175191
'onRoomParticipantDidConnect',
176192
'onRoomParticipantDidDisconnect',
177193
'onParticipantEnabledVideoTrack',

0 commit comments

Comments
 (0)