Skip to content

Commit 3306aaa

Browse files
committed
Merge branch 'develop' of https://github.com/ElectronNET/Electron.NET into feature/socket-enhancements
2 parents d3b895e + 2010461 commit 3306aaa

File tree

9 files changed

+68
-12
lines changed

9 files changed

+68
-12
lines changed

src/ElectronNET.API/Bridge/BridgeConnector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace ElectronNET.API
44
{
55
internal static class BridgeConnector
66
{
7-
public static SocketIoFacade Socket
7+
public static ISocketConnection Socket
88
{
99
get
1010
{
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
namespace ElectronNET.API;
2+
3+
using System;
4+
using System.Threading.Tasks;
5+
6+
/// <summary>
7+
/// Common interface for communication facades.
8+
/// Provides methods for bidirectional communication between .NET and Electron.
9+
/// </summary>
10+
internal interface ISocketConnection : IDisposable
11+
{
12+
/// <summary>
13+
/// Raised when the bridge connection is established.
14+
/// </summary>
15+
event EventHandler BridgeConnected;
16+
17+
/// <summary>
18+
/// Raised when the bridge connection is lost.
19+
/// </summary>
20+
event EventHandler BridgeDisconnected;
21+
22+
/// <summary>
23+
/// Establishes the connection to Electron.
24+
/// </summary>
25+
void Connect();
26+
27+
/// <summary>
28+
/// Registers a persistent event handler.
29+
/// </summary>
30+
void On(string eventName, Action action);
31+
32+
/// <summary>
33+
/// Registers a persistent event handler with a typed parameter.
34+
/// </summary>
35+
void On<T>(string eventName, Action<T> action);
36+
37+
/// <summary>
38+
/// Registers a one-time event handler.
39+
/// </summary>
40+
void Once(string eventName, Action action);
41+
42+
/// <summary>
43+
/// Registers a one-time event handler with a typed parameter.
44+
/// </summary>
45+
void Once<T>(string eventName, Action<T> action);
46+
47+
/// <summary>
48+
/// Removes an event handler.
49+
/// </summary>
50+
void Off(string eventName);
51+
52+
/// <summary>
53+
/// Sends a message to Electron.
54+
/// </summary>
55+
Task Emit(string eventName, params object[] args);
56+
}

src/ElectronNET.API/Bridge/SocketIOFacade.cs renamed to src/ElectronNET.API/Bridge/SocketIOConnection.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ namespace ElectronNET.API;
1010
using SocketIO = SocketIOClient.SocketIO;
1111
using SocketIOOptions = SocketIOClient.SocketIOOptions;
1212

13-
internal class SocketIoFacade : IDisposable
13+
internal class SocketIOConnection : ISocketConnection
1414
{
1515
private readonly SocketIO _socket;
1616
private readonly object _lockObj = new object();
1717
private bool _isDisposed;
1818

19-
public SocketIoFacade(string uri, string authorization)
19+
public SocketIOConnection(string uri, string authorization)
2020
{
2121
var opts = string.IsNullOrEmpty(authorization) ? new SocketIOOptions() : new SocketIOOptions
2222
{
@@ -149,7 +149,7 @@ private void CheckDisposed()
149149
{
150150
if (this._isDisposed)
151151
{
152-
throw new ObjectDisposedException(nameof(SocketIoFacade));
152+
throw new ObjectDisposedException(nameof(SocketIOConnection));
153153
}
154154
}
155155
}

src/ElectronNET.API/ElectronNetRuntime.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static ElectronNetRuntime()
5252

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

55-
internal static SocketIoFacade GetSocket()
55+
internal static ISocketConnection GetSocket()
5656
{
5757
return RuntimeControllerCore?.Socket;
5858
}

src/ElectronNET.API/Runtime/Controllers/RuntimeControllerBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ protected RuntimeControllerBase()
1212
{
1313
}
1414

15-
internal abstract SocketIoFacade Socket { get; }
15+
internal abstract ISocketConnection Socket { get; }
1616

1717
internal abstract ElectronProcessBase ElectronProcess { get; }
1818

src/ElectronNET.API/Runtime/Controllers/RuntimeControllerDotNetFirst.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public RuntimeControllerDotNetFirst()
1818
{
1919
}
2020

21-
internal override SocketIoFacade Socket
21+
internal override ISocketConnection Socket
2222
{
2323
get
2424
{

src/ElectronNET.API/Runtime/Controllers/RuntimeControllerElectronFirst.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public RuntimeControllerElectronFirst()
1616
{
1717
}
1818

19-
internal override SocketIoFacade Socket
19+
internal override ISocketConnection Socket
2020
{
2121
get
2222
{

src/ElectronNET.API/Runtime/Services/SocketBridge/SocketBridgeService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ internal class SocketBridgeService : LifetimeServiceBase
1010
private readonly int socketPort;
1111
private readonly string authorization;
1212
private readonly string socketUrl;
13-
private SocketIoFacade socket;
13+
private SocketIOConnection socket;
1414

1515
public SocketBridgeService(int socketPort, string authorization)
1616
{
@@ -21,11 +21,11 @@ public SocketBridgeService(int socketPort, string authorization)
2121

2222
public int SocketPort => this.socketPort;
2323

24-
internal SocketIoFacade Socket => this.socket;
24+
internal SocketIOConnection Socket => this.socket;
2525

2626
protected override Task StartCore()
2727
{
28-
this.socket = new SocketIoFacade(this.socketUrl, this.authorization);
28+
this.socket = new SocketIOConnection(this.socketUrl, this.authorization);
2929
this.socket.BridgeConnected += this.Socket_BridgeConnected;
3030
this.socket.BridgeDisconnected += this.Socket_BridgeDisconnected;
3131
Task.Run(this.Connect);

src/ElectronNET.AspNet/Runtime/Controllers/RuntimeControllerAspNetBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected RuntimeControllerAspNetBase(IServer server, AspNetLifetimeAdapter aspN
3434

3535
internal override SocketBridgeService SocketBridge => this.socketBridge;
3636

37-
internal override SocketIoFacade Socket
37+
internal override ISocketConnection Socket
3838
{
3939
get
4040
{

0 commit comments

Comments
 (0)