@scalemule/conference 0.0.1

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.
Files changed (38) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/LICENSE +21 -0
  3. package/README.md +53 -0
  4. package/dist/assets/sounds.d.ts +12 -0
  5. package/dist/assets/sounds.d.ts.map +1 -0
  6. package/dist/core/ConferenceClient.d.ts +103 -0
  7. package/dist/core/ConferenceClient.d.ts.map +1 -0
  8. package/dist/index.cjs +171 -0
  9. package/dist/index.d.ts +5 -0
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +168 -0
  12. package/dist/react/CallButton.d.ts +22 -0
  13. package/dist/react/CallButton.d.ts.map +1 -0
  14. package/dist/react/CallControls.d.ts +17 -0
  15. package/dist/react/CallControls.d.ts.map +1 -0
  16. package/dist/react/CallOverlay.d.ts +30 -0
  17. package/dist/react/CallOverlay.d.ts.map +1 -0
  18. package/dist/react/CallWindow.d.ts +10 -0
  19. package/dist/react/CallWindow.d.ts.map +1 -0
  20. package/dist/react/HuddleBar.d.ts +25 -0
  21. package/dist/react/HuddleBar.d.ts.map +1 -0
  22. package/dist/react/PreCallLobby.d.ts +22 -0
  23. package/dist/react/PreCallLobby.d.ts.map +1 -0
  24. package/dist/react/useConference.d.ts +37 -0
  25. package/dist/react/useConference.d.ts.map +1 -0
  26. package/dist/react/useDevices.d.ts +28 -0
  27. package/dist/react/useDevices.d.ts.map +1 -0
  28. package/dist/react/useIncomingCalls.d.ts +34 -0
  29. package/dist/react/useIncomingCalls.d.ts.map +1 -0
  30. package/dist/react.cjs +1004 -0
  31. package/dist/react.d.ts +18 -0
  32. package/dist/react.d.ts.map +1 -0
  33. package/dist/react.js +990 -0
  34. package/dist/transport.d.ts +21 -0
  35. package/dist/transport.d.ts.map +1 -0
  36. package/dist/types.d.ts +13 -0
  37. package/dist/types.d.ts.map +1 -0
  38. package/package.json +70 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ # Changelog
