network_relay (1.0.0)

Published 2026-09-12 04:15:11 +00:00 by Platform

Installation

dart pub add network_relay:1.0.0 --hosted-url=

About this package

Standalone relay server/client for session-based message routing between clients.

Dart.Package.Network.Relay

A standalone relay server/client on top of Dart.Package.Network.Dedicated: clients register into named sessions and exchange direct or broadcast payloads with each other through the server — no client ever opens a connection to another client directly. Ported from CSharp.Package.Network.Relay.

The first client to register in a session is its master; if it disconnects, the next-oldest client still connected becomes master.

Quick start

import 'package:network_relay/network_relay.dart';
import 'package:transports_websocket/transports_websocket.dart';

final server = RelayServer();
await server.startAsync(WebSocketTransport(), 9000);

final alice = RelayClient('alice');
await alice.connectAsync(WebSocketTransport(), 'localhost', 9000, sessionName: 'room1');

final bob = RelayClient('bob');
await bob.connectAsync(WebSocketTransport(), 'localhost', 9000, sessionName: 'room1');

bob.onDirectMessageReceived.listen((event) {
  final (fromId, payload) = event;
  print('$fromId sent ${payload.length} bytes');
});

await alice.sendDirect('bob', Uint8List.fromList([1, 2, 3]));

A payload that decodes to a NetworkMessage type registered on the receiving client dispatches through the normal handler machinery (as if it arrived from a RelayPeerConnection standing in for the sender) instead of surfacing through onDirectMessageReceived/onBroadcastReceived — so RelayClient.sendRelay<T>() lets unrelated code reuse the same subscribe<T>() handlers it would use on a direct connection.

Versioning and publishing

Version.txt is the exact version that gets published — a push to main publishes it only when that version isn't on the feed yet. Pushes to any other branch only resolve and test.

Details
Pub
2026-09-12 04:15:11 +00:00
0
8.8 KiB
Assets (1)
1.0.0.tar.gz 8.8 KiB
Versions (1) View all
1.0.0 2026-09-12