Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@relaybox/rest

Package Overview
Dependencies
Maintainers
0
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@relaybox/rest

A robust and scalable realtime infrastructure service with comprehensive WebSocket support, designed to facilitate live updates, event-driven communication, and seamless data streaming. Ideal for building realtime applications such as chat, multiplayer ga

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

RelayBox REST SDK

Find the full technical documention here

Welcome to RelayBox.

In order to use this library, you need to create a free account and API key. Find more details here.

@relaybox/rest

The purpose of this library is to enable seamless integration between your server-side applications and RelayBox's REST services.

Installation

To install the REST services library, ensure that npm is installed on the host machine, then run the following command:

npm install @relaybox/rest

Once you have successfully installed the library, the following API reference applies.

RelayBox Class

Instantiate the Relaybox class to enable usage of the server-side SDK.

const relayBox = new RelayBox();

class RelayBox {
  constructor(opts: RelayBoxOptions);
  generateTokenResponse(params: TokenResponseParams): TokenResponse;
  publish(roomId: string | string[], event: string, data: any): Promise<PublishResponseData>;
}

RelayBoxOptions

RelayBox class constructor options:

interface RelayBoxOptions {
  apiKey?: string;
}

interface TokenResponseParams {
  clientId?: string | string[];
  expiresIn?: number;
  permissions?: Permission[] | Permissions;
}

interface TokenResponse {
  token: string;
  expiresIn: number;
}

const allowedPermissions: readonly ['subscribe', 'publish', 'presence', 'metrics', '*'];

type Permission = (typeof allowedPermissions)[number];

interface Permissions {
  [room: string]: string[];
}
Configuration OptionDescriptionType
apiKey
(required)
Associate an API key with the connection, which you can generate via the dashboard. To create an API key, first register for a free account. string

generateTokenResponse()

Responsible for generating a secure token to be sent as an HTTP response, which can be exchanged for access to real-time services via @relaybox/client. To learn more about auth tokens, please refer to the Auth Tokens documentation.

relayBox.generateTokenResponse();

Returns string in JWT format

ParameterDescriptionDefault
clientId
(optional)
Include a clientId to associate an identity with the token. You must provide a clientId for a connection using the generated token to participate in a room's presence set. -
expiresIn
(optional)
The length of time specified in seconds before the generated token expires and can no longer be used to connect to real-time services 900
permissions
(optional)
Optional dynamic permissions overrides specific to the token being generated. To learn more about permissions please see Dynamic Permissions ["*"]

Example:

// Generate a token response with a clientId and custom expiry
const tokenResponse = relayBox.generateTokenResponse({
  clientId: 123,
  expiresIn: 300
});

// Generate a token response attaching dynamic permissions
const permissions = {
  myRoom: [
    'subscribe',
    'publish',
    'presence',
    'metrics'
  ];
};

const tokenResponse = relayBox.generateTokenResponse({
  permissions
});

publish()

Responsible for publishing an event to a named "room".

relayBox.publish();

Returns object of type PublishResponseData

interface PublishResponseData {
  timestamp: string;
  signature: string;
}
ArgumentDescriptionType
1**Room Name (required):** The name of the room to publish the event tostring
2 **Event Name (required):** The name of the published event. Connections subscribing to this event by name will receive the event. string / function
2**Data (optional):** The data to be sent as the event payloadstring / object

Example:

const data = {
  hello: 'world'
};

// Publish an event named 'message' to 'room:one' containing data payload
const response = relayBox.publish('room:one', 'message', data);

License

This project is licensed under the MIT License - see the LICENSE file for details.

Keywords

FAQs

Package last updated on 01 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc