Closed LeetCodes closed 7 years ago
const WebSocket = require('reconnecting-websocket');
const ws = new WebSocket('ws://echo.websocket.org', null, {maxRetries: 3});
ws.addEventListener('open', () => {
ws.send('hello!');
});
ws.onerror = (err) => {
console.log(err);
};
Where are you executing your code? Browser (using webpack/browserify) or node.js?
If you are using node.js, it fails because there's no global WebSocket in node.
Have a look at the README (there's a section named "using alternative constructor") or see how tests are implemented (using the module html5-websocket to wrap a ws)
code doesnt work at all, just get this error TypeError: Invalid WebSocket constructor. Set
options.constructor
tried running all examples, also tried to test but got errors with it, any help is appreciated