question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Force websocket close without reconnection how?

See original GitHub issue

Hi pal,

How do you intentional close the websocket without reconnection execution, its necessary to pass event code to close method?

when manually invoke close method I think that the reconnection should not be done

ws.close()

thanks

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:20 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
lukeedcommented, Nov 7, 2018

@nonotest Thanks~! You could wrap/overwrite the reconnect method after you initialize Sockette.

Since the onclose event is passed to reconnect() directly, you can assert against/abort the reconnection.

It sounds like RN is doing something funky – and tbh, I’ve never used or plan to use RN so I can’t really help in that particular context.

let foo = new Sockette({ ... });

// save old function
let _reconnect = foo.reconnect.bind(foo);

// overwrite it
foo.reconnect = e => {
  if (e && e.code === 1001) return; // abort
  _reconnect(e); // invoke old fn
};
0reactions
nonotestcommented, Nov 7, 2018

Hello,

When using a browser and connecting to the same server, I get the correct close code (using sockette as well), so I would definitely say there is something happening on the RN side.

I have found a few people talking about it https://github.com/facebook/react-native/issues/12678 but the issue was closed without much discussion… I am not on the latest RN version (55.3) so not 100% sure if it’s the intended behaviour thus I would not automatically exclude it for browsers.

I will try with RN latest and do some more research later and update you!

thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

WebSocket.close() - Web APIs - MDN Web Docs
The WebSocket.close() method closes the WebSocket connection or connection attempt, if any. If the connection is already CLOSED , this method ...
Read more >
How to reconnect to websocket after close connection [duplicate]
Just make a new WebSocket again. The reason a reconnect doesn't exist is because it would probably be just like creating a new...
Read more >
How to Disconnect a WebSocket Connection in JavaScript?
To close a WebSocket connection, you can simply use the WebSocket.close() method, for example, like so:
Read more >
How to Close a WebSocket (Correctly) - Forty Years of Code
A client WebSocket that starts the closing handshake fails to transition to the Closed state when the server acknowledges the initial Close ......
Read more >
WebSockets - Closing a Connection - Tutorialspoint
Closing a connection is possible with the help of onclose event. After marking the end of communication with the help of onclose event,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found