peer_node_connection 1.0.0 peer_node_connection: ^1.0.0 copied to clipboard
A peer to peer node connection
PeerNodeConnection #
Simple package to define peer to peer communication
for more examples visit the example section
Simple Node Example #
final node = Node();
node.on(
start: () {
print('node started on port ${node.port}');
Timer(const Duration(seconds: 3), () {
node.stop();
});
},
stop: () => print('node stopped!'),
);
node.start();
await node.onNextEmit<NodeOnStopEvent>();
print('bye bye!');
Simple Peer Example #
// connect to localhost on port 3000
final peer = Peer.local(3000);
// handle general events
peer.on(
connect: () {
print('connected');
peer.sendText('hello world!');
Timer(const Duration(seconds: 3), () {
peer.destroy();
});
},
disconnect: () {
print('disconnected');
}
);
peer.connect(); // start peer connection
await peer.onNextEmit<PeerOnDisconnectEvent>();
print('bye bye!');