8000 Support null tracks in sender replace track and set track (#929) · sujeking/flutter-webrtc@bf345fe · GitHub
[go: up one dir, main page]

Skip to content

Commit bf345fe

Browse files
itsthetasteRichard Brookes-Tee
andauthored
Support null tracks in sender replace track and set track (flutter-webrtc#929)
* - ios - if track is null, pass an empty string through - if an empty string is passed, don't look for the track, just set it to nil * - android - if we are passed an empty trackId pass null in * add example testing replacing tracks and setting them to null * tidy up Co-authored-by: Richard Brookes-Tee <rbt@vee24.com>
1 parent 626fef1 commit bf345fe

File tree

5 files changed

+533
-21
lines changed

5 files changed

+533
-21
lines changed

android/src/main/java/com/cloudwebrtc/webrtc/MethodCallHandlerImpl.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,11 +1703,14 @@ public void rtpSenderSetTrack(String peerConnectionId, String rtpSenderId, Strin
17031703
PeerConnectionObserver pco = mPeerConnectionObservers.get(peerConnectionId);
17041704
if (pco == null || pco.getPeerConnection() == null) {
17051705
resultError("rtpSenderSetTrack", "peerConnection is null", result);
1706-
} else {
1707-
MediaStreamTrack track = localTracks.get(trackId);
1708-
if (track == null) {
1709-
resultError("rtpSenderSetTrack", "track is null", result);
1710-
return;
1706+
} else {
1707+
MediaStreamTrack track = null;
1708+
if (trackId.length() > 0) {
1709+
track = localTracks.get(trackId);
1710+
if (track == null) {
1711+
resultError("rtpSenderSetTrack", "track is null", result);
1712+
return;
1713+
}
17111714
}
17121715
pco.rtpSenderSetTrack(rtpSenderId, track, result, replace);
17131716
}

common/darwin/Classes/FlutterWebRTCPlugin.m

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -852,12 +852,15 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult) result
852852
details:nil]);
853853
return;
854854
}
855-
RTCMediaStreamTrack *track = [self trackForId:trackId];
856-
if(track == nil) {
857-
result([FlutterError errorWithCode:[NSString stringWithFormat:@"%@Failed",call.method]
858-
message:[NSString stringWithFormat:@"Error: track not found!"]
859-
details:nil]);
860-
return;
855+
RTCMediaStreamTrack *track = nil;
856+
if ([trackId length] > 0) {
857+
track = [self trackForId:trackId];
858+
if(track == nil) {
859+
result([FlutterError errorWithCode:[NSString stringWithFormat:@"%@Failed",call.method]
860+< 8000 div class="diff-text-inner"> message:[NSString stringWithFormat:@"Error: track not found!"]
861+
details:nil]);
862+
return;
863+
}
861864
}
862865
[sender setTrack:track];
863866
result(nil);
@@ -880,12 +883,15 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult) result
880883
details:nil]);
881884
return;
882885
}
883-
RTCMediaStreamTrack *track = [self trackForId:trackId];
884-
if(track == nil) {
885-
result([FlutterError errorWithCode:[NSString stringWithFormat:@"%@Failed",call.method]
886-
message:[NSString stringWithFormat:@"Error: track not found!"]
887-
details:nil]);
888-
return;
886+
RTCMediaStreamTrack *track = nil;
887+
if ([trackId length] > 0) {
888+
track = [self trackForId:trackId];
889+
if(track == nil) {
890+
result([FlutterError errorWithCode:[NSString stringWithFormat:@"%@Failed",call.method]
891+
message:[NSString stringWithFormat:@"Error: track not found!"]
892+
details:nil]);
893+
return;
894+
}
889895
}
890896
[sender setTrack:track];
891897
result(nil);

example/lib/main.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'src/get_display_media_sample.dart';
1111
import 'src/get_user_media_sample.dart'
1212
if (dart.library.html) 'src/get_user_media_sample_web.dart';
1313
import 'src/loopback_sample.dart';
14+
import 'src/loopback_sample_unified_tracks.dart';
1415
import 'src/route_item.dart';
1516

1617
void main() {
@@ -105,6 +106,15 @@ class _MyAppState extends State<MyApp> {
105106
MaterialPageRoute(
106107
builder: (BuildContext context) => LoopBackSample()));
107108
}),
109+
RouteItem(
110+
title: 'LoopBack Sample (Unified Tracks)',
111+
push: (BuildContext context) {
112+
Navigator.push(
113+
context,
114+
MaterialPageRoute(
115+
builder: (BuildContext context) =>
116+
LoopBackSampleUnifiedTracks()));
117+
}),
108118
RouteItem(
109119
title: 'DataChannel',
110120
push: (BuildContext context) {

0 commit comments

Comments
 (0)
0