Skip to content

Commit

Permalink
feat: participant attributes. (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwebrtc authored Sep 2, 2024
1 parent 19b7903 commit d5b10b1
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Runtime/Scripts/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ public enum RoomEvent
[EnumMember(Value = "audioPlaybackChanged")]
AudioPlaybackStatusChanged,
[EnumMember(Value = "mediaDevicesError")]
MediaDevicesError
MediaDevicesError,
[EnumMember(Value = "participantAttributesChanged")]
ParticipantAttributesChanged,
}

[JsonConverter(typeof(StringEnumConverter))]
Expand Down
17 changes: 17 additions & 0 deletions Runtime/Scripts/Room/Participant/LocalParticipant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,22 @@ public void SetTrackSubscriptionPermissions(bool allParticipantsAllowed,

JSNative.CallMethod(NativeHandle, "setTrackSubscriptionPermissions");
}

public JSPromise SetName(string name)
{
JSNative.PushString(name);
return Acquire<JSPromise>(JSNative.CallMethod(NativeHandle, "setName"));
}

public JSPromise SetMetadata(string metadata)
{
JSNative.PushString(metadata);
return Acquire<JSPromise>(JSNative.CallMethod(NativeHandle, "setMetadata"));
}

public JSPromise SetAttributes(JSMap<string, string> attributes) {
JSNative.PushObject(attributes.NativeHandle);
return Acquire<JSPromise>(JSNative.CallMethod(NativeHandle, "setAttributes"));
}
}
}
9 changes: 9 additions & 0 deletions Runtime/Scripts/Room/Participant/Participant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ public string Metadata
}
}

public JSMap<string,string> attributes
{
get
{
JSNative.PushString("attributes");
return Acquire<JSMap<string,string>>(JSNative.GetProperty(NativeHandle));
}
}

public DateTime? LastSpokeAt
{
get
Expand Down
10 changes: 10 additions & 0 deletions Runtime/Scripts/Room/Room.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class Room : JSEventEmitter<RoomEvent>, IDisposable
public delegate void TrackStreamStateChangedDelegate(RemoteTrackPublication publication, TrackStreamState streamState, RemoteParticipant participant);
public delegate void TrackSubscriptionPermissionChangedDelegate(RemoteTrackPublication publication, SubscriptionStatus status, RemoteParticipant participant);
public delegate void AudioPlaybackChangedDelegate(bool playing);
public delegate void AttributesChangedDelegate(Participant participant, JSMap<string, string> changedAttributes);

public event ReconnectingDelegate Reconnecting;
public event ReconnectedDelegate Reconnected;
Expand All @@ -71,6 +72,7 @@ public class Room : JSEventEmitter<RoomEvent>, IDisposable
public event TrackStreamStateChangedDelegate TrackStreamStateChanged;
public event TrackSubscriptionPermissionChangedDelegate TrackSubscriptionPermissionChanged;
public event AudioPlaybackChangedDelegate AudioPlaybackChanged;
public event AttributesChangedDelegate AttributesChanged;

[MonoPInvokeCallback(typeof(JSNative.JSDelegate))]
private static void EventReceived(IntPtr iptr)
Expand Down Expand Up @@ -285,6 +287,14 @@ private static void EventReceived(IntPtr iptr)
room.AudioPlaybackChanged?.Invoke(status);
break;
}
case RoomEvent.ParticipantAttributesChanged:
{
var changedAttributes = Acquire<JSMap<string, string>>(JSNative.ShiftStack());
var participant = Acquire<Participant>(JSNative.ShiftStack());
Log.Debug($"Room: Received AttributesChanged({participant.Sid}, {changedAttributes})");
room.AttributesChanged?.Invoke(participant, changedAttributes);
break;
}
}
}
catch (Exception e)
Expand Down

0 comments on commit d5b10b1

Please sign in to comment.