podchat 10.14.13 → 11.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.
- package/config.js +59 -0
- package/dist/podchat-10.14.13.js +112005 -112005
- package/examples/index.html +27 -13
- package/package.json +8 -2
- package/src/chat.js +180 -7
package/examples/index.html
CHANGED
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
<script type="text/javascript" src="../node_modules/podasync/src/network/async.js"></script>
|
|
12
12
|
<script type="text/javascript" src="../node_modules/crypto-js/crypto-js.js"></script>
|
|
13
13
|
<script type="text/javascript" src="../node_modules/dexie/dist/dexie.min.js"></script>
|
|
14
|
+
<script type="text/javascript" src="../node_modules/dompurify/dist/purify.min.js"></script>
|
|
15
|
+
|
|
14
16
|
<script type="text/javascript" src="../src/chat.js"></script>
|
|
15
17
|
|
|
16
18
|
<!-- Production Mode -->
|
|
@@ -43,22 +45,22 @@
|
|
|
43
45
|
/**
|
|
44
46
|
* Main Server
|
|
45
47
|
*/
|
|
46
|
-
socketAddress: 'wss://msg.pod.ir/ws', // {**REQUIRED**} Socket Address
|
|
47
|
-
ssoHost: 'https://accounts.pod.ir', // {**REQUIRED**} Socket Address
|
|
48
|
-
platformHost: 'https://api.pod.ir/srv/core', // {**REQUIRED**} Platform Core Address
|
|
49
|
-
fileServer: 'https://core.pod.ir', // {**REQUIRED**} File Server Address
|
|
50
|
-
podSpaceFileServer: 'https://podspace.pod.ir', // {**REQUIRED**} File Server Address
|
|
51
|
-
serverName: 'chat-server', // {**REQUIRED**} Server to to register on
|
|
48
|
+
// socketAddress: 'wss://msg.pod.ir/ws', // {**REQUIRED**} Socket Address
|
|
49
|
+
// ssoHost: 'https://accounts.pod.ir', // {**REQUIRED**} Socket Address
|
|
50
|
+
// platformHost: 'https://api.pod.ir/srv/core', // {**REQUIRED**} Platform Core Address
|
|
51
|
+
// fileServer: 'https://core.pod.ir', // {**REQUIRED**} File Server Address
|
|
52
|
+
// podSpaceFileServer: 'https://podspace.pod.ir', // {**REQUIRED**} File Server Address
|
|
53
|
+
// serverName: 'chat-server', // {**REQUIRED**} Server to to register on
|
|
52
54
|
|
|
53
55
|
/**
|
|
54
56
|
* Sand Box
|
|
55
57
|
*/
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
socketAddress: "wss://chat-sandbox.pod.ir/ws",
|
|
59
|
+
ssoHost: "https://accounts.pod.ir",
|
|
60
|
+
platformHost: "https://sandbox.pod.ir:8043/srv/basic-platform",
|
|
61
|
+
fileServer: 'https://core.pod.ir',
|
|
62
|
+
podSpaceFileServer: 'https://podspace.pod.ir',
|
|
63
|
+
serverName: "chat-server",
|
|
62
64
|
|
|
63
65
|
/**
|
|
64
66
|
* PodSpace test
|
|
@@ -85,7 +87,7 @@
|
|
|
85
87
|
fullResponseObject: false,
|
|
86
88
|
mapApiKey: '8b77db18704aa646ee5aaea13e7370f4f88b9e8c',
|
|
87
89
|
// typeCode: "talk",
|
|
88
|
-
token: "
|
|
90
|
+
token: "0bea561f71af4cc9829afce8ac472f2f",
|
|
89
91
|
// token: "f19933ae1b1e424db9965a243bf3bcd3", // {**REQUIRED**} SSO Token ZiZi
|
|
90
92
|
// token: "81025b3fbc1a4f7184c3600a2f874673", // {**REQUIRED**} SSO Token JiJi
|
|
91
93
|
// token: "3c4d62b6068043aa898cf7426d5cae68", // {**REQUIRED**} SSO Token FiFi
|
|
@@ -799,6 +801,18 @@
|
|
|
799
801
|
break;
|
|
800
802
|
}
|
|
801
803
|
});
|
|
804
|
+
/**
|
|
805
|
+
* Listen to Call Events
|
|
806
|
+
*/
|
|
807
|
+
chatAgent.on("callEvents", function (event) {
|
|
808
|
+
var type = event.type;
|
|
809
|
+
console.log(event);
|
|
810
|
+
/*
|
|
811
|
+
switch (type) {
|
|
812
|
+
default:
|
|
813
|
+
break;
|
|
814
|
+
}*/
|
|
815
|
+
});
|
|
802
816
|
|
|
803
817
|
/**
|
|
804
818
|
* Listen to User Events
|
package/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "podchat",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.3.0",
|
|
4
4
|
"description": "Javascript SDK to use POD's Chat Service",
|
|
5
5
|
"main": "./src/chat.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "mocha --reporter spec --exit"
|
|
7
|
+
"test": "mocha --reporter spec --exit",
|
|
8
|
+
"publish:snapshot": "npm run version:snapshot && npm publish --tag snapshot",
|
|
9
|
+
"version:snapshot": "npm version prerelease --preid snapshot",
|
|
10
|
+
"publish:release": "npm run version:release && npm publish",
|
|
11
|
+
"version:release": "npm version 11.3.0"
|
|
8
12
|
},
|
|
9
13
|
"repository": {
|
|
10
14
|
"type": "git",
|
|
@@ -28,10 +32,12 @@
|
|
|
28
32
|
"dependencies": {
|
|
29
33
|
"crypto-js": "^3.1.9-1",
|
|
30
34
|
"dexie": "^2.0.4",
|
|
35
|
+
"dompurify": "^2.3.3",
|
|
31
36
|
"faker": "^4.1.0",
|
|
32
37
|
"form-data": "^2.5.0",
|
|
33
38
|
"image-size": "^0.8.3",
|
|
34
39
|
"indexeddbshim": "^3.10.0",
|
|
40
|
+
"jsdom": "^18.0.0",
|
|
35
41
|
"mime": "^2.4.4",
|
|
36
42
|
"podasync": "^2.8.3",
|
|
37
43
|
"query-string": "^6.8.1",
|
package/src/chat.js
CHANGED
|
@@ -9,15 +9,21 @@
|
|
|
9
9
|
ChatUtility,
|
|
10
10
|
FormData,
|
|
11
11
|
Request,
|
|
12
|
-
Dexie
|
|
12
|
+
Dexie,
|
|
13
|
+
JSDOM,
|
|
14
|
+
DOMPurify;
|
|
13
15
|
|
|
14
16
|
function Chat(params) {
|
|
15
17
|
if (typeof (require) !== 'undefined' && typeof (exports) !== 'undefined') {
|
|
16
|
-
Async = require('podasync')
|
|
17
|
-
ChatUtility = require('./utility/utility.js')
|
|
18
|
-
FormData = require('form-data')
|
|
19
|
-
Request = require('request')
|
|
18
|
+
Async = require('podasync');
|
|
19
|
+
ChatUtility = require('./utility/utility.js');
|
|
20
|
+
FormData = require('form-data');
|
|
21
|
+
Request = require('request');
|
|
20
22
|
Dexie = require('dexie').default || require('dexie');
|
|
23
|
+
DOMPurify = require('dompurify');
|
|
24
|
+
JSDOM = require('jsdom').JSDOM;
|
|
25
|
+
DOMPurify = DOMPurify(new JSDOM('').window);
|
|
26
|
+
|
|
21
27
|
|
|
22
28
|
var QueryString = require('querystring'),
|
|
23
29
|
FS = require('fs'),
|
|
@@ -44,7 +50,8 @@
|
|
|
44
50
|
Async = window.POD.Async,
|
|
45
51
|
ChatUtility = window.POD.ChatUtility,
|
|
46
52
|
FormData = window.FormData,
|
|
47
|
-
Dexie = window.Dexie
|
|
53
|
+
Dexie = window.Dexie,
|
|
54
|
+
DOMPurify = window.DOMPurify;
|
|
48
55
|
}
|
|
49
56
|
|
|
50
57
|
/*******************************************************
|
|
@@ -89,7 +96,8 @@
|
|
|
89
96
|
systemEvents: {},
|
|
90
97
|
chatReady: {},
|
|
91
98
|
error: {},
|
|
92
|
-
chatState: {}
|
|
99
|
+
chatState: {},
|
|
100
|
+
callEvents: {}
|
|
93
101
|
},
|
|
94
102
|
messagesCallbacks = {},
|
|
95
103
|
sendMessageCallbacks = {},
|
|
@@ -156,6 +164,14 @@
|
|
|
156
164
|
THREAD_ALL_BOTS: 69,
|
|
157
165
|
CONTACT_SYNCED: 90,
|
|
158
166
|
LOGOUT: 100,
|
|
167
|
+
|
|
168
|
+
RECORD_CALL: 121,
|
|
169
|
+
END_RECORD_CALL: 122,
|
|
170
|
+
DESTINATED_RECORD_CALL: 126,
|
|
171
|
+
ASSISTANT_CALL_STARTED: 127,
|
|
172
|
+
ASSISTANT_CALL_ENDED: 128,
|
|
173
|
+
EXPORT_CHAT: 152,
|
|
174
|
+
|
|
159
175
|
ERROR: 999
|
|
160
176
|
},
|
|
161
177
|
inviteeVOidTypes = {
|
|
@@ -1468,6 +1484,9 @@
|
|
|
1468
1484
|
messageVO.content = JSON.stringify(params.content);
|
|
1469
1485
|
} else {
|
|
1470
1486
|
messageVO.content = params.content;
|
|
1487
|
+
if(DOMPurify.isSupported) {
|
|
1488
|
+
messageVO.content = DOMPurify.sanitize(messageVO.content, {ALLOWED_TAGS: []});
|
|
1489
|
+
}
|
|
1471
1490
|
}
|
|
1472
1491
|
}
|
|
1473
1492
|
|
|
@@ -3110,6 +3129,85 @@
|
|
|
3110
3129
|
});
|
|
3111
3130
|
break;
|
|
3112
3131
|
|
|
3132
|
+
/**
|
|
3133
|
+
* Type 121 Record Call Request
|
|
3134
|
+
*/
|
|
3135
|
+
case chatMessageVOTypes.RECORD_CALL:
|
|
3136
|
+
if (messagesCallbacks[uniqueId]) {
|
|
3137
|
+
messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
|
|
3138
|
+
}
|
|
3139
|
+
|
|
3140
|
+
fireEvent('callEvents', {
|
|
3141
|
+
type: 'START_RECORDING_CALL',
|
|
3142
|
+
result: messageContent
|
|
3143
|
+
});
|
|
3144
|
+
|
|
3145
|
+
break;
|
|
3146
|
+
|
|
3147
|
+
/**
|
|
3148
|
+
* Type 122 End Record Call Request
|
|
3149
|
+
*/
|
|
3150
|
+
case chatMessageVOTypes.END_RECORD_CALL:
|
|
3151
|
+
if (messagesCallbacks[uniqueId]) {
|
|
3152
|
+
messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
|
|
3153
|
+
}
|
|
3154
|
+
|
|
3155
|
+
fireEvent('callEvents', {
|
|
3156
|
+
type: 'STOP_RECORDING_CALL',
|
|
3157
|
+
result: messageContent
|
|
3158
|
+
});
|
|
3159
|
+
|
|
3160
|
+
break;
|
|
3161
|
+
|
|
3162
|
+
/**
|
|
3163
|
+
* Type 126 Destined Record Call Request
|
|
3164
|
+
*/
|
|
3165
|
+
case chatMessageVOTypes.DESTINATED_RECORD_CALL:
|
|
3166
|
+
if (messagesCallbacks[uniqueId]) {
|
|
3167
|
+
messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
|
|
3168
|
+
}
|
|
3169
|
+
|
|
3170
|
+
fireEvent('callEvents', {
|
|
3171
|
+
type: 'START_RECORDING_CALL',
|
|
3172
|
+
result: messageContent
|
|
3173
|
+
});
|
|
3174
|
+
|
|
3175
|
+
break;
|
|
3176
|
+
|
|
3177
|
+
/**
|
|
3178
|
+
* Type 127 Assistant call started
|
|
3179
|
+
*
|
|
3180
|
+
* Tells the assistant that a call started
|
|
3181
|
+
*/
|
|
3182
|
+
case chatMessageVOTypes.ASSISTANT_CALL_STARTED:
|
|
3183
|
+
/*if (messagesCallbacks[uniqueId]) {
|
|
3184
|
+
messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
|
|
3185
|
+
}*/
|
|
3186
|
+
|
|
3187
|
+
fireEvent('callEvents', {
|
|
3188
|
+
type: 'ASSISTANT_CALL_STARTED',
|
|
3189
|
+
result: {
|
|
3190
|
+
callId: threadId
|
|
3191
|
+
}
|
|
3192
|
+
});
|
|
3193
|
+
|
|
3194
|
+
break;
|
|
3195
|
+
|
|
3196
|
+
/**
|
|
3197
|
+
* Type 128 Assistant call ended
|
|
3198
|
+
*
|
|
3199
|
+
* Tells the assistant that a call ended
|
|
3200
|
+
*/
|
|
3201
|
+
case chatMessageVOTypes.ASSISTANT_CALL_ENDED:
|
|
3202
|
+
/* if (messagesCallbacks[uniqueId]) {
|
|
3203
|
+
messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
|
|
3204
|
+
}*/
|
|
3205
|
+
|
|
3206
|
+
fireEvent('callEvents', {
|
|
3207
|
+
type: 'ASSISTANT_CALL_ENDED'
|
|
3208
|
+
});
|
|
3209
|
+
|
|
3210
|
+
break;
|
|
3113
3211
|
|
|
3114
3212
|
/**
|
|
3115
3213
|
* Type 999 All unknown errors
|
|
@@ -11710,6 +11808,81 @@
|
|
|
11710
11808
|
|
|
11711
11809
|
this.generateUUID = Utility.generateUUID;
|
|
11712
11810
|
|
|
11811
|
+
this.startRecordingCall = function (params, callback) {
|
|
11812
|
+
var recordCallData = {
|
|
11813
|
+
chatMessageVOType: chatMessageVOTypes.RECORD_CALL,
|
|
11814
|
+
typeCode: params.typeCode,
|
|
11815
|
+
pushMsgType: 3,
|
|
11816
|
+
token: token,
|
|
11817
|
+
content: {}
|
|
11818
|
+
};
|
|
11819
|
+
|
|
11820
|
+
if (params) {
|
|
11821
|
+
if (typeof +params.callId === 'number' && params.callId > 0) {
|
|
11822
|
+
recordCallData.subjectId = +params.callId;
|
|
11823
|
+
} else {
|
|
11824
|
+
fireEvent('error', {
|
|
11825
|
+
code: 999,
|
|
11826
|
+
message: 'Invalid Call id!'
|
|
11827
|
+
});
|
|
11828
|
+
return;
|
|
11829
|
+
}
|
|
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
|
+
} else {
|
|
11838
|
+
fireEvent('error', {
|
|
11839
|
+
code: 999,
|
|
11840
|
+
message: 'No params have been sent to Record call!'
|
|
11841
|
+
});
|
|
11842
|
+
return;
|
|
11843
|
+
}
|
|
11844
|
+
|
|
11845
|
+
return sendMessage(recordCallData, {
|
|
11846
|
+
onResult: function (result) {
|
|
11847
|
+
callback && callback(result);
|
|
11848
|
+
}
|
|
11849
|
+
});
|
|
11850
|
+
};
|
|
11851
|
+
|
|
11852
|
+
this.stopRecordingCall = function (params, callback) {
|
|
11853
|
+
var stopRecordingCallData = {
|
|
11854
|
+
chatMessageVOType: chatMessageVOTypes.END_RECORD_CALL,
|
|
11855
|
+
typeCode: params.typeCode,
|
|
11856
|
+
pushMsgType: 3,
|
|
11857
|
+
token: token
|
|
11858
|
+
};
|
|
11859
|
+
|
|
11860
|
+
if (params) {
|
|
11861
|
+
if (typeof +params.callId === 'number' && params.callId > 0) {
|
|
11862
|
+
stopRecordingCallData.subjectId = +params.callId;
|
|
11863
|
+
} else {
|
|
11864
|
+
fireEvent('error', {
|
|
11865
|
+
code: 999,
|
|
11866
|
+
message: 'Invalid Call id!'
|
|
11867
|
+
});
|
|
11868
|
+
return;
|
|
11869
|
+
}
|
|
11870
|
+
} else {
|
|
11871
|
+
fireEvent('error', {
|
|
11872
|
+
code: 999,
|
|
11873
|
+
message: 'No params have been sent to Stop Recording the call!'
|
|
11874
|
+
});
|
|
11875
|
+
return;
|
|
11876
|
+
}
|
|
11877
|
+
|
|
11878
|
+
return sendMessage(stopRecordingCallData, {
|
|
11879
|
+
onResult: function (result) {
|
|
11880
|
+
callback && callback(result);
|
|
11881
|
+
}
|
|
11882
|
+
});
|
|
11883
|
+
};
|
|
11884
|
+
|
|
11885
|
+
|
|
11713
11886
|
this.logout = function () {
|
|
11714
11887
|
clearChatServerCaches();
|
|
11715
11888
|
|