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

[feat req] Use in browser via webpack, browserify #491

Closed
redbrain opened this issue Mar 22, 2021 · 16 comments · Fixed by #633
Closed

[feat req] Use in browser via webpack, browserify #491

redbrain opened this issue Mar 22, 2021 · 16 comments · Fixed by #633

Comments

@redbrain
Copy link

Hello,
It would be nice if flying-squid would be webpackable to use completely client-side.
What currently limits flying-squid from being webpacked, and can these limitations be ignored to create a simple server?

@rom1504
Copy link
Member

rom1504 commented Mar 22, 2021

yeah totally agree, that's something we want for PrismarineJS/prismarine-web-client#47

Nobody tried to do it but the minimum we need is a connection provider in node-minecraft-protocol server to replace the tcp server. Opened an issue for this there PrismarineJS/node-minecraft-protocol#829

@redbrain
Copy link
Author

Good to hear that this is already in consideration.
I'll subscribe to the mentioned issues, and speak here again once those are mature enough to implement a client-side server.

@redbrain
Copy link
Author

In addition to a TCP alternative, we'll need to provide an alternative to FS, since browsers don't have native FS access (yet).
For player data, perhaps the browser's localStorage is a good alternative; that will probably need an option to be enabled.
The items exported via requireindex could probably be specified manually, at least to my understanding.
I'm not sure how we should implement world storage and logging. I also haven't looked at FS usage in any dependencies.

@rom1504
Copy link
Member

rom1504 commented Mar 22, 2021

Yeah world storage can be done using indexeddb

@mollthecoder
Copy link

BrowserFS would be a good way to access FS in browser.

@bluefoxy009
Copy link
Contributor

Maybe WebSockets for the client communication?

@extremeheat
Copy link
Member

No network connection is necessary in single player mode

@bluefoxy009
Copy link
Contributor

No network connection is necessary in single player mode

Fair, we could use a one-sided messaging channel with some javascript, like the way socket.io works for messages.

@extremeheat
Copy link
Member

All that needs to be done is use the existing event emitters. Drop nmp dep and when mineflayer does a write, the event should instead be emitted to flying squid directly.

@extremeheat
Copy link
Member

No serialization is needed, and when flying squid wants to write it would just go right to mineflayer bot eventemitter

@tutacat
Copy link

tutacat commented Mar 16, 2022

webStorage isn't an actual fs, it is emulated, and indexedDB is much faster, and with a Blob

But does it even make sense to webpack it???

@vantezzen
Copy link

I've worked on wrapping flying-squid to let it run in the browser over at https://github.com/vantezzen/electric-squid (https://squid.blymp.io/). It's still a very rough proof-of-concept, but connecting to the server via a Minecraft Client is still (mostly) possible.

There were some difficulties getting webpack to build the bundle (mainly solved by increasing the RAM limit, writing custom polyfills and patching dependencies manually) but generally it seems do-able. webpack's tree-shaking also seems to be very stressed as some small changes to the code result in the bundle size fluctuating between 50-400MB.

I've used the methods discussed here to create a client-server connection via WebSockets and using IndexedDB via the level filesystem to replace the fs module.

@rom1504
Copy link
Member

rom1504 commented May 22, 2022

@vantezzen that's awesome!
Let's us know how it goes
If you see changes in flying-squid that could make this experiment easier, do say

@zardoy
Copy link
Contributor

zardoy commented Aug 17, 2023

Hi everyone! I couldn't find a way to polyfill all the necessary components, so I decided to debug and modify the required code instead.
Right now, I've managed to use this server in the browser and implemented the desired singleplayer support in forked mineflayer web client. In the browser, we can easily save worlds in browser memory or interact with the real file system instead (however the sad part is that Chrome doesn't allow to open folders in %appdata% directly). I don't have a clean solution yet, though there are already some improvements in the fork

@rom1504
Copy link
Member

rom1504 commented Aug 17, 2023 via email

@zardoy
Copy link
Contributor

zardoy commented Aug 17, 2023

If you can figure out some branching so that both in browser and in node is supported with the same code and contribute to this repo it would be great.

Sure thing! No worries at all, as long as you're up for reviewing the code :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants