@chat21/chat21-ionic 3.0.55 → 3.0.59-rc10

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 (96) hide show
  1. package/CHANGELOG.md +65 -0
  2. package/README.md +4 -0
  3. package/config.xml +11 -2
  4. package/env.sample +2 -0
  5. package/package.json +1 -1
  6. package/resources/Android/splash/drawable-land-hdpi-screen.png +0 -0
  7. package/resources/Android/splash/drawable-land-ldpi-screen.png +0 -0
  8. package/resources/Android/splash/drawable-land-mdpi-screen.png +0 -0
  9. package/resources/Android/splash/drawable-land-xhdpi-screen.png +0 -0
  10. package/resources/Android/splash/drawable-land-xxhdpi-screen.png +0 -0
  11. package/resources/Android/splash/drawable-land-xxxhdpi-screen.png +0 -0
  12. package/resources/Android/splash/drawable-port-hdpi-screen.png +0 -0
  13. package/resources/Android/splash/drawable-port-ldpi-screen.png +0 -0
  14. package/resources/Android/splash/drawable-port-mdpi-screen.png +0 -0
  15. package/resources/Android/splash/drawable-port-xhdpi-screen.png +0 -0
  16. package/resources/Android/splash/drawable-port-xxhdpi-screen.png +0 -0
  17. package/resources/Android/splash/drawable-port-xxxhdpi-screen.png +0 -0
  18. package/resources/Android/splash.png +0 -0
  19. package/src/app/app-routing.module.ts +21 -17
  20. package/src/app/app.component.html +6 -3
  21. package/src/app/app.component.ts +323 -185
  22. package/src/app/app.module.ts +16 -8
  23. package/src/app/chatlib/conversation-detail/ion-conversation-detail/ion-conversation-detail.component.html +4 -4
  24. package/src/app/chatlib/conversation-detail/ion-conversation-detail/ion-conversation-detail.component.scss +8 -2
  25. package/src/app/chatlib/conversation-detail/ion-conversation-detail/ion-conversation-detail.component.ts +6 -1
  26. package/src/app/chatlib/conversation-detail/message/bubble-message/bubble-message.component.html +7 -2
  27. package/src/app/chatlib/conversation-detail/message/bubble-message/bubble-message.component.ts +48 -3
  28. package/src/app/chatlib/conversation-detail/message/image/image.component.html +7 -6
  29. package/src/app/chatlib/conversation-detail/message/image/image.component.ts +20 -1
  30. package/src/app/chatlib/list-conversations-component/ion-list-conversations/ion-list-conversations.component.html +39 -9
  31. package/src/app/chatlib/list-conversations-component/ion-list-conversations/ion-list-conversations.component.scss +8 -144
  32. package/src/app/chatlib/list-conversations-component/ion-list-conversations/ion-list-conversations.component.ts +14 -17
  33. package/src/app/components/authentication/login/login.component.html +2 -2
  34. package/src/app/components/authentication/login/login.component.ts +2 -1
  35. package/src/app/components/conversation-detail/bubble-my-message/bubble-my-message.component.ts +1 -1
  36. package/src/app/components/conversation-detail/bubble-others-message/bubble-others-message.component.ts +1 -1
  37. package/src/app/components/conversation-detail/header-conversation-detail/header-conversation-detail.component.html +17 -12
  38. package/src/app/components/conversation-detail/header-conversation-detail/header-conversation-detail.component.scss +12 -0
  39. package/src/app/components/conversation-detail/header-conversation-detail/header-conversation-detail.component.ts +21 -5
  40. package/src/app/components/conversation-detail/message-text-area/message-text-area.component.html +3 -2
  41. package/src/app/components/conversation-detail/message-text-area/message-text-area.component.scss +22 -17
  42. package/src/app/components/conversation-detail/message-text-area/message-text-area.component.ts +46 -5
  43. package/src/app/components/ddp-header/ddp-header.component.html +1 -1
  44. package/src/app/components/ddp-header/ddp-header.component.ts +4 -2
  45. package/src/app/components/image-viewer/image-viewer.component.html +23 -0
  46. package/src/app/components/image-viewer/image-viewer.component.scss +107 -0
  47. package/src/app/components/image-viewer/image-viewer.component.spec.ts +24 -0
  48. package/src/app/components/image-viewer/image-viewer.component.ts +38 -0
  49. package/src/app/components/project-item/project-item.component.html +147 -0
  50. package/src/app/components/project-item/project-item.component.scss +669 -0
  51. package/src/app/components/project-item/project-item.component.spec.ts +24 -0
  52. package/src/app/components/project-item/project-item.component.ts +316 -0
  53. package/src/app/components/utils/avatar-profile/avatar-profile.component.html +7 -0
  54. package/src/app/components/utils/avatar-profile/avatar-profile.component.ts +22 -5
  55. package/src/app/pages/authentication/login/login.page.ts +2 -2
  56. package/src/app/pages/conversation-detail/conversation-detail.page.html +5 -3
  57. package/src/app/pages/conversation-detail/conversation-detail.page.ts +122 -30
  58. package/src/app/pages/conversations-list/conversations-list.page.html +40 -24
  59. package/src/app/pages/conversations-list/conversations-list.page.scss +146 -1
  60. package/src/app/pages/conversations-list/conversations-list.page.ts +87 -6
  61. package/src/app/pages/unassigned-conversations/unassigned-conversations-routing.module.ts +17 -0
  62. package/src/app/pages/unassigned-conversations/unassigned-conversations.module.ts +22 -0
  63. package/src/app/pages/unassigned-conversations/unassigned-conversations.page.html +22 -0
  64. package/src/app/pages/unassigned-conversations/unassigned-conversations.page.scss +79 -0
  65. package/src/app/pages/unassigned-conversations/unassigned-conversations.page.spec.ts +24 -0
  66. package/src/app/pages/unassigned-conversations/unassigned-conversations.page.ts +108 -0
  67. package/src/app/services/nav-proxy.service.ts +1 -1
  68. package/src/app/services/tiledesk/tiledesk.service.ts +22 -1
  69. package/src/app/services/websocket/websocket-js.ts +559 -0
  70. package/src/app/services/websocket/websocket.service.spec.ts +12 -0
  71. package/src/app/services/websocket/websocket.service.ts +274 -0
  72. package/src/app/shared/shared.module.ts +7 -1
  73. package/src/assets/i18n/en.json +9 -1
  74. package/src/assets/i18n/it.json +10 -2
  75. package/src/assets/js/chat21client.js +141 -67
  76. package/src/assets/transparent.png +0 -0
  77. package/src/chat-config-pre-test.json +4 -2
  78. package/src/chat-config-template.json +3 -1
  79. package/src/chat-config.json +3 -1
  80. package/src/chat21-core/providers/abstract/app-storage.service.ts +2 -2
  81. package/src/chat21-core/providers/chat-manager.ts +3 -3
  82. package/src/chat21-core/providers/firebase/firebase-archivedconversations-handler.ts +1 -1
  83. package/src/chat21-core/providers/firebase/firebase-auth-service.ts +125 -79
  84. package/src/chat21-core/providers/firebase/firebase-conversation-handler.ts +1 -1
  85. package/src/chat21-core/providers/firebase/firebase-notifications.ts +11 -17
  86. package/src/chat21-core/providers/firebase/firebase-presence.service.ts +2 -2
  87. package/src/chat21-core/providers/firebase/firebase-typing.service.ts +1 -1
  88. package/src/chat21-core/providers/firebase/firebase-upload.service.ts +1 -1
  89. package/src/chat21-core/providers/localSessionStorage.ts +155 -154
  90. package/src/chat21-core/providers/mqtt/mqtt-auth-service.ts +27 -27
  91. package/src/chat21-core/providers/mqtt/mqtt-conversations-handler.ts +13 -5
  92. package/src/chat21-core/providers/mqtt/mqtt-notifications.ts +101 -11
  93. package/src/chat21-core/providers/tiledesk/tiledesk-auth.service.ts +1 -1
  94. package/src/chat21-core/utils/utils.ts +1 -1
  95. package/src/global.scss +2 -7
  96. package/src/index.html +1 -1
