Skip to content

Commit

Permalink
Add pinnings docs + add IsPinned
Browse files Browse the repository at this point in the history
  • Loading branch information
sierpinskid committed Dec 21, 2023
1 parent ccec02f commit e1b948b
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using System.Linq;
using System.Threading.Tasks;
using StreamVideo.Core;

namespace DocsCodeSamples._03_guides
{
/// <summary>
/// Code examples for guides/pinning-participants/ page
/// </summary>
internal class CallParticipantsPinning
{
public async Task PinLocally()
{
var callType = StreamCallType.Default; // Call type affects default permissions
var callId = "my-call-id";

// Get call or create if it doesn't exist
var streamCall = await _client.GetOrCreateCallAsync(callType, callId);

var participant = streamCall.Participants.First();

streamCall.PinLocally(participant);
}

public async Task UnpinLocally()
{
var callType = StreamCallType.Default; // Call type affects default permissions
var callId = "my-call-id";

// Get call or create if it doesn't exist
var streamCall = await _client.GetOrCreateCallAsync(callType, callId);

var participant = streamCall.Participants.First();

streamCall.UnpinLocally(participant);
}

public async Task GetPinnedParticipants()
{
var callType = StreamCallType.Default; // Call type affects default permissions
var callId = "my-call-id";

// Get call or create if it doesn't exist
var streamCall = await _client.GetOrCreateCallAsync(callType, callId);

var participant = streamCall.Participants.First();

streamCall.PinLocally(participant);

foreach (var pinnedParticipant in streamCall.PinnedParticipants)
{
// Iterate through pinned participants
}
}

public async Task CheckIfParticipantIsPinned()
{
var callType = StreamCallType.Default; // Call type affects default permissions
var callId = "my-call-id";

// Get call or create if it doesn't exist
var streamCall = await _client.GetOrCreateCallAsync(callType, callId);

var participant = streamCall.Participants.First();

streamCall.PinLocally(participant);

var isPinned = streamCall.IsPinnedLocally(participant);
var isPinnedLocally = streamCall.IsPinnedLocally(participant);
var isPinnedRemotely = streamCall.IsPinnedRemotely(participant);
}

private IStreamVideoClient _client;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions Packages/StreamVideo/Runtime/Core/StatefulModels/IStreamCall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,5 +251,23 @@ Task<QueryMembersResult> QueryMembersAsync(IEnumerable<IFieldFilterRule> filters
/// </summary>
/// <param name="participant">Participant to unpin</param>
void UnpinLocally(IStreamVideoCallParticipant participant);

/// <summary>
/// Check if this participant is pinned locally. Also check <see cref="IsPinnedRemotely"/> & <see cref="IsPinned"/>.
/// </summary>
/// <returns>True if participant is pinned locally</returns>
bool IsPinnedLocally(IStreamVideoCallParticipant participant);

/// <summary>
/// Check if this participant is pinned remotely. Also check <see cref="IsPinnedLocally"/> & <see cref="IsPinned"/>.
/// </summary>
/// <returns>True if participant is pinned remotely</returns>
bool IsPinnedRemotely(IStreamVideoCallParticipant participant);

/// <summary>
/// Check if this participant is pinned. Also check <see cref="IsPinnedLocally"/> & <see cref="IsPinnedRemotely"/>.
/// </summary>
/// <returns>True if participant is pinned remotely</returns>
bool IsPinned(IStreamVideoCallParticipant participant);
}
}
18 changes: 13 additions & 5 deletions Packages/StreamVideo/Runtime/Core/StatefulModels/StreamCall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@ public Task SendCustomEventAsync(Dictionary<string, object> eventData)
// {
// return Task.CompletedTask; //StreamTodo: implement
// }

public Task AcceptAsync() => LowLevelClient.InternalVideoClientApi.AcceptCallAsync(Type, Id);

public Task RejectAsync() => LowLevelClient.InternalVideoClientApi.RejectCallAsync(Type, Id);
Expand Down Expand Up @@ -370,6 +369,15 @@ public void UnpinLocally(IStreamVideoCallParticipant participant)
UpdateSortedParticipants();
}

