2017-10-14 17:58:16 +02:00
|
|
|
|
using Quobject.SocketIoClientDotNet.Client;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
|
|
namespace ElectronNET.API
|
|
|
|
|
|
{
|
|
|
|
|
|
internal static class BridgeConnector
|
|
|
|
|
|
{
|
2017-10-23 21:24:05 +02:00
|
|
|
|
private static Socket _socket;
|
2019-05-18 02:00:56 +02:00
|
|
|
|
private static object _syncRoot = new object();
|
2017-10-14 17:58:16 +02:00
|
|
|
|
|
2017-10-23 21:24:05 +02:00
|
|
|
|
public static Socket Socket
|
2017-10-14 17:58:16 +02:00
|
|
|
|
{
|
2017-10-23 21:24:05 +02:00
|
|
|
|
get
|
2017-10-14 17:58:16 +02:00
|
|
|
|
{
|
2017-10-23 21:24:05 +02:00
|
|
|
|
if(_socket == null && HybridSupport.IsElectronActive)
|
|
|
|
|
|
{
|
2017-11-04 00:16:14 +01:00
|
|
|
|
lock (_syncRoot)
|
2017-10-23 21:24:05 +02:00
|
|
|
|
{
|
2017-11-04 00:16:14 +01:00
|
|
|
|
if (_socket == null && HybridSupport.IsElectronActive)
|
|
|
|
|
|
{
|
|
|
|
|
|
_socket = IO.Socket("http://localhost:" + BridgeSettings.SocketPort);
|
|
|
|
|
|
_socket.On(Socket.EVENT_CONNECT, () =>
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine("BridgeConnector connected!");
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-23 21:24:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
else if(_socket == null && !HybridSupport.IsElectronActive)
|
|
|
|
|
|
{
|
2017-11-04 00:16:14 +01:00
|
|
|
|
lock (_syncRoot)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_socket == null && !HybridSupport.IsElectronActive)
|
|
|
|
|
|
{
|
|
|
|
|
|
_socket = IO.Socket(new Uri("http://localhost"), new IO.Options { AutoConnect = false });
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-23 21:24:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return _socket;
|
|
|
|
|
|
}
|
2017-10-14 17:58:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|