@@ -0,0 +1,559 @@
1
+
2
+ //import { Injectable } from '@angular/core';
3
+ import { forwardRef, Inject } from '@angular/core';
4
+
5
+ import { LoggerService } from 'src/chat21-core/providers/abstract/logger.service';
6
+ import { LoggerInstance } from 'src/chat21-core/providers/logger/loggerInstance';
7
+ //@Injectable()
8
+ export class WebSocketJs {
9
+
10
+ public url;
11
+ public onCreate;
12
+ public onUpdate;
13
+ public onOpen;
14
+ public onData;
15
+ public ws;
16
+ public topics;
17
+ public callbacks;
18
+ public readyState: number;
19
+ // public userHasClosed: boolean;
20
+
21
+ // HEARTBEAT https://github.com/zimv/websocket-heartbeat-js/blob/master/lib/index.js
22
+ private pingTimeoutId;
23
+ private pongTimeoutId;
24
+
25
+ public pingMsg = { action: "heartbeat", payload: { message: { text: "ping" } } }
26
+
27
+ public pongMsg = { action: "heartbeat", payload: { message: { text: "pong" } } }
28
+
29
+
30
+ public pongTimeout = 10000;
31
+ public pingTimeout = 15000;
32
+
33
+ // nktest
34
+ // startTimeMS = 0;
35
+
36
+ private logger: LoggerService = LoggerInstance.getInstance();
37
+
38
+ constructor() {
39
+
40
+ // this.logger.log("[WEBSOCKET-JS] HELLO !!!");
41
+ this.topics = [];
42
+ this.callbacks = new Map();
43
+
44
+ // this.sendingMessages = [];//new Map();
45
+ }
46
+
47
+
48
+ /**
49
+ * readyState: A read-only attribute. It represents the state of the connection. It can have the following values:
50
+ * 0: Connection is in progress and has not yet been established.
51
+ * 1: Connection is established and messages can be sent between the client and the server.
52
+ * 2: Connection is going through the closing handshake.
53
+ * 3: Connection has been closed or could not be opened.
54
+ */
55
+
56
+ // -----------------------------------------------------------------------------------------------------
57
+ // @ ref - called by 'WsRequestsService' and 'WsMsgsService' & call 'subscribe'
58
+ // -----------------------------------------------------------------------------------------------------
59
+ // WsRequestsService:
60
+ // - in getCurrentProjectAndSubscribeTo_WsRequests()
61
+ // - in subscribeTo_wsRequestById() called when in
62
+ // WsRequestsMsgsComponent onInit() is got the request id from url params
63
+ // WsMsgsService
64
+ // - in subsToWS_MsgsByRequestId() called when in
65
+ // WsRequestsMsgsComponent onInit() is got the request id from url params
66
+
67
+ ref(topic, calledby, onCreate, onUpdate, onData) {
68
+ // this.logger.log('[WEBSOCKET-JS] ****** CALLING REF ****** ');
69
+ this.logger.log('[WEBSOCKET-JS] - REF - calledby ', calledby);
70
+ this.logger.log('[WEBSOCKET-JS] - REF - TOPIC ', topic);
71
+ this.logger.log('[WEBSOCKET-JS] - REF - CALLBACKS', this.callbacks);
72
+
73
+ if (!this.callbacks) {
74
+ this.logger.log('[WEBSOCKET-JS] - REF OOOOPS! NOT CALLBACKS ***', this.callbacks);
75
+ return
76
+ }
77
+
78
+ this.callbacks.set(topic, { onCreate: onCreate, onUpdate: onUpdate, onData: onData });
79
+ this.logger.log('[WEBSOCKET-JS] - CALLBACK-SET - callbacks', this.callbacks);
80
+
81
+ this.logger.log('[WEBSOCKET-JS] - REF - READY STATE ', this.ws.readyState);
82
+
83
+ if (this.ws && this.ws.readyState == 1) {
84
+
85
+ this.logger.log('[WEBSOCKET-JS] - REF - READY STATE = 1 > SUBSCRIBE TO TOPICS ');
86
+
87
+ this.subscribe(topic);
88
+
89
+ } else {
90
+ // this.ws = new WebSocket("wss://tiledesk-server-pre.herokuapp.com/?token=JWT eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1ZGRkMzBiZmYwMTk1ZjAwMTdmNzJjNmQiLCJlbWFpbCI6InByZWdpbm9AZjIxdGVzdC5pdCIsImZpcnN0bmFtZSI6Ikdpbm8iLCJsYXN0bmFtZSI6IlByZSIsImVtYWlsdmVyaWZpZWQiOnRydWUsImlhdCI6MTYwODgwNjY0MCwiYXVkIjoiaHR0cHM6Ly90aWxlZGVzay5jb20iLCJpc3MiOiJodHRwczovL3RpbGVkZXNrLmNvbSIsInN1YiI6InVzZXIiLCJqdGkiOiI1YmVmMDcxYy00ODBlLTQzYzQtOTRhYS05ZjQxYzMyNDcxMGQifQ.wv6uBn2P6H9wGb5WCYQkpPEScMU9PB1pBUzFouhJk20");
91
+
92
+ this.logger.log('[WEBSOCKET-JS] - REF - READY STATE ≠ 1 > OPEN WS AND THEN SUBSCRIBE TO TOPICS');
93
+ // this.logger.log('% »»» WebSocketJs WF *** REF *** WS 2 ', this.ws);
94
+
95
+ var that = this;
96
+ if (this.ws) {
97
+ this.ws.addEventListener("open", function (event) {
98
+ that.logger.log('[WEBSOCKET-JS] - REF - OPEN EVENT *** ', event);
99
+ that.subscribe(topic);
100
+ });
101
+ }
102
+
103
+ if (this.topics.indexOf(topic) === -1) {
104
+ this.topics.push(topic);
105
+ }
106
+ }
107
+ }
108
+
109
+ // -----------------------------------------------------------------------------------------------------
110
+ // @ subscribe - is called by 'ref' & call 'send'
111
+ // -----------------------------------------------------------------------------------------------------
112
+ subscribe(topic) {
113
+
114
+ if (this.topics.indexOf(topic) === -1) {
115
+ this.topics.push(topic);
116
+ }
117
+ this.logger.log('[WEBSOCKET-JS] - SUBSCRIBE TO TOPIC ', topic);
118
+
119
+ var message = {
120
+ action: 'subscribe',
121
+ payload: {
122
+ //topic: '/' + project_id + '/requests',
123
+ topic: topic,
124
+ message: undefined,
125
+ method: undefined
126
+ },
127
+ };
128
+ var str = JSON.stringify(message);
129
+ this.logger.log("[WEBSOCKET-JS] - SUBSCRIBE TO TOPIC - STRING TO SEND " + str, " FOR SUBSCRIBE TO TOPIC: ", topic);
130
+
131
+ this.send(str, `SUBSCRIBE to ${topic}`);
132
+ }
133
+
134
+ // -----------------------------------------------------------------------------------------------------
135
+ // @ unsubscribe
136
+ // - called by: 'WsRequestsService' > getCurrentProjectAndSubscribeTo_WsRequests()
137
+ // > unsubscribeTo_wsRequestById() called by WsRequestsMsgsComponent > On Init & On Destroy
138
+ // 'WsMsgsService' > unsubsToWS_MsgsByRequestId() > On Init & On Destroy
139
+ // - call 'send'
140
+ // -----------------------------------------------------------------------------------------------------
141
+ unsubscribe(topic) {
142
+ this.logger.log("[WEBSOCKET-JS] - UN-SUBSCRIBE - FROM TOPIC: ", topic);
143
+ // this.logger.log("% »»» WebSocketJs WF *** UNSUBSCRIBE *** - this.topics ", this.topics);
144
+ // this.logger.log("% »»» WebSocketJs WF *** UNSUBSCRIBE *** - topic ", topic);
145
+ // this.logger.log("% »»» WebSocketJs WF *** UNSUBSCRIBE *** - callbacks ", this.callbacks);
146
+
147
+
148
+ var index = this.topics.indexOf(topic);
149
+
150
+ if (index > -1) {
151
+ this.topics.splice(index, 1);
152
+ }
153
+
154
+ this.logger.log("[WEBSOCKET-JS] - UN-SUBSCRIBE - TOPICS AFTER SPLICE THE TOPIC ", this.topics);
155
+ this.logger.log("[WEBSOCKET-JS] - UN-SUBSCRIBE - DELETE TOPIC FROM CALLBACKS - CALLBACKS SIZE ", this.callbacks.size);
156
+
157
+ // if (this.callbacks.length > 0) {
158
+ if (this.callbacks.size > 0) {
159
+ this.callbacks.delete(topic);
160
+ this.logger.log("[WEBSOCKET-JS] - UN-SUBSCRIBE - CALLBACKS AFTER DELETE TOPIC ", this.callbacks);
161
+ }
162
+
163
+ var message = {
164
+ action: 'unsubscribe',
165
+ payload: {
166
+ //topic: '/' + project_id + '/requests',
167
+ topic: topic,
168
+ message: undefined,
169
+ method: undefined
170
+ },
171
+ };
172
+ var str = JSON.stringify(message);
173
+ this.logger.log("[WEBSOCKET-JS] - UN-SUBSCRIBE str " + str);
174
+
175
+ if (this.ws.readyState == 1) {
176
+ this.logger.log("[WEBSOCKET-JS] - UN-SUBSCRIBE TO TOPIC - STRING TO SEND " + str, " FOR UNSUBSCRIBE TO TOPIC: ", topic);
177
+ this.send(str, `UNSUSCRIBE from ${topic}`);
178
+
179
+ } else {
180
+ this.logger.log("[WEBSOCKET-JS] - UN-SUBSCRIBE TRY 'SEND' BUT READY STASTE IS : ", this.ws.readyState);
181
+ }
182
+ }
183
+
184
+ // -----------------------------------------------------------------------------------------------------
185
+ // @ send -
186
+ // -----------------------------------------------------------------------------------------------------
187
+ send(initialMessage, calling_method) {
188
+ // this.logger.log("[WEBSOCKET-JS] - SEND - INIZIAL-MSG ", initialMessage, " CALLED BY ", calling_method);
189
+
190
+ this.ws.send(initialMessage);
191
+ }
192
+
193
+
194
+ // -----------------------------------------------------------------------------------------------------
195
+ // @ close (to find where is used search for x webSocketClose())
196
+ // -----------------------------------------------------------------------------------------------------
197
+ close() {
198
+ this.topics = [];
199
+ this.callbacks = [];
200
+ this.logger.log("[WEBSOCKET-JS] - CALLED CLOSE - TOPICS ", this.topics, ' - CALLLBACKS ', this.callbacks);
201
+
202
+ if (this.ws) {
203
+ this.ws.onclose = function () { }; // disable onclose handler first
204
+ this.ws.close();
205
+ }
206
+ this.heartReset();
207
+ }
208
+
209
+ // -----------------------------------------------------------------------------------------------------
210
+ // @ Resubscribe
211
+ // -----------------------------------------------------------------------------------------------------
212
+ resubscribe() {
213
+ this.logger.log("[WEBSOCKET-JS] - RESUBSCRIBE - TO TOPICS ", this.topics);
214
+ this.logger.log("[WEBSOCKET-JS] - RESUBSCRIBE - CALLBACKS ", this.callbacks);
215
+
216
+ if (this.topics.length > 0) {
217
+ this.topics.forEach(topic => {
218
+ this.logger.log("[WEBSOCKET-JS] - RESUBSCRIBE - SUBDCRIBE TO TOPICS ", topic);
219
+ this.subscribe(topic); // nn fa sudbcribe
220
+ });
221
+ }
222
+ }
223
+
224
+ // -----------------------------------------------------------------------------------------------------
225
+ // @ HeartCheck
226
+ // -----------------------------------------------------------------------------------------------------
227
+ heartCheck() {
228
+ this.heartReset();
229
+ this.heartStart();
230
+ }
231
+
232
+ // _heartStart() {
233
+ // // if(this.forbidReconnect) return;//Non ricollegare o eseguire il battito cardiaco
234
+ // this.pingTimeoutId = setTimeout(() => {
235
+ // // Qui viene inviato un battito cardiaco Dopo averlo ricevuto, viene restituito un messaggio di battito cardiaco.
236
+ // // onmessage Ottieni il battito cardiaco restituito per indicare che la connessione è normale
237
+ // try {
238
+ // this.logger.log('% »»» WebSocketJs - HEARTBEAT send MSG ', JSON.stringify(this.pingMsg));
239
+ // this.ws.send(JSON.stringify(this.pingMsg));
240
+ // // Se non viene ripristinato dopo un determinato periodo di tempo, il backend viene attivamente disconnesso
241
+ // this.pongTimeoutId = setTimeout(() => {
242
+ // // se onclose Si esibirà reconnect,Eseguiamo ws.close() Bene, se lo esegui direttamente reconnect Si innescherà onclose Causa riconnessione due volte
243
+ // this.ws.close();
244
+ // }, this.pongTimeout);
245
+
246
+ // } catch (e) {
247
+
248
+ // this.logger.log('% »»» WebSocketJs - HEARTBEAT err ', e);
249
+ // }
250
+
251
+ // }, this.pingTimeout);
252
+ // }
253
+
254
+
255
+ // getRemainingTime() {
256
+ // var milliSecondsTime = 15000;
257
+ // var timer;
258
+
259
+ // this.logger.log('% »»» WebSocketJs - heartStart timer 1', milliSecondsTime / 1000);
260
+ // timer = setInterval(function () {
261
+ // milliSecondsTime = milliSecondsTime - 1000;
262
+ // if (milliSecondsTime / 1000 == 0) {
263
+ // clearTimeout(timer);
264
+ // }
265
+ // else {
266
+ // this.logger.log('% »»» WebSocketJs - heartStart timer 2 ', milliSecondsTime / 1000);
267
+ // }
268
+ // }, 1000);
269
+ // }
270
+
271
+ // -----------------------------------------------------------------------------------------------------
272
+ // @ HeartStart
273
+ // -----------------------------------------------------------------------------------------------------
274
+ heartStart() {
275
+ // this.getRemainingTime();
276
+ this.pingTimeoutId = setTimeout(() => {
277
+
278
+ // Qui viene inviato un battito cardiaco Dopo averlo ricevuto, viene restituito un messaggio di battito cardiaco.
279
+ // onmessage Ottieni il battito cardiaco restituito per indicare che la connessione è normale
280
+ if (this.ws.readyState == 1) {
281
+
282
+ // this.logger.log("[WEBSOCKET-JS] - HEART-START - SEND PING-MSG");
283
+
284
+ this.send(JSON.stringify(this.pingMsg), 'HEART-START')
285
+
286
+ } else {
287
+
288
+ this.logger.log("[WEBSOCKET-JS] - HEART-START - TRY TO SEND PING-MSG BUT READY STATE IS ", this.ws.readyState);
289
+
290
+ }
291
+
292
+ // Se non viene ripristinato dopo un determinato periodo di tempo, il backend viene attivamente disconnesso
293
+ this.pongTimeoutId = setTimeout(() => {
294
+ this.logger.log("[WEBSOCKET-JS] - HEART-START - PONG-TIMEOUT-ID - CLOSE WS ");
295
+ // se onclose Si esibirà reconnect,Eseguiamo ws.close() Bene, se lo esegui direttamente reconnect Si innescherà onclose Causa riconnessione due volte
296
+ this.ws.close();
297
+ }, this.pongTimeout);
298
+
299
+ }, this.pingTimeout);
300
+ }
301
+
302
+ // -----------------------------------------------------------------------------------------------------
303
+ // @ heartReset
304
+ // -----------------------------------------------------------------------------------------------------
305
+ heartReset() {
306
+ // this.logger.log("[WEBSOCKET-JS] - HEART-RESET");
307
+ clearTimeout(this.pingTimeoutId);
308
+ clearTimeout(this.pongTimeoutId);
309
+ }
310
+
311
+ // -----------------------------------------------------------------------------------------------------
312
+ // @ init
313
+ // -----------------------------------------------------------------------------------------------------
314
+ init(url, onCreate, onUpdate, onData, onOpen = undefined, onOpenCallback = undefined, _topics = [], _callbacks = new Map()) {
315
+
316
+
317
+
318
+ this.url = url;
319
+ this.onCreate = onCreate;
320
+ this.onUpdate = onUpdate;
321
+ this.onData = onData;
322
+ this.onOpen = onOpen;
323
+ this.topics = _topics//[];//new Map();
324
+ this.callbacks = _callbacks// new Map();
325
+ // this.userHasClosed = false;
326
+ // this.logger.log('% »»» WebSocketJs WF - closeWebsocket this.userHasClosed ' , this.userHasClosed);
327
+
328
+ // this.sendingMessages = [];//new Map();
329
+ // this.data = [];
330
+ // this.init(this.sendMesagesInSendingArray);
331
+
332
+ this.logger.log("[WEBSOCKET-JS] - CALLING INIT - topics ", this.topics);
333
+ this.logger.log("[WEBSOCKET-JS] - CALLING INIT - url ", this.url);
334
+ this.logger.log("[WEBSOCKET-JS] - CALLING INIT - callbacks ", this.callbacks);
335
+
336
+
337
+ var that = this;
338
+ return new Promise(function (resolve, reject) {
339
+ // var options = {
340
+ // // headers: {
341
+ // // "Authorization" : "JWT " + token
342
+ // // }
343
+ // };
344
+ // this.logger.log('options', options);
345
+ // var ws = new WebSocket('ws://localhost:3000');
346
+ // var ws = new WebSocket('ws://localhost:3000/public/requests');
347
+ // var ws = new WebSocket('ws://localhost:3000/5bae41325f03b900401e39e8/messages');
348
+
349
+
350
+ // -----------------------------------------------------------------------------------------------------
351
+ // @ new WebSocket
352
+ // -----------------------------------------------------------------------------------------------------
353
+ that.ws = new WebSocket(that.url);
354
+
355
+
356
+ // -----------------------------------------------------------------------------------------------------
357
+ // @ onopen
358
+ // -----------------------------------------------------------------------------------------------------
359
+ that.ws.onopen = function (e) {
360
+ that.logger.log('[WEBSOCKET-JS] - websocket is connected ...', e);
361
+
362
+ // -----------------
363
+ // @ heartCheck
364
+ // -----------------
365
+ that.heartCheck();
366
+
367
+
368
+ if (onOpenCallback) {
369
+ onOpenCallback();
370
+ }
371
+
372
+ if (that.onOpen) {
373
+ that.onOpen();
374
+ }
375
+
376
+ }
377
+
378
+ // -----------------------------------------------------------------------------------------------------
379
+ // @ onclose
380
+ // -----------------------------------------------------------------------------------------------------
381
+ that.ws.onclose = function (e) {
382
+ that.logger.log('[WEBSOCKET-JS] websocket IS CLOSED ... Try to reconnect in 3 seconds ', e);
383
+
384
+ // this.logger.log('% »»» WebSocketJs - websocket onclose this.userHasClosed ', that.userHasClosed);
385
+ // https://stackoverflow.com/questions/3780511/reconnection-of-client-when-server-reboots-in-websocket
386
+ // Try to reconnect in 3 seconds
387
+
388
+ // --------------------
389
+ // @ init > resubscribe
390
+ // --------------------
391
+
392
+ setTimeout(function () {
393
+ that.init(url, onCreate, onUpdate, onData, onOpen, function () {
394
+ that.logger.log('[WEBSOCKET-JS] websocket IS CLOSED ... CALLING RESUSCRIBE ');
395
+ that.resubscribe();
396
+ }, that.topics, that.callbacks);
397
+ }, 3000);
398
+ }
399
+
400
+ // -----------------------------------------------------------------------------------------------------
401
+ // @ onerror
402
+ // -----------------------------------------------------------------------------------------------------
403
+ that.ws.onerror = function (err) {
404
+ that.logger.error('[WEBSOCKET-JS] websocket IS CLOSED - websocket error ...', err)
405
+ }
406
+
407
+ // -----------------------------------------------------------------------------------------------------
408
+ // @ onmessage
409
+ // -----------------------------------------------------------------------------------------------------
410
+ that.ws.onmessage = function (message) {
411
+ // that.logger.log('[WEBSOCKET-JS] websocket onmessage ', message);
412
+ // that.logger.log('[WEBSOCKET-JS] websocket onmessage data', message.data);
413
+
414
+ // let test = '{ "action": "publish","payload": {"topic": "/5df26badde7e1c001743b63c/requests", "method": "CREATE", "message": [ { "_id": "5f29372d690e6f0034edf100", "status": 200, "preflight": false, "hasBot": true, "participants": ["bot_5df272e8de7e1c001743b645"], "participantsAgents": [], "participantsBots": ["5df272e8de7e1c001743b645"], "request_id": "support-group-MDszsSJlwqQn1_WCh6u", "requester": "5f29371b690e6f0034edf0f5", "lead": "5f29372d690e6f0034edf0ff", "first_text": "ocourse the email is valid ","department": "5df26badde7e1c001743b63e", "agents": [{"user_available": true,"online_status": "online", "number_assigned_requests": 35, "_id": "5e0f2119705a35001725714d","id_project": "5df26badde7e1c001743b63c", "id_user": "5aaa99024c3b110014b478f0", "role": "admin", "createdBy": "5df26ba1de7e1c001743b637","createdAt": "2020-01-03T11:10:17.123Z", "updatedAt": "2020-01-03T11:10:17.123Z", "__v": 0 }, { "user_available": false, "online_status": "offline", "number_assigned_requests": 0, "_id": "5e1a13824437eb0017f712b4", "id_project": "5df26badde7e1c001743b63c","id_user": "5ac7521787f6b50014e0b592", "role": "admin", "createdBy": "5df26ba1de7e1c001743b637", "createdAt": "2020-01-11T18:27:14.657Z","updatedAt": "2020-01-11T18:27:14.657Z", "__v": 0}, { "user_available": false,"online_status": "offline", "number_assigned_requests": 0, "_id": "5df26bdfde7e1c001743b640", "id_project": "5df26badde7e1c001743b63c", "id_user": "5de9200d6722370017731969","role": "admin","createdBy": "5df26ba1de7e1c001743b637", "createdAt": "2019-12-12T16:33:35.244Z", "updatedAt": "2019-12-12T16:33:35.244Z","__v": 0 }, {"user_available": true, "online_status": "online","number_assigned_requests": -11, "_id": "5eb1a3647ac005003480f54d", "id_project": "5df26badde7e1c001743b63c","id_user": "5e09d16d4d36110017506d7f","role": "owner", "createdBy": "5aaa99024c3b110014b478f0","createdAt": "2020-05-05T17:33:24.328Z", "updatedAt": "2020-05-05T17:33:24.328Z","__v": 0}], "sourcePage": "https://www.tiledesk.com/pricing-self-managed/", "language": "en","userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36","attributes": { "departmentId": "5df26badde7e1c001743b63e","departmentName": "Default Department","ipAddress": "115.96.30.154","client": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36","sourcePage": "https://www.tiledesk.com/pricing-self-managed/", "projectId": "5df26badde7e1c001743b63c", "requester_id": "ce31d3fd-a358-49c7-9b9f-5aead8330063", "subtype": "info","decoded_jwt": {"_id": "ce31d3fd-a358-49c7-9b9f-5aead8330063","firstname": "Guest", "id": "ce31d3fd-a358-49c7-9b9f-5aead8330063", "fullName": "Guest ","iat": 1596536604,"aud": "https://tiledesk.com","iss": "https://tiledesk.com","sub": "guest","jti": "702a4a7e-e56a-43cf-aadd-376f7c12f633"}},"id_project": "5df26badde7e1c001743b63c","createdBy": "ce31d3fd-a358-49c7-9b9f-5aead8330063","tags": [], "notes": [],"channel": {"name": "chat21"},"createdAt": "2020-08-04T10:23:41.641Z","updatedAt": "2021-03-25T18:01:13.371Z","__v": 3,"assigned_at": "2020-08-04T10:25:26.059Z","channelOutbound": {"name": "chat21"},"snapshot": {"agents": [{"id_user": "5aaa99024c3b110014b478f0"}, {"id_user": "5ac7521787f6b50014e0b592"}, {"id_user": "5de9200d6722370017731969"}, { "id_user": "5e09d16d4d36110017506d7f"}]},"id": "5f29372d690e6f0034edf100","requester_id": "5f29372d690e6f0034edf0ff"}]}}'
415
+ // let test_due = '{ "action": "publish","payload": {"topic": "/5df26badde7e1c001743b63c/requests", "method": "CREATE", "message": [ { "_id": "5f29372d690e6f0034edf100", "status": 200, "preflight": false, "hasBot": true, "participants": ["bot_5df272e8de7e1c001743b645"], "participantsAgents": [], "participantsBots": ["5df272e8de7e1c001743b645"], "request_id": "support-group-MDszsSJlwqQn1_WCh6u", "requester": "5f29371b690e6f0034edf0f5", "lead": "5f29372d690e6f0034edf0ff", "first_text": "ocourse the email is valid ","department": "5df26badde7e1c001743b63e", "agents": [{"user_available": true,"online_status": "online", "number_assigned_requests": 35, "_id": "5e0f2119705a35001725714d","id_project": "5df26badde7e1c001743b63c", "id_user": "5aaa99024c3b110014b478f0", "role": "admin", "createdBy": "5df26ba1de7e1c001743b637","createdAt": "2020-01-03T11:10:17.123Z", "updatedAt": "2020-01-03T11:10:17.123Z", "__v": 0 }, { "user_available": false, "online_status": "offline", "number_assigned_requests": 0, "_id": "5e1a13824437eb0017f712b4", "id_project": "5df26badde7e1c001743b63c","id_user": "5ac7521787f6b50014e0b592", "role": "admin", "createdBy": "5df26ba1de7e1c001743b637", "createdAt": "2020-01-11T18:27:14.657Z","updatedAt": "2020-01-11T18:27:14.657Z", "__v": 0}, { "user_available": false,"online_status": "offline", "number_assigned_requests": 0, "_id": "5df26bdfde7e1c001743b640", "id_project": "5df26badde7e1c001743b63c", "id_user": "5de9200d6722370017731969","role": "admin","createdBy": "5df26ba1de7e1c001743b637", "createdAt": "2019-12-12T16:33:35.244Z", "updatedAt": "2019-12-12T16:33:35.244Z","__v": 0 }, {"user_available": true, "online_status": "online","number_assigned_requests": -11, "_id": "5eb1a3647ac005003480f54d", "id_project": "5df26badde7e1c001743b63c","id_user": "5e09d16d4d36110017506d7f","role": "owner", "createdBy": "5aaa99024c3b110014b478f0","createdAt": "2020-05-05T17:33:24.328Z", "updatedAt": "2020-05-05T17:33:24.328Z","__v": 0}], "sourcePage": "https://www.tiledesk.com/pricing-self-managed/", "language": "en","userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36","attributes": { "departmentId": "5df26badde7e1c001743b63e","departmentName": "Default Department","ipAddress": "115.96.30.154","client": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36","sourcePage": "https://www.tiledesk.com/pricing-self-managed/", "projectId": "5df26badde7e1c001743b63c", "requester_id": "ce31d3fd-a358-49c7-9b9f-5aead8330063", "subtype": "info","decoded_jwt": {"_id": "ce31d3fd-a358-49c7-9b9f-5aead8330063","firstname": "Guest", "id": "ce31d3fd-a358-49c7-9b9f-5aead8330063", "fullName": "Guest ","iat": 1596536604,"aud": "https://tiledesk.com","iss": "https://tiledesk.com","sub": "guest","jti": "702a4a7e-e56a-43cf-aadd-376f7c12f633"}},"id_project": "5df26badde7e1c001743b63c","createdBy": "ce31d3fd-a358-49c7-9b9f-5aead8330063","tags": [], "notes": [],"channel": {"name": "chat21"},"createdAt": "2020-08-04T10:23:41.641Z","updatedAt": "2021-03-25T18:01:13.371Z","__v": 3,"assigned_at": "2020-08-04T10:25:26.059Z","channelOutbound": {"name": "chat21"},"_snapshot": {"agents": [{"id_user": "5aaa99024c3b110014b478f0"}, {"id_user": "5ac7521787f6b50014e0b592"}, {"id_user": "5de9200d6722370017731969"}, { "id_user": "5e09d16d4d36110017506d7f"}]},"id": "5f29372d690e6f0034edf100","requester_id": "5f29372d690e6f0034edf0ff"}]}}'
416
+
417
+ try {
418
+ var json = JSON.parse(message.data);
419
+ // var json = JSON.parse(test_due);
420
+ // this.logger.log('% »»» WebSocketJs - websocket onmessage JSON.parse(message.data) json payload', json.payload);
421
+ // this.logger.log('% »»» WebSocketJs - websocket onmessage JSON.parse(message.data) json payload topic', json.payload.topic);
422
+ // this.logger.log('% »»» WebSocketJs - websocket onmessage JSON.parse(message.data) json ', json);
423
+ } catch (e) {
424
+ that.logger.error('[WEBSOCKET-JS] - This doesn\'t look like a valid JSON: ', message.data);
425
+ return;
426
+ }
427
+
428
+
429
+ // -------------------
430
+ // @ heartCheck
431
+ // -------------------
432
+ that.heartCheck();
433
+
434
+ // --------------------------------------------------------------------------------------------------------------------
435
+ // @ check the action and the message's text - if action is 'heartbeat' and text is ping send the PONG message and return
436
+ // --------------------------------------------------------------------------------------------------------------------
437
+
438
+ if (json.action == "heartbeat") {
439
+
440
+ if (json.payload.message.text == "ping") {
441
+ // -------------------
442
+ // @ send PONG
443
+ // -------------------
444
+ // that.logger.log('[WEBSOCKET-JS] - RECEIVED PING -> SEND PONG MSG');
445
+
446
+ that.send(JSON.stringify(that.pongMsg), 'ON-MESSAGE')
447
+
448
+ } else {
449
+ // nk
450
+ // this.logger.log('[WEBSOCKET-JS] - NOT RECEIVED PING ');
451
+ }
452
+ return;
453
+ }
454
+
455
+ var object = { event: json.payload, data: json };
456
+ if (that.onData) {
457
+ that.onData(json.payload.message, object);
458
+ }
459
+
460
+ var callbackObj = that.callbacks.get(object.event.topic);
461
+ if (callbackObj && callbackObj.onData) {
462
+ callbackObj.onData(json.payload.message, object);
463
+ }
464
+
465
+ if (json && json.payload && json.payload.message && that.isArray(json.payload.message)) {
466
+
467
+ json.payload.message.forEach(element => {
468
+
469
+ //let insUp = that.insertOrUpdate(element);
470
+ let insUp = json.payload.method;
471
+
472
+ var object = { event: json.payload, data: element };
473
+
474
+ var callbackObj = that.callbacks.get(object.event.topic);
475
+
476
+
477
+ if (insUp == "CREATE") {
478
+ if (that.onCreate) {
479
+ that.onCreate(element, object);
480
+ }
481
+
482
+ if (callbackObj) {
483
+ callbackObj.onCreate(element, object);
484
+ }
485
+ }
486
+
487
+ if (insUp == "UPDATE") {
488
+ if (that.onUpdate) {
489
+ that.onUpdate(element, object);
490
+ }
491
+
492
+ if (callbackObj && callbackObj.onUpdate) {
493
+ callbackObj.onUpdate(element, object);
494
+ }
495
+ }
496
+ resolve({ element: element, object: object });
497
+ });
498
+
499
+ } else {
500
+ //let insUp = that.insertOrUpdate(json.payload.message);
501
+ let insUp = json.payload.method;
502
+
503
+ var object = { event: json.payload, data: json };
504
+ var callbackObj = that.callbacks.get(object.event.topic);
505
+
506
+
507
+ if (insUp == "CREATE") {
508
+ if (that.onCreate) {
509
+ that.onCreate(json.payload.message, object);
510
+ }
511
+
512
+ if (callbackObj && callbackObj.onCreate) {
513
+ callbackObj.onCreate(json.payload.message, object);
514
+ }
515
+ }
516
+
517
+ if (insUp == "UPDATE") {
518
+ if (that.onUpdate) {
519
+ that.onUpdate(json.payload.message, object);
520
+ }
521
+
522
+ if (callbackObj && callbackObj.onUpdate) {
523
+ callbackObj.onUpdate(json.payload.message, object);
524
+ }
525
+
526
+ }
527
+
528
+ resolve({ element: json.payload.message, object: object });
529
+ // resolve:
530
+ // $('#messages').after(json.text + '<br>');
531
+ }
532
+ }
533
+ }); // .PROMISE
534
+ }
535
+
536
+ // -------------------------------------
537
+ // !! not use this but the above close()
538
+ // -------------------------------------
539
+
540
+ // closeWebsocket() {
541
+ // this.topics = [];
542
+ // this.callbacks = [];
543
+ // this.logger.log('% »»» WebSocketJs WF - closeWebsocket this.ws ', this.ws)
544
+
545
+ // if (this.ws) {
546
+ // this.ws.close();
547
+ // this.logger.log('% »»» WebSocketJs WF - closeWebsocket ')
548
+ // }
549
+ // }
550
+
551
+
552
+
553
+
554
+ isArray(what) {
555
+ return Object.prototype.toString.call(what) === '[object Array]';
556
+ }
557
+
558
+
559
+ }
@@ -0,0 +1,12 @@
1
+ import { TestBed } from '@angular/core/testing';
2
+
3
+ import { WebsocketService } from './websocket.service';
4
+
5
+ describe('WebsocketServiceService', () => {
6
+ beforeEach(() => TestBed.configureTestingModule({}));
7
+
8
+ it('should be created', () => {
9
+ const service: WebsocketService = TestBed.get(WebsocketService);
10
+ expect(service).toBeTruthy();
11
+ });
12
+ });