Rainway Network
Rainway Network
The Rainway Network is how apps using Rainway find each other.
Each entity connected to the network is a Peer, identified by its Rainway Peer ID.
Peers on the Rainway Network exchange connection requests and session information in order to establish a peer-to-peer connection. Once a connection between Peers has been established, they no longer use the Rainway Network to communicate.
First steps
Connecting to the Rainway Network happens when you call connect
on the default export. The only property you're required to pass is apiKey
.
import rainway from "@rainway/native";
const conn = await rainway.connect({ apiKey: "pk_XXXXXX" })
The resulting Promise resolves to a RainwayConnection
instance that can be used to connect or handle requests to connect from other peers. It's time to get connected peer-to-peer!
Peer IDs
The first time Rainway is initialized on a device, it generates and stores a Peer ID. This is a 63-bit number that uniquely identifies the device on the Rainway Network.
To connect your device to another over Rainway, you must know the other's Peer ID. A device's Peer ID is exposed through the id
property on RainwayConnection
.
const peerId = conn.id;
How you store Peer IDs will vary depending on how your application uses Rainway. For example, you could store them in your application database to let Peers know about each other.
Connecting to a Peer
Once you have a Peer's ID, you can call connect
to establish the connection:
const peer = await conn.connect(remotePeerId);
This promise will resolve once the Peer has accepted your connection request.
To test against the example web app, try running it on another device, and connecting from your web app to its Peer ID.
Updated over 2 years ago