Init: Debugging
This commit is contained in:
@@ -44,7 +44,7 @@ public partial class MainPage : ContentPage
|
|||||||
_wsc.Send("GET_SERVER_KEY");
|
_wsc.Send("GET_SERVER_KEY");
|
||||||
_wsc.Send("GET_CHANNELS");
|
_wsc.Send("GET_CHANNELS");
|
||||||
|
|
||||||
webRTCTest();
|
_ = webRTCTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SendButton_OnClicked(object? sender, EventArgs e)
|
private void SendButton_OnClicked(object? sender, EventArgs e)
|
||||||
@@ -295,66 +295,144 @@ public partial class MainPage : ContentPage
|
|||||||
|
|
||||||
private async Task webRTCTest()
|
private async Task webRTCTest()
|
||||||
{
|
{
|
||||||
// var path = "D:\\DDI\\Relay\\RelayChat\\RelayCore\\RelayClient\\bin\\debug.txt";
|
var path = Path.GetFullPath(
|
||||||
// AudioTrackSource microphoneSource = null;
|
Path.Combine(AppContext.BaseDirectory, @"..\..\..\debug.txt")
|
||||||
// VideoTrackSource webcamSource = null;
|
);
|
||||||
// Transceiver audioTransceiver = null;
|
|
||||||
// Transceiver videoTransceiver = null;
|
void Log(string msg)
|
||||||
// LocalAudioTrack localAudioTrack = null;
|
{
|
||||||
// LocalVideoTrack localVideoTrack = null;
|
File.AppendAllText(path, msg + Environment.NewLine);
|
||||||
|
Console.WriteLine(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
AudioTrackSource? microphoneSource = null;
|
||||||
|
DeviceVideoTrackSource? webcamSource = null;
|
||||||
|
Transceiver? audioTransceiver = null;
|
||||||
|
Transceiver? videoTransceiver = null;
|
||||||
|
LocalAudioTrack? localAudioTrack = null;
|
||||||
|
LocalVideoTrack? localVideoTrack = null;
|
||||||
|
|
||||||
|
Log("=== WebRTC TEST START ===");
|
||||||
|
|
||||||
|
IReadOnlyList<VideoCaptureDevice>? deviceList = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var deviceList = await DeviceVideoTrackSource.GetCaptureDevicesAsync();
|
Log("Getting video devices...");
|
||||||
string devices = "";
|
|
||||||
|
deviceList = await DeviceVideoTrackSource.GetCaptureDevicesAsync();
|
||||||
|
|
||||||
foreach (var device in deviceList)
|
foreach (var device in deviceList)
|
||||||
{
|
{
|
||||||
devices += $"Found device: {device.name} (id: {device.id})\n";
|
Log($"Found device: {device.name} (id: {device.id})");
|
||||||
Console.WriteLine($"Found device: {device.name} (id: {device.id})");
|
|
||||||
}
|
}
|
||||||
File.WriteAllText(path, devices);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
File.WriteAllText(path, e.Message);
|
|
||||||
Console.WriteLine(e);
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
|
|
||||||
using var pc = new PeerConnection();
|
|
||||||
var config = new PeerConnectionConfiguration
|
|
||||||
{
|
|
||||||
IceServers = new List<IceServer>
|
|
||||||
{
|
|
||||||
new IceServer { Urls = { "stun:stun.l.google.com:19302" } }
|
|
||||||
}
|
|
||||||
};
|
|
||||||
await pc.InitializeAsync(config);
|
|
||||||
|
|
||||||
// webcamSource = await DeviceVideoTrackSource.CreateAsync();
|
Log("Device enumeration complete.");
|
||||||
// var videoTrackConfig = new LocalVideoTrackInitConfig
|
}
|
||||||
// {
|
catch (Exception ex)
|
||||||
// trackName = "webcam_track"
|
{
|
||||||
// };
|
Log("Device enumeration FAILED:");
|
||||||
// localVideoTrack = LocalVideoTrack.CreateFromSource(webcamSource, videoTrackConfig);
|
Log(ex.ToString());
|
||||||
// microphoneSource = await DeviceAudioTrackSource.CreateAsync();
|
return;
|
||||||
// var audioTrackConfig = new LocalAudioTrackInitConfig
|
}
|
||||||
// {
|
|
||||||
// trackName = "microphone_track"
|
try
|
||||||
// };
|
{
|
||||||
// localAudioTrack = LocalAudioTrack.CreateFromSource(microphoneSource, audioTrackConfig);
|
Log("Creating PeerConnection...");
|
||||||
// videoTransceiver = pc.AddTransceiver(MediaKind.Video);
|
|
||||||
// videoTransceiver.LocalVideoTrack = localVideoTrack;
|
using var pc = new PeerConnection();
|
||||||
// videoTransceiver.DesiredDirection = Transceiver.Direction.SendReceive;
|
|
||||||
//
|
Log("PeerConnection created.");
|
||||||
// audioTransceiver = pc.AddTransceiver(MediaKind.Audio);
|
|
||||||
// audioTransceiver.LocalAudioTrack = localAudioTrack;
|
var config = new PeerConnectionConfiguration
|
||||||
// audioTransceiver.DesiredDirection = Transceiver.Direction.SendReceive;
|
{
|
||||||
//
|
IceServers =
|
||||||
//
|
{
|
||||||
//
|
new IceServer { Urls = { "stun:stun.l.google.com:19302" } }
|
||||||
// localAudioTrack?.Dispose();
|
}
|
||||||
// localVideoTrack?.Dispose();
|
};
|
||||||
// microphoneSource?.Dispose();
|
|
||||||
// webcamSource?.Dispose();
|
Log("Config created.");
|
||||||
|
Log("Calling InitializeAsync...");
|
||||||
|
|
||||||
|
await pc.InitializeAsync(config);
|
||||||
|
|
||||||
|
Log("InitializeAsync SUCCESS.");
|
||||||
|
|
||||||
|
if (deviceList.Count > 0)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Log($"Getting formats for first device: {deviceList[0].name}");
|
||||||
|
|
||||||
|
var formats = await DeviceVideoTrackSource.GetCaptureFormatsAsync(deviceList[0].id);
|
||||||
|
|
||||||
|
foreach (var f in formats)
|
||||||
|
{
|
||||||
|
Log($"Format: {f.width}x{f.height} @ {f.framerate}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log("Format enumeration FAILED:");
|
||||||
|
Log(ex.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Log("Creating webcam source (default device)...");
|
||||||
|
webcamSource = await DeviceVideoTrackSource.CreateAsync();
|
||||||
|
Log("Webcam source created.");
|
||||||
|
|
||||||
|
Log("Creating local video track...");
|
||||||
|
var videoTrackConfig = new LocalVideoTrackInitConfig
|
||||||
|
{
|
||||||
|
trackName = "webcam_track"
|
||||||
|
};
|
||||||
|
localVideoTrack = LocalVideoTrack.CreateFromSource(webcamSource, videoTrackConfig);
|
||||||
|
Log("Local video track created.");
|
||||||
|
|
||||||
|
Log("Creating microphone source...");
|
||||||
|
microphoneSource = await DeviceAudioTrackSource.CreateAsync();
|
||||||
|
Log("Microphone source created.");
|
||||||
|
|
||||||
|
Log("Creating local audio track...");
|
||||||
|
var audioTrackConfig = new LocalAudioTrackInitConfig
|
||||||
|
{
|
||||||
|
trackName = "microphone_track"
|
||||||
|
};
|
||||||
|
localAudioTrack = LocalAudioTrack.CreateFromSource(microphoneSource, audioTrackConfig);
|
||||||
|
Log("Local audio track created.");
|
||||||
|
|
||||||
|
Log("Adding video transceiver...");
|
||||||
|
videoTransceiver = pc.AddTransceiver(MediaKind.Video);
|
||||||
|
videoTransceiver.LocalVideoTrack = localVideoTrack;
|
||||||
|
videoTransceiver.DesiredDirection = Transceiver.Direction.SendReceive;
|
||||||
|
Log("Video transceiver configured.");
|
||||||
|
|
||||||
|
Log("Adding audio transceiver...");
|
||||||
|
audioTransceiver = pc.AddTransceiver(MediaKind.Audio);
|
||||||
|
audioTransceiver.LocalAudioTrack = localAudioTrack;
|
||||||
|
audioTransceiver.DesiredDirection = Transceiver.Direction.SendReceive;
|
||||||
|
Log("Audio transceiver configured.");
|
||||||
|
|
||||||
|
Log("WebRTC setup complete.");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log("WebRTC setup FAILED:");
|
||||||
|
Log(ex.ToString());
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
Log("Disposing WebRTC resources...");
|
||||||
|
|
||||||
|
localAudioTrack?.Dispose();
|
||||||
|
localVideoTrack?.Dispose();
|
||||||
|
microphoneSource?.Dispose();
|
||||||
|
webcamSource?.Dispose();
|
||||||
|
|
||||||
|
Log("Resource disposal complete.");
|
||||||
|
Log("=== WebRTC TEST END ===");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user