When send a message 1 to 1 I haven't problem not even recover history ofchat, but if open a socket with a second user don't switched the channel and create problem sending message.
The destinatary don't recived message despite the message arrived on the socket(topic/chat).
let stompClient = this.webSocketService.connect();
stompClient.connect({}, frame => {
// Subscribe to notification topic
stompClient.subscribe('/topic/notification', notifications => {
// Update notifications attribute with the recent messsage sent from the server
this.notifications = JSON.parse(notifications.body).count;
})
stompClient.subscribe('/topic/chat', notifications => {
let chat: any = {};
console.log(notifications);
chat = JSON.parse(notifications.body)
// Update notifications attribute with the recent messsage sent from the server
if (!(this.listChanneli.includes(chat.channel))) {
let idUser = this.accountService.userValue.data.id;
let index = 0;
if (chat.id.indexOf(idUser) === 0) {
index = 1;
}
let array: number[]=[];
let userId = this.accountService.userValue.data.id;
chat.id.forEach(element=>{
array.push(element);
})
if (!this.listChannel.includes(this.channel)){
array=chat.id;
if (array.includes(userId)) {
let element:string;
this.listaCanali.forEach(element => {
let index = element.indexOf('-');
let firstID : any = '';
for(let i = 0;i < index;i++) {
firstID = firstID + element[index]
}
if (userId !== Number(firstID)){
this.listCanaliFinale[firstID]=element;
}
let secondID : any = '';
for(let i = index;i < element.length;i++) {
secondID = secondID + element[index]
}
if (userId !== Number(secondID)){
this.listCanaliFinale[secondID]=element;
}
});
// this.service.changeListaCanaliFinale(this.listCanaliFinale);
this.service.changeIdChannel(chat.channnel);
this.listChannel[index] = chat.canale;
if (chat.id.indexOf(idUser) !== -1) {
stompClient.subscribe('/topic/chat/' + chat.channel, notifications => {
if (notifications.body) {
this.flag = !this.flag;
this.service.changeMessageHistory(this.flag);
}
this.service.changeMessage(notifications.body);
chat = JSON.parse(notifications.body)
// Update notifications attribute with the recent messsage sent from the server
this.message= JSON.parse(notifications.body)
service.changeMessage(JSON.parse(notifications.body));
})
this.listaCanali.push(chat.channel)
}
}
} }else{
chat.channel= null;
console.log("channel exist")
}
})
});
When send a message 1 to 1 I haven't problem not even recover history ofchat, but if open a socket with a second user don't switched the channel and create problem sending message. The destinatary don't recived message despite the message arrived on the socket(topic/chat).
let stompClient = this.webSocketService.connect(); stompClient.connect({}, frame => {