podchat 12.2.0 → 12.5.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,6 +3,39 @@
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.5.0] - 11-7-2022
7
+ ### Added
8
+ - Added global typeCode and typeCodeOwnerId
9
+ - Added SWITCH_TO_GROUP_CALL_REQUEST , RECORD_CALL_STARTED , fixed GET_CALLS_TO_JOIN
10
+ - Added callId to event type: CALL_STARTED
11
+ - Removed contentCount from hasNext calculation in getThreads and getHistory
12
+
13
+
14
+ ## [12.4.0] - 24-5-2022
15
+ ### Added
16
+ - Parameter: threadInfo in startCall and startGroupCall
17
+ - Parameter: joinCall to acceptCall
18
+ - Parameter: threadId to getCallsList
19
+ - Method: getCallsToJoin
20
+
21
+ ### Fixed
22
+ - error on eventType that has no callback
23
+
24
+
25
+ ## [12.3.0] - 26-4-2022
26
+ ### Added
27
+ - callNoAnswerTimeout to SDK configs
28
+
29
+
30
+ ## [12.2.0] - 23-1-2022
31
+ ### Added
32
+ - callId in END CALL events
33
+
34
+ ### Changed
35
+ - idType as string in invitees list for startCall and startGroupCall
36
+
37
+ ### Fixed
38
+ - fixed errors on newMessageHandler
6
39
 
7
40
 
8
41
  ## [11.4.0] - 11-12-2021
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "podchat",
3
- "version": "12.2.0",
3
+ "version": "12.5.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 12.2.0"
11
+ "version:release": "npm version 12.5.0"
12
12
  },
13
13
  "repository": {
14
14
  "type": "git",
package/src/chat.js CHANGED
@@ -61,11 +61,13 @@
61
61
  var Utility = new ChatUtility();
62
62
 
63
63
  var asyncClient,
64
+ currentModuleInstance = this,
64
65
  peerId,
65
66
  oldPeerId,
66
67
  userInfo,
67
68
  token = params.token,
68
69
  generalTypeCode = params.typeCode || 'default',
70
+ typeCodeOwnerId = params.typeCodeOwnerId || null,
69
71
  mapApiKey = params.mapApiKey || '8b77db18704aa646ee5aaea13e7370f4f88b9e8c',
70
72
  deviceId,
71
73
  isNode = Utility.isNode(),
@@ -195,8 +197,12 @@
195
197
  DESTINATED_RECORD_CALL: 126,
196
198
  ASSISTANT_CALL_STARTED: 127,
197
199
  ASSISTANT_CALL_ENDED: 128,
200
+ GET_CALLS_TO_JOIN: 129,
198
201
  EXPORT_CHAT: 152,
199
202
 
203
+ SWITCH_TO_GROUP_CALL_REQUEST: 221,
204
+ RECORD_CALL_STARTED: 222,
205
+
200
206
  ERROR: 999
201
207
  },
202
208
  inviteeVOidTypes = {
@@ -374,6 +380,7 @@
374
380
  },
375
381
  currentCallParams = {},
376
382
  currentCallId = null,
