The way we have our chat is that the chat room is completely dynamic, e.g. If user went to /chat/abc123 they will load the channelId abc123 and so on, this abc123 could be anything.
Now what I do, is that when they load the channel abc123 I first “Create” the channel with Id as abc123 and then “Join” it. Now this is bad!! because if they refresh the chatroom I’ll attempt to create the channel abc123 again. because I do not know for sure that if channel exists or not, therefore getting the error A channel already exist with the input id.
How to solve it? How to just a Join a channel, if it’s already created? Cool. If it’s not created? then create it for me in the background and lemme continue. But currently I cannot join a channel that’s not created.
PubNub solved it by just joining the channel and listening to it without the “Create” step before “Join”.
Hi @Moe Please allow me to clarify my understanding, you would like to know if that specific channel already exists, before you join, correct? If yes, you can check channel by calling get channel first.
const liveChannel = ChannelRepository.getChannel('channel3');
liveChannel.once('dataUpdated', data => {
...
});
And this is the logic behind channelId and how channels work.
Well yes and no,
Simply I have a dynamic chat rooms IDs, means I cannot have the concept of “Create” then “Join” because those channels are being accessed by the direct URL. e.g. /chat/abc123
Problem is that every time the user enters the chat room link I have to “Create” and “Join” every single time. But that does not work because on the “Create” step I’ll have an error that this chat room is already created before!