Skip to content

Commit b16d41e

Browse files
authored
Merge pull request #177 from GetStream/feature/uni-131-add-features-to-the-example-project
Feature/uni 131 add features to the example project
2 parents 91cd7c8 + cce9e58 commit b16d41e

File tree

11 files changed

+100
-24
lines changed

11 files changed

+100
-24
lines changed

Assets/Samples/Stream Video & Audio Chat SDK/0.8.10.meta renamed to Assets/Samples/Stream Video & Audio Chat SDK/0.8.11.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.11/Video & Audio Chat Example Project/Scripts/StreamVideoManager.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ public async Task JoinAsync(string callId, bool create = true)
6666

6767
Debug.Log($"Join call, create: {create}, callId: {callId}");
6868
await Client.JoinCallAsync(StreamCallType.Default, callId, create, ring: true, notify: false);
69+
70+
if (_autoEnableMicrophone)
71+
{
72+
Client.AudioDeviceManager.SetEnabled(true);
73+
}
74+
75+
if (_autoEnableCamera)
76+
{
77+
Client.VideoDeviceManager.SetEnabled(true);
78+
}
6979

7080
if (_playOnCallStart)
7181
{
@@ -209,6 +219,13 @@ private string _info
209219

210220
[SerializeField]
211221
private bool _playOnCallStart = false;
222+
223+
[Header("Auto-enable devices on joining a call")]
224+
[SerializeField]
225+
private bool _autoEnableCamera = false;
226+
227+
[SerializeField]
228+
private bool _autoEnableMicrophone = false;
212229

213230
private StreamClientConfig _clientConfig;
214231
private IStreamCall _activeCall;

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,13 @@ protected void Update()
6464
{
6565
var rect = _videoRectTransform.rect;
6666
var videoRenderedSize = new Vector2(rect.width, rect.height);
67-
if (videoRenderedSize != _lastVideoRenderedSize)
67+
var forcedRequestedSize = new Vector2(_forceRequestedResolutionWidth, _forceRequestedResolutionHeight);
68+
var finalRequestedSize = _forceRequestedResolution ? forcedRequestedSize : videoRenderedSize;
69+
70+
if (_lastRequestedResolution != finalRequestedSize)
6871
{
69-
_lastVideoRenderedSize = videoRenderedSize;
70-
var videoResolution = new VideoResolution((int)videoRenderedSize.x, (int)videoRenderedSize.y);
72+
_lastRequestedResolution = finalRequestedSize;
73+
var videoResolution = new VideoResolution((int)finalRequestedSize.x, (int)finalRequestedSize.y);
7174

7275
// To optimize bandwidth we always request the video resolution that matches what we're actually rendering
7376
Participant.UpdateRequestedVideoResolution(videoResolution);
@@ -119,9 +122,18 @@ protected void OnDestroy()
119122
[SerializeField]
120123
private Color32 _defaultSpeakerFrameColor;
121124

125+
[SerializeField]
126+
private bool _forceRequestedResolution = false;
127+
128+
[SerializeField]
129+
private int _forceRequestedResolutionWidth = 300;
130+
131+
[SerializeField]
132+
private int _forceRequestedResolutionHeight = 300;
133+
122134
private AudioSource _audioSource;
123135
private RectTransform _videoRectTransform;
124-
private Vector2 _lastVideoRenderedSize;
136+
private Vector2 _lastRequestedResolution;
125137
private Quaternion _baseVideoRotation;
126138

127139
private void OnParticipantTrackAdded(IStreamVideoCallParticipant participant, IStreamTrack track)

Assets/Samples/Stream Video & Audio Chat SDK/0.8.11/Video & Audio Chat Example Project/Scripts/UI/Screens/MainScreenView.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,11 @@ private void OnLocalCameraChanged(WebCamTexture activeCamera)
140140

141141
private async Task<string> CreateRandomCallId()
142142
{
143-
var length = 4;
143+
var length = 3;
144+
var smallSet = true;
144145
for (var i = 0; i < 10; i++)
145146
{
146-
var callId = GenerateShortId(length);
147+
var callId = GenerateShortId(length, smallSet);
147148
var isAvailable = await VideoManager.IsCallIdAvailableToTake(callId);
148149
if (isAvailable)
149150
{
@@ -162,20 +163,24 @@ private async Task<string> CreateRandomCallId()
162163
if (i > 5)
163164
{
164165
length = 8;
166+
smallSet = false;
165167
}
166168

167169
}
168170

169171
throw new Exception("Failed to generate a unique call ID");
170172
}
171173

172-
public static string GenerateShortId(int length = 8)
174+
public static string GenerateShortId(int length = 8, bool smallSet = false)
173175
{
174176
// Some symbols, very close visually, are removed like: (1, l, I) or (O, 0)
175177
const string chars = "ABCDEFGHJKMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz23456789SBZGUV";
178+
const string charsSmallSet = "abcdefghjkmnpqrstuvwxyz1234567890";
179+
180+
var symbols = smallSet ? charsSmallSet : chars;
176181
var random = new System.Random();
177182

178-
return new string(Enumerable.Repeat(chars, length)
183+
return new string(Enumerable.Repeat(symbols, length)
179184
.Select(s => s[random.Next(s.Length)]).ToArray());
180185
}
181186
}

Assets/Samples/Stream Video & Audio Chat SDK/0.8.11/Video & Audio Chat Example Project/Scripts/UI/UIManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private async Task SelectFirstWorkingCameraOrDefaultAsync()
133133
var isWorking = await _videoManager.Client.VideoDeviceManager.TestDeviceAsync(device);
134134
if (isWorking)
135135
{
136-
_videoManager.Client.VideoDeviceManager.SelectDevice(device, enable: false);
136+
_videoManager.Client.VideoDeviceManager.SelectDevice(device, SenderVideoResolution, enable: false, _senderVideoFps);
137137
return;
138138
}
139139
}
@@ -142,7 +142,7 @@ private async Task SelectFirstWorkingCameraOrDefaultAsync()
142142
var workingDevice = await _videoManager.Client.VideoDeviceManager.TryFindFirstWorkingDeviceAsync();
143143
if (workingDevice.HasValue)
144144
{
145-
_videoManager.Client.VideoDeviceManager.SelectDevice(workingDevice.Value, enable: false);
145+
_videoManager.Client.VideoDeviceManager.SelectDevice(workingDevice.Value, SenderVideoResolution, enable: false, _senderVideoFps);
146146
return;
147147
}
148148

@@ -156,7 +156,7 @@ private async Task SelectFirstWorkingCameraOrDefaultAsync()
156156
return;
157157
}
158158

159-
_videoManager.Client.VideoDeviceManager.SelectDevice(firstDevice, enable: false);
159+
_videoManager.Client.VideoDeviceManager.SelectDevice(firstDevice, SenderVideoResolution, enable: false, _senderVideoFps);
160160
}
161161

162162
private void SelectFirstMicrophone()

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,10 @@ public async Task StopAsync(string reason = "")
393393
{
394394
// Trace leave call before leaving the call. Otherwise, stats are not send because SFU WS disconnects
395395
_sfuTracer?.Trace(PeerConnectionTraceKey.LeaveCall, new { SessionId = SessionId, Reason = reason });
396-
await _statsSender.SendFinalStatsAsync();
396+
if (_statsSender != null) // This was null in tests
397+
{
398+
await _statsSender.SendFinalStatsAsync();
399+
}
397400
}
398401
catch (Exception e)
399402
{

Packages/StreamVideo/Runtime/Core/Stats/WebRtcStatsSender.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ internal WebRtcStatsSender(RtcSession rtcSession, IWebRtcStatsCollector webRtcSt
7676

7777
private async Task CollectAndSend()
7878
{
79+
if (_rtcSession.ActiveCall == null)
80+
{
81+
return;
82+
}
83+
7984
var subscriberStatsJson = await _webRtcStatsCollector.GetSubscriberStatsJsonAsync();
8085
var publisherStatsJson = await _webRtcStatsCollector.GetPublisherStatsJsonAsync();
8186
var rtcStatsJson = await _webRtcStatsCollector.GetRtcStatsJsonAsync();

Packages/StreamVideo/Samples~/VideoChat/Scripts/StreamVideoManager.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ public async Task JoinAsync(string callId, bool create = true)
6666

6767
Debug.Log($"Join call, create: {create}, callId: {callId}");
6868
await Client.JoinCallAsync(StreamCallType.Default, callId, create, ring: true, notify: false);
69+
70+
if (_autoEnableMicrophone)
71+
{
72+
Client.AudioDeviceManager.SetEnabled(true);
73+
}
74+
75+
if (_autoEnableCamera)
76+
{
77+
Client.VideoDeviceManager.SetEnabled(true);
78+
}
6979

7080
if (_playOnCallStart)
7181
{
@@ -209,6 +219,13 @@ private string _info
209219

210220
[SerializeField]
211221
private bool _playOnCallStart = false;
222+
223+
[Header("Auto-enable devices on joining a call")]
224+
[SerializeField]
225+
private bool _autoEnableCamera = false;
226+
227+
[SerializeField]
228+
private bool _autoEnableMicrophone = false;
212229

213230
private StreamClientConfig _clientConfig;
214231
private IStreamCall _activeCall;

Packages/StreamVideo/Samples~/VideoChat/Scripts/UI/ParticipantView.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,13 @@ protected void Update()
6464
{
6565
var rect = _videoRectTransform.rect;
6666
var videoRenderedSize = new Vector2(rect.width, rect.height);
67-
if (videoRenderedSize != _lastVideoRenderedSize)
67+
var forcedRequestedSize = new Vector2(_forceRequestedResolutionWidth, _forceRequestedResolutionHeight);
68+
var finalRequestedSize = _forceRequestedResolution ? forcedRequestedSize : videoRenderedSize;
69+
70+
if (_lastRequestedResolution != finalRequestedSize)
6871
{
69-
_lastVideoRenderedSize = videoRenderedSize;
70-
var videoResolution = new VideoResolution((int)videoRenderedSize.x, (int)videoRenderedSize.y);
72+
_lastRequestedResolution = finalRequestedSize;
73+
var videoResolution = new VideoResolution((int)finalRequestedSize.x, (int)finalRequestedSize.y);
7174

7275
// To optimize bandwidth we always request the video resolution that matches what we're actually rendering
7376
Participant.UpdateRequestedVideoResolution(videoResolution);
@@ -119,9 +122,18 @@ protected void OnDestroy()
119122
[SerializeField]
120123
private Color32 _defaultSpeakerFrameColor;
121124

125+
[SerializeField]
126+
private bool _forceRequestedResolution = false;
127+
128+
[SerializeField]
129+
private int _forceRequestedResolutionWidth = 300;
130+
131+
[SerializeField]
132+
private int _forceRequestedResolutionHeight = 300;
133+
122134
private AudioSource _audioSource;
123135
private RectTransform _videoRectTransform;
124-
private Vector2 _lastVideoRenderedSize;
136+
private Vector2 _lastRequestedResolution;
125137
private Quaternion _baseVideoRotation;
126138

127139
private void OnParticipantTrackAdded(IStreamVideoCallParticipant participant, IStreamTrack track)

Packages/StreamVideo/Samples~/VideoChat/Scripts/UI/Screens/MainScreenView.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,11 @@ private void OnLocalCameraChanged(WebCamTexture activeCamera)
140140

141141
private async Task<string> CreateRandomCallId()
142142
{
143-
var length = 4;
143+
var length = 3;
144+
var smallSet = true;
144145
for (var i = 0; i < 10; i++)
145146
{
146-
var callId = GenerateShortId(length);
147+
var callId = GenerateShortId(length, smallSet);
147148
var isAvailable = await VideoManager.IsCallIdAvailableToTake(callId);
148149
if (isAvailable)
149150
{
@@ -162,20 +163,24 @@ private async Task<string> CreateRandomCallId()
162163
if (i > 5)
163164
{
164165
length = 8;
166+
smallSet = false;
165167
}
166168

167169
}
168170

169171
throw new Exception("Failed to generate a unique call ID");
170172
}
171173

172-
public static string GenerateShortId(int length = 8)
174+
public static string GenerateShortId(int length = 8, bool smallSet = false)
173175
{
174176
// Some symbols, very close visually, are removed like: (1, l, I) or (O, 0)
175177
const string chars = "ABCDEFGHJKMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz23456789SBZGUV";
178+
const string charsSmallSet = "abcdefghjkmnpqrstuvwxyz1234567890";
179+
180+
var symbols = smallSet ? charsSmallSet : chars;
176181
var random = new System.Random();
177182

178-
return new string(Enumerable.Repeat(chars, length)
183+
return new string(Enumerable.Repeat(symbols, length)
179184
.Select(s => s[random.Next(s.Length)]).ToArray());
180185
}
181186
}

0 commit comments

Comments
 (0)