Introduces the new .listen()
API and adds support for Angular 20.
New listening API
Listening happens in the background until you stop it explicitly. This allows you to start listening for handshake from multiple peers at once, using a variety of ways to accept or decline incoming connections.
// start listening for specific incoming connections
const stop = peer.listen(/* filter using ids, objects, or a custom function */);
// stop listening
stop();
Features
- Introduce the new
.listen()
API (dc1907c) - Introduce the
Peer.peerConnections
API and harmonize connection messages (668c8d2) - Expose
'handshake'
message to the user inserviceMessages
(55b83a2)
Fixes
MessagePeerService
should disconnect and stop listening inngOnDestroy
(9feba99)
BREAKING CHANGES
- new
.listen()
API returns a function that stops listening
// BEFORE
const disconnect = await peer.listen('foo'); // start listening for 'two'
disconnect(); // disconnect, no way you can stop listening
// AFTER
const stop = peer.listen('foo'); // start listening
stop(); // stop listening
peer.disconnect('foo'); // disconnect from peer 'two'
- new
.listen()
API changes the way of listening for multiple connections
// BEFORE
peer.listen('foo'); // start listening for 'foo'
peer.listen('bar'); // start listening for 'bar' <- this will not work as expected before
// AFTER
// In new version the example above would not work
// it would stop listening for 'foo' and start listening for 'bar'.
// Ideally you should call `.listen()` only once. ex:
peer.listen(['foo', 'bar']); // start listening for connections from both 'foo' and 'bar'
// or
peer.listen(); // allow any connection unitl stopped listening
// or
peer.listen((message, source, origin) => {
// accept or decline connection based on the handshake message, source and origin
return ['foo', 'bar'].includes(message.from);
});