mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-02-14 21:24:58 +00:00
implement auto port support for socket bridge communication
This commit is contained in:
@@ -19,7 +19,7 @@ namespace ElectronNET.API
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver()
|
||||
};
|
||||
|
||||
_socket = IO.Socket("http://localhost:3000");
|
||||
_socket = IO.Socket("http://localhost:" + BridgeSettings.SocketPort);
|
||||
_socket.On(Socket.EVENT_CONNECT, () =>
|
||||
{
|
||||
Console.WriteLine("Verbunden!");
|
||||
|
||||
7
ElectronNET.API/BridgeSettings.cs
Normal file
7
ElectronNET.API/BridgeSettings.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
public static class BridgeSettings
|
||||
{
|
||||
public static string SocketPort { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -11,5 +11,11 @@
|
||||
<PackageReference Include="SocketIoClientDotNet" Version="1.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.AspNetCore.Hosting.Abstractions">
|
||||
<HintPath>..\..\..\..\..\..\..\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.hosting.abstractions\2.0.0\lib\netstandard2.0\Microsoft.AspNetCore.Hosting.Abstractions.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
</Project>
|
||||
|
||||
32
ElectronNET.API/WebHostBuilderExtensions.cs
Normal file
32
ElectronNET.API/WebHostBuilderExtensions.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using System;
|
||||
|
||||
namespace ElectronNET.API
|
||||
{
|
||||
public static class WebHostBuilderExtensions
|
||||
{
|
||||
public static IWebHostBuilder UseElectron(this IWebHostBuilder builder, string[] args)
|
||||
{
|
||||
foreach (string argument in args)
|
||||
{
|
||||
if (argument.ToUpper().Contains("ELECTRONPORT"))
|
||||
{
|
||||
BridgeSettings.SocketPort = argument.ToUpper().Replace("/ELECTRONPORT=", "");
|
||||
Console.WriteLine("Use Electron Port: " + BridgeSettings.SocketPort);
|
||||
}
|
||||
}
|
||||
|
||||
if(IsElectronActive())
|
||||
{
|
||||
builder.UseContentRoot(AppDomain.CurrentDomain.BaseDirectory);
|
||||
}
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
private static bool IsElectronActive()
|
||||
{
|
||||
return !string.IsNullOrEmpty(BridgeSettings.SocketPort);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user