in my app when i click on another users profile(open a chat screen with him) i need to subscribe both of those users to the the same channel.any suggestions on how it is done
Here's a very simple overview of two ways to do this.
Assign a channel name to every user that is well-known or discoverable by all other users (or just friends). When you click the user it can send a chat invite to a newly created channel and that channel name can be sent to the user. The inviter is already subscribed to the new channel and the response to the invite by the invitee can be sent on that channel (or to the inviter's personal channel).
Or you can just use the personal channels as one way communication. Each user subscribes to his own channel receive all messages from any user and publishes message to other users on their personal channels.
Hope that makes sense.
thanks for the suggestions. this is what i was doing till now. i have one global channel.when a user opens the chat screen for the first time(with any other user) i send a message on the global channel with the new private channel name.then inside the onsuccess callback for the global channel i subscribe both the users to the new private channel.from here onwards the commnication will be on the private channel. is it a good way to do it?
Using the global channel means that every user subscribed to that channel will get the message even if you intend it for only one user. This is not secure and you get charged for every message that is received. So if 1000 users are subscribed, 1 user sends the message and 1000 users will get it and that counts as 1001 messages.
So it is best to use a single channel per user that you can invite that user with. Make sense?
thank you for the explaination. I am implemented the second method that you suggested(every user has his own channel). but once you subscribe to a channel,how long is it valid? i mean once subscribed does it always remain subscribed or does it have a expiry?
The channel never really expires but the subscribe does after 5 minutes if there are no messages published but it reconnects immediately to maintain that subscription t the channel. This continues until your client(s) can no longer stay connected (network issues) or your app unsubscribes or disconnects.
See what is the subscribe cycle for more details.
Let me know if you still have further questions about this.
hey thank you for the response. right now i am running the subscribe code in a service(android) so that the callback runs even if the app is closed.bt some times i dont get the message. do i have to run the subscribe code again and again after a certain interval?may be once in 10 min.
Did you implement the subscribe at boot background service? Take note of the partial wake lock details.