add callback option to client service to track login state #4733
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.
WHY
When using frp as library, I want to check if the connection between frpc and frps is working properly.
In most cases, we can determine that by the proxy status, for example, if the login was unsuccessful, the API
/api/statuswill respond with an empty object. However, this method is not working if no proxy is provided in the config.It would be great if a callback function could be added to client service to allow users to track the login state. I'm not sure this single callback function is sufficient to cover common use cases. If we should do more work, I think we can add more callbacks, such as
on_connect(msg.LoginResp),on_connect_failandon_disconnect. In my opinion, since we currently don't have error codes defined in login response, the callback functionon_connect(msg.LoginResp)may be replaced withon_connect(bool). As for the callbackon_connect_fail, it may not be commonly used.