Skip to content

Commit

Permalink
added: chat21client v0.1.12.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriele Panico committed Jul 31, 2024
1 parent b25fd4c commit 9b82457
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 16 deletions.
12 changes: 10 additions & 2 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 4 additions & 5 deletions src/app/pages/conversation-detail/conversation-detail.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down
19 changes: 13 additions & 6 deletions src/assets/js/chat21client.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Chat21Client
v0.1.12.7
v0.1.12.8
@Author Andrea Sponziello
@Member Gabriele Panico
Expand All @@ -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) {
Expand Down Expand Up @@ -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')
}
);
}
Expand Down
11 changes: 9 additions & 2 deletions src/chat21-core/providers/mqtt/mqtt-auth-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/chat21-core/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9b82457

Please sign in to comment.