Init: Debugging
This commit is contained in:
@@ -44,7 +44,7 @@ public partial class MainPage : ContentPage
|
||||
_wsc.Send("GET_SERVER_KEY");
|
||||
_wsc.Send("GET_CHANNELS");
|
||||
|
||||
webRTCTest();
|
||||
_ = webRTCTest();
|
||||
}
|
||||
|
||||
private void SendButton_OnClicked(object? sender, EventArgs e)
|
||||
@@ -295,66 +295,144 @@ public partial class MainPage : ContentPage
|
||||
|
||||
private async Task webRTCTest()
|
||||
{
|
||||
// var path = "D:\\DDI\\Relay\\RelayChat\\RelayCore\\RelayClient\\bin\\debug.txt";
|
||||
// AudioTrackSource microphoneSource = null;
|
||||
// VideoTrackSource webcamSource = null;
|
||||
// Transceiver audioTransceiver = null;
|
||||
// Transceiver videoTransceiver = null;
|
||||
// LocalAudioTrack localAudioTrack = null;
|
||||
// LocalVideoTrack localVideoTrack = null;
|
||||
var path = Path.GetFullPath(
|
||||
Path.Combine(AppContext.BaseDirectory, @"..\..\..\debug.txt")
|
||||
);
|
||||
|
||||
void Log(string msg)
|
||||
{
|
||||
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
|
||||
{
|
||||
var deviceList = await DeviceVideoTrackSource.GetCaptureDevicesAsync();
|
||||
string devices = "";
|
||||
Log("Getting video devices...");
|
||||
|
||||
deviceList = await DeviceVideoTrackSource.GetCaptureDevicesAsync();
|
||||
|
||||
foreach (var device in deviceList)
|
||||
{
|
||||
devices += $"Found device: {device.name} (id: {device.id})\n";
|
||||
Console.WriteLine($"Found device: {device.name} (id: {device.id})");
|
||||
Log($"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();
|
||||
// var videoTrackConfig = new LocalVideoTrackInitConfig
|
||||
// {
|
||||
// trackName = "webcam_track"
|
||||
// };
|
||||
// localVideoTrack = LocalVideoTrack.CreateFromSource(webcamSource, videoTrackConfig);
|
||||
// microphoneSource = await DeviceAudioTrackSource.CreateAsync();
|
||||
// var audioTrackConfig = new LocalAudioTrackInitConfig
|
||||
// {
|
||||
// trackName = "microphone_track"
|
||||
// };
|
||||
// localAudioTrack = LocalAudioTrack.CreateFromSource(microphoneSource, audioTrackConfig);
|
||||
// videoTransceiver = pc.AddTransceiver(MediaKind.Video);
|
||||
// videoTransceiver.LocalVideoTrack = localVideoTrack;
|
||||
// videoTransceiver.DesiredDirection = Transceiver.Direction.SendReceive;
|
||||
//
|
||||
// audioTransceiver = pc.AddTransceiver(MediaKind.Audio);
|
||||
// audioTransceiver.LocalAudioTrack = localAudioTrack;
|
||||
// audioTransceiver.DesiredDirection = Transceiver.Direction.SendReceive;
|
||||
//
|
||||
//
|
||||
//
|
||||
// localAudioTrack?.Dispose();
|
||||
// localVideoTrack?.Dispose();
|
||||
// microphoneSource?.Dispose();
|
||||
// webcamSource?.Dispose();
|
||||
Log("Device enumeration complete.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log("Device enumeration FAILED:");
|
||||
Log(ex.ToString());
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Log("Creating PeerConnection...");
|
||||
|
||||
using var pc = new PeerConnection();
|
||||
|
||||
Log("PeerConnection created.");
|
||||
|
||||
var config = new PeerConnectionConfiguration
|
||||
{
|
||||
IceServers =
|
||||
{
|
||||
new IceServer { Urls = { "stun:stun.l.google.com:19302" } }
|
||||
}
|
||||
};
|
||||
|
||||
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