Skip to content

Commit f3b89ec

Browse files
authored
Merge pull request #205 from GetStream/feature/uni-155-handle-sfu-audiolevelschanged-event
Feature/uni 155 handle sfu audiolevelschanged event
2 parents 6647e0c + ac42e49 commit f3b89ec

File tree

10 files changed

+548
-5
lines changed

10 files changed

+548
-5
lines changed

Assets/Samples/Stream Video & Audio Chat SDK/0.8.20.meta renamed to Assets/Samples/Stream Video & Audio Chat SDK/0.8.21.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Samples/Stream Video & Audio Chat SDK/0.8.21/Video & Audio Chat Example Project/Prefabs/UI/Screens/ParticipantView.prefab

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,139 @@
11
%YAML 1.1
22
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!1 &1859891430991424952
4+
GameObject:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
serializedVersion: 6
10+
m_Component:
11+
- component: {fileID: 6866918036725292465}
12+
- component: {fileID: 926551099080777182}
13+
- component: {fileID: 8686146479983388870}
14+
m_Layer: 5
15+
m_Name: AudioLevel
16+
m_TagString: Untagged
17+
m_Icon: {fileID: 0}
18+
m_NavMeshLayer: 0
19+
m_StaticEditorFlags: 0
20+
m_IsActive: 0
21+
--- !u!224 &6866918036725292465
22+
RectTransform:
23+
m_ObjectHideFlags: 0
24+
m_CorrespondingSourceObject: {fileID: 0}
25+
m_PrefabInstance: {fileID: 0}
26+
m_PrefabAsset: {fileID: 0}
27+
m_GameObject: {fileID: 1859891430991424952}
28+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
29+
m_LocalPosition: {x: 0, y: 0, z: 0}
30+
m_LocalScale: {x: 1, y: 1, z: 1}
31+
m_ConstrainProportionsScale: 0
32+
m_Children: []
33+
m_Father: {fileID: 2006121863080428319}
34+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
35+
m_AnchorMin: {x: 0, y: 0}
36+
m_AnchorMax: {x: 0, y: 0}
37+
m_AnchoredPosition: {x: 112.09, y: 39.4}
38+
m_SizeDelta: {x: 400, y: 50}
39+
m_Pivot: {x: 0, y: 0}
40+
--- !u!222 &926551099080777182
41+
CanvasRenderer:
42+
m_ObjectHideFlags: 0
43+
m_CorrespondingSourceObject: {fileID: 0}
44+
m_PrefabInstance: {fileID: 0}
45+
m_PrefabAsset: {fileID: 0}
46+
m_GameObject: {fileID: 1859891430991424952}
47+
m_CullTransparentMesh: 1
48+
--- !u!114 &8686146479983388870
49+
MonoBehaviour:
50+
m_ObjectHideFlags: 0
51+
m_CorrespondingSourceObject: {fileID: 0}
52+
m_PrefabInstance: {fileID: 0}
53+
m_PrefabAsset: {fileID: 0}
54+
m_GameObject: {fileID: 1859891430991424952}
55+
m_Enabled: 1
56+
m_EditorHideFlags: 0
57+
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
58+
m_Name:
59+
m_EditorClassIdentifier:
60+
m_Material: {fileID: 0}
61+
m_Color: {r: 1, g: 1, b: 1, a: 1}
62+
m_RaycastTarget: 1
63+
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
64+
m_Maskable: 1
65+
m_OnCullStateChanged:
66+
m_PersistentCalls:
67+
m_Calls: []
68+
m_text: 23
69+
m_isRightToLeft: 0
70+
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
71+
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
72+
m_fontSharedMaterials: []
73+
m_fontMaterial: {fileID: 0}
74+
m_fontMaterials: []
75+
m_fontColor32:
76+
serializedVersion: 2
77+
rgba: 4294967295
78+
m_fontColor: {r: 1, g: 1, b: 1, a: 1}
79+
m_enableVertexGradient: 0
80+
m_colorMode: 3
81+
m_fontColorGradient:
82+
topLeft: {r: 1, g: 1, b: 1, a: 1}
83+
topRight: {r: 1, g: 1, b: 1, a: 1}
84+
bottomLeft: {r: 1, g: 1, b: 1, a: 1}
85+
bottomRight: {r: 1, g: 1, b: 1, a: 1}
86+
m_fontColorGradientPreset: {fileID: 0}
87+
m_spriteAsset: {fileID: 0}
88+
m_tintAllSprites: 0
89+
m_StyleSheet: {fileID: 0}
90+
m_TextStyleHashCode: -1183493901
91+
m_overrideHtmlColors: 0
92+
m_faceColor:
93+
serializedVersion: 2
94+
rgba: 4294967295
95+
m_fontSize: 40
96+
m_fontSizeBase: 40
97+
m_fontWeight: 400
98+
m_enableAutoSizing: 0
99+
m_fontSizeMin: 18
100+
m_fontSizeMax: 72
101+
m_fontStyle: 0
102+
m_HorizontalAlignment: 1
103+
m_VerticalAlignment: 256
104+
m_textAlignment: 65535
105+
m_characterSpacing: 0
106+
m_wordSpacing: 0
107+
m_lineSpacing: 0
108+
m_lineSpacingMax: 0
109+
m_paragraphSpacing: 0
110+
m_charWidthMaxAdj: 0
111+
m_enableWordWrapping: 1
112+
m_wordWrappingRatios: 0.4
113+
m_overflowMode: 0
114+
m_linkedTextComponent: {fileID: 0}
115+
parentLinkedComponent: {fileID: 0}
116+
m_enableKerning: 1
117+
m_enableExtraPadding: 0
118+
checkPaddingRequired: 0
119+
m_isRichText: 1
120+
m_parseCtrlCharacters: 1
121+
m_isOrthographic: 1
122+
m_isCullingEnabled: 0
123+
m_horizontalMapping: 0
124+
m_verticalMapping: 0
125+
m_uvLineOffset: 0
126+
m_geometrySortingOrder: 0
127+
m_IsTextObjectScaleStatic: 0
128+
m_VertexBufferAutoSizeReduction: 0
129+
m_useMaxVisibleDescender: 1
130+
m_pageToDisplay: 1
131+
m_margin: {x: 0, y: 0, z: 0, w: 0}
132+
m_isUsingLegacyAnimationComponent: 0
133+
m_isVolumetricText: 0
134+
m_hasFontAssetChanged: 0
135+
m_baseMaterial: {fileID: 0}
136+
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
3137
--- !u!1 &2006121863080428312
4138
GameObject:
5139
m_ObjectHideFlags: 0
@@ -34,6 +168,8 @@ RectTransform:
34168
- {fileID: 7252032941131618416}
35169
- {fileID: 7637150640667577125}
36170
- {fileID: 3604744137779619309}
171+
- {fileID: 1036960430990650392}
172+
- {fileID: 6866918036725292465}
37173
m_Father: {fileID: 2006121863544806348}
38174
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
39175
m_AnchorMin: {x: 0, y: 0}
@@ -193,6 +329,8 @@ MonoBehaviour:
193329
_forceRequestedResolutionHeight: 300
194330
_isMutedIcon: {fileID: 7852245601941594288}
195331
_muteLocallyToggleButton: {fileID: 6073022831238027141}
332+
_audioLevel: {fileID: 8686146479983388870}
333+
_isSpeakingIcon: {fileID: 4664516320093859518}
196334
--- !u!1 &2006121864280196914
197335
GameObject:
198336
m_ObjectHideFlags: 0
@@ -348,6 +486,81 @@ MonoBehaviour:
348486
m_FlexibleWidth: -1
349487
m_FlexibleHeight: -1
350488
m_LayoutPriority: 1
489+
--- !u!1 &4664516320093859518
490+
GameObject:
491+
m_ObjectHideFlags: 0
492+
m_CorrespondingSourceObject: {fileID: 0}
493+
m_PrefabInstance: {fileID: 0}
494+
m_PrefabAsset: {fileID: 0}
495+
serializedVersion: 6
496+
m_Component:
497+
- component: {fileID: 1036960430990650392}
498+
- component: {fileID: 8542746723167520707}
499+
- component: {fileID: 5072929113691457332}
500+
m_Layer: 5
501+
m_Name: IsSpeakingIcon
502+
m_TagString: Untagged
503+
m_Icon: {fileID: 0}
504+
m_NavMeshLayer: 0
505+
m_StaticEditorFlags: 0
506+
m_IsActive: 1
507+
--- !u!224 &1036960430990650392
508+
RectTransform:
509+
m_ObjectHideFlags: 0
510+
m_CorrespondingSourceObject: {fileID: 0}
511+
m_PrefabInstance: {fileID: 0}
512+
m_PrefabAsset: {fileID: 0}
513+
m_GameObject: {fileID: 4664516320093859518}
514+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
515+
m_LocalPosition: {x: 0, y: 0, z: 0}
516+
m_LocalScale: {x: 1, y: 1, z: 1}
517+
m_ConstrainProportionsScale: 0
518+
m_Children: []
519+
m_Father: {fileID: 2006121863080428319}
520+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
521+
m_AnchorMin: {x: 0, y: 0}
522+
m_AnchorMax: {x: 0, y: 0}
523+
m_AnchoredPosition: {x: 10, y: 10}
524+
m_SizeDelta: {x: 100, y: 100}
525+
m_Pivot: {x: 0, y: 0}
526+
--- !u!222 &8542746723167520707
527+
CanvasRenderer:
528+
m_ObjectHideFlags: 0
529+
m_CorrespondingSourceObject: {fileID: 0}
530+
m_PrefabInstance: {fileID: 0}
531+
m_PrefabAsset: {fileID: 0}
532+
m_GameObject: {fileID: 4664516320093859518}
533+
m_CullTransparentMesh: 1
534+
--- !u!114 &5072929113691457332
535+
MonoBehaviour:
536+
m_ObjectHideFlags: 0
537+
m_CorrespondingSourceObject: {fileID: 0}
538+
m_PrefabInstance: {fileID: 0}
539+
m_PrefabAsset: {fileID: 0}
540+
m_GameObject: {fileID: 4664516320093859518}
541+
m_Enabled: 1
542+
m_EditorHideFlags: 0
543+
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
544+
m_Name:
545+
m_EditorClassIdentifier:
546+
m_Material: {fileID: 0}
547+
m_Color: {r: 0, g: 1, b: 0.030314207, a: 1}
548+
m_RaycastTarget: 1
549+
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
550+
m_Maskable: 1
551+
m_OnCullStateChanged:
552+
m_PersistentCalls:
553+
m_Calls: []
554+
m_Sprite: {fileID: 10913, guid: 0000000000000000f000000000000000, type: 0}
555+
m_Type: 0
556+
m_PreserveAspect: 0
557+
m_FillCenter: 1
558+
m_FillMethod: 4
559+
m_FillAmount: 1
560+
m_FillClockwise: 1
561+
m_FillOrigin: 0
562+
m_UseSpriteMesh: 0
563+
m_PixelsPerUnitMultiplier: 1
351564
--- !u!1 &5510979313677697257
352565
GameObject:
353566
m_ObjectHideFlags: 0

