-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use WebSocket from within worker? #9
Comments
Yeah. Currently we recommend the use of OneJS ( https://github.com/azer/onejs ) or similar packagers to pack node modules into a single script that can be passed to However, that only pertains to computation-only node modules, and currently we don't expose Node's network stack to Thread-local usage. https://github.com/rob333/thread.js contains the bits we need (indeed our |
Thanks for the links. Until you get a volunteer (I'd try but probably not up to the task...!) it might be worth a quick section in the intro / docs to quickly highlight what's not exposed from Node or W3C Worker spec. A lot of the Web Worker tutorials suggested 'use cases' mention handling network activity in the background so its probably quite a common need for a Web Worker. |
Hi - did you get any volunteers on exposing node's network stack? (currently I'm still with my original design of WebSocket command handlers being handled from within the WebWorker, but as a workaround for the above I added another layer of message routing back between the MainThread - however now the app is getting fairly complex I could do with removing this extra layer of complexity, either by rebuilding the WS handlers solely in the main thread, or (hopefully!) waiting for nodes network stack to be exposed) Many thanks! |
Understood. No volunteers have stepped forward yet. I'm still hopeful though! :-) |
I am trying to do something similar. I need to be able to use the perl inside of the worker function. Is it possible to pass the constructed object to the worker? |
Hi audreyt, Can you explain a little bit in detail in why WebSocket implementation using node JS , for example this one: https://github.com/websockets/ws does not work in webwoker threads?. I am trying to use ws with webwoker threads to debug and test some project that involve using these two. Although I am new NodeJS , I might offer to help in implementing the missing stuff that web worker needs to get WebSocket needed for my own project if you explain a little bit. Thank you. |
Hi @saadnaji , the main issue is that, as described #9 (comment) workers run in a "pure" v8 Isolate, and does not have access to Node's |
Thank you for the reply, I have knowledge in C programming which webwoker threads uses part of it in its implementation. What is the best way to start contributing to help expose 'net' module?. Can you provide directions?. Like I said above, I started learning NodeJS last month and JS 3 months ago for my undergraduate CS project. |
Yes. However, currently unless you need to pass very large amount of data between threads, or plan to spawn a huge amount of threads, the process-based https://www.npmjs.com/package/workerjs should already work with Similar discussions: nodejs/node#180 node-forward/discussions#25 |
Hi
Firstly, great work. I have a huge OCD for not using 3rd party libraries, but your 'node-webworker-threads' feels like it should be part of the core node.
As context, I've written a browser based wep-app that relies on WebWorkers, and now I'm able to use your library to simulate a headless client at the server side with node, with almost no coding changes to the App. A real breakthrough for me!
I've come up against a challenge though, as I also require WebSockets - initiated from within the WebWorker.
Inside my worker code I have :
connection = new WebSocket( url, protocol);
I've run some successfull tests from a node main thread using:
var WebSocket = require('websocket').client; [from https://github.com/Worlize/WebSocket-Node]
However I can't use require to pull in modules into a node-webworker.
Can you let me know your recommended approach to get around this?
Many thanks.
The text was updated successfully, but these errors were encountered: