@volorio/react 0.1.0
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 +33 -0
- package/dist/src/index.d.ts +26 -0
- package/dist/src/index.js +99 -0
- package/dist/src/index.js.map +1 -0
- package/package.json +42 -0
package/README.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# @volorio/react
|
|
2
|
+
|
|
3
|
+
React hooks for Volorio RTC, chat, screen sharing, and usage estimates.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @volorio/sdk @volorio/react livekit-client react
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
Create the room session on your backend with `@volorio/sdk/node`. Do not expose your Volorio API key in the browser.
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { useVolorioRoom } from "@volorio/react";
|
|
17
|
+
|
|
18
|
+
export function CallView({ session }: { session: { livekitUrl: string; token: string; identity: string } }) {
|
|
19
|
+
const room = useVolorioRoom(session);
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
status: room.status,
|
|
23
|
+
participantMinutes: room.usageEstimate.participantMinutes,
|
|
24
|
+
estimatedAmountMicros: room.usageEstimate.estimatedAmountMicros,
|
|
25
|
+
join: () => room.join(),
|
|
26
|
+
leave: () => room.leave(),
|
|
27
|
+
camera: () => room.enableCamera(true),
|
|
28
|
+
microphone: () => room.enableMicrophone(true),
|
|
29
|
+
screenShare: () => room.shareScreen(true),
|
|
30
|
+
chat: (message: string) => room.sendMessage(message),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
```
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { VolorioRoomClient, type VolorioBrowserSession, type VolorioRoomClientOptions, type VolorioUsageEstimate } from "@volorio/sdk";
|
|
2
|
+
export type VolorioReactRoomStatus = "idle" | "connecting" | "connected" | "disconnected" | "error";
|
|
3
|
+
export interface VolorioReactRoomState {
|
|
4
|
+
status: VolorioReactRoomStatus;
|
|
5
|
+
cameraEnabled: boolean;
|
|
6
|
+
microphoneEnabled: boolean;
|
|
7
|
+
screenShareEnabled: boolean;
|
|
8
|
+
lastError: string | undefined;
|
|
9
|
+
usageEstimate: VolorioUsageEstimate;
|
|
10
|
+
}
|
|
11
|
+
export interface UseVolorioRoomOptions extends VolorioRoomClientOptions {
|
|
12
|
+
autoJoin?: boolean;
|
|
13
|
+
clientFactory?: () => VolorioRoomClient;
|
|
14
|
+
}
|
|
15
|
+
export interface UseVolorioRoomResult extends VolorioReactRoomState {
|
|
16
|
+
client: VolorioRoomClient;
|
|
17
|
+
join: (nextSession?: VolorioBrowserSession) => Promise<void>;
|
|
18
|
+
leave: () => void;
|
|
19
|
+
enableCamera: (enabled: boolean) => Promise<void>;
|
|
20
|
+
enableMicrophone: (enabled: boolean) => Promise<void>;
|
|
21
|
+
shareScreen: (enabled: boolean) => Promise<void>;
|
|
22
|
+
sendMessage: (message: string) => Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
export declare function createInitialVolorioRoomState(): VolorioReactRoomState;
|
|
25
|
+
export declare function normalizeVolorioRoomStatus(status: VolorioReactRoomStatus, hasSession: boolean): VolorioReactRoomStatus;
|
|
26
|
+
export declare function useVolorioRoom(session: VolorioBrowserSession | null | undefined, options?: UseVolorioRoomOptions): UseVolorioRoomResult;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createInitialVolorioRoomState = createInitialVolorioRoomState;
|
|
4
|
+
exports.normalizeVolorioRoomStatus = normalizeVolorioRoomStatus;
|
|
5
|
+
exports.useVolorioRoom = useVolorioRoom;
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const sdk_1 = require("@volorio/sdk");
|
|
8
|
+
function createInitialVolorioRoomState() {
|
|
9
|
+
return {
|
|
10
|
+
status: "idle",
|
|
11
|
+
cameraEnabled: false,
|
|
12
|
+
microphoneEnabled: false,
|
|
13
|
+
screenShareEnabled: false,
|
|
14
|
+
lastError: undefined,
|
|
15
|
+
usageEstimate: {
|
|
16
|
+
participantMinutes: 0,
|
|
17
|
+
estimatedAmountMicros: 0,
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function normalizeVolorioRoomStatus(status, hasSession) {
|
|
22
|
+
if (status === "idle" && hasSession) {
|
|
23
|
+
return "disconnected";
|
|
24
|
+
}
|
|
25
|
+
return status;
|
|
26
|
+
}
|
|
27
|
+
function useVolorioRoom(session, options = {}) {
|
|
28
|
+
const client = (0, react_1.useMemo)(() => options.clientFactory?.() ?? new sdk_1.VolorioRoomClient(options), [options.clientFactory]);
|
|
29
|
+
const sessionRef = (0, react_1.useRef)(session);
|
|
30
|
+
const [state, setState] = (0, react_1.useState)(() => createInitialVolorioRoomState());
|
|
31
|
+
sessionRef.current = session;
|
|
32
|
+
(0, react_1.useEffect)(() => {
|
|
33
|
+
const unsubscribeConnected = client.on("connected", () => {
|
|
34
|
+
setState((current) => ({ ...current, status: "connected", lastError: undefined }));
|
|
35
|
+
});
|
|
36
|
+
const unsubscribeDisconnected = client.on("disconnected", () => {
|
|
37
|
+
setState((current) => ({ ...current, status: "disconnected" }));
|
|
38
|
+
});
|
|
39
|
+
const unsubscribeUsage = client.on("usageEstimateChanged", (event) => {
|
|
40
|
+
setState((current) => ({ ...current, usageEstimate: event }));
|
|
41
|
+
});
|
|
42
|
+
return () => {
|
|
43
|
+
unsubscribeConnected();
|
|
44
|
+
unsubscribeDisconnected();
|
|
45
|
+
unsubscribeUsage();
|
|
46
|
+
};
|
|
47
|
+
}, [client]);
|
|
48
|
+
const runAction = (0, react_1.useCallback)(async (action, patch) => {
|
|
49
|
+
try {
|
|
50
|
+
await action();
|
|
51
|
+
if (patch !== undefined) {
|
|
52
|
+
setState((current) => ({ ...current, ...patch, lastError: undefined }));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
setState((current) => ({ ...current, status: "error", lastError: error instanceof Error ? error.message : String(error) }));
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
}, []);
|
|
60
|
+
const join = (0, react_1.useCallback)(async (nextSession) => {
|
|
61
|
+
const resolvedSession = nextSession ?? sessionRef.current;
|
|
62
|
+
if (resolvedSession === null || resolvedSession === undefined) {
|
|
63
|
+
throw new Error("Volorio room session is required before joining");
|
|
64
|
+
}
|
|
65
|
+
setState((current) => ({ ...current, status: "connecting", lastError: undefined }));
|
|
66
|
+
await runAction(() => client.join(resolvedSession));
|
|
67
|
+
}, [client, runAction]);
|
|
68
|
+
const leave = (0, react_1.useCallback)(() => {
|
|
69
|
+
client.disconnect();
|
|
70
|
+
setState((current) => ({
|
|
71
|
+
...current,
|
|
72
|
+
status: "disconnected",
|
|
73
|
+
cameraEnabled: false,
|
|
74
|
+
microphoneEnabled: false,
|
|
75
|
+
screenShareEnabled: false,
|
|
76
|
+
}));
|
|
77
|
+
}, [client]);
|
|
78
|
+
const enableCamera = (0, react_1.useCallback)((enabled) => runAction(() => client.enableCamera(enabled), { cameraEnabled: enabled }), [client, runAction]);
|
|
79
|
+
const enableMicrophone = (0, react_1.useCallback)((enabled) => runAction(() => client.enableMicrophone(enabled), { microphoneEnabled: enabled }), [client, runAction]);
|
|
80
|
+
const shareScreen = (0, react_1.useCallback)((enabled) => runAction(() => client.enableScreenShare(enabled), { screenShareEnabled: enabled }), [client, runAction]);
|
|
81
|
+
const sendMessage = (0, react_1.useCallback)((message) => runAction(() => client.sendMessage(message)), [client, runAction]);
|
|
82
|
+
(0, react_1.useEffect)(() => {
|
|
83
|
+
if (options.autoJoin === true && session !== null && session !== undefined) {
|
|
84
|
+
void join(session);
|
|
85
|
+
}
|
|
86
|
+
}, [join, options.autoJoin, session]);
|
|
87
|
+
return {
|
|
88
|
+
...state,
|
|
89
|
+
status: normalizeVolorioRoomStatus(state.status, session !== null && session !== undefined),
|
|
90
|
+
client,
|
|
91
|
+
join,
|
|
92
|
+
leave,
|
|
93
|
+
enableCamera,
|
|
94
|
+
enableMicrophone,
|
|
95
|
+
shareScreen,
|
|
96
|
+
sendMessage,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;AA6BA,sEAYC;AAED,gEAMC;AAED,wCAmFC;AAtID,iCAA0E;AAC1E,sCAAuI;AA4BvI,SAAgB,6BAA6B;IAC3C,OAAO;QACL,MAAM,EAAE,MAAM;QACd,aAAa,EAAE,KAAK;QACpB,iBAAiB,EAAE,KAAK;QACxB,kBAAkB,EAAE,KAAK;QACzB,SAAS,EAAE,SAAS;QACpB,aAAa,EAAE;YACb,kBAAkB,EAAE,CAAC;YACrB,qBAAqB,EAAE,CAAC;SACzB;KACF,CAAC;AACJ,CAAC;AAED,SAAgB,0BAA0B,CAAC,MAA8B,EAAE,UAAmB;IAC5F,IAAI,MAAM,KAAK,MAAM,IAAI,UAAU,EAAE,CAAC;QACpC,OAAO,cAAc,CAAC;IACxB,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAgB,cAAc,CAAC,OAAiD,EAAE,UAAiC,EAAE;IACnH,MAAM,MAAM,GAAG,IAAA,eAAO,EAAC,GAAG,EAAE,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,IAAI,IAAI,uBAAiB,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;IACnH,MAAM,UAAU,GAAG,IAAA,cAAM,EAA2C,OAAO,CAAC,CAAC;IAC7E,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,IAAA,gBAAQ,EAAwB,GAAG,EAAE,CAAC,6BAA6B,EAAE,CAAC,CAAC;IAEjG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AC;IAEtC,OAAO;QACL,GAAG,KAAK;QACR,MAAM,EAAE,0BAA0B,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,SAAS,CAAC;QAC3F,MAAM;QACN,IAAI;QACJ,KAAK;QACL,YAAY;QACZ,gBAAgB;QAChB,WAAW;QACX,WAAW;KACZ,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@volorio/react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "React hooks for Volorio RTC, chat, screen sharing, and usage estimates.",
|
|
6
|
+
"main": "dist/src/index.js",
|
|
7
|
+
"types": "dist/src/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/src/index.d.ts",
|
|
11
|
+
"default": "./dist/src/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist/src",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public",
|
|
20
|
+
"registry": "https://registry.npmjs.org/"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsc -p tsconfig.build.json",
|
|
24
|
+
"test": "tsc -p tsconfig.json && node --test dist/test/*.spec.js",
|
|
25
|
+
"pack:local": "pnpm build && npm pack --pack-destination dist"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"@volorio/sdk": ">=0.1.0",
|
|
29
|
+
"livekit-client": "^2.0.0",
|
|
30
|
+
"react": ">=18.0.0"
|
|
31
|
+
},
|
|
32
|
+
"peerDependenciesMeta": {
|
|
33
|
+
"livekit-client": {
|
|
34
|
+
"optional": true
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/react": "^18.2.79",
|
|
39
|
+
"@volorio/sdk": "workspace:*",
|
|
40
|
+
"react": "^18.2.0"
|
|
41
|
+
}
|
|
42
|
+
}
|