Init: Debugging

This commit is contained in:
2026-03-22 05:36:10 -04:00
parent 619f1add51
commit 3d5c35fb15

View File

@@ -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;
try
{ {
var deviceList = await DeviceVideoTrackSource.GetCaptureDevicesAsync(); File.AppendAllText(path, msg + Environment.NewLine);
string devices = ""; Console.WriteLine(msg);
foreach (var device in deviceList)
{
devices += $"Found device: {device.name} (id: {device.id})\n";
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;
} }
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
{
Log("Getting video devices...");
deviceList = await DeviceVideoTrackSource.GetCaptureDevicesAsync();
foreach (var device in deviceList)
{
Log($"Found device: {device.name} (id: {device.id})");
}
Log("Device enumeration complete.");
}
catch (Exception ex)
{
Log("Device enumeration FAILED:");
Log(ex.ToString());
return;
}
try
{
Log("Creating PeerConnection...");
using var pc = new PeerConnection(); using var pc = new PeerConnection();
Log("PeerConnection created.");
var config = new PeerConnectionConfiguration var config = new PeerConnectionConfiguration
{ {
IceServers = new List<IceServer> IceServers =
{ {
new IceServer { Urls = { "stun:stun.l.google.com:19302" } } new IceServer { Urls = { "stun:stun.l.google.com:19302" } }
} }
}; };
Log("Config created.");
Log("Calling InitializeAsync...");
await pc.InitializeAsync(config); await pc.InitializeAsync(config);
// webcamSource = await DeviceVideoTrackSource.CreateAsync(); Log("InitializeAsync SUCCESS.");
// var videoTrackConfig = new LocalVideoTrackInitConfig
// { if (deviceList.Count > 0)
// trackName = "webcam_track" {
// }; try
// localVideoTrack = LocalVideoTrack.CreateFromSource(webcamSource, videoTrackConfig); {
// microphoneSource = await DeviceAudioTrackSource.CreateAsync(); Log($"Getting formats for first device: {deviceList[0].name}");
// var audioTrackConfig = new LocalAudioTrackInitConfig
// { var formats = await DeviceVideoTrackSource.GetCaptureFormatsAsync(deviceList[0].id);
// trackName = "microphone_track"
// }; foreach (var f in formats)
// localAudioTrack = LocalAudioTrack.CreateFromSource(microphoneSource, audioTrackConfig); {
// videoTransceiver = pc.AddTransceiver(MediaKind.Video); Log($"Format: {f.width}x{f.height} @ {f.framerate}");
// videoTransceiver.LocalVideoTrack = localVideoTrack; }
// videoTransceiver.DesiredDirection = Transceiver.Direction.SendReceive; }
// catch (Exception ex)
// audioTransceiver = pc.AddTransceiver(MediaKind.Audio); {
// audioTransceiver.LocalAudioTrack = localAudioTrack; Log("Format enumeration FAILED:");
// audioTransceiver.DesiredDirection = Transceiver.Direction.SendReceive; Log(ex.ToString());
// }
// }
//
// localAudioTrack?.Dispose(); Log("Creating webcam source (default device)...");
// localVideoTrack?.Dispose(); webcamSource = await DeviceVideoTrackSource.CreateAsync();
// microphoneSource?.Dispose(); Log("Webcam source created.");
// webcamSource?.Dispose();
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 ===");
}
} }
} }