Skip to main content

Quickstart

Welcome to the SuperViz Real-time Quickstart guide. This guide provides a straightforward step-by-step process to help you integrate our Real-time into your project.

JavaScript Quickstart

This section provides a step-by-step guide to integrate SuperViz Real-time into your JavaScript project. We offer two methods for integration: using a package manager or via a CDN. Choose the approach that best fits your development environment and follow the corresponding instructions to quickly set up and start using SuperViz Real-time in your application.

1

Before we start

Make sure your development environment has Node.js (v14 or more recent) and npm/yarn installed.

2

Install the package

Install SuperViz Real-time in your Node.js-powered apps with the npm package:

npm install --save @superviz/realtime
3

Import the Real-time

Once installed, import the Real-time to your code:

import { Realtime } from '@superviz/realtime'
4

Initialize Real-Time

After importing the Real-time you can initialize passing DEVELOPER_KEY as a parameter and the options object.

  const realtime = new Realtime('DEVELOPER_KEY', {
participant: {
id: 'PARTICIPANT_ID',
},
});
5

Create and connect to a channel

After initializing the Real-time instance, you can create and connect to a channel. This allows you to establish real-time communication between participants.

const channel = await realtime.connect("my-channel");
6

Subscribe and publish events

After connecting to a channel, you can subscribe to events and publish messages. Here's an example of how to do this:

// Function to publish a test message
const publishTest = () => {
channel.publish("test", { message: "Hello, world!" });
};

// Function to subscribe to test events
const subscribeToTest = () => {
channel.subscribe("test", (event) => {
console.log("Received test event:", event);
});
};

// Call these functions to start publishing and subscribing
publishTest();
subscribeToTest();