podchat 11.3.0 → 12.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/changelog.md +56 -2
  2. package/package.json +2 -2
  3. package/src/chat.js +2601 -1394
package/src/chat.js CHANGED
@@ -61,6 +61,7 @@
61
61
  var Utility = new ChatUtility();
62
62
 
63
63
  var asyncClient,
64
+ currentModuleInstance = this,
64
65
  peerId,
65
66
  oldPeerId,
66
67
  userInfo,
@@ -162,9 +163,34 @@
162
163
  STOP_BOT: 65,
163
164
  BOT_COMMANDS: 68,
164
165
  THREAD_ALL_BOTS: 69,
166
+
167
+ CALL_REQUEST: 70,
168
+ ACCEPT_CALL: 71,
169
+ REJECT_CALL: 72,
170
+ RECEIVE_CALL_REQUEST: 73,
171
+ START_CALL: 74,
172
+ END_CALL_REQUEST: 75,
173
+ END_CALL: 76,
174
+ GET_CALLS: 77,
175
+
165
176
  CONTACT_SYNCED: 90,
177
+
178
+ GROUP_CALL_REQUEST: 91,
179
+ LEAVE_CALL: 92,
180
+ ADD_CALL_PARTICIPANT: 93,
181
+ CALL_PARTICIPANT_JOINED: 94,
182
+ REMOVE_CALL_PARTICIPANT: 95,
183
+ TERMINATE_CALL: 96,
184
+ MUTE_CALL_PARTICIPANT: 97,
185
+ UNMUTE_CALL_PARTICIPANT: 98,
186
+
166
187
  LOGOUT: 100,
167
188
 
189
+ ACTIVE_CALL_PARTICIPANTS: 110,
190
+ CALL_SESSION_CREATED: 111,
191
+ TURN_ON_VIDEO_CALL: 113,
192
+ TURN_OFF_VIDEO_CALL: 114,
193
+
168
194
  RECORD_CALL: 121,
169
195
  END_RECORD_CALL: 122,
170
196
  DESTINATED_RECORD_CALL: 126,
@@ -336,7 +362,39 @@
336
362
  chatWaitQueue = [],
337
363
  chatUploadQueue = [],
338
364
  chatSendQueueHandlerTimeout,
339
- fullResponseObject = params.fullResponseObject || false;
365
+ fullResponseObject = params.fullResponseObject || false,
366
+
367
+ consoleLogging = (params.asyncLogging.consoleLogging && typeof params.asyncLogging.consoleLogging === 'boolean')
368
+ ? params.asyncLogging.consoleLogging
369
+ : false,
370
+
371
+ /** call variables */
372
+ callTypes = {
373
+ 'VOICE': 0x0,
374
+ 'VIDEO': 0x1
375
+ },
376
+ currentCallParams = {},
377
+ currentCallId = null,
378
+ newCallId = null,
379
+ callClientType = {
380
+ WEB: 1,
381
+ ANDROID: 2,
382
+ DESKTOP: 3,
383
+ NODE: 4
384
+ },
385
+ callRequestController = {
386
+ callRequestReceived: false,
387
+ callEstablishedInMySide: false,
388
+ iCanAcceptTheCall: function () {
389
+ return callRequestController.callRequestReceived && callRequestController.callEstablishedInMySide;
390
+ }
391
+ },
392
+ callStopQueue = {
393
+ callStarted: false,
394
+ },
395
+ callRequestTimeout = (typeof params.callRequestTimeout === 'number' && params.callRequestTimeout >= 0) ? params.callRequestTimeout : 10000,
396
+ callNoAnswerTimeout = params.callOptions && params.callOptions.callNoAnswerTimeout ? params.callOptions.callNoAnswerTimeout : 0;
397
+
340
398
 
341
399
  /*******************************************************
342
400
  * P R I V A T E M E T H O D S *
@@ -2672,45 +2730,17 @@
2672
2730
  * Type 31 Thread Last Seen Updated
2673
2731
  */
2674
2732
  case chatMessageVOTypes.LAST_SEEN_UPDATED:
2675
- if (fullResponseObject) {
2676
- getThreads({
2677
- threadIds: [messageContent.id]
2678
- }, function (threadsResult) {
2679
- var threads = threadsResult.result.threads;
2680
-
2681
- if (!threadsResult.cache) {
2682
- fireEvent('threadEvents', {
2683
- type: 'THREAD_UNREAD_COUNT_UPDATED',
2684
- result: {
2685
- thread: threads[0],
2686
- unreadCount: messageContent.unreadCount
2687
- }
2688
- });
2733
+ var threadObject = messageContent;
2734
+ threadObject.unreadCount = (messageContent.unreadCount) ? messageContent.unreadCount : 0;
2689
2735
 
2690
- fireEvent('threadEvents', {
2691
- type: 'THREAD_LAST_ACTIVITY_TIME',
2692
- result: {
2693
- thread: threads[0]
2694
- }
2695
- });
2696
- }
2697
- });
2698
- } else {
2699
- fireEvent('threadEvents', {
2700
- type: 'THREAD_UNREAD_COUNT_UPDATED',
2701
- result: {
2702
- thread: threadId,
2703
- unreadCount: messageContent.unreadCount
2704
- }
2705
- });
2736
+ fireEvent('threadEvents', {
2737
+ type: 'THREAD_UNREAD_COUNT_UPDATED',
2738
+ result: {
2739
+ thread: (fullResponseObject ? threadObject : messageContent.id),
2740
+ unreadCount: (messageContent.unreadCount) ? messageContent.unreadCount : 0
2741
+ }
2742
+ });
2706
2743
 
2707
- fireEvent('threadEvents', {
2708
- type: 'THREAD_LAST_ACTIVITY_TIME',
2709
- result: {
2710
- thread: threadId
2711
- }
2712
- });
2713
- }
2714
2744
 
2715
2745
  break;
2716
2746
 
@@ -3120,214 +3150,576 @@
3120
3150
  break;
3121
3151
 
3122
3152
  /**
3123
- * Type 90 Contacts Synced
3153
+ * Type 70 Send Call Request
3124
3154
  */
3125
- case chatMessageVOTypes.CONTACT_SYNCED:
3126
- fireEvent('contactEvents', {
3127
- type: 'CONTACTS_SYNCED',
3155
+ case chatMessageVOTypes.CALL_REQUEST:
3156
+ callRequestController.callRequestReceived = true;
3157
+ callReceived({
3158
+ callId: messageContent.callId
3159
+ }, function (r) {
3160
+
3161
+ });
3162
+
3163
+ if (messagesCallbacks[uniqueId]) {
3164
+ messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
3165
+ }
3166
+
3167
+ fireEvent('callEvents', {
3168
+ type: 'RECEIVE_CALL',
3128
3169
  result: messageContent
3129
3170
  });
3171
+
3172
+ if (messageContent.callId > 0) {
3173
+ if(!currentCallId ) {
3174
+ currentCallId = messageContent.callId;
3175
+ }
3176
+ else
3177
+ newCallId = messageContent.callId;
3178
+ } else {
3179
+ fireEvent('callEvents', {
3180
+ type: 'PARTNER_RECEIVED_YOUR_CALL',
3181
+ result: messageContent
3182
+ });
3183
+ }
3184
+
3185
+ currentCallId = messageContent.callId;
3186
+
3130
3187
  break;
3131
3188
 
3132
3189
  /**
3133
- * Type 121 Record Call Request
3190
+ * Type 71 Accept Call Request
3134
3191
  */
3135
- case chatMessageVOTypes.RECORD_CALL:
3192
+ case chatMessageVOTypes.ACCEPT_CALL:
3136
3193
  if (messagesCallbacks[uniqueId]) {
3137
3194
  messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
3138
3195
  }
3139
3196
 
3140
3197
  fireEvent('callEvents', {
3141
- type: 'START_RECORDING_CALL',
3198
+ type: 'ACCEPT_CALL',
3142
3199
  result: messageContent
3143
3200
  });
3144
3201
 
3145
3202
  break;
3146
3203
 
3147
3204
  /**
3148
- * Type 122 End Record Call Request
3205
+ * Type 72 Reject Call Request
3149
3206
  */
3150
- case chatMessageVOTypes.END_RECORD_CALL:
3207
+ case chatMessageVOTypes.REJECT_CALL:
3151
3208
  if (messagesCallbacks[uniqueId]) {
3152
3209
  messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
3153
3210
  }
3154
3211
 
3155
3212
  fireEvent('callEvents', {
3156
- type: 'STOP_RECORDING_CALL',
3213
+ type: 'REJECT_CALL',
3157
3214
  result: messageContent
3158
3215
  });
3159
3216
 
3160
3217
  break;
3161
3218
 
3162
3219
  /**
3163
- * Type 126 Destined Record Call Request
3220
+ * Type 73 Receive Call Request
3164
3221
  */
3165
- case chatMessageVOTypes.DESTINATED_RECORD_CALL:
3222
+ case chatMessageVOTypes.RECEIVE_CALL_REQUEST:
3223
+ if (messagesCallbacks[uniqueId]) {
3224
+ messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
3225
+ }
3226
+
3227
+ if (messageContent.callId > 0) {
3228
+ fireEvent('callEvents', {
3229
+ type: 'RECEIVE_CALL',
3230
+ result: messageContent
3231
+ });
3232
+ if(!currentCallId ) {
3233
+ currentCallId = messageContent.callId;
3234
+ }
3235
+ else
3236
+ newCallId = messageContent.callId;
3237
+ } else {
3238
+ fireEvent('callEvents', {
3239
+ type: 'PARTNER_RECEIVED_YOUR_CALL',
3240
+ result: messageContent
3241
+ });
3242
+ }
3243
+
3244
+ // currentCallId = messageContent.callId;
3245
+
3246
+ break;
3247
+
3248
+ /**
3249
+ * Type 74 Start Call Request
3250
+ */
3251
+ case chatMessageVOTypes.START_CALL:
3252
+ if(!callRequestController.iCanAcceptTheCall()) {
3253
+ //Do not handle the call if it is already started elsewhere for the same user
3254
+ fireEvent('callEvents', {
3255
+ type: 'CALL_STARTED_ELSEWHERE',
3256
+ message: 'Call already started somewhere else..., aborting...'
3257
+ });
3258
+ return;
3259
+ }
3260
+
3166
3261
  if (messagesCallbacks[uniqueId]) {
3167
3262
  messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
3168
3263
  }
3169
3264
 
3170
3265
  fireEvent('callEvents', {
3171
- type: 'START_RECORDING_CALL',
3266
+ type: 'CALL_STARTED',
3172
3267
  result: messageContent
3173
3268
  });
3174
3269
 
3270
+ if (typeof messageContent === 'object'
3271
+ && messageContent.hasOwnProperty('chatDataDto')
3272
+ && !!messageContent.chatDataDto.kurentoAddress) {
3273
+ } else {
3274
+ fireEvent('callEvents', {
3275
+ type: 'CALL_ERROR',
3276
+ message: 'Chat Data DTO is not present!'
3277
+ });
3278
+ }
3279
+
3175
3280
  break;
3176
3281
 
3177
- /**
3178
- * Type 127 Assistant call started
3179
- *
3180
- * Tells the assistant that a call started
3282
+ /**
3283
+ * Type 75 End Call Request
3181
3284
  */
3182
- case chatMessageVOTypes.ASSISTANT_CALL_STARTED:
3183
- /*if (messagesCallbacks[uniqueId]) {
3285
+ case chatMessageVOTypes.END_CALL_REQUEST:
3286
+ if (messagesCallbacks[uniqueId]) {
3184
3287
  messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
3185
- }*/
3288
+ }
3186
3289
 
3187
3290
  fireEvent('callEvents', {
3188
- type: 'ASSISTANT_CALL_STARTED',
3189
- result: {
3190
- callId: threadId
3191
- }
3291
+ type: 'END_CALL',
3292
+ result: messageContent
3192
3293
  });
3193
3294
 
3295
+ callStop();
3296
+
3194
3297
  break;
3195
3298
 
3196
- /**
3197
- * Type 128 Assistant call ended
3198
- *
3199
- * Tells the assistant that a call ended
3299
+ /**
3300
+ * Type 76 Call Ended
3200
3301
  */
3201
- case chatMessageVOTypes.ASSISTANT_CALL_ENDED:
3202
- /* if (messagesCallbacks[uniqueId]) {
3302
+ case chatMessageVOTypes.END_CALL:
3303
+ if (messagesCallbacks[uniqueId]) {
3203
3304
  messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
3204
- }*/
3305
+ }
3205
3306
 
