origx-cloud-sdk
v1.1.2
Published
Complete developer-first WebRTC client SDK for Origx Cloud calling rooms
Maintainers
Readme
Origx Cloud Client SDK
The developer-first, lightweight WebRTC client SDK for integrating Audio and Video calling into modern web applications using Origx Cloud.
Version: 1.1.2
Installation
npm install origx-cloud-sdkQuick Start
1. Initialize and Join a Room
Generate a secure token on your backend using your Application Secret Key, then connect:
import { OrigxCloud } from "origx-cloud-sdk";
const rtc = new OrigxCloud({
appId: "your_application_id",
token: "secure_token_from_your_backend",
channelName: "lobby-room-101",
uid: "user-42"
});
await rtc.join();2. Capture and Render Media
// Request camera + microphone access
const localStream = await rtc.getLocalStream(true, true);
// Render local video
document.getElementById("local-video").srcObject = localStream;
// Render incoming peer video
rtc.on("track", (remoteUid, remoteStream, track) => {
document.getElementById("remote-video").srcObject = remoteStream;
});3. Mute Controls
Muting automatically notifies all peers in the room — no extra code needed.
// Microphone
rtc.muteAudio(true); // mute
rtc.muteAudio(false); // unmute
// Camera
rtc.muteVideo(true); // camera off
rtc.muteVideo(false); // camera on4. React to Peer Mute State
Listen for the peerState event to know when a remote participant mutes or turns off their camera:
rtc.on("peerState", (uid, state) => {
if (state.audioMuted) {
showMuteIcon(uid);
}
if (state.videoMuted) {
showCameraOffPlaceholder(uid);
}
});5. Video Effects (Filters)
Apply real-time visual filters to your outgoing video stream. The effect is processed via canvas and sent to peers using RTCRtpSender.replaceTrack().
Available effects: none, blur, grayscale, sepia, vintage, invert, cool, warm
// Apply a filter — returns the processed MediaStream for local preview
const effectStream = await rtc.applyEffect("sepia");
document.getElementById("local-video").srcObject = effectStream;
// Remove the filter and restore original camera
await rtc.removeEffect();
document.getElementById("local-video").srcObject = rtc.localStream;
// Check what effect is currently active
const current = rtc.getActiveEffect(); // "sepia" | "none" | null6. Disconnect
Cleanly closes all peer connections, stops media tracks, and cancels any active effect loop:
rtc.leave();SDK Events
| Event | Arguments | Description |
|---|---|---|
| joined | (channelName, uid) | Successfully connected to the channel |
| userJoined | (uid) | A remote participant joined |
| userLeft | (uid) | A remote participant disconnected |
| track | (uid, stream, track) | Received an incoming media track |
| peerState | (uid, { audioMuted, videoMuted }) | Peer toggled mute or camera |
| audioMuted | (uid) | Peer muted their microphone |
| audioUnmuted | (uid) | Peer unmuted their microphone |
| videoStopped | (uid) | Peer turned off their camera |
| videoStarted | (uid) | Peer turned on their camera |
| disconnected | — | WebSocket signaling disconnected |
| error | (Error) | An RTC or signaling error occurred |
Example
rtc.on("joined", (channelName, uid) => {
console.log(`Connected to ${channelName} as ${uid}`);
});
rtc.on("userJoined", (uid) => {
console.log(`Peer ${uid} joined`);
});
rtc.on("userLeft", (uid) => {
console.log(`Peer ${uid} left`);
// Clean up their video element
});
rtc.on("peerState", (uid, state) => {
if (state.audioMuted !== undefined) {
toggleMuteUI(uid, state.audioMuted);
}
if (state.videoMuted !== undefined) {
toggleCameraUI(uid, state.videoMuted);
}
});
rtc.on("error", (err) => {
console.error("RTC error:", err.message);
});
rtc.on("disconnected", () => {
console.log("Signaling disconnected");
});API Reference
new OrigxCloud(config)
| Option | Type | Required | Description |
|---|---|---|---|
| appId | string | ✅ | Your Origx application ID |
| token | string | ✅ | Signed JWT token from your backend |
| channelName | string | ✅ | Room/channel identifier |
| uid | string | ✅ | Unique user identifier |
Methods
| Method | Returns | Description |
|---|---|---|
| join() | Promise<void> | Connect to the signaling server and join the room |
| leave() | void | Disconnect, stop tracks, clean up |
| getLocalStream(audio, video) | Promise<MediaStream> | Request camera/mic access |
| muteAudio(mute: boolean) | void | Toggle mic; notifies peers automatically |
| muteVideo(mute: boolean) | void | Toggle camera; notifies peers automatically |
| applyEffect(name: string) | Promise<MediaStream> | Apply a live video filter; returns processed stream |
| removeEffect() | Promise<void> | Remove filter, restore original camera track to peers |
| getActiveEffect() | string \| null | Returns the currently active effect name |
| on(event, callback) | void | Subscribe to an event |
| off(event, callback) | void | Unsubscribe from an event |
