Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem 1
Websocket connections could not poll to see if the connection was terminated by the client unless
ReceiveAsync
was called.WsController
, if utilizingwhile (context.IsOpen())
would need to callReceiveAsync
Solution: Move the burden of calling
ReceiveAsync
from theWsController
to theWsRouter
. It has been madeinternal
and renamed toPollAsync
so as not to be confused: it should NOT be called outside ofWsRouter
.This places the responsibility of maintaining and managing the connection on the
WsRouter
instead of theWsController
s. This approach is also eh. In hindsight theHttpServer
may have been best off owning and managing the state of theWsContext
but it shouldn't be that big of a deal.Problem 2
Because we are not fire and forgetting the controller's handle functions if a
WsController
runs a while loop for constant polling to check for data then theWsRouter
will never continue.Solution: Move to an event based system. The
WsContext
callsWsController.RunAsync
which subscribes its callbacks toWsContext
's events. This allows for us to overrideWsController.RunAsync
in order to subscribe to only events that we need. By default all of them are subscribed.I have done testing in and outside of the game, as well as making it so that I can relay notifications to my client from Postman. It is working exactly as I expected.