twilio-video.js
twilio-video.js copied to clipboard
Is there any way to pass custom metadata when connecting to a room?
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
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
I have filed a feature request for this (JSDK-2664)
Thanks, I guess that will have to do for now. Looking forward to this feature
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?
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
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
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?
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.
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.
+1 I want to pass a profile picture (URL String).
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.
@manjeshbhargav was this feature included on a newer release?