1
+ import 'dart:core' ;
1
2
import 'dart:typed_data' ;
2
3
3
4
import 'package:flutter/material.dart' ;
4
5
import 'package:flutter_webrtc/webrtc.dart' ;
5
- import 'dart:core' ;
6
6
7
7
class DataChannelSample extends StatefulWidget {
8
8
static String tag = 'data_channel_sample' ;
9
9
10
10
@override
11
- _DataChannelSampleState createState () => new _DataChannelSampleState ();
11
+ _DataChannelSampleState createState () => _DataChannelSampleState ();
12
12
}
13
13
14
14
class _DataChannelSampleState extends State <DataChannelSample > {
@@ -21,23 +21,23 @@ class _DataChannelSampleState extends State<DataChannelSample> {
21
21
String _sdp;
22
22
23
23
@override
24
- initState () {
24
+ void initState () {
25
25
super .initState ();
26
26
}
27
27
28
- _onSignalingState (RTCSignalingState state) {
28
+ void _onSignalingState (RTCSignalingState state) {
29
29
print (state);
30
30
}
31
31
32
- _onIceGatheringState (RTCIceGatheringState state) {
32
+ void _onIceGatheringState (RTCIceGatheringState state) {
33
33
print (state);
34
34
}
35
35
36
- _onIceConnectionState (RTCIceConnectionState state) {
36
+ void _onIceConnectionState (RTCIceConnectionState state) {
37
37
print (state);
38
38
}
39
39
40
- _onCandidate (RTCIceCandidate candidate) {
40
+ void _onCandidate (RTCIceCandidate candidate) {
41
41
print ('onCandidate: ' + candidate.candidate);
42
42
_peerConnection.addCandidate (candidate);
43
43
setState (() {
@@ -46,12 +46,12 @@ class _DataChannelSampleState extends State<DataChannelSample> {
46
46
});
47
47
}
48
48
49
- _onRenegotiationNeeded () {
49
+ void _onRenegotiationNeeded () {
50
50
print ('RenegotiationNeeded' );
51
51
}
52
52
53
53
/// Send some sample messages and handle incoming messages.
54
- _onDataChannel (RTCDataChannel dataChannel) {
54
+ void _onDataChannel (RTCDataChannel dataChannel) {
55
55
dataChannel.onMessage = (message) {
56
56
if (message.type == MessageType .text) {
57
57
print (message.text);
@@ -68,30 +68,30 @@ class _DataChannelSampleState extends State<DataChannelSample> {
68
68
}
69
69
});
70
70
71
- dataChannel.send (RTCDataChannelMessage (" Hello!" ));
71
+ dataChannel.send (RTCDataChannelMessage (' Hello!' ));
72
72
dataChannel.send (RTCDataChannelMessage .fromBinary (Uint8List (5 )));
73
73
}
74
74
75
75
// Platform messages are asynchronous, so we initialize in an async method.
76
- _makeCall () async {
77
- Map <String , dynamic > configuration = {
78
- " iceServers" : [
79
- {" url" : " stun:stun.l.google.com:19302" },
76
+ void _makeCall () async {
77
+ var configuration = < String , dynamic > {
78
+ ' iceServers' : [
79
+ {' url' : ' stun:stun.l.google.com:19302' },
80
80
]
81
81
};
82
82
83
- final Map <String , dynamic > offerSdpConstraints = {
84
- " mandatory" : {
85
- " OfferToReceiveAudio" : false ,
86
- " OfferToReceiveVideo" : false ,
83
+ final offerSdpConstraints = < String , dynamic > {
84
+ ' mandatory' : {
85
+ ' OfferToReceiveAudio' : false ,
86
+ ' OfferToReceiveVideo' : false ,
87
87
},
88
- " optional" : [],
88
+ ' optional' : [],
89
89
};
90
90
91
- final Map <String , dynamic > loopbackConstraints = {
92
- " mandatory" : {},
93
- " optional" : [
94
- {" DtlsSrtpKeyAgreement" : true },
91
+ final loopbackConstraints = < String , dynamic > {
92
+ ' mandatory' : {},
93
+ ' optional' : [
94
+ {' DtlsSrtpKeyAgreement' : true },
95
95
],
96
96
};
97
97
@@ -107,22 +107,21 @@ class _DataChannelSampleState extends State<DataChannelSample> {
107
107
_peerConnection.onIceCandidate = _onCandidate;
108
108
_peerConnection.onRenegotiationNeeded = _onRenegotiationNeeded;
109
109
110
- _dataChannelDict = new RTCDataChannelInit ();
110
+ _dataChannelDict = RTCDataChannelInit ();
111
111
_dataChannelDict.id = 1 ;
112
112
_dataChannelDict.ordered = true ;
113
113
_dataChannelDict.maxRetransmitTime = - 1 ;
114
114
_dataChannelDict.maxRetransmits = - 1 ;
115
- _dataChannelDict.protocol = " sctp" ;
115
+ _dataChannelDict.protocol = ' sctp' ;
116
116
_dataChannelDict.negotiated = false ;
117
117
118
118
_dataChannel = await _peerConnection.createDataChannel (
119
119
'dataChannel' , _dataChannelDict);
120
120
_peerConnection.onDataChannel = _onDataChannel;
121
121
122
- RTCSessionDescription description =
123
- await _peerConnection.createOffer (offerSdpConstraints);
122
+ var description = await _peerConnection.createOffer (offerSdpConstraints);
124
123
print (description.sdp);
125
- _peerConnection.setLocalDescription (description);
124
+ await _peerConnection.setLocalDescription (description);
126
125
127
126
_sdp = description.sdp;
128
127
//change for loopback.
@@ -138,7 +137,7 @@ class _DataChannelSampleState extends State<DataChannelSample> {
138
137
});
139
138
}
140
139
141
- _hangUp () async {
140
+ void _hangUp () async {
142
141
try {
143
142
await _dataChannel.close ();
144
143
await _peerConnection.close ();
@@ -153,23 +152,23 @@ class _DataChannelSampleState extends State<DataChannelSample> {
153
152
154
153
@override
155
154
Widget build (BuildContext context) {
156
- return new Scaffold (
157
- appBar: new AppBar (
158
- title: new Text ('Data Channel Test' ),
155
+ return Scaffold (
156
+ appBar: AppBar (
157
+ title: Text ('Data Channel Test' ),
159
158
),
160
- body: new OrientationBuilder (
159
+ body: OrientationBuilder (
161
160
builder: (context, orientation) {
162
- return new Center (
163
- child: new Container (
161
+ return Center (
162
+ child: Container (
164
163
child: _inCalling ? Text (_sdp) : Text ('data channel test' ),
165
164
),
166
165
);
167
166
},
168
167
),
169
- floatingActionButton: new FloatingActionButton (
168
+ floatingActionButton: FloatingActionButton (
170
169
onPressed: _inCalling ? _hangUp : _makeCall,
171
170
tooltip: _inCalling ? 'Hangup' : 'Call' ,
172
- child: new Icon (_inCalling ? Icons .call_end : Icons .phone),
171
+ child: Icon (_inCalling ? Icons .call_end : Icons .phone),
173
172
),
174
173
);
175
174
}
0 commit comments