You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to close a socket connection when my this.state.chartSymbol changes, and reconnect with a new WS url using the new this.state.chartSymbol. The image attached is what I have so far, I know its wrong, but I dont know why.
Thank you
The text was updated successfully, but these errors were encountered:
When you call reconnect (which is a function btw), it reconnects to the existing / current URL. You need to recreate a new ws entirely by calling binanceSocket (or extracting the Sockette portion to a helper function).
binanceSocket is initially called in componentWillMount. Even when symbolChanger calls binanceSocket(), it maintains the old connection and the new connection. How do I stop the old connection?
Closing as it's not related to Sockette anymore, but lemme know how it goes~!
classFoobarextendsComponent{state={symbol: ''};binanceSocket(){this.ws=newSockette(`ws://.../ws/${this.state.symbol}@kline`,{// ...});}componentWillMount(){this.binanceSocket();// now `this.ws` exists}// You can also do this in:// - componentWillReceiveProps// - // etc, depends on your appcomponentDidUpdate(_,prev){letnow=this.state;if(prev.symbol!==now.symbol){// We now have a NEW symbol; update the socketthis.ws.close();// graceful shutdown of old socketthis.binanceSocket();// NEW websocket is now created}}}
Hello,
I would like to close a socket connection when my this.state.chartSymbol changes, and reconnect with a new WS url using the new this.state.chartSymbol. The image attached is what I have so far, I know its wrong, but I dont know why.
Thank you
The text was updated successfully, but these errors were encountered: