Connections

Before beginning this section, please familiarize yourself with the various methods available to authenticate users to Relaybox services. Suggested reading includes Authentication.

Defining "Connections"

When we refer to a connection, we mean a bidirectional WebSocket connection between your application and Relaybox services. This is the primary way to gain access to the functionality provided by the service.

Connections are established using WebSockets and enhanced with the client library SDK, providing secure authentication, reconnection logic, and various ways to establish the connection via authentication tokens or API keys.

Client vs Server Connections

Connections are established on both the client and the server but handle very different tasks. A client connection is responsible for creating the bidirectional transport between your application and Relaybox services. A server connection is responsible for pushing notifications to all connected clients.

// Server side connection
import RelayBox from '@relaybox/rest';

const relayBox = new RelayBox({
  apiKey: 'xxxxxxx.xxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
});

It's considered safe to use your API key on the server. However, please be cautious about securing the key.

// Client side connection
import {RelayBox} from '@relaybox/client';

const relayBox = new RelayBox({
  authEndpint: 'user/auth'
});

await relayBox.connect();

It's not recommended to use API keys directly in client-side applications. Better practice would be to generate secure authentication tokens.

Clients can both send and receive data, whereas servers can only send data to interested parties.

    On this page