Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New feature : generate events optionally #136

Open
frogeater opened this issue Sep 5, 2023 · 0 comments
Open

New feature : generate events optionally #136

frogeater opened this issue Sep 5, 2023 · 0 comments

Comments

@frogeater
Copy link

frogeater commented Sep 5, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant