
Product
Introducing Scala and Kotlin Support in Socket
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
peer-relay is a p2p message relay that works in nodejs and in the browser. It supports WebSockets and WebRTC as transports. Sending a small amount of message to a large number of peers isn't easy to do with WebRTC since the time and resource cost of starting a WebRTC connection can be high. Instead of connecting directly to each peer you need to send message to, it can be better to relay that message through the peers you are already connected to; especially if you only need to send just a few messages. Peer-relay takes care of this by relaying messages for you and providing a simple interface for sending and receiving messages.
peer = new PeerRelay([opts])
Creates a new peer that becomes apart of the relay network
The following fields can be specified within opts
:
port
can only be specified if the peer is running nodejs since start a WebSocket server is not possible in a browser. Every peer should specify at least on bootstrap peer (unless that peer is the first/only peer in the network)
peer.id
The peer's id. id
is 160 bit Buffer.
peer.connect(id)
Forms a direct connection with the given peer. id
is the id of the peer to connect to and must be a Buffer.
peer.disconnect(id)
Disconnect the a currently connected peer with id
.
peer.send(id, data)
Send data
to the peer with and id equal to id
. The peer does not have to be directly connected to because it will be relayed through other peers. This is similiar to UDP in that message delivery or order is not guaranteed.
peer.destroy([cb])
Destroy the peer and free it's resources. An optional callback can be specified and will be called when all the resources are freed.
var socket = new PeerRelay.Socket([opts])
Creates a new dgram like socket that uses peer-relay to send messages between peers. This allows for peer-relay to be used by programs that expect the dgram interface. This method accepts the same arguments as the PeerRelay constructor. The returned object tries to match the interface provided by dgram's Socket.
socket.peer
references the underlying PeerRelay instance.
peer.on('message', function (data, from) {})
Fired when a message addressed to the peer was received. from
is the Buffer id of the peer that sent the message.
peer.on('peer', function (id) {})
Fired when a peer has been directly connected to
FAQs
relay messages through peers in a network
The npm package peer-relay receives a total of 1 weekly downloads. As such, peer-relay popularity was classified as not popular.
We found that peer-relay demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Application Security
/Security News
Socket CEO Feross Aboukhadijeh and a16z partner Joel de la Garza discuss vibe coding, AI-driven software development, and how the rise of LLMs, despite their risks, still points toward a more secure and innovative future.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.