video-saas-client
v0.1.8
Published
Video calling SDK for Video SaaS
Maintainers
Readme
video-saas-client
Video calling SDK for Video SaaS. Connect to video rooms with token-based authentication.
Install
npm install video-saas-clientGetting a token
Tokens are generated server-side using video-saas-admin. Never expose your API key in the browser. For API key access, contact [email protected].
Install the admin package in your backend:
npm install video-saas-adminCreate an API route that returns a token for a given room (example: Next.js):
// app/api/room-token/route.js import { createRoomToken } from "video-saas-admin"; export async function GET(request) { const roomId = request.nextUrl.searchParams.get("roomId"); const token = await createRoomToken(roomId, { apiKey: process.env.VIDEO_SAAS_API_KEY }); return Response.json({ token }); }Fetch the token on the frontend before joining:
const { token } = await fetch(`/api/room-token?roomId=${roomId}`).then(r => r.json()); useVideoCall(roomId, { token });
Usage
import { useVideoCall } from "video-saas-client";
function MyVideoCall({ roomId, token }) {
const {
localStream,
remoteStreams,
isConnected,
error,
leaveRoom,
} = useVideoCall(roomId, { token });
return (
<div>
{localStream && <video ref={el => { if (el) el.srcObject = localStream; }} muted autoPlay />}
{Array.from(remoteStreams.entries()).map(([peerId, stream]) => (
<video key={peerId} ref={el => { if (el) el.srcObject = stream; }} autoPlay />
))}
<button onClick={leaveRoom}>Leave</button>
</div>
);
}With a custom video track (e.g. virtual background)
Pass a pre-processed MediaStreamTrack via videoTrack. The SDK will use it instead of calling getUserMedia for video.
import { useVideoCall } from "video-saas-client";
function MyVideoCall({ roomId, token }) {
const [videoTrack, setVideoTrack] = useState(null);
useEffect(() => {
// Apply your virtual background and get a processed track
applyVirtualBackground().then(track => setVideoTrack(track));
}, []);
const { localStream, remoteStreams, leaveRoom } = useVideoCall(roomId, { token, videoTrack });
// ...
}API
useVideoCall(roomId, options)
| Option | Type | Required | Description |
|--------|------|----------|-------------|
| token | string | Yes | Short-lived room token from video-saas-admin |
| videoTrack | MediaStreamTrack | No | Custom video track — use this to pass a pre-processed track (e.g. with virtual background applied). Falls back to getUserMedia if not provided. |
Returns
| Value | Type | Description |
|-------|------|-------------|
| localStream | MediaStream | null | The local camera/mic stream |
| remoteStreams | Map<peerId, MediaStream> | Streams from other participants |
| isConnected | boolean | Whether the socket is connected |
| error | string | null | Error message if something went wrong |
| leaveRoom | () => void | Disconnect and stop all tracks |
| startRecording | (patientPeerId) => Promise | Start recording (if supported by server) |
| stopRecording | () => Promise | Stop recording |
| isRecording | boolean | Whether recording is active |
| recordingIds | { doctor, patient } | Active recording IDs |