383
+ newCallId = null,
377
384
  callClientType = {
378
385
  WEB: 1,
379
386
  ANDROID: 2,
@@ -390,8 +397,8 @@
390
397
  callStopQueue = {
391
398
  callStarted: false,
392
399
  },
393
- callRequestTimeout = (typeof params.callRequestTimeout === 'number' && params.callRequestTimeout >= 0) ? params.callRequestTimeout : 10000;
394
-
400
+ callRequestTimeout = (typeof params.callRequestTimeout === 'number' && params.callRequestTimeout >= 0) ? params.callRequestTimeout : 10000,
401
+ callNoAnswerTimeout = params.callOptions && params.callOptions.callNoAnswerTimeout ? params.callOptions.callNoAnswerTimeout : 0;
395
402
 
396
403
  /*******************************************************
397
404
  * P R I V A T E M E T H O D S *
@@ -1519,10 +1526,14 @@
1519
1526
  tokenIssuer: 1
1520
1527
  };
1521
1528
 
1522
- if (params.typeCode) {
1523
- messageVO.typeCode = params.typeCode;
1524
- } else if (generalTypeCode) {
1529
+ if (params.typeCode || generalTypeCode) {
1530
+ messageVO.typeCode = generalTypeCode;//params.typeCode;
1531
+ }/* else if (generalTypeCode) {
1525
1532
  messageVO.typeCode = generalTypeCode;
1533
+ }*/
1534
+
1535
+ if(typeCodeOwnerId) {
1536
+ messageVO.ownerId = typeCodeOwnerId;
1526
1537
  }
1527
1538
 
1528
1539
  if (params.messageType) {
@@ -1822,6 +1833,10 @@
1822
1833
  * @return {undefined}
1823
1834
  */
1824
1835
  chatMessageHandler = function (chatMessage) {
1836
+ if(chatMessage.typeCode && chatMessage.typeCode !== generalTypeCode) {
1837
+ return;
1838
+ }
1839
+
1825
1840
  var threadId = chatMessage.subjectId,
1826
1841
  type = chatMessage.type,
1827
1842
  // TODO Check this again
@@ -3166,6 +3181,19 @@
3166
3181
  result: messageContent
3167
3182
  });
3168
3183
 
3184
+ if (messageContent.callId > 0) {
3185
+ if(!currentCallId ) {
3186
+ currentCallId = messageContent.callId;
3187
+ }
3188
+ else
3189
+ newCallId = messageContent.callId;
3190
+ } else {
3191
+ fireEvent('callEvents', {
3192
+ type: 'PARTNER_RECEIVED_YOUR_CALL',
3193
+ result: messageContent
3194
+ });
3195
+ }
3196
+
3169
3197
  currentCallId = messageContent.callId;
3170
3198
 
3171
3199
  break;
@@ -3213,6 +3241,11 @@
3213
3241
  type: 'RECEIVE_CALL',
3214
3242
  result: messageContent
3215
3243
  });
3244
+ if(!currentCallId ) {
3245
+ currentCallId = messageContent.callId;
3246
+ }
3247
+ else
3248
+ newCallId = messageContent.callId;
3216
3249
  } else {
3217
3250
  fireEvent('callEvents', {
3218
3251
  type: 'PARTNER_RECEIVED_YOUR_CALL',
@@ -3220,7 +3253,7 @@
3220
3253
  });
3221
3254
  }
3222
3255
 
3223
- currentCallId = messageContent.callId;
3256
+ // currentCallId = messageContent.callId;
3224
3257
 
3225
3258
  break;
3226
3259
 
@@ -3241,6 +3274,7 @@
3241
3274
  messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
3242
3275
  }
3243
3276
 
3277
+ messageContent.callId = threadId;
3244
3278
  fireEvent('callEvents', {
3245
3279
  type: 'CALL_STARTED',
3246
3280
  result: messageContent
@@ -3326,12 +3360,19 @@
3326
3360
  messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
3327
3361
  }
3328
3362
 
3363
+ if (messageContent.callId > 0) {
3364
+ if(!currentCallId )
3365
+ currentCallId = messageContent.callId;
3366
+ else
3367
+ newCallId = messageContent.callId;
3368
+ }
3369
+
3329
3370
  fireEvent('callEvents', {
3330
3371
  type: 'RECEIVE_CALL',
3331
3372
  result: messageContent
3332
3373
  });
3333
3374
 
3334
- currentCallId = messageContent.callId;
3375
+ // currentCallId = messageContent.callId;
3335
3376
 
3336
3377
  break;
3337
3378
 
@@ -3460,8 +3501,12 @@
3460
3501
  type: 'CALL_SESSION_CREATED',
3461
3502
  result: messageContent
3462
3503
  });
3504
+ if(!currentCallId)
3505
+ currentCallId = messageContent.callId;
3506
+ else
3507
+ newCallId = messageContent.callId;
3463
3508
 
