Client
Getting Started
Get the Huddle01 JS SDK
$ npm install --save huddle01-client
OR
$ yarn add huddle01-client
2. Get your API Key: You can get your access keys in the Developer section of the Huddle01 Dashboard
3. Importing into your application: Import modules & instantiate Huddle01 Client. Import HuddleTypes to access the types.
import HuddleClient, { emitter, HuddleTypes } from "huddle01-client";
The infrastructure mandates a schema on the URL of the type https://domain.com/room?roomId=C132
Thus, on component mount, we add:
history.push(`?roomId=${config.roomId}`);
Initialise a new huddle client instance
const huddle: HuddleClient = new HuddleClient(config);
An example config
object can be given as
//write this as it is -- used to check for the recorder
const isRecorderBot = localStorage.getItem("bot_password") === "huddle01";
const config: HuddleTypes.HuddleClientConfig = {
apiKey: "<API Key>", // API KEY (issued on the dashboard)
roomId: "C132", // Room ID
peerId: "rick254", // Peer ID (needs to be unique for every peer)
displayName: "Rick Sanchez", // Display Name
window, // Your browser's window object
isBot, // bot flag
};
By this step, you should be connected to the Huddle servers.
To allow recordings, make sure to add:
huddle && isRecorderBot && joinRoomBtn.click();
Setting up event listeners
The emitter that we imported in the 1st step is used to emit events by Huddle about your application. Please refer to the demo app for application references
The various types of events are:
Trigger: on room status changes
Return value: room status of the type string
emitter.on("roomState", (state: string) => {
//do whatever (ideally switch-case between all state types)
//for example
switch (state) {
case "connected":
//code for roomState == "connected"
break;
case "failed":
//code for roomState == "failed"
break;
case "disconnected":
//code for roomState == "disconnected"
break;
default:
setRoomState(state);
break;
}
setRoomState(state);
});
Different state types:
connected
failed
disconnected
successfully connected to the room
failure in connection to the room
successfully disconnected from the room
Methods Available:
huddle.join()
huddle.close()
const joinRoom = async () => {
if (!huddle) return;
try {
setupEventListeners();
await huddle.join();
} catch (error) {
alert(error);
}
};
huddle.enableWebcam()
huddle.enableMic()
huddle.enableShare()
const enableWebcam = async () => {
if (!huddle) return;
try {
await huddle.enableWebcam();
setWebcamState(true);
} catch (error) {
alert(error);
}
};
huddle.disableWebcam()
huddle.disableShare()
huddle.disableMic()
const disableWebcam = async () => {
if (!huddle) return;
try {
await huddle.disableWebcam();
setWebcamState(false);
} catch (error) {
alert(error);
}
};
huddle.startRecording()
huddle.stopRecording()
const startRecording = async () => {
if (!huddle) return;
try {
const status: boolean = await huddle.startRecording();
if (status) console.log("recording successfully initiated");
} catch (error: any) {
console.error(error);
}
};
Last updated
Was this helpful?