Specify a "realm" name that is likely unique to your application to avoid cross-talk with other app's peers.
Extra optional config values that this instance will use.
This is the secret ID generated for use in cryptography. You should copy and reuse this if you wish to maintain a persistent Peer ID.
Note: This should never be shared. It allows whoever owns a copy to impersonate this Peer.
If you wish to know a valid seed before running Matchmaking, you can pre-generate a Seed using makeSeed.
A list of all Peers currently connected to this Switchboard instance.
The current long-form ID for this peer. When connecting to a target Host, this may technically be more secure than the shortened peerID.
The current ID this client is using. By default, uses shorter IDs, but can be toggled with SBClientOptions.useLongIds.
The short form of the local client ID. If additional security is desired when connecting to specific IDs, use fullID.
Returns a count of the Trackers currently processing or connected. This will include broken trackers that have not yet timed out. For more reliable detection of tracker activity, subscribe to the emitted tracker events.
Increases a Peer's failure count - potentially resulting in their blacklisting. If increment is not given, the Peer will be automatically blacklisted.
The peer to (potentially) blacklist.
The amount of failures to increment. Defaults to instantly blacklisting.
Connects only to the given Host PeerID. This requires that you have exchanged in advance the Host's ID.
For this to work, the Host must call host. If the Host is not yet online, they will be located once they become available.
The ID of the target host. If the Host is using long-form IDs, make sure this matches!
Connect to trackers as a Host, listening for client Peers. Clients looking for a specific Host via findHost will require that this is eventually called by the Host.
Optionally limit the maximum concurrently connected peers.
Check if a client has retried connections enough to be "blacklisted".
Kill all connections to the tracker servers, and optionally the Peers connected as well.
The error to be emitted by this object's "kill" event, or null.
If true, also close all active Peer connections.
Builds a binary buffer, containing the current public key & a validation signature from the matching private key.
Emitted when all possible trackers have connected. If all trackers fail, this is not emitted.
For potential ease of debugging, the internally-used array of connected TrackerConnectors will be provided with this event. It is not advisable to manipulate these.
You should not wait for this event. Peers may come in from faster trackers before they are all connected.
A function which can accept an array of the internal TrackerConnectors.
A function to call, in order to unsubscribe.
Emitted after a new Peer object is located, connected, and authenticated. You should always subscribe to this event, because all Peers will be returned via this emitter.
A function to call, in order to unsubscribe.
Emitted when any connected Peer has an error.
You can catch these at a more granular level by subscribing directly to the Peer's on('error')
emitter instead.
A function that can receive the Error, if any, that caused termination.
A function to call, in order to unsubscribe.
Emitted when a PeerID is offered by a Tracker. The Peer may not actually connect.
A function that can receive the Peer ID.
A function to call, in order to unsubscribe.
Emitted whenever a Peer ID is blacklisted. The emitted Peer will be valid until the callback has run (synchronously), then it will be disconnected.
A function that can receive the PeerWrapper that was blacklisted.
A function to call, in order to unsubscribe.
Emitted when a non-fatal error occurs. You should not assume that the Switchboard is broken based off these.
A function that can receive the Error, if any, that caused termination.
A function to call, in order to unsubscribe.
Triggered when this Switchboard is unrecoverably killed.
If this is emitted, this Switchboard is dead. You should create a new one if you need to reconnect.
A function that can receive the Error, if any, that caused termination.
A function to call, in order to unsubscribe.
Emitted when each of the trackers connects.
A function that can receive the TrackerOptions.
A function to call, in order to unsubscribe.
Triggered when a Tracker finds a peer that has passed the blacklist.
This handler initializes and verifies the new Peer's identity, using a binary handshake.
The new Peer that has connected.
Same as on(), but only triggers one time & automatically cleans up.
Removes all non-permanent callbacks for the given event type, or every event type if none is given.
Determine if a given PeerID can connect. Called by TrackerConnectors before a handshake is established.
Connect to all Trackers, and register event handling internally.
ID to use for the swarm. This is hashed into an InfoHash.
Connect to all Peers within a given "swarm ID".
This ID can be any string you'd like, though it is suggested you make it something unique in order to avoid finding unrelated peers.
The ID of the swarm to join.
An optional limit on the number of unique connected Peers.
Convenience wrapper for users who want to set their own trackers, but still want access to Switchboard's defaults.
Use this to fetch a list of additional, dynamic trackers, as provided by ngosang/trackerslist. By default, this is used internally to add additional trackers unless it is disabled.
Get the (full) ID that a given seed string will use.
The string Seed, can be generated using makeSeed.
If the returned ID should be the full-length ID, or the short version.
Accepts a string "seed", and uses it to rehydrate a pair of public/private keys.
The seed, as generated by makeSeed.
Returns the long-form ID for the given Key, not truncated.
Generate a (short) ID from the given Public Key.
This ID will be a shortened (20 chars) SHA-1 hash.
The public key to hash.
Generate a new "seed", which is an encoded string of 32 random bytes.
Attempts to verify that the given packet was signed by, and for, the given peerID.
Validates that the packet's public key matches the Peer's ID, then validates that the packet was signed by the corresponding private key.
The (short) ID of the Peer responsible for this packet.
The binary packet received.
If a specific Host ID is desired, restrict it to this.
The value of the current SDP config from the Remote connection.
Generated using TypeDoc
This is the main entrypoint for Switchboard.js.
This class manages all connections, and abstracts away all the complex details of WebRTC + Matchmaking.