From 9b824577a6879e592946353810ad4be73a22b4e3 Mon Sep 17 00:00:00 2001 From: Gabriele Panico Date: Wed, 31 Jul 2024 16:58:06 +0200 Subject: [PATCH] added: chat21client v0.1.12.8 --- src/app/app.component.ts | 12 ++++++++++-- .../conversation-detail.page.ts | 9 ++++----- src/assets/js/chat21client.js | 19 +++++++++++++------ .../providers/mqtt/mqtt-auth-service.ts | 11 +++++++++-- src/chat21-core/utils/constants.ts | 3 ++- 5 files changed, 38 insertions(+), 16 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index e99a2539..6675f0d6 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -27,7 +27,7 @@ import { CustomTranslateService } from 'src/chat21-core/providers/custom-transla import { NotificationsService } from 'src/chat21-core/providers/abstract/notifications.service'; import { NetworkService } from './services/network-service/network.service'; import { ScriptService } from './services/scripts/script.service'; -import { AUTH_STATE_OFFLINE, AUTH_STATE_ONLINE, PLATFORM_DESKTOP, PLATFORM_MOBILE, tranlatedLanguage, TYPE_DIRECT, URL_SOUND_CONVERSATION_ADDED, URL_SOUND_CONVERSATION_UNASSIGNED, URL_SOUND_LIST_CONVERSATION } from 'src/chat21-core/utils/constants'; +import { AUTH_STATE_CLOSE, AUTH_STATE_OFFLINE, AUTH_STATE_ONLINE, PLATFORM_DESKTOP, PLATFORM_MOBILE, tranlatedLanguage, TYPE_DIRECT, URL_SOUND_CONVERSATION_ADDED, URL_SOUND_CONVERSATION_UNASSIGNED, URL_SOUND_LIST_CONVERSATION } from 'src/chat21-core/utils/constants'; import { ActivatedRoute, Router } from '@angular/router'; import { ConversationModel } from 'src/chat21-core/models/conversation'; import { LoginPage } from './pages/authentication/login/login.page'; @@ -1073,8 +1073,16 @@ export class AppComponent implements OnInit { // this.checkTokenAndGoOffline() //se c'รจ un tiledeskToken salvato, allora aspetta, altrimenti vai offline this.IS_ONLINE = false; // console.log('[APP-COMP] IS_ONLINE', this.IS_ONLINE) - this.goOffLine() + this.goOffLine(); this.triggerOnAuthStateChanged(state) + } else if(state && state === AUTH_STATE_CLOSE ){ + this.logger.info('[APP-COMP] CLOSE - CHANNEL CLOSED: ', this.chatManager); + // let IDConv= null + // if(this.route && this.route.snapshot && this.route.snapshot.firstChild){ + // IDConv = this.route.snapshot.firstChild.paramMap.get('IDConv'); + // this.chatManager.removeConversationHandler(IDConv); + // } + // this.checkPlatform(); } }, error => { this.logger.error('initialize FROM [APP-COMP] - [APP-COMP] ***** BSAuthStateChanged * error * ', error) diff --git a/src/app/pages/conversation-detail/conversation-detail.page.ts b/src/app/pages/conversation-detail/conversation-detail.page.ts index 5c824ffd..66984b0b 100644 --- a/src/app/pages/conversation-detail/conversation-detail.page.ts +++ b/src/app/pages/conversation-detail/conversation-detail.page.ts @@ -524,9 +524,9 @@ export class ConversationDetailPage implements OnInit, OnDestroy, AfterViewInit this.disableTextarea = false this._getProjectIdByConversationWith(this.conversationWith) this.initConversationHandler() - this.initGroupsHandler() - this.initSubscriptions() - this.startConversation() + this.initGroupsHandler(); + this.startConversation(); + this.initSubscriptions(); this.getLeadDetail() this.initializeTyping(); } @@ -879,7 +879,6 @@ export class ConversationDetailPage implements OnInit, OnDestroy, AfterViewInit conv.attributes['project_name'], conv.attributes['request_channel'] ) - } if (!conv) { this.logger.debug('[CONV-COMP] setHeaderContent getConversationDetail: conv not exist --> search in archived list', this.conversationWith, this.conv_type) @@ -1317,7 +1316,7 @@ export class ConversationDetailPage implements OnInit, OnDestroy, AfterViewInit updateLeadInfo(msg) { if (msg.attributes && msg.attributes.hasOwnProperty("updateUserFullname")) { const userFullname = msg.attributes['updateUserFullname']; - this.logger.debug('[CONVS-DETAIL] newMessageAdded --> updateUserFullname', userFullname) + this.logger.debug('[CONVS-DETAIL] newMessageAdded --> updateUserFullname', userFullname, this.conversation) this.conversationWithFullname = userFullname //update info for next sendMessage object //updates conversation header info this.conversationAvatar = setConversationAvatar( diff --git a/src/assets/js/chat21client.js b/src/assets/js/chat21client.js index 9e023270..851ca3a9 100644 --- a/src/assets/js/chat21client.js +++ b/src/assets/js/chat21client.js @@ -1,7 +1,7 @@ /* Chat21Client - v0.1.12.7 + v0.1.12.8 @Author Andrea Sponziello @Member Gabriele Panico @@ -24,6 +24,7 @@ class Chat21Client { this.reconnections = 0 // just to check how many reconnections this.client_id = this.uuidv4(); this.log = options.log ? true : false; + if (options && options.MQTTendpoint) { if (options.MQTTendpoint.startsWith('/')) { if (this.log) { @@ -1021,25 +1022,31 @@ class Chat21Client { ); } ); + this.client.on('error', + (error) => { + console.error("Chat client error event", error); + } + ); + } + + onDisconnect(callback){ this.client.on('reconnect', () => { if (this.log) {console.log("Chat client reconnect event");} + // callback('reconnect') } ); this.client.on('close', () => { this.connected = false if (this.log) {console.log("Chat client close event");} + callback('close') } ); this.client.on('offline', () => { if (this.log) {console.log("Chat client offline event");} - } - ); - this.client.on('error', - (error) => { - console.error("Chat client error event", error); + // callback('offline') } ); } diff --git a/src/chat21-core/providers/mqtt/mqtt-auth-service.ts b/src/chat21-core/providers/mqtt/mqtt-auth-service.ts index 149dac7d..94afc939 100644 --- a/src/chat21-core/providers/mqtt/mqtt-auth-service.ts +++ b/src/chat21-core/providers/mqtt/mqtt-auth-service.ts @@ -246,8 +246,7 @@ z const responseType = 'text'; const postData = {}; // const that = this; - this.http.post(this.URL_TILEDESK_CREATE_CUSTOM_TOKEN, postData, { headers, responseType}) - .subscribe(data => { + this.http.post(this.URL_TILEDESK_CREATE_CUSTOM_TOKEN, postData, { headers, responseType}).subscribe(data => { this.logger.debug("[MQTTAuthService] connectWithCustomToken: **** data", data) const result = JSON.parse(data); this.connectMQTT(result); @@ -262,9 +261,17 @@ z this.chat21Service.chatClient.connect(userid, credentials.token, () => { this.logger.debug('[MQTTAuthService] connectMQTT: Chat connected.'); this.BSAuthStateChanged.next('online'); + this.onDisconnectMQTT(); }); } + onDisconnectMQTT(): any{ + this.chat21Service.chatClient.onDisconnect((state)=> { + this.logger.debug('[MQTTAuthService] onDisconnect --> ', state) + this.BSAuthStateChanged.next('close'); + }) + } + // /** // * createCompleteUser // * @param user diff --git a/src/chat21-core/utils/constants.ts b/src/chat21-core/utils/constants.ts index 57c536e6..39203617 100755 --- a/src/chat21-core/utils/constants.ts +++ b/src/chat21-core/utils/constants.ts @@ -13,7 +13,8 @@ export const PUSH_ENGINE_FIREBASE = 'firebase'; // AUTH export const AUTH_STATE_OFFLINE = 'offline'; -export const AUTH_STATE_ONLINE = 'online' +export const AUTH_STATE_ONLINE = 'online'; +export const AUTH_STATE_CLOSE = 'close'; // MESSAGES STATUS