public bool IsPinnedLocally(IStreamVideoCallParticipant participant)
=> _localPinsSessionIds.Contains(participant.SessionId);

public bool IsPinnedRemotely(IStreamVideoCallParticipant participant)
=> _serverPinsSessionIds.Contains(participant.SessionId);

public bool IsPinned(IStreamVideoCallParticipant participant)
=> IsPinnedLocally(participant) || IsPinnedRemotely(participant);

void IUpdateableFrom<CallResponseInternalDTO, StreamCall>.UpdateFromDto(CallResponseInternalDTO dto,
ICache cache)
{
Expand Down Expand Up @@ -466,7 +474,7 @@ internal void UpdateFromSfu(ParticipantLeft participantLeft, ICache cache)
UpdateSortedParticipants();

cache.CallParticipants.TryRemove(participant.sessionId);

//StreamTodo: if we delete the participant from cache we should then pass SessionId and UserId
ParticipantLeft?.Invoke(participant.sessionId, participant.userId);
}
Expand Down Expand Up @@ -543,15 +551,15 @@ private void UpdatePinnedParticipants()
//StreamTodo: use hashset pool to optimize
foreach (var participant in Participants)
{
if (_localPinsSessionIds.Contains(participant.SessionId))
if (_serverPinsSessionIds.Contains(participant.SessionId))
{
_pinnedParticipants.Add(participant);
}
}

foreach (var participant in Participants)
{
if (_serverPinsSessionIds.Contains(participant.SessionId))
if (_localPinsSessionIds.Contains(participant.SessionId))
{
_pinnedParticipants.Add(participant);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using StreamVideo.Core.StatefulModels.Tracks;
using StreamVideo.Core.Utils;
using Unity.WebRTC;
using UnityEngine;
using Participant = Stream.Video.v1.Sfu.Models.Participant;

namespace StreamVideo.Core.StatefulModels
Expand Down Expand Up @@ -128,7 +127,7 @@ internal void SetTrack(TrackType type, MediaStreamTrack mediaStreamTrack, out IS
{

#if STREAM_DEBUG_ENABLED
Debug.LogWarning(
Logs.Warning(
$"[Participant] Local: {IsLocalParticipant} Session ID: {SessionId} set track of type {type}");
#endif

Expand Down
41 changes: 41 additions & 0 deletions docusaurus/docs/Unity/03-guides/09-pinning-call-participants.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
title: Pinning participants
description: How to pin participants
---

The StreamVideo SDK has support for pinning users, both locally for the current user, and remotely for everyone in the call.
Every user can pin as many participants on the call as they want, and those users will be shown first in the list of participants for that user. Pinning someone for everyone in the call requires the `pinForEveryone` capability.
By default, the pinned users appear first in the `streamCall.SortedParticipants` array. The ones which are pinned remotely appear before the local ones. If there are several remotely pinned users, they are sorted by the pinning date (the most recent pins appear first).

### Local pins
In order to pin a user locally:

```csharp
streamCall.PinLocally(participant);
```

To unpin the user:
```csharp
streamCall.UnpinLocally(participant);
```

In both examples, the `participant` is an object of type `IStreamVideoCallParticipant`.

To get all pinned participants:
```csharp
foreach (var pinnedParticipant in streamCall.PinnedParticipants)
{
// Iterate through pinned participants
}
```

You can check if the participant is pinned either locally or remotely by:
```csharp
var isPinned = streamCall.IsPinnedLocally(participant);
```

Or to distinguish whether the participant is pinned locally or remotely you can more specific versions:
```csharp
var isPinnedLocally = streamCall.IsPinnedLocally(participant);
var isPinnedRemotely = streamCall.IsPinnedRemotely(participant);
```

0 comments on commit e1b948b

Please sign in to comment.