@huddle01/server-sdk
TypeScript icon, indicating that this package has built-in type declarations

2.2.2 • Public • Published

Huddle01 Server SDK

https://huddle01-assets-frontend.s3.amazonaws.com/general/huddle01-logo-blue.svg

People-powered Communication

The Huddle01 Server SDK allows you to perform protected admin actions on your server side, like generating peer access tokens and starting and stopping meeting recordings and livestreams.

Installation

npm install @huddle01/server-sdk
yarn add @huddle01/server-sdk
pnpm i @huddle01/server-sdk
bun install @huddle01/server-sdk

Auth

To enable client apps to establish connections with Huddle01 rooms, they require a token that is produced by your backend server. This guide will lead you through the process of configuring a server to create tokens for your clients.

import { AccessToken, Role } from '@huddle01/server-sdk/auth';
 
const accessToken = new AccessToken({
    apiKey: 'YOUR_API_KEY',
    roomId: 'YOUR_ROOM_ID',
    //available roles: Role.HOST, Role.CO_HOST, Role.SPEAKER, Role.LISTENER, Role.GUEST - depending on the privileges you want to give to the user
    role: Role.HOST,
    //custom permissions give you more flexibility in terms of the user privileges than a pre-defined role
    permissions: {
          admin: true,
          canConsume: true,
          canProduce: true,
          canProduceSources: {
            cam: true,
            mic: true,
            screen: true,
          },
          canRecvData: true,
          canSendData: true,
          canUpdateMetadata: true,
        },
        options: {
          metadata: { 
             // you can add any custom attributes here which you want to associate with the user
            walletAddress: "mizanxali.eth"
          },
        },
  });
 
const token = accessToken.toJwt();
 

Recording/ Livestreaming

Server side helpers to start/stop recording and livestreaming

import { Recorder } from '@huddle01/server-sdk/recorder';

const recorder = new Recorder("PROJECT_ID", "API_KEY");

1. Start recording

/**
 * @returns {
 *  msg: string,
 * }
 */
const { msg } = recorder.startRecording({
	roomId: 'YOUR_ROOM_ID',
	token,
})

console.log({ msg });

2. Start Livestream

Start a livestream and we can stream it to multiple RTMP endpoints.

/**
 * @returns {
 *  msg: string,
 * }
 */
const { msg } = await recorder.startLivestream({ 
  roomId: "ROOM_ID",
  token: "TOKEN_FOR_RECORDER" ,
  rtmpUrls: ["rtmp://example.com/live"],
  recordLivestream: true; // false by default
});

console.log({ msg });

3. Stop recording/livestream

/**
 * @returns {
 *  msg: string,
 * }
 */
recorder.stop({
	roomId: 'YOUR_ROOM_ID',
})

Package Sidebar

Install

npm i @huddle01/server-sdk

Weekly Downloads

568

Version

2.2.2

License

ISC

Unpacked Size

179 kB

Total Files

90

Last publish

Collaborators

  • akash_huddle01
  • maxwang0223
  • itsomg
  • mizanxali
  • deepso7
  • 0xvaibhav
  • support01
  • a4748g