3206
- fireEvent('callEvents', {
3207
- type: 'ASSISTANT_CALL_ENDED'
3307
+ fireEvent('callEvents', {
3308
+ type: 'CALL_ENDED',
3309
+ callId: threadId
3208
3310
  });
3209
3311
 
3312
+ callStop();
3313
+
3210
3314
  break;
3211
3315
 
3212
3316
  /**
3213
- * Type 999 All unknown errors
3317
+ * Type 77 Get Calls History
3214
3318
  */
3215
- case chatMessageVOTypes.ERROR:
3319
+ case chatMessageVOTypes.GET_CALLS:
3216
3320
  if (messagesCallbacks[uniqueId]) {
3217
- messagesCallbacks[uniqueId](Utility.createReturnData(true, messageContent.message, messageContent.code, messageContent, 0));
3321
+ messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
3218
3322
  }
3219
3323
 
3220
- /**
3221
- * If error code is 21, Token is invalid &
3222
- * user should logged out
3223
- */
3224
- if (messageContent.code == 21) {
3225
- // TODO: Temporarily removed due to unknown side-effects
3226
- // chatState = false;
3227
- // asyncClient.logout();
3228
- // clearChatServerCaches();
3229
- }
3324
+ break;
3230
3325
 
3231
- fireEvent('error', {
3232
- code: messageContent.code,
3233
- message: messageContent.message,
3234
- error: messageContent
3326
+
3327
+ /**
3328
+ * Type 90 Contacts Synced
3329
+ */
3330
+ case chatMessageVOTypes.CONTACT_SYNCED:
3331
+ fireEvent('contactEvents', {
3332
+ type: 'CONTACTS_SYNCED',
3333
+ result: messageContent
3235
3334
  });
3236
3335
  break;
3237
- }
3238
- },
3239
3336
 
3240
- /**
3241
- * Send Message Callbacks Handler
3242
- *
3243
- * When you send Delivery or Seen Acknowledgements of a message
3244
- * You should send Delivery and Seen for all the Messages before
3245
- * that message so that you wont have un delivered/unseen messages
3246
- * after seeing the last message of a thread
3247
- *
3248
- * @access private
3249
- *
3250
- * @param {int} actionType Switch between Delivery or Seen
3251
- * @param {long} threadId Id of thread
3252
- * @param {string} uniqueId uniqueId of message
3253
- *
3254
- * @return {undefined}
3255
- */
3256
- sendMessageCallbacksHandler = function (actionType, threadId, uniqueId) {
3257
- switch (actionType) {
3337
+ /**
3338
+ * Type 91 Send Group Call Request
3339
+ */
3340
+ case chatMessageVOTypes.GROUP_CALL_REQUEST:
3341
+ callRequestController.callRequestReceived = true;
3342
+ callReceived({
3343
+ callId: messageContent.callId
3344
+ }, function (r) {});
3258
3345
 
3259
- case chatMessageVOTypes.DELIVERY:
3260
- if (threadCallbacks[threadId]) {
3261
- var lastThreadCallbackIndex = Object.keys(threadCallbacks[threadId])
3262
- .indexOf(uniqueId);
3263
- if (lastThreadCallbackIndex !== undefined) {
3264
- while (lastThreadCallbackIndex > -1) {
3265
- var tempUniqueId = Object.entries(threadCallbacks[threadId])[lastThreadCallbackIndex][0];
3266
- if (sendMessageCallbacks[tempUniqueId] && sendMessageCallbacks[tempUniqueId].onDeliver) {
3267
- if (threadCallbacks[threadId][tempUniqueId] && threadCallbacks[threadId][tempUniqueId].onSent) {
3268
- sendMessageCallbacks[tempUniqueId].onDeliver(
3269
- {
3270
- uniqueId: tempUniqueId
3271
- });
3272
- delete (sendMessageCallbacks[tempUniqueId].onDeliver);
3273
- threadCallbacks[threadId][tempUniqueId].onDeliver = true;
3274
- }
3275
- }
3346
+ if (messagesCallbacks[uniqueId]) {
3347
+ messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
3348
+ }
3276
3349
 
3277
- lastThreadCallbackIndex -= 1;
3278
- }
3279
- }
3350
+ if (messageContent.callId > 0) {
3351
+ if(!currentCallId )
3352
+ currentCallId = messageContent.callId;
3353
+ else
3354
+ newCallId = messageContent.callId;
3280
3355
  }
3281
- break;
3282
3356
 
3283
- case chatMessageVOTypes.SEEN:
3284
- if (threadCallbacks[threadId]) {
3285
- var lastThreadCallbackIndex = Object.keys(threadCallbacks[threadId])
3286
- .indexOf(uniqueId);
3287
- if (lastThreadCallbackIndex !== undefined) {
3288
- while (lastThreadCallbackIndex > -1) {
3289
- var tempUniqueId = Object.entries(threadCallbacks[threadId])[lastThreadCallbackIndex][0];
3357
+ fireEvent('callEvents', {
3358
+ type: 'RECEIVE_CALL',
3359
+ result: messageContent
3360
+ });
3290
3361
 
3291
- if (sendMessageCallbacks[tempUniqueId] && sendMessageCallbacks[tempUniqueId].onSeen) {
3292
- if (threadCallbacks[threadId][tempUniqueId] && threadCallbacks[threadId][tempUniqueId].onSent) {
3293
- if (!threadCallbacks[threadId][tempUniqueId].onDeliver) {
3294
- sendMessageCallbacks[tempUniqueId].onDeliver(
3295
- {
3296
- uniqueId: tempUniqueId
3297
- });
3298
- delete (sendMessageCallbacks[tempUniqueId].onDeliver);
3299
- threadCallbacks[threadId][tempUniqueId].onDeliver = true;
3300
- }
3362
+ // currentCallId = messageContent.callId;
3301
3363
 
3302
- sendMessageCallbacks[tempUniqueId].onSeen(
3303
- {
3304
- uniqueId: tempUniqueId
3305
- });
3364
+ break;
3306
3365
 
3307
- delete (sendMessageCallbacks[tempUniqueId].onSeen);
3308
- threadCallbacks[threadId][tempUniqueId].onSeen = true;
3366
+ /**
3367
+ * Type 92 Call Partner Leave
3368
+ */
3369
+ case chatMessageVOTypes.LEAVE_CALL:
3370
+ if (messagesCallbacks[uniqueId]) {
3371
+ messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
3372
+ }
3309
3373
 
3310
- if (threadCallbacks[threadId][tempUniqueId].onSent &&
3311
- threadCallbacks[threadId][tempUniqueId].onDeliver &&
3312
- threadCallbacks[threadId][tempUniqueId].onSeen) {
3313
- delete threadCallbacks[threadId][tempUniqueId];
3314
- delete sendMessageCallbacks[tempUniqueId];
3315
- }
3316
- }
3317
- }
3374
+ fireEvent('callEvents', {
3375
+ type: 'CALL_PARTICIPANT_LEFT',
3376
+ result: messageContent
3377
+ });
3318
3378
 
3319
- lastThreadCallbackIndex -= 1;
3320
- }
3321
- }
3322
- }
3323
3379
  break;
3324
3380
 
3325
- default:
3381
+ /**
3382
+ * Type 93 Add Call Participant
3383
+ */
3384
+ case chatMessageVOTypes.ADD_CALL_PARTICIPANT:
3385
+ if (messagesCallbacks[uniqueId]) {
3386
+ messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
3387
+ }
3388
+
3326
3389
  break;
3327
- }
3328
- },
3329
3390
 
3330
- /**
3391
+ /**
3392
+ * Type 94 Call Participant Joined
3393
+ */
3394
+ case chatMessageVOTypes.CALL_PARTICIPANT_JOINED:
3395
+ if (messagesCallbacks[uniqueId]) {
3396
+ messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
3397
+ }
3398
+
3399
+ fireEvent('callEvents', {
3400
+ type: 'CALL_PARTICIPANT_JOINED',
3401
+ result: messageContent
3402
+ });
3403
+
3404
+ break;
3405
+
3406
+ /**
3407
+ * Type 95 Remove Call Participant
3408
+ */
3409
+ case chatMessageVOTypes.REMOVE_CALL_PARTICIPANT:
3410
+ if (messagesCallbacks[uniqueId]) {
3411
+ messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
3412
+ }
3413
+
3414
+ fireEvent('callEvents', {
3415
+ type: 'CALL_PARTICIPANT_REMOVED',
3416
+ result: messageContent
3417
+ });
3418
+
3419
+ break;
3420
+
3421
+ /**
3422
+ * Type 96 Terminate Call
3423
+ */
3424
+ case chatMessageVOTypes.TERMINATE_CALL:
3425
+ if (messagesCallbacks[uniqueId]) {
3426
+ messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
3427
+ }
3428
+
3429
+ fireEvent('callEvents', {
3430
+ type: 'TERMINATE_CALL',
3431
+ result: messageContent
3432
+ });
3433
+
3434
+ callStop();
3435
+
3436
+ break;
3437
+
3438
+ /**
3439
+ * Type 97 Mute Call Participant
3440
+ */
3441
+ case chatMessageVOTypes.MUTE_CALL_PARTICIPANT:
3442
+ if (messagesCallbacks[uniqueId]) {
3443
+ messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
3444
+ }
3445
+
3446
+
3447
+ fireEvent('callEvents', {
3448
+ type: 'CALL_PARTICIPANT_MUTE',
3449
+ result: messageContent
3450
+ });
3451
+
3452
+ break;
3453
+
3454
+ /**
3455
+ * Type 98 UnMute Call Participant
3456
+ */
3457
+ case chatMessageVOTypes.UNMUTE_CALL_PARTICIPANT:
3458
+ if (messagesCallbacks[uniqueId]) {
3459
+ messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
3460
+ } else {
3461
+ }
3462
+
3463
+ fireEvent('callEvents', {
3464
+ type: 'CALL_PARTICIPANT_UNMUTE',
3465
+ result: messageContent
3466
+ });
3467
+
3468
+ break;
3469
+
3470
+ /**
3471
+ * Type 110 Active Call Participants List
3472
+ */
3473
+ case chatMessageVOTypes.ACTIVE_CALL_PARTICIPANTS:
3474
+ if (messagesCallbacks[uniqueId]) {
3475
+ messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
3476
+ }
3477
+
3478
+ break;
3479
+
3480
+ /**
3481
+ * Type 111 Kafka Call Session Created
3482
+ */
3483
+ case chatMessageVOTypes.CALL_SESSION_CREATED:
3484
+ if(!callRequestController.callEstablishedInMySide)
3485
+ return;
3486
+
3487
+ fireEvent('callEvents', {
3488
+ type: 'CALL_SESSION_CREATED',
3489
+ result: messageContent
3490
+ });
3491
+ if(!currentCallId)
3492
+ currentCallId = messageContent.callId;
3493
+ else
3494
+ newCallId = messageContent.callId;
3495
+
3496
+ // currentCallId = messageContent.callId;
3497
+
3498
+ break;
3499
+
3500
+ /**
3501
+ * Type 113 Turn On Video Call
3502
+ */
3503
+ case chatMessageVOTypes.TURN_ON_VIDEO_CALL:
3504
+ if (messagesCallbacks[uniqueId]) {
3505
+ messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
3506
+ }
3507
+
3508
+ fireEvent('callEvents', {
3509
+ type: 'TURN_ON_VIDEO_CALL',
3510
+ result: messageContent
3511
+ });
3512
+
3513
+ break;
3514
+
3515
+ /**
3516
+ * Type 114 Turn Off Video Call
3517
+ */
3518
+ case chatMessageVOTypes.TURN_OFF_VIDEO_CALL:
3519
+ if (messagesCallbacks[uniqueId]) {
3520
+ messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
3521
+ }
3522
+
3523
+ fireEvent('callEvents', {
3524
+ type: 'TURN_OFF_VIDEO_CALL',
3525
+ result: messageContent
3526
+ });
3527
+
3528
+ break;
3529
+
3530
+ /**
3531
+ * Type 121 Record Call Request
3532
+ */
3533
+ case chatMessageVOTypes.RECORD_CALL:
3534
+ if (messagesCallbacks[uniqueId]) {
3535
+ messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
3536
+ }
3537
+
3538
+ fireEvent('callEvents', {
3539
+ type: 'START_RECORDING_CALL',
3540
+ result: messageContent
3541
+ });
3542
+
3543
+ break;
3544
+
3545
+ /**
3546
+ * Type 122 End Record Call Request
3547
+ */
3548
+ case chatMessageVOTypes.END_RECORD_CALL:
3549
+ if (messagesCallbacks[uniqueId]) {
3550
+ messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
3551
+ }
3552
+
3553
+ fireEvent('callEvents', {
3554
+ type: 'STOP_RECORDING_CALL',
3555
+ result: messageContent
3556
+ });
3557
+
3558
+ break;
3559
+
3560
+ /**
3561
+ * Type 126 Destined Record Call Request
3562
+ */
3563
+ case chatMessageVOTypes.DESTINATED_RECORD_CALL:
3564
+ if (messagesCallbacks[uniqueId]) {
3565
+ messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
3566
+ }
3567
+
3568
+ fireEvent('callEvents', {
3569
+ type: 'START_RECORDING_CALL',
3570
+ result: messageContent
3571
+ });
3572
+
3573
+ break;
3574
+
3575
+ /**
3576
+ * Type 127 Assistant call started
3577
+ *
3578
+ * Tells the assistant that a call started
3579
+ */
3580
+ case chatMessageVOTypes.ASSISTANT_CALL_STARTED:
3581
+ fireEvent('callEvents', {
3582
+ type: 'ASSISTANT_CALL_STARTED',
3583
+ result: {
3584
+ callId: threadId
3585
+ }
3586
+ });
3587
+
3588
+ break;
3589
+
3590
+ /**
3591
+ * Type 128 Assistant call ended
3592
+ *
3593
+ * Tells the assistant that a call ended
3594
+ */
3595
+ case chatMessageVOTypes.ASSISTANT_CALL_ENDED:
3596
+ fireEvent('callEvents', {
3597
+ type: 'ASSISTANT_CALL_ENDED',
3598
+ callId: threadId
3599
+ });
3600
+
3601
+ break;
3602
+
3603
+ /**
3604
+ * Type 999 All unknown errors
3605
+ */
3606
+ case chatMessageVOTypes.ERROR:
3607
+ if (messagesCallbacks[uniqueId]) {
3608
+ messagesCallbacks[uniqueId](Utility.createReturnData(true, messageContent.message, messageContent.code, messageContent, 0));
3609
+ }
3610
+
3611
+ /**
3612
+ * If error code is 21, Token is invalid &
3613
+ * user should logged out
3614
+ */
3615
+ if (messageContent.code == 21) {
3616
+ // TODO: Temporarily removed due to unknown side-effects
3617
+ // chatState = false;
3618
+ // asyncClient.logout();
3619
+ // clearChatServerCaches();
3620
+ }
3621
+
3622
+ fireEvent('error', {
3623
+ code: messageContent.code,
3624
+ message: messageContent.message,
3625
+ error: messageContent
3626
+ });
3627
+
3628
+ break;
3629
+ }
3630
+ },
3631
+
3632
+ /**
3633
+ * Send Message Callbacks Handler
3634
+ *
3635
+ * When you send Delivery or Seen Acknowledgements of a message
3636
+ * You should send Delivery and Seen for all the Messages before
3637
+ * that message so that you wont have un delivered/unseen messages
3638
+ * after seeing the last message of a thread
3639
+ *
3640
+ * @access private
3641
+ *
3642
+ * @param {int} actionType Switch between Delivery or Seen
3643
+ * @param {long} threadId Id of thread
3644
+ * @param {string} uniqueId uniqueId of message
3645
+ *
3646
+ * @return {undefined}
3647
+ */
3648
+ sendMessageCallbacksHandler = function (actionType, threadId, uniqueId) {
3649
+ switch (actionType) {
3650
+
3651
+ case chatMessageVOTypes.DELIVERY:
3652
+ if (threadCallbacks[threadId]) {
3653
+ var lastThreadCallbackIndex = Object.keys(threadCallbacks[threadId])
3654
+ .indexOf(uniqueId);
3655
+ if (lastThreadCallbackIndex !== undefined) {
3656
+ while (lastThreadCallbackIndex > -1) {
3657
+ var tempUniqueId = Object.entries(threadCallbacks[threadId])[lastThreadCallbackIndex][0];
3658
+ if (sendMessageCallbacks[tempUniqueId] && sendMessageCallbacks[tempUniqueId].onDeliver) {
3659
+ if (threadCallbacks[threadId][tempUniqueId] && threadCallbacks[threadId][tempUniqueId].onSent) {
3660
+ sendMessageCallbacks[tempUniqueId].onDeliver(
3661
+ {
3662
+ uniqueId: tempUniqueId
3663
+ });
3664
+ delete (sendMessageCallbacks[tempUniqueId].onDeliver);
3665
+ threadCallbacks[threadId][tempUniqueId].onDeliver = true;
3666
+ }
3667
+ }
3668
+
3669
+ lastThreadCallbackIndex -= 1;
3670
+ }
3671
+ }
3672
+ }
3673
+ break;
3674
+
3675
+ case chatMessageVOTypes.SEEN:
3676
+ if (threadCallbacks[threadId]) {
3677
+ var lastThreadCallbackIndex = Object.keys(threadCallbacks[threadId])
3678
+ .indexOf(uniqueId);
3679
+ if (lastThreadCallbackIndex !== undefined) {
3680
+ while (lastThreadCallbackIndex > -1) {
3681
+ var tempUniqueId = Object.entries(threadCallbacks[threadId])[lastThreadCallbackIndex][0];
3682
+
3683
+ if (sendMessageCallbacks[tempUniqueId] && sendMessageCallbacks[tempUniqueId].onSeen) {
3684
+ if (threadCallbacks[threadId][tempUniqueId] && threadCallbacks[threadId][tempUniqueId].onSent) {
3685
+ if (!threadCallbacks[threadId][tempUniqueId].onDeliver) {
3686
+ sendMessageCallbacks[tempUniqueId].onDeliver(
3687
+ {
3688
+ uniqueId: tempUniqueId
3689
+ });
3690
+ delete (sendMessageCallbacks[tempUniqueId].onDeliver);
3691
+ threadCallbacks[threadId][tempUniqueId].onDeliver = true;
3692
+ }
3693
+
3694
+ sendMessageCallbacks[tempUniqueId].onSeen(
3695
+ {
3696
+ uniqueId: tempUniqueId
3697
+ });
3698
+
3699
+ delete (sendMessageCallbacks[tempUniqueId].onSeen);
3700
+ threadCallbacks[threadId][tempUniqueId].onSeen = true;
3701
+
3702
+ if (threadCallbacks[threadId][tempUniqueId].onSent &&
3703
+ threadCallbacks[threadId][tempUniqueId].onDeliver &&
3704
+ threadCallbacks[threadId][tempUniqueId].onSeen) {
3705
+ delete threadCallbacks[threadId][tempUniqueId];
3706
+ delete sendMessageCallbacks[tempUniqueId];
3707
+ }
3708
+ }
3709
+ }
3710
+
3711
+ lastThreadCallbackIndex -= 1;
3712
+ }
3713
+ }
3714
+ }
3715
+ break;
3716
+
3717
+ default:
3718
+ break;
3719
+ }
3720
+ },
3721
+
3722
+ /**
3331
3723
  * New Message Handler
3332
3724
  *
3333
3725
  * Handles Event Emitter of a newly received Chat Message
@@ -3401,43 +3793,30 @@
3401
3793
  }
3402
3794
  });
3403
3795
 
3404
- if (fullResponseObject) {
3405
- getThreads({
3406
- threadIds: [threadId]
3407
- }, function (threadsResult) {
3408
- var threads = threadsResult.result.threads;
3796
+ var threadObject = message.conversation;
3797
+ var lastMessageVoCopy = Object.assign({}, message);
3798
+ lastMessageVoCopy.conversation && delete lastMessageVoCopy.conversation;
3409
3799
 
3410
- fireEvent('threadEvents', {
3411
- type: 'THREAD_UNREAD_COUNT_UPDATED',
3412
- result: {
3413
- thread: threads[0],
3414
- unreadCount: threads[0].unreadCount
3415
- }
3416
- });
3800
+ threadObject.lastParticipantImage = (!!message.participant && message.participant.hasOwnProperty('image')) ? message.participant.image : '';
3801
+ threadObject.lastMessageVO = lastMessageVoCopy;
3802
+ threadObject.lastParticipantName = (!!message.participant && message.participant.hasOwnProperty('name')) ? message.participant.name : '';
3803
+ threadObject.lastMessage = (message.hasOwnProperty('message')) ? message.message : '';
3417
3804
 
3418
- fireEvent('threadEvents', {
3419
- type: 'THREAD_LAST_ACTIVITY_TIME',
3420
- result: {
3421
- thread: threads[0]
3422
- }
3423
- });
3424
- });
3425
- } else {
3426
- fireEvent('threadEvents', {
3427
- type: 'THREAD_LAST_ACTIVITY_TIME',
3428
- result: {
3429
- thread: threadId
3430
- }
3431
- });
3432
3805
 
3433
- fireEvent('threadEvents', {
3434
- type: 'THREAD_UNREAD_COUNT_UPDATED',
3435
- result: {
3436
- thread: messageContent.id,
3437
- unreadCount: messageContent.conversation.unreadCount
3438
- }
3439
- });
3440
- }
3806
+ fireEvent('threadEvents', {
3807
+ type: 'THREAD_UNREAD_COUNT_UPDATED',
3808
+ result: {
3809
+ thread: (fullResponseObject ? threadObject : messageContent.id),
3810
+ unreadCount: (threadObject.unreadCount) ? threadObject.unreadCount : 0
3811
+ }
3812
+ });
3813
+
3814
+ fireEvent('threadEvents', {
3815
+ type: 'THREAD_LAST_ACTIVITY_TIME',
3816
+ result: {
3817
+ thread: (fullResponseObject ? threadObject : messageContent.id),
3818
+ }
3819
+ });
3441
3820
 
3442
3821
  /**
3443
3822
  * Update waitQ and remove sent messages from it
@@ -8655,52 +9034,207 @@
8655
9034
  };
8656
9035
  },
8657
9036
 
8658
- cancelFileDownload = function (params, callback) {
8659
- if (params) {
8660
- if (typeof params.uniqueId == 'string') {
8661
- var uniqueId = params.uniqueId;
8662
- httpRequestObject[eval('uniqueId')] && httpRequestObject[eval('uniqueId')].abort();
8663
- httpRequestObject[eval('uniqueId')] && delete (httpRequestObject[eval('uniqueId')]);
8664
-
8665
- callback && callback(uniqueId);
9037
+ cancelFileDownload = function (params, callback) {
9038
+ if (params) {
9039
+ if (typeof params.uniqueId == 'string') {
9040
+ var uniqueId = params.uniqueId;
9041
+ httpRequestObject[eval('uniqueId')] && httpRequestObject[eval('uniqueId')].abort();
9042
+ httpRequestObject[eval('uniqueId')] && delete (httpRequestObject[eval('uniqueId')]);
9043
+
9044
+ callback && callback(uniqueId);
9045
+ }
9046
+ }
9047
+ return;
9048
+ },
9049
+
9050
+ //TODO Change Node Version
9051
+ getImageFormUrl = function (url, callback) {
9052
+ var img = new Image();
9053
+ img.setAttribute('crossOrigin', 'anonymous');
9054
+ img.onload = function (a) {
9055
+ var canvas = document.createElement("canvas");
9056
+ canvas.width = this.width;
9057
+ canvas.height = this.height;
9058
+ var ctx = canvas.getContext("2d");
9059
+ ctx.drawImage(this, 0, 0);
9060
+
9061
+ var dataURI = canvas.toDataURL("image/jpg");
9062
+
9063
+ // convert base64/URLEncoded data component to raw binary data held in a string
9064
+ var byteString;
9065
+ if (dataURI.split(',')[0].indexOf('base64') >= 0)
9066
+ byteString = atob(dataURI.split(',')[1]);
9067
+ else
9068
+ byteString = unescape(dataURI.split(',')[1]);
9069
+
9070
+ // separate out the mime component
9071
+ var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];
9072
+
9073
+ // write the bytes of the string to a typed array
9074
+ var ia = new Uint8Array(byteString.length);
9075
+ for (var i = 0; i < byteString.length; i++) {
9076
+ ia[i] = byteString.charCodeAt(i);
9077
+ }
9078
+
9079
+ return callback(new Blob([ia], {type: mimeString}));
9080
+ }
9081
+
9082
+ img.src = url;
9083
+ },
9084
+
9085
+ callReceived = function (params, callback) {
9086
+ var receiveCallData = {
9087
+ chatMessageVOType: chatMessageVOTypes.RECEIVE_CALL_REQUEST,
9088
+ typeCode: params.typeCode,
9089
+ pushMsgType: 3,
9090
+ token: token
9091
+ };
9092
+
9093
+ if (params) {
9094
+ if (typeof +params.callId === 'number' && params.callId > 0) {
9095
+ receiveCallData.subjectId = +params.callId;
9096
+ } else {
9097
+ fireEvent('error', {
9098
+ code: 999,
9099
+ message: 'Invalid call id!'
9100
+ });
9101
+ return;
9102
+ }
9103
+ } else {
9104
+ fireEvent('error', {
9105
+ code: 999,
9106
+ message: 'No params have been sent to ReceiveCall()'
9107
+ });
9108
+ return;
9109
+ }
9110
+
9111
+ return sendMessage(receiveCallData, {
9112
+ onResult: function (result) {
9113
+ callback && callback(result);
9114
+ }
9115
+ });
9116
+ },
9117
+
9118
+ endCall = function (params, callback) {
9119
+ consoleLogging && console.log('[SDK][endCall] called...');
9120
+
9121
+ var endCallData = {
9122
+ chatMessageVOType: chatMessageVOTypes.END_CALL_REQUEST,
9123
+ typeCode: params.typeCode,
9124
+ pushMsgType: 3,
9125
+ token: token
9126
+ };
9127
+
9128
+ if (!callRequestController.callEstablishedInMySide) {
9129
+ return;
9130
+ }
9131
+
9132
+ if (params) {
9133
+ if (typeof +params.callId === 'number' && params.callId > 0) {
9134
+ endCallData.subjectId = +params.callId;
9135
+ } else {
9136
+ fireEvent('error', {
9137
+ code: 999,
9138
+ message: 'Invalid call id!'
9139
+ });
9140
+ return;
9141
+ }
9142
+ } else {
9143
+ fireEvent('error', {
9144
+ code: 999,
9145
+ message: 'No params have been sent to End the call!'
9146
+ });
9147
+ return;
9148
+ }
9149
+
9150
+ callStop();
9151
+
9152
+ return sendMessage(endCallData, {
9153
+ onResult: function (result) {
9154
+ callback && callback(result);
9155
+ }
9156
+ });
9157
+ },
9158
+
9159
+ callStop = function () {
9160
+ if (callStopQueue.callStarted) {
9161
+ callStopQueue.callStarted = false;
8666
9162
  }
8667
- }
8668
- return;
9163
+
9164
+ callRequestController.callEstablishedInMySide = false;
9165
+ callRequestController.callRequestReceived = false;
9166
+ currentCallParams = {};
9167
+ currentCallId = null;
8669
9168
  },
8670
9169
 
8671
- //TODO Change Node Version
8672
- getImageFormUrl = function (url, callback) {
8673
- var img = new Image();
8674
- img.setAttribute('crossOrigin', 'anonymous');
8675
- img.onload = function (a) {
8676
- var canvas = document.createElement("canvas");
8677
- canvas.width = this.width;
8678
- canvas.height = this.height;
8679
- var ctx = canvas.getContext("2d");
8680
- ctx.drawImage(this, 0, 0);
9170
+ /**
9171
+ * Reformat Call Participants
9172
+ *
9173
+ * This functions reformats given Array of call Participants
9174
+ * into proper call participant
9175
+ *
9176
+ * @access private
9177
+ *
9178
+ * @param {object} participantsContent Array of Call Participant Objects
9179
+ * @param {int} threadId Id of call
9180
+ *
9181
+ * @return {object} Formatted Call Participant Array
9182
+ */
9183
+ reformatCallParticipants = function (participantsContent) {
9184
+ var returnData = [];
8681
9185
 
8682
- var dataURI = canvas.toDataURL("image/jpg");
9186
+ for (var i = 0; i < participantsContent.length; i++) {
9187
+ returnData.push(formatDataToMakeCallParticipant(participantsContent[i]));
9188
+ }
8683
9189
 
8684
- // convert base64/URLEncoded data component to raw binary data held in a string
8685
- var byteString;
8686
- if (dataURI.split(',')[0].indexOf('base64') >= 0)
8687
- byteString = atob(dataURI.split(',')[1]);
8688
- else
8689
- byteString = unescape(dataURI.split(',')[1]);
9190
+ return returnData;
9191
+ },
8690
9192
 
8691
- // separate out the mime component
8692
- var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];
9193
+ formatDataToMakeCallParticipant = function (messageContent) {
9194
+ /**
9195
+ * + CallParticipantVO {object}
9196
+ * - id {int}
9197
+ * - joinTime {int}
9198
+ * - leaveTime {int}
9199
+ * - threadParticipant {object}
9200
+ * - sendTopic {string}
9201
+ * - receiveTopic {string}
9202
+ * - brokerAddress {string}
9203
+ * - active {boolean}
9204
+ * - callSession {object}
9205
+ * - callStatus {int}
9206
+ * - createTime {int}
9207
+ * - sendKey {string}
9208
+ * - mute {boolean}
9209
+ */
8693
9210
 
8694
- // write the bytes of the string to a typed array
8695
- var ia = new Uint8Array(byteString.length);
8696
- for (var i = 0; i < byteString.length; i++) {
8697
- ia[i] = byteString.charCodeAt(i);
8698
- }
9211
+ var participant = {
9212
+ id: messageContent.id,
9213
+ joinTime: messageContent.joinTime,
9214
+ leaveTime: messageContent.leaveTime,
9215
+ sendTopic: messageContent.sendTopic,
9216
+ receiveTopic: messageContent.receiveTopic,
9217
+ brokerAddress: messageContent.brokerAddress,
9218
+ active: messageContent.active,
9219
+ callSession: messageContent.callSession,
9220
+ callStatus: messageContent.callStatus,
9221
+ createTime: messageContent.createTime,
9222
+ sendKey: messageContent.sendKey,
9223
+ mute: messageContent.mute
9224
+ };
8699
9225
 
8700
- return callback(new Blob([ia], {type: mimeString}));
9226
+ // Add Chat Participant if exist
9227
+ if (messageContent.participantVO) {
9228
+ participant.participantVO = messageContent.participantVO;
8701
9229
  }
8702
9230
 
8703
- img.src = url;
9231
+ // Add Call Session if exist
9232
+ if (messageContent.callSession) {
9233
+ participant.callSession = messageContent.callSession;
9234
+ }
9235
+
9236
+ // return participant;
9237
+ return JSON.parse(JSON.stringify(participant));
8704
9238
  };
8705
9239
 
8706
9240
  /******************************************************
@@ -10103,97 +10637,303 @@
10103
10637
  });
10104
10638
  };
10105
10639
 
10106
- this.forwardMessage = function (params, callbacks) {
10107
- var threadId = params.threadId,
10108
- messageIdsList = params.messageIds,
10109
- uniqueIdsList = [];
10640
+ this.forwardMessage = function (params, callbacks) {
10641
+ var threadId = params.threadId,
10642
+ messageIdsList = params.messageIds,
10643
+ uniqueIdsList = [];
10644
+
10645
+ for (i in messageIdsList) {
10646
+ if (!threadCallbacks[threadId]) {
10647
+ threadCallbacks[threadId] = {};
10648
+ }
10649
+
10650
+ var uniqueId = Utility.generateUUID();
10651
+ uniqueIdsList.push(uniqueId);
10652
+
10653
+ threadCallbacks[threadId][uniqueId] = {};
10654
+
10655
+ sendMessageCallbacks[uniqueId] = {};
10656
+
10657
+ if (callbacks.onSent) {
10658
+ sendMessageCallbacks[uniqueId].onSent = callbacks.onSent;
10659
+ threadCallbacks[threadId][uniqueId].onSent = false;
10660
+ threadCallbacks[threadId][uniqueId].uniqueId = uniqueId;
10661
+ }
10662
+
10663
+ if (callbacks.onSeen) {
10664
+ sendMessageCallbacks[uniqueId].onSeen = callbacks.onSeen;
10665
+ threadCallbacks[threadId][uniqueId].onSeen = false;
10666
+ }
10667
+
10668
+ if (callbacks.onDeliver) {
10669
+ sendMessageCallbacks[uniqueId].onDeliver = callbacks.onDeliver;
10670
+ threadCallbacks[threadId][uniqueId].onDeliver = false;
10671
+ }
10672
+ }
10673
+
10674
+ putInChatSendQueue({
10675
+ message: {
10676
+ chatMessageVOType: chatMessageVOTypes.FORWARD_MESSAGE,
10677
+ typeCode: params.typeCode,
10678
+ subjectId: params.threadId,
10679
+ repliedTo: params.repliedTo,
10680
+ content: messageIdsList,
10681
+ uniqueId: uniqueIdsList,
10682
+ metadata: JSON.stringify(params.metadata),
10683
+ pushMsgType: 5
10684
+ },
10685
+ callbacks: callbacks
10686
+ }, function () {
10687
+ chatSendQueueHandler();
10688
+ });
10689
+ };
10690
+
10691
+ this.deliver = deliver(params);
10692
+
10693
+ this.seen = function (params) {
10694
+ if (userInfo && params.ownerId !== userInfo.id) {
10695
+ return sendMessage({
10696
+ chatMessageVOType: chatMessageVOTypes.SEEN,
10697
+ typeCode: params.typeCode,
10698
+ content: params.messageId,
10699
+ pushMsgType: 3
10700
+ });
10701
+ }
10702
+ };
10703
+
10704
+ this.startTyping = function (params) {
10705
+ var uniqueId = Utility.generateUUID();
10706
+
10707
+ if (parseInt(params.threadId) > 0) {
10708
+ var threadId = params.threadId;
10709
+ }
10710
+ isTypingInterval && clearInterval(isTypingInterval);
10711
+
10712
+ isTypingInterval = setInterval(function () {
10713
+ sendSystemMessage({
10714
+ content: JSON.stringify({
10715
+ type: systemMessageTypes.IS_TYPING
10716
+ }),
10717
+ threadId: threadId,
10718
+ uniqueId: uniqueId
10719
+ });
10720
+ }, systemMessageIntervalPitch);
10721
+ };
10722
+
10723
+ this.stopTyping = function () {
10724
+ isTypingInterval && clearInterval(isTypingInterval);
10725
+ };
10726
+
10727
+ this.getMessageDeliveredList = function (params, callback) {
10728
+
10729
+ var deliveryListData = {
10730
+ chatMessageVOType: chatMessageVOTypes.GET_MESSAGE_DELEVERY_PARTICIPANTS,
10731
+ typeCode: params.typeCode,
10732
+ content: {},
10733
+ pushMsgType: 4,
10734
+ token: token,
10735
+ timeout: params.timeout
10736
+ };
10737
+
10738
+ if (params) {
10739
+ if (parseInt(params.messageId) > 0) {
10740
+ deliveryListData.content.messageId = params.messageId;
10741
+ }
10742
+ }
10743
+
10744
+ return sendMessage(deliveryListData, {
10745
+ onResult: function (result) {
10746
+ if (typeof result.result == 'object') {
10747
+ for (var i = 0; i < result.result.length; i++) {
10748
+ result.result[i] = formatDataToMakeUser(result.result[i]);
10749
+ }
10750
+ }
10751
+ callback && callback(result);
10752
+ }
10753
+ });
10754
+ };
10755
+
10756
+ this.getMessageSeenList = function (params, callback) {
10757
+ var seenListData = {
10758
+ chatMessageVOType: chatMessageVOTypes.GET_MESSAGE_SEEN_PARTICIPANTS,
10759
+ typeCode: params.typeCode,
10760
+ content: {},
10761
+ pushMsgType: 4,
10762
+ token: token,
10763
+ timeout: params.timeout
10764
+ };
10765
+
10766
+ if (params) {
10767
+ if (parseInt(params.messageId) > 0) {
10768
+ seenListData.content.messageId = params.messageId;
10769
+ }
10770
+ }
10771
+
10772
+ return sendMessage(seenListData, {
10773
+ onResult: function (result) {
10774
+ if (typeof result.result == 'object') {
10775
+ for (var i = 0; i < result.result.length; i++) {
10776
+ result.result[i] = formatDataToMakeUser(result.result[i]);
10777
+ }
10778
+ }
10779
+ callback && callback(result);
10780
+ }
10781
+ });
10782
+ };
10783
+
10784
+ this.updateThreadInfo = updateThreadInfo;
10785
+
10786
+ this.updateChatProfile = updateChatProfile;
10787
+
10788
+ this.muteThread = function (params, callback) {
10789
+ return sendMessage({
10790
+ chatMessageVOType: chatMessageVOTypes.MUTE_THREAD,
10791
+ typeCode: params.typeCode,
10792
+ subjectId: params.threadId,
10793
+ content: {},
10794
+ pushMsgType: 4,
10795
+ token: token
10796
+ }, {
10797
+ onResult: function (result) {
10798
+ callback && callback(result);
10799
+ }
10800
+ });
10801
+ };
10802
+
10803
+ this.unMuteThread = function (params, callback) {
10804
+ return sendMessage({
10805
+ chatMessageVOType: chatMessageVOTypes.UNMUTE_THREAD,
10806
+ typeCode: params.typeCode,
10807
+ subjectId: params.threadId,
10808
+ content: {},
10809
+ pushMsgType: 4,
10810
+ token: token
10811
+ }, {
10812
+ onResult: function (result) {
10813
+ callback && callback(result);
10814
+ }
10815
+ });
10816
+ };
10817
+
10818
+ this.joinPublicThread = function (params, callback) {
10819
+ var joinThreadData = {
10820
+ chatMessageVOType: chatMessageVOTypes.JOIN_THREAD,
10821
+ typeCode: params.typeCode,
10822
+ content: '',
10823
+ pushMsgType: 4,
10824
+ token: token
10825
+ };
10826
+
10827
+ if (params) {
10828
+ if (typeof params.uniqueName === 'string' && params.uniqueName.length > 0) {
10829
+ joinThreadData.content = params.uniqueName;
10830
+ }
10831
+ }
10832
+
10833
+ return sendMessage(joinThreadData, {
10834
+ onResult: function (result) {
10835
+ callback && callback(result);
10836
+ }
10837
+ });
10838
+ };
10839
+
10840
+ this.isPublicThreadNameAvailable = function (params, callback) {
10841
+ var isNameAvailableData = {
10842
+ chatMessageVOType: chatMessageVOTypes.IS_NAME_AVAILABLE,
10843
+ typeCode: params.typeCode,
10844
+ content: '',
10845
+ pushMsgType: 4,
10846
+ token: token
10847
+ };
10110
10848
 
10111
- for (i in messageIdsList) {
10112
- if (!threadCallbacks[threadId]) {
10113
- threadCallbacks[threadId] = {};
10849
+ if (params) {
10850
+ if (typeof params.uniqueName === 'string' && params.uniqueName.length > 0) {
10851
+ isNameAvailableData.content = params.uniqueName;
10114
10852
  }
10853
+ }
10115
10854
 
10116
- var uniqueId = Utility.generateUUID();
10117
- uniqueIdsList.push(uniqueId);
10118
-
10119
- threadCallbacks[threadId][uniqueId] = {};
10120
-
10121
- sendMessageCallbacks[uniqueId] = {};
10122
-
10123
- if (callbacks.onSent) {
10124
- sendMessageCallbacks[uniqueId].onSent = callbacks.onSent;
10125
- threadCallbacks[threadId][uniqueId].onSent = false;
10126
- threadCallbacks[threadId][uniqueId].uniqueId = uniqueId;
10855
+ return sendMessage(isNameAvailableData, {
10856
+ onResult: function (result) {
10857
+ callback && callback(result);
10127
10858
  }
10859
+ });
10860
+ };
10128
10861
 
10129
- if (callbacks.onSeen) {
10130
- sendMessageCallbacks[uniqueId].onSeen = callbacks.onSeen;
10131
- threadCallbacks[threadId][uniqueId].onSeen = false;
10862
+ this.pinThread = function (params, callback) {
10863
+ return sendMessage({
10864
+ chatMessageVOType: chatMessageVOTypes.PIN_THREAD,
10865
+ typeCode: params.typeCode,
10866
+ subjectId: params.threadId,
10867
+ content: {},
10868
+ pushMsgType: 4,
10869
+ token: token
10870
+ }, {
10871
+ onResult: function (result) {
10872
+ callback && callback(result);
10132
10873
  }
10874
+ });
10875
+ };
10133
10876
 
10134
- if (callbacks.onDeliver) {
10135
- sendMessageCallbacks[uniqueId].onDeliver = callbacks.onDeliver;
10136
- threadCallbacks[threadId][uniqueId].onDeliver = false;
10877
+ this.unPinThread = function (params, callback) {
10878
+ return sendMessage({
10879
+ chatMessageVOType: chatMessageVOTypes.UNPIN_THREAD,
10880
+ typeCode: params.typeCode,
10881
+ subjectId: params.threadId,
10882
+ content: {},
10883
+ pushMsgType: 4,
10884
+ token: token
10885
+ }, {
10886
+ onResult: function (result) {
10887
+ callback && callback(result);
10137
10888
  }
10138
- }
10139
-
10140
- putInChatSendQueue({
10141
- message: {
10142
- chatMessageVOType: chatMessageVOTypes.FORWARD_MESSAGE,
10143
- typeCode: params.typeCode,
10144
- subjectId: params.threadId,
10145
- repliedTo: params.repliedTo,
10146
- content: messageIdsList,
10147
- uniqueId: uniqueIdsList,
10148
- metadata: JSON.stringify(params.metadata),
10149
- pushMsgType: 5
10150
- },
10151
- callbacks: callbacks
10152
- }, function () {
10153
- chatSendQueueHandler();
10154
10889
  });
10155
10890
  };
10156
10891
 
10157
- this.deliver = deliver(params);
10158
-
10159
- this.seen = function (params) {
10160
- if (userInfo && params.ownerId !== userInfo.id) {
10161
- return sendMessage({
10162
- chatMessageVOType: chatMessageVOTypes.SEEN,
10163
- typeCode: params.typeCode,
10164
- content: params.messageId,
10165
- pushMsgType: 3
10166
- });
10167
- }
10892
+ this.pinMessage = function (params, callback) {
10893
+ return sendMessage({
10894
+ chatMessageVOType: chatMessageVOTypes.PIN_MESSAGE,
10895
+ typeCode: params.typeCode,
10896
+ subjectId: params.messageId,
10897
+ content: JSON.stringify({
10898
+ 'notifyAll': (typeof params.notifyAll === 'boolean') ? params.notifyAll : false
10899
+ }),
10900
+ pushMsgType: 4,
10901
+ token: token
10902
+ }, {
10903
+ onResult: function (result) {
10904
+ callback && callback(result);
10905
+ }
10906
+ });
10168
10907
  };
10169
10908
 
10170
- this.startTyping = function (params) {
10171
- var uniqueId = Utility.generateUUID();
10909
+ this.unPinMessage = unPinMessage;
10172
10910
 
10173
- if (parseInt(params.threadId) > 0) {
10174
- var threadId = params.threadId;
10175
- }
10176
- isTypingInterval && clearInterval(isTypingInterval);
10911
+ this.spamPrivateThread = function (params, callback) {
10912
+ var spamData = {
10913
+ chatMessageVOType: chatMessageVOTypes.SPAM_PV_THREAD,
10914
+ typeCode: params.typeCode,
10915
+ pushMsgType: 4,
10916
+ token: token,
10917
+ timeout: params.timeout
10918
+ };
10177
10919
 
10178
- isTypingInterval = setInterval(function () {
10179
- sendSystemMessage({
10180
- content: JSON.stringify({
10181
- type: systemMessageTypes.IS_TYPING
10182
- }),
10183
- threadId: threadId,
10184
- uniqueId: uniqueId
10185
- });
10186
- }, systemMessageIntervalPitch);
10187
- };
10920
+ if (params) {
10921
+ if (parseInt(params.threadId) > 0) {
10922
+ spamData.subjectId = params.threadId;
10923
+ }
10924
+ }
10188
10925
 
10189
- this.stopTyping = function () {
10190
- isTypingInterval && clearInterval(isTypingInterval);
10926
+ return sendMessage(spamData, {
10927
+ onResult: function (result) {
10928
+ callback && callback(result);
10929
+ }
10930
+ });
10191
10931
  };
10192
10932
 
10193
- this.getMessageDeliveredList = function (params, callback) {
10933
+ this.block = function (params, callback) {
10194
10934
 
10195
- var deliveryListData = {
10196
- chatMessageVOType: chatMessageVOTypes.GET_MESSAGE_DELEVERY_PARTICIPANTS,
10935
+ var blockData = {
10936
+ chatMessageVOType: chatMessageVOTypes.BLOCK,
10197
10937
  typeCode: params.typeCode,
10198
10938
  content: {},
10199
10939
  pushMsgType: 4,
@@ -10202,423 +10942,764 @@
10202
10942
  };
10203
10943
 
10204
10944
  if (params) {
10205
- if (parseInt(params.messageId) > 0) {
10206
- deliveryListData.content.messageId = params.messageId;
10945
+ if (parseInt(params.contactId) > 0) {
10946
+ blockData.content.contactId = params.contactId;
10947
+ }
10948
+
10949
+ if (parseInt(params.threadId) > 0) {
10950
+ blockData.content.threadId = params.threadId;
10951
+ }
10952
+
10953
+ if (parseInt(params.userId) > 0) {
10954
+ blockData.content.userId = params.userId;
10207
10955
  }
10208
10956
  }
10209
10957
 
10210
- return sendMessage(deliveryListData, {
10958
+ return sendMessage(blockData, {
10211
10959
  onResult: function (result) {
10212
10960
  if (typeof result.result == 'object') {
10213
- for (var i = 0; i < result.result.length; i++) {
10214
- result.result[i] = formatDataToMakeUser(result.result[i]);
10215
- }
10961
+ result.result = formatDataToMakeBlockedUser(result.result);
10216
10962
  }
10217
10963
  callback && callback(result);
10218
10964
  }
10219
10965
  });
10220
10966
  };
10221
10967
 
10222
- this.getMessageSeenList = function (params, callback) {
10223
- var seenListData = {
10224
- chatMessageVOType: chatMessageVOTypes.GET_MESSAGE_SEEN_PARTICIPANTS,
10968
+ this.unblock = function (params, callback) {
10969
+ var unblockData = {
10970
+ chatMessageVOType: chatMessageVOTypes.UNBLOCK,
10225
10971
  typeCode: params.typeCode,
10226
- content: {},
10227
10972
  pushMsgType: 4,
10228
10973
  token: token,
10974
+ content: {},
10229
10975
  timeout: params.timeout
10230
10976
  };
10231
10977
 
10232
10978
  if (params) {
10233
- if (parseInt(params.messageId) > 0) {
10234
- seenListData.content.messageId = params.messageId;
10979
+ if (parseInt(params.blockId) > 0) {
10980
+ unblockData.subjectId = params.blockId;
10981
+ }
10982
+
10983
+ if (parseInt(params.contactId) > 0) {
10984
+ unblockData.content.contactId = params.contactId;
10985
+ }
10986
+
10987
+ if (parseInt(params.threadId) > 0) {
10988
+ unblockData.content.threadId = params.threadId;
10989
+ }
10990
+
10991
+ if (parseInt(params.userId) > 0) {
10992
+ unblockData.content.userId = params.userId;
10235
10993
  }
10236
10994
  }
10237
10995
 
10238
- return sendMessage(seenListData, {
10996
+ return sendMessage(unblockData, {
10239
10997
  onResult: function (result) {
10240
10998
  if (typeof result.result == 'object') {
10241
- for (var i = 0; i < result.result.length; i++) {
10242
- result.result[i] = formatDataToMakeUser(result.result[i]);
10243
- }
10999
+ result.result = formatDataToMakeBlockedUser(result.result);
10244
11000
  }
11001
+
10245
11002
  callback && callback(result);
10246
11003
  }
10247
11004
  });
10248
11005
  };
10249
11006
 
10250
- this.updateThreadInfo = updateThreadInfo;
11007
+ this.getBlockedList = function (params, callback) {
11008
+ var count = 50,
11009
+ offset = 0,
11010
+ content = {};
10251
11011
 
10252
- this.updateChatProfile = updateChatProfile;
11012
+ if (params) {
11013
+ if (parseInt(params.count) > 0) {
11014
+ count = params.count;
11015
+ }
10253
11016
 
10254
- this.muteThread = function (params, callback) {
10255
- return sendMessage({
10256
- chatMessageVOType: chatMessageVOTypes.MUTE_THREAD,
11017
+ if (parseInt(params.offset) > 0) {
11018
+ offset = params.offset;
11019
+ }
11020
+ }
11021
+
11022
+ content.count = count;
11023
+ content.offset = offset;
11024
+
11025
+ var getBlockedData = {
11026
+ chatMessageVOType: chatMessageVOTypes.GET_BLOCKED,
10257
11027
  typeCode: params.typeCode,
10258
- subjectId: params.threadId,
10259
- content: {},
11028
+ content: content,
10260
11029
  pushMsgType: 4,
10261
- token: token
10262
- }, {
11030
+ token: token,
11031
+ timeout: params.timeout
11032
+ };
11033
+
11034
+ return sendMessage(getBlockedData, {
10263
11035
  onResult: function (result) {
10264
- callback && callback(result);
11036
+ var returnData = {
11037
+ hasError: result.hasError,
11038
+ cache: false,
11039
+ errorMessage: result.errorMessage,
11040
+ errorCode: result.errorCode
11041
+ };
11042
+
11043
+ if (!returnData.hasError) {
11044
+ var messageContent = result.result,
11045
+ messageLength = messageContent.length,
11046
+ resultData = {
11047
+ blockedUsers: [],
11048
+ contentCount: result.contentCount,
11049
+ hasNext: (offset + count < result.contentCount && messageLength > 0),
11050
+ nextOffset: offset + messageLength
11051
+ },
11052
+ blockedUser;
11053
+
11054
+ for (var i = 0; i < messageLength; i++) {
11055
+ blockedUser = formatDataToMakeBlockedUser(messageContent[i]);
11056
+ if (blockedUser) {
11057
+ resultData.blockedUsers.push(blockedUser);
11058
+ }
11059
+ }
11060
+
11061
+ returnData.result = resultData;
11062
+ }
11063
+
11064
+ callback && callback(returnData);
10265
11065
  }
10266
11066
  });
10267
11067
  };
10268
11068
 
10269
- this.unMuteThread = function (params, callback) {
10270
- return sendMessage({
10271
- chatMessageVOType: chatMessageVOTypes.UNMUTE_THREAD,
11069
+ this.getUserNotSeenDuration = function (params, callback) {
11070
+ var content = {};
11071
+
11072
+ if (params) {
11073
+ if (Array.isArray(params.userIds)) {
11074
+ content.userIds = params.userIds;
11075
+ }
11076
+ }
11077
+
11078
+ var getNotSeenDurationData = {
11079
+ chatMessageVOType: chatMessageVOTypes.GET_NOT_SEEN_DURATION,
10272
11080
  typeCode: params.typeCode,
10273
- subjectId: params.threadId,
10274
- content: {},
11081
+ content: content,
10275
11082
  pushMsgType: 4,
10276
- token: token
10277
- }, {
11083
+ token: token,
11084
+ timeout: params.timeout
11085
+ };
11086
+
11087
+ return sendMessage(getNotSeenDurationData, {
10278
11088
  onResult: function (result) {
10279
- callback && callback(result);
11089
+ var returnData = {
11090
+ hasError: result.hasError,
11091
+ cache: false,
11092
+ errorMessage: result.errorMessage,
11093
+ errorCode: result.errorCode
11094
+ };
11095
+
11096
+ if (!returnData.hasError) {
11097
+ returnData.result = result.result;
11098
+ }
11099
+
11100
+ callback && callback(returnData);
10280
11101
  }
10281
11102
  });
10282
11103
  };
10283
11104
 
10284
- this.joinPublicThread = function (params, callback) {
10285
- var joinThreadData = {
10286
- chatMessageVOType: chatMessageVOTypes.JOIN_THREAD,
10287
- typeCode: params.typeCode,
10288
- content: '',
10289
- pushMsgType: 4,
10290
- token: token
10291
- };
11105
+ this.addContacts = function (params, callback) {
11106
+ var data = {};
10292
11107
 
10293
11108
  if (params) {
10294
- if (typeof params.uniqueName === 'string' && params.uniqueName.length > 0) {
10295
- joinThreadData.content = params.uniqueName;
11109
+ if (typeof params.firstName === 'string') {
11110
+ data.firstName = params.firstName;
11111
+ } else {
11112
+ data.firstName = '';
10296
11113
  }
10297
- }
10298
11114
 
10299
- return sendMessage(joinThreadData, {
10300
- onResult: function (result) {
10301
- callback && callback(result);
11115
+ if (typeof params.lastName === 'string') {
11116
+ data.lastName = params.lastName;
11117
+ } else {
11118
+ data.lastName = '';
10302
11119
  }
10303
- });
10304
- };
10305
11120
 
10306
- this.isPublicThreadNameAvailable = function (params, callback) {
10307
- var isNameAvailableData = {
10308
- chatMessageVOType: chatMessageVOTypes.IS_NAME_AVAILABLE,
10309
- typeCode: params.typeCode,
10310
- content: '',
10311
- pushMsgType: 4,
10312
- token: token
10313
- };
11121
+ if (typeof params.typeCode === 'string') {
11122
+ data.typeCode = params.typeCode;
11123
+ } else if (generalTypeCode) {
11124
+ data.typeCode = generalTypeCode;
11125
+ }
10314
11126
 
10315
- if (params) {
10316
- if (typeof params.uniqueName === 'string' && params.uniqueName.length > 0) {
10317
- isNameAvailableData.content = params.uniqueName;
11127
+ if (typeof params.cellphoneNumber === 'string') {
11128
+ data.cellphoneNumber = params.cellphoneNumber;
11129
+ } else {
11130
+ data.cellphoneNumber = '';
10318
11131
  }
10319
- }
10320
11132
 
10321
- return sendMessage(isNameAvailableData, {
10322
- onResult: function (result) {
10323
- callback && callback(result);
11133
+ if (typeof params.email === 'string') {
11134
+ data.email = params.email;
11135
+ } else {
11136
+ data.email = '';
10324
11137
  }
10325
- });
10326
- };
10327
11138
 
10328
- this.pinThread = function (params, callback) {
10329
- return sendMessage({
10330
- chatMessageVOType: chatMessageVOTypes.PIN_THREAD,
10331
- typeCode: params.typeCode,
10332
- subjectId: params.threadId,
10333
- content: {},
10334
- pushMsgType: 4,
10335
- token: token
10336
- }, {
10337
- onResult: function (result) {
10338
- callback && callback(result);
11139
+ if (typeof params.username === 'string') {
11140
+ data.username = params.username;
10339
11141
  }
10340
- });
10341
- };
10342
11142
 
10343
- this.unPinThread = function (params, callback) {
10344
- return sendMessage({
10345
- chatMessageVOType: chatMessageVOTypes.UNPIN_THREAD,
10346
- typeCode: params.typeCode,
10347
- subjectId: params.threadId,
10348
- content: {},
10349
- pushMsgType: 4,
10350
- token: token
10351
- }, {
10352
- onResult: function (result) {
10353
- callback && callback(result);
11143
+ data.uniqueId = Utility.generateUUID();
11144
+ }
11145
+
11146
+ var requestParams = {
11147
+ url: SERVICE_ADDRESSES.PLATFORM_ADDRESS + SERVICES_PATH.ADD_CONTACTS,
11148
+ method: 'POST',
11149
+ data: data,
11150
+ headers: {
11151
+ '_token_': token,
11152
+ '_token_issuer_': 1
11153
+ }
11154
+ };
11155
+
11156
+ httpRequest(requestParams, function (result) {
11157
+ if (!result.hasError) {
11158
+ var responseData = JSON.parse(result.result.responseText);
11159
+
11160
+ var returnData = {
11161
+ hasError: responseData.hasError,
11162
+ cache: false,
11163
+ errorMessage: responseData.message,
11164
+ errorCode: responseData.errorCode
11165
+ };
11166
+
11167
+ if (!responseData.hasError) {
11168
+ var messageContent = responseData.result,
11169
+ messageLength = responseData.result.length,
11170
+ resultData = {
11171
+ contacts: [],
11172
+ contentCount: messageLength
11173
+ },
11174
+ contactData;
11175
+
11176
+ for (var i = 0; i < messageLength; i++) {
11177
+ contactData = formatDataToMakeContact(messageContent[i]);
11178
+ if (contactData) {
11179
+ resultData.contacts.push(contactData);
11180
+ }
11181
+ }
11182
+
11183
+ returnData.result = resultData;
11184
+
11185
+ /**
11186
+ * Add Contacts into cache database #cache
11187
+ */
11188
+ if (canUseCache && cacheSecret.length > 0) {
11189
+ if (db) {
11190
+ var cacheData = [];
11191
+
11192
+ for (var i = 0; i < resultData.contacts.length; i++) {
11193
+ try {
11194
+ var tempData = {},
11195
+ salt = Utility.generateUUID();
11196
+ tempData.id = resultData.contacts[i].id;
11197
+ tempData.owner = userInfo.id;
11198
+ tempData.uniqueId = resultData.contacts[i].uniqueId;
11199
+ tempData.userId = Utility.crypt(resultData.contacts[i].userId, cacheSecret, salt);
11200
+ tempData.cellphoneNumber = Utility.crypt(resultData.contacts[i].cellphoneNumber, cacheSecret, salt);
11201
+ tempData.email = Utility.crypt(resultData.contacts[i].email, cacheSecret, salt);
11202
+ tempData.firstName = Utility.crypt(resultData.contacts[i].firstName, cacheSecret, salt);
11203
+ tempData.lastName = Utility.crypt(resultData.contacts[i].lastName, cacheSecret, salt);
11204
+ tempData.expireTime = new Date().getTime() + cacheExpireTime;
11205
+ tempData.data = Utility.crypt(JSON.stringify(unsetNotSeenDuration(resultData.contacts[i])), cacheSecret, salt);
11206
+ tempData.salt = salt;
11207
+
11208
+ cacheData.push(tempData);
11209
+ } catch (error) {
11210
+ fireEvent('error', {
11211
+ code: error.code,
11212
+ message: error.message,
11213
+ error: error
11214
+ });
11215
+ }
11216
+ }
11217
+
11218
+ db.contacts.bulkPut(cacheData)
11219
+ .catch(function (error) {
11220
+ fireEvent('error', {
11221
+ code: error.code,
11222
+ message: error.message,
11223
+ error: error
11224
+ });
11225
+ });
11226
+ } else {
11227
+ fireEvent('error', {
11228
+ code: 6601,
11229
+ message: CHAT_ERRORS[6601],
11230
+ error: null
11231
+ });
11232
+ }
11233
+ }
11234
+
11235
+ }
11236
+
11237
+ callback && callback(returnData);
11238
+
11239
+ } else {
11240
+ fireEvent('error', {
11241
+ code: result.errorCode,
11242
+ message: result.errorMessage,
11243
+ error: result
11244
+ });
10354
11245
  }