2
+
3
+ ## 0.0.1 — 2026-04-11
4
+
5
+ Initial release — conference calling extracted from `@scalemule/chat`.
6
+
7
+ **Core:**
8
+ - `ConferenceClient` — vendor-neutral HTTP client for the ScaleMule conference service
9
+ - Call lifecycle: `createCall`, `getCall`, `listCalls`, `joinCall`, `leaveCall`, `endCall`
10
+ - Types: `Call`, `CallSession`, `CallParticipant`, `CreateCallOptions`, `ListCallsOptions`
11
+
12
+ **React components** (from `@scalemule/conference/react`):
13
+ - `CallOverlay` — full-screen LiveKit room wrapper with lazy-loaded backend
14
+ - `CallButton` — one-click call initiation with `getUserMedia` in click handler (mobile WebRTC safe)
15
+ - `CallControls` — mute/camera/screen share/end call control bar
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ScaleMule Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # @scalemule/conference
2
+
3
+ ScaleMule Conference SDK — audio/video calls, screen sharing, device management.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @scalemule/conference
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Core client (no React required)
14
+
15
+ ```ts
16
+ import { ConferenceClient } from '@scalemule/conference';
17
+
18
+ const conf = new ConferenceClient({ baseUrl: '/api/conference' });
19
+ const call = await conf.createCall({ conversationId, callType: 'video' });
20
+ const session = await conf.joinCall(call.id);
21
+ ```
22
+
23
+ ### React components
24
+
25
+ ```tsx
26
+ import { CallOverlay, CallButton, CallControls } from '@scalemule/conference/react';
27
+
28
+ <CallOverlay
29
+ session={session}
30
+ onTokenRefresh={() => conf.joinCall(call.id)}
31
+ onClose={() => conf.leaveCall(call.id)}
32
+ />
33
+ ```
34
+
35
+ ## Optional: LiveKit default styling
36
+
37
+ If you want LiveKit's default cosmetic styling for CallOverlay/VideoConference:
38
+
39
+ ```bash
40
+ npm install @livekit/components-styles
41
+ ```
42
+
43
+ Then import it in your app entry:
44
+
45
+ ```ts
46
+ import '@livekit/components-styles';
47
+ ```
48
+
49
+ Without this, the components still work (they have inline layout styles) but lack LiveKit's theme styling.
50
+
51
+ ## License
52
+
53
+ MIT
@@ -0,0 +1,12 @@
1
+ /** Short "bling" sound for call connect. */
2
+ export declare const JOIN_SOUND: string;
3
+ /** Notification ring for incoming calls. */
4
+ export declare const RING_SOUND: string;
5
+ /**
6
+ * Play a conference sound effect.
7
+ *
8
+ * Returns a promise that resolves when playback starts (may be rejected
9
+ * if the browser blocks autoplay — callers should catch and ignore).
10
+ */
11
+ export declare function playSound(sound: 'join' | 'ring'): Promise<void>;
12
+ //# sourceMappingURL=sounds.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sounds.d.ts","sourceRoot":"","sources":["../../src/assets/sounds.ts"],"names":[],"mappings":"AAwDA,4CAA4C;AAC5C,eAAO,MAAM,UAAU,QAAyB,CAAC;AAEjD,4CAA4C;AAC5C,eAAO,MAAM,UAAU,QAAyB,CAAC;AAEjD;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAO/D"}
@@ -0,0 +1,103 @@
1
+ import { type HttpTransportConfig } from '../transport';
2
+ /** A call session as returned by the conference service. */
3
+ export interface Call {
4
+ /** Call session UUID. */
5
+ id: string;
6
+ /** Linked conversation, if this call is tied to a chat conversation. */
7
+ conversationId: string | null;
8
+ /** `"audio"` | `"video"` | `"screen_share"`. */
9
+ callType: 'audio' | 'video' | 'screen_share';
10
+ /** Lifecycle state: `"created"` | `"active"` | `"ended"` (and whatever else the backend emits). */
11
+ status: string;
12
+ /** UUID of the participant who created the call. */
13
+ createdBy: string;
14
+ /** Opaque room identifier used to route all participants into the same session. */
15
+ roomId: string;
16
+ /** ISO-8601 creation timestamp. */
17
+ createdAt: string;
18
+ }
19
+ /** A single participant in a call. */
20
+ export interface CallParticipant {
21
+ id: string;
22
+ userId: string;
23
+ role: string;
24
+ status: string;
25
+ }
26
+ /**
27
+ * Credentials and participant info returned when joining a call.
28
+ *
29
+ * `accessToken` is short-lived. Refresh it by calling `joinCall()` again
30
+ * before `tokenExpiresAt`.
31
+ */
32
+ export interface CallSession {
33
+ /** The call being joined (same as `Call.id`). */
34
+ callId: string;
35
+ /** WebSocket URL for the real-time media session. */
36
+ serverUrl: string;
37
+ /** Short-lived access token presented to `serverUrl`. */
38
+ accessToken: string;
39
+ /**
40
+ * Absolute timestamp (epoch ms) when `accessToken` expires.
41
+ * The client should refresh before this time.
42
+ */
43
+ tokenExpiresAt: number;
44
+ /** The joining user's participant record. */
45
+ participant: CallParticipant;
46
+ }
47
+ /** Options for `ConferenceClient.createCall()`. */
48
+ export interface CreateCallOptions {
49
+ /** Link the call to an existing chat conversation. */
50
+ conversationId?: string;
51
+ /** Defaults to `"video"`. */
52
+ callType?: 'audio' | 'video' | 'screen_share';
53
+ /** Free-form metadata attached to the call record. */
54
+ metadata?: Record<string, unknown>;
55
+ }
56
+ /** Options for `ConferenceClient.listCalls()`. */
57
+ export interface ListCallsOptions {
58
+ conversationId?: string;
59
+ status?: string;
60
+ page?: number;
61
+ perPage?: number;
62
+ }
63
+ /** Configuration for a `ConferenceClient`. */
64
+ export type ConferenceClientConfig = HttpTransportConfig;
65
+ /**
66
+ * Vendor-neutral client for the ScaleMule conference service.
67
+ *
68
+ * Handles call lifecycle (create/list/get/end) and participation
69
+ * (join/leave). The returned `CallSession` object contains generic
70
+ * `serverUrl` and `accessToken` fields that `CallOverlay` knows how to
71
+ * consume — customer code never names the underlying video backend.
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * const conf = new ConferenceClient({ baseUrl, apiKey });
76
+ * const call = await conf.createCall({ conversationId, callType: 'video' });
77
+ * const session = await conf.joinCall(call.id);
78
+ * // <CallOverlay session={session} onClose={() => conf.leaveCall(call.id)} />
79
+ * ```
80
+ */
81
+ export declare class ConferenceClient {
82
+ private http;
83
+ constructor(config: ConferenceClientConfig);
84
+ /** Create a new call session. */
85
+ createCall(options?: CreateCallOptions): Promise<Call>;
86
+ /** Fetch a single call by id. */
87
+ getCall(callId: string): Promise<Call>;
88
+ /** List calls (most recent first), optionally filtered by conversation or status. */
89
+ listCalls(options?: ListCallsOptions): Promise<Call[]>;
90
+ /**
91
+ * Join a call. Returns a vendor-neutral session with the credentials
92
+ * the client needs to connect to the media server.
93
+ *
94
+ * Also used to refresh credentials: call `joinCall()` again before the
95
+ * previous `tokenExpiresAt` to get a fresh access token.
96
+ */
97
+ joinCall(callId: string): Promise<CallSession>;
98
+ /** Leave a call (idempotent). */
99
+ leaveCall(callId: string): Promise<void>;
100
+ /** End a call — only the host can call this. */
101
+ endCall(callId: string): Promise<void>;
102
+ }
103
+ //# sourceMappingURL=ConferenceClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConferenceClient.d.ts","sourceRoot":"","sources":["../../src/core/ConferenceClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAiB,KAAK,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAevE,4DAA4D;AAC5D,MAAM,WAAW,IAAI;IACnB,yBAAyB;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,wEAAwE;IACxE,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,gDAAgD;IAChD,QAAQ,EAAE,OAAO,GAAG,OAAO,GAAG,cAAc,CAAC;IAC7C,mGAAmG;IACnG,MAAM,EAAE,MAAM,CAAC;IACf,oDAAoD;IACpD,SAAS,EAAE,MAAM,CAAC;IAClB,mFAAmF;IACnF,MAAM,EAAE,MAAM,CAAC;IACf,mCAAmC;IACnC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,sCAAsC;AACtC,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IAC1B,iDAAiD;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,qDAAqD;IACrD,SAAS,EAAE,MAAM,CAAC;IAClB,yDAAyD;IACzD,WAAW,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB,6CAA6C;IAC7C,WAAW,EAAE,eAAe,CAAC;CAC9B;AAED,mDAAmD;AACnD,MAAM,WAAW,iBAAiB;IAChC,sDAAsD;IACtD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,6BAA6B;IAC7B,QAAQ,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,cAAc,CAAC;IAC9C,sDAAsD;IACtD,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,kDAAkD;AAClD,MAAM,WAAW,gBAAgB;IAC/B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AA4DD,8CAA8C;AAC9C,MAAM,MAAM,sBAAsB,GAAG,mBAAmB,CAAC;AAEzD;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,IAAI,CAAgB;gBAEhB,MAAM,EAAE,sBAAsB;IAI1C,iCAAiC;IAC3B,UAAU,CAAC,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAahE,iCAAiC;IAC3B,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAK5C,qFAAqF;IAC/E,SAAS,CAAC,OAAO,GAAE,gBAAqB,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAahE;;;;;;OAMG;IACG,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAOpD,iCAAiC;IAC3B,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI9C,gDAAgD;IAC1C,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAG7C"}
package/dist/index.cjs ADDED
@@ -0,0 +1,171 @@
1
+ 'use strict';
2
+
3
+ // src/transport.ts
4
+ var DEFAULT_REQUEST_TIMEOUT = 1e4;
5
+ var HttpTransport = class {
6
+ constructor(config) {
7
+ this.baseUrl = config.baseUrl.replace(/\/$/, "");
8
+ this.apiKey = config.apiKey;
9
+ this.getToken = config.getToken;
10
+ this.timeout = config.timeout ?? DEFAULT_REQUEST_TIMEOUT;
11
+ }
12
+ async get(path) {
13
+ return this.request("GET", path);
14
+ }
15
+ async post(path, body) {
16
+ return this.request("POST", path, body);
17
+ }
18
+ async patch(path, body) {
19
+ return this.request("PATCH", path, body);
20
+ }
21
+ async put(path, body) {
22
+ return this.request("PUT", path, body);
23
+ }
24
+ async del(path) {
25
+ return this.request("DELETE", path);
26
+ }
27
+ async request(method, path, body) {
28
+ const headers = {
29
+ "Content-Type": "application/json"
30
+ };
31
+ if (this.apiKey) {
32
+ headers["x-api-key"] = this.apiKey;
33
+ }
34
+ if (this.getToken) {
35
+ const token = await this.getToken();
36
+ if (token) {
37
+ headers["Authorization"] = `Bearer ${token}`;
38
+ }
39
+ }
40
+ const controller = new AbortController();
41
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
42
+ try {
43
+ const response = await fetch(`${this.baseUrl}${path}`, {
44
+ method,
45
+ headers,
46
+ body: body ? JSON.stringify(body) : void 0,
47
+ signal: controller.signal
48
+ });
49
+ clearTimeout(timeoutId);
50
+ if (response.status === 204) {
51
+ return { data: null, error: null };
52
+ }
53
+ const json = await response.json().catch(() => null);
54
+ if (!response.ok) {
55
+ const error = {
56
+ code: json?.error?.code ?? json?.code ?? "unknown",
57
+ message: json?.error?.message ?? json?.message ?? response.statusText,
58
+ status: response.status,
59
+ details: json?.error?.details ?? json?.details
60
+ };
61
+ return { data: null, error };
62
+ }
63
+ const data = json?.data !== void 0 ? json.data : json;
64
+ return { data, error: null };
65
+ } catch (err) {
66
+ clearTimeout(timeoutId);
67
+ const message = err instanceof Error ? err.message : "Network error";
68
+ return {
69
+ data: null,
70
+ error: { code: "network_error", message, status: 0 }
71
+ };
72
+ }
73
+ }
74
+ };
75
+
76
+ // src/core/ConferenceClient.ts
77
+ function wireToCall(w) {
78
+ return {
79
+ id: w.id,
80
+ conversationId: w.conversation_id,
81
+ callType: w.call_type,
82
+ status: w.status,
83
+ createdBy: w.created_by,
84
+ roomId: w.room_id,
85
+ createdAt: w.created_at
86
+ };
87
+ }
88
+ function wireToSession(w) {
89
+ return {
90
+ callId: w.call_id,
91
+ serverUrl: w.server_url,
92
+ accessToken: w.access_token,
93
+ tokenExpiresAt: Date.now() + w.token_ttl_seconds * 1e3,
94
+ participant: {
95
+ id: w.participant.id,
96
+ userId: w.participant.user_id,
97
+ role: w.participant.role,
98
+ status: w.participant.status
99
+ }
100
+ };
101
+ }
102
+ var ConferenceClient = class {
103
+ constructor(config) {
104
+ this.http = new HttpTransport(config);
105
+ }
106
+ /** Create a new call session. */
107
+ async createCall(options = {}) {
108
+ const body = {
109
+ conversation_id: options.conversationId,
110
+ call_type: options.callType ?? "video",
111
+ metadata: options.metadata
112
+ };
113
+ const res = await this.http.post(
114
+ "/v1/conference/calls",
115
+ body
116
+ );
117
+ return wireToCall(unwrap(res));
118
+ }
119
+ /** Fetch a single call by id. */
120
+ async getCall(callId) {
121
+ const res = await this.http.get(`/v1/conference/calls/${callId}`);
122
+ return wireToCall(unwrap(res));
123
+ }
124
+ /** List calls (most recent first), optionally filtered by conversation or status. */
125
+ async listCalls(options = {}) {
126
+ const params = new URLSearchParams();
127
+ if (options.conversationId) params.set("conversation_id", options.conversationId);
128
+ if (options.status) params.set("status", options.status);
129
+ if (options.page !== void 0) params.set("page", String(options.page));
130
+ if (options.perPage !== void 0) params.set("per_page", String(options.perPage));
131
+ const query = params.toString();
132
+ const path = query ? `/v1/conference/calls?${query}` : "/v1/conference/calls";
133
+ const res = await this.http.get(path);
134
+ const data = unwrap(res);
135
+ return (data.calls ?? []).map(wireToCall);
136
+ }
137
+ /**
138
+ * Join a call. Returns a vendor-neutral session with the credentials
139
+ * the client needs to connect to the media server.
140
+ *
141
+ * Also used to refresh credentials: call `joinCall()` again before the
142
+ * previous `tokenExpiresAt` to get a fresh access token.
143
+ */
144
+ async joinCall(callId) {
145
+ const res = await this.http.post(
146
+ `/v1/conference/calls/${callId}/join`
147
+ );
148
+ return wireToSession(unwrap(res));
149
+ }
150
+ /** Leave a call (idempotent). */
151
+ async leaveCall(callId) {
152
+ await this.http.post(`/v1/conference/calls/${callId}/leave`);
153
+ }
154
+ /** End a call — only the host can call this. */
155
+ async endCall(callId) {
156
+ await this.http.post(`/v1/conference/calls/${callId}/end`);
157
+ }
158
+ };
159
+ function unwrap(res) {
160
+ if (res.error || res.data === null) {
161
+ const msg = res.error?.message ?? "Conference API request failed";
162
+ throw new Error(msg);
163
+ }
164
+ return res.data;
165
+ }
166
+
167
+ // src/index.ts
168
+ var CONFERENCE_VERSION = "0.0.1";
169
+
170
+ exports.CONFERENCE_VERSION = CONFERENCE_VERSION;
171
+ exports.ConferenceClient = ConferenceClient;
@@ -0,0 +1,5 @@
1
+ export { ConferenceClient } from './core/ConferenceClient';
2
+ export type { Call, CallParticipant, CallSession, ConferenceClientConfig, CreateCallOptions, ListCallsOptions, } from './core/ConferenceClient';
3
+ export type { ApiResponse, ApiError } from './types';
4
+ export declare const CONFERENCE_VERSION = "0.0.1";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,YAAY,EACV,IAAI,EACJ,eAAe,EACf,WAAW,EACX,sBAAsB,EACtB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,yBAAyB,CAAC;AAEjC,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAErD,eAAO,MAAM,kBAAkB,UAAU,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,168 @@
1
+ // src/transport.ts
2
+ var DEFAULT_REQUEST_TIMEOUT = 1e4;
3
+ var HttpTransport = class {
4
+ constructor(config) {
5
+ this.baseUrl = config.baseUrl.replace(/\/$/, "");
6
+ this.apiKey = config.apiKey;
7
+ this.getToken = config.getToken;
8
+ this.timeout = config.timeout ?? DEFAULT_REQUEST_TIMEOUT;
9
+ }
10
+ async get(path) {
11
+ return this.request("GET", path);
12
+ }
13
+ async post(path, body) {
14
+ return this.request("POST", path, body);
15
+ }
16
+ async patch(path, body) {
17
+ return this.request("PATCH", path, body);
18
+ }
19
+ async put(path, body) {
20
+ return this.request("PUT", path, body);
21
+ }
22
+ async del(path) {
23
+ return this.request("DELETE", path);
24
+ }
25
+ async request(method, path, body) {
26
+ const headers = {
27
+ "Content-Type": "application/json"
28
+ };
29
+ if (this.apiKey) {
30
+ headers["x-api-key"] = this.apiKey;
31
+ }
32
+ if (this.getToken) {
33
+ const token = await this.getToken();
34
+ if (token) {
35
+ headers["Authorization"] = `Bearer ${token}`;
36
+ }
37
+ }
38
+ const controller = new AbortController();
39
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
40
+ try {
41
+ const response = await fetch(`${this.baseUrl}${path}`, {
42
+ method,
43
+ headers,
44
+ body: body ? JSON.stringify(body) : void 0,
45
+ signal: controller.signal
46
+ });
47
+ clearTimeout(timeoutId);
48
+ if (response.status === 204) {
49
+ return { data: null, error: null };
50
+ }
51
+ const json = await response.json().catch(() => null);
52
+ if (!response.ok) {
53
+ const error = {
54
+ code: json?.error?.code ?? json?.code ?? "unknown",
55
+ message: json?.error?.message ?? json?.message ?? response.statusText,
56
+ status: response.status,
57
+ details: json?.error?.details ?? json?.details
58
+ };
59
+ return { data: null, error };
60
+ }
61
+ const data = json?.data !== void 0 ? json.data : json;
62
+ return { data, error: null };
63
+ } catch (err) {
64
+ clearTimeout(timeoutId);
65
+ const message = err instanceof Error ? err.message : "Network error";
66
+ return {
67
+ data: null,
68
+ error: { code: "network_error", message, status: 0 }
69
+ };
70
+ }
71
+ }
72
+ };
73
+
74
+ // src/core/ConferenceClient.ts
75
+ function wireToCall(w) {
76
+ return {
77
+ id: w.id,
78
+ conversationId: w.conversation_id,
79
+ callType: w.call_type,
80
+ status: w.status,
81
+ createdBy: w.created_by,
82
+ roomId: w.room_id,
83
+ createdAt: w.created_at
84
+ };
85
+ }
86
+ function wireToSession(w) {
87
+ return {
88
+ callId: w.call_id,
89
+ serverUrl: w.server_url,
90
+ accessToken: w.access_token,
91
+ tokenExpiresAt: Date.now() + w.token_ttl_seconds * 1e3,
92
+ participant: {
93
+ id: w.participant.id,
94
+ userId: w.participant.user_id,
95
+ role: w.participant.role,
96
+ status: w.participant.status
97
+ }
98
+ };
99
+ }
100
+ var ConferenceClient = class {
101
+ constructor(config) {
102
+ this.http = new HttpTransport(config);
103
+ }
104
+ /** Create a new call session. */
105
+ async createCall(options = {}) {
106
+ const body = {
107
+ conversation_id: options.conversationId,
108
+ call_type: options.callType ?? "video",
109
+ metadata: options.metadata
110
+ };
111
+ const res = await this.http.post(
112
+ "/v1/conference/calls",
113
+ body
114
+ );
115
+ return wireToCall(unwrap(res));
116
+ }
117
+ /** Fetch a single call by id. */
118
+ async getCall(callId) {
119
+ const res = await this.http.get(`/v1/conference/calls/${callId}`);
120
+ return wireToCall(unwrap(res));
121
+ }
122
+ /** List calls (most recent first), optionally filtered by conversation or status. */
123
+ async listCalls(options = {}) {
124
+ const params = new URLSearchParams();
125
+ if (options.conversationId) params.set("conversation_id", options.conversationId);
126
+ if (options.status) params.set("status", options.status);
127
+ if (options.page !== void 0) params.set("page", String(options.page));
128
+ if (options.perPage !== void 0) params.set("per_page", String(options.perPage));
129
+ const query = params.toString();
130
+ const path = query ? `/v1/conference/calls?${query}` : "/v1/conference/calls";
131
+ const res = await this.http.get(path);
132
+ const data = unwrap(res);
133
+ return (data.calls ?? []).map(wireToCall);
134
+ }
135
+ /**
136
+ * Join a call. Returns a vendor-neutral session with the credentials
137
+ * the client needs to connect to the media server.
138
+ *
139
+ * Also used to refresh credentials: call `joinCall()` again before the
140
+ * previous `tokenExpiresAt` to get a fresh access token.
141
+ */
142
+ async joinCall(callId) {
143
+ const res = await this.http.post(
144
+ `/v1/conference/calls/${callId}/join`
145
+ );
146
+ return wireToSession(unwrap(res));
147
+ }
148
+ /** Leave a call (idempotent). */
149
+ async leaveCall(callId) {
150
+ await this.http.post(`/v1/conference/calls/${callId}/leave`);
151
+ }
152
+ /** End a call — only the host can call this. */
153
+ async endCall(callId) {
154
+ await this.http.post(`/v1/conference/calls/${callId}/end`);
155
+ }
156
+ };
157
+ function unwrap(res) {
158
+ if (res.error || res.data === null) {
159
+ const msg = res.error?.message ?? "Conference API request failed";
160
+ throw new Error(msg);
161
+ }
162
+ return res.data;
163
+ }
164
+
165
+ // src/index.ts
166
+ var CONFERENCE_VERSION = "0.0.1";
167
+
168
+ export { CONFERENCE_VERSION, ConferenceClient };
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ interface CallButtonProps {
3
+ conversationId: string;
4
+ callType?: 'audio' | 'video';
5
+ className?: string;
6
+ style?: React.CSSProperties;
7
+ onCallStarted?: (callId: string) => void;
8
+ onError?: (error: string) => void;
9
+ disabled?: boolean;
10
+ children?: React.ReactNode;
11
+ }
12
+ /**
13
+ * One-click call button for initiating audio/video calls from a conversation.
14
+ *
15
+ * IMPORTANT (Mobile WebRTC): This component renders a real <button> element.
16
+ * The onClick handler must trigger getUserMedia synchronously within the user
17
+ * gesture to satisfy iOS Safari and Android Chrome autoplay/media policies.
18
+ * Do NOT defer media access to useEffect or async callbacks outside the gesture.
19
+ */
20
+ export declare function CallButton({ conversationId, callType, className, style, onCallStarted, onError, disabled, children, }: CallButtonProps): React.JSX.Element;
21
+ export {};
22
+ //# sourceMappingURL=CallButton.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CallButton.d.ts","sourceRoot":"","sources":["../../src/react/CallButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAgC,MAAM,OAAO,CAAC;AAErD,UAAU,eAAe;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAC5B,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,EACzB,cAAc,EACd,QAAkB,EAClB,SAAS,EACT,KAAK,EACL,aAAa,EACb,OAAO,EACP,QAAgB,EAChB,QAAQ,GACT,EAAE,eAAe,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAmErC"}
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ interface CallControlsProps {
3
+ isMuted?: boolean;
4
+ isVideoOff?: boolean;
5
+ isScreenSharing?: boolean;
6
+ onToggleMute?: () => void;
7
+ onToggleVideo?: () => void;
8
+ onToggleScreenShare?: () => void;
9
+ onEndCall?: () => void;
10
+ style?: React.CSSProperties;
11
+ }
12
+ /**
13
+ * Call control bar with mute, camera, screen share, and end call buttons.
14
+ */
15
+ export declare function CallControls({ isMuted, isVideoOff, isScreenSharing, onToggleMute, onToggleVideo, onToggleScreenShare, onEndCall, style, }: CallControlsProps): React.JSX.Element;
16
+ export {};
17
+ //# sourceMappingURL=CallControls.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CallControls.d.ts","sourceRoot":"","sources":["../../src/react/CallControls.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,UAAU,iBAAiB;IACzB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;IAC1B,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;IAC3B,mBAAmB,CAAC,EAAE,MAAM,IAAI,CAAC;IACjC,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;CAC7B;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,EAC3B,OAAe,EACf,UAAkB,EAClB,eAAuB,EACvB,YAAY,EACZ,aAAa,EACb,mBAAmB,EACnB,SAAS,EACT,KAAK,GACN,EAAE,iBAAiB,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAmEvC"}
@@ -0,0 +1,30 @@
1
+ import React from 'react';
2
+ import type { CallSession } from '../core/ConferenceClient';
3
+ export interface CallOverlayProps {
4
+ /**
5
+ * The active call session, obtained via `ConferenceClient.joinCall(callId)`.
6
+ * The SDK re-calls `joinCall` internally before `session.tokenExpiresAt`
7
+ * via `onTokenRefresh` to keep the connection alive.
8
+ */
9
+ session: CallSession;
10
+ /**
11
+ * Called when the access token is about to expire. Should resolve to a
12
+ * fresh session (typically by calling `ConferenceClient.joinCall(callId)`
13
+ * again). If omitted, the call will disconnect when the token expires.
14
+ */
15
+ onTokenRefresh?: () => Promise<CallSession>;
16
+ /** Called when the user closes the overlay (or the call is ended). */
17
+ onClose?: () => void;
18
+ /** Fired on media-session errors. */
19
+ onError?: (error: Error) => void;
20
+ style?: React.CSSProperties;
21
+ }
22
+ /**
23
+ * Full-screen video call overlay.
24
+ *
25
+ * Takes a `CallSession` from `ConferenceClient.joinCall()` and renders a
26
+ * live video conference. The specific video backend is an implementation
27
+ * detail — this component's public API is entirely vendor-neutral.
28
+ */
29
+ export declare function CallOverlay({ session, onTokenRefresh, onClose, onError, style, }: CallOverlayProps): React.JSX.Element;
30
+ //# sourceMappingURL=CallOverlay.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CallOverlay.d.ts","sourceRoot":"","sources":["../../src/react/CallOverlay.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAkD5D,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,OAAO,EAAE,WAAW,CAAC;IACrB;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC;IAC5C,sEAAsE;IACtE,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,qCAAqC;IACrC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;CAC7B;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,EAC1B,OAAO,EACP,cAAc,EACd,OAAO,EACP,OAAO,EACP,KAAK,GACN,EAAE,gBAAgB,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAiMtC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Pop-out call window component.
3
+ *
4
+ * Opens a detached browser window with the call UI. Communicates back to
5
+ * the parent via BroadcastChannel or postMessage.
6
+ *
7
+ * Stub in 0.0.1 — full implementation in 0.0.2.
8
+ */
9
+ export declare function CallWindow(): null;
10
+ //# sourceMappingURL=CallWindow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CallWindow.d.ts","sourceRoot":"","sources":["../../src/react/CallWindow.tsx"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,UAAU,SAEzB"}