@chat21/chat21-ionic 3.4.27-rc22 → 3.4.27-rc23
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 +3 -0
- package/package.json +1 -1
- package/src/app/app.component.ts +5 -7
- package/src/app/services/websocket/websocket-js.ts +17 -16
- package/src/app/services/websocket/websocket.worker.ts +1 -1
- package/src/assets/js/chat21client.js +34 -0
- package/src/assets/js/mqtt-keepalive-worker.js +52 -0
- package/src/assets/test.html +5 -2
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/app/app.component.ts
CHANGED
|
@@ -543,10 +543,13 @@ export class AppComponent implements OnInit {
|
|
|
543
543
|
this.statusBar.styleLightContent();
|
|
544
544
|
this.navService.init(this.sidebarNav, this.detailNav);
|
|
545
545
|
this.tiledeskAuthService.initialize(this.appConfigProvider.getConfig().apiUrl);
|
|
546
|
-
this.
|
|
547
|
-
|
|
546
|
+
this.tiledeskService.initialize(this.appConfigProvider.getConfig().apiUrl)
|
|
547
|
+
this.projectService.initialize(this.appConfigProvider.getConfig().apiUrl);
|
|
548
|
+
this.contactsService.initialize(this.appConfigProvider.getConfig().apiUrl)
|
|
549
|
+
|
|
548
550
|
// this.currentUserService.initialize();
|
|
549
551
|
this.chatManager.initialize();
|
|
552
|
+
this.messagingAuthService.initialize();
|
|
550
553
|
this.presenceService.initialize(this.tenant);
|
|
551
554
|
this.typingService.initialize(this.tenant);
|
|
552
555
|
|
|
@@ -1181,7 +1184,6 @@ export class AppComponent implements OnInit {
|
|
|
1181
1184
|
// this.logger.info('initialize FROM [APP-COMP] - [APP-COMP] - GO-ONLINE isOnline ', this.isOnline);
|
|
1182
1185
|
// clearTimeout(this.timeModalLogin);
|
|
1183
1186
|
const tiledeskToken = this.tiledeskAuthService.getTiledeskToken();
|
|
1184
|
-
const serverBaseURL = this.appConfigProvider.getConfig().apiUrl
|
|
1185
1187
|
// const supportmode = this.appConfigProvider.getConfig().supportMode;
|
|
1186
1188
|
// this.logger.log('[APP-COMP] - GO-ONLINE - supportmode ', supportmode);
|
|
1187
1189
|
// if (supportmode === true) {
|
|
@@ -1195,10 +1197,6 @@ export class AppComponent implements OnInit {
|
|
|
1195
1197
|
this.chatManager.setTiledeskToken(tiledeskToken);
|
|
1196
1198
|
this.chatManager.setCurrentUser(currentUser);
|
|
1197
1199
|
|
|
1198
|
-
this.tiledeskService.initialize(serverBaseURL)
|
|
1199
|
-
this.projectService.initialize(serverBaseURL)
|
|
1200
|
-
this.projectUsersService.initialize(serverBaseURL)
|
|
1201
|
-
this.contactsService.initialize(serverBaseURL)
|
|
1202
1200
|
// this.chatManager.startApp();
|
|
1203
1201
|
|
|
1204
1202
|
|
|
@@ -5,9 +5,9 @@ import { LoggerInstance } from 'src/chat21-core/providers/logger/loggerInstance'
|
|
|
5
5
|
interface Subscription {
|
|
6
6
|
topic: string;
|
|
7
7
|
label?: string;
|
|
8
|
-
onCreate?: (msg: any) => void;
|
|
9
|
-
onUpdate?: (msg: any) => void;
|
|
10
|
-
onData?: (msg: any) => void;
|
|
8
|
+
onCreate?: (msg: any, notification: any) => void;
|
|
9
|
+
onUpdate?: (msg: any, notification: any) => void;
|
|
10
|
+
onData?: (msg: any, notification: any) => void;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
@Injectable({
|
|
@@ -22,6 +22,14 @@ export class WebSocketJs {
|
|
|
22
22
|
constructor() {
|
|
23
23
|
this.worker = new Worker(new URL('./websocket.worker', import.meta.url));
|
|
24
24
|
|
|
25
|
+
// ➤ AGGIUNTA: notifica al worker quando la tab va in background
|
|
26
|
+
document.addEventListener("visibilitychange", () => {
|
|
27
|
+
this.worker.postMessage({
|
|
28
|
+
action: "visibility",
|
|
29
|
+
data: { hidden: document.hidden }
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
25
33
|
// ricezione dei messaggi dal worker
|
|
26
34
|
this.worker.onmessage = (event) => {
|
|
27
35
|
const msg = event.data;
|
|
@@ -30,28 +38,21 @@ export class WebSocketJs {
|
|
|
30
38
|
const sub = this.subscriptions.get(msg.topic);
|
|
31
39
|
if (!sub) return;
|
|
32
40
|
|
|
41
|
+
let object = { event: msg.payload, data: msg };
|
|
33
42
|
switch (msg.method) {
|
|
34
|
-
case 'CREATE': sub.onCreate?.(msg.payload); break;
|
|
35
|
-
case 'UPDATE': sub.onUpdate?.(msg.payload); break;
|
|
36
|
-
case 'DATA': sub.onData?.(msg.payload); break;
|
|
43
|
+
case 'CREATE': sub.onCreate?.(msg.payload, object); break;
|
|
44
|
+
case 'UPDATE': sub.onUpdate?.(msg.payload, object); break;
|
|
45
|
+
case 'DATA': sub.onData?.(msg.payload, object); break;
|
|
37
46
|
}
|
|
38
|
-
|
|
39
|
-
// ➤ AGGIUNTA: notifica al worker quando la tab va in background
|
|
40
|
-
document.addEventListener("visibilitychange", () => {
|
|
41
|
-
this.worker.postMessage({
|
|
42
|
-
action: "visibility",
|
|
43
|
-
data: { hidden: document.hidden }
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
init(url: string) {
|
|
51
51
|
this.worker.postMessage({ action: 'init', data: { url } });
|
|
52
|
+
this.worker.postMessage({ action: 'visibility', data: { hidden: document.hidden } });
|
|
52
53
|
}
|
|
53
54
|
|
|
54
|
-
ref(topic: string, calledby?: string, onCreate?: (msg:any)=>void, onUpdate?: (msg:any)=>void, onData?: (msg:any)=>void) {
|
|
55
|
+
ref(topic: string, calledby?: string, onCreate?: (msg:any, notification: any)=>void, onUpdate?: (msg:any, notification: any)=>void, onData?: (msg:any, notification: any)=>void) {
|
|
55
56
|
this.logger.log('[WEBSOCKET-JS] - REF - calledby ', calledby);
|
|
56
57
|
this.logger.log('[WEBSOCKET-JS] - REF - TOPIC ', topic);
|
|
57
58
|
|
|
@@ -154,7 +154,7 @@ function handleMessage(msg: WSMessage) {
|
|
|
154
154
|
// Notifica solo le subscription che matchano
|
|
155
155
|
subscriptions.forEach(sub => {
|
|
156
156
|
if (sub.topic === topic) {
|
|
157
|
-
postMessage({ topic, method, payload }, undefined);
|
|
157
|
+
postMessage({ topic, method, payload, msg }, undefined);
|
|
158
158
|
}
|
|
159
159
|
});
|
|
160
160
|
}
|
|
@@ -1010,6 +1010,7 @@ class Chat21Client {
|
|
|
1010
1010
|
this.start( () => {
|
|
1011
1011
|
// callback();
|
|
1012
1012
|
});
|
|
1013
|
+
this.initKeepAliveWorker()
|
|
1013
1014
|
}
|
|
1014
1015
|
this.client.publish(
|
|
1015
1016
|
this.presence_topic,
|
|
@@ -1027,6 +1028,34 @@ class Chat21Client {
|
|
|
1027
1028
|
console.error("Chat client error event", error);
|
|
1028
1029
|
}
|
|
1029
1030
|
);
|
|
1031
|
+
|
|
1032
|
+
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
|
|
1036
|
+
initKeepAliveWorker(){
|
|
1037
|
+
this.worker= new Worker('assets/js/mqtt-keepalive-worker.js');
|
|
1038
|
+
console.log("Chat21Client - initKeepAliveWorker() - worker created", this.worker);
|
|
1039
|
+
// this.worker.postMessage({
|
|
1040
|
+
// action: 'start',
|
|
1041
|
+
// user_id: this.user_id,
|
|
1042
|
+
// client_id: this.client_id,
|
|
1043
|
+
// jwt: this.jwt,
|
|
1044
|
+
// endpoint: this.endpoint
|
|
1045
|
+
// });
|
|
1046
|
+
this.worker.onmessage = (event) => {
|
|
1047
|
+
if (event.data.action === 'ping') {
|
|
1048
|
+
if (this.client && this.client.connected) {
|
|
1049
|
+
// questo non causa refresh di niente
|
|
1050
|
+
this.client.publish(
|
|
1051
|
+
`apps/tilechat/users/${this.user_id}/keepalive`,
|
|
1052
|
+
JSON.stringify({ ts: Date.now() })
|
|
1053
|
+
);
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
};
|
|
1057
|
+
|
|
1058
|
+
this.worker.postMessage({ action: 'ping' });
|
|
1030
1059
|
}
|
|
1031
1060
|
|
|
1032
1061
|
onDisconnect(callback){
|
|
@@ -1041,6 +1070,11 @@ class Chat21Client {
|
|
|
1041
1070
|
this.connected = false
|
|
1042
1071
|
if (this.log) {console.log("Chat client close event");}
|
|
1043
1072
|
callback('close')
|
|
1073
|
+
if (this.worker) {
|
|
1074
|
+
this.worker.postMessage({ action: 'stop' });
|
|
1075
|
+
this.worker.terminate();
|
|
1076
|
+
this.worker = null;
|
|
1077
|
+
}
|
|
1044
1078
|
}
|
|
1045
1079
|
);
|
|
1046
1080
|
this.client.on('offline',
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
importScripts('https://unpkg.com/mqtt/dist/mqtt.min.js');
|
|
2
|
+
|
|
3
|
+
let client = null;
|
|
4
|
+
let user_id = null;
|
|
5
|
+
let pingIntervalId = null;
|
|
6
|
+
self.onmessage = function(event) {
|
|
7
|
+
const data = event.data;
|
|
8
|
+
|
|
9
|
+
console.log('MQTT KEEPALIVE WORKER - received message ', data);
|
|
10
|
+
if (data.action === 'start') {
|
|
11
|
+
user_id = data.user_id;
|
|
12
|
+
const endpoint = data.endpoint;
|
|
13
|
+
const jwt = data.jwt;
|
|
14
|
+
|
|
15
|
+
const options = {
|
|
16
|
+
keepalive: 3, // basso keepalive
|
|
17
|
+
reconnectPeriod: 1000,
|
|
18
|
+
clientId: data.client_id,
|
|
19
|
+
username: 'JWT',
|
|
20
|
+
password: jwt,
|
|
21
|
+
rejectUnauthorized: false
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
client = mqtt.connect(endpoint, options);
|
|
25
|
+
|
|
26
|
+
client.on('connect', () => {
|
|
27
|
+
// start ping
|
|
28
|
+
pingIntervalId = setInterval(() => {
|
|
29
|
+
if (client && client.connected) {
|
|
30
|
+
console.log('MQTT KEEPALIVE WORKER - sending keepalive ping for user ', user_id);
|
|
31
|
+
client.publish(`apps/tilechat/users/${user_id}/keepalive`,
|
|
32
|
+
JSON.stringify({ ts: new Date().getTime() }));
|
|
33
|
+
}
|
|
34
|
+
}, 3000);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
client.on('close', () => {
|
|
38
|
+
clearInterval(pingIntervalId);
|
|
39
|
+
pingIntervalId = null;
|
|
40
|
+
});
|
|
41
|
+
}else if (data.action === 'ping') {
|
|
42
|
+
if (self.timer) return;
|
|
43
|
+
self.timer = setInterval(() => {
|
|
44
|
+
postMessage({ action: 'ping' });
|
|
45
|
+
}, 3000);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (data.action === 'stop') {
|
|
49
|
+
if (pingIntervalId) clearInterval(pingIntervalId);
|
|
50
|
+
if (client) client.end();
|
|
51
|
+
}
|
|
52
|
+
};
|
package/src/assets/test.html
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<head>
|
|
5
5
|
<meta charset="utf-8">
|
|
6
6
|
<meta name="viewport" content="width=device-width">
|
|
7
|
-
<title>
|
|
7
|
+
<title>Iframe test</title>
|
|
8
8
|
</head>
|
|
9
9
|
|
|
10
10
|
<body style="height: 100%;">
|
|
@@ -20,7 +20,10 @@
|
|
|
20
20
|
</div>
|
|
21
21
|
|
|
22
22
|
<iframe id="myIFrame" frameBorder="0" width="100%" style="display: flex; height: 95vh" onload="onLoad()"
|
|
23
|
-
|
|
23
|
+
src="http://localhost:8080/#/conversation-detail?tiledesk_supportMode=true&jwt=JWT eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2NWM1ZjM1OTlmYWYyZDA0Y2Q3ZGE1MjgiLCJlbWFpbCI6Imdpb3Zhbm5pQHRpbGVkZXNrLmNvbSIsImZpcnN0bmFtZSI6Ikdpb3Zhbm5pIiwibGFzdG5hbWUiOiJUcm9pc2kgQWRtIiwiZW1haWx2ZXJpZmllZCI6dHJ1ZSwiaWF0IjoxNzY0NjAyMTQxLCJhdWQiOiJodHRwczovL3RpbGVkZXNrLmNvbSIsImlzcyI6Imh0dHBzOi8vdGlsZWRlc2suY29tIiwic3ViIjoidXNlciIsImp0aSI6IjIwNzZjYmMxLTI0NzgtNGU4MC1iZjFmLTBiZTA3MTQ3MjQ3MSJ9.R60xZC5M2n-hc-mRIMpA9KaUFxnBQHA_FrLyL9cCiqxeCitfCfbfA3_EKXWbWg3rDztmOR7SVjEO8Gyw_hdhKyjpx-OpaDAILw0dSsuBHB0R4h0F4fN2J_JJ60UIItXxoAq1AI9ML2cRGoRNAtfl6PMjpHXdbpdBAGcBYoGqGv3xWPlM7wOdIhGasnWT932DiscF3I_ltcFkS3naebQQfsgztlbU-UF7EcFjDc-mMzMxqnE1MYKzyqUAR9J9zFmqiUlCsl_J0TNhAjqUw-0GHXpzLQJN9dutVyH4y_MZxt_p6qAIzNo9LpMi-a5bfvQvpJjSuc9POvmlmWFAmwoQGw"
|
|
24
|
+
allow="autoplay; fullscreen; geolocation; microphone; camera; display-capture; encrypted-media; clipboard-read; clipboard-write;"
|
|
25
|
+
loading="eager" importance="high">
|
|
26
|
+
</iframe>
|
|
24
27
|
|
|
25
28
|
<script>
|
|
26
29
|
// window.addEventListener('message', event => {
|