Skip to main content

Getting Started

Installation

To install the Cerebellum SDK, use the following command:

npm install @cerebellum/sdk

Local Development Setup

Cerebellum has a Docker image for local development, allowing you to test your application easily. If you have Docker installed, you can start the local development environment by running the following command:

npx cerebellum-start

This command will start the Cerebellum local development environment with the following components:

  • The main Cerebellum WebSocket server on port 8001 for real-time communication.
  • Example authentication route on port 3000.
  • Local DynamoDB server on port 8000.
  • Redis server on port 6379.

The DynamoDB is used for message persistence, while Redis servers as a pub/sub system and a cache for presence information.

To stop the local development server, run:

npx cerebellum-stop

Getting Started

To use the Cerebellum SDK, create a new instance of Cerebellum by calling the Cerebellum function and passing in the endpoint of the Cerebellum server along with any desired options. Here's an example of how to create a new instance of Cerebellum:

import Cerebellum from "@cerebellum/sdk";

const endpoint = "localhost:8001"; // Use appropriate URL for production

const CerebellumOptions = {
autoConnect: true, // Enable auto-connect. Requires API key or auth route.
API_KEY: "SAMPLE_API_KEY", // DO NOT USE IN PRODUCTION.
reconnection: true, // Enable reconnection attempts.
reconnectionAttempts: 5, // Number of attempts before giving up.
reconnectionDelay: 5000, // Delay between reconnection attempts (ms).
reconnectionDelayMax: 5000, // Maximum delay between reconnection attempts (ms).
timeout: 20000, // Timeout before a connection attempt is considered failed (ms).
};

const cerebellum = await Cerebellum(endpoint, CerebellumOptions);

For development, you can use the options above to connect to the local development server.

In production, replace the URL with your Cerebellum server URL and use a secure API key or auth route.

Once an instance of Cerebellum has been created, you can use the various hooks and components provided by the Cerebellum SDK to interact with the Cerebellum server.