podchat 11.4.0 → 12.4.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.
package/changelog.md CHANGED
@@ -3,10 +3,53 @@
3
3
  All notable changes to this project will be documented here.
4
4
  to see complete list of changelog please visit [ChangeLog](https://github.com/masoudmanson/pod-chat/blob/master/changelog.md)
5
5
 
6
+ ## [12.3.0] - 26-4-2022
7
+ ### Added
8
+ - callNoAnswerTimeout to SDK configs
9
+
10
+ ## [12.2.0] - 23-1-2022
11
+ ### Added
12
+ - callId in END CALL events
13
+
14
+ ### Changed
15
+ - idType as string in invitees list for startCall and startGroupCall
16
+
17
+ ### Fixed
18
+ - fixed errors on newMessageHandler
6
19
 
7
- ## [Unreleased]
8
20
 
9
- - Search in threads metadata
21
+ ## [11.4.0] - 11-12-2021
22
+ ### Added
23
+
24
+ - method: startCall
25
+ - method: startGroupCall
26
+ - method: endCall
27
+ - method: terminateCall
28
+ - method: rejectCall
29
+ - method: muteCallParticipants
30
+ - method: unMuteCallParticipants
31
+ - method: turnOnVideoCall
32
+ - method: turnOffVideoCall
33
+ - method: getCallParticipants
34
+ - method: addCallParticipants
35
+ - method: removeCallParticipants
36
+ - method: getCallsList
37
+ - event: callEvents.CALL_STARTED_ELSEWHERE
38
+ - event: callEvents.RECEIVE_CALL
39
+ - event: callEvents.CALL_SESSION_CREATED
40
+ - event: callEvents.ACCEPT_CALL
41
+ - event: callEvents.REJECT_CALL
42
+ - event: callEvents.PARTNER_RECEIVED_YOUR_CALL
43
+ - event: callEvents.CALL_SESSION_CREATED
44
+ - event: callEvents.CALL_STARTED
45
+ - event: callEvents.CALL_ENDED
46
+ - event: callEvents.CALL_PARTICIPANT_JOINED
47
+ - event: callEvents.CALL_PARTICIPANT_LEFT
48
+ - event: callEvents.CALL_PARTICIPANT_MUTE
49
+ - event: callEvents.CALL_PARTICIPANT_UNMUTE
50
+ - event: callEvents.TURN_ON_VIDEO_CALL
51
+ - event: callEvents.TURN_OFF_VIDEO_CALL
52
+ - event: callEvents.CALL_ERROR
10
53
 
11
54
 
12
55
  ## [11.3.0] - 27-11-2021
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "podchat",
3
- "version": "11.4.0",
3
+ "version": "12.4.0",
4
4
  "description": "Javascript SDK to use POD's Chat Service",
5
5
  "main": "./src/chat.js",
6
6
  "scripts": {
@@ -8,7 +8,7 @@
8
8
  "publish:snapshot": "npm run version:snapshot && npm publish --tag snapshot",
9
9
  "version:snapshot": "npm version prerelease --preid snapshot",
10
10
  "publish:release": "npm run version:release && npm publish",
11
- "version:release": "npm version 11.3.0"
11
+ "version:release": "npm version 12.4.0"
12
12
  },
13
13
  "repository": {
14
14
  "type": "git",
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,
@@ -195,6 +196,7 @@
195
196
  DESTINATED_RECORD_CALL: 126,
196
197
  ASSISTANT_CALL_STARTED: 127,
197
198
  ASSISTANT_CALL_ENDED: 128,
199
+ GET_CALLS_TO_JOIN: 129,
198
200
  EXPORT_CHAT: 152,
199
201
 
200
202
  ERROR: 999
@@ -374,6 +376,7 @@
374
376
  },
375
377
  currentCallParams = {},
376
378
  currentCallId = null,
379
+ newCallId = null,
377
380
  callClientType = {
378
381
  WEB: 1,
379
382
  ANDROID: 2,
@@ -390,7 +393,8 @@
390
393
  callStopQueue = {
391
394
  callStarted: false,
392
395
  },
393
- callRequestTimeout = (typeof params.callRequestTimeout === 'number' && params.callRequestTimeout >= 0) ? params.callRequestTimeout : 10000;
396
+ callRequestTimeout = (typeof params.callRequestTimeout === 'number' && params.callRequestTimeout >= 0) ? params.callRequestTimeout : 10000,
397
+ callNoAnswerTimeout = params.callOptions && params.callOptions.callNoAnswerTimeout ? params.callOptions.callNoAnswerTimeout : 0;
394
398
 
395
399
 
396
400
  /*******************************************************
@@ -2727,45 +2731,17 @@
2727
2731
  * Type 31 Thread Last Seen Updated
2728
2732
  */
2729
2733
  case chatMessageVOTypes.LAST_SEEN_UPDATED:
2730
- if (fullResponseObject) {
2731
- getThreads({
2732
- threadIds: [messageContent.id]
2733
- }, function (threadsResult) {
2734
- var threads = threadsResult.result.threads;
2734
+ var threadObject = messageContent;
2735
+ threadObject.unreadCount = (messageContent.unreadCount) ? messageContent.unreadCount : 0;
2735
2736
 
2736
- if (!threadsResult.cache) {
2737
- fireEvent('threadEvents', {
2738
- type: 'THREAD_UNREAD_COUNT_UPDATED',
2739
- result: {
2740
- thread: threads[0],
2741
- unreadCount: messageContent.unreadCount
2742
- }
2743
- });
2744
-
2745
- fireEvent('threadEvents', {
2746
- type: 'THREAD_LAST_ACTIVITY_TIME',
2747
- result: {
2748
- thread: threads[0]
2749
- }
2750
- });
2751
- }
2752
- });
2753
- } else {
2754
- fireEvent('threadEvents', {
2755
- type: 'THREAD_UNREAD_COUNT_UPDATED',
2756
- result: {
2757
- thread: threadId,
2758
- unreadCount: messageContent.unreadCount
2759
- }
2760
- });
2737
+ fireEvent('threadEvents', {
2738
+ type: 'THREAD_UNREAD_COUNT_UPDATED',
2739
+ result: {
2740
+ thread: (fullResponseObject ? threadObject : messageContent.id),
2741
+ unreadCount: (messageContent.unreadCount) ? messageContent.unreadCount : 0
2742
+ }
2743
+ });
2761
2744
 
2762
- fireEvent('threadEvents', {
2763
- type: 'THREAD_LAST_ACTIVITY_TIME',
2764
- result: {
2765
- thread: threadId
2766
- }
2767
- });
2768
- }
2769
2745
 
2770
2746
  break;
2771
2747
 
@@ -3194,6 +3170,19 @@
3194
3170
  result: messageContent
3195
3171
  });
