Universal Hubs
Getting Started
Section titled “Getting Started”| GitHub | |
| Hubs, host, client, generator | |
| Bluetooth LE | |
| HTTP (Wi-Fi, LAN, tunnels) | |
| Multipeer (Apple) | |
| Nearby (Android, iOS, macOS) |
Universal Hubs brings the SignalR programming model to nearby devices. One device hosts a hub, and other devices discover it, connect, and call it through a strongly typed proxy. The host pushes events back to all clients, one client, everyone else, or a group.
Write the hub once and serve it over Bluetooth LE, HTTP (Wi-Fi, LAN or the internet through a tunnel), Apple’s MultipeerConnectivity and Google’s Nearby Connections at the same time, or over a transport of your own. Every client shares the same hub, groups and pushes, whichever way it connected. Players on a plane connect over BLE or Nearby. At home they connect over Wi-Fi.
Features
Section titled “Features”- One interface describes the hub. Its methods are client → host calls (
Task,Task<T>,IAsyncEnumerable<T>) and its events are host → client pushes. - Source generated: the client proxy, hub dispatcher and typed push methods, with compile-time diagnostics.
- Hubs:
Context,Clients(All / Others / Caller / Client / Group…),Groups,OnConnectedAsync/OnDisconnectedAsyncandContext.Abort(), on every transport at once. - Each hub picks its transports, its own serializer and, over BLE, its own GATT service.
- One discovery list. A host seen over several transports is one entry. Clients connect over the first transport that works, in an order you choose, and fall back to the next.
- Turn transports on and off while the app runs, on the host and the client.
- Resume after a dropped link: same connection id and groups, missed pushes replayed, on every transport.
- Files and media channels (live audio and video packet pipes) on every transport.
- Dynamic hubs: hubs defined while the app runs.
- AOT and trim safe, with no reflection.
-
Install the core package and the transports you use. The transport packages also build for plain .NET, where a transport the platform doesn’t have reports itself unsupported and is skipped, so one registration works in a cross-platform app.
Terminal window dotnet add package Shiny.UniversalHubsdotnet add package Shiny.UniversalHubs.BluetoothLEdotnet add package Shiny.UniversalHubs.Http -
Describe the hub in an interface both sides can see (see Contracts):
using Shiny.UniversalHubs;[UniversalHubContract]public interface IChatHub{Task<bool> Send(string message); // client -> hostevent Action<string, string> Received; // host -> clients (who, message)}[JsonSerializable(typeof(string))][JsonSerializable(typeof(bool))]public partial class ChatJsonContext : JsonSerializerContext; -
Implement it on the host:
public class ChatHub : UniversalHub<IChatHub>{public async Task<bool> Send(string message){// this.Connection.Transport says how the caller is connectedawait this.Clients.All.Received(this.Context.Client.Name ?? "?", message);return true;}} -
Register everything in
MauiProgram. Each hub has a name, and picks its transports:Shiny.Json.AddContext(ChatJsonContext.Default);// hostbuilder.Services.AddUniversalServer(server => server.Configure(o => o.LocalName = "Allan").AddHub<ChatHub>("chat", hub => hub.UseHttp("_mychat._tcp").UseBluetoothLE(serviceUuid: "FE10", characteristicUuid: ChatCharacteristicUuid)));// client - the same name, and the same transport settingsbuilder.Services.AddUniversalHubClient<IChatHub>("chat", o => o.UseHttp("_mychat._tcp").UseBluetoothLE("FE10", ChatCharacteristicUuid)); -
Start hosting on one device:
// IUniversalHubHost host - every hub on every transport this device can run right nowIReadOnlyList<IHubTransport> running = await host.Start(); -
Discover, connect and call it from another:
// IUniversalHubClient<IChatHub> clientclient.Hub.Received += (who, message) => Messages.Add($"{who}: {message}");var host = await client.DiscoverAll().FirstAsync(x => x.Transports.Count > 0);await client.Connect(host, new HubConnectOptions("Allan")); // HTTP first here, then BLEawait client.Hub.Send($"hello over {client.Transport?.DisplayName}!");
Platform Setup
Section titled “Platform Setup”iOS / macOS (Info.plist), on both the host and the client:
<key>NSBluetoothAlwaysUsageDescription</key><string>Bluetooth is used to talk to nearby devices</string><key>NSLocalNetworkUsageDescription</key><string>The local network is used to talk to nearby devices</string><key>NSBonjourServices</key><array> <string>_mychat._tcp</string> <!-- every hub's mDNS service type --></array><!-- clients: hubs on the local network are plain HTTP to a private address --><key>NSAppTransportSecurity</key><dict> <key>NSAllowsLocalNetworking</key> <true/></dict>Multipeer and Nearby add their own
NSBonjourServices entries.
Android (Platforms/Android/AndroidManifest.xml):
<!-- Bluetooth LE --><uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation" /><uses-permission android:name="android.permission.BLUETOOTH_CONNECT" /><uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" /><uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" /><uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" /><uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:maxSdkVersion="30" />
<!-- HTTP + mDNS --><uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /><uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /><uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<!-- clients: hubs on the local network are plain HTTP --><application android:usesCleartextTraffic="true" ... />Nearby adds its own permissions to the manifest.
| Feature | iOS | macOS / Mac Catalyst | Android | Windows / Linux |
|---|---|---|---|---|
| Bluetooth LE host | Foreground | Yes | Yes | — |
| Bluetooth LE client | Yes | Yes | Yes | Register an IBleManager |
| HTTP host and client | Foreground | Yes | Yes | Yes |
| Multipeer | Foreground | Yes | — | — |
| Nearby | Foreground | macOS | With Google Play services | — |
| Files and media channels | Yes | Yes | Yes (L2CAP over BLE on API 29+) | HTTP |
Things to Know
Section titled “Things to Know”- Plane, hotel and public Wi-Fi usually isolate clients from each other. mDNS and device-to-device traffic are blocked there. BLE, Multipeer and Nearby still work.
- Hubs are foreground only: no background BLE, no state restoration.
- A transport that can’t start (Bluetooth off, no network, not this platform) is skipped as long as another starts.
Sample
Section titled “Sample”The sample is a .NET MAUI app (Android, iOS) and a macOS AppKit app with a tic-tac-toe game and an always-on chat, hosting and joining over every transport:
- One phone hosts a game and plays X. The next to join plays O, and anyone after that spectates.
- Moves are hub calls, and board updates and emotes are pushes. Avatars and chat photos are file transfers.
- 📞 and 📹 in a chat call the other person over whichever link they’re on, built on media channels.
- The Transports page turns each transport on and off for hosting and connecting, and Solo runs one alone both ways, so each can be tested on its own.
- Contracts & Source Generator: what a hub interface may contain, and what gets generated
- Hosting:
AddUniversalServer,UniversalHub<T>,IHubContext<THub>, start and stop - Connecting Clients: discovery, transport order, calls, streams, events, resume
- Files & Media Channels: file transfers and live packet pipes on every transport
- Transports: Bluetooth LE, HTTP, Multipeer, Nearby, your own
- Dynamic Hubs: hubs defined while the app runs
- How It Works: the wire protocols, discovery, limits and best practices
Step 1 — Add the marketplace:
claude plugin marketplace add shinyorg/skillsStep 2 — Install the plugin:
claude plugin install shiny@shinyOne plugin installs all 48 Shiny skills. Your agent loads only the skill relevant to what you're building, so there's no cost to having them all available.
Step 1 — Add the marketplace:
copilot plugin marketplace add https://github.com/shinyorg/skillsStep 2 — Install the plugin:
copilot plugin install shiny@shinyOne plugin installs all 48 Shiny skills. Your agent loads only the skill relevant to what you're building, so there's no cost to having them all available.

