SpawnDev.BlazorJS.MessagePack
1.3.1
See the version list below for details.
dotnet add package SpawnDev.BlazorJS.MessagePack --version 1.3.1
NuGet\Install-Package SpawnDev.BlazorJS.MessagePack -Version 1.3.1
<PackageReference Include="SpawnDev.BlazorJS.MessagePack" Version="1.3.1" />
paket add SpawnDev.BlazorJS.MessagePack --version 1.3.1
#r "nuget: SpawnDev.BlazorJS.MessagePack, 1.3.1"
// Install SpawnDev.BlazorJS.MessagePack as a Cake Addin #addin nuget:?package=SpawnDev.BlazorJS.MessagePack&version=1.3.1 // Install SpawnDev.BlazorJS.MessagePack as a Cake Tool #tool nuget:?package=SpawnDev.BlazorJS.MessagePack&version=1.3.1
SpawnDev.BlazorJS.MessagePack
MessagePack binary Javascript encoder and decoder for Blazor WebAssembly.
SpawnDev.BlazorJS.MessagePack brings the amazing MessagePack library to Blazor WebAssembly.
SpawnDev.BlazorJS.MessagePack uses SpawnDev.BlazorJS for Javascript interop allowing strongly typed, full usage of the MessagePack Javascript library. Voice, video and data channels are all fully supported in Blazor WebAssembly. The SpawnDev.BlazorJS.MessagePack API is a strongly typed version of the API found at the MessagePack repo.
Demo
Getting started
Add the Nuget package SpawnDev.BlazorJS.MessagePack
to your project using your package manager of choice.
dotnet add package SpawnDev.BlazorJS.MessagePack
Add MessagePack Javascript Library
Add to index.html
<script src="_content/SpawnDev.BlazorJS.MessagePack/msgpack.min.js"></script>
Modify the Blazor WebAssembly Program.cs
to initialize SpawnDev.BlazorJS for Javascript interop.
Example Program.cs
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using SpawnDev.BlazorJS;
using SpawnDev.BlazorJS.MessagePack.Demo;
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");
// Add SpawnDev.BlazorJS interop
builder.Services.AddBlazorJSRuntime();
// Run app using BlazorJSRunAsync
await builder.Build().BlazorJSRunAsync();
Example Home.razor
@page "/"
<PageTitle>SpawnDev.BlazorJS.MessagePack</PageTitle>
<h1>SpawnDev.BlazorJS.MessagePack</h1>
<p>
This demo converts text to binary using MessagePack Javascript library and SpawnDev.BlazorJS.MessagePack
</p>
<div>
<textarea style="width: 600px; word-wrap: break-word; white-space: normal;" @bind=@incoming></textarea>
<button @onclick=@Submit>Pack</button>
</div>
<div>
<pre style="width: 600px; word-wrap: break-word; white-space: normal;">@((MarkupString)outgoing)</pre>
</div>
<div>
<pre style="width: 600px; word-wrap: break-word; white-space: normal;">@((MarkupString)readback)</pre>
</div>
Example Home.razor.cs
using SpawnDev.BlazorJS.JSObjects;
namespace SpawnDev.BlazorJS.MessagePack.Demo.Pages
{
public partial class Home
{
string outgoing = "";
string incoming = "";
string readback = "";
void Submit()
{
// encode to a Uint8Array using MessagePack
using Uint8Array uint8Array = MessagePack.Encode(incoming);
// the Uint8Array could now be sent over WebRTC, saved to file, etc.
// for this demo we are converting to hex and displaying it
var bytes = uint8Array.ReadBytes();
outgoing = Convert.ToHexString(bytes);
// decode to a string using MessagePack
readback = MessagePack.Decode<string>(uint8Array);
}
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- Microsoft.AspNetCore.Components.WebAssembly (>= 6.0.25)
- SpawnDev.BlazorJS (>= 2.5.4)
-
net7.0
- Microsoft.AspNetCore.Components.WebAssembly (>= 7.0.14)
- SpawnDev.BlazorJS (>= 2.5.4)
-
net8.0
- Microsoft.AspNetCore.Components.WebAssembly (>= 8.0.1)
- SpawnDev.BlazorJS (>= 2.5.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.