-
Notifications
You must be signed in to change notification settings - Fork 592
Add support for browser platform #2975
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
Conversation
Thank you for opening this! We'll work on getting it reviewed. One thing I can say is that the |
if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("Browser"))) | ||
{ | ||
// For WebAssembly, we need to pass the auth token as a query parameter | ||
uri += $"&token={Uri.EscapeDataString(auth)}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's generally not considered best practice to send an auth token via a URL param. To get around this in our C# (WebGL) and Typescript SDKs we generate a short-lived token which you can generate via an API call. This short lived token is then used instead of your real token. You can see an implementation of this here: (C# SDK) https://github.com/clockworklabs/SpacetimeDB/pull/2988/files and then also here for the typescript SDK: https://github.com/clockworklabs/SpacetimeDB/blob/36f7ca2583a7491285460454839e41ff43ec27a7/sdks/typescript/packages/sdk/src/websocket_decompress_adapter.ts#L93C1-L110C6
I think let's wait for #2988 to land first and see if we can just use the same auth flow that we're using for WebGL?
@rekhoff Testing requirements for this:
Impl requirements:
|
Changes in 461e245 break all Unity projects, including BitCraft. Without maintaing support for Unity projects, this PR can not move forward. |
@alex47 Thank you for your contribution!
If you're able to fix those issues we'll give this another review, |
Thanks again for the contribution, we haven't heard back in a while so we're going to close this for now but if you end up wanting to move this forward let us know 👍 |
Description of Changes
This is a continuation of:
browser
platform com.clockworklabs.spacetimedbsdk#274I have applied those changes to the latest codebase.
Added support for the browser platform.
This required:
Thread.Start
with aTask
(Thread.Start
is not supported forbrowser
platforms)PreProcessMessages
async, in order to use Channels async methodsTask
to be allowed to run on a separate thread (ConfigureAwait(false)
)BlockingCollection
(which is not supported on thebrowser
platform) withChannel
(which is supported on all platforms)IDbConnection.Connect
to run on any thread, not necessarily the caller (ConfigureAwait(false)
)Ws.Options.UseDefaultCredentials = true;
(this is alreadytrue
by default. In addition, using this setter is not being supported bybrowser
platforms.)Ws.Options.SetRequestHeader
is not supported onbrowser
platformAPI
N/A. No changes to the API.
Requires SpacetimeDB PRs
N/A
Testsuite
SpacetimeDB branch name: master
Testing
Testing was performed manually inside of a Blazor WebAssembly Standalone App, using the reference quickstart-chat code.
The test project can be found here: https://github.com/alex47/BlazorWebassemblyChat