8000 [example] flutter format. · Condelab/flutter-webrtc@aec7d99 · GitHub
[go: up one dir, main page]

Skip to content

Commit aec7d99

Browse files
committed
[example] flutter format.
1 parent a4851bf commit aec7d99

File tree

6 files changed

+125
-120
lines changed

6 files changed

+125
-120
lines changed

example/lib/src/data_channel_sample.dart

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import 'package:flutter_webrtc/webrtc.dart';
55
import 'dart:core';
66

77
class DataChannelSample extends StatefulWidget {
8-
98
static String tag = 'data_channel_sample';
109

1110
@override
@@ -56,30 +55,25 @@ class _DataChannelSampleState extends State<DataChannelSample> {
5655
dataChannel.onMessage = (message) {
5756
if (message.type == MessageType.text) {
5857
print(message.text);
59-
}
60-
else {
58+
} else {
6159
// do something with message.binary
6260
}
6361
};
6462
// or alternatively:
6563
dataChannel.messageStream.listen((message) {
6664
if (message.type == MessageType.text) {
6765
print(message.text);
68-
}
69-
else {
66+
} else {
7067
// do something with message.binary
7168
}
7269
});
73-
70+
7471
dataChannel.send(RTCDataChannelMessage("Hello!"));
75-
dataChannel.send(RTCDataChannelMessage.fromBinary(
76-
Uint8List(5)
77-
));
72+
dataChannel.send(RTCDataChannelMessage.fromBinary(Uint8List(5)));
7873
}
7974

8075
// Platform messages are asynchronous, so we initialize in an async method.
8176
_makeCall() async {
82-
8377
Map<String, dynamic> configuration = {
8478
"iceServers": [
8579
{"url": "stun:stun.l.google.com:19302"},
@@ -97,16 +91,15 @@ class _DataChannelSampleState extends State<DataChannelSample> {
9791
final Map<String, dynamic> loopbackConstraints = {
9892
"mandatory": {},
9993
"optional": [
100-
{"DtlsSrtpKeyAgreement": true },
94+
{"DtlsSrtpKeyAgreement": true},
10195
],
10296
};
10397

10498
if (_peerConnection != null) return;
10599

106100
try {
107-
108101
_peerConnection =
109-
await createPeerConnection(configuration, loopbackConstraints);
102+
await createPeerConnection(configuration, loopbackConstraints);
110103

111104
_peerConnection.onSignalingState = _onSignalingState;
112105
_peerConnection.onIceGatheringState = _onIceGatheringState;
@@ -122,11 +115,12 @@ class _DataChannelSampleState extends State<DataChannelSample> {
122115
_dataChannelDict.protocol = "sctp";
123116
_dataChannelDict.negotiated = false;
124117

125-
_dataChannel = await _peerConnection.createDataChannel('dataChannel', _dataChannelDict);
118+
_dataChannel = await _peerConnection.createDataChannel(
119+
'dataChannel', _dataChannelDict);
126120
_peerConnection.onDataChannel = _onDataChannel;
127121

128122
RTCSessionDescription description =
129-
await _peerConnection.createOffer(offerSdpConstraints);
123+
await _peerConnection.createOffer(offerSdpConstraints);
130124
print(description.sdp);
131125
_peerConnection.setLocalDescription(description);
132126

@@ -159,26 +153,24 @@ class _DataChannelSampleState extends State<DataChannelSample> {
159153

160154
@override
161155
Widget build(BuildContext context) {
162-
return
163-
new Scaffold(
164-
appBar: new AppBar(
165-
title: new Text('Data Channel Test'),
166-
),
167-
body: new OrientationBuilder(
168-
builder: (context, orientation) {
169-
return new Center(
170-
child: new Container(
171-
child: _inCalling? Text(_sdp) : Text('data channel test'),
172-
),
173-
);
174-
},
175-
),
176-
floatingActionButton: new FloatingActionButton(
177-
onPressed: _inCalling ? _hangUp : _makeCall,
178-
tooltip: _inCalling ? 'Hangup' : 'Call',
179-
child: new Icon(_inCalling ? Icons.call_end : Icons.phone),
180-
),
181-
);
182-
156+
return new Scaffold(
157+
appBar: new AppBar(
158+
title: new Text('Data Channel Test'),
159+
),
160+
body: new OrientationBuilder(
161+
builder: (context, orientation) {
162+
return new Center(
163+
child: new Container(
164+
child: _inCalling ? Text(_sdp) : Text('data channel test'),
165+
),
166+
);
167+
},
168+
),
169+
floatingActionButton: new FloatingActionButton(
170+
onPressed: _inCalling ? _hangUp : _makeCall,
171+
tooltip: _inCalling ? 'Hangup' : 'Call',
172+
child: new Icon(_inCalling ? Icons.call_end : Icons.phone),
173+
),
174+
);
183175
}
184176
}

example/lib/src/get_display_media_sample.dart

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ import 'package:flutter/material.dart';
22
import 'package:flutter_webrtc/webrtc.dart';
33
import 'dart:core';
44
import 'dart:async';
5+
56
/*
67
* getDisplayMedia sample
78
*/
89
class GetDisplayMediaSample extends StatefulWidget {
910
static String tag = 'get_display_media_sample';
1011

1112
@override
12-
_GetDisplayMediaSampleState createState() => new _GetDisplayMediaSampleState();
13+
_GetDisplayMediaSampleState createState() =>
14+
new _GetDisplayMediaSampleState();
1315
}
1416

1517
class _GetDisplayMediaSampleState extends State<GetDisplayMediaSample> {
@@ -31,7 +33,7 @@ class _GetDisplayMediaSampleState extends State<GetDisplayMediaSample> {
3133
if (_inCalling) {
3234
_hangUp();
3335
}
34-
if(_timer != null) _timer.cancel();
36+
if (_timer != null) _timer.cancel();
3537
_localRenderer.dispose();
3638
}
3739

@@ -90,19 +92,18 @@ class _GetDisplayMediaSampleState extends State<GetDisplayMediaSample> {
9092
body: new OrientationBuilder(
9193
builder: (context, orientation) {
9294
return new Center(
93-
child: new Stack(
94-
children: <Widget>[
95-
new Center(
96-
child:new Text('counter: ' + _counter.toString()),
97-
),
98-
new Container(
99-
margin: new EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 0.0),
100-
width: MediaQuery.of(context).size.width,
101-
height: MediaQuery.of(context).size.height,
102-
child: RTCVideoView(_localRenderer),
103-
decoration: new BoxDecoration(color: Colors.black54),
104-
)
105-
]),
95+
child: new Stack(children: <Widget>[
96+
new Center(
97+
child: new Text('counter: ' + _counter.toString()),
98+
),
99+
new Container(
100+
margin: new EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 0.0),
101+
width: MediaQuery.of(context).size.width,
102+
height: MediaQuery.of(context).size.height,
103+
child: RTCVideoView(_localRenderer),
104+
decoration: new BoxDecoration(color: Colors.black54),
105+
)
106+
]),
106107
);
107108
},
108109
),

example/lib/src/get_user_media_sample.dart

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ class _GetUserMediaSampleState extends State<GetUserMediaSample> {
4848
"audio": false,
4949
"video": {
5050
"mandatory": {
51-
"minWidth": '1280', // Provide your own width, height and frame rate here
51+
"minWidth":
52+
'1280', // Provide your own width, height and frame rate here
5253
"minHeight": '720',
5354
"minFrameRate": '30',
5455
},
@@ -95,7 +96,9 @@ class _GetUserMediaSampleState extends State<GetUserMediaSample> {
9596
_mediaRecorder = MediaRecorder();
9697
setState(() {});
9798
await _localStream.getMediaTracks();
98-
final videoTrack = _localStream.getVideoTracks().firstWhere((track) => track.kind == "video");
99+
final videoTrack = _localStream
100+
.getVideoTracks()
101+
.firstWhere((track) => track.kind == "video");
99102
await _mediaRecorder.start(
100103
filePath,
101104
videoTrack: videoTrack,
@@ -110,7 +113,9 @@ class _GetUserMediaSampleState extends State<GetUserMediaSample> {
110113
}
111114

112115
_toggleTorch() async {
113-
final videoTrack = _localStream.getVideoTracks().firstWhere((track) => track.kind == "video");
116+
final videoTrack = _localStream
117+
.getVideoTracks()
118+
.firstWhere((track) => track.kind == "video");
114119
final has = await videoTrack.hasTorch();
115120
if (has) {
116121
print("[TORCH] Current camera supports torch mode");
@@ -123,7 +128,9 @@ class _GetUserMediaSampleState extends State<GetUserMediaSample> {
123128
}
124129

125130
_toggleCamera() async {
126-
final videoTrack = _localStream.getVideoTracks().firstWhere((track) => track.kind == "video");
131+
final videoTrack = _localStream
132+
.getVideoTracks()
133+
.firstWhere((track) => track.kind == "video");
127134
await videoTrack.switchCamera();
128135
}
129136

@@ -137,7 +144,9 @@ class _GetUserMediaSampleState extends State<GetUserMediaSample> {
137144
filePath = storagePath.path + '/test${DateTime.now()}.jpg';
138145
}
139146

140-
final videoTrack = _localStream.getVideoTracks().firstWhere((track) => track.kind == "video");
147+
final videoTrack = _localStream
148+
.getVideoTracks()
149+
.firstWhere((track) => track.kind == "video");
141150
videoTrack.captureFrame(filePath);
142151
}
143152

example/lib/src/get_user_media_sample_web.dart

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ class _GetUserMediaSampleState extends State<GetUserMediaSample> {
5353
"audio": true,
5454
"video": {
5555
"mandatory": {
56-
"minWidth": '1280', // Provide your own width, height and frame rate here
56+
"minWidth":
57+
'1280', // Provide your own width, height and frame rate here
5758
"minHeight": '720',
5859
"minFrameRate": '30',
5960
},
@@ -103,34 +104,40 @@ class _GetUserMediaSampleState extends State<GetUserMediaSample> {
103104
}
104105

105106
_captureFrame() async {
106-
final videoTrack = _localStream.getVideoTracks().firstWhere((track) => track.kind == "video");
107+
final videoTrack = _localStream
108+
.getVideoTracks()
109+
.firstWhere((track) => track.kind == "video");
107110
final frame = await videoTrack.captureFrame();
108-
showDialog(context: context, builder: (context) => AlertDialog(
109-
content: Image.network(frame, height: 720, width: 1280),
110-
actions: <Widget>[
111-
FlatButton(
112-
child: Text("OK"),
113-
onPressed: Navigator.of(context, rootNavigator: true).pop,
114-
)
115-
],
116-
));
111+
showDialog(
112+
context: context,
113+
builder: (context) => AlertDialog(
114+
content: Image.network(frame, height: 720, width: 1280),
115+
actions: <Widget>[
116+
FlatButton(
117+
child: Text("OK"),
118+
onPressed: Navigator.of(context, rootNavigator: true).pop,
119+
)
120+
],
121+
));
117122
}
118123

119124
@override
120125
Widget build(BuildContext context) {
121126
return new Scaffold(
122127
appBar: new AppBar(
123128
title: new Text('GetUserMedia API Test'),
124-
actions: _inCalling ? <Widget>[
125-
IconButton(
126-
icon: Icon(Icons.camera),
127-
onPressed: _captureFrame,
128-
),
129-
IconButton(
130-
icon: Icon(_isRec ? Icons.stop : Icons.fiber_manual_record),
131-
onPressed: _isRec ? _stopRecording : _startRecording,
132-
),
133-
] : null,
129+
actions: _inCalling
130+
? <Widget>[
131+
IconButton(
132+
icon: Icon(Icons.camera),
133+
onPressed: _captureFrame,
134+
),
135+
IconButton(
136+
icon: Icon(_isRec ? Icons.stop : Icons.fiber_manual_record),
137+
onPressed: _isRec ? _stopRecording : _startRecording,
138+
),
139+
]
140+
: null,
134141
),
135142
body: new OrientationBuilder(
136143
builder: (context, orientation) {

0 commit comments

Comments
 (0)
0