Assets/Samples/Stream Video & Audio Chat SDK/0.8.21/Video & Audio Chat Example Project/Scripts/UI/ParticipantView.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ public void Init(IStreamVideoCallParticipant participant, StreamVideoManager vid
2828
OnParticipantTrackAdded(Participant, track);
2929
}
3030

31+
OnIsSpeakingChanged(Participant.IsSpeaking);
32+
OnAudioLevelChanged(Participant.AudioLevel);
33+
3134
Participant.TrackAdded += OnParticipantTrackAdded;
35+
Participant.AudioLevelChanged += OnAudioLevelChanged;
36+
Participant.IsSpeakingChanged += OnIsSpeakingChanged;
3237

3338
_name.text = Participant.Name;
3439
}
@@ -107,6 +112,8 @@ protected void OnDestroy()
107112
if (Participant != null)
108113
{
109114
Participant.TrackAdded -= OnParticipantTrackAdded;
115+
Participant.AudioLevelChanged -= OnAudioLevelChanged;
116+
Participant.IsSpeakingChanged -= OnIsSpeakingChanged;
110117
}
111118
}
112119

@@ -140,6 +147,12 @@ protected void OnDestroy()
140147
[SerializeField]
141148
private Button _muteLocallyToggleButton;
142149

150+
[SerializeField]
151+
private TMP_Text _audioLevel;
152+
153+
[SerializeField]
154+
private GameObject _isSpeakingIcon;
155+
143156
private AudioSource _audioSource;
144157
private RectTransform _videoRectTransform;
145158
private Vector2 _lastRequestedResolution;
@@ -211,5 +224,15 @@ private void UpdateMuteIcon()
211224
var isMuted = _videoManager.IsParticipantMutedLocally(Participant);
212225
_isMutedIcon.SetActive(isMuted);
213226
}
227+
228+
private void OnIsSpeakingChanged(bool isSpeaking)
229+
{
230+
_isSpeakingIcon.SetActive(isSpeaking);
231+
}
232+
233+
private void OnAudioLevelChanged(float audioLevel)
234+
{
235+
_audioLevel.text = audioLevel.ToString();
236+
}
214237
}
215238
}

