File tree Expand file tree Collapse file tree 9 files changed +68
-12
lines changed
ElectronNET.AspNet/Runtime/Controllers Expand file tree Collapse file tree 9 files changed +68
-12
lines changed Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change @@ -8,13 +8,13 @@ namespace ElectronNET.API;
88using SocketIO . Serializer . SystemTextJson ;
99using SocketIO = SocketIOClient . SocketIO ;
1010
11- internal class SocketIoFacade : IDisposable
11+ internal class SocketIOConnection : ISocketConnection
1212{
1313 private readonly SocketIO _socket ;
1414 private readonly object _lockObj = new object ( ) ;
1515 private bool _isDisposed ;
1616
17- public SocketIoFacade ( string uri )
17+ public SocketIOConnection ( string uri )
1818 {
1919 _socket = new SocketIO ( uri ) ;
2020 _socket . Serializer = new SystemTextJsonSerializer ( ElectronJson . Options ) ;
@@ -140,7 +140,7 @@ private void CheckDisposed()
140140 {
141141 if ( this . _isDisposed )
142142 {
143- throw new ObjectDisposedException ( nameof ( SocketIoFacade ) ) ;
143+ throw new ObjectDisposedException ( nameof ( SocketIOConnection ) ) ;
144144 }
145145 }
146146}
Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ static ElectronNetRuntime()
4949
5050 internal static Func < Task > OnAppReadyCallback { get ; set ; }
5151
52- internal static SocketIoFacade GetSocket ( )
52+ internal static ISocketConnection GetSocket ( )
5353 {
5454 return RuntimeControllerCore ? . Socket ;
5555 }
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ public RuntimeControllerDotNetFirst()
1919 {
2020 }
2121
22- internal override SocketIoFacade Socket
22+ internal override ISocketConnection Socket
2323 {
2424 get
2525 {
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ public RuntimeControllerElectronFirst()
1717 {
1818 }
1919
20- internal override SocketIoFacade Socket
20+ internal override ISocketConnection Socket
2121 {
2222 get
2323 {
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ internal class SocketBridgeService : LifetimeServiceBase
99 {
1010 private readonly int socketPort ;
1111 private readonly string socketUrl ;
12- private SocketIoFacade socket ;
12+ private SocketIOConnection socket ;
1313
1414 public SocketBridgeService ( int socketPort )
1515 {
@@ -19,11 +19,11 @@ public SocketBridgeService(int socketPort)
1919
2020 public int SocketPort => this . socketPort ;
2121
22- internal SocketIoFacade Socket => this . socket ;
22+ internal SocketIOConnection Socket => this . socket ;
2323
2424 protected override Task StartCore ( )
2525 {
26- this . socket = new SocketIoFacade ( this . socketUrl ) ;
26+ this . socket = new SocketIOConnection ( this . socketUrl ) ;
2727 this . socket . BridgeConnected += this . Socket_BridgeConnected ;
2828 this . socket . BridgeDisconnected += this . Socket_BridgeDisconnected ;
2929 Task . Run ( this . Connect ) ;
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ protected RuntimeControllerAspNetBase(AspNetLifetimeAdapter aspNetLifetimeAdapte
2525
2626 internal override SocketBridgeService SocketBridge => this . socketBridge ;
2727
28- internal override SocketIoFacade Socket
28+ internal override ISocketConnection Socket
2929 {
3030 get
3131 {
You can’t perform that action at this time.
0 commit comments