twilio-video.js icon indicating copy to clipboard operation
twilio-video.js copied to clipboard

Is there any way to pass custom metadata when connecting to a room?

Open rayhaanq opened this issue 5 years ago • 11 comments

I'm showing a list of connected participant videos in a room, but I also want to overlay their video with some information about the user like their name + email address. Is there any way I can do this currently? There's ways to possibly use the DataTrack API and pass that information around, but I think this will over-complicate things as I'll need to resend all user information of every participant every time a new participant joins the room. This information is static so I don't think this is the correct use of the DataTrack API.

I think there should be some sort of metadata field available when connecting to a room which attaches to the RemoteParticipant so information like this is passable. Or is there any other way this can be done?

Thanks

rayhaanq avatar Jan 25 '20 14:01 rayhaanq

Thank you @rayhaanq for writing with your suggestion. Unfortunately there isn't anyway to pass such metadata outside using data channels. Yeah, it would be good feature to have. I will file a feature request.

I have one suggestion for a workaround - Can you use user identity field that you pass when creating access token ? I see that the length of identity is limited to about 120 characters. If your metadata can be encoded in those 120 characters, perhaps you can use the field and have your application encode/decode the metadata from identity to surface to user?

Thanks, Makarand JSDK Team

makarandp0 avatar Jan 29 '20 19:01 makarandp0

I have filed a feature request for this (JSDK-2664)

makarandp0 avatar Jan 29 '20 19:01 makarandp0

Thanks, I guess that will have to do for now. Looking forward to this feature

rayhaanq avatar Feb 11 '20 17:02 rayhaanq

Just to chime in here... in examples I see that during token creation the identity is set to Alice or Bob. Of course this needs to be unique, so I'll have to use the user ID instead. That means I cannot easily show notifications such as "Alice has joined". In chat there is a User resource (edit: https://www.twilio.com/docs/chat/rest/user-resource) that has a friendlyName - this is basically all I'm looking for. Do I also need to wait for this feature request or is there an "easy" way to achieve this today?

AxelTheGerman avatar Apr 06 '20 00:04 AxelTheGerman

Using the Twilio programmable chat I loved the friendlyName feature. Here is what I did for my solution. In my scenario. I wanted to save the email and the name of the person that was in the video call.

I have a form that they fill out: email, name, relation to the user, etc. This stuff goes to a database but I don't want to make a separate call to a database to retrieve this information. My unique identifier on my backend is a concatenated string of email and fullName with a $ in between.

It ends up looking like this: [email protected]$Lewis Menelaws

Then on my front end application, I can use it like this:

// participant is the object, I split by using the $ and grab the first part of it. etc
const participantEmail = participant.identity.split("$")[0];
const participantName = participant.identity.split("$")[1];

Until the friendly name comes in, I believe this is the best option. Depending on the level of display you are looking for, you can get pretty crazy with this 120 character count:

[email protected]$Lewis Menelaws$@LewisMenelaws$@elebumm$Loves Dogs$Loves Running$Is looking for a job

elebumm avatar Jun 12 '20 03:06 elebumm

I ended up with something similar. I simply use JSON to avoid potential problems with separator characters (not likely with a $ being in the email but you never know)

When creating the token:

Twilio::JWT::AccessToken.new(
   ...
   identity: { id: current_user.id, name: current_user.name }.to_json
)

On the client side:

const identity = JSON.parse(participant.identity)
console.log(identity.id)
console.log(identity.name)

Pro: all encoding is taken care of by JSON Con: slight overhead for the JSON attribute names

AxelTheGerman avatar Jun 12 '20 03:06 AxelTheGerman

Still, I don't see why the token cannot have an optional parameter to take the user's friendlyName or displayName. Not sure if there is any limitation (size) on the token in the end, otherwise being able to pass an arbitrary (I don't mind if limited in size) payload to describe the token and it's owner in more detail.

One major reason people (including myself) choose Twilio over other competitors is the flexibility Twilio gives - not in this case :disappointed:

@makarandp0 I can't find that feature request searching online - is there anyway we can follow the progress?

AxelTheGerman avatar Jun 12 '20 04:06 AxelTheGerman

I would also be interested in that feature. In my case I wanna do a one-to-many (up to 50) group call and therefore I need to know who is the "one" by passing around an admin=true/false value.

ErnestBrandi avatar Oct 14 '20 15:10 ErnestBrandi

Just came to chip in about needing this feature. TwilioVoice already allows you to pass custom parameters that will be delivered on the callback url, this is basically what my use case is. When a participant connects get those params on the webhook.

rapito avatar Jan 27 '21 13:01 rapito

+1 I want to pass a profile picture (URL String).

aliraza12636 avatar Jun 03 '21 13:06 aliraza12636

I also would gladly see this feature available to use. In my case it's user name and profile picture url that I would like to add.

ksocha avatar Jun 08 '21 12:06 ksocha

@manjeshbhargav was this feature included on a newer release?

rapito avatar Oct 13 '22 22:10 rapito