Packages/StreamVideo/Runtime/Core/LowLevelClient/RtcSession.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,8 +1421,8 @@ private void OnSfuConnectionQualityChanged(ConnectionQualityChanged connectionQu
14211421

14221422
private void OnSfuAudioLevelChanged(AudioLevelChanged audioLevelChanged)
14231423
{
1424-
1425-
// StreamTODO: Implement OnSfuAudioLevelChanged
1424+
// Ignore tracing AudioLevelChanged -> not much debug value + creates too much noise in data
1425+
ActiveCall?.UpdateFromSfu(audioLevelChanged);
14261426
}
14271427

14281428
private void OnSfuPublisherAnswer(PublisherAnswer publisherAnswer)

Packages/StreamVideo/Runtime/Core/Models/CallSession.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,5 +232,19 @@ private void UpdateParticipantCountFromSessionInternal(int anonymousParticipantC
232232
((IStateLoadableFrom<SfuParticipantCount, ParticipantCount>)ParticipantCount)
233233
.LoadFromDto(dto, null);
234234
}
235+
236+
internal void UpdateFromSfu(AudioLevelChanged audioLevelChanged)
237+
{
238+
foreach (var entry in audioLevelChanged.AudioLevels)
239+
{
240+
for (int i = 0; i < _participants.Count; i++)
241+
{
242+
if (_participants[i].SessionId == entry.SessionId)
243+
{
244+
_participants[i].UpdateFromSfu(entry);
245+
}
246+
}
247+
}
248+
}
235249
}
236250
}

