network_relay (1.0.0)
Installation
dart pub add network_relay:1.0.0 --hosted-url=About this package
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.