3196
3172
 
3173
+ if (messageContent.callId > 0) {
3174
+ if(!currentCallId ) {
3175
+ currentCallId = messageContent.callId;
3176
+ }
3177
+ else
3178
+ newCallId = messageContent.callId;
3179
+ } else {
3180
+ fireEvent('callEvents', {
3181
+ type: 'PARTNER_RECEIVED_YOUR_CALL',
3182
+ result: messageContent
3183
+ });
3184
+ }
3185
+
3197
3186
  currentCallId = messageContent.callId;
3198
3187
 
3199
3188
  break;
@@ -3241,6 +3230,11 @@
3241
3230
  type: 'RECEIVE_CALL',
3242
3231
  result: messageContent
3243
3232
  });
3233
+ if(!currentCallId ) {
3234
+ currentCallId = messageContent.callId;
3235
+ }
3236
+ else
3237
+ newCallId = messageContent.callId;
3244
3238
  } else {
3245
3239
  fireEvent('callEvents', {
3246
3240
  type: 'PARTNER_RECEIVED_YOUR_CALL',
@@ -3248,7 +3242,7 @@
3248
3242
  });
3249
3243
  }
3250
3244
 
3251
- currentCallId = messageContent.callId;
3245
+ // currentCallId = messageContent.callId;
3252
3246
 
3253
3247
  break;
3254
3248
 
@@ -3313,7 +3307,7 @@
3313
3307
 
3314
3308
  fireEvent('callEvents', {
3315
3309
  type: 'CALL_ENDED',
3316
- result: messageContent
3310
+ callId: threadId
3317
3311
  });
3318
3312
 
3319
3313
  callStop();
@@ -3354,12 +3348,19 @@
3354
3348
  messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
3355
3349
  }
3356
3350
 
3351
+ if (messageContent.callId > 0) {
3352
+ if(!currentCallId )
3353
+ currentCallId = messageContent.callId;
3354
+ else
3355
+ newCallId = messageContent.callId;
3356
+ }
3357
+
3357
3358
  fireEvent('callEvents', {
3358
3359
  type: 'RECEIVE_CALL',
3359
3360
  result: messageContent
3360
3361
  });
3361
3362
 
3362
- currentCallId = messageContent.callId;
3363
+ // currentCallId = messageContent.callId;
3363
3364
 
3364
3365
  break;
3365
3366
 
@@ -3488,8 +3489,12 @@
3488
3489
  type: 'CALL_SESSION_CREATED',
3489
3490
  result: messageContent
3490
3491
  });
3492
+ if(!currentCallId)
3493
+ currentCallId = messageContent.callId;
3494
+ else
3495
+ newCallId = messageContent.callId;
3491
3496
 
3492
- currentCallId = messageContent.callId;
3497
+ // currentCallId = messageContent.callId;
3493
3498
 
3494
3499
  break;
3495
3500
 
@@ -3574,10 +3579,6 @@
3574
3579
  * Tells the assistant that a call started
3575
3580
  */
3576
3581
  case chatMessageVOTypes.ASSISTANT_CALL_STARTED:
3577
- /*if (messagesCallbacks[uniqueId]) {
3578
- messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
3579
- }*/
3580
-
3581
3582
  fireEvent('callEvents', {
3582
3583
  type: 'ASSISTANT_CALL_STARTED',
3583
3584
  result: {
@@ -3593,12 +3594,9 @@
3593
3594
  * Tells the assistant that a call ended
3594
3595
  */
3595
3596
  case chatMessageVOTypes.ASSISTANT_CALL_ENDED:
3596
- /* if (messagesCallbacks[uniqueId]) {
3597
- messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
3598
- }*/
3599
-
3600
3597
  fireEvent('callEvents', {
3601
- type: 'ASSISTANT_CALL_ENDED'
3598
+ type: 'ASSISTANT_CALL_ENDED',
3599
+ callId: threadId
3602
3600
  });
3603
3601
 
3604
3602
  break;
@@ -3796,43 +3794,30 @@
3796
3794
  }
3797
3795
  });
3798
3796
 
3799
- if (fullResponseObject) {
3800
- getThreads({
3801
- threadIds: [threadId]
3802
- }, function (threadsResult) {
3803
- var threads = threadsResult.result.threads;
3797
+ var threadObject = message.conversation;
3798
+ var lastMessageVoCopy = Object.assign({}, message);
3799
+ lastMessageVoCopy.conversation && delete lastMessageVoCopy.conversation;
3804
3800
 
3805
- fireEvent('threadEvents', {
3806
- type: 'THREAD_UNREAD_COUNT_UPDATED',
3807
- result: {
3808
- thread: threads[0],
3809
- unreadCount: threads[0].unreadCount
3810
- }
3811
- });
3801
+ threadObject.lastParticipantImage = (!!message.participant && message.participant.hasOwnProperty('image')) ? message.participant.image : '';
3802
+ threadObject.lastMessageVO = lastMessageVoCopy;
3803
+ threadObject.lastParticipantName = (!!message.participant && message.participant.hasOwnProperty('name')) ? message.participant.name : '';
3804
+ threadObject.lastMessage = (message.hasOwnProperty('message')) ? message.message : '';
3812
3805
 
3813
- fireEvent('threadEvents', {
3814
- type: 'THREAD_LAST_ACTIVITY_TIME',
3815
- result: {
3816
- thread: threads[0]
3817
- }
3818
- });
3819
- });
3820
- } else {
3821
- fireEvent('threadEvents', {
3822
- type: 'THREAD_LAST_ACTIVITY_TIME',
3823
- result: {
3824
- thread: threadId
3825
- }
3826
- });
3827
3806
 
3828
- fireEvent('threadEvents', {
3829
- type: 'THREAD_UNREAD_COUNT_UPDATED',
3830
- result: {
3831
- thread: messageContent.id,
3832
- unreadCount: messageContent.conversation.unreadCount
3833
- }
3834
- });
3835
- }
3807
+ fireEvent('threadEvents', {
3808
+ type: 'THREAD_UNREAD_COUNT_UPDATED',
3809
+ result: {
3810
+ thread: (fullResponseObject ? threadObject : messageContent.id),
3811
+ unreadCount: (threadObject.unreadCount) ? threadObject.unreadCount : 0
3812
+ }
3813
+ });
3814
+
3815
+ fireEvent('threadEvents', {
3816
+ type: 'THREAD_LAST_ACTIVITY_TIME',
3817
+ result: {
3818
+ thread: (fullResponseObject ? threadObject : messageContent.id),
3819
+ }
3820
+ });
3836
3821
 
