8000 update. · next-coder/flutter-webrtc@f0a64df · GitHub
[go: up one dir, main page]

Skip to content

Commit f0a64df

Browse files
committed
update.
1 parent 5dddd58 commit f0a64df

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

example/lib/src/loopback_sample.dart

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ class _MyAppState extends State<LoopBackSample> {
1919
bool _inCalling = false;
2020
Timer _timer;
2121

22+
String get sdpSemantics =>
23+
WebRTC.platformIsWindows ? 'plan-b' : 'unified-plan';
24+
2225
@override
2326
void initState() {
2427
super.initState();
@@ -137,7 +140,7 @@ class _MyAppState extends State<LoopBackSample> {
137140
'iceServers': [
138141
{'url': 'stun:stun.l.google.com:19302'},
139142
],
140-
'sdpSemantics': 'unified-plan'
143+
'sdpSemantics': sdpSemantics
141144
};
142145

143146
final offerSdpConstraints = <String, dynamic>{
@@ -170,20 +173,22 @@ class _MyAppState extends State<LoopBackSample> {
170173
_peerConnection.onIceCandidate = _onCandidate;
171174
_peerConnection.onRenegotiationNeeded = _onRenegotiationNeeded;
172175

173-
_peerConnection.onTrack = _onTrack;
174-
175176
_localStream =
176177
await navigator.mediaDevices.getUserMedia(mediaConstraints);
177178
_localRenderer.srcObject = _localStream;
178-
await _peerConnection.addStream(_localStream);
179-
/* old API
180-
await _peerConnection.addStream(_localStream);
181-
// Unified-Plan
182-
_localStream.getTracks().forEach((track) {
183-
_peerConnection.addTrack(track, [_localStream]);
184-
});
185-
*/
186-
// or
179+
180+
switch (sdpSemantics) {
181+
case 'plan-b':
182+
await _peerConnection.addStream(_localStream);
183+
break;
184+
case 'unified-plan':
185+
_peerConnection.onTrack = _onTrack;
186+
_localStream.getTracks().forEach((track) {
187+
_peerConnection.addTrack(track, _localStream);
188+
});
189+
break;
190+
}
191+
187192
/*
188193
await _peerConnection.addTransceiver(
189194
track: _localStream.getAudioTracks()[0],
@@ -251,7 +256,6 @@ class _MyAppState extends State<LoopBackSample> {
251256
_localRenderer.srcObject = _localStream;
252257
await transceiver.sender.replaceTrack(stream.getVideoTracks()[0]);
253258
// do re-negotiation ....
254-
255259
*/
256260
} catch (e) {
257261
print(e.toString());

lib/src/native/utils.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ class WebRTC {
88
static bool get platformIsDesktop =>
99
Platform.isWindows || Platform.isLinux || Platform.isMacOS;
1010

11+
static bool get platformIsWindows => Platform.isWindows;
12+
1113
static bool get platformIsMobile => Platform.isIOS || Platform.isAndroid;
1214

1315
static bool get platformIsIOS => Platform.isIOS;

lib/src/web/utils.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import 'package:flutter/services.dart';
33
class WebRTC {
44
static bool get platformIsDesktop => false;
55

6+
static bool get platformIsWindows => false;
7+
68
static bool get platformIsMobile => false;
79

810
static bool get platformIsIOS => false;

0 commit comments

Comments
 (0)
0