Skip to main content

Quickstart

This is an interactive demo to get you up and running with Relay SDKs in minutes.

Prerequisites

You need to complete the setup first (< 3 mins to complete):

  1. Sign Up
  2. Create a Project
  3. Generate API Keys

Goal

This tutorial shows you how easy it is to subscribe to topics and publish messages instantly.


Select Your Platform

Choose which SDK you want to try:


Set API Keys

Load your API keys from the JSON file you downloaded during setup. Skip this step if you don't want to do the interactive demo.

warning

Important: Your API keys are stored only in your browser's local memory. We do not upload these keys anywhere. Messages sent during this demo will count toward your messaging allowance based on your chosen plan.

SDK Installation

Please select a platform above to see installation instructions.


SDK Initialization

info

The API keys in the code below are the keys you just loaded.

Initializing our SDKs with the API Key & Secret key so it can connect to the Relay Network.

// Select a platform to see code

Subscribe & Publish

Here, we initialize listeners for the topic chat.room1 and the CONNECTED topic. The CONNECTED topic is a reserved SDK Topic which calls its listener (if initialized) when the SDK connects to the Relay Network.

We publish a message to chat.room1 when we connect to the Relay Network.

  • on() is used to subscribe to a topic.
  • publish() is used to publish to a topic
// Select a platform to see code

Unsubscribe & Disconnect

We now unsubscribe from chat.room1 and disconnect from the Relay Network.

  • off() is used to unsubscribe from a topic.
  • close() is used to close the connection to the Relay Network.

Building on the previous code snippet,

// Select a platform to see code

Next Up

We'll put everything we learned in this tutorial together with an interactive demo!