3464
- currentCallId = messageContent.callId;
3509
+ // currentCallId = messageContent.callId;
3465
3510
 
3466
3511
  break;
3467
3512
 
@@ -3568,6 +3613,42 @@
3568
3613
 
3569
3614
  break;
3570
3615
 
3616
+ /**
3617
+ * Type 129 Get Calls To Join
3618
+ */
3619
+ case chatMessageVOTypes.GET_CALLS_TO_JOIN:
3620
+ if (messagesCallbacks[uniqueId]) {
3621
+ messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
3622
+ }
3623
+ break;
3624
+
3625
+ /**
3626
+ * Type 221 Event to tell us p2p call converted to a group call
3627
+ */
3628
+ case chatMessageVOTypes.SWITCH_TO_GROUP_CALL_REQUEST:
3629
+ fireEvent('callEvents', {
3630
+ type: 'SWITCH_TO_GROUP_CALL',
3631
+ result: messageContent //contains: isGroup, callId, threadId
3632
+ });
3633
+
3634
+ break;
3635
+
3636
+ /**
3637
+ * Type 222 Call Recording Started
3638
+ */
3639
+ case chatMessageVOTypes.RECORD_CALL_STARTED:
3640
+ if (messagesCallbacks[uniqueId]) {
3641
+ messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
3642
+ }
3643
+
3644
+ fireEvent('callEvents', {
3645
+ type: 'CALL_RECORDING_STARTED',
3646
+ result: messageContent
3647
+ });
3648
+
3649
+ break;
3650
+
3651
+
3571
3652
  /**
3572
3653
  * Type 999 All unknown errors
3573
3654
  */
@@ -4932,7 +5013,7 @@
4932
5013
  resultData = {
4933
5014
  threads: [],
4934
5015
  contentCount: result.contentCount,
4935
- hasNext: (offset + count < result.contentCount && messageLength > 0),
5016
+ hasNext: messageContent && !(messageLength < count),//(offset + count < result.contentCount && messageLength > 0),
4936
5017
  nextOffset: offset + messageLength
4937
5018
  },
4938
5019
  threadData;
@@ -6216,8 +6297,7 @@
6216
6297
  var resultData = {
6217
6298
  history: history,
6218
6299
  contentCount: result.contentCount,
6219
- hasNext: (sendMessageParams.content.offset + sendMessageParams.content.count < result.contentCount &&
6220
- messageLength > 0),
6300
+ hasNext: result.result && !(result.result.length < sendMessageParams.content.count),//(sendMessageParams.content.offset + sendMessageParams.content.count < result.contentCount &&messageLength > 0),
6221
6301
  nextOffset: sendMessageParams.content.offset + messageLength
6222
6302
  };
6223
6303
 
@@ -8181,7 +8261,8 @@
8181
8261
  }
8182
8262
  }
8183
8263
  for (var id in eventCallbacks[eventName]) {
8184
- eventCallbacks[eventName][id](param);
8264
+ if(eventCallbacks[eventName] && eventCallbacks[eventName][id])
8265
+ eventCallbacks[eventName][id](param);
8185
8266
  }
8186
8267
  },
8187
8268
 
@@ -12439,6 +12520,13 @@
12439
12520
  }
12440
12521
  }
12441
12522
 
12523
+ if(params.threadInfo
12524
+ && (params.threadInfo.metadata
12525
+ || params.threadInfo.uniqueName)
12526
+ ) {
12527
+ content.createCallThreadRequest = params.threadInfo
12528
+ }
12529
+
12442
12530
  startCallData.content = JSON.stringify(content);
