-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathStringeeConstants.dart
More file actions
522 lines (460 loc) · 11.1 KB
/
StringeeConstants.dart
File metadata and controls
522 lines (460 loc) · 11.1 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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
import 'dart:async';
import 'dart:math';
import '../stringee_plugin.dart';
/// Events for StringeeClient
enum StringeeClientEvents {
didConnect,
didDisconnect,
didFailWithError,
requestAccessToken,
didReceiveCustomMessage,
incomingCall,
incomingCall2,
didReceiveChatRequest,
didReceiveTransferChatRequest,
timeoutAnswerChat,
timeoutInQueue,
conversationEnded,
userBeginTyping,
userEndTyping
}
/// Events for StringeeCall
enum StringeeCallEvents {
didChangeSignalingState,
didChangeMediaState,
didReceiveCallInfo,
didHandleOnAnotherDevice,
didReceiveLocalStream,
didReceiveRemoteStream,
}
/// Events for StringeeCall2
enum StringeeCall2Events {
didChangeSignalingState,
didChangeMediaState,
didReceiveCallInfo,
didHandleOnAnotherDevice,
didReceiveLocalStream,
didReceiveRemoteStream,
didAddVideoTrack,
didRemoveVideoTrack,
}
/// Events for StringeeChat
enum StringeeChatEvents {
didReceiveObjectChange,
}
/// Events for StringeeChat
enum StringeeRoomEvents {
didJoinRoom,
didLeaveRoom,
didAddVideoTrack,
didRemoveVideoTrack,
didReceiveRoomMessage,
trackReadyToPlay
// didReceiveVideoTrackControlNotification,
}
enum StringeeChannelType {
normal,
livechat,
facebook,
zalo,
}
enum StringeeChatRequestType {
normal,
transfer,
}
/// Type of event
enum StringeeObjectEventType {
client,
call,
call2,
chat,
room,
}
/// Error code and message in flutter:
/// -1 : StringeeClient is not initialized or disconnected
/// -2 : value is invalid
/// -3 : Object is not found
/// -4 : This function work only for Android
Future<Map<String, dynamic>> reportInvalidValue(String value) async {
Map<String, dynamic> params = {
'status': false,
'code': -2,
'message': value + ' value is invalid',
};
return params;
}
/// Type of Call
enum StringeeCallType {
appToAppOutgoing,
appToAppIncoming,
appToPhone,
phoneToApp,
}
/// Type of Signaling State
enum StringeeSignalingState {
calling,
ringing,
answered,
busy,
ended,
}
/// Type of Media State
enum StringeeMediaState {
connected,
disconnected,
}
/// Type of Video Quality
enum VideoQuality {
normal,
hd,
fullHd,
}
///Type of Scaling type
enum ScalingType {
fit,
fill,
}
///Class represents options for make a call
class MakeCallParams {
String? _from;
String? _to;
bool? _isVideoCall;
Map<dynamic, dynamic>? _customData;
VideoQuality? _videoQuality;
MakeCallParams(
String from,
String to, {
bool? isVideoCall,
Map<dynamic, dynamic>? customData,
VideoQuality? videoQuality,
}) : assert(from.trim().isNotEmpty),
assert(to.trim().isNotEmpty) {
this._from = from.trim();
this._to = to.trim();
this._isVideoCall = (isVideoCall != null) ? isVideoCall : false;
if (customData != null) this._customData = customData;
if (this._isVideoCall!)
this._videoQuality =
(videoQuality != null) ? videoQuality : VideoQuality.normal;
}
VideoQuality? get videoQuality => _videoQuality;
Map<dynamic, dynamic>? get customData => _customData;
bool? get isVideoCall => _isVideoCall;
String? get to => _to;
String? get from => _from;
Map<String, dynamic> toJson() {
Map<String, dynamic> params = new Map();
params['from'] = this._from!.trim();
params['to'] = this._to!.trim();
if (this._customData != null) params['customData'] = this._customData;
params['isVideoCall'] = this._isVideoCall;
if (this._isVideoCall!) {
switch (this._videoQuality) {
case VideoQuality.normal:
params['videoResolution'] = "NORMAL";
break;
case VideoQuality.hd:
params['videoResolution'] = "HD";
break;
case VideoQuality.fullHd:
params['videoResolution'] = "FULLHD";
break;
default:
params['videoResolution'] = "NORMAL";
break;
}
}
return params;
}
}
/// Chat object type
enum ObjectType {
conversation,
message,
}
/// Chat change type
enum ChangeType {
insert,
update,
delete,
}
/// Role of user
enum UserRole {
admin,
member,
}
/// [message]'s State
enum MsgState {
initialize,
sending,
sent,
delivered,
read,
}
/// Type of [message]
enum MsgType {
text,
photo,
video,
audio,
file,
link,
createConversation,
renameConversation,
location,
contact,
sticker,
notification,
}
extension MsgTypeValueExtension on MsgType? {
// ignore: missing_return
int get value {
switch (this) {
case MsgType.text:
return 1;
case MsgType.photo:
return 2;
case MsgType.video:
return 3;
case MsgType.audio:
return 4;
case MsgType.file:
return 5;
case MsgType.link:
return 6;
case MsgType.createConversation:
return 7;
case MsgType.renameConversation:
return 8;
case MsgType.location:
return 9;
case MsgType.contact:
return 10;
case MsgType.sticker:
return 11;
case MsgType.notification:
return 100;
default:
return 1;
}
}
}
extension MsgTypeExtension on int? {
// ignore: missing_return
MsgType get msgType {
switch (this) {
case 1:
return MsgType.text;
case 2:
return MsgType.photo;
case 3:
return MsgType.video;
case 4:
return MsgType.audio;
case 5:
return MsgType.file;
case 6:
return MsgType.link;
case 7:
return MsgType.createConversation;
case 8:
return MsgType.renameConversation;
case 9:
return MsgType.location;
case 10:
return MsgType.contact;
case 11:
return MsgType.sticker;
case 100:
return MsgType.notification;
default:
return MsgType.text;
}
}
}
/// Type of noti [message]
enum MsgNotifyType {
addParticipants,
removeParticipants,
changeGroupName,
}
extension MsgNotifyTypeExtension on int? {
// ignore: missing_return
MsgNotifyType get notifyType {
switch (this) {
case 1:
return MsgNotifyType.addParticipants;
case 2:
return MsgNotifyType.removeParticipants;
case 3:
return MsgNotifyType.changeGroupName;
default:
return MsgNotifyType.changeGroupName;
}
}
}
///Class represents options for create a new [StringeeConversation]
class StringeeConversationOption {
String? _name;
bool _isGroup = false;
bool _isDistinct = false;
String? _oaId;
String? _customData;
String? _creatorId;
StringeeConversationOption(
{required bool isGroup,
required bool isDistinct,
String? name,
String? oaId,
String? customData,
String? creatorId}) {
if (name != null) this._name = name;
this._isGroup = isGroup;
this._isDistinct = isDistinct;
if (oaId != null) this._oaId = oaId;
if (customData != null) this._customData = customData;
if (creatorId != null) this._creatorId = creatorId;
}
Map<String, dynamic> toJson() {
return {
if (_name != null) 'name': _name!.trim(),
'isGroup': _isGroup,
'isDistinct': _isDistinct,
if (_oaId != null) 'oaId': _oaId!.trim(),
if (_customData != null) 'customData': _customData!.trim(),
if (_creatorId != null) 'creatorId': _creatorId!.trim(),
};
}
}
/// Class represents the change of [StringeeConversation] and [StringeeMessage]
class StringeeObjectChange {
ChangeType? _type;
ObjectType? _objectType;
List<dynamic>? _objects;
ChangeType? get type => _type;
ObjectType? get objectType => _objectType;
List<dynamic>? get objects => _objects;
StringeeObjectChange(
ChangeType type, ObjectType objectType, List<dynamic> objects) {
this._type = type;
this._objects = objects;
this._objectType = objectType;
}
}
///Class represents server address
class StringeeServerAddress {
String? _host;
int? _port;
String? get host => _host;
int? get port => _port;
StringeeServerAddress(String host, int port) {
this._host = host;
this._port = port;
}
Map<String, dynamic> toJson() {
Map<String, dynamic> params = new Map();
if (_host != null) params['host'] = _host!.trim();
if (_port != null) params['port'] = _port;
return params;
}
}
///Class represents options for create/subscribe a [StringeeVideoTrack]
class StringeeVideoTrackOption {
late bool _audio;
late bool _video;
late bool _screen;
StringeeVideoDimensions _videoDimension =
StringeeVideoDimensions.dimesion_288;
bool get audio => _audio;
bool get video => _video;
bool get screen => _screen;
StringeeVideoDimensions get videoDimension => _videoDimension;
StringeeVideoTrackOption(
{required bool audio,
required bool video,
required bool screen,
StringeeVideoDimensions? videoDimension}) {
this._audio = audio;
this._video = video;
this._screen = screen;
if (videoDimension != null) this._videoDimension = videoDimension;
}
Map<String, dynamic> toJson() {
Map<String, dynamic> params = new Map();
params['audio'] = _audio;
params['video'] = _video;
params['screen'] = _screen;
switch (this._videoDimension) {
case StringeeVideoDimensions.dimesion_288:
params['videoDimension'] = '288';
break;
case StringeeVideoDimensions.dimesion_480:
params['videoDimension'] = '480';
break;
case StringeeVideoDimensions.dimesion_720:
params['videoDimension'] = '720';
break;
case StringeeVideoDimensions.dimesion_1080:
params['videoDimension'] = '1080';
break;
default:
params['videoDimension'] = '288';
break;
}
return params;
}
}
/// Dimension of [StringeeVideoTrack]
enum StringeeVideoDimensions {
dimesion_1080,
dimesion_720,
dimesion_480,
dimesion_288,
}
/// Type of audio device
enum AudioType {
speakerPhone,
wiredHeadset,
earpiece,
bluetooth,
other,
none,
}
extension AudioTypeX on AudioType {
static AudioType fromValue(int? value) {
switch (value) {
case 0:
return AudioType.speakerPhone;
case 1:
return AudioType.wiredHeadset;
case 2:
return AudioType.earpiece;
case 3:
return AudioType.bluetooth;
case 4:
return AudioType.other;
default:
return AudioType.none;
}
}
}
class GUIDGen {
static String generate() {
Random random = new Random(new DateTime.now().millisecond);
final String hexDigits = "0123456789abcdef";
final List<String?> uuid =
new List<String?>.filled(36, null, growable: false);
for (int i = 0; i < 36; i++) {
final int hexPos = random.nextInt(16);
uuid[i] = (hexDigits.substring(hexPos, hexPos + 1));
}
int pos = (int.parse(uuid[19]!, radix: 16) & 0x3) |
0x8; // bits 6-7 of the clock_seq_hi_and_reserved to 01
uuid[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
uuid[19] = hexDigits.substring(pos, pos + 1);
uuid[8] = uuid[13] = uuid[18] = uuid[23] = "-";
final StringBuffer buffer = new StringBuffer();
buffer.writeAll(uuid);
return buffer.toString();
}
}