New feature : generate events optionally
frogeater opened this issue · 0 comments
frogeater commented
Thank you very much for this websocket client which has made my life so much easier.
I am currently optimizing event-driven powershell scripts that collect and consolidate information from many sources. Some of them are websocket servers.
To be able to generate events easily usable by Powershell I created a C# class derived from WebsocketClient inserted into the scripts.
In my opinion, having the three events and the SubscribeEvents method available directly in the WebsocketClient class would be a welcome addition to event-driven applications.
The SubscribeEvents method is available to users, who may or may not use it as required.
Here's the class I use.
public class WebsocketClientExt : WebsocketClient {
public event EventHandler<ReconnectionInfo> Connected;
public event EventHandler<ResponseMessage> Received;
public event EventHandler<DisconnectionInfo> Disconnected;
public WebsocketClientExt( Uri url ): base(url) { }
public void SubscribeEvents () {
ReconnectionHappened.Subscribe(c => Connected?.Invoke(this, c));
MessageReceived.Subscribe(m => Received?.Invoke(this, m));
DisconnectionHappened.Subscribe(d => Disconnected?.Invoke(this, d));
}
}
Alain