Packages/StreamVideo/Runtime/Core/StatefulModels/IStreamVideoCallParticipant.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ public interface IStreamVideoCallParticipant : IStreamStatefulModel, IHasCustomD
2222
/// </summary>
2323
event ParticipantTrackChangedHandler TrackIsEnabledChanged;
2424

25+
/// <summary>
26+
/// Event notifying that the value of <see cref="AudioLevel"/> changed for this participant. The event callback contains the current value of <see cref="AudioLevel"/>
27+
/// </summary>
28+
event Action<float> AudioLevelChanged;
29+
30+
/// <summary>
31+
/// Event notifying that the value of <see cref="IsSpeaking"/> changed for this participant. The event callback contains the current value of <see cref="IsSpeaking"/>
32+
/// </summary>
33+
event Action<bool> IsSpeakingChanged;
34+
2535
/// <summary>
2636
/// Is this participant "pinned" in the call meaning it will have precedence in <see cref="IStreamCall.SortedParticipants"/> list
2737
/// </summary>

Packages/StreamVideo/Runtime/Core/StatefulModels/StreamCall.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,11 @@ internal void UpdateFromSfu(HealthCheckResponse healthCheckResponse, ICache cach
720720
{
721721
Session?.UpdateFromSfu(healthCheckResponse, cache);
722722
}
723+
724+
internal void UpdateFromSfu(AudioLevelChanged audioLevelChanged)
725+
{
726+
Session?.UpdateFromSfu(audioLevelChanged);
727+
}
723728

724729
internal void UpdateFromCoordinator(CallSessionParticipantCountsUpdatedEventInternalDTO eventData)
725730
{

0 commit comments

Comments
 (0)