10355
11246
  });
10356
11247
  };
10357
11248
 
10358
- this.pinMessage = function (params, callback) {
10359
- return sendMessage({
10360
- chatMessageVOType: chatMessageVOTypes.PIN_MESSAGE,
10361
- typeCode: params.typeCode,
10362
- subjectId: params.messageId,
10363
- content: JSON.stringify({
10364
- 'notifyAll': (typeof params.notifyAll === 'boolean') ? params.notifyAll : false
10365
- }),
10366
- pushMsgType: 4,
10367
- token: token
10368
- }, {
10369
- onResult: function (result) {
10370
- callback && callback(result);
11249
+ this.updateContacts = function (params, callback) {
11250
+ var data = {};
11251
+
11252
+ if (params) {
11253
+ if (parseInt(params.id) > 0) {
11254
+ data.id = parseInt(params.id);
11255
+ } else {
11256
+ fireEvent('error', {
11257
+ code: 999,
11258
+ message: 'ID is required for Updating Contact!',
11259
+ error: undefined
11260
+ });
11261
+ }
11262
+
11263
+ if (typeof params.firstName === 'string') {
11264
+ data.firstName = params.firstName;
11265
+ } else {
11266
+ fireEvent('error', {
11267
+ code: 999,
11268
+ message: 'firstName is required for Updating Contact!'
11269
+ });
10371
11270
  }
10372
- });
10373
- };
10374
11271
 
10375
- this.unPinMessage = unPinMessage;
11272
+ if (typeof params.lastName === 'string') {
11273
+ data.lastName = params.lastName;
11274
+ } else {
11275
+ fireEvent('error', {
11276
+ code: 999,
11277
+ message: 'lastName is required for Updating Contact!'
11278
+ });
11279
+ }
10376
11280
 
10377
- this.spamPrivateThread = function (params, callback) {
10378
- var spamData = {
10379
- chatMessageVOType: chatMessageVOTypes.SPAM_PV_THREAD,
10380
- typeCode: params.typeCode,
10381
- pushMsgType: 4,
10382
- token: token,
10383
- timeout: params.timeout
10384
- };
11281
+ if (typeof params.cellphoneNumber === 'string') {
11282
+ data.cellphoneNumber = params.cellphoneNumber;
11283
+ } else {
11284
+ fireEvent('error', {
11285
+ code: 999,
11286
+ message: 'cellphoneNumber is required for Updating Contact!'
11287
+ });
11288
+ }
10385
11289
 
10386
- if (params) {
10387
- if (parseInt(params.threadId) > 0) {
10388
- spamData.subjectId = params.threadId;
11290
+ if (typeof params.email === 'string') {
11291
+ data.email = params.email;
11292
+ } else {
11293
+ fireEvent('error', {
11294
+ code: 999,
11295
+ message: 'email is required for Updating Contact!'
11296
+ });
10389
11297
  }
11298
+
11299
+ data.uniqueId = Utility.generateUUID();
10390
11300
  }
10391
11301
 
10392
- return sendMessage(spamData, {
10393
- onResult: function (result) {
10394
- callback && callback(result);
11302
+ var requestParams = {
11303
+ url: SERVICE_ADDRESSES.PLATFORM_ADDRESS +
11304
+ SERVICES_PATH.UPDATE_CONTACTS,
11305
+ method: 'GET',
11306
+ data: data,
11307
+ headers: {
11308
+ '_token_': token,
11309
+ '_token_issuer_': 1
10395
11310
  }
10396
- });
10397
- };
11311
+ };
10398
11312
 
10399
- this.block = function (params, callback) {
11313
+ httpRequest(requestParams, function (result) {
11314
+ if (!result.hasError) {
11315
+ var responseData = JSON.parse(result.result.responseText);
10400
11316
 
10401
- var blockData = {
10402
- chatMessageVOType: chatMessageVOTypes.BLOCK,
10403
- typeCode: params.typeCode,
10404
- content: {},
10405
- pushMsgType: 4,
10406
- token: token,
10407
- timeout: params.timeout
10408
- };
11317
+ var returnData = {
11318
+ hasError: responseData.hasError,
11319
+ cache: false,
11320
+ errorMessage: responseData.message,
11321
+ errorCode: responseData.errorCode
11322
+ };
10409
11323
 
10410
- if (params) {
10411
- if (parseInt(params.contactId) > 0) {
10412
- blockData.content.contactId = params.contactId;
10413
- }
11324
+ if (!responseData.hasError) {
11325
+ var messageContent = responseData.result,
11326
+ messageLength = responseData.result.length,
11327
+ resultData = {
11328
+ contacts: [],
11329
+ contentCount: messageLength
11330
+ },
11331
+ contactData;
10414
11332
 
10415
- if (parseInt(params.threadId) > 0) {
10416
- blockData.content.threadId = params.threadId;
10417
- }
11333
+ for (var i = 0; i < messageLength; i++) {
11334
+ contactData = formatDataToMakeContact(messageContent[i]);
11335
+ if (contactData) {
11336
+ resultData.contacts.push(contactData);
11337
+ }
11338
+ }
10418
11339
 
10419
- if (parseInt(params.userId) > 0) {
10420
- blockData.content.userId = params.userId;
10421
- }
10422
- }
11340
+ returnData.result = resultData;
11341
+
11342
+ /**
11343
+ * Add Contacts into cache database #cache
11344
+ */
11345
+ if (canUseCache && cacheSecret.length > 0) {
11346
+ if (db) {
11347
+ var cacheData = [];
11348
+
11349
+ for (var i = 0; i < resultData.contacts.length; i++) {
11350
+ try {
11351
+ var tempData = {},
11352
+ salt = Utility.generateUUID();
11353
+ tempData.id = resultData.contacts[i].id;
11354
+ tempData.owner = userInfo.id;
11355
+ tempData.uniqueId = resultData.contacts[i].uniqueId;
11356
+ tempData.userId = Utility.crypt(resultData.contacts[i].userId, cacheSecret, salt);
11357
+ tempData.cellphoneNumber = Utility.crypt(resultData.contacts[i].cellphoneNumber, cacheSecret, salt);
11358
+ tempData.email = Utility.crypt(resultData.contacts[i].email, cacheSecret, salt);
11359
+ tempData.firstName = Utility.crypt(resultData.contacts[i].firstName, cacheSecret, salt);
11360
+ tempData.lastName = Utility.crypt(resultData.contacts[i].lastName, cacheSecret, salt);
11361
+ tempData.expireTime = new Date().getTime() + cacheExpireTime;
11362
+ tempData.data = Utility.crypt(JSON.stringify(unsetNotSeenDuration(resultData.contacts[i])), cacheSecret, salt);
11363
+ tempData.salt = salt;
11364
+
11365
+ cacheData.push(tempData);
11366
+ } catch (error) {
11367
+ fireEvent('error', {
11368
+ code: error.code,
11369
+ message: error.message,
11370
+ error: error
11371
+ });
11372
+ }
11373
+ }
11374
+
11375
+ db.contacts.bulkPut(cacheData)
11376
+ .catch(function (error) {
11377
+ fireEvent('error', {
11378
+ code: error.code,
11379
+ message: error.message,
11380
+ error: error
11381
+ });
11382
+ });
11383
+ } else {
11384
+ fireEvent('error', {
11385
+ code: 6601,
11386
+ message: CHAT_ERRORS[6601],
11387
+ error: null
11388
+ });
11389
+ }
11390
+ }
10423
11391
 
10424
- return sendMessage(blockData, {
10425
- onResult: function (result) {
10426
- if (typeof result.result == 'object') {
10427
- result.result = formatDataToMakeBlockedUser(result.result);
10428
11392
  }
10429
- callback && callback(result);
11393
+
11394
+ callback && callback(returnData);
11395
+
11396
+ } else {
11397
+ fireEvent('error', {
11398
+ code: result.errorCode,
11399
+ message: result.errorMessage,
11400
+ error: result
11401
+ });
10430
11402
  }
10431
11403
  });
10432
11404
  };
10433
11405
 
10434
- this.unblock = function (params, callback) {
10435
- var unblockData = {
10436
- chatMessageVOType: chatMessageVOTypes.UNBLOCK,
10437
- typeCode: params.typeCode,
10438
- pushMsgType: 4,
10439
- token: token,
10440
- content: {},
10441
- timeout: params.timeout
10442
- };
11406
+ this.removeContacts = function (params, callback) {
11407
+ var data = {};
10443
11408
 
10444
11409
  if (params) {
10445
- if (parseInt(params.blockId) > 0) {
10446
- unblockData.subjectId = params.blockId;
11410
+ if (parseInt(params.id) > 0) {
11411
+ data.id = parseInt(params.id);
11412
+ } else {
11413
+ fireEvent('error', {
11414
+ code: 999,
11415
+ message: 'ID is required for Deleting Contact!',
11416
+ error: undefined
11417
+ });
10447
11418
  }
11419
+ }
10448
11420
 
10449
- if (parseInt(params.contactId) > 0) {
10450
- unblockData.content.contactId = params.contactId;
11421
+ var requestParams = {
11422
+ url: SERVICE_ADDRESSES.PLATFORM_ADDRESS + SERVICES_PATH.REMOVE_CONTACTS,
11423
+ method: 'POST',
11424
+ data: data,
11425
+ headers: {
11426
+ '_token_': token,
11427
+ '_token_issuer_': 1
10451
11428
  }
11429
+ };
10452
11430
 
10453
- if (parseInt(params.threadId) > 0) {
10454
- unblockData.content.threadId = params.threadId;
10455
- }
11431
+ httpRequest(requestParams, function (result) {
11432
+ if (!result.hasError) {
11433
+ var responseData = JSON.parse(result.result.responseText);
10456
11434
 
10457
- if (parseInt(params.userId) > 0) {
10458
- unblockData.content.userId = params.userId;
10459
- }
10460
- }
11435
+ var returnData = {
11436
+ hasError: responseData.hasError,
11437
+ cache: false,
11438
+ errorMessage: responseData.message,
11439
+ errorCode: responseData.errorCode
11440
+ };
10461
11441
 
10462
- return sendMessage(unblockData, {
10463
- onResult: function (result) {
10464
- if (typeof result.result == 'object') {
10465
- result.result = formatDataToMakeBlockedUser(result.result);
11442
+ if (!responseData.hasError) {
11443
+ returnData.result = responseData.result;
10466
11444
  }
10467
11445
 
10468
- callback && callback(result);
11446
+ /**
11447
+ * Remove the contact from cache
11448
+ */
11449
+ if (canUseCache) {
11450
+ if (db) {
11451
+ db.contacts.where('id')
11452
+ .equals(parseInt(params.id))
11453
+ .delete()
11454
+ .catch(function (error) {
11455
+ fireEvent('error', {
11456
+ code: 6602,
11457
+ message: CHAT_ERRORS[6602],
11458
+ error: error
11459
+ });
11460
+ });
11461
+ } else {
11462
+ fireEvent('error', {
11463
+ code: 6601,
11464
+ message: CHAT_ERRORS[6601],
11465
+ error: null
11466
+ });
11467
+ }
11468
+ }
11469
+
11470
+ callback && callback(returnData);
11471
+
11472
+ } else {
11473
+ fireEvent('error', {
11474
+ code: result.errorCode,
11475
+ message: result.errorMessage,
11476
+ error: result
11477
+ });
10469
11478
  }
10470
11479
  });
10471
11480
  };
10472
11481
 
10473
- this.getBlockedList = function (params, callback) {
10474
- var count = 50,
10475
- offset = 0,
10476
- content = {};
11482
+ this.searchContacts = function (params, callback) {
11483
+ var data = {
11484
+ size: 50,
11485
+ offset: 0
11486
+ },
11487
+ whereClause = {},
11488
+ returnCache = false;
10477
11489
 
10478
11490
  if (params) {
10479
- if (parseInt(params.count) > 0) {
10480
- count = params.count;
11491
+ if (typeof params.firstName === 'string') {
11492
+ data.firstName = whereClause.firstName = params.firstName;
10481
11493
  }
10482
11494
 
10483
- if (parseInt(params.offset) > 0) {
10484
- offset = params.offset;
11495
+ if (typeof params.lastName === 'string') {
11496
+ data.lastName = whereClause.lastName = params.lastName;
10485
11497
  }
10486
- }
10487
11498
 
10488
- content.count = count;
10489
- content.offset = offset;
10490
-
10491
- var getBlockedData = {
10492
- chatMessageVOType: chatMessageVOTypes.GET_BLOCKED,
10493
- typeCode: params.typeCode,
10494
- content: content,
10495
- pushMsgType: 4,
10496
- token: token,
10497
- timeout: params.timeout
10498
- };
11499
+ if (parseInt(params.cellphoneNumber) > 0) {
11500
+ data.cellphoneNumber = whereClause.cellphoneNumber = params.cellphoneNumber;
11501
+ }
10499
11502
 
10500
- return sendMessage(getBlockedData, {
10501
- onResult: function (result) {
10502
- var returnData = {
10503
- hasError: result.hasError,
10504
- cache: false,
10505
- errorMessage: result.errorMessage,
10506
- errorCode: result.errorCode
10507
- };
11503
+ if (typeof params.email === 'string') {
11504
+ data.email = whereClause.email = params.email;
11505
+ }
10508
11506
 
10509
- if (!returnData.hasError) {
10510
- var messageContent = result.result,
10511
- messageLength = messageContent.length,
10512
- resultData = {
10513
- blockedUsers: [],
10514
- contentCount: result.contentCount,
10515
- hasNext: (offset + count < result.contentCount && messageLength > 0),
10516
- nextOffset: offset + messageLength
10517
- },
10518
- blockedUser;
11507
+ if (typeof params.query === 'string') {
11508
+ data.q = whereClause.q = params.query;
11509
+ }
10519
11510
 
10520
- for (var i = 0; i < messageLength; i++) {
10521
- blockedUser = formatDataToMakeBlockedUser(messageContent[i]);
10522
- if (blockedUser) {
10523
- resultData.blockedUsers.push(blockedUser);
10524
- }
10525
- }
11511
+ if (typeof params.uniqueId === 'string') {
11512
+ data.uniqueId = whereClause.uniqueId = params.uniqueId;
11513
+ }
10526
11514
 
10527
- returnData.result = resultData;
10528
- }
11515
+ if (parseInt(params.id) > 0) {
11516
+ data.id = whereClause.id = params.id;
11517
+ }
10529
11518
 
10530
- callback && callback(returnData);
11519
+ if (parseInt(params.typeCode) > 0) {
11520
+ data.typeCode = whereClause.typeCode = params.typeCode;
10531
11521
  }
10532
- });
10533
- };
10534
11522
 
10535
- this.getUserNotSeenDuration = function (params, callback) {
10536
- var content = {};
11523
+ if (parseInt(params.size) > 0) {
11524
+ data.size = params.size;
11525
+ }
10537
11526
 
10538
- if (params) {
10539
- if (Array.isArray(params.userIds)) {
10540
- content.userIds = params.userIds;
11527
+ if (parseInt(params.offset) > 0) {
11528
+ data.offset = params.offset;
10541
11529
  }
11530
+
11531
+ var functionLevelCache = (typeof params.cache == 'boolean') ? params.cache : true;
10542
11532
  }
10543
11533
 
10544
- var getNotSeenDurationData = {
10545
- chatMessageVOType: chatMessageVOTypes.GET_NOT_SEEN_DURATION,
10546
- typeCode: params.typeCode,
10547
- content: content,
10548
- pushMsgType: 4,
10549
- token: token,
10550
- timeout: params.timeout
11534
+ var requestParams = {
11535
+ url: SERVICE_ADDRESSES.PLATFORM_ADDRESS + SERVICES_PATH.SEARCH_CONTACTS,
11536
+ method: 'POST',
11537
+ data: data,
11538
+ headers: {
11539
+ '_token_': token,
11540
+ '_token_issuer_': 1
11541
+ }
10551
11542
  };
10552
11543
 
10553
- return sendMessage(getNotSeenDurationData, {
10554
- onResult: function (result) {
10555
- var returnData = {
10556
- hasError: result.hasError,
10557
- cache: false,
10558
- errorMessage: result.errorMessage,
10559
- errorCode: result.errorCode
10560
- };
11544
+ /**
11545
+ * Search contacts in cache #cache
11546
+ */
11547
+ if (functionLevelCache && canUseCache && cacheSecret.length > 0) {
11548
+ if (db) {
10561
11549
 
10562
- if (!returnData.hasError) {
10563
- returnData.result = result.result;
10564
- }
11550
+ /**
11551
+ * First of all we delete all contacts those
11552
+ * expireTime has been expired. after that
11553
+ * we query our cache database to retrieve
11554
+ * what we wanted
11555
+ */
11556
+ db.contacts.where('expireTime')
11557
+ .below(new Date().getTime())
11558
+ .delete()
11559
+ .then(function () {
10565
11560
 
10566
- callback && callback(returnData);
10567
- }
10568
- });
10569
- };
11561
+ /**
11562
+ * Query cache database to get contacts
11563
+ */
10570
11564
 
10571
- this.addContacts = function (params, callback) {
10572
- var data = {};
11565
+ var thenAble;
10573
11566
 
10574
- if (params) {
10575
- if (typeof params.firstName === 'string') {
10576
- data.firstName = params.firstName;
10577
- } else {
10578
- data.firstName = '';
10579
- }
11567
+ if (Object.keys(whereClause).length === 0) {
11568
+ thenAble = db.contacts.where('owner')
11569
+ .equals(parseInt(userInfo.id));
11570
+ } else {
11571
+ if (whereClause.hasOwnProperty('id')) {
11572
+ thenAble = db.contacts.where('owner')
11573
+ .equals(parseInt(userInfo.id))
11574
+ .and(function (contact) {
11575
+ return contact.id == whereClause.id;
11576
+ });
11577
+ } else if (whereClause.hasOwnProperty('uniqueId')) {
11578
+ thenAble = db.contacts.where('owner')
11579
+ .equals(parseInt(userInfo.id))
11580
+ .and(function (contact) {
11581
+ return contact.uniqueId == whereClause.uniqueId;
11582
+ });
11583
+ } else {
11584
+ if (whereClause.hasOwnProperty('firstName')) {
11585
+ thenAble = db.contacts.where('owner')
11586
+ .equals(parseInt(userInfo.id))
11587
+ .filter(function (contact) {
11588
+ var reg = new RegExp(whereClause.firstName);
11589
+ return reg.test(chatDecrypt(contact.firstName, cacheSecret, contact.salt));
11590
+ });
11591
+ }
10580
11592
 
10581
- if (typeof params.lastName === 'string') {
10582
- data.lastName = params.lastName;
10583
- } else {
10584
- data.lastName = '';
10585
- }
11593
+ if (whereClause.hasOwnProperty('lastName')) {
11594
+ thenAble = db.contacts.where('owner')
11595
+ .equals(parseInt(userInfo.id))
11596
+ .filter(function (contact) {
11597
+ var reg = new RegExp(whereClause.lastName);
11598
+ return reg.test(chatDecrypt(contact.lastName, cacheSecret, contact.salt));
11599
+ });
11600
+ }
10586
11601
 
10587
- if (typeof params.typeCode === 'string') {
10588
- data.typeCode = params.typeCode;
10589
- } else if (generalTypeCode) {
10590
- data.typeCode = generalTypeCode;
10591
- }
11602
+ if (whereClause.hasOwnProperty('email')) {
11603
+ thenAble = db.contacts.where('owner')
11604
+ .equals(parseInt(userInfo.id))
11605
+ .filter(function (contact) {
11606
+ var reg = new RegExp(whereClause.email);
11607
+ return reg.test(chatDecrypt(contact.email, cacheSecret, contact.salt));
11608
+ });
11609
+ }
10592
11610
 
10593
- if (typeof params.cellphoneNumber === 'string') {
10594
- data.cellphoneNumber = params.cellphoneNumber;
10595
- } else {
10596
- data.cellphoneNumber = '';
10597
- }
11611
+ if (whereClause.hasOwnProperty('q')) {
11612
+ thenAble = db.contacts.where('owner')
11613
+ .equals(parseInt(userInfo.id))
11614
+ .filter(function (contact) {
11615
+ var reg = new RegExp(whereClause.q);
11616
+ return reg.test(chatDecrypt(contact.firstName, cacheSecret, contact.salt) + ' ' +
11617
+ chatDecrypt(contact.lastName, cacheSecret, contact.salt) + ' ' +
11618
+ chatDecrypt(contact.email, cacheSecret, contact.salt));
11619
+ });
11620
+ }
11621
+ }
11622
+ }
10598
11623
 
10599
- if (typeof params.email === 'string') {
10600
- data.email = params.email;
10601
- } else {
10602
- data.email = '';
10603
- }
11624
+ thenAble.offset(data.offset)
11625
+ .limit(data.size)
11626
+ .toArray()
11627
+ .then(function (contacts) {
11628
+ db.contacts.where('owner')
11629
+ .equals(parseInt(userInfo.id))
11630
+ .count()
11631
+ .then(function (contactsCount) {
11632
+ var cacheData = [];
11633
+
11634
+ for (var i = 0; i < contacts.length; i++) {
11635
+ try {
11636
+ var tempData = {},
11637
+ salt = contacts[i].salt;
11638
+
11639
+ cacheData.push(formatDataToMakeContact(JSON.parse(chatDecrypt(contacts[i].data, cacheSecret, ontacts[i].salt))));
11640
+ } catch (error) {
11641
+ fireEvent('error', {
11642
+ code: error.code,
11643
+ message: error.message,
11644
+ error: error
11645
+ });
11646
+ }
11647
+ }
11648
+
11649
+ var returnData = {
11650
+ hasError: false,
11651
+ cache: true,
11652
+ errorCode: 0,
11653
+ errorMessage: '',
11654
+ result: {
11655
+ contacts: cacheData,
11656
+ contentCount: contactsCount,
11657
+ hasNext: !(contacts.length < data.size),
11658
+ nextOffset: data.offset + contacts.length
11659
+ }
11660
+ };
10604
11661
 
10605
- if (typeof params.username === 'string') {
10606
- data.username = params.username;
11662
+ if (cacheData.length > 0) {
11663
+ callback && callback(returnData);
11664
+ callback = undefined;
11665
+ returnCache = true;
11666
+ }
11667
+ })
11668
+ .catch(function (error) {
11669
+ fireEvent('error', {
11670
+ code: error.code,
11671
+ message: error.message,
11672
+ error: error
11673
+ });
11674
+ });
11675
+ })
11676
+ .catch(function (error) {
11677
+ fireEvent('error', {
11678
+ code: error.code,
11679
+ message: error.message,
11680
+ error: error
11681
+ });
11682
+ });
11683
+ })
11684
+ .catch(function (error) {
11685
+ fireEvent('error', {
11686
+ code: error.code,
11687
+ message: error.message,
11688
+ error: error
11689
+ });
11690
+ });
11691
+ } else {
11692
+ fireEvent('error', {
11693
+ code: 6601,
11694
+ message: CHAT_ERRORS[6601],
11695
+ error: null
11696
+ });
10607
11697
  }
10608
-
10609
- data.uniqueId = Utility.generateUUID();
10610
11698
  }
10611
11699
 
10612
- var requestParams = {
10613
- url: SERVICE_ADDRESSES.PLATFORM_ADDRESS + SERVICES_PATH.ADD_CONTACTS,
10614
- method: 'POST',
10615
- data: data,
10616
- headers: {
10617
- '_token_': token,
10618
- '_token_issuer_': 1
10619
- }
10620
- };
10621
-
11700
+ /**
11701
+ * Get Search Contacts Result From Server
11702
+ */
10622
11703
  httpRequest(requestParams, function (result) {
10623
11704
  if (!result.hasError) {
10624
11705
  var responseData = JSON.parse(result.result.responseText);
@@ -10659,6 +11740,7 @@
10659
11740
  try {
10660
11741
  var tempData = {},
10661
11742
  salt = Utility.generateUUID();
11743
+
10662
11744
  tempData.id = resultData.contacts[i].id;
10663
11745
  tempData.owner = userInfo.id;
10664
11746
  tempData.uniqueId = resultData.contacts[i].uniqueId;
@@ -10668,7 +11750,7 @@
10668
11750
  tempData.firstName = Utility.crypt(resultData.contacts[i].firstName, cacheSecret, salt);
10669
11751
  tempData.lastName = Utility.crypt(resultData.contacts[i].lastName, cacheSecret, salt);
10670
11752
  tempData.expireTime = new Date().getTime() + cacheExpireTime;
10671
- tempData.data = Utility.crypt(JSON.stringify(unsetNotSeenDuration(resultData.contacts[i])), cacheSecret, salt);
11753
+ tempData.data = crypt(JSON.stringify(unsetNotSeenDuration(resultData.contacts[i])), cacheSecret, salt);
10672
11754
  tempData.salt = salt;
10673
11755
 
10674
11756
  cacheData.push(tempData);
@@ -10697,82 +11779,310 @@
10697
11779
  });
10698
11780
  }
10699
11781
  }
10700
-
10701
11782
  }
10702
11783
 
10703
11784
  callback && callback(returnData);
11785
+ /**
11786
+ * Delete callback so if server pushes response before
11787
+ * cache, cache won't send data again
11788
+ */
11789
+ callback = undefined;
11790
+
11791
+ if (!returnData.hasError && returnCache) {
11792
+ fireEvent('contactEvents', {
11793
+ type: 'CONTACTS_SEARCH_RESULT_CHANGE',
11794
+ result: returnData.result
11795
+ });
11796
+ }
11797
+ } else {
11798
+ fireEvent('error', {
11799
+ code: result.errorCode,
11800
+ message: result.errorMessage,
11801
+ error: result
11802
+ });
11803
+ }
11804
+ });
11805
+ };
11806
+
11807
+ this.createBot = function (params, callback) {
11808
+ var createBotData = {
11809
+ chatMessageVOType: chatMessageVOTypes.CREATE_BOT,
11810
+ typeCode: params.typeCode,
11811
+ content: '',
11812
+ pushMsgType: 4,
11813
+ token: token
11814
+ };
11815
+
11816
+ if (params) {
11817
+ if (typeof params.botName === 'string' && params.botName.length > 0) {
11818
+ if (params.botName.substr(-3) === "BOT") {
11819
+ createBotData.content = params.botName;
11820
+ } else {
11821
+ fireEvent('error', {
11822
+ code: 999,
11823
+ message: 'Bot name should end in "BOT", ex. "testBOT"'
11824
+ });
11825
+ return;
11826
+ }
11827
+ } else {
11828
+ fireEvent('error', {
11829
+ code: 999,
11830
+ message: 'Insert a bot name to create one!'
11831
+ });
11832
+ return;
11833
+ }
11834
+ } else {
11835
+ fireEvent('error', {
11836
+ code: 999,
11837
+ message: 'Insert a bot name to create one!'
11838
+ });
11839
+ return;
11840
+ }
11841
+
11842
+ return sendMessage(createBotData, {
11843
+ onResult: function (result) {
11844
+ callback && callback(result);
11845
+ }
11846
+ });
11847
+ };
11848
+
11849
+ this.defineBotCommand = function (params, callback) {
11850
+ var defineBotCommandData = {
11851
+ chatMessageVOType: chatMessageVOTypes.DEFINE_BOT_COMMAND,
11852
+ typeCode: params.typeCode,
11853
+ content: {},
11854
+ pushMsgType: 4,
11855
+ token: token
11856
+ }, commandList = [];
11857
+
11858
+ if (params) {
11859
+ if (typeof params.botName !== 'string' || params.botName.length == 0) {
11860
+ fireEvent('error', {
11861
+ code: 999,
11862
+ message: 'You need to insert a botName!'
11863
+ });
11864
+ return;
11865
+ }
11866
+
11867
+ if (!Array.isArray(params.commandList) || !params.commandList.length) {
11868
+ fireEvent('error', {
11869
+ code: 999,
11870
+ message: 'Bot Commands List has to be an array of strings.'
11871
+ });
11872
+ return;
11873
+ } else {
11874
+ for (var i = 0; i < params.commandList.length; i++) {
11875
+ commandList.push('/' + params.commandList[i].trim());
11876
+ }
11877
+ }
11878
+
11879
+ defineBotCommandData.content = {
11880
+ botName: params.botName.trim(),
11881
+ commandList: commandList
11882
+ };
11883
+
11884
+ } else {
11885
+ fireEvent('error', {
11886
+ code: 999,
11887
+ message: 'No params have been sent to create bot commands'
11888
+ });
11889
+ return;
11890
+ }
11891
+
11892
+ return sendMessage(defineBotCommandData, {
11893
+ onResult: function (result) {
11894
+ callback && callback(result);
11895
+ }
11896
+ });
11897
+ };
11898
+
11899
+ this.startBot = function (params, callback) {
11900
+ var startBotData = {
11901
+ chatMessageVOType: chatMessageVOTypes.START_BOT,
11902
+ typeCode: params.typeCode,
11903
+ content: {},
11904
+ pushMsgType: 4,
11905
+ token: token
11906
+ };
11907
+
11908
+ if (params) {
11909
+ if (typeof +params.threadId !== 'number' || params.threadId < 0) {
11910
+ fireEvent('error', {
11911
+ code: 999,
11912
+ message: 'Enter a valid Thread Id for Bot to start in!'
11913
+ });
11914
+ return;
11915
+ }
11916
+
11917
+ if (typeof params.botName !== 'string' || params.botName.length == 0) {
11918
+ fireEvent('error', {
11919
+ code: 999,
11920
+ message: 'You need to insert a botName!'
11921
+ });
11922
+ return;
11923
+ }
11924
+
11925
+ startBotData.subjectId = +params.threadId;
11926
+
11927
+ startBotData.content = JSON.stringify({
11928
+ botName: params.botName.trim()
11929
+ });
11930
+
11931
+ } else {
11932
+ fireEvent('error', {
11933
+ code: 999,
11934
+ message: 'No params have been sent to create bot commands'
11935
+ });
11936
+ return;
11937
+ }
11938
+
11939
+ return sendMessage(startBotData, {
11940
+ onResult: function (result) {
11941
+ callback && callback(result);
11942
+ }
11943
+ });
11944
+ };
11945
+
11946
+ this.stopBot = function (params, callback) {
11947
+ var stopBotData = {
11948
+ chatMessageVOType: chatMessageVOTypes.STOP_BOT,
11949
+ typeCode: params.typeCode,
11950
+ content: {},
11951
+ pushMsgType: 4,
11952
+ token: token
11953
+ }, commandList = [];
11954
+
11955
+ if (params) {
11956
+ if (typeof +params.threadId !== 'number' || params.threadId < 0) {
11957
+ fireEvent('error', {
11958
+ code: 999,
11959
+ message: 'Enter a valid Thread Id for Bot to stop on!'
11960
+ });
11961
+ return;
11962
+ }
11963
+
11964
+ if (typeof params.botName !== 'string' || params.botName.length == 0) {
11965
+ fireEvent('error', {
11966
+ code: 999,
11967
+ message: 'You need to insert a botName!'
11968
+ });
11969
+ return;
11970
+ }
11971
+
11972
+ stopBotData.subjectId = +params.threadId;
11973
+
11974
+ stopBotData.content = JSON.stringify({
11975
+ botName: params.botName.trim()
11976
+ });
11977
+
11978
+ } else {
11979
+ fireEvent('error', {
11980
+ code: 999,
11981
+ message: 'No params have been sent to create bot commands'
11982
+ });
11983
+ return;
11984
+ }
10704
11985
 
10705
- } else {
10706
- fireEvent('error', {
10707
- code: result.errorCode,
10708
- message: result.errorMessage,
10709
- error: result
10710
- });
11986
+ return sendMessage(stopBotData, {
11987
+ onResult: function (result) {
11988
+ callback && callback(result);
10711
11989
  }
10712
11990
  });
10713
11991
  };
10714
11992
 
10715
- this.updateContacts = function (params, callback) {
10716
- var data = {};
11993
+ this.getBotCommandsList = function (params, callback) {
11994
+ var getBotCommandsListData = {
11995
+ chatMessageVOType: chatMessageVOTypes.BOT_COMMANDS,
11996
+ typeCode: params.typeCode,
11997
+ content: {},
11998
+ pushMsgType: 4,
11999
+ token: token
12000
+ };
10717
12001
 
10718
12002
  if (params) {
10719
- if (parseInt(params.id) > 0) {
10720
- data.id = parseInt(params.id);
10721
- } else {
12003
+ if (typeof params.botName !== 'string' || params.botName.length == 0) {
10722
12004
  fireEvent('error', {
10723
12005
  code: 999,
10724
- message: 'ID is required for Updating Contact!',
10725
- error: undefined
12006
+ message: 'You need to insert a botName!'
10726
12007
  });
12008
+ return;
10727
12009
  }
10728
12010
 
10729
- if (typeof params.firstName === 'string') {
10730
- data.firstName = params.firstName;
10731
- } else {
10732
- fireEvent('error', {
10733
- code: 999,
10734
- message: 'firstName is required for Updating Contact!'
10735
- });
12011
+ getBotCommandsListData.content = JSON.stringify({
12012
+ botName: params.botName.trim()
12013
+ });
12014
+
12015
+ } else {
12016
+ fireEvent('error', {
12017
+ code: 999,
12018
+ message: 'No params have been sent to get bot commands'
12019
+ });
12020
+ return;
12021
+ }
12022
+
12023
+ return sendMessage(getBotCommandsListData, {
12024
+ onResult: function (result) {
12025
+ callback && callback(result);
10736
12026
  }
12027
+ });
12028
+ };
10737
12029
 
10738
- if (typeof params.lastName === 'string') {
10739
- data.lastName = params.lastName;
10740
- } else {
12030
+ this.getThreadAllBots = function (params, callback) {
12031
+ var getThreadBotsData = {
12032
+ chatMessageVOType: chatMessageVOTypes.THREAD_ALL_BOTS,
12033
+ typeCode: params.typeCode,
12034
+ content: {},
12035
+ pushMsgType: 4,
12036
+ token: token
12037
+ };
12038
+
12039
+ if (params) {
12040
+ if (typeof +params.threadId !== 'number' || params.threadId < 0) {
10741
12041
  fireEvent('error', {
10742
12042
  code: 999,
10743
- message: 'lastName is required for Updating Contact!'
12043
+ message: 'Enter a valid Thread Id to get all Bots List!'
10744
12044
  });
12045
+ return;
10745
12046
  }
10746
12047
 
10747
- if (typeof params.cellphoneNumber === 'string') {
10748
- data.cellphoneNumber = params.cellphoneNumber;
10749
- } else {
10750
- fireEvent('error', {
10751
- code: 999,
10752
- message: 'cellphoneNumber is required for Updating Contact!'
10753
- });
12048
+ getThreadBotsData.subjectId = +params.threadId;
12049
+
12050
+ } else {
12051
+ fireEvent('error', {
12052
+ code: 999,
12053
+ message: 'No params have been sent to get thread\' bots list!'
12054
+ });
12055
+ return;
12056
+ }
12057
+
12058
+ return sendMessage(getThreadBotsData, {
12059
+ onResult: function (result) {
12060
+ callback && callback(result);
10754
12061
  }
12062
+ });
12063
+ };
10755
12064
 
10756
- if (typeof params.email === 'string') {
10757
- data.email = params.email;
10758
- } else {
10759
- fireEvent('error', {
10760
- code: 999,
10761
- message: 'email is required for Updating Contact!'
10762
- });
12065
+ this.mapReverse = function (params, callback) {
12066
+ var data = {};
12067
+
12068
+ if (params) {
12069
+ if (parseFloat(params.lat) > 0) {
12070
+ data.lat = params.lat;
12071
+ }
12072
+
12073
+ if (parseFloat(params.lng) > 0) {
12074
+ data.lng = params.lng;
10763
12075
  }
10764
12076
 
10765
12077
  data.uniqueId = Utility.generateUUID();
10766
12078
  }
10767
12079
 
10768
12080
  var requestParams = {
10769
- url: SERVICE_ADDRESSES.PLATFORM_ADDRESS +
10770
- SERVICES_PATH.UPDATE_CONTACTS,
12081
+ url: SERVICE_ADDRESSES.MAP_ADDRESS + SERVICES_PATH.REVERSE,
10771
12082
  method: 'GET',
10772
12083
  data: data,
10773
12084
  headers: {
10774
- '_token_': token,
10775
- '_token_issuer_': 1
12085
+ 'Api-Key': mapApiKey
10776
12086
  }
10777
12087
  };
10778
12088
 
@@ -10781,82 +12091,13 @@
10781
12091
  var responseData = JSON.parse(result.result.responseText);
10782
12092
 
10783
12093
  var returnData = {
10784
- hasError: responseData.hasError,
10785
- cache: false,
10786
- errorMessage: responseData.message,
10787
- errorCode: responseData.errorCode
12094
+ hasError: result.hasError,
12095
+ cache: result.cache,
12096
+ errorMessage: result.message,
12097
+ errorCode: result.errorCode,
12098
+ result: responseData
10788
12099
  };
10789
12100
 
10790
- if (!responseData.hasError) {
10791
- var messageContent = responseData.result,
10792
- messageLength = responseData.result.length,
10793
- resultData = {
10794
- contacts: [],
10795
- contentCount: messageLength
10796
- },
10797
- contactData;
10798
-
10799
- for (var i = 0; i < messageLength; i++) {
10800
- contactData = formatDataToMakeContact(messageContent[i]);
10801
- if (contactData) {
10802
- resultData.contacts.push(contactData);
10803
- }
10804
- }
10805
-
10806
- returnData.result = resultData;
10807
-
10808
- /**
10809
- * Add Contacts into cache database #cache
10810
- */
10811
- if (canUseCache && cacheSecret.length > 0) {
10812
- if (db) {
10813
- var cacheData = [];
10814
-
10815
- for (var i = 0; i < resultData.contacts.length; i++) {
10816
- try {
10817
- var tempData = {},
10818
- salt = Utility.generateUUID();
10819
- tempData.id = resultData.contacts[i].id;
10820
- tempData.owner = userInfo.id;
10821
- tempData.uniqueId = resultData.contacts[i].uniqueId;
10822
- tempData.userId = Utility.crypt(resultData.contacts[i].userId, cacheSecret, salt);
10823
- tempData.cellphoneNumber = Utility.crypt(resultData.contacts[i].cellphoneNumber, cacheSecret, salt);
10824
- tempData.email = Utility.crypt(resultData.contacts[i].email, cacheSecret, salt);
10825
- tempData.firstName = Utility.crypt(resultData.contacts[i].firstName, cacheSecret, salt);
10826
- tempData.lastName = Utility.crypt(resultData.contacts[i].lastName, cacheSecret, salt);
10827
- tempData.expireTime = new Date().getTime() + cacheExpireTime;
10828
- tempData.data = Utility.crypt(JSON.stringify(unsetNotSeenDuration(resultData.contacts[i])), cacheSecret, salt);
10829
- tempData.salt = salt;
10830
-
10831
- cacheData.push(tempData);
10832
- } catch (error) {
10833
- fireEvent('error', {
10834
- code: error.code,
10835
- message: error.message,
10836
- error: error
10837
- });
10838
- }
10839
- }
10840
-
10841
- db.contacts.bulkPut(cacheData)
10842
- .catch(function (error) {
10843
- fireEvent('error', {
10844
- code: error.code,
10845
- message: error.message,
10846
- error: error
10847
- });
10848
- });
10849
- } else {
10850
- fireEvent('error', {
10851
- code: 6601,
10852
- message: CHAT_ERRORS[6601],
10853
- error: null
10854
- });
10855
- }
10856
- }
10857
-
10858
- }
10859
-
10860
12101
  callback && callback(returnData);
10861
12102
 
10862
12103
  } else {
@@ -10869,28 +12110,31 @@
10869
12110
  });
10870
12111
  };
10871
12112
 
10872
- this.removeContacts = function (params, callback) {
12113
+ this.mapSearch = function (params, callback) {
10873
12114
  var data = {};
10874
12115
 
10875
12116
  if (params) {
10876
- if (parseInt(params.id) > 0) {
10877
- data.id = parseInt(params.id);
10878
- } else {
10879
- fireEvent('error', {
10880
- code: 999,
10881
- message: 'ID is required for Deleting Contact!',
10882
- error: undefined
10883
- });
12117
+ if (typeof params.term === 'string') {
12118
+ data.term = params.term;
12119
+ }
12120
+
12121
+ if (parseFloat(params.lat) > 0) {
12122
+ data.lat = params.lat;
10884
12123
  }
12124
+
12125
+ if (parseFloat(params.lng) > 0) {
12126
+ data.lng = params.lng;
12127
+ }
12128
+
12129
+ data.uniqueId = Utility.generateUUID();
10885
12130
  }
10886
12131
 
10887
12132
  var requestParams = {
10888
- url: SERVICE_ADDRESSES.PLATFORM_ADDRESS + SERVICES_PATH.REMOVE_CONTACTS,
10889
- method: 'POST',
12133
+ url: SERVICE_ADDRESSES.MAP_ADDRESS + SERVICES_PATH.SEARCH,
12134
+ method: 'GET',
10890
12135
  data: data,
10891
12136
  headers: {
10892
- '_token_': token,
10893
- '_token_issuer_': 1
12137
+ 'Api-Key': mapApiKey
10894
12138
  }
10895
12139
  };
10896
12140
 
@@ -10898,41 +12142,14 @@
10898
12142
  if (!result.hasError) {
10899
12143
  var responseData = JSON.parse(result.result.responseText);
10900
12144
 
10901
- var returnData = {
10902
- hasError: responseData.hasError,
10903
- cache: false,
10904
- errorMessage: responseData.message,
10905
- errorCode: responseData.errorCode
10906
- };
10907
-
10908
- if (!responseData.hasError) {
10909
- returnData.result = responseData.result;
10910
- }
10911
-
10912
- /**
10913
- * Remove the contact from cache
10914
- */
10915
- if (canUseCache) {
10916
- if (db) {
10917
- db.contacts.where('id')
10918
- .equals(parseInt(params.id))
10919
- .delete()
10920
- .catch(function (error) {
10921
- fireEvent('error', {
10922
- code: 6602,
10923
- message: CHAT_ERRORS[6602],
10924
- error: error
10925
- });
10926
- });
10927
- } else {
10928
- fireEvent('error', {
10929
- code: 6601,
10930
- message: CHAT_ERRORS[6601],
10931
- error: null
10932
- });
10933
- }
10934
- }
10935
-
12145
+ var returnData = {
12146
+ hasError: result.hasError,
12147
+ cache: result.cache,
12148
+ errorMessage: result.message,
12149
+ errorCode: result.errorCode,
12150
+ result: responseData
12151
+ };
12152
+
10936
12153
  callback && callback(returnData);
10937
12154
 
10938
12155
  } else {
@@ -10945,913 +12162,901 @@
10945
12162
  });
10946
12163
  };
10947
12164
 
10948
- this.searchContacts = function (params, callback) {
10949
- var data = {
10950
- size: 50,
10951
- offset: 0
10952
- },
10953
- whereClause = {},
10954
- returnCache = false;
12165
+ this.mapRouting = function (params, callback) {
12166
+ var data = {};
10955
12167
 
10956
12168
  if (params) {
10957
- if (typeof params.firstName === 'string') {
10958
- data.firstName = whereClause.firstName = params.firstName;
10959
- }
10960
-
10961
- if (typeof params.lastName === 'string') {
10962
- data.lastName = whereClause.lastName = params.lastName;
10963
- }
10964
-
10965
- if (parseInt(params.cellphoneNumber) > 0) {
10966
- data.cellphoneNumber = whereClause.cellphoneNumber = params.cellphoneNumber;
10967
- }
10968
-
10969
- if (typeof params.email === 'string') {
10970
- data.email = whereClause.email = params.email;
10971
- }
10972
-
10973
- if (typeof params.query === 'string') {
10974
- data.q = whereClause.q = params.query;
10975
- }
10976
-
10977
- if (typeof params.uniqueId === 'string') {
10978
- data.uniqueId = whereClause.uniqueId = params.uniqueId;
10979
- }
10980
-
10981
- if (parseInt(params.id) > 0) {
10982
- data.id = whereClause.id = params.id;
10983
- }
10984
-
10985
- if (parseInt(params.typeCode) > 0) {
10986
- data.typeCode = whereClause.typeCode = params.typeCode;
12169
+ if (typeof params.alternative === 'boolean') {
12170
+ data.alternative = params.alternative;
12171
+ } else {
12172
+ data.alternative = true;
10987
12173
  }
10988
12174
 
10989
- if (parseInt(params.size) > 0) {
10990
- data.size = params.size;
12175
+ if (typeof params.origin === 'object') {
12176
+ if (parseFloat(params.origin.lat) > 0 && parseFloat(params.origin.lng)) {
12177
+ data.origin = params.origin.lat + ',' + parseFloat(params.origin.lng);
12178
+ } else {
12179
+ console.log('No origin has been selected!');
12180
+ }
10991
12181
  }
10992
12182
 
10993
- if (parseInt(params.offset) > 0) {
10994
- data.offset = params.offset;
12183
+ if (typeof params.destination === 'object') {
12184
+ if (parseFloat(params.destination.lat) > 0 && parseFloat(params.destination.lng)) {
12185
+ data.destination = params.destination.lat + ',' + parseFloat(params.destination.lng);
12186
+ } else {
12187
+ console.log('No destination has been selected!');
12188
+ }
10995
12189
  }
10996
12190
 
10997
- var functionLevelCache = (typeof params.cache == 'boolean') ? params.cache : true;
12191
+ data.uniqueId = Utility.generateUUID();
10998
12192
  }
10999
12193
 
11000
12194
  var requestParams = {
11001
- url: SERVICE_ADDRESSES.PLATFORM_ADDRESS + SERVICES_PATH.SEARCH_CONTACTS,
11002
- method: 'POST',
12195
+ url: SERVICE_ADDRESSES.MAP_ADDRESS + SERVICES_PATH.ROUTING,
12196
+ method: 'GET',
11003
12197
  data: data,
11004
12198
  headers: {
11005
- '_token_': token,
11006
- '_token_issuer_': 1
12199
+ 'Api-Key': mapApiKey
11007
12200
  }
11008
12201
  };
11009
12202
 
11010
- /**
11011
- * Search contacts in cache #cache
11012
- */
11013
- if (functionLevelCache && canUseCache && cacheSecret.length > 0) {
11014
- if (db) {
11015
-
11016
- /**
11017
- * First of all we delete all contacts those
11018
- * expireTime has been expired. after that
11019
- * we query our cache database to retrieve
11020
- * what we wanted
11021
- */
11022
- db.contacts.where('expireTime')
11023
- .below(new Date().getTime())
11024
- .delete()
11025
- .then(function () {
11026
-
11027
- /**
11028
- * Query cache database to get contacts
11029
- */
11030
-
11031
- var thenAble;
11032
-
11033
- if (Object.keys(whereClause).length === 0) {
11034
- thenAble = db.contacts.where('owner')
11035
- .equals(parseInt(userInfo.id));
11036
- } else {
11037
- if (whereClause.hasOwnProperty('id')) {
11038
- thenAble = db.contacts.where('owner')
11039
- .equals(parseInt(userInfo.id))
11040
- .and(function (contact) {
11041
- return contact.id == whereClause.id;
11042
- });
11043
- } else if (whereClause.hasOwnProperty('uniqueId')) {
11044
- thenAble = db.contacts.where('owner')
11045
- .equals(parseInt(userInfo.id))
11046
- .and(function (contact) {
11047
- return contact.uniqueId == whereClause.uniqueId;
11048
- });
11049
- } else {
11050
- if (whereClause.hasOwnProperty('firstName')) {
11051
- thenAble = db.contacts.where('owner')
11052
- .equals(parseInt(userInfo.id))
11053
- .filter(function (contact) {
11054
- var reg = new RegExp(whereClause.firstName);
11055
- return reg.test(chatDecrypt(contact.firstName, cacheSecret, contact.salt));
11056
- });
11057
- }
12203
+ httpRequest(requestParams, function (result) {
12204
+ if (!result.hasError) {
12205
+ var responseData = JSON.parse(result.result.responseText);
11058
12206
 
11059
- if (whereClause.hasOwnProperty('lastName')) {
11060
- thenAble = db.contacts.where('owner')
11061
- .equals(parseInt(userInfo.id))
11062
- .filter(function (contact) {
11063
- var reg = new RegExp(whereClause.lastName);
11064
- return reg.test(chatDecrypt(contact.lastName, cacheSecret, contact.salt));
11065
- });
11066
- }
12207
+ var returnData = {
12208
+ hasError: result.hasError,
12209
+ cache: result.cache,
12210
+ errorMessage: result.message,
12211
+ errorCode: result.errorCode,
12212
+ result: responseData
12213
+ };
11067
12214
 
11068
- if (whereClause.hasOwnProperty('email')) {
11069
- thenAble = db.contacts.where('owner')
11070
- .equals(parseInt(userInfo.id))
11071
- .filter(function (contact) {
11072
- var reg = new RegExp(whereClause.email);
11073
- return reg.test(chatDecrypt(contact.email, cacheSecret, contact.salt));
11074
- });
11075
- }
12215
+ callback && callback(returnData);
11076
12216
 
11077
- if (whereClause.hasOwnProperty('q')) {
11078
- thenAble = db.contacts.where('owner')
11079
- .equals(parseInt(userInfo.id))
11080
- .filter(function (contact) {
11081
- var reg = new RegExp(whereClause.q);
11082
- return reg.test(chatDecrypt(contact.firstName, cacheSecret, contact.salt) + ' ' +
11083
- chatDecrypt(contact.lastName, cacheSecret, contact.salt) + ' ' +
11084
- chatDecrypt(contact.email, cacheSecret, contact.salt));
11085
- });
11086
- }
11087
- }
11088
- }
12217
+ } else {
12218
+ fireEvent('error', {
12219
+ code: result.errorCode,
12220
+ message: result.errorMessage,
12221
+ error: result
12222
+ });
12223
+ }
12224
+ });
12225
+ };
11089
12226
 
11090
- thenAble.offset(data.offset)
11091
- .limit(data.size)
11092
- .toArray()
11093
- .then(function (contacts) {
11094
- db.contacts.where('owner')
11095
- .equals(parseInt(userInfo.id))
11096
- .count()
11097
- .then(function (contactsCount) {
11098
- var cacheData = [];
12227
+ this.mapStaticImage = function (params, callback) {
12228
+ var data = {},
12229
+ url = SERVICE_ADDRESSES.MAP_ADDRESS + SERVICES_PATH.STATIC_IMAGE,
12230
+ hasError = false;
11099
12231
 
11100
- for (var i = 0; i < contacts.length; i++) {
11101
- try {
11102
- var tempData = {},
11103
- salt = contacts[i].salt;
12232
+ if (params) {
12233
+ if (typeof params.type === 'string') {
12234
+ data.type = params.type;
12235
+ } else {
12236
+ data.type = 'standard-night';
12237
+ }
11104
12238
 
11105
- cacheData.push(formatDataToMakeContact(JSON.parse(chatDecrypt(contacts[i].data, cacheSecret, ontacts[i].salt))));
11106
- } catch (error) {
11107
- fireEvent('error', {
11108
- code: error.code,
11109
- message: error.message,
11110
- error: error
11111
- });
11112
- }
11113
- }
12239
+ if (parseInt(params.zoom) > 0) {
12240
+ data.zoom = params.zoom;
12241
+ } else {
12242
+ data.zoom = 15;
12243
+ }
11114
12244
 
11115
- var returnData = {
11116
- hasError: false,
11117
- cache: true,
11118
- errorCode: 0,
11119
- errorMessage: '',
11120
- result: {
11121
- contacts: cacheData,
11122
- contentCount: contactsCount,
11123
- hasNext: !(contacts.length < data.size),
11124
- nextOffset: data.offset + contacts.length
11125
- }
11126
- };
12245
+ if (parseInt(params.width) > 0) {
12246
+ data.width = params.width;
12247
+ } else {
12248
+ data.width = 800;
12249
+ }
11127
12250
 
11128
- if (cacheData.length > 0) {
11129
- callback && callback(returnData);
11130
- callback = undefined;
11131
- returnCache = true;
11132
- }
11133
- })
11134
- .catch(function (error) {
11135
- fireEvent('error', {
11136
- code: error.code,
11137
- message: error.message,
11138
- error: error
11139
- });
11140
- });
11141
- })
11142
- .catch(function (error) {
11143
- fireEvent('error', {
11144
- code: error.code,
11145
- message: error.message,
11146
- error: error
11147
- });
11148
- });
11149
- })
11150
- .catch(function (error) {
11151
- fireEvent('error', {
11152
- code: error.code,
11153
- message: error.message,
11154
- error: error
11155
- });
12251
+ if (parseInt(params.height) > 0) {
12252
+ data.height = params.height;
12253
+ } else {
12254
+ data.height = 600;
12255
+ }
12256
+
12257
+ if (typeof params.center === 'object') {
12258
+ if (parseFloat(params.center.lat) > 0 && parseFloat(params.center.lng)) {
12259
+ data.center = params.center.lat + ',' + parseFloat(params.center.lng);
12260
+ } else {
12261
+ hasError = true;
12262
+ fireEvent('error', {
12263
+ code: 6700,
12264
+ message: CHAT_ERRORS[6700],
12265
+ error: undefined
11156
12266
  });
12267
+ }
11157
12268
  } else {
12269
+ hasError = true;
11158
12270
  fireEvent('error', {
11159
- code: 6601,
11160
- message: CHAT_ERRORS[6601],
11161
- error: null
12271
+ code: 6700,
12272
+ message: CHAT_ERRORS[6700],
12273
+ error: undefined
11162
12274
  });
11163
12275
  }
12276
+
12277
+ data.key = mapApiKey;
11164
12278
  }
11165
12279
 
11166
- /**
11167
- * Get Search Contacts Result From Server
11168
- */
11169
- httpRequest(requestParams, function (result) {
11170
- if (!result.hasError) {
11171
- var responseData = JSON.parse(result.result.responseText);
12280
+ var keys = Object.keys(data);
11172
12281
 
11173
- var returnData = {
11174
- hasError: responseData.hasError,
11175
- cache: false,
11176
- errorMessage: responseData.message,
11177
- errorCode: responseData.errorCode
11178
- };
12282
+ if (keys.length > 0) {
12283
+ url += '?';
11179
12284
 
11180
- if (!responseData.hasError) {
11181
- var messageContent = responseData.result,
11182
- messageLength = responseData.result.length,
11183
- resultData = {
11184
- contacts: [],
11185
- contentCount: messageLength
11186
- },
11187
- contactData;
12285
+ for (var i = 0; i < keys.length; i++) {
12286
+ var key = keys[i];
12287
+ url += key + '=' + data[key];
12288
+ if (i < keys.length - 1) {
12289
+ url += '&';
12290
+ }
12291
+ }
12292
+ }
11188
12293
 
11189
- for (var i = 0; i < messageLength; i++) {
11190
- contactData = formatDataToMakeContact(messageContent[i]);
11191
- if (contactData) {
11192
- resultData.contacts.push(contactData);
11193
- }
11194
- }
12294
+ var returnData = {
12295
+ hasError: hasError,
12296
+ cache: false,
12297
+ errorMessage: (hasError) ? CHAT_ERRORS[6700] : '',
12298
+ errorCode: (hasError) ? 6700 : undefined,
12299
+ result: {
12300
+ link: (!hasError) ? url : ''
12301
+ }
12302
+ };
11195
12303
 
11196
- returnData.result = resultData;
12304
+ callback && callback(returnData);
12305
+ };
11197
12306
 
11198
- /**
11199
- * Add Contacts into cache database #cache
11200
- */
11201
- if (canUseCache && cacheSecret.length > 0) {
11202
- if (db) {
11203
- var cacheData = [];
12307
+ this.setAdmin = function (params, callback) {
12308
+ setRoleToUser(params, callback);
12309
+ };
11204
12310
 
11205
- for (var i = 0; i < resultData.contacts.length; i++) {
11206
- try {
11207
- var tempData = {},
11208
- salt = Utility.generateUUID();
12311
+ this.removeAdmin = function (params, callback) {
12312
+ removeRoleFromUser(params, callback);
12313
+ };
11209
12314
 
11210
- tempData.id = resultData.contacts[i].id;
11211
- tempData.owner = userInfo.id;
11212
- tempData.uniqueId = resultData.contacts[i].uniqueId;
11213
- tempData.userId = Utility.crypt(resultData.contacts[i].userId, cacheSecret, salt);
11214
- tempData.cellphoneNumber = Utility.crypt(resultData.contacts[i].cellphoneNumber, cacheSecret, salt);
11215
- tempData.email = Utility.crypt(resultData.contacts[i].email, cacheSecret, salt);
11216
- tempData.firstName = Utility.crypt(resultData.contacts[i].firstName, cacheSecret, salt);
11217
- tempData.lastName = Utility.crypt(resultData.contacts[i].lastName, cacheSecret, salt);
11218
- tempData.expireTime = new Date().getTime() + cacheExpireTime;
11219
- tempData.data = crypt(JSON.stringify(unsetNotSeenDuration(resultData.contacts[i])), cacheSecret, salt);
11220
- tempData.salt = salt;
12315
+ this.setAuditor = function (params, callback) {
12316
+ setRoleToUser(params, callback);
12317
+ };
11221
12318
 
11222
- cacheData.push(tempData);
11223
- } catch (error) {
11224
- fireEvent('error', {
11225
- code: error.code,
11226
- message: error.message,
11227
- error: error
11228
- });
11229
- }
11230
- }
12319
+ this.removeAuditor = function (params, callback) {
12320
+ removeRoleFromUser(params, callback);
12321
+ };
11231
12322
 
11232
- db.contacts.bulkPut(cacheData)
11233
- .catch(function (error) {
11234
- fireEvent('error', {
11235
- code: error.code,
11236
- message: error.message,
11237
- error: error
11238
- });
11239
- });
11240
- } else {
11241
- fireEvent('error', {
11242
- code: 6601,
11243
- message: CHAT_ERRORS[6601],
11244
- error: null
11245
- });
11246
- }
11247
- }
11248
- }
12323
+ this.clearChatServerCaches = clearChatServerCaches;
11249
12324
 
11250
- callback && callback(returnData);
11251
- /**
11252
- * Delete callback so if server pushes response before
11253
- * cache, cache won't send data again
11254
- */
11255
- callback = undefined;
12325
+ this.deleteCacheDatabases = deleteCacheDatabases;
11256
12326
 
11257
- if (!returnData.hasError && returnCache) {
11258
- fireEvent('contactEvents', {
11259
- type: 'CONTACTS_SEARCH_RESULT_CHANGE',
11260
- result: returnData.result
11261
- });
11262
- }
12327
+ this.clearCacheDatabasesOfUser = clearCacheDatabasesOfUser;
12328
+
12329
+ this.getChatState = function () {
12330
+ return chatFullStateObject;
12331
+ };
12332
+
12333
+ this.reconnect = function () {
12334
+ asyncClient.reconnectSocket();
12335
+ };
12336
+
12337
+ this.setToken = function (newToken) {
12338
+ if (typeof newToken != 'undefined') {
12339
+ token = newToken;
12340
+ }
12341
+ };
12342
+
12343
+ this.generateUUID = Utility.generateUUID;
12344
+
12345
+
12346
+ /** Call public methods */
12347
+ this.startRecordingCall = function (params, callback) {
12348
+ var recordCallData = {
12349
+ chatMessageVOType: chatMessageVOTypes.RECORD_CALL,
12350
+ typeCode: params.typeCode,
12351
+ pushMsgType: 3,
12352
+ token: token,
12353
+ content: {}
12354
+ };
12355
+
12356
+ if (params) {
12357
+ if (typeof +params.callId === 'number' && params.callId > 0) {
12358
+ recordCallData.subjectId = +params.callId;
11263
12359
  } else {
11264
12360
  fireEvent('error', {
11265
- code: result.errorCode,
11266
- message: result.errorMessage,
11267
- error: result
12361
+ code: 999,
12362
+ message: 'Invalid Call id!'
11268
12363
  });
12364
+ return;
12365
+ }
12366
+
12367
+ if(params.destinated === true) {
12368
+ recordCallData.chatMessageVOType = chatMessageVOTypes.DESTINATED_RECORD_CALL;
12369
+ recordCallData.content.recordType = typeof +params.recordType === 'number' ? params.recordType : 1;
12370
+ recordCallData.content.tags = Array.isArray(params.tags) ? params.tags : null;
12371
+ recordCallData.content.threadId = typeof +params.threadId === 'number' ? params.threadId : null;
12372
+ }
12373
+ } else {
12374
+ fireEvent('error', {
12375
+ code: 999,
12376
+ message: 'No params have been sent to Record call!'
12377
+ });
12378
+ return;
12379
+ }
12380
+
12381
+ return sendMessage(recordCallData, {
12382
+ onResult: function (result) {
12383
+ callback && callback(result);
11269
12384
  }
11270
12385
  });
11271
12386
  };
11272
12387
 
11273
- this.createBot = function (params, callback) {
11274
- var createBotData = {
11275
- chatMessageVOType: chatMessageVOTypes.CREATE_BOT,
12388
+ this.stopRecordingCall = function (params, callback) {
12389
+ var stopRecordingCallData = {
12390
+ chatMessageVOType: chatMessageVOTypes.END_RECORD_CALL,
11276
12391
  typeCode: params.typeCode,
11277
- content: '',
11278
- pushMsgType: 4,
12392
+ pushMsgType: 3,
11279
12393
  token: token
11280
12394
  };
11281
12395
 
11282
12396
  if (params) {
11283
- if (typeof params.botName === 'string' && params.botName.length > 0) {
11284
- if (params.botName.substr(-3) === "BOT") {
11285
- createBotData.content = params.botName;
11286
- } else {
11287
- fireEvent('error', {
11288
- code: 999,
11289
- message: 'Bot name should end in "BOT", ex. "testBOT"'
11290
- });
11291
- return;
11292
- }
12397
+ if (typeof +params.callId === 'number' && params.callId > 0) {
12398
+ stopRecordingCallData.subjectId = +params.callId;
11293
12399
  } else {
11294
12400
  fireEvent('error', {
11295
12401
  code: 999,
11296
- message: 'Insert a bot name to create one!'
12402
+ message: 'Invalid Call id!'
11297
12403
  });
11298
12404
  return;
11299
12405
  }
11300
12406
  } else {
11301
12407
  fireEvent('error', {
11302
12408
  code: 999,
11303
- message: 'Insert a bot name to create one!'
12409
+ message: 'No params have been sent to Stop Recording the call!'
11304
12410
  });
11305
12411
  return;
11306
12412
  }
11307
12413
 
11308
- return sendMessage(createBotData, {
12414
+ return sendMessage(stopRecordingCallData, {
11309
12415
  onResult: function (result) {
11310
12416
  callback && callback(result);
11311
12417
  }
11312
12418
  });
11313
12419
  };
11314
12420
 
11315
- this.defineBotCommand = function (params, callback) {
11316
- var defineBotCommandData = {
11317
- chatMessageVOType: chatMessageVOTypes.DEFINE_BOT_COMMAND,
12421
+ this.startCall = function (params, callback) {
12422
+ var startCallData = {
12423
+ chatMessageVOType: chatMessageVOTypes.CALL_REQUEST,
11318
12424
  typeCode: params.typeCode,
11319
- content: {},
11320
- pushMsgType: 4,
12425
+ pushMsgType: 3,
11321
12426
  token: token
11322
- }, commandList = [];
12427
+ }, content = {
12428
+ creatorClientDto: {}
12429
+ };
11323
12430
 
11324
12431
  if (params) {
11325
- if (typeof params.botName !== 'string' || params.botName.length == 0) {
11326
- fireEvent('error', {
11327
- code: 999,
11328
- message: 'You need to insert a botName!'
11329
- });
11330
- return;
11331
- }
12432
+ /*if (typeof params.type === 'string' && callTypes.hasOwnProperty(params.type.toUpperCase())) {
12433
+ content.type = callTypes[params.type.toUpperCase()];
12434
+ } else {
12435
+ content.type = 0x0; // Defaults to AUDIO Call
12436
+ }*/
11332
12437
 
11333
- if (!Array.isArray(params.commandList) || !params.commandList.length) {
11334
- fireEvent('error', {
11335
- code: 999,
11336
- message: 'Bot Commands List has to be an array of strings.'
11337
- });
11338
- return;
12438
+ content.type = 0x0;
12439
+
12440
+ //TODO: Check for mute
12441
+ content.creatorClientDto.mute = true;//(params.mute && typeof params.mute === 'boolean') ? params.mute : false;
12442
+ content.mute = true;//(params.mute && typeof params.mute === 'boolean') ? params.mute : false;
12443
+
12444
+ if (params.clientType
12445
+ && typeof params.clientType === 'string'
12446
+ && callClientType[params.clientType.toUpperCase()] > 0) {
12447
+ content.creatorClientDto.clientType = callClientType[params.clientType.toUpperCase()];
11339
12448
  } else {
11340
- for (var i = 0; i < params.commandList.length; i++) {
11341
- commandList.push('/' + params.commandList[i].trim());
12449
+ content.creatorClientDto.clientType = callClientType.NODE;
12450
+ }
12451
+
12452
+ if (typeof +params.threadId === 'number' && +params.threadId > 0) {
12453
+ content.threadId = +params.threadId;
12454
+ } else {
12455
+ if (Array.isArray(params.invitees)) {
12456
+ content.invitees = [];//params.invitees;
12457
+ for (var i = 0; i < params.invitees.length; i++) {
12458
+ var tempInvitee = params.invitees[i];
12459
+
12460
+ if (tempInvitee && typeof tempInvitee.idType === "string") {
12461
+ tempInvitee.idType = inviteeVOidTypes[tempInvitee.idType];
12462
+ content.invitees.push(tempInvitee);
12463
+ }
12464
+ }
12465
+ } else {
12466
+ fireEvent('error', {
12467
+ code: 999,
12468
+ message: 'Invitees list is empty! Send an array of invitees to start a call with, Or send a Thread Id to start a call with current participants'
12469
+ });
12470
+ return;
11342
12471
  }
11343
12472
  }
11344
12473
 
11345
- defineBotCommandData.content = {
11346
- botName: params.botName.trim(),
11347
- commandList: commandList
11348
- };
11349
-
12474
+ startCallData.content = JSON.stringify(content);
11350
12475
  } else {
11351
12476
  fireEvent('error', {
11352
12477
  code: 999,
11353
- message: 'No params have been sent to create bot commands'
12478
+ message: 'No params have been sent to start call!'
11354
12479
  });
11355
12480
  return;
11356
12481
  }
11357
12482
 
11358
- return sendMessage(defineBotCommandData, {
12483
+ callRequestController.callRequestReceived = true;
12484
+ callRequestController.callEstablishedInMySide = true;
12485
+
12486
+ if(callNoAnswerTimeout) {
12487
+ //TODO: Remove timeout when call ends fast
12488
+ setTimeout( function(metaData) {
12489
+ //Reject the call if participant didn't answer
12490
+ if(!callStopQueue.callStarted ) {
12491
+ fireEvent("callEvents", {
12492
+ type: "CALL_NO_ANSWER_TIMEOUT",
12493
+ message: "Call request timed out, Participant(s) didn't answer",
12494
+ });
12495
+
12496
+ metaData.callInstance.rejectCall({
12497
+ callId: currentCallId
12498
+ });
12499
+ }
12500
+ }, callNoAnswerTimeout, {callInstance: currentModuleInstance});
12501
+ }
12502
+
12503
+ return sendMessage(startCallData, {
11359
12504
  onResult: function (result) {
11360
12505
  callback && callback(result);
11361
12506
  }
11362
12507
  });
11363
12508
  };
11364
12509
 
11365
- this.startBot = function (params, callback) {
11366
- var startBotData = {
11367
- chatMessageVOType: chatMessageVOTypes.START_BOT,
12510
+ this.startGroupCall = function (params, callback) {
12511
+ var startCallData = {
12512
+ chatMessageVOType: chatMessageVOTypes.GROUP_CALL_REQUEST,
11368
12513
  typeCode: params.typeCode,
11369
- content: {},
11370
- pushMsgType: 4,
12514
+ pushMsgType: 3,
11371
12515
  token: token
12516
+ }, content = {
12517
+ creatorClientDto: {}
11372
12518
  };
11373
12519
 
11374
12520
  if (params) {
11375
- if (typeof +params.threadId !== 'number' || params.threadId < 0) {
11376
- fireEvent('error', {
11377
- code: 999,
11378
- message: 'Enter a valid Thread Id for Bot to start in!'
11379
- });
11380
- return;
11381
- }
12521
+ /*if (typeof params.type === 'string' && callTypes.hasOwnProperty(params.type.toUpperCase())) {
12522
+ content.type = callTypes[params.type.toUpperCase()];
12523
+ } else {
12524
+ content.type = 0x0; // Defaults to AUDIO Call
12525
+ }*/
12526
+ content.type = 0x0;
11382
12527
 
11383
- if (typeof params.botName !== 'string' || params.botName.length == 0) {
11384
- fireEvent('error', {
11385
- code: 999,
11386
- message: 'You need to insert a botName!'
11387
- });
11388
- return;
11389
- }
12528
+ content.creatorClientDto.mute = true;//(typeof params.mute === 'boolean') ? params.mute : false;
12529
+ content.mute = true;//(params.mute && typeof params.mute === 'boolean') ? params.mute : false;
11390
12530
 
11391
- startBotData.subjectId = +params.threadId;
12531
+ if (params.clientType && typeof params.clientType === 'string' && callClientType[params.clientType.toUpperCase()] > 0) {
12532
+ content.creatorClientDto.clientType = callClientType[params.clientType.toUpperCase()];
12533
+ } else {
12534
+ content.creatorClientDto.clientType = callClientType.NODE;
12535
+ }
11392
12536
 
11393
- startBotData.content = JSON.stringify({
11394
- botName: params.botName.trim()
11395
- });
12537
+ if (typeof +params.threadId === 'number' && params.threadId > 0) {
12538
+ content.threadId = +params.threadId;
12539
+ } else {
12540
+ if (Array.isArray(params.invitees)) {
12541
+ content.invitees = [];//params.invitees;
12542
+ for (var i = 0; i < params.invitees.length; i++) {
12543
+ var tempInvitee = params.invitees[i];
12544
+
12545
+ if (tempInvitee && typeof tempInvitee.idType === "string") {
12546
+ tempInvitee.idType = inviteeVOidTypes[tempInvitee.idType];
12547
+ content.invitees.push(tempInvitee);
12548
+ }
12549
+ }
12550
+ } else {
12551
+ fireEvent('error', {
12552
+ code: 999,
12553
+ message: 'Invitees list is empty! Send an array of invitees to start a call with, Or send a Thread Id to start a call with current participants'
12554
+ });
12555
+ return;
12556
+ }
12557
+ }
11396
12558
 
12559
+ startCallData.content = JSON.stringify(content);
11397
12560
  } else {
11398
12561
  fireEvent('error', {
11399
12562
  code: 999,
11400
- message: 'No params have been sent to create bot commands'
12563
+ message: 'No params have been sent to start call!'
11401
12564
  });
11402
12565
  return;
11403
12566
  }
11404
12567
 
11405
- return sendMessage(startBotData, {
12568
+ callRequestController.callRequestReceived = true;
12569
+ callRequestController.callEstablishedInMySide = true;
12570
+
12571
+ return sendMessage(startCallData, {
11406
12572
  onResult: function (result) {
11407
12573
  callback && callback(result);
11408
12574
  }
11409
12575
  });
11410
12576
  };
11411
12577
 
11412
- this.stopBot = function (params, callback) {
11413
- var stopBotData = {
11414
- chatMessageVOType: chatMessageVOTypes.STOP_BOT,
12578
+ this.callReceived = callReceived;
12579
+
12580
+ this.terminateCall = function (params, callback) {
12581
+ var terminateCallData = {
12582
+ chatMessageVOType: chatMessageVOTypes.TERMINATE_CALL,
11415
12583
  typeCode: params.typeCode,
11416
- content: {},
11417
- pushMsgType: 4,
12584
+ pushMsgType: 3,
11418
12585
  token: token
11419
- }, commandList = [];
12586
+ }, content = {};
11420
12587
 
11421
12588
  if (params) {
11422
- if (typeof +params.threadId !== 'number' || params.threadId < 0) {
11423
- fireEvent('error', {
11424
- code: 999,
11425
- message: 'Enter a valid Thread Id for Bot to stop on!'
11426
- });
11427
- return;
11428
- }
11429
-
11430
- if (typeof params.botName !== 'string' || params.botName.length == 0) {
12589
+ if (typeof +params.callId === 'number' && params.callId > 0) {
12590
+ terminateCallData.subjectId = +params.callId;
12591
+ } else {
11431
12592
  fireEvent('error', {
11432
12593
  code: 999,
11433
- message: 'You need to insert a botName!'
12594
+ message: 'Invalid call id!'
11434
12595
  });
11435
12596
  return;
11436
12597
  }
11437
12598
 
11438
- stopBotData.subjectId = +params.threadId;
11439
-
11440
- stopBotData.content = JSON.stringify({
11441
- botName: params.botName.trim()
11442
- });
11443
-
12599
+ terminateCallData.content = JSON.stringify(content);
11444
12600
  } else {
11445
12601
  fireEvent('error', {
11446
12602
  code: 999,
11447
- message: 'No params have been sent to create bot commands'
12603
+ message: 'No params have been sent to terminate the call!'
11448
12604
  });
11449
12605
  return;
11450
12606
  }
11451
12607
 
11452
- return sendMessage(stopBotData, {
12608
+ return sendMessage(terminateCallData, {
11453
12609
  onResult: function (result) {
11454
12610
  callback && callback(result);
11455
12611
  }
11456
12612
  });
11457
12613
  };
11458
12614
 
11459
- this.getBotCommandsList = function (params, callback) {
11460
- var getBotCommandsListData = {
11461
- chatMessageVOType: chatMessageVOTypes.BOT_COMMANDS,
12615
+ this.acceptCall = function (params, callback) {
12616
+ var acceptCallData = {
12617
+ chatMessageVOType: chatMessageVOTypes.ACCEPT_CALL,
11462
12618
  typeCode: params.typeCode,
11463
- content: {},
11464
- pushMsgType: 4,
12619
+ pushMsgType: 3,
11465
12620
  token: token
11466
- };
12621
+ }, content = {};
11467
12622
 
11468
12623
  if (params) {
11469
- if (typeof params.botName !== 'string' || params.botName.length == 0) {
12624
+ if (typeof +params.callId === 'number' && params.callId > 0) {
12625
+ acceptCallData.subjectId = +params.callId;
12626
+ } else {
11470
12627
  fireEvent('error', {
11471
12628
  code: 999,
11472
- message: 'You need to insert a botName!'
12629
+ message: 'Invalid call id!'
11473
12630
  });
11474
12631
  return;
11475
12632
  }
11476
12633
 
11477
- getBotCommandsListData.content = JSON.stringify({
11478
- botName: params.botName.trim()
11479
- });
12634
+ content.mute = true;//(typeof params.mute === 'boolean') ? params.mute : false;
12635
+
12636
+ content.video = false;//(typeof params.video === 'boolean') ? params.video : false;
11480
12637
 
12638
+ content.videoCall = false;// content.video;
12639
+
12640
+ if (params.clientType && typeof params.clientType === 'string' && callClientType[params.clientType.toUpperCase()] > 0) {
12641
+ content.clientType = callClientType[params.clientType.toUpperCase()];
12642
+ } else {
12643
+ content.clientType = callClientType.NODE;
12644
+ }
12645
+
12646
+ acceptCallData.content = JSON.stringify(content);
11481
12647
  } else {
11482
12648
  fireEvent('error', {
11483
12649
  code: 999,
11484
- message: 'No params have been sent to get bot commands'
12650
+ message: 'No params have been sent to accept the call!'
11485
12651
  });
11486
12652
  return;
11487
12653
  }
11488
-
11489
- return sendMessage(getBotCommandsListData, {
12654
+ callRequestController.callEstablishedInMySide = true;
12655
+ return sendMessage(acceptCallData, {
11490
12656
  onResult: function (result) {
11491
12657
  callback && callback(result);
11492
12658
  }
11493
12659
  });
11494
12660
  };
11495
12661
 
11496
- this.getThreadAllBots = function (params, callback) {
11497
- var getThreadBotsData = {
11498
- chatMessageVOType: chatMessageVOTypes.THREAD_ALL_BOTS,
12662
+ this.rejectCall = this.cancelCall = function (params, callback) {
12663
+ var rejectCallData = {
12664
+ chatMessageVOType: chatMessageVOTypes.REJECT_CALL,
11499
12665
  typeCode: params.typeCode,
11500
- content: {},
11501
- pushMsgType: 4,
12666
+ pushMsgType: 3,
11502
12667
  token: token
11503
12668
  };
11504
12669
 
11505
12670
  if (params) {
11506
- if (typeof +params.threadId !== 'number' || params.threadId < 0) {
12671
+ if (typeof +params.callId === 'number' && params.callId > 0) {
12672
+ rejectCallData.subjectId = +params.callId;
12673
+ } else {
11507
12674
  fireEvent('error', {
11508
12675
  code: 999,
11509
- message: 'Enter a valid Thread Id to get all Bots List!'
12676
+ message: 'Invalid call id!'
11510
12677
  });
11511
12678
  return;
11512
12679
  }
11513
-
11514
- getThreadBotsData.subjectId = +params.threadId;
11515
-
11516
12680
  } else {
11517
12681
  fireEvent('error', {
11518
12682
  code: 999,
11519
- message: 'No params have been sent to get thread\' bots list!'
12683
+ message: 'No params have been sent to reject the call!'
11520
12684
  });
11521
12685
  return;
11522
12686
  }
11523
12687
 
11524
- return sendMessage(getThreadBotsData, {
12688
+ return sendMessage(rejectCallData, {
11525
12689
  onResult: function (result) {
11526
12690
  callback && callback(result);
11527
12691
  }
11528
12692
  });
11529
12693
  };
11530
12694
 
11531
- this.mapReverse = function (params, callback) {
11532
- var data = {};
12695
+ this.endCall = endCall;
12696
+
12697
+ this.getCallsList = function (params, callback) {
12698
+ var getCallListData = {
12699
+ chatMessageVOType: chatMessageVOTypes.GET_CALLS,
12700
+ typeCode: params.typeCode,
12701
+ pushMsgType: 3,
12702
+ token: token
12703
+ }, content = {};
11533
12704
 
11534
12705
  if (params) {
11535
- if (parseFloat(params.lat) > 0) {
11536
- data.lat = params.lat;
12706
+ if (typeof params.count === 'number' && params.count >= 0) {
12707
+ content.count = +params.count;
12708
+ } else {
12709
+ content.count = 50;
11537
12710
  }
11538
12711
 
11539
- if (parseFloat(params.lng) > 0) {
11540
- data.lng = params.lng;
12712
+ if (typeof params.offset === 'number' && params.offset >= 0) {
12713
+ content.offset = +params.offset;
12714
+ } else {
12715
+ content.offset = 0;
11541
12716
  }
11542
12717
 
11543
- data.uniqueId = Utility.generateUUID();
11544
- }
11545
-
11546
- var requestParams = {
11547
- url: SERVICE_ADDRESSES.MAP_ADDRESS + SERVICES_PATH.REVERSE,
11548
- method: 'GET',
11549
- data: data,
11550
- headers: {
11551
- 'Api-Key': mapApiKey
12718
+ if (typeof params.creatorCoreUserId === 'number' && params.creatorCoreUserId > 0) {
12719
+ content.creatorCoreUserId = +params.creatorCoreUserId;
11552
12720
  }
11553
- };
11554
-
11555
- httpRequest(requestParams, function (result) {
11556
- if (!result.hasError) {
11557
- var responseData = JSON.parse(result.result.responseText);
11558
-
11559
- var returnData = {
11560
- hasError: result.hasError,
11561
- cache: result.cache,
11562
- errorMessage: result.message,
11563
- errorCode: result.errorCode,
11564
- result: responseData
11565
- };
11566
12721
 
11567
- callback && callback(returnData);
12722
+ if (typeof params.creatorSsoId === 'number' && params.creatorSsoId > 0) {
12723
+ content.creatorSsoId = +params.creatorSsoId;
12724
+ }
11568
12725
 
11569
- } else {
11570
- fireEvent('error', {
11571
- code: result.errorCode,
11572
- message: result.errorMessage,
11573
- error: result
11574
- });
12726
+ if (typeof params.name === 'string') {
12727
+ content.name = params.name;
11575
12728
  }
11576
- });
11577
- };
11578
12729
 
11579
- this.mapSearch = function (params, callback) {
11580
- var data = {};
12730
+ if (typeof params.type === 'string' && callTypes.hasOwnProperty(params.type.toUpperCase())) {
12731
+ content.type = callTypes[params.type.toUpperCase()];
12732
+ }
11581
12733
 
11582
- if (params) {
11583
- if (typeof params.term === 'string') {
11584
- data.term = params.term;
12734
+ if (Array.isArray(params.callIds)) {
12735
+ content.callIds = params.callIds;
11585
12736
  }
11586
12737
 
11587
- if (parseFloat(params.lat) > 0) {
11588
- data.lat = params.lat;
12738
+ if (typeof params.contactType === 'string') {
12739
+ content.contactType = params.contactType;
11589
12740
  }
11590
12741
 
11591
- if (parseFloat(params.lng) > 0) {
11592
- data.lng = params.lng;
12742
+ if (typeof params.uniqueId === 'string') {
12743
+ content.uniqueId = params.uniqueId;
11593
12744
  }
11594
12745
 
11595
- data.uniqueId = Utility.generateUUID();
12746
+ getCallListData.content = JSON.stringify(content);
12747
+ } else {
12748
+ fireEvent('error', {
12749
+ code: 999,
12750
+ message: 'No params have been sent to End the call!'
12751
+ });
12752
+ return;
11596
12753
  }
11597
12754
 
11598
- var requestParams = {
11599
- url: SERVICE_ADDRESSES.MAP_ADDRESS + SERVICES_PATH.SEARCH,
11600
- method: 'GET',
11601
- data: data,
11602
- headers: {
11603
- 'Api-Key': mapApiKey
12755
+ return sendMessage(getCallListData, {
12756
+ onResult: function (result) {
12757
+ callback && callback(result);
11604
12758
  }
12759
+ });
12760
+ };
12761
+
12762
+ this.getCallParticipants = function (params, callback) {
12763
+ var sendMessageParams = {
12764
+ chatMessageVOType: chatMessageVOTypes.ACTIVE_CALL_PARTICIPANTS,
12765
+ typeCode: params.typeCode,
12766
+ content: {}
11605
12767
  };
11606
12768
 
11607
- httpRequest(requestParams, function (result) {
11608
- if (!result.hasError) {
11609
- var responseData = JSON.parse(result.result.responseText);
12769
+ if (params) {
12770
+ if (isNaN(params.callId)) {
12771
+ fireEvent('error', {
12772
+ code: 999,
12773
+ message: 'Call Id should be a valid number!'
12774
+ });
12775
+ return;
12776
+ } else {
12777
+ var callId = +params.callId;
12778
+ sendMessageParams.subjectId = callId;
11610
12779
 
11611
- var returnData = {
11612
- hasError: result.hasError,
11613
- cache: result.cache,
11614
- errorMessage: result.message,
11615
- errorCode: result.errorCode,
11616
- result: responseData
11617
- };
12780
+ var offset = (parseInt(params.offset) > 0)
12781
+ ? parseInt(params.offset)
12782
+ : 0,
12783
+ count = (parseInt(params.count) > 0)
12784
+ ? parseInt(params.count)
12785
+ : config.getHistoryCount;
11618
12786
 
11619
- callback && callback(returnData);
12787
+ sendMessageParams.content.count = count;
12788
+ sendMessageParams.content.offset = offset;
11620
12789
 
11621
- } else {
11622
- fireEvent('error', {
11623
- code: result.errorCode,
11624
- message: result.errorMessage,
11625
- error: result
12790
+ return sendMessage(sendMessageParams, {
12791
+ onResult: function (result) {
12792
+ var returnData = {
12793
+ hasError: result.hasError,
12794
+ cache: false,
12795
+ errorMessage: result.errorMessage,
12796
+ errorCode: result.errorCode
12797
+ };
12798
+
12799
+ if (!returnData.hasError) {
12800
+ var messageContent = result.result,
12801
+ messageLength = messageContent.length,
12802
+ resultData = {
12803
+ participants: reformatCallParticipants(messageContent),
12804
+ contentCount: result.contentCount,
12805
+ hasNext: (sendMessageParams.content.offset + sendMessageParams.content.count < result.contentCount && messageLength > 0),
12806
+ nextOffset: sendMessageParams.content.offset * 1 + messageLength * 1
12807
+ };
12808
+
12809
+ returnData.result = resultData;
12810
+ }
12811
+
12812
+ callback && callback(returnData);
12813
+ /**
12814
+ * Delete callback so if server pushes response before
12815
+ * cache, cache won't send data again
12816
+ */
12817
+ callback = undefined;
12818
+
12819
+ if (!returnData.hasError) {
12820
+ fireEvent('callEvents', {
12821
+ type: 'CALL_PARTICIPANTS_LIST_CHANGE',
12822
+ threadId: callId,
12823
+ result: returnData.result
12824
+ });
12825
+ }
12826
+ }
11626
12827
  });
11627
12828
  }
11628
- });
12829
+ } else {
12830
+ fireEvent('error', {
12831
+ code: 999,
12832
+ message: 'No params have been sent to Get Call Participants!'
12833
+ });
12834
+ return;
12835
+ }
11629
12836
  };
11630
12837
 
11631
- this.mapRouting = function (params, callback) {
11632
- var data = {};
12838
+ this.addCallParticipants = function (params, callback) {
12839
+ /**
12840
+ * + AddCallParticipantsRequest {object}
12841
+ * - subjectId {int}
12842
+ * + content {list} List of CONTACT IDs or inviteeVO Objects
12843
+ * - uniqueId {string}
12844
+ */
12845
+
12846
+ var sendMessageParams = {
12847
+ chatMessageVOType: chatMessageVOTypes.ADD_CALL_PARTICIPANT,
12848
+ typeCode: params.typeCode,
12849
+ content: []
12850
+ };
11633
12851
 
11634
12852
  if (params) {
11635
- if (typeof params.alternative === 'boolean') {
11636
- data.alternative = params.alternative;
11637
- } else {
11638
- data.alternative = true;
12853
+ if (typeof params.callId === 'number' && params.callId > 0) {
12854
+ sendMessageParams.subjectId = params.callId;
11639
12855
  }
11640
12856
 
11641
- if (typeof params.origin === 'object') {
11642
- if (parseFloat(params.origin.lat) > 0 && parseFloat(params.origin.lng)) {
11643
- data.origin = params.origin.lat + ',' + parseFloat(params.origin.lng);
11644
- } else {
11645
- console.log('No origin has been selected!');
11646
- }
12857
+ if (Array.isArray(params.contactIds)) {
12858
+ sendMessageParams.content = params.contactIds;
11647
12859
  }
11648
12860
 
11649
- if (typeof params.destination === 'object') {
11650
- if (parseFloat(params.destination.lat) > 0 && parseFloat(params.destination.lng)) {
11651
- data.destination = params.destination.lat + ',' + parseFloat(params.destination.lng);
11652
- } else {
11653
- console.log('No destination has been selected!');
12861
+ if (Array.isArray(params.usernames)) {
12862
+ sendMessageParams.content = [];
12863
+ for (var i = 0; i < params.usernames.length; i++) {
12864
+ sendMessageParams.content.push({
12865
+ id: params.usernames[i],
12866
+ idType: inviteeVOidTypes.TO_BE_USER_USERNAME
12867
+ });
11654
12868
  }
11655
12869
  }
11656
12870
 
11657
- data.uniqueId = Utility.generateUUID();
11658
- }
11659
-
11660
- var requestParams = {
11661
- url: SERVICE_ADDRESSES.MAP_ADDRESS + SERVICES_PATH.ROUTING,
11662
- method: 'GET',
11663
- data: data,
11664
- headers: {
11665
- 'Api-Key': mapApiKey
12871
+ if (Array.isArray(params.coreUserids)) {
12872
+ sendMessageParams.content = [];
12873
+ for (var i = 0; i < params.coreUserids.length; i++) {
12874
+ sendMessageParams.content.push({
12875
+ id: params.coreUserids[i],
12876
+ idType: inviteeVOidTypes.TO_BE_CORE_USER_ID
12877
+ });
12878
+ }
11666
12879
  }
11667
- };
11668
-
11669
- httpRequest(requestParams, function (result) {
11670
- if (!result.hasError) {
11671
- var responseData = JSON.parse(result.result.responseText);
12880
+ }
11672
12881
 
12882
+ return sendMessage(sendMessageParams, {
12883
+ onResult: function (result) {
11673
12884
  var returnData = {
11674
12885
  hasError: result.hasError,
11675
- cache: result.cache,
11676
- errorMessage: result.message,
11677
- errorCode: result.errorCode,
11678
- result: responseData
12886
+ cache: false,
12887
+ errorMessage: result.errorMessage,
12888
+ errorCode: result.errorCode
11679
12889
  };
11680
-
12890
+ if (!returnData.hasError) {
12891
+ // TODO : What is the result?!
12892
+ var messageContent = result.result;
12893
+ returnData.result = messageContent;
12894
+ }
11681
12895
  callback && callback(returnData);
11682
-
11683
- } else {
11684
- fireEvent('error', {
11685
- code: result.errorCode,
11686
- message: result.errorMessage,
11687
- error: result
11688
- });
11689
12896
  }
11690
12897
  });
11691
12898
  };
11692
12899
 
11693
- this.mapStaticImage = function (params, callback) {
11694
- var data = {},
11695
- url = SERVICE_ADDRESSES.MAP_ADDRESS + SERVICES_PATH.STATIC_IMAGE,
11696
- hasError = false;
11697
-
11698
- if (params) {
11699
- if (typeof params.type === 'string') {
11700
- data.type = params.type;
11701
- } else {
11702
- data.type = 'standard-night';
11703
- }
12900
+ this.removeCallParticipants = function (params, callback) {
12901
+ /**
12902
+ * + removeCallParticipantsRequest {object}
12903
+ * - subjectId {int}
12904
+ * + content {list} List of Participants UserIds
12905
+ */
11704
12906
 
11705
- if (parseInt(params.zoom) > 0) {
11706
- data.zoom = params.zoom;
11707
- } else {
11708
- data.zoom = 15;
11709
- }
12907
+ var sendMessageParams = {
12908
+ chatMessageVOType: chatMessageVOTypes.REMOVE_CALL_PARTICIPANT,
12909
+ typeCode: params.typeCode,
12910
+ content: []
12911
+ };
11710
12912
 
11711
- if (parseInt(params.width) > 0) {
11712
- data.width = params.width;
11713
- } else {
11714
- data.width = 800;
12913
+ if (params) {
12914
+ if (typeof params.callId === 'number' && params.callId > 0) {
12915
+ sendMessageParams.subjectId = params.callId;
11715
12916
  }
11716
12917
 
11717
- if (parseInt(params.height) > 0) {
11718
- data.height = params.height;
11719
- } else {
11720
- data.height = 600;
12918
+ if (Array.isArray(params.userIds)) {
12919
+ sendMessageParams.content = params.userIds;
11721
12920
  }
12921
+ }
11722
12922
 
11723
- if (typeof params.center === 'object') {
11724
- if (parseFloat(params.center.lat) > 0 && parseFloat(params.center.lng)) {
11725
- data.center = params.center.lat + ',' + parseFloat(params.center.lng);
11726
- } else {
11727
- hasError = true;
11728
- fireEvent('error', {
11729
- code: 6700,
11730
- message: CHAT_ERRORS[6700],
11731
- error: undefined
11732
- });
12923
+ return sendMessage(sendMessageParams, {
12924
+ onResult: function (result) {
12925
+ var returnData = {
12926
+ hasError: result.hasError,
12927
+ cache: false,
12928
+ errorMessage: result.errorMessage,
12929
+ errorCode: result.errorCode
12930
+ };
12931
+ if (!returnData.hasError) {
12932
+ // TODO : What is the result?!
12933
+ var messageContent = result.result;
12934
+ returnData.result = messageContent;
11733
12935
  }
11734
- } else {
11735
- hasError = true;
11736
- fireEvent('error', {
11737
- code: 6700,
11738
- message: CHAT_ERRORS[6700],
11739
- error: undefined
11740
- });
12936
+ callback && callback(returnData);
11741
12937
  }
12938
+ });
12939
+ };
11742
12940
 
11743
- data.key = mapApiKey;
11744
- }
12941
+ this.muteCallParticipants = function (params, callback) {
12942
+ /**
12943
+ * + muteCallParticipantsRequest {object}
12944
+ * - subjectId {int}
12945
+ * + content {list} List of Participants UserIds
12946
+ */
11745
12947
 
11746
- var keys = Object.keys(data);
12948
+ var sendMessageParams = {
12949
+ chatMessageVOType: chatMessageVOTypes.MUTE_CALL_PARTICIPANT,
12950
+ typeCode: params.typeCode,
12951
+ content: []
12952
+ };
11747
12953
 
11748
- if (keys.length > 0) {
11749
- url += '?';
12954
+ if (params) {
12955
+ if (typeof params.callId === 'number' && params.callId > 0) {
12956
+ sendMessageParams.subjectId = params.callId;
12957
+ }
11750
12958
 
11751
- for (var i = 0; i < keys.length; i++) {
11752
- var key = keys[i];
11753
- url += key + '=' + data[key];
11754
- if (i < keys.length - 1) {
11755
- url += '&';
11756
- }
12959
+ if (Array.isArray(params.userIds)) {
12960
+ sendMessageParams.content = params.userIds;
11757
12961
  }
11758
12962
  }
11759
12963
 
11760
- var returnData = {
11761
- hasError: hasError,
11762
- cache: false,
11763
- errorMessage: (hasError) ? CHAT_ERRORS[6700] : '',
11764
- errorCode: (hasError) ? 6700 : undefined,
11765
- result: {
11766
- link: (!hasError) ? url : ''
12964
+ return sendMessage(sendMessageParams, {
12965
+ onResult: function (result) {
12966
+ var returnData = {
12967
+ hasError: result.hasError,
12968
+ cache: false,
12969
+ errorMessage: result.errorMessage,
12970
+ errorCode: result.errorCode
12971
+ };
12972
+ if (!returnData.hasError) {
12973
+ // TODO : What is the result?!
12974
+ var messageContent = result.result;
12975
+ returnData.result = messageContent;
12976
+ }
12977
+ callback && callback(returnData);
11767
12978
  }
11768
- };
11769
-
11770
- callback && callback(returnData);
11771
- };
11772
-
11773
- this.setAdmin = function (params, callback) {
11774
- setRoleToUser(params, callback);
11775
- };
11776
-
11777
- this.removeAdmin = function (params, callback) {
11778
- removeRoleFromUser(params, callback);
11779
- };
11780
-
11781
- this.setAuditor = function (params, callback) {
11782
- setRoleToUser(params, callback);
11783
- };
11784
-
11785
- this.removeAuditor = function (params, callback) {
11786
- removeRoleFromUser(params, callback);
12979
+ });
11787
12980
  };
11788
12981
 
11789
- this.clearChatServerCaches = clearChatServerCaches;
11790
-
11791
- this.deleteCacheDatabases = deleteCacheDatabases;
11792
-
11793
- this.clearCacheDatabasesOfUser = clearCacheDatabasesOfUser;
12982
+ this.unMuteCallParticipants = function (params, callback) {
12983
+ /**
12984
+ * + unMuteCallParticipantsRequest {object}
12985
+ * - subjectId {int}
12986
+ * + content {list} List of Participants UserIds
12987
+ */
11794
12988
 
11795
- this.getChatState = function () {
11796
- return chatFullStateObject;
11797
- };
12989
+ var sendMessageParams = {
12990
+ chatMessageVOType: chatMessageVOTypes.UNMUTE_CALL_PARTICIPANT,
12991
+ typeCode: params.typeCode,
12992
+ content: []
12993
+ };
11798
12994
 
11799
- this.reconnect = function () {
11800
- asyncClient.reconnectSocket();
11801
- };
12995
+ if (params) {
12996
+ if (typeof params.callId === 'number' && params.callId > 0) {
12997
+ sendMessageParams.subjectId = params.callId;
12998
+ }
11802
12999
 
11803
- this.setToken = function (newToken) {
11804
- if (typeof newToken != 'undefined') {
11805
- token = newToken;
13000
+ if (Array.isArray(params.userIds)) {
13001
+ sendMessageParams.content = params.userIds;
13002
+ }
11806
13003
  }
11807
- };
13004
+ var myId = userInfo.id;
11808
13005
 
11809
- this.generateUUID = Utility.generateUUID;
13006
+ return sendMessage(sendMessageParams, {
13007
+ onResult: function (result) {
13008
+ var returnData = {
13009
+ hasError: result.hasError,
13010
+ cache: false,
13011
+ errorMessage: result.errorMessage,
13012
+ errorCode: result.errorCode
13013
+ };
13014
+ if (!returnData.hasError) {
13015
+ // TODO : What is the result?!
13016
+ var messageContent = result.result;
13017
+ returnData.result = messageContent;
13018
+ }
13019
+ callback && callback(returnData);
13020
+ }
13021
+ });
13022
+ };
11810
13023
 
11811
- this.startRecordingCall = function (params, callback) {
11812
- var recordCallData = {
11813
- chatMessageVOType: chatMessageVOTypes.RECORD_CALL,
13024
+ this.turnOnVideoCall = function (params, callback) {
13025
+ var turnOnVideoData = {
13026
+ chatMessageVOType: chatMessageVOTypes.TURN_ON_VIDEO_CALL,
11814
13027
  typeCode: params.typeCode,
11815
13028
  pushMsgType: 3,
11816
- token: token,
11817
- content: {}
13029
+ token: token
11818
13030
  };
11819
13031
 
11820
13032
  if (params) {
11821
13033
  if (typeof +params.callId === 'number' && params.callId > 0) {
11822
- recordCallData.subjectId = +params.callId;
13034
+ turnOnVideoData.subjectId = +params.callId;
11823
13035
  } else {
11824
13036
  fireEvent('error', {
11825
13037
  code: 999,
11826
- message: 'Invalid Call id!'
13038
+ message: 'Invalid call id!'
11827
13039
  });
11828
13040
  return;
11829
13041
  }
11830
-
11831
- if(params.destinated === true) {
11832
- recordCallData.chatMessageVOType = chatMessageVOTypes.DESTINATED_RECORD_CALL;
11833
- recordCallData.content.recordType = typeof +params.recordType === 'number' ? params.recordType : 1;
11834
- recordCallData.content.tags = Array.isArray(params.tags) ? params.tags : null;
11835
- recordCallData.content.threadId = typeof +params.threadId === 'number' ? params.threadId : null;
11836
- }
11837
13042
  } else {
11838
13043
  fireEvent('error', {
11839
13044
  code: 999,
11840
- message: 'No params have been sent to Record call!'
13045
+ message: 'No params have been sent to turn on the video call!'
11841
13046
  });
11842
13047
  return;
11843
13048
  }
11844
13049
 
11845
- return sendMessage(recordCallData, {
13050
+ return sendMessage(turnOnVideoData, {
11846
13051
  onResult: function (result) {
11847
13052
  callback && callback(result);
11848
13053
  }
11849
13054
  });
11850
13055
  };
11851
13056
 
11852
- this.stopRecordingCall = function (params, callback) {
11853
- var stopRecordingCallData = {
11854
- chatMessageVOType: chatMessageVOTypes.END_RECORD_CALL,
13057
+ this.turnOffVideoCall = function (params, callback) {
13058
+ var turnOffVideoData = {
13059
+ chatMessageVOType: chatMessageVOTypes.TURN_OFF_VIDEO_CALL,
11855
13060
  typeCode: params.typeCode,
11856
13061
  pushMsgType: 3,
11857
13062
  token: token
@@ -11859,29 +13064,31 @@
11859
13064
 
11860
13065
  if (params) {
11861
13066
  if (typeof +params.callId === 'number' && params.callId > 0) {
11862
- stopRecordingCallData.subjectId = +params.callId;
13067
+ turnOffVideoData.subjectId = +params.callId;
11863
13068
  } else {
11864
13069
  fireEvent('error', {
11865
13070
  code: 999,
11866
- message: 'Invalid Call id!'
13071
+ message: 'Invalid call id!'
11867
13072
  });
11868
13073
  return;
11869
13074
  }
11870
13075
  } else {
11871
13076
  fireEvent('error', {
11872
13077
  code: 999,
11873
- message: 'No params have been sent to Stop Recording the call!'
13078
+ message: 'No params have been sent to turn off the video call!'
11874
13079
  });
11875
13080
  return;
11876
13081
  }
11877
13082
 
11878
- return sendMessage(stopRecordingCallData, {
13083
+
13084
+ return sendMessage(turnOffVideoData, {
11879
13085
  onResult: function (result) {
11880
13086
  callback && callback(result);
11881
13087
  }
11882
13088
  });
11883
13089
  };
11884
13090
 
13091
+ this.callStop = callStop;
11885
13092
 
11886
13093
  this.logout = function () {
11887
13094
  clearChatServerCaches();