-1

I'm trying to play back PubNub messages in real time as suggested by their Replay functionality, however the only examples I can find online just relate to obtaining a static history of messages over a certain timeframe.

Does anyone know of an online tutorial actually dealing with the Replay API request (rather than History API) or can give some sample code here (Swift if possible)?

Many thanks.

RobertyBob
  • 803
  • 1
  • 8
  • 20
  • The replay feature was only available in the JavaScript SDK and has been deprecated since it is not in demand. You can replicate this feature on your end if you require it. What is your use case? – Craig Conover Jul 17 '16 at 12:41

1 Answers1

2

Custom PubNub Replay Implementation

The replay feature was only available in the PubNub Node/JavaScript SDK and has been deprecated (it will not be part of the v4 SDKs) because it is not in demand. You can replicate this feature on your end if you require it. Most likely you would want to do this from your server and not your client app but you can do this from your client, too.

Using the history API (Swift SDK for your client implementation), you will retrieve as many of the messages as needed paging through storage since history only returns 100 messages per call (new features coming in the future to simplify iterative storage paging).

Here is a high level design, from your server, to implement your own replay feature:

  1. On your server get history from the desired channel – you can only get 100 messages at a time so you may have to page through the messages to get more than 100.
  2. Create a new channel to replay the message on and let your clients know what that channel name is and have them subscribe to it. You might publish a message that has the replay channel name on another channel that those clients are already subscribed to.
  3. Once the clients are subscribed to this replay channel, you can proceed with replaying the messages.
  4. Starting with the oldest message that you retrieved using history, publish it then sleep for the amount of time of the difference between the message timetoken just published and the timetoken of the next message to be published.
Community
  • 1
  • 1
Craig Conover
  • 4,710
  • 34
  • 59
  • Many thanks Craig - was hoping it was more of a 'start replay api when play button pressed' but alas... lol. This will take a while for me to implement on the server so will get back as soon as possible with confirmation. It all sounds perfectly reasonable though so thanks again. – RobertyBob Jul 17 '16 at 15:14
  • It sounds more complex than it really is. I think you will find the code fairly straight forward once you get started but it depends on how robust of a *DVR* like functionality that you are looking for. The main part is the request the replay from the client to the server to kick it off. The client can actually tell the server the name of the channel to replay messages to and then the client can already be subscribed to the channel. The server can see if there is a user subscribed to the channel before publishing messages to that channel so you are not *replaying* to no one. – Craig Conover Jul 17 '16 at 15:26
  • Contact [PubNub Supprt](http://pubnub.com/support) if you have further questions/issues. It might be best to talk with a PubNub solution architect to discuss your exact requirements and provide best practices to you. – Craig Conover Jul 17 '16 at 15:27
  • According to PubNub, the playback feature remains available but is not suitable for paused/skipped playback so the best way to deal with this is indeed to create a process using the History API – RobertyBob Jul 22 '16 at 20:30