Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lostbeard/spawndev.blazorjs.messagepack
MessagePack Javascript library for Blazor WebAssembly
https://github.com/lostbeard/spawndev.blazorjs.messagepack
blazor blazor-webassembly dotnet message-pack
Last synced: about 1 month ago
JSON representation
MessagePack Javascript library for Blazor WebAssembly
- Host: GitHub
- URL: https://github.com/lostbeard/spawndev.blazorjs.messagepack
- Owner: LostBeard
- License: mit
- Created: 2024-06-05T15:50:17.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-08-06T16:04:18.000Z (3 months ago)
- Last Synced: 2024-10-14T05:22:34.799Z (about 1 month ago)
- Topics: blazor, blazor-webassembly, dotnet, message-pack
- Language: CSS
- Homepage: https://lostbeard.github.io/SpawnDev.BlazorJS.MessagePack/
- Size: 6.38 MB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# SpawnDev.BlazorJS.MessagePack
MessagePack binary Javascript encoder and decoder for Blazor WebAssembly.[![NuGet version](https://badge.fury.io/nu/SpawnDev.BlazorJS.MessagePack.svg?label=SpawnDev.BlazorJS.MessagePack)](https://www.nuget.org/packages/SpawnDev.BlazorJS.MessagePack)
**SpawnDev.BlazorJS.MessagePack** brings the amazing [MessagePack](https://github.com/msgpack/msgpack-javascript) library to Blazor WebAssembly.
**SpawnDev.BlazorJS.MessagePack** uses [SpawnDev.BlazorJS](https://github.com/LostBeard/SpawnDev.BlazorJS) for Javascript interop allowing strongly typed, full usage of the [MessagePack](https://github.com/msgpack/msgpack-javascript) 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](https://github.com/msgpack/msgpack-javascript) repo.
### Demo
[Basic Demo](https://lostbeard.github.io/SpawnDev.BlazorJS.MessagePack/)### Getting started
Add the Nuget package `SpawnDev.BlazorJS.MessagePack` to your project using your package manager of choice.
```dotnet
dotnet add package SpawnDev.BlazorJS.MessagePack
```**Add MessagePack Javascript Library**
Add to `index.html`
```html```
Modify the Blazor WebAssembly `Program.cs` to initialize SpawnDev.BlazorJS for Javascript interop.
Example Program.cs
```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");
builder.RootComponents.Add("head::after");// Add SpawnDev.BlazorJS interop
builder.Services.AddBlazorJSRuntime();// Run app using BlazorJSRunAsync
await builder.Build().BlazorJSRunAsync();
```Example Home.razor
```html
@page "/"SpawnDev.BlazorJS.MessagePack
SpawnDev.BlazorJS.MessagePack
This demo converts text to binary using MessagePack Javascript library and SpawnDev.BlazorJS.MessagePack
Pack
@((MarkupString)outgoing)
@((MarkupString)readback)
```Example Home.razor.cs
```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(uint8Array);
}
}
}
```