8000 Merge branch 'master' into dtmf-send · tmthecoder/flutter-webrtc@9adb13d · GitHub
[go: up one dir, main page]

Skip to content

Commit 9adb13d

Browse files
authored
Merge branch 'master' into dtmf-send
2 parents 71bb24a + bb70057 commit 9adb13d

File tree

5 files changed

+208
-196
lines changed

5 files changed

+208
-196
lines changed

example/lib/src/get_user_media_sample_web.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class _GetUserMediaSampleState extends State<GetUserMediaSample> {
2929
initRenderers();
3030
MediaDevices.getSources().then((md) {
3131
setState(() {
32-
cameras = md.where((d) => d['kind'] == 'videoinput');
32+
cameras = md.where((d) => d['kind'] == 'videoinput').toList();
3333
});
3434
});
3535
}

lib/src/rtc_peerconnection.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ typedef AddTrackCallback = void Function(
2626
typedef RemoveTrackCallback = void Function(
2727
MediaStream stream, MediaStreamTrack track);
2828
typedef RTCDataChannelCallback = void Function(RTCDataChannel channel);
29+
typedef RenegotiationNeededCallback = void Function();
2930

3031
/*
3132
* PeerConnection
@@ -61,7 +62,6 @@ class RTCPeerConnection {
6162
AddTrackCallback onAddTrack;
6263
RemoveTrackCallback onRemoveTrack;
6364
RTCDataChannelCallback onDataChannel;
64-
6565
RenegotiationNeededCallback onRenegotiationNeeded;
6666

6767
final Map<String, dynamic> defaultSdpConstraints = {
@@ -172,9 +172,7 @@ class RTCPeerConnection {
172172
onDataChannel?.call(_dataChannel);
173173
break;
174174
case 'onRenegotiationNeeded':
175-
if (onRenegotiationNeeded != null) {
176-
onRenegotiationNeeded();
177-
}
175+
onRenegotiationNeeded?.call();
178176
break;
179177
}
180178
}

lib/src/rtc_video_view.dart

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class RTCVideoValue {
1616
this.rotation = 0,
1717
this.renderVideo = false,
1818
});
19-
static const RTCVideoValue empty = RTCVideoValue();
19+
static const empty = RTCVideoValue();
2020
final double width;
2121
final double height;
2222
final int rotation;
@@ -61,7 +61,7 @@ class RTCVideoRenderer extends ValueNotifier<RTCVideoValue> {
6161
final response = await _channel
6262
.invokeMethod<Map<dynamic, dynamic>>('createVideoRenderer', {});
6363
_textureId = response['textureId'];
64-
_eventSubscription = _eventChannelFor(_textureId)
64+
_eventSubscription = EventChannel('FlutterWebRTC/Texture$textureId')
6565
.receiveBroadcastStream()
6666
.listen(eventListener, onError: errorListener);
6767
}
@@ -71,17 +71,17 @@ class RTCVideoRenderer extends ValueNotifier<RTCVideoValue> {
7171
MediaStream get srcObject => _srcObject;
7272

7373
set srcObject(MediaStream stream) {
74+
if (textureId == null) throw 'Call initialize before setting the stream';
75+
7476
_srcObject = stream;
7577
_channel.invokeMethod('videoRendererSetSrcObject', <String, dynamic>{
76-
'textureId': _textureId,
78+
'textureId': textureId,
7779
'streamId': stream?.id ?? '',
7880
'ownerTag': stream?.ownerTag ?? ''
7981
}).then((_) {
80-
if (stream == null) {
81-
value = RTCVideoValue.empty;
82-
} else {
83-
value = value.copyWith(renderVideo: renderVideo);
84-
}
82+
value = (stream == null)
83+
? RTCVideoValue.empty
84+
: value.copyWith(renderVideo: renderVideo);
8585
});
8686
}
8787

@@ -95,10 +95,6 @@ class RTCVideoRenderer extends ValueNotifier<RTCVideoValue> {
9595
);
9696
}
9797

98-
EventChannel _eventChannelFor(int textureId) {
99-
return EventChannel('FlutterWebRTC/Texture$textureId');
100-
}
101-
10298
void eventListener(dynamic event) {
10399
final Map<dynamic, dynamic> map = event;
104100
switch (map['event']) {
@@ -142,38 +138,37 @@ class RTCVideoView extends StatelessWidget {
142138
@override
143139
Widget build(BuildContext context) {
144140
return LayoutBuilder(
145-
builder: (BuildContext context, BoxConstraints constraints) {
146-
return Center(
147-
child: _buildVideoView(constraints),
148-
);
149-
},
150-
);
141+
builder: (BuildContext context, BoxConstraints constraints) =>
142+
_buildVideoView(constraints));
151143
}
152144

153145
Widget _buildVideoView(BoxConstraints constraints) {
154-
return Container(
155-
width: constraints.maxWidth,
156-
height: constraints.maxHeight,
157-
child: FittedBox(
158-
fit: objectFit == RTCVideoViewObjectFit.RTCVideoViewObjectFitContain
159-
? BoxFit.contain
160-
: BoxFit.cover,
161-
child: Center(
162-
child: ValueListenableBuilder<RTCVideoValue>(
163-
valueListenable: _renderer,
164-
builder: (BuildContext context, RTCVideoValue value, Widget child) {
165-
return SizedBox(
166-
width: constraints.maxHeight * value.aspectRatio,
167-
height: constraints.maxHeight,
168-
child: value.renderVideo ? child : Container(),
169-
);
170-
},
171-
child: Transform(
172-
transform: Matrix4.identity()..rotateY(mirror ? -pi : 0.0),
173-
alignment: FractionalOffset.center,
174-
child: _renderer.textureId != null
175-
? Texture(textureId: _renderer.textureId)
176-
: Container(),
146+
return Center(
147+
child: Container(
148+
width: constraints.maxWidth,
149+
height: constraints.maxHeight,
150+
child: FittedBox(
151+
fit: objectFit == RTCVideoViewObjectFit.RTCVideoViewObjectFitContain
152+
? BoxFit.contain
153+
: BoxFit.cover,
154+
child: Center(
155+
child: ValueListenableBuilder<RTCVideoValue>(
156+
valueListenable: _renderer,
157+
builder:
158+
(BuildContext context, RTCVideoValue value, Widget child) {
159+
return SizedBox(
160+
width: constraints.maxHeight * value.aspectRatio,
161+
height: constraints.maxHeight,
162+
child: value.renderVideo ? child : Container(),
163+
);
164+
},
165+
child: Transform(
166+
transform: Matrix4.identity()..rotateY(mirror ? -pi : 0.0),
167+
alignment: FractionalOffset.center,
168+
child: _renderer.textureId != null
169+
? Texture(textureId: _renderer.textureId)
170+
: Container(),
171+
),
177172
),
178173
),
179174
),

lib/src/web/rtc_peerconnection.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ typedef AddTrackCallback = void Function(
2525
typedef RemoveTrackCallback = void Function(
2626
MediaStream stream, MediaStreamTrack track);
2727
typedef RTCDataChannelCallback = void Function(RTCDataChannel channel);
28+
typedef RenegotiationNeededCallback = void Function();
2829

2930
/*
3031
* PeerConnection
@@ -76,7 +77,7 @@ class RTCPeerConnection {
7677
js.JsObject.fromBrowserObject(_jsPc)['onicegatheringstatechange'] =
7778
js.JsFunction.withThis((_) {
7879
_iceGatheringState = ice C915 GatheringStateforString(_jsPc.iceGatheringState);
79-
onIceGatheringState.call(_iceGatheringState);
80+
onIceGatheringState?.call(_iceGatheringState);
8081
});
8182

8283
_jsPc.onRemoveStream.listen((mediaStreamEvent) {
@@ -89,6 +90,11 @@ class RTCPeerConnection {
8990
onSignalingState?.call(_signalingState);
9091
});
9192

93+
js.JsObject.fromBrowserObject(_jsPc)['negotiationneeded'] =
94+
js.JsFunction.withThis(() {
95+
onRenegotiationNeeded?.call();
96+
});
97+
9298
js.JsObject.fromBrowserObject(_jsPc)['ontrack'] =
9399
js.JsFunction.withThis((_, trackEvent) {
94100
// TODO(rostopira): trackEvent is JsObject conforming to RTCTrackEvent,
@@ -116,7 +122,7 @@ class RTCPeerConnection {
116122
AddTrackCallback onAddTrack;
117123
RemoveTrackCallback onRemoveTrack;
118124
RTCDataChannelCallback onDataChannel;
119-
dynamic onRenegotiationNeeded;
125+
RenegotiationNeededCallback onRenegotiationNeeded;
120126

121127
RTCSignalingState get signalingState => _signalingState;
122128

0 commit comments

Comments
 (0)
0