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 automatically when you initialize RainwayRuntime
.
RainwayRuntime
is your way into the Rainway SDK. To initialize it, you must provide some configuration values and handlers through which Rainway and your app will communicate. This is done using the initialize
static method on RainwayRuntime
.
You can leave all the handlers empty for now. Just make sure you provide your apiKey
.
By the way,
externalId
is a string identifying a user or entity within your app. This way you can easily tie an incoming connection back to a user in your app.
using Rainway.SDK;
var runtime = await RainwayRuntime.Initialize(new RainwayConfig {
ApiKey = "myApiKey",
ExternalId = "Jane Doe",
OnRuntimeConnectionLost = (runtime) => {},
OnConnectionRequest = (runtime, request) => {},
OnPeerStateChange = (runtime, peer, state) => {},
OnPeerError = (runtime, peer, error) => {},
OnPeerMessage = (runtime, peer, channelName, message) => {},
OnStreamRequest = (runtime, request) => request.Accept(new RainwayStreamConfig() { InputLevel = AllPermissions }),
);
At this stage, runtime
is ready to use. It's time to get connected peer-to-peer!
Peer IDs
The first time RainwayRuntime 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 peerId
property on RainwayRuntime.
var peerId = runtime.PeerId;
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:
var peer = await runtime.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.
Multiple Peers
Rainway lets you connect to multiple Peers at a time. The Peers
property on RainwayRuntime
tracks every currently connected RainwayPeer
, mapped by their Peer IDs.
Updated over 2 years ago