Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Blazor WebAssembly call another WASM module directly?

Can Blazor WebAssembly code call functions from another WASM module directly or is a JavaScript bridge required?

OpenCV has been built for WASM, as OpenCV.js. Is there a way of exporting the function definitions from the OpenCV WASM implementation and using them directly from the Blazor code? Is the best alternative to use JS Interop and have JS functions that call the OpenCV functions?

like image 940
Bernard Darnton Avatar asked Apr 28 '20 21:04

Bernard Darnton


People also ask

Is Blazor Wasm faster than JavaScript?

In essence, you can write C# code where you'd previously use JavaScript, and Blazor will compile that C# to WebAssembly to allow it to run in the browser. However, I was a little surprised to find that when I tested the speed of it versus the application written in JavaScript, it was noticeably slower.

What is the difference between Blazor server and Blazor WebAssembly?

Blazor Server apps have direct access to server and network resources where the app is executing. Because Blazor WebAssembly apps execute on a client, they don't have direct access to server and network resources.

Is Blazor Wasm a spa?

Blazor WebAssembly is a single-page app (SPA) framework for building interactive client-side web apps with . NET. Blazor WebAssembly uses open web standards without plugins or recompiling code into other languages. Blazor WebAssembly works in all modern web browsers, including mobile browsers.

What is AOT compilation Blazor?

Ahead-of-time (AOT) compilation. Blazor WebAssembly supports ahead-of-time (AOT) compilation, where you can compile your . NET code directly into WebAssembly. AOT compilation results in runtime performance improvements at the expense of a larger app size.

What is Blazor WebAssembly (wasm)?

Blazor WebAssembly (WASM) apps executes directly in the browser on a WebAssembly, just like JavaScript. Blazor WebAssembly apps are provided with the following things:

How do I create a Blazor Wasm site in Visual Studio?

When creating a Blazor Wasm site you can choose this option in Visual Studio by selecting these options: Both of these create a solution with a Blazor Wasm client app, ASP.NET Core Server app, and a shared (optional) library project for sharing code between the two (like models or things like that).

How do I bind a 3rd party API to Blazor Wasm?

What you need to do is bind your service and client together like this: First be sure your 3rd party api support CORS or you will not be able to call them. On blazor WASM httpclient just uses JavaScript to make network calls, and is restricted by the browser rules.

Can Blazor WebAssembly apps be deployed to Azure App services?

Blazor WebAssembly apps can be deployed to Azure App Services on Windows, which hosts the app on IIS. Deploying a standalone Blazor WebAssembly app to Azure App Service for Linux isn't currently supported. A Linux server image to host the app isn't available at this time.


Video Answer


1 Answers

This should be achieved much more easily with .NET 6 as Blazor now supports native dependencies. You can compile the OpenCV C++ or OpenCV.js to wasm using emscripten and add a native file to your csproj as shown below.

<NativeFileReference Include="path-to-output-file" />

You can then go ahead and P/Invoke into the native code. In this YouTube video, Steve Sanderson demos a very similar scenario. You can also check out the docs on Native Dependencies in Blazor for more information.

like image 109
SmartE Avatar answered Oct 22 '22 08:10

SmartE