-
Notifications
You must be signed in to change notification settings - Fork 22
Description
As the title says I currently am unable to disconnect the socket at runtime and then reconnect it as if I do I just get the error:
[08:53:22 ERR] Error with Twitch EventSub [System.InvalidOperationException: The WebSocket has already been started.
at System.Net.WebSockets.ClientWebSocket.ConnectAsync(Uri uri, HttpMessageInvoker invoker, CancellationToken cancellationToken)
at TwitchLib.EventSub.Websockets.Client.WebsocketClient.ConnectAsync(Uri url)]
The scenario I have is a GUI app where the user can connect/disconnect from twitch as they please, here is the steps:
@Scenario Should let me disconnect and reconnect to twitch event sub on same socket
Given I have valid twitch auth tokens
And I have already called `ConnectAsync`
And am connected to twitch EventSub
When I call `DisconnectAsync`
And then call `ConnectAsync`
Then it should connect to twitch EventSubAs mentioned above the calls occurring are basically:
// One pathway which is triggered a few ways which runs this
var success = await myEventSubWebSocket.ConnectAsync(new Uri("wss://eventsub.wss.twitch.tv/ws")); // To Connect
// A pathway runs this if the client disconnects/removes their twitch auth
var success = await myEventsubWebSocket.DisconnectAsync(); // To DisconnectIf it helps here are the related logs I can see being spat out from this process:
[08:52:52 INF] Checking to see if twitch EventSub needs connecting
[08:52:52 INF] Connecting to twitch EventSub
[08:52:52 INF] Connected to twitch EventSub
[08:52:53 INF] Attempting to Subscribe to [whatever] for [channel.update]
[08:52:53 INF] Timestamp: 06/13/2024 08:52:53 Type: Request Method: POST Resource: https://api.twitch.tv/helix/eventsub/subscriptions Content: {
"type": "channel.update",
"version": "2",
"condition": {
"broadcaster_user_id": "whatever"
},
"transport": {
"method": "websocket",
"session_id": "whatever"
}
}
[08:52:53 INF] Successfully Subscribed to [whatever] for [channel.update]
[08:52:53 INF] EventSub Channel Update Subscription Successful
[08:53:13 INF] Revoking Twitch Token
[08:53:15 FTL] NormalClosure - client disconnected
[08:53:22 INF] [Twitch OAuth]: Successfully authenticated
[08:53:22 INF] Checking to see if twitch EventSub needs re/connecting
[08:53:22 INF] Connecting to twitch EventSub
[08:53:22 ERR] Error with Twitch EventSub [System.InvalidOperationException: The WebSocket has already been started.
at System.Net.WebSockets.ClientWebSocket.ConnectAsync(Uri uri, HttpMessageInvoker invoker, CancellationToken cancellationToken)
at TwitchLib.EventSub.Websockets.Client.WebsocketClient.ConnectAsync(Uri url)]
[08:53:22 INF] Could not connect to twitch EventSub
Some of that logging is specific to my App but at least this can give you some idea as to the flow of things and whats happening. As some of the logic takes place outside of the TwitchLib functionality, such as the Twitch OAuth process etc, but once that happens it triggers other logic to run.
I think the main thing for me is that it seems to show [08:53:15 FTL] NormalClosure - client disconnected could possibly be raised from TwitchLib.EventSub.Websockets/Client/WebsocketClient.cs which would imply its blowing up internally for some reason.
If you need any further information let me know.