flying-squid icon indicating copy to clipboard operation
flying-squid copied to clipboard

[feat req] Use in browser via webpack, browserify

Open redbrain opened this issue 4 years ago • 13 comments
trafficstars

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?

redbrain avatar Mar 22 '21 19:03 redbrain

yeah totally agree, that's something we want for https://github.com/PrismarineJS/prismarine-web-client/issues/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 https://github.com/PrismarineJS/node-minecraft-protocol/issues/829

rom1504 avatar Mar 22 '21 19:03 rom1504

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 avatar Mar 22 '21 23:03 redbrain

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.

redbrain avatar Mar 22 '21 23:03 redbrain

Yeah world storage can be done using indexeddb

rom1504 avatar Mar 22 '21 23:03 rom1504

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

mollthecoder avatar May 16 '21 23:05 mollthecoder

Maybe WebSockets for the client communication?

bluefoxy009 avatar Jan 23 '22 22:01 bluefoxy009

No network connection is necessary in single player mode

extremeheat avatar Jan 24 '22 00:01 extremeheat

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.

bluefoxy009 avatar Jan 24 '22 15:01 bluefoxy009

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 avatar Jan 24 '22 19:01 extremeheat

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

extremeheat avatar Jan 24 '22 19:01 extremeheat

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???

tutacat avatar Mar 16 '22 00:03 tutacat

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.

vantezzen avatar May 22 '22 17:05 vantezzen

@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

rom1504 avatar May 22 '22 18:05 rom1504

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

zardoy avatar Aug 17 '23 03:08 zardoy

Hey! Sounds great!

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.

On Thu, Aug 17, 2023, 05:18 Vitaly @.***> wrote:

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 https://github.com/zardoy/prismarine-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 http://github.com/zardoy/space-squid

— Reply to this email directly, view it on GitHub https://github.com/PrismarineJS/flying-squid/issues/491#issuecomment-1681549526, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAR437VYSO24MQLV35YN2KDXVWER7ANCNFSM4ZTWTRAQ . You are receiving this because you commented.Message ID: @.***>

rom1504 avatar Aug 17 '23 07:08 rom1504

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 :)

zardoy avatar Aug 17 '23 17:08 zardoy