Skip to content
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

example for using remote web worker ( stockfish js) #93

Open
hunght opened this issue Nov 20, 2020 · 3 comments
Open

example for using remote web worker ( stockfish js) #93

hunght opened this issue Nov 20, 2020 · 3 comments
Assignees
Labels
question Further information is requested

Comments

@hunght
Copy link

hunght commented Nov 20, 2020

i try to use this lib https://github.com/nmrugg/stockfish.js/ as a web worker, but it not working. could you have the same example which using normal web worker like postMessage and onmessage, thanks in advance

@hunght hunght added the question Further information is requested label Nov 20, 2020
@alewin
Copy link
Owner

alewin commented Nov 20, 2020

Of course, in the next few days I'll try to look at it

@alewin alewin self-assigned this Nov 20, 2020
@alewin
Copy link
Owner

alewin commented Nov 22, 2020

HI @zant I was preparing a demo with "stockfish.js"

const demoFn = () => {
  var stockfish = STOCKFISH();
  .....
};

function App() {
  const { addToast } = useToasts();

  const [ worker, { status, kill } ] = useWorker(demoFn, {
    remoteDependencies: [
      "https://cdn.jsdelivr.net/npm/[email protected]/src/stockfish.min.js"
    ]
  });

I noticed that the sotckfish library uses by default a communication with "postMessages": API Docs.
Even if it would work it wouldn't make sense to call

stockfish.postMessage ("go depth 15 ");

inside demoFN.


Proposal

I thought that we could make available the possibility to import a webworker file as well.

const [ worker, { status, kill } ] = useWorker("stockfish.js")

Obviously, if you want to use this feature, you will have to modify your webpack configuration
https://webpack.js.org/loaders/worker-loader/

What do you think about it? 🤔

@zant
Copy link
Collaborator

zant commented Nov 23, 2020

Killer feature! @alewin

Looks really good to me, with good docs on the webpack thingy I think it's good to go 👍

Also, FWIW there's an ongoing proposal (Stage 1) on JS module blocks it will basically let us inline modules in code and pass them around as they were files. So if that gets through we will have two ways of doing this, with lots of other cool stuff :)

@alewin alewin moved this to Nice to have in useWorker TODOs Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
Status: Nice to have
Development

No branches or pull requests

3 participants