video-saas-client 0.1.5 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -8,6 +8,33 @@ Video calling SDK for Video SaaS. Connect to video rooms with token-based authen
8
8
  npm install video-saas-client
9
9
  ```
10
10
 
11
+ ## Getting a token
12
+
13
+ Tokens are generated server-side using [video-saas-admin](https://www.npmjs.com/package/video-saas-admin). Never expose your API key in the browser.
14
+
15
+ 1. **Install the admin package** in your backend:
16
+ ```bash
17
+ npm install video-saas-admin
18
+ ```
19
+
20
+ 2. **Create an API route** that returns a token for a given room (example: Next.js):
21
+ ```js
22
+ // app/api/room-token/route.js
23
+ import { createRoomToken } from "video-saas-admin";
24
+
25
+ export async function GET(request) {
26
+ const roomId = request.nextUrl.searchParams.get("roomId");
27
+ const token = await createRoomToken(roomId, { apiKey: process.env.VIDEO_SAAS_API_KEY });
28
+ return Response.json({ token });
29
+ }
30
+ ```
31
+
32
+ 3. **Fetch the token** on the frontend before joining:
33
+ ```jsx
34
+ const { token } = await fetch(`/api/room-token?roomId=${roomId}`).then(r => r.json());
35
+ useVideoCall(roomId, { token });
36
+ ```
37
+
11
38
  ## Usage
12
39
 
13
40
  ```jsx
package/dist/index.js CHANGED
@@ -14968,7 +14968,6 @@ function useVideoCall(roomId, options = {}) {
14968
14968
  const sendTransportRef = (0, import_react.useRef)(null);
14969
14969
  const recvTransportRef = (0, import_react.useRef)(null);
14970
14970
  const localStreamRef = (0, import_react.useRef)(null);
14971
- const videoProducerRef = (0, import_react.useRef)(null);
14972
14971
  const recordingIdsRef = (0, import_react.useRef)({ doctor: null, patient: null });
14973
14972
  (0, import_react.useEffect)(() => {
14974
14973
  if (!roomId) return;
@@ -15045,8 +15044,7 @@ function useVideoCall(roomId, options = {}) {
15045
15044
  }
15046
15045
  setLocalStream(stream);
15047
15046
  for (const track of stream.getTracks()) {
15048
- const producer = await sendTransport.produce({ track });
15049
- if (track.kind === "video") videoProducerRef.current = producer;
15047
+ await sendTransport.produce({ track });
15050
15048
  }
15051
15049
  return stream;
15052
15050
  }
@@ -15120,13 +15118,7 @@ function useVideoCall(roomId, options = {}) {
15120
15118
  cancelled = true;
15121
15119
  cleanup();
15122
15120
  };
15123
- }, [roomId, token]);
15124
- (0, import_react.useEffect)(() => {
15125
- if (!videoTrack || !videoProducerRef.current) return;
15126
- videoProducerRef.current.replaceTrack({ track: videoTrack }).catch((err) => {
15127
- console.error("[video-saas-client] replaceTrack failed:", err);
15128
- });
15129
- }, [videoTrack]);
15121
+ }, [roomId, token, videoTrack]);
15130
15122
  function cleanup() {
15131
15123
  localStreamRef.current?.getTracks().forEach((t) => t.stop());
15132
15124
  sendTransportRef.current?.close();
@@ -15137,7 +15129,6 @@ function useVideoCall(roomId, options = {}) {
15137
15129
  sendTransportRef.current = null;
15138
15130
  recvTransportRef.current = null;
15139
15131
  localStreamRef.current = null;
15140
- videoProducerRef.current = null;
15141
15132
  }
15142
15133
  function leaveRoom() {
15143
15134
  cleanup();
package/dist/index.mjs CHANGED
@@ -14960,7 +14960,6 @@ function useVideoCall(roomId, options = {}) {
14960
14960
  const sendTransportRef = useRef(null);
14961
14961
  const recvTransportRef = useRef(null);
14962
14962
  const localStreamRef = useRef(null);
14963
- const videoProducerRef = useRef(null);
14964
14963
  const recordingIdsRef = useRef({ doctor: null, patient: null });
14965
14964
  useEffect(() => {
14966
14965
  if (!roomId) return;
@@ -15037,8 +15036,7 @@ function useVideoCall(roomId, options = {}) {
15037
15036
  }
15038
15037
  setLocalStream(stream);
15039
15038
  for (const track of stream.getTracks()) {
15040
- const producer = await sendTransport.produce({ track });
15041
- if (track.kind === "video") videoProducerRef.current = producer;
15039
+ await sendTransport.produce({ track });
15042
15040
  }
15043
15041
  return stream;
15044
15042
  }
@@ -15112,13 +15110,7 @@ function useVideoCall(roomId, options = {}) {
15112
15110
  cancelled = true;
15113
15111
  cleanup();
15114
15112
  };
15115
- }, [roomId, token]);
15116
- useEffect(() => {
15117
- if (!videoTrack || !videoProducerRef.current) return;
15118
- videoProducerRef.current.replaceTrack({ track: videoTrack }).catch((err) => {
15119
- console.error("[video-saas-client] replaceTrack failed:", err);
15120
- });
15121
- }, [videoTrack]);
15113
+ }, [roomId, token, videoTrack]);
15122
15114
  function cleanup() {
15123
15115
  localStreamRef.current?.getTracks().forEach((t) => t.stop());
15124
15116
  sendTransportRef.current?.close();
@@ -15129,7 +15121,6 @@ function useVideoCall(roomId, options = {}) {
15129
15121
  sendTransportRef.current = null;
15130
15122
  recvTransportRef.current = null;
15131
15123
  localStreamRef.current = null;
15132
- videoProducerRef.current = null;
15133
15124
  }
15134
15125
  function leaveRoom() {
15135
15126
  cleanup();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "video-saas-client",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Video calling SDK for Video SaaS",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",