You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I spent the morning kind of messing around with setting up a new overlay and I was wondering if it would be possible to run the log parsing part in a web worker and then just post the interesting, processed, messages to my overlay to do stuff with.
Unfortunately, common.js doesn't really work in a web-worker, for various reasons I imagine. For one, it poops whenever you try to use window which is not available in a worker, and for another I'm not sure if whatever magi-globals the plugin puts in the window exist in the worker space.
Websockets work great, though, so I managed to get it working by modifying the contents of common. It's not ideal since it relies on implementation details that could change so I wonder if we could get like a common.worker.js in dist (or some other way cooler solution)?
To get it to work I had to:
Change wsUrl to not come from the location and instead be a param of connectWs
Make an onmessage handler to initiate connectWs from the main process (the main process sends the wsUrl)
Delete the 'else' part of the websocket/local statement so it always tries to use websocket.
Change anything that assigned to window.variable into a const variable = declaration
Sorry if this is weird, it's not really an issue, it's a feature request so feel free to close it if it doesn't fit your scope! I would be willing to do a PR for the first version but I wanted to see if it's even interesting to you.
Thanks for making this amazing bit of tech.
The text was updated successfully, but these errors were encountered:
You're correct that window isn't available from the WebWorker's scope, however you can simulate the needed global-scope properties pretty easily for the purposes that common.js needs, something like this should be sufficient:
window=window||{};
You'd then make sure to run that before loading common.js or make it its own separate file that can be included/required depending on how you're doing things.
As for the location property, that exists within the scope of a webworker already, it just uses the webworker's location to begin with, so if you append ?OVERLAY_WS=... to the webworker's location when creating it, that should be sufficient to pass it through.
sandtechnology
pushed a commit
to sandtechnology/OverlayPlugin
that referenced
this issue
May 7, 2023
So this is out of left field,
I spent the morning kind of messing around with setting up a new overlay and I was wondering if it would be possible to run the log parsing part in a web worker and then just post the interesting, processed, messages to my overlay to do stuff with.
Unfortunately, common.js doesn't really work in a web-worker, for various reasons I imagine. For one, it poops whenever you try to use window which is not available in a worker, and for another I'm not sure if whatever magi-globals the plugin puts in the window exist in the worker space.
Websockets work great, though, so I managed to get it working by modifying the contents of common. It's not ideal since it relies on implementation details that could change so I wonder if we could get like a common.worker.js in dist (or some other way cooler solution)?
To get it to work I had to:
window.variable
into aconst variable =
declarationSorry if this is weird, it's not really an issue, it's a feature request so feel free to close it if it doesn't fit your scope! I would be willing to do a PR for the first version but I wanted to see if it's even interesting to you.
Thanks for making this amazing bit of tech.
The text was updated successfully, but these errors were encountered: