Managed Watch Party

Managed Watch Party

A new feature to the StreamLayer SDK is the Managed Watch Party. A Managed Watch Party is a special kind of Watch Party that is created and managed by the backend - you or your users cannot create a Managed Watch Party from inside your application that uses the StreamLayer SDK. Before you get started, please check the backend API for the integration steps.

If you want to allow your users to be able to join a Managed Watch Party, you will need to use the following method when you create the StreamLayer session.

StreamLayer.createWatchPartySession(groupId:String, title: String, @escaping completion: (SLRWatchPartySession?, Error?) -> Void)

When you call that method, it will return an instance of SLRWatchPartySession interface or error. This is the entry point for the API of a Managed Watch Party on the SDK side. The parameter groupId is the string value of the created group id, which you get from the backend.

SLRWatchPartySession

SLRWatchPartySession contains a couple of objects that describe supported features and internal data. These objects include:

  1. SLRWatchParty.User - an object which provides access to the following ids: internal ID of SDK user’s and external(bypassId), which is provided by the host app during mapping API calls.
    You can choose which one is a better option for you for merging with your own data on the host app side.

  2. SLRWatchParty.Participant - object which provides access to SLRWatchParty.User and SLRWatchParty.ParticipantStatus objects for the user that is currently a part of the Watch Party.

  3. SLRWatchParty.ParticipantStatus is an enum:

enum ParticipantStatus: String {
    case pending = "PENDING" // when used added to the group via API but isn't subscribed to the group
    case subscribed = "SUBSCRIBED" // when user subscribe to the group via `StreamLayer.createWatchPartySession` method
    case onCall = "ON_CALL" // when user is on call and opened Watch Party overlay
  }
  1. SLRWatchParty.Message - object which provides access to SLRWatchParty.User, who sent a message, and content of message, which other participants are sending to you.

  2. SLRWatchParty.Event - enum which provides access to different events of a Managed Watch Party. Full description of all events see below:

    SLRWatchParty.Event.participantAdded is triggered when a new user will be subscribed to a Managed Watch Party.
    SLRWatchParty.Event.participantRemoved is triggered when the user will be unsubscribed from a Managed Watch Party.
    SLRWatchParty.Event.participantUpdated is triggered when the user's status will be changed.

Methods

SLRWatchPartySession contains a couple of methods, which allow you to communicate and get updates from other group participants, show the UI of the watch party, etc. Full description of all methods see below:

  1. Get ID of group:
var topicId: String

This method returns the id of the managed watch party.

  1. Get all participants of group:
func participants(): [SLRWatchParty.Participant]

This method returns all participants of the group.

  1. Subscribe to group updates:
func events(): Observable<SLRWatchParty.Event>

This method returns RxSwift Observable, which allows you to subscribe and get updates. Check SLRWatchParty.Event object definition above to get know when each event will be triggered.

  1. Send a message to all subscribed participants:
func sendMessage(_ message: String, completion: @escaping SLRWatchPartyMessageCompletion)

The parameter 'message' is the string value which you want to send to other participants.

  1. Subscribe to messages updates:
 func messages(): Observable<SLRWatchParty.Message>

Note: SDK doesn't persist messages between subscriptions. For example: if you subscribe to a Managed Watch Party, get Message1 and Message2, unsubscribe from a managed watch party and then subscribe again, you will not get Message1 and Message2 - only new messages when they will be sent(Message3, Message4, etc)

  1. Open Watch Party UI overlay:
 func openWatchParty()
  1. Unsubscribe from managed watch party and release unused resources:
 func release()

Don't forget to call this method when you want to unsubscribe from a group - it is required for getting other participants to know that the current user leaves the managed watch party.
Note: If you call this method during an active call it will stop the call first and then unsubscribe from the managed watch party and release unused resources.