Giter Club home page Giter Club logo

Comments (8)

elliotaplant avatar elliotaplant commented on July 20, 2024 1

I can verify that tomorrow!

from sockette.

lukeed avatar lukeed commented on July 20, 2024

How are you constructing the Sockette instance? Are you using new Sockette(...)? Are you experiencing the same issue on other browsers, or is it only IE11?

Thanks!

from sockette.

houyaowei avatar houyaowei commented on July 20, 2024

I use Sockette with npm package
the code like blow:

`import Sockette from "sockette";

this.ws = new Sockette(url, {
timeout: 100,
maxAttempts: 10,
},
onmessage: e => { },
onmaximum: e => {
that.ws.reconnect;
},
onerror: e => { },
onclose: e => {},
onreconnect: e => { }
});
`
the errors orrcured on the IE11 and Edge, other browsers(Chrome, Firefox, Opera) work fine.

Thanks!

from sockette.

lukeed avatar lukeed commented on July 20, 2024

@houyaowei Try this:

this.ws ? this.ws.close(1000) : null

Unrelated, but when the opts.maximum is reached, Sockette quits. If you want to restart it, you need to call open and not reconnect because open starts the series whereas reconnect is a single attempt.

onmaximum: e => {
-  that.ws.reconnect;
+ this.ws.open();
},

from sockette.

elliotaplant avatar elliotaplant commented on July 20, 2024

@lukeed I know this issue is closed, but it seems a bit concerning that the default close .close() call throws an error in IE. Also, MDN states that specifying any code except 1000 and 3000 is illegal (in FireFox): https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent#Status_codes.

Could we make it so that the .close() method simply passes along its args to the native .close() method?

...
$.close = ws.close;
...

from sockette.

lukeed avatar lukeed commented on July 20, 2024

@elliotaplant Thanks, this actually matches what I had thought initially, but I changed it to 1005 at the last second. Can you re-verify for me that sending code 1000 on close works on IE and your copy of Firefox? (I don't have access to any IE)

Thanks!

from sockette.

elliotaplant avatar elliotaplant commented on July 20, 2024

Sending ws.close(1000) Works on IE and Firefox for me!

I'm pretty busy right now but I could make a PR for this in January.

If you want to make the change, I think it would just be:

// src/index.js
...
-  $.close = function (x, y) {
-    ws.close(x || 1005, y);
-  };
+  $.close = ws.close
...

from sockette.

lukeed avatar lukeed commented on July 20, 2024

Awesome, thank you 🙇

It cannot be your suggestion because the internal ws changes over any given Sockette instance's lifespan. After all, the purpose of Sockette is to swap out & setup new WebSocket instances without your concern.

Plus, ws isn't defined until $.open() is called, whereas $.close = ws.close would run (and $ returned) instantly

from sockette.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.