Skip to content
Shiny PlatformShiny Platform

Universal Hubs

GitHub GitHub stars for shinyorg/hubs
Hubs, host, client, generator NuGet downloads for Shiny.UniversalHubs
Bluetooth LE NuGet downloads for Shiny.UniversalHubs.BluetoothLE
HTTP (Wi-Fi, LAN, tunnels) NuGet downloads for Shiny.UniversalHubs.Http
Multipeer (Apple) NuGet downloads for Shiny.UniversalHubs.Multipeer
Nearby (Android, iOS, macOS) NuGet downloads for Shiny.UniversalHubs.Nearby
Frameworks
.NET
.NET MAUI
Operating Systems
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.

  • 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 / OnDisconnectedAsync and Context.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.
  1. 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.UniversalHubs
    dotnet add package Shiny.UniversalHubs.BluetoothLE
    dotnet add package Shiny.UniversalHubs.Http
  2. 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 -> host
    event Action<string, string> Received; // host -> clients (who, message)
    }
    [JsonSerializable(typeof(string))]
    [JsonSerializable(typeof(bool))]
    public partial class ChatJsonContext : JsonSerializerContext;
  3. 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 connected
    await this.Clients.All.Received(this.Context.Client.Name ?? "?", message);
    return true;
    }
    }
  4. Register everything in MauiProgram. Each hub has a name, and picks its transports:

    Shiny.Json.AddContext(ChatJsonContext.Default);
    // host
    builder.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 settings
    builder.Services.AddUniversalHubClient<IChatHub>("chat", o => o
    .UseHttp("_mychat._tcp")
    .UseBluetoothLE("FE10", ChatCharacteristicUuid));
  5. Start hosting on one device:

    // IUniversalHubHost host - every hub on every transport this device can run right now
    IReadOnlyList<IHubTransport> running = await host.Start();
  6. Discover, connect and call it from another:

    // IUniversalHubClient<IChatHub> client
    client.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 BLE
    await client.Hub.Send($"hello over {client.Transport?.DisplayName}!");

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
  • 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.

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.
claude plugin marketplace add shinyorg/skills
claude plugin install shiny@shiny

One 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.

copilot plugin marketplace add https://github.com/shinyorg/skills
copilot plugin install shiny@shiny

One 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.

View shiny-universal-hubs Skill