8000 add input ip dialog · suresh44t/flutter-webrtc@12a6021 · GitHub
[go: up one dir, main page]

Skip to content

Commit 12a6021

Browse files
committed
add input ip dialog
1 parent d51413e commit 12a6021

File tree

2 files changed

+79
-22
lines changed

2 files changed

+79
-22
lines changed

example/lib/main.dart

Lines changed: 67 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,15 @@ class MyApp extends StatefulWidget {
1111
_MyAppState createState() => new _MyAppState();
1212
}
1313

14-
final List<RouteItem> items = <RouteItem>[
15-
RouteItem(
16-
title: 'Basic API Tests',
17-
subtitle: 'Basic API Tests.',
18-
push: (BuildContext context) {
19-
Navigator.push(
20-
context,
21-
new MaterialPageRoute(
22-
builder: (BuildContext context) => new BasicSample()));
23-
}),
24-
RouteItem(
25-
title: 'P2P Call Sample',
26-
subtitle: 'P2P Call Sample.',
27-
push: (BuildContext context) {
28-
Navigator.push(
29-
context,
30-
new MaterialPageRoute(
31-
builder: (BuildContext context) => new CallSample()));
32-
}),
33-
];
14+
3415

3516
class _MyAppState extends State<MyApp> {
3617
@override
3718
initState() {
3819
super.initState();
20+
21+
_initItems();
22+
3923
}
4024

4125
_buildRow(context, item) {
@@ -65,4 +49,67 @@ class _MyAppState extends State<MyApp> {
6549
})),
6650
);
6751
}
52+
53+
List<RouteItem> items;
54+
String _ip = '192.168.2.168';
55+
56+
_initItems(){
57+
58+
items = <RouteItem>[
59+
RouteItem(
60+
title: 'Basic API Tests',
61+
subtitle: 'Basic API Tests.',
62+
push: (BuildContext context) {
63+
Navigator.push(
64+
context,
65+
new MaterialPageRoute(
66+
builder: (BuildContext context) => new BasicSample()));
67+
}),
68+
RouteItem(
69+
title: 'P2P Call Sample',
70+
subtitle: 'P2P Call Sample.',
71+
push: (BuildContext context) {
72+
73+
showDialog<Null>(
74+
context: context,
75+
builder: (BuildContext context) {
76+
return SimpleDialog(
77+
title: const Text('Please input server ip'),
78+
children: <Widget>[
79+
TextField(
80+
onChanged: (String text){
81+
setState(() {
82+
_ip = text;
83+
});
84+
},
85+
decoration: InputDecoration(
86+
hintText: _ip,
87+
),
88+
textAlign: TextAlign.center,
89+
),
90+
91+
SimpleDialogOption(
92+
onPressed: () {},
93+
child: RaisedButton(
94+
onPressed: () {
95+
Navigator.push(
96+
context,
97+
MaterialPageRoute(
98+
builder: (BuildContext context) => CallSample(ip:_ip)
99+
));
100+
},
101+
child: const Text('connect server'),
102+
),
103+
),
104+
],
105+
);
106+
});
107+
}),
108+
];
109+
110+
}
111+
112+
113+
114+
68115
}

example/lib/src/call_sample/call_sample.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@ import 'package:webrtc/webrtc.dart';
77

88
class CallSample extends StatefulWidget {
99
static String tag = 'call_sample';
10+
11+
final String ip;
12+
13+
CallSample({Key key, @required this.ip}) : super(key: key);
14+
1015
@override
11-
_CallSampleState createState() => new _CallSampleState();
16+
_CallSampleState createState() => new _CallSampleState(serverIP:ip);
1217
}
1318

1419
class _CallSampleState extends State<CallSample> {
@@ -23,10 +28,15 @@ class _CallSampleState extends State<CallSample> {
2328
bool _inCalling = false;
2429
Timer _timer;
2530

31+
final String serverIP;
32+
33+
_CallSampleState({Key key, @required this.serverIP});
34+
2635
@override
2736
initState() {
2837
super.initState();
2938
initRenderers();
39+
_connect();
3040
}
3141

3242
initRenderers() async {
@@ -42,7 +52,7 @@ class _CallSampleState extends State<CallSample> {
4252

4353
void _connect() async {
4454
if (_signaling == null) {
45-
_signaling = new Signaling('ws://192.168.31.152:4442', _displayName);
55+
_signaling = new Signaling('ws://' + serverIP + ':4442', _displayName);
4656
await _signaling.connect();
4757

4858
_signaling.onPeers.listen((message) {

0 commit comments

Comments
 (0)
0