3837
3822
  /**
3838
3823
  * Update waitQ and remove sent messages from it
@@ -8229,7 +8214,8 @@
8229
8214
  }
8230
8215
  }
8231
8216
  for (var id in eventCallbacks[eventName]) {
8232
- eventCallbacks[eventName][id](param);
8217
+ if(eventCallbacks[eventName] && eventCallbacks[eventName][id])
8218
+ eventCallbacks[eventName][id](param);
8233
8219
  }
8234
8220
  },
8235
8221
 
@@ -9181,7 +9167,7 @@
9181
9167
  callRequestController.callRequestReceived = false;
9182
9168
  currentCallParams = {};
9183
9169
  currentCallId = null;
9184
- },
9170
+ },
9185
9171
 
9186
9172
  /**
9187
9173
  * Reformat Call Participants
@@ -12469,7 +12455,15 @@
12469
12455
  content.threadId = +params.threadId;
12470
12456
  } else {
12471
12457
  if (Array.isArray(params.invitees)) {
12472
- content.invitees = params.invitees;
12458
+ content.invitees = [];//params.invitees;
12459
+ for (var i = 0; i < params.invitees.length; i++) {
12460
+ var tempInvitee = params.invitees[i];
12461
+
12462
+ if (tempInvitee && typeof tempInvitee.idType === "string") {
12463
+ tempInvitee.idType = inviteeVOidTypes[tempInvitee.idType];
12464
+ content.invitees.push(tempInvitee);
12465
+ }
12466
+ }
12473
12467
  } else {
12474
12468
  fireEvent('error', {
12475
12469
  code: 999,
@@ -12479,6 +12473,13 @@
12479
12473
  }
12480
12474
  }
12481
12475
 
12476
+ if(params.threadInfo
12477
+ && (params.threadInfo.metadata
12478
+ || params.threadInfo.uniqueName)
12479
+ ) {
12480
+ content.createCallThreadRequest = params.threadInfo
12481
+ }
12482
+
12482
12483
  startCallData.content = JSON.stringify(content);
12483
12484
  } else {
12484
12485
  fireEvent('error', {
@@ -12491,6 +12492,23 @@
12491
12492
  callRequestController.callRequestReceived = true;
12492
12493
  callRequestController.callEstablishedInMySide = true;
12493
12494
 
12495
+ if(callNoAnswerTimeout) {
12496
+ //TODO: Remove timeout when call ends fast
12497
+ setTimeout( function(metaData) {
12498
+ //Reject the call if participant didn't answer
12499
+ if(!callStopQueue.callStarted ) {
12500
+ fireEvent("callEvents", {
12501
+ type: "CALL_NO_ANSWER_TIMEOUT",
12502
+ message: "Call request timed out, Participant(s) didn't answer",
12503
+ });
12504
+
12505
+ metaData.callInstance.rejectCall({
12506
+ callId: currentCallId
12507
+ });
12508
+ }
12509
+ }, callNoAnswerTimeout, {callInstance: currentModuleInstance});
12510
+ }
12511
+
12494
12512
  return sendMessage(startCallData, {
12495
12513
  onResult: function (result) {
12496
12514
  callback && callback(result);
@@ -12529,8 +12547,15 @@
12529
12547
  content.threadId = +params.threadId;
12530
12548
  } else {
12531
12549
  if (Array.isArray(params.invitees)) {
12532
- content.invitees = params.invitees;
12550
+ content.invitees = [];//params.invitees;
12551
+ for (var i = 0; i < params.invitees.length; i++) {
12552
+ var tempInvitee = params.invitees[i];
12533
12553
 
12554
+ if (tempInvitee && typeof tempInvitee.idType === "string") {
12555
+ tempInvitee.idType = inviteeVOidTypes[tempInvitee.idType];
12556
+ content.invitees.push(tempInvitee);
12557
+ }
12558
+ }
12534
12559
  } else {
12535
12560
  fireEvent('error', {
12536
12561
  code: 999,
@@ -12540,6 +12565,15 @@
12540
12565
  }
12541
12566
  }
12542
12567
 
12568
+ if(params.threadInfo
12569
+ && (params.threadInfo.title
12570
+ || params.threadInfo.description
12571
+ || params.threadInfo.metadata
12572
+ || params.threadInfo.uniqueName)
12573
+ ) {
12574
+ content.createCallThreadRequest = params.threadInfo
12575
+ }
12576
+
12543
12577
  startCallData.content = JSON.stringify(content);
12544
12578
  } else {
12545
12579
  fireEvent('error', {
@@ -12628,6 +12662,11 @@
12628
12662
  }
12629
12663
 
12630
12664
  acceptCallData.content = JSON.stringify(content);
12665
+
12666
+ if(params.joinCall) {
12667
+ callRequestController.callRequestReceived = true;
12668
+ currentCallId = params.callId;
12669
+ }
12631
12670
  } else {
12632
12671
  fireEvent('error', {
12633
12672
  code: 999,
@@ -12719,6 +12758,10 @@
12719
12758
  content.callIds = params.callIds;
12720
12759
  }
12721
12760
 
12761
+ if (typeof params.threadId === 'number' && +params.threadId > 0) {
12762
+ content.threadId = +params.threadId;
12763
+ }
12764
+
12722
12765
  if (typeof params.contactType === 'string') {
12723
12766
  content.contactType = params.contactType;
12724
12767
  }
@@ -12743,6 +12786,62 @@
12743
12786
  });
12744
12787
  };
12745
12788
 
12789
+ this.getCallsToJoin = function (params, callback) {
12790
+ var getCallListData = {
12791
+ chatMessageVOType: chatMessageVOTypes.GET_CALLS_TO_JOIN,
12792
+ pushMsgType: 3,
12793
+ token: token
12794
+ }, content = {};
12795
+
12796
+ if (params) {
12797
+ if (typeof params.count === 'number' && params.count >= 0) {
12798
+ content.count = +params.count;
12799
+ } else {
12800
+ content.count = 50;
12801
+ }
12802
+
12803
+ if (typeof params.offset === 'number' && params.offset >= 0) {
12804
+ content.offset = +params.offset;
12805
+ } else {
12806
+ content.offset = 0;
12807
+ }
12808
+
12809
+ if (typeof params.creatorSsoId === 'number' && params.creatorSsoId > 0) {
12810
+ content.creatorSsoId = +params.creatorSsoId;
12811
+ }
12812
+
12813
+ if (typeof params.name === 'string') {
12814
+ content.name = params.name;
12815
+ }
12816
+
12817
+ if (typeof params.type === 'string' && callTypes.hasOwnProperty(params.type.toUpperCase())) {
12818
+ content.type = callTypes[params.type.toUpperCase()];
12819
+ }
12820
+
12821
+ if (Array.isArray(params.threadIds)) {
12822
+ content.threadIds = params.threadIds;
12823
+ }
12824
+
12825
+ if (typeof params.uniqueId === 'string') {
12826
+ content.uniqueId = params.uniqueId;
12827
+ }
12828
+
12829
+ getCallListData.content = JSON.stringify(content);
12830
+ } else {
12831
+ fireEvent('error', {
12832
+ code: 999,
12833
+ message: 'Invalid params'
12834
+ });
12835
+ return;
12836
+ }
12837
+
12838
+ return sendMessage(getCallListData, {
12839
+ onResult: function (result) {
12840
+ callback && callback(result);
12841
+ }
12842
+ });
12843
+ };
12844
+
12746
12845
  this.getCallParticipants = function (params, callback) {
12747
12846
  var sendMessageParams = {
12748
12847
  chatMessageVOType: chatMessageVOTypes.ACTIVE_CALL_PARTICIPANTS,