12443
12531
  } else {
12444
12532
  fireEvent('error', {
@@ -12451,6 +12539,23 @@
12451
12539
  callRequestController.callRequestReceived = true;
12452
12540
  callRequestController.callEstablishedInMySide = true;
12453
12541
 
12542
+ if(callNoAnswerTimeout) {
12543
+ //TODO: Remove timeout when call ends fast
12544
+ setTimeout( function(metaData) {
12545
+ //Reject the call if participant didn't answer
12546
+ if(!callStopQueue.callStarted ) {
12547
+ fireEvent("callEvents", {
12548
+ type: "CALL_NO_ANSWER_TIMEOUT",
12549
+ message: "Call request timed out, Participant(s) didn't answer",
12550
+ });
12551
+
12552
+ metaData.callInstance.rejectCall({
12553
+ callId: currentCallId
12554
+ });
12555
+ }
12556
+ }, callNoAnswerTimeout, {callInstance: currentModuleInstance});
12557
+ }
12558
+
12454
12559
  return sendMessage(startCallData, {
12455
12560
  onResult: function (result) {
12456
12561
  callback && callback(result);
@@ -12507,6 +12612,15 @@
12507
12612
  }
12508
12613
  }
12509
12614
 
12615
+ if(params.threadInfo
12616
+ && (params.threadInfo.title
12617
+ || params.threadInfo.description
12618
+ || params.threadInfo.metadata
12619
+ || params.threadInfo.uniqueName)
12620
+ ) {
12621
+ content.createCallThreadRequest = params.threadInfo
12622
+ }
12623
+
12510
12624
  startCallData.content = JSON.stringify(content);
12511
12625
  } else {
12512
12626
  fireEvent('error', {
@@ -12595,6 +12709,11 @@
12595
12709
  }
12596
12710
 
12597
12711
  acceptCallData.content = JSON.stringify(content);
12712
+
12713
+ if(params.joinCall) {
12714
+ callRequestController.callRequestReceived = true;
12715
+ currentCallId = params.callId;
12716
+ }
12598
12717
  } else {
12599
12718
  fireEvent('error', {
12600
12719
  code: 999,
@@ -12686,6 +12805,10 @@
12686
12805
  content.callIds = params.callIds;
12687
12806
  }
12688
12807
 
12808
+ if (typeof params.threadId === 'number' && +params.threadId > 0) {
12809
+ content.threadId = +params.threadId;
12810
+ }
12811
+
12689
12812
  if (typeof params.contactType === 'string') {
12690
12813
  content.contactType = params.contactType;
12691
12814
  }
@@ -12710,6 +12833,62 @@
12710
12833
  });
12711
12834
  };
12712
12835
 
12836
+ this.getCallsToJoin = function (params, callback) {
12837
+ var getCallListData = {
12838
+ chatMessageVOType: chatMessageVOTypes.GET_CALLS_TO_JOIN,
12839
+ pushMsgType: 3,
12840
+ token: token
12841
+ }, content = {};
12842
+
12843
+ if (params) {
12844
+ if (typeof params.count === 'number' && params.count >= 0) {
12845
+ content.count = +params.count;
12846
+ } else {
12847
+ content.count = 50;
12848
+ }
12849
+
12850
+ if (typeof params.offset === 'number' && params.offset >= 0) {
12851
+ content.offset = +params.offset;
12852
+ } else {
12853
+ content.offset = 0;
12854
+ }
12855
+
12856
+ if (typeof params.creatorSsoId === 'number' && params.creatorSsoId > 0) {
12857
+ content.creatorSsoId = +params.creatorSsoId;
12858
+ }
12859
+
12860
+ if (typeof params.name === 'string') {
12861
+ content.name = params.name;
12862
+ }
12863
+
12864
+ if (typeof params.type === 'string' && callTypes.hasOwnProperty(params.type.toUpperCase())) {
12865
+ content.type = callTypes[params.type.toUpperCase()];
12866
+ }
12867
+
12868
+ if (Array.isArray(params.threadIds)) {
12869
+ content.threadIds = params.threadIds;
12870
+ }
12871
+
12872
+ if (typeof params.uniqueId === 'string') {
12873
+ content.uniqueId = params.uniqueId;
12874
+ }
12875
+
12876
+ getCallListData.content = JSON.stringify(content);
12877
+ } else {
12878
+ fireEvent('error', {
12879
+ code: 999,
12880
+ message: 'Invalid params'
12881
+ });
12882
+ return;
12883
+ }
12884
+
12885
+ return sendMessage(getCallListData, {
12886
+ onResult: function (result) {
12887
+ callback && callback(result);
12888
+ }
12889
+ });
12890
+ };
12891
+
12713
12892
  this.getCallParticipants = function (params, callback) {
12714
12893
  var sendMessageParams = {
12715
12894
  chatMessageVOType: chatMessageVOTypes.ACTIVE_CALL_PARTICIPANTS,
package/config.js DELETED
@@ -1,59 +0,0 @@
1
- var CONFIG = {
2
- // token: '1cfce37b60d4421db870e67dcfe407d9', // gameBOT
3
- // token: '567179f126d84277b8dced22599e0b82', // takiBOT
4
- // token: '1a9d91ccb4d5431b89dd74f7e0bb417b', // talkyBOT
5
- // token: 'd10237d19ad24ba089f66bdfe3de9974', // Clasor
6
- // token: "b135febd870746f88032df84dfb01c85", // Clasor Test BOT
7
- token: 'b45fa3d386f54e34b82d81a11bc27e90',
8
-
9
- // Permenant Integration Tokens
10
- // token: "3dd6895c8dc64f93bcd43b58dcc2aab3", // Masoud Amjadi
11
- // token: "9c627a9125d04ebf8455bf57bb33d2a9", // Pooria Pahlevani
12
- // token: "f6464d4e0f044314b1a668f90287ba26", // Nadia Anvari
13
- // token: "99506f7c32c849a9a6e2a954303b81ee", // Farhad Kheirkhah
14
- // token: "979aa5de03934c73a5c6c855bd80cb04", // Mahyar Zhiani
15
- // token: "a47c9016c8354236abc01395093bed5c", // Ahmad Sajadi
16
- // token: "d3114ed2fd2a49b4a0a386e727c9e5fa", // Saba Safavi
17
- // token: "872110b9c6944eda9bc98ef2a68dcf50", // Leila Nemati
18
-
19
- // ActiveMQ Connection config
20
- // queueHost: "10.56.16.25",
21
- // queuePort: "61613",
22
- // queueUsername: "root",
23
- // queuePassword: "zalzalak",
24
- // queueReceive: "queue-in-amjadi-stomp",
25
- // queueSend: "queue-out-amjadi-stomp",
26
-
27
- // Neshan Map Api Token
28
- mapApiKey: '8b77db18704aa646ee5aaea13e7370f4f88b9e8c',
29
-
30
- // Main Server
31
- main: {
32
- socketAddress: 'wss://msg.pod.ir/ws',
33
- ssoHost: 'https://accounts.pod.ir',
34
- platformHost: 'https://api.pod.ir/srv/core',
35
- fileServer: 'https://core.pod.ir',
36
- podSpaceFileServer: 'https://podspace.podland.ir',
37
- serverName: 'chat-server'
38
- },
39
-
40
- // Sand Box Server
41
- sandbox: {
42
- socketAddress: "wss://chat-sandbox.pod.ir/ws",
43
- ssoHost: "https://accounts.pod.ir",
44
- platformHost: "https://sandbox.pod.ir:8043/srv/basic-platform",
45
- fileServer: 'https://core.pod.ir',
46
- podSpaceFileServer: 'http://sandbox.podspace.ir:8080',
47
- serverName: "chat-server"
48
- },
49
-
50
- // Integration Server
51
- integration: {
52
- socketAddress: "ws://172.16.110.235:8003/ws",
53
- ssoHost: "http://172.16.110.76",
54
- platformHost: "http://172.16.110.235:8003/srv/bptest-core",
55
- fileServer: 'https://core.pod.ir',
56
- podSpaceFileServer: 'http://172.16.110.61:8780/podspace',
57
- serverName: "chatlocal"
58
- }
59
- }