Comments (8)
No problem~!
You shouldn't modify any node_modules/**
code -- all your changes will be immediately lost anytime you install another dependency or if/when a coworker tries to replicate your setup.
Instead, you should do this in your testing setup file, or at the top of test files (repetitive):
// test/setup.js
global.WebSocket = require('ws');
from sockette.
Hey @tinchoz49 👋
No I would not, sorry. It would be meaningless to Sockette. You should simply do this instead:
global.WebSocket = require('ws');
This would only be set in your Node.js environment, leaving window.WebSocket
intact for your browser bundle(s). If that's not the case, then you will need to take a closer look at your build config because you should never have server code/deps in your front-end bundles. I can maybe help with this part if you have questions or issues.
The above will give you full support 👍
from sockette.
Hi, this isn't to do with Sockette.
There's no WebSocket class in node.js, so you have to add one to the global
scope.
Not sure if mock-socket
does that or if you have to do it manually. However, I did notice in the first paragraph it says it's"unstable" so maybe you should find another solution?
I've answered elsewhere in these issues my recommendation. Eventually I'll include tests in this repo so that there's an example to follow, but no time now =\
Good luck!
from sockette.
Thanks Lukeed,
Just info for those who have the same problem. I solve it by installing ws and import it (see below) in the first line of node_modules/sockette/dist/sockette.js
const WebSocket = require('ws');
from sockette.
it works! thanks again ^^
from sockette.
Hi @lukeed how are you?
There's no WebSocket class in node.js, so you have to add one to the global scope.
Would you accept a PR to change the behavior so we can do something like this:
const ws = new Sockette('ws://localhost:3000', {
ws: require('ws')
});
By default would be the window.WebSocket if is the browser and throw an error if you don't set a ws for nodejs
from sockette.
Don't worry 😃 I understand. Thanks for the quick response!
from sockette.
Of course! Feel free to ping me if you have issues with setting that up~
from sockette.
Related Issues (20)
- Disable reconnect programmatically HOT 15
- Access underlying socket object HOT 3
- SCRIPT5022: SecurityError in IE11 HOT 1
- onerror not returning code HOT 2
- ws.close should clear pending setTimeout HOT 1
- Still in CONNECTING state HOT 1
- Still reconnecting after close() HOT 5
- didunmount
- Bump npm version to include #48 HOT 1
- Able to detect network lost? HOT 1
- Possible to get WebSocket instance? HOT 1
- How to get error code HOT 1
- When I close the connection, it doesn't send queryStringParameters HOT 1
- Socket connection code choices HOT 2
- [Feature] Ability to set url before reconnecting HOT 1
- Automatically split & re-combine messages over a certain size HOT 5
- Increment timeout HOT 2
- Sockette.close can unexpectedly clear other timeouts/intervals
- project status? HOT 2
- Put an option to always reconnect, no matter what
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 sockette.