Skip to content

Commit 46fbe57

Browse files
committed
fix: resolve display name from participant metadata for castV2 support
Parse displayName from participant.Metadata JSON (used by unauthenticated castV2 users), falling back to participant.Name then participant.Identity.
1 parent 8250dd1 commit 46fbe57

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

Explorer/Assets/DCL/Infrastructure/SceneRuntime/Apis/Modules/CommsApi/GetActiveVideoStreamsResponse.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using LiveKit.Rooms.Participants;
55
using LiveKit.Rooms.TrackPublications;
66
using Newtonsoft.Json;
7+
using Newtonsoft.Json.Linq;
78
using System;
89

910
namespace SceneRuntime.Apis.Modules.CommsApi
@@ -21,6 +22,26 @@ private static VideoTrackSourceType From(TrackSource trackSource) =>
2122
_ => throw new ArgumentOutOfRangeException()
2223
};
2324

25+
private static string ResolveDisplayName(Participant participant)
26+
{
27+
string metadata = participant.Metadata;
28+
29+
if (!string.IsNullOrEmpty(metadata))
30+
{
31+
try
32+
{
33+
var json = JObject.Parse(metadata);
34+
string displayName = json.Value<string>("displayName");
35+
36+
if (!string.IsNullOrEmpty(displayName))
37+
return displayName;
38+
}
39+
catch (JsonException) { }
40+
}
41+
42+
return !string.IsNullOrEmpty(participant.Name) ? participant.Name : participant.Identity;
43+
}
44+
2445
private static void WriteTo(JsonWriter writer, string identity, string trackSid, Participant participant, TrackPublication publication)
2546
{
2647
var sourceType = From(publication.Source);
@@ -33,7 +54,7 @@ private static void WriteTo(JsonWriter writer, string identity, string trackSid,
3354
writer.WritePropertyName("sourceType");
3455
writer.WriteValue(sourceType);
3556
writer.WritePropertyName("name");
36-
writer.WriteValue(participant.Name);
57+
writer.WriteValue(ResolveDisplayName(participant));
3758
writer.WritePropertyName("speaking");
3859
writer.WriteValue(participant.Speaking);
3960
writer.WritePropertyName("trackName");

0 commit comments

Comments
 (0)