diff --git a/src/InsightBytes.BlackBoxk/InsightBytes.BlackBox.csproj b/src/InsightBytes.BlackBoxk/InsightBytes.BlackBox.csproj index a65f617..1be370d 100644 --- a/src/InsightBytes.BlackBoxk/InsightBytes.BlackBox.csproj +++ b/src/InsightBytes.BlackBoxk/InsightBytes.BlackBox.csproj @@ -7,6 +7,10 @@ enable + + + + diff --git a/src/InsightBytes.BlackBoxk/Program.cs b/src/InsightBytes.BlackBoxk/Program.cs index 922a2d1..d952764 100644 --- a/src/InsightBytes.BlackBoxk/Program.cs +++ b/src/InsightBytes.BlackBoxk/Program.cs @@ -1,92 +1,80 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Net.Http; +using System.Text; using System.Threading; using System.Threading.Tasks; using InsightBytes.Utilities.Endpoints; -namespace InsightBytes.BlackBox +using Newtonsoft.Json; + +namespace InsightBytes.BlackBox; + +internal class Program { - internal class Program - { - static async Task Main(string[] args) - { - Program p = new Program(); - await p.StartServerAndRequestData(); - } + private readonly HttpClient _httpClient; - async Task StartServerAndRequestData() - { - // Start the Go server process - var process = ProcessStarter(); - try - { - // Request data from the Go server - var users = await GetAllUsers(); + public Program() { _httpClient = new HttpClient(); } - foreach (var user in users) - { - Console.WriteLine($"ID: {user.ID}, Name: {user.Name}, Age: {user.Age}"); - } - } - finally - { - // Ensure to kill the process when done - if (!process.HasExited) - { - process.Kill(); - } - } - } + static async Task Main(string[] args) + { + var program = new Program(); - Process ProcessStarter() - { - string goServerExePath = @"C:\Users\gabriel.cornejo\source\repos\VSCodeApps\Golang\gin-quickstart\goServerExecutable.exe"; - - ProcessStartInfo startInfo = new ProcessStartInfo() - { - FileName = goServerExePath, - UseShellExecute = false, - RedirectStandardOutput = true, - RedirectStandardError = true, - CreateNoWindow = true, - }; + var sdpOffer = @"v=0 +o=- 5841829617509545627 1709000931 IN IP4 0.0.0.0 +s=- +t=0 0 +a=fingerprint:sha-256 52:74:14:CD:57:F7:20:26:D1:1E:C0:CC:5C:D4:61:A0:AF:16:61:BB:70:BE:70:5C:F8:B9:C4:D7:76:10:70:9D +a=extmap-allow-mixed +a=group:BUNDLE 0 +m=application 9 UDP/DTLS/SCTP webrtc-datachannel +c=IN IP4 0.0.0.0 +a=setup:actpass +a=mid:0 +a=sendrecv +a=sctp-port:5000 +a=ice-ufrag:xqpbWsfYSDiUJdbC +a=ice-pwd:MFTlHpwBEyxmFmcLFctEXCflyLUaaljX"; - Process process = new Process() - { - StartInfo = startInfo - }; + await program.SendOfferAsync(sdpOffer); + } - process.Start(); + public async Task SendOfferAsync(string offer) + { + var requestUri = "http://localhost:8080/offer"; + var offerData = new { sdp = offer }; // Assuming offer is your SDP string + var jsonContent = JsonConvert.SerializeObject(offerData); + var content = new StringContent(jsonContent, Encoding.UTF8, "application/json"); - return process; + HttpResponseMessage response = await _httpClient.PostAsync(requestUri, content); + if(response.IsSuccessStatusCode) + { + Console.WriteLine("Offer sent successfully."); + // Optionally, read the response + string responseBody = await response.Content.ReadAsStringAsync(); + Console.WriteLine(responseBody); + } else + { + Console.WriteLine("Failed to send offer."); } + } - async Task> GetAllUsers() + public async Task GetOfferOrAnswerAsync(string sessionId) + { + var requestUri = $"http://localhost:8080/offer/{sessionId}"; + HttpResponseMessage response = await _httpClient.GetAsync(requestUri); + if(response.IsSuccessStatusCode) { - List userList = new List(); - Console.WriteLine("Getting users from Go service..."); - Console.WriteLine("##############################\n"); - - var httpClient = new HttpClient(); - var golangService = new GolangService(httpClient); - - try - { - var users = await golangService.GetUserDataAsync(); - userList.AddRange(users); - } - catch (Exception e) - { - Console.WriteLine($"Error getting users: {e.Message}"); - } - finally - { - Console.WriteLine("##############################\n"); - } - - return userList; + string responseBody = await response.Content.ReadAsStringAsync(); + Console.WriteLine("Received response: " + responseBody); + return responseBody; + } else + { + Console.WriteLine("Failed to receive offer/answer."); + return null; } } } + diff --git a/src/InsightBytes/ViewModels/MainWindowViewModel.cs b/src/InsightBytes/ViewModels/MainWindowViewModel.cs index bd54b43..9cd6f7c 100644 --- a/src/InsightBytes/ViewModels/MainWindowViewModel.cs +++ b/src/InsightBytes/ViewModels/MainWindowViewModel.cs @@ -2,4 +2,5 @@ public class MainWindowViewModel : ViewModelBase { + } diff --git a/src/InsightBytes/Views/AppSplash.axaml b/src/InsightBytes/Views/AppSplash.axaml index 2b96191..c310c23 100644 --- a/src/InsightBytes/Views/AppSplash.axaml +++ b/src/InsightBytes/Views/AppSplash.axaml @@ -6,20 +6,29 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="400" d:DesignWidth="600" + xmlns:vm="using:InsightBytes.ViewModels" + x:DataType="vm:MainWindowViewModel" mc:Ignorable="d"> - - + + + + +