Shared State with Session Metadata (Deprecated)

Session Store is the new API for this functionality.

Session metadata is a shared state that is accessible to all participants in a room. It can be used for features such as pinning text or highlighting a particular participant. The session metadata is retained throughout the duration of a session and is cleared once all participants have left the room.

Differences between Session Metadata and Peer Metadata

While peer metadata is associated with individual peers and each peer can have their own metadata, session metadata remains the same for every peer in the room.

How to store shared data with 100ms SDK

To update the value of the session metadata for the current room session, call setSessionMetaData method on SDK instance. In the following example, the "test" string will be saved in the session metadata and accessible to all participants in the room as a shared state.

Make sure you call session metadata API after you joined the room. You should listen to onJoin() callback to proceed.

hmsSDK.setSessionMetaData("some data", object : HMSActionResultListener { override fun onError(error: HMSException) { } override fun onSuccess() { } })

How to read shared data with 100ms SDK

To retrieve the session metadata, use the getSessionMetaData method:

Make sure you call session metadata API after you joined the room. You should listen to onJoin() callback to proceed.

hmsSDK.getSessionMetaData(object :HMSSessionMetadataListener { override fun onSuccess(sessionMetadata: String?) { // Use the metadata Log.d("Data","The data is $sessionMetadata") } override fun onError(error: HMSException) { } })

Limitations in the Beta Release

At present, there is no callback that will be triggered to indicate changes in the session metadata.

Then how can I notify other users that session metadata has changed?

To notify others that the session data has been changed, you can send a broadcast message.

One way to notify other apps of a change in session metadata is to send a custom broadcast message when a set succeeds. The type can be set to something like "metadata" or whatever you choose and this should then be handled in the onMessageReceived of all apps. To getMetaData at that time instead of showing a message for that type.

  1. Example Set of how we do it in the sample app. By sending a particular broadcast message when a set succeeds.
  2. When the broadcast message is received, if it's of the custom type we set it then don't show the message and get metadata instead.
  3. It is also recommended to get the metadata in the onJoin method so existing metadata is shown to peers to have just joined the room.

Have a suggestion? Recommend changes ->

Was this helpful?

1234