There is project which have chat feature which is been done by using PubNub. I had gone through the tutorial provided by PubNub and had integrated the pubnub.framework and CocoaLumberjack in my project. And had added the coded as shown in this tutorial
My questions are:
- Do i have to create different channel to chat with the different friends? Or how the channel in the PubNub will work? I want to do only one-one chat. I don’t want to implement any group chats. As per my study from using PubNub for multi users chatting every user have their own channel. But in that case how can I load the unread message count or messages when I am offline.
- What is the process to install the PubNub server in my backend server? I am using backend as PHP Laravel.
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
- you are free to create an unlimited number of channels, so for 1-1 chats, every user is subscribed to their own private channel. to chat with you, I publish a message to your private channel. here is a write-up that outlines this in more detail. for short periods of being offline (less than 10 mins), you can rely on the catch-up mechanism (make sure you configure this). for retrieving the actual messages while you were offline, you can use the history() function of Storage & Playback. retrieving only the count of unread messages requires logic on your end… perhaps keeping count of the number of messages published for each channel in your backend database, and then clients can make a REST call to your backend to retrieve this count.
- PubNub has a PHP SDK you can use… what do you plan on having your backend server do?
@Alex is right and here is some more clarity on that:
Every user should have an inbound channel that they subscribe to and anyone that wants to invite them to a private chat publishes an invite message with the name of the new 1-1 chat channel, in that message. If the invited users accepts, that user will subscribe to the new 1-1 channel, else a decline message can be returned on the inviter user’s inbound channel.
For any channel that a user needs to know the number of messages missed while offline (or just not actively subscribed to a channel), you need to call
history on those channels with the timetoken of the last received message on that channel. This will retrieve the messages and you can just get the size of the array of returned messages to display that unread message count.
There is no PubNub server to install. Your PHP server app/script will use the PubNub network in much the same way that your iOS client apps use it. There is just the PHP SDK that you have to download and requre:
- PubNub PHP Composer
- PubNub PHP (non-Composer)
- PubNub PHP Larvel (NOTE: third party – PubNub cannot provide support for this but it might provide some insights into using PubNub with Laravel)
You can think of both your server and your client apps as clients of the PubNub Network. Your PHP app will likely on publish messages on channel but not subscribe to channels, though. If you are thinking you need to subscribe to channels from your PHP app, please contact PubNub Support with details about your use case.