Closed holmrenser closed 7 years ago
I have pushed my own version of this PR to falieson/asteroid until this is merged which can be installed with npm i falieson/asteroid
and used just like asteroid.
The difference between this and the PR is only my removal of /lib from the .gitignore and pushing the babel compiled version up.
@holmrenser don't know why your changes would cause this but when I use my compiled version of this PR (npm i falieson/asteroid
) I get CORS errors that I can't resolve by adding to browser-policy to Meteor's server/main.js
This should not be merged, I use this PR for testing but it causes a CORS issue in my frontend. @holmrenser did you overcome the CORS websocket issue somehow?
This pull request was an error on my side. Asteroid allows you to specify the exact WebSocket implementation you want:
const asteroid = require('asteroid');
const WebSocket = require('ws');
const Connection = asteroid.createClass()
const portal = new Connection({
endpoint: 'ws://localhost:3000/websocket',
SocketConstructor: WebSocket // <-------------- HERE
})
You should only use the above code when using node on the server. In the browser asteroid uses the browser WebSocket variable so you do not need to do anything there.
Thank you very much for the explanation. @holmrenser What if we added some node environment variables to conditionally import and add the socketConstructor. There are some standard ones that I believe will map to most people's setups, I just haven't done the research to know the right way of doing this yet. This would solve my jest issue for asteroid. Unfortunately, it doesn't seem like the maintainer has had a chance to catch up on PRs. I've started to use a local npm registry to get around unreleased versions of packages.
This pull request adds the import of the WebSocket package (https://www.npmjs.com/package/ws) to be able to run the asteroid package on node.
See #121