Skip to content

Add multiplayer mode by hosting the Blazor Wasm Site, inside a Blazor Server Site #181

@lachlanwgordon

Description

@lachlanwgordon

Playing with trains all on your own during a pandemic is lonely. Let's make it multiplayer so we can all work on the same train set at the same time.

I'm experimenting with running BlazorWasm apps inside iframes on Blazor Server sites. This seems a little confusing but could open up some cool scenarios.

For Trains.Net this would mean having a Balzor server site with very little code in it. I will manages a shared set of Entities and terrain that each client renders.

The benefits of an approach like this over pure server or pure wasm blazor are:

  • Blazor server makes it easy to share data between users
  • Blazor WASM is super fast and can run SkiaSharp at high framerates with most of the processing done on the client.

This could all be done by having the WASM app call a server but i think that would be a lot more code, and I'm using this as an experiment because I'm interested in adding high performance Skia content to existing server side blazor applications.

Code Changes

To get this running I'll need to add a method to the WASM Site that can be called from JavaScript to pass in the new/modified entities. Most of the saving/loading and serializing is already working, but I'll need to fix issue #180 to get this work.

There will need to be a new project added to the solution to host the Blazor Server App.

POC

As an experiment I've got this map running in a Blazor server website. When ever any user modifies it, all users see the updates instantly. The only difference is that this is a Javascript Map(not WASM, but still running on the client) that gets passed lat/lon coordinates. For trains it will be the existing Trains running in skia that gets entities and terrain passed to it.

Here it is running on my Mac and on my phone over 4g.

2021-11-04 00 14 34

You can try it at https://mapcollaborate.azurewebsites.net/ and view the source at https://github.com/lachlanwgordon/MapCollaborate.

Hosting/Merging?

Are you open to this feature?

Would you want to host it on your own server, or can i have permission to run it on my own Azure App Service?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions