Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ElectronNET.API/Bridge/BridgeConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace ElectronNET.API
{
internal static class BridgeConnector
{
public static SocketIoFacade Socket
public static ISocketConnection Socket
{
get
{
Expand Down
56 changes: 56 additions & 0 deletions src/ElectronNET.API/Bridge/ISocketConnection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
namespace ElectronNET.API;

using System;
using System.Threading.Tasks;

/// <summary>
/// Common interface for communication facades.
/// Provides methods for bidirectional communication between .NET and Electron.
/// </summary>
internal interface ISocketConnection : IDisposable
{
/// <summary>
/// Raised when the bridge connection is established.
/// </summary>
event EventHandler BridgeConnected;

/// <summary>
/// Raised when the bridge connection is lost.
/// </summary>
event EventHandler BridgeDisconnected;

/// <summary>
/// Establishes the connection to Electron.
/// </summary>
void Connect();

/// <summary>
/// Registers a persistent event handler.
/// </summary>
void On(string eventName, Action action);

/// <summary>
/// Registers a persistent event handler with a typed parameter.
/// </summary>
void On<T>(string eventName, Action<T> action);

/// <summary>
/// Registers a one-time event handler.
/// </summary>
void Once(string eventName, Action action);

/// <summary>
/// Registers a one-time event handler with a typed parameter.
/// </summary>
void Once<T>(string eventName, Action<T> action);

/// <summary>
/// Removes an event handler.
/// </summary>
void Off(string eventName);

/// <summary>
/// Sends a message to Electron.
/// </summary>
Task Emit(string eventName, params object[] args);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ namespace ElectronNET.API;
using SocketIO.Serializer.SystemTextJson;
using SocketIO = SocketIOClient.SocketIO;

internal class SocketIoFacade : IDisposable
internal class SocketIOConnection : ISocketConnection
{
private readonly SocketIO _socket;
private readonly object _lockObj = new object();
private bool _isDisposed;

public SocketIoFacade(string uri)
public SocketIOConnection(string uri)
{
_socket = new SocketIO(uri);
_socket.Serializer = new SystemTextJsonSerializer(ElectronJson.Options);
Expand Down Expand Up @@ -140,7 +140,7 @@ private void CheckDisposed()
{
if (this._isDisposed)
{
throw new ObjectDisposedException(nameof(SocketIoFacade));
throw new ObjectDisposedException(nameof(SocketIOConnection));
}
}
}
2 changes: 1 addition & 1 deletion src/ElectronNET.API/ElectronNetRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static ElectronNetRuntime()

internal static Func<Task> OnAppReadyCallback { get; set; }

internal static SocketIoFacade GetSocket()
internal static ISocketConnection GetSocket()
{
return RuntimeControllerCore?.Socket;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ protected RuntimeControllerBase()
{
}

internal abstract SocketIoFacade Socket { get; }
internal abstract ISocketConnection Socket { get; }

internal abstract ElectronProcessBase ElectronProcess { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public RuntimeControllerDotNetFirst()
{
}

internal override SocketIoFacade Socket
internal override ISocketConnection Socket
{
get
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public RuntimeControllerElectronFirst()
{
}

internal override SocketIoFacade Socket
internal override ISocketConnection Socket
{
get
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal class SocketBridgeService : LifetimeServiceBase
{
private readonly int socketPort;
private readonly string socketUrl;
private SocketIoFacade socket;
private SocketIOConnection socket;

public SocketBridgeService(int socketPort)
{
Expand All @@ -19,11 +19,11 @@ public SocketBridgeService(int socketPort)

public int SocketPort => this.socketPort;

internal SocketIoFacade Socket => this.socket;
internal SocketIOConnection Socket => this.socket;

protected override Task StartCore()
{
this.socket = new SocketIoFacade(this.socketUrl);
this.socket = new SocketIOConnection(this.socketUrl);
this.socket.BridgeConnected += this.Socket_BridgeConnected;
this.socket.BridgeDisconnected += this.Socket_BridgeDisconnected;
Task.Run(this.Connect);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected RuntimeControllerAspNetBase(AspNetLifetimeAdapter aspNetLifetimeAdapte

internal override SocketBridgeService SocketBridge => this.socketBridge;

internal override SocketIoFacade Socket
internal override ISocketConnection Socket
{
get
{
Expand Down