Comments (6)
I was calling close like this:
websocket.close({ keepClosed: true });
I feel very ashamed now, re-reading the docs.
from reconnecting-websocket.
Yes can confirm when calling it inside of React, inside of a Vanilla Class...
...
constructor(){
this.ws = null
}
init(){
this.ws = new ReconnectingWebSocket('ws://...',[],{startClosed: true})
}
...
will cause two connections to be opened. Unaware if this is down to react's development strict mode, or a bug with reconnecting-websocket.
But most likely strict mode:
Strict mode canβt automatically detect side effects for you, but it can help you spot them by making them a little more deterministic. This is done by intentionally double-invoking the following functions:
Class component constructor, render, and shouldComponentUpdate methods
Class component static getDerivedStateFromProps method
Function component bodies
State updater functions (the first argument to setState)
Functions passed to useState, useMemo, or useReducer
from reconnecting-websocket.
It would be great to have some consistent steps to reproduce. Please, update the ticket if you gather more information.
Aso, additional details about your environment would be appreciated. Is this running in browser? Happens for all vendors / versions? Is the uniqueToken() always returning different tokens in every call? Are you sure that the constructor isn't called multiple times?
from reconnecting-websocket.
Hi @Joris-van-der-Wel , did you solve this?
I have something similar and not sure if its the library or my use with Redux. I'm trying now to use a unique ID so I can keep a single websocket on the server side..
from reconnecting-websocket.
I'm using this module with react. If init websocket in the constructor, it will connect twice.
class TokenWatch extends Component {
constructor(props) {
super(props);
// this.ws = new ReconnectingWebSocket(URL) // will have two sockets if init here
}
componentDidMount() {
this.ws = new ReconnectingWebSocket(URL) // only one socket if init here
}
}
from reconnecting-websocket.
I'm having this issue as well. It doesn't seem to happen with a production build; But there are two seperate socket connections even though the constructor is only being called once.
from reconnecting-websocket.
Related Issues (20)
- Prevented reconnect HOT 7
- Old websockets do not seem to be terminated HOT 5
- Dequeue Events from send
- does not support http headers HOT 4
- How to use "ws.once" with this library?
- Update this._url on a preexisting ReconnectingWebSocket object HOT 1
- Seems to be broken with API Gateway Websockets HOT 2
- allow passing multiple arguments to send method
- on leave session close event not fired HOT 1
- new ReconnectingWebSocket(url).url always empty string
- WebSocket reconnection fails when using it in a React Native simulator
- WebSocket was closed before the connection was established HOT 5
- Add a user callback After the minuptime check
- I cannot close a connection HOT 2
- Use native EventTarget instead of a custom implementation
- Project abandoned? HOT 5
- This expression is not constructable HOT 1
- Bug: `_disconnect` causes uncaught exception and process to crash if using `ws` library HOT 10
- Bug: `_handleError` does not bubble up actual error reason (e.g. `ECONNREFUSED`)
- Bug: `_getNextDelay` returns `0` while a socket may be reconnecting/connecting
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reconnecting-websocket.