I want to dynamically start Echo channels, which were filled by a new message, and almost of my channels work correctly. That is if I click on the any chat, there is includes 4 broadcast channels for me and for my companion, and here we go.
BUT if I want to send a message somebody else, and I wish do that this somebody else keep a notify about message (in the background mode), it is no possible, because when I DYNAMICALLY pass value of chatId here
window.Echo.private("lastsent." + chatId),
there is nothing happens for other person. From my side broadcast creates, but for other person no.
This is iniciation of my channel listener:
function listenSentLastMessage(chatId) {
window.Echo.private("lastsent." + chatId).listen(".SentLastMessageEvent", (event) => {
//... code, which no matters in our situation
});
}
The chatId for channel I planned to get as soon as I click of any my chats, using that function:
$(document).on("click", ".group-conversation-item", function () {...
inside of that function I get chatId value of clicked chat and pass it in listenSentLastMessage(chatId). And it should pass that chatId to function, then start broadcasting for other berson in background mode, thats it, but nothing happens for other person.
I tryed different forms of passing chatId data to channel, for example using outside constant const activeChatIds = []; then using that function
function addActiveChat(chatId) {
// Check if the chatId is not already in the array
if (!activeChatIds.includes(chatId)) {
activeChatIds.push(chatId); // Add the chatId to the array
listenSentLastMessage(chatId); // Start listening to events for this chat
}
}
But that dynamically method useless, no works. And most of all works 2 methods: when I directly record number of channel which should be listen:
window.Echo.private("lastsent." + 14).listen(".SentLastMessageEvent", (event) => {
or if I run link, which catch all of my channels in database and listen them simultaneously:
$.get("/get-priv-chats", function (response) {
response.forEach(function (chatId) {
listenSentLastMessage(chatId);
});
});
All of that method no fits for me, because it will be overload my service in time of high intensive chating, it no catched new channel, if somebody new to write me, somebody, which absent in my channels list before, and this person appears on channels list only if I reload a page.