-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathcall_tab.dart
More file actions
269 lines (252 loc) · 8.7 KB
/
call_tab.dart
File metadata and controls
269 lines (252 loc) · 8.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
import 'package:flutter/material.dart';
import 'package:stringee_flutter_plugin_example/ui/call.dart';
import 'package:stringee_plugin/stringee_plugin.dart';
StringeeClient client = new StringeeClient();
class CallTab extends StatefulWidget {
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return CallTabState();
}
}
class CallTabState extends State<CallTab> {
String myUserId = 'Not connected...';
String token = '';
String toUser = '';
@override
void initState() {
// TODO: implement initState
super.initState();
/// Lắng nghe sự kiện của StringeeClient(kết nối, cuộc gọi đến...)
client.eventStreamController.stream.listen((event) {
Map<dynamic, dynamic> map = event;
switch (map['eventType']) {
case StringeeClientEvents.didConnect:
handleDidConnectEvent();
break;
case StringeeClientEvents.didDisconnect:
handleDiddisconnectEvent();
break;
case StringeeClientEvents.didFailWithError:
handleDidFailWithErrorEvent(
map['body']['code'], map['body']['message']);
break;
case StringeeClientEvents.requestAccessToken:
handleRequestAccessTokenEvent();
break;
case StringeeClientEvents.didReceiveCustomMessage:
handleDidReceiveCustomMessageEvent(map['body']);
break;
case StringeeClientEvents.incomingCall:
StringeeCall call = map['body'];
handleIncomingCallEvent(call);
break;
case StringeeClientEvents.incomingCall2:
StringeeCall2 call = map['body'];
handleIncomingCall2Event(call);
break;
default:
break;
}
});
/// Connect
if (token.isNotEmpty) {
client.connect(token);
}
}
@override
Widget build(BuildContext context) {
// TODO: implement build
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
resizeToAvoidBottomInset: false,
body: new Stack(
children: <Widget>[
Container(
padding: EdgeInsets.only(left: 10.0, top: 10.0),
child: new Text(
'Connected as: $myUserId',
style: new TextStyle(
color: Colors.black,
fontSize: 20.0,
),
),
),
Form(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
new Container(
padding: EdgeInsets.all(20.0),
child: new TextField(
onChanged: (String value) {
setState(() {
toUser = value;
});
},
decoration: InputDecoration(
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red),
),
),
),
),
new Container(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
new Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
mainAxisSize: MainAxisSize.max,
children: [
new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
new Container(
height: 40.0,
width: 175.0,
child: new ElevatedButton(
onPressed: () {
callTapped(
false, StringeeObjectEventType.call);
},
child: Text('CALL'),
),
),
new Container(
height: 40.0,
width: 175.0,
margin: EdgeInsets.only(top: 20.0),
child: new ElevatedButton(
onPressed: () {
callTapped(
true, StringeeObjectEventType.call);
},
child: Text('VIDEOCALL'),
),
),
],
),
new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
new Container(
height: 40.0,
width: 175.0,
child: new ElevatedButton(
style: ElevatedButton.styleFrom(
padding: EdgeInsets.only(
left: 20.0, right: 20.0)),
onPressed: () {
callTapped(
false, StringeeObjectEventType.call2);
},
child: Text('CALL2'),
),
),
new Container(
height: 40.0,
width: 175.0,
margin: EdgeInsets.only(top: 20.0),
child: new ElevatedButton(
style: ElevatedButton.styleFrom(
padding: EdgeInsets.only(
left: 20.0, right: 20.0)),
onPressed: () {
callTapped(
true, StringeeObjectEventType.call2);
},
child: Text('VIDEOCALL2'),
),
),
],
),
],
),
],
),
),
],
),
),
],
),
),
);
}
//region Handle Client Event
void handleDidConnectEvent() {
setState(() {
myUserId = client.userId!;
});
}
void handleDiddisconnectEvent() {
setState(() {
myUserId = 'Not connected';
});
}
void handleDidFailWithErrorEvent(int code, String message) {
print('code: ' + code.toString() + '\nmessage: ' + message);
}
void handleRequestAccessTokenEvent() {
print('Request new access token');
}
void handleDidReceiveCustomMessageEvent(Map<dynamic, dynamic> map) {
print('from: ' +
map['fromUserId'] +
'\nmessage: ' +
map['message'].toString());
}
void handleIncomingCallEvent(StringeeCall call) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Call(
client,
call.from!,
call.to!,
true,
call.isVideoCall,
StringeeObjectEventType.call,
stringeeCall: call,
),
),
);
}
void handleIncomingCall2Event(StringeeCall2 call) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Call(
client,
call.from!,
call.to!,
true,
call.isVideoCall,
StringeeObjectEventType.call2,
stringeeCall2: call,
),
),
);
}
void callTapped(bool isVideoCall, StringeeObjectEventType callType) {
if (toUser.isEmpty || !client.hasConnected) return;
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Call(
client,
client.userId!,
toUser,
false,
isVideoCall,
callType,
)),
);
}
@override
// TODO: implement wantKeepAlive
bool get wantKeepAlive => true;
}