Skip to content
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

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

Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ public async Task JoinAsync(string callId, bool create = true)

Debug.Log($"Join call, create: {create}, callId: {callId}");
await Client.JoinCallAsync(StreamCallType.Default, callId, create, ring: true, notify: false);

if (_autoEnableMicrophone)
{
Client.AudioDeviceManager.SetEnabled(true);
}

if (_autoEnableCamera)
{
Client.VideoDeviceManager.SetEnabled(true);
}

if (_playOnCallStart)
{
Expand Down Expand Up @@ -209,6 +219,13 @@ private string _info

[SerializeField]
private bool _playOnCallStart = false;

[Header("Auto-enable devices on joining a call")]
[SerializeField]
private bool _autoEnableCamera = false;

[SerializeField]
private bool _autoEnableMicrophone = false;

private StreamClientConfig _clientConfig;
private IStreamCall _activeCall;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,13 @@ protected void Update()
{
var rect = _videoRectTransform.rect;
var videoRenderedSize = new Vector2(rect.width, rect.height);
if (videoRenderedSize != _lastVideoRenderedSize)
var forcedRequestedSize = new Vector2(_forceRequestedResolutionWidth, _forceRequestedResolutionHeight);
var finalRequestedSize = _forceRequestedResolution ? forcedRequestedSize : videoRenderedSize;

if (_lastRequestedResolution != finalRequestedSize)
{
_lastVideoRenderedSize = videoRenderedSize;
var videoResolution = new VideoResolution((int)videoRenderedSize.x, (int)videoRenderedSize.y);
_lastRequestedResolution = finalRequestedSize;
var videoResolution = new VideoResolution((int)finalRequestedSize.x, (int)finalRequestedSize.y);

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

[SerializeField]
private bool _forceRequestedResolution = false;

[SerializeField]
private int _forceRequestedResolutionWidth = 300;

[SerializeField]
private int _forceRequestedResolutionHeight = 300;

private AudioSource _audioSource;
private RectTransform _videoRectTransform;
private Vector2 _lastVideoRenderedSize;
private Vector2 _lastRequestedResolution;
private Quaternion _baseVideoRotation;

private void OnParticipantTrackAdded(IStreamVideoCallParticipant participant, IStreamTrack track)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,11 @@ private void OnLocalCameraChanged(WebCamTexture activeCamera)

private async Task<string> CreateRandomCallId()
{
var length = 4;
var length = 3;
var smallSet = true;
for (var i = 0; i < 10; i++)
{
var callId = GenerateShortId(length);
var callId = GenerateShortId(length, smallSet);
var isAvailable = await VideoManager.IsCallIdAvailableToTake(callId);
if (isAvailable)
{
Expand All @@ -162,20 +163,24 @@ private async Task<string> CreateRandomCallId()
if (i > 5)
{
length = 8;
smallSet = false;
}

}

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

public static string GenerateShortId(int length = 8)
public static string GenerateShortId(int length = 8, bool smallSet = false)
{
// Some symbols, very close visually, are removed like: (1, l, I) or (O, 0)
const string chars = "ABCDEFGHJKMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz23456789SBZGUV";
const string charsSmallSet = "abcdefghjkmnpqrstuvwxyz1234567890";

var symbols = smallSet ? charsSmallSet : chars;
var random = new System.Random();

return new string(Enumerable.Repeat(chars, length)
return new string(Enumerable.Repeat(symbols, length)
.Select(s => s[random.Next(s.Length)]).ToArray());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private async Task SelectFirstWorkingCameraOrDefaultAsync()
var isWorking = await _videoManager.Client.VideoDeviceManager.TestDeviceAsync(device);
if (isWorking)
{
_videoManager.Client.VideoDeviceManager.SelectDevice(device, enable: false);
_videoManager.Client.VideoDeviceManager.SelectDevice(device, SenderVideoResolution, enable: false, _senderVideoFps);
return;
}
}
Expand All @@ -142,7 +142,7 @@ private async Task SelectFirstWorkingCameraOrDefaultAsync()
var workingDevice = await _videoManager.Client.VideoDeviceManager.TryFindFirstWorkingDeviceAsync();
if (workingDevice.HasValue)
{
_videoManager.Client.VideoDeviceManager.SelectDevice(workingDevice.Value, enable: false);
_videoManager.Client.VideoDeviceManager.SelectDevice(workingDevice.Value, SenderVideoResolution, enable: false, _senderVideoFps);
return;
}

Expand All @@ -156,7 +156,7 @@ private async Task SelectFirstWorkingCameraOrDefaultAsync()
return;
}

_videoManager.Client.VideoDeviceManager.SelectDevice(firstDevice, enable: false);
_videoManager.Client.VideoDeviceManager.SelectDevice(firstDevice, SenderVideoResolution, enable: false, _senderVideoFps);
}

private void SelectFirstMicrophone()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,10 @@ public async Task StopAsync(string reason = "")
{
// Trace leave call before leaving the call. Otherwise, stats are not send because SFU WS disconnects
_sfuTracer?.Trace(PeerConnectionTraceKey.LeaveCall, new { SessionId = SessionId, Reason = reason });
await _statsSender.SendFinalStatsAsync();
if (_statsSender != null) // This was null in tests
{
await _statsSender.SendFinalStatsAsync();
}
}
catch (Exception e)
{
Expand Down
5 changes: 5 additions & 0 deletions Packages/StreamVideo/Runtime/Core/Stats/WebRtcStatsSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ internal WebRtcStatsSender(RtcSession rtcSession, IWebRtcStatsCollector webRtcSt

private async Task CollectAndSend()
{
if (_rtcSession.ActiveCall == null)
{
return;
}

var subscriberStatsJson = await _webRtcStatsCollector.GetSubscriberStatsJsonAsync();
var publisherStatsJson = await _webRtcStatsCollector.GetPublisherStatsJsonAsync();
var rtcStatsJson = await _webRtcStatsCollector.GetRtcStatsJsonAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ public async Task JoinAsync(string callId, bool create = true)

Debug.Log($"Join call, create: {create}, callId: {callId}");
await Client.JoinCallAsync(StreamCallType.Default, callId, create, ring: true, notify: false);

if (_autoEnableMicrophone)
{
Client.AudioDeviceManager.SetEnabled(true);
}

if (_autoEnableCamera)
{
Client.VideoDeviceManager.SetEnabled(true);
}

if (_playOnCallStart)
{
Expand Down Expand Up @@ -209,6 +219,13 @@ private string _info

[SerializeField]
private bool _playOnCallStart = false;

[Header("Auto-enable devices on joining a call")]
[SerializeField]
private bool _autoEnableCamera = false;

[SerializeField]
private bool _autoEnableMicrophone = false;

private StreamClientConfig _clientConfig;
private IStreamCall _activeCall;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,13 @@ protected void Update()
{
var rect = _videoRectTransform.rect;
var videoRenderedSize = new Vector2(rect.width, rect.height);
if (videoRenderedSize != _lastVideoRenderedSize)
var forcedRequestedSize = new Vector2(_forceRequestedResolutionWidth, _forceRequestedResolutionHeight);
var finalRequestedSize = _forceRequestedResolution ? forcedRequestedSize : videoRenderedSize;

if (_lastRequestedResolution != finalRequestedSize)
{
_lastVideoRenderedSize = videoRenderedSize;
var videoResolution = new VideoResolution((int)videoRenderedSize.x, (int)videoRenderedSize.y);
_lastRequestedResolution = finalRequestedSize;
var videoResolution = new VideoResolution((int)finalRequestedSize.x, (int)finalRequestedSize.y);

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

[SerializeField]
private bool _forceRequestedResolution = false;

[SerializeField]
private int _forceRequestedResolutionWidth = 300;

[SerializeField]
private int _forceRequestedResolutionHeight = 300;

private AudioSource _audioSource;
private RectTransform _videoRectTransform;
private Vector2 _lastVideoRenderedSize;
private Vector2 _lastRequestedResolution;
private Quaternion _baseVideoRotation;

private void OnParticipantTrackAdded(IStreamVideoCallParticipant participant, IStreamTrack track)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,11 @@ private void OnLocalCameraChanged(WebCamTexture activeCamera)

private async Task<string> CreateRandomCallId()
{
var length = 4;
var length = 3;
var smallSet = true;
for (var i = 0; i < 10; i++)
{
var callId = GenerateShortId(length);
var callId = GenerateShortId(length, smallSet);
var isAvailable = await VideoManager.IsCallIdAvailableToTake(callId);
if (isAvailable)
{
Expand All @@ -162,20 +163,24 @@ private async Task<string> CreateRandomCallId()
if (i > 5)
{
length = 8;
smallSet = false;
}

}

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

public static string GenerateShortId(int length = 8)
public static string GenerateShortId(int length = 8, bool smallSet = false)
{
// Some symbols, very close visually, are removed like: (1, l, I) or (O, 0)
const string chars = "ABCDEFGHJKMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz23456789SBZGUV";
const string charsSmallSet = "abcdefghjkmnpqrstuvwxyz1234567890";

var symbols = smallSet ? charsSmallSet : chars;
var random = new System.Random();

return new string(Enumerable.Repeat(chars, length)
return new string(Enumerable.Repeat(symbols, length)
.Select(s => s[random.Next(s.Length)]).ToArray());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private async Task SelectFirstWorkingCameraOrDefaultAsync()
var isWorking = await _videoManager.Client.VideoDeviceManager.TestDeviceAsync(device);
if (isWorking)
{
_videoManager.Client.VideoDeviceManager.SelectDevice(device, enable: false);
_videoManager.Client.VideoDeviceManager.SelectDevice(device, SenderVideoResolution, enable: false, _senderVideoFps);
return;
}
}
Expand All @@ -142,7 +142,7 @@ private async Task SelectFirstWorkingCameraOrDefaultAsync()
var workingDevice = await _videoManager.Client.VideoDeviceManager.TryFindFirstWorkingDeviceAsync();
if (workingDevice.HasValue)
{
_videoManager.Client.VideoDeviceManager.SelectDevice(workingDevice.Value, enable: false);
_videoManager.Client.VideoDeviceManager.SelectDevice(workingDevice.Value, SenderVideoResolution, enable: false, _senderVideoFps);
return;
}

Expand All @@ -156,7 +156,7 @@ private async Task SelectFirstWorkingCameraOrDefaultAsync()
return;
}

_videoManager.Client.VideoDeviceManager.SelectDevice(firstDevice, enable: false);
_videoManager.Client.VideoDeviceManager.SelectDevice(firstDevice, SenderVideoResolution, enable: false, _senderVideoFps);
}

private void SelectFirstMicrophone()
Expand Down
Loading