Skip to content

Ability to invoke async JavaScript functions and methods #3084

Closed

Description

@bricelam

What would you like to be added:

I'd love to see something similar to Blazor's IJSRuntime.InvokeAsync method. The workaround suggested in #65 is less than ideal.

Why is this needed:

I'm trying to leverage the oidc-client JavaScript library whose methods are all async (return Promise).

For which Platform:

  • iOS
  • Android
  • WebAssembly
  • WebAssembly renderers for Xamarin.Forms
  • macOS
  • Windows
  • Build tasks
  • Solution Templates

Activity

  1. added
    kind/enhancement
    triage/untriaged
    on Apr 29, 2020
  2. bricelam commented on May 4, 2020

    @bricelam
    Author

    I was able to leverage mono-wasm for now.

    <PropertyGroup>  
      <MonoWasmSDKName>mono-wasm-34cccfa2fde</MonoWasmSDKName>
      <MonoWasmSDKUri>https://unowasmbootstrap.blob.core.windows.net/runtime/$(MonoWasmSDKName).zip</MonoWasmSDKUri>
      <WasmShellMonoTempFolder>$([System.IO.Path]::GetTempPath())\</WasmShellMonoTempFolder>
      <MonoWasmSDKPath>$(WasmShellMonoTempFolder)$(MonoWasmSDKName)\</MonoWasmSDKPath>
    </PropertyGroup>
    <ItemGroup>
      <Reference Include="WebAssembly.Bindings">
        <HintPath>$(MonoWasmSDKPath)framework\WebAssembly.Bindings.dll</HintPath>
        <Private>false</Private>
      </Reference>
    </ItemGroup>
    <Target Name="InstallMonoWasmSDK" AfterTargets="Restore">  
      <DownloadFile SourceUrl="$(MonoWasmSDKUri)" DestinationFolder="$(WasmShellMonoTempFolder)" />
      <Unzip SourceFiles="$(WasmShellMonoTempFolder)$(MonoWasmSDKName).zip" DestinationFolder="$(MonoWasmSDKPath)" />
    </Target>
    var oidcModule = (JSObject)Runtime.GetGlobalObject("Oidc");            
    var userManagerType = (Function)oidcModule.GetObjectProperty("UserManager");
    var userManager = Runtime.NewJSObject(userManagerType);
    
    var user = (JSObject)await (Task<object>)userManager.Invoke("signinSilent");
  3. jeromelaban commented on May 5, 2020

    @jeromelaban
    Member

    Indeed that's a way to use async methods there. The distribution model of the Bindings is not appropriate, and is very dependent on the mono version.

    We'll most probably adjust that within the .NET 5 timeframe.

  4. self-assigned this
    on May 18, 2020
  5. added
    platform/wasm 🌐
    and removed
    triage/untriaged
    on May 19, 2020
  6. carldebilly commented on May 19, 2020

    @carldebilly
    Member

    @bricelam This feature has been merged into master and available as version 3.0.0-dev.25 on nuget.

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

Metadata

Metadata

Assignees

Labels

kind/enhancementplatform/wasm 🌐

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions