I have a button a user can push to subscribe to additional channels (using websocket client). How do I tell after the first subscription is started that the websocket client is already up and running connected/initialized and doesn't need to be initialized again?
There is no isInitialized() method, so is it just a matter of using a Try...Catch?
I'm going to experiment in the meantime, but what's the preferred method?
I guess you do websocket at client. you have to do new websocket at first, but you may set a boolean as its initialized state after conneting success.
or you also check websocket.readyState to see if it has already been initialized.
The readyState is a state of websocket, as I said, you have to new WebSocket at the first, you can do like this
B4X:
ws = new WebSocket("yoururl");
console.log(ws.readyState)
You can also test ws whether it is be defined or ws.readyState to see if it has already been initialized.
A way to do this is to initialize the websocket once after page onloaded, and then use it in send or onmessage event each time,you don't need to consider whether it has been initialized
Wait wait wait. How did I miss that?!!? Wow. I got tunnel vision on that one, for sure! Looking for "IsInitialized" and completely missed "Connected." Wow.
Thank you!
BTW: Using ws.Connected prior to ws.Initialize() seems to work just fine and provides the functionality I was needing.