Session Metadata (Deprecated)

Session Store is the new API for this functionality.

Session Metadata is an alpha feature that allows you to set and get metadata for a given session.

A session is defined as the period from when the first peer joins an empty room till the last peer leaves.

The same room can have multiple sessions. During one session the metadata will be preserved. Once a session ends the session metadata will also be cleared, that is, when the last peer leaves.

Limits

Since session metadata is an alpha feature, it does not have the following:

  1. Locks to ensure consistency of the data. If two peers update it at the same time, it will be a race condition for which one succeeds last, overwriting whatever was before.
  2. SDKs are not made aware of session metadata updates on their own. This has to be done manually. One suggested way is listed below.

Set Session Metadata

Any peer can set the session metadata by calling setSessionMetadata and passing String value to its metadata parameter.

No updates are sent to other peers after calling setSessionMetadata as it's an alpha feature. So, some extra code needs to be written to send updates. The implementation can be found here

class Meeting implements HMSUpdateListener, HMSActionResultListener{ ... void setSessionMetadata( {required String? metadata}) { ///[metadata]: String data which you wish to set as session metadata ///[hmsActionResultListener]: an instance of a class which implements HMSActionResultListener //Here this is an instance of a class that implements HMSActionResultListener, that is, Meeting hmsSDK.setSessionMetadata( metadata: metadata, hmsActionResultListener: this); } void onSuccess( {HMSActionResultListenerMethod methodType = HMSActionResultListenerMethod.unknown, Map<String, dynamic>? arguments}) { switch (methodType) { ... case HMSActionResultListenerMethod.setSessionMetadata: //Session metadata set successfully break; } } void onException( {HMSActionResultListenerMethod methodType = HMSActionResultListenerMethod.unknown, Map<String, dynamic>? arguments, required HMSException hmsException}) { switch (methodType) { ... case HMSActionResultListenerMethod.setSessionMetadata: // Check the HMSException object for details about the error break; } }

You will receive an update on onSuccess Callback after successfully setting metadata in HMSActionResultListenerMethod.setSessionMetadata.

Get Session Metadata

Any peer can get the session metadata by calling getSessionMetadata.

String? metadata = await hmsSDK.getSessionMetadata();

Updating session metadata manually

Since no updates are sent for session metadata as it is an alpha feature, here is one suggested way of getting peers to receive it once set.

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 onMessage of all apps. To getSessionMetadata at that time instead of showing a message for that type.

Let's understand it from a diagram:

session-metadata

Let's look at them step-by-step:

PeerA calls setSessionMetadata

//Assuming this function is called in class where HMSActionResultListener is implemented as the above example hmsSDK.setSessionMetadata( metadata: metadata, hmsActionResultListener: this);

PeerA gets onSuccess callback from HMSSDK and sends a broadcast message with type

onSuccess callback sends a broadcast message as follows:

void onSuccess( {HMSActionResultListenerMethod methodType = HMSActionResultListenerMethod.unknown, Map<String, dynamic>? arguments}) { switch (methodType){ case HMSActionResultListenerMethod.setSessionMetadata: hmssdk.sendBroadcastMessage(message: "refresh", type: "metadata", hmsActionResultListener:hmsActionResultListener); break; } }

🔑 Note: We can set the type as any string just make sure you check the same type string on the onMessage callback. We have taken metadata as an example

Other peers receive onMessage callback

In onMessage callback check for message type and update session Metadata value using getSessionMetadata.

class Meeting implements HMSUpdateListener, HMSActionResultListener{ ... void getSessionMetadata() async{ await hmsSDK.getSessionMetadata(); } void onMessage({required HMSMessage message}) { if(message.type=="metadata") { getSessionMetadata(); return; } } }

Have a suggestion? Recommend changes ->

Was this helpful?

1234