Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide participantIdentity instead of SID for permission APIs #26

Merged
merged 1 commit into from
Apr 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ namespace LiveKit
{
public struct ParticipantTrackPermission
{
[JsonProperty("participantSid")]
public string ParticipantSid;
[JsonProperty("participantIdentity")]
public string ParticipantIdentity;
[JsonProperty("allowAll")]
public bool? AllowAll;
[JsonProperty("allowedTrackSids")]
Expand Down
32 changes: 16 additions & 16 deletions Runtime/Scripts/Room/Room.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,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 event ReconnectingDelegate Reconnecting;
public event ReconnectedDelegate Reconnected;
public event DisconnectedDelegate Disconnected;
Expand Down Expand Up @@ -83,7 +83,7 @@ private static void EventReceived(IntPtr iptr)
try
{
var room = Acquire<Room>(JSNative.GetFunctionInstance());

switch (evRef.Event)
{
case RoomEvent.Reconnecting:
Expand All @@ -100,7 +100,7 @@ private static void EventReceived(IntPtr iptr)
DisconnectReason? reason = null;
if(JSNative.IsNumber(pPtr))
reason = (DisconnectReason?) JSNative.GetNumber(pPtr);

Log.Debug($"Room: Received Disconnected({reason})");
room.Disconnected?.Invoke(reason);
break;
Expand Down Expand Up @@ -210,7 +210,7 @@ private static void EventReceived(IntPtr iptr)
string metadata = null;
if (JSNative.IsString(mdPtr))
metadata = JSNative.GetString(mdPtr);

var participant = Acquire<Participant>(JSNative.ShiftStack());
Log.Debug($"Room: Received ParticipantMetadataChanged(\"{metadata}\", {participant.Sid})");
room.ParticipantMetadataChanged?.Invoke(metadata, participant);
Expand Down Expand Up @@ -243,7 +243,7 @@ private static void EventReceived(IntPtr iptr)
DataPacketKind? kind = null;
if (JSNative.IsNumber(kindPtr))
kind = (DataPacketKind?) JSNative.GetNumber(kindPtr);

Log.Debug($"Room: Received DataReceived({data}, {participant?.Sid}, {kind})");
room.DataReceived?.Invoke(data.ToArray(), participant, kind);
break;
Expand Down Expand Up @@ -301,7 +301,7 @@ private static void EventReceived(IntPtr iptr)
Log.Error($"Error happened on RoomEvent.{evRef.Event} ( Is your listeners working correctly ? ): {Environment.NewLine} {e.Message}");
}
}

public bool IsClosed
{
get
Expand All @@ -310,7 +310,7 @@ public bool IsClosed
return JSNative.GetBoolean(JSNative.GetProperty(NativeHandle));
}
}

public ConnectionState State
{
get
Expand Down Expand Up @@ -340,7 +340,7 @@ public JSArray<Participant> ActiveSpeakers

public string Sid
{
get
get
{
JSNative.PushString("sid");
return JSNative.GetString(JSNative.GetProperty(NativeHandle));
Expand Down Expand Up @@ -428,26 +428,26 @@ public static JSPromise<JSArray<MediaDeviceInfo>> GetLocalDevices(MediaDeviceKin
JSNative.PushString(Utils.ToEnumString(kind.Value));
else
JSNative.PushUndefined();

if(requestPermissions.HasValue)
JSNative.PushBoolean(requestPermissions.Value);

return Acquire<JSPromise<JSArray<MediaDeviceInfo>>>(JSNative.CallMethod(roomClazz, "getLocalDevices"));
}

private void RegisterEvents()
{
foreach (var e in Enum.GetValues(typeof(RoomEvent)))
SetListener((RoomEvent) e, EventReceived);

SetKeepAlive(LocalParticipant, true);

ParticipantConnected += (p) => SetKeepAlive(p, true);
ParticipantDisconnected += (p) => SetKeepAlive(p, false);

LocalTrackPublished += (publication, participant) => SetKeepAlive(publication.Track, true);
LocalTrackUnpublished += (publication, participant) => SetKeepAlive(publication.Track, false);

TrackSubscribed += (track, publication, participant) => SetKeepAlive(track, true);
TrackUnsubscribed += (track, publication, participant) => SetKeepAlive(track, false);
}
Expand All @@ -468,7 +468,7 @@ public void Dispose()
Dispose(true);
GC.SuppressFinalize(this);
}

public void Disconnect(bool stopTracks = true)
{
JSNative.PushBoolean(stopTracks);
Expand All @@ -482,7 +482,7 @@ public Participant GetParticipantByIdentity(string identity)
var ptr = JSNative.CallMethod(NativeHandle, "getParticipantByIdentity");
if (!JSNative.IsObject(ptr))
return null;

return Acquire<Participant>(ptr);
}

Expand Down