Skip to content

Commit

Permalink
[Docs] Update audio tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
sierpinskid committed Nov 23, 2023
1 parent 619576e commit 486b87f
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions docusaurus/docs/Unity/02-tutorials/02-audio-room.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -674,15 +674,15 @@ private IStreamVideoCallParticipant _participant;

---

Next, add the following field to the `AudioRoomsManager` class:
Next, add the following field to the `UIManager` class:
```csharp
private readonly Dictionary<string, ParticipantPanel> _callParticipantBySessionId
= new Dictionary<string, ParticipantPanel>();
```

We'll use this to reference the `ParticipantPanel` component we'll create for every participant. We keep references in the dictionary where a `SessionId` will be the key. This way, whenever a participant leaves the call, we can easily find and destroy the corresponding game object.

Next, add this method to the `AudioRoomsManager` class:
Next, add this method to the `UIManager` class:
```csharp
private void OnParticipantJoined(IStreamVideoCallParticipant participant)
{
Expand All @@ -698,7 +698,7 @@ The `OnParticipantJoined` method will be executed for each call participant. It
* Calls the `ParticipantPanel.Init` method and passes the `IStreamVideoCallParticipant` object.
* Adds the newly spawned panel to the `_participantPanels` dictionary using the participant's **SessionId** as key.

Next, add the `OnParticipantLeft` method to the `AudioRoomsManager` class:
Next, add the `OnParticipantLeft` method to the `UIManager` class:
```csharp
private void OnParticipantLeft(string sessionId, string userid)
{
Expand All @@ -720,6 +720,29 @@ private void OnParticipantLeft(string sessionId, string userid)

The `OnParticipantLeft` will be called whenever a participant leaves the call. We're attempting to find the `ParticipantPanel` component using the participant's `sessionId` in the `_callParticipantBySessionId` dictionary and destroy its game object.

---

Next open the `AudioRoomsManager.cs` script and apply the following changes:

First, add the following events:
```csharp
public Action<IStreamVideoCallParticipant> ParticipantJoined;
public Action<string> ParticipantLeft;
```

Next, add these 2 methods:
```csharp
private void OnParticipantJoined(IStreamVideoCallParticipant participant)
{
ParticipantJoined?.Invoke(participant);
}

private void OnParticipantLeft(string sessionId, string userid)
{
ParticipantLeft?.Invoke(sessionId);
}
```

Next, replace the `JoinCallAsync` method with the following code:
```csharp
public async Task JoinCallAsync(string callId)
Expand Down

0 comments on commit 486b87f

Please sign in to comment.