Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onClose never called ?! #38

Open
batteurMDR opened this issue Sep 12, 2018 · 1 comment
Open

onClose never called ?! #38

batteurMDR opened this issue Sep 12, 2018 · 1 comment

Comments

@batteurMDR
Copy link

Hi, yesterday I used react-websocket and it works well but when I do this :

<Websocket 
          url='ws://localhost:8080/' 
          onMessage={this.handleData.bind(this)}
          onClose={this.handleClose.bind(this)}
          onOpen={this.handleOpen.bind(this)}/>

onOpen works, onMessage works but onClose doesn't works.
I go into the module to see index.jsx file and I see :

websocket.onclose = () => {
    this.logging('Websocket disconnected');
    if (typeof this.props.onClose === 'function') this.props.onClose();
    if (this.shouldReconnect) {
        let time = this.generateInterval(this.state.attempts);
        this.timeoutID = setTimeout(() => {
            this.setState({attempts: this.state.attempts+1});
            this.setState({ws: new WebSocket(this.props.url, this.props.protocol)});
            this.setupWebsocket();
        }, time);
    }
}

So it will works but in the build file, the

if (typeof _this.props.onClose !== 'undefined') _this.props.onClose();

is missing.
On Master branch, the build file has this line so could you add new tag to npm Please ? Because for now I need to add this line in the build file.

Thanks.

@chanoch
Copy link

chanoch commented Oct 27, 2018

Do you still want this updated? It seems to me that this repo is no longer maintained so you might want to fork it to create the update.

Personally, I am not happy with the use of refs if it can be avoided so I would want a change making or maybe this way is convenient way to receive messages. Alternatively, causing a re-render at each message (and then probably a rerender once the socket updated the state according to the message doesn't seem ideal. Maybe creating a react component for code that isn't directly visual isn't the way it should be done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants