How to judge whether it is in a non-active state

What can I do to intercept ws, or how to judge whether it is in a non-active state, I need to disconnect after the non-activel state to release resources. thanks any more

Closing since it’s been asked as a duplicate on github discussions forum: