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

webworker clientstream + webrtc datachannels as workers #21

Merged
merged 23 commits into from
Jul 31, 2024

Conversation

lesleyrs
Copy link
Contributor

@lesleyrs lesleyrs commented Jul 14, 2024

Note: I commented out reserved mangle properties as they are causing the webworker bundles to break, however I haven't come across issues without them. For example I reported the members property having to be reserved but it's fine right now and am able to use members items. data/src won't be copied to public as it's not needed and embedding LoginThread inside of worker.js was breaking out of the string variable due to string interpolation. Fixed.

From here the only thing that's needed is npm run bundle and set world to 999.

@lesleyrs lesleyrs changed the title webworker client webworker clientstream Jul 14, 2024
@ultraviolet-jordan
Copy link
Collaborator

If you built for prod then you will see why the reserves for the names are necessary. If this PR goes through it should break the client.

@lesleyrs
Copy link
Contributor Author

No it definitely works for me on prod (it's live running on my github pages world 999) and member items work. But haven't tested every reserve.

image

I'm using the same workflow and right clicked the dragon long. It's a bit sus why it works now though as I haven't really changed anything that would avoid it breaking.

@ultraviolet-jordan
Copy link
Collaborator

No it definitely works for me on prod (it's live running on my github pages world 999) and member items work. But haven't tested every reserve.

image

I'm using the same workflow and right clicked the dragon long. It's a bit sus why it works now though as I haven't really changed anything that would avoid it breaking.

I think the bug comes from when it tries to read the world list specifically, the terser plugin for some reason can mess up some code that it's running through. I think you'd want to check that Free to Play worlds would show Members objects for these members items was the original bug (it wouldnt do that). If it works then we ship

@lesleyrs
Copy link
Contributor Author

If that's the case the problem would still be around when connecting to official servers unfortunately.

I don't mind the worker client just being a fork because client2 doesn't get many changes at all, but I may look into this more after I finish webrtc stuff. And iirc the problem was members worlds showing members item

@lesleyrs lesleyrs marked this pull request as draft July 23, 2024 01:21
@ultraviolet-jordan
Copy link
Collaborator

Don't get me wrong I am totally cool to merge it in I just wanna make sure but yeah let me know and we can merge it in.
Also do the added wasm files have to be included as well? I can understand just having the bzip one generated from assemblyscript there, not sure about the rsmod one, rsmod should only have to be server only.

@lesleyrs
Copy link
Contributor Author

lesleyrs commented Jul 23, 2024

The bzip is also from the server. worker.js+LoginThread.js generated by npm run bundle in server is the app entrypoint of 2004scape (minus cache packing, compiling runescript, http server) running as a webworker in the browser. The bundles need rsmod+server bzip to run, client bzip could've been used but didn't want to add another bzip lib to the server. It's essentially a no install, offline, singleplayer server until webrtc is added for peer to peer play.

The wasm files don't change often so I added them directly, the js bundles and data dir are gitignored by default.

This is the vision but 2004: https://2003scape.github.io/

@lesleyrs
Copy link
Contributor Author

lesleyrs commented Jul 28, 2024

Completed the webworker stream + webrtc data channel connections which emulate a webworker.

It works kind of like https://github.com/2003scape/rsc-client/blob/master/src/lib/net/socket.js#L43 but without using the peer library

Updated readme for a quick explanation, basically world 999 for webrtc host and world 998 for peers. The webclient on world 999 will turn into a server where you manually add peers but you can still play on it as well. The SDP message does contain your public ip though. AND it's copied automatically when you click new user.

Live on github as well:
Host: https://lesleyrs.github.io/Client2/?world=999
Peer: https://lesleyrs.github.io/Client2/?world=998

Final issue I couldn't fix is adding exclude to terserplugin didn't do anything, so I had to comment the reserved properties once again, it kept giving errors about the js bundles even though they should have been ignored... Maybe somebody else knows?

@lesleyrs lesleyrs marked this pull request as ready for review July 28, 2024 13:52
@lesleyrs lesleyrs changed the title webworker clientstream webworker clientstream + webrtc datachannels as workers Jul 28, 2024
@lesleyrs
Copy link
Contributor Author

lesleyrs commented Jul 29, 2024

Ok got terser working again, having the bundles in /public instead of src/public directly worked (it just didn't seem to work as I had the files in both places before). Pull from server branch to get path changes and remove the src/public bundles obviously.

Apparently the fix from earlier (not pushed) with only including src/js dir and making server use a bit of cjs to avoid top level awaits actually worked and index.js is supposed to be 373kb, but I prefer this fix anyway as you don't need server changes because terser still gave the top level errors even with module: true as that only applies to files that are included.

@ultraviolet-jordan ultraviolet-jordan merged commit bf004a8 into 2004Scape:main Jul 31, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants