@@ -16,7 +16,7 @@ class RTCVideoValue {
16
16
this .rotation = 0 ,
17
17
this .renderVideo = false ,
18
18
});
19
- static const RTCVideoValue empty = RTCVideoValue ();
19
+ static const empty = RTCVideoValue ();
20
20
final double width;
21
21
final double height;
22
22
final int rotation;
@@ -61,7 +61,7 @@ class RTCVideoRenderer extends ValueNotifier<RTCVideoValue> {
61
61
final response = await _channel
62
62
.invokeMethod <Map <dynamic , dynamic >>('createVideoRenderer' , {});
63
63
_textureId = response['textureId' ];
64
- _eventSubscription = _eventChannelFor (_textureId )
64
+ _eventSubscription = EventChannel ( 'FlutterWebRTC/Texture$ textureId ' )
65
65
.receiveBroadcastStream ()
66
66
.listen (eventListener, onError: errorListener);
67
67
}
@@ -71,17 +71,17 @@ class RTCVideoRenderer extends ValueNotifier<RTCVideoValue> {
71
71
MediaStream get srcObject => _srcObject;
72
72
73
73
set srcObject (MediaStream stream) {
74
+ if (textureId == null ) throw 'Call initialize before setting the stream' ;
75
+
74
76
_srcObject = stream;
75
77
_channel.invokeMethod ('videoRendererSetSrcObject' , < String , dynamic > {
76
- 'textureId' : _textureId ,
78
+ 'textureId' : textureId ,
77
79
'streamId' : stream? .id ?? '' ,
78
80
'ownerTag' : stream? .ownerTag ?? ''
79
81
}).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);
85
85
});
86
86
}
87
87
@@ -95,10 +95,6 @@ class RTCVideoRenderer extends ValueNotifier<RTCVideoValue> {
95
95
);
96
96
}
97
97
98
- EventChannel _eventChannelFor (int textureId) {
99
- return EventChannel ('FlutterWebRTC/Texture$textureId ' );
100
- }
101
-
102
98
void eventListener (dynamic event) {
103
99
final Map <dynamic , dynamic > map = event;
104
100
switch (map['event' ]) {
@@ -142,38 +138,37 @@ class RTCVideoView extends StatelessWidget {
142
138
@override
143
139
Widget build (BuildContext context) {
144
140
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));
151
143
}
152
144
153
145
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
+ ),
177
172
),
4248
div>
178
173
),
179
174
),
0 commit comments