@scalemule/conference 0.0.1 → 0.0.2
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/CHANGELOG.md +6 -0
- package/dist/chunk-22YIR7AY.js +165 -0
- package/dist/chunk-LJ7QRNXU.cjs +167 -0
- package/dist/index.cjs +6 -165
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -165
- package/dist/react.cjs +5 -1
- package/dist/react.d.ts +1 -0
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.0.2 — 2026-04-12
|
|
4
|
+
|
|
5
|
+
**Fix:** `ConferenceClient` is now re-exported from `@scalemule/conference/react`.
|
|
6
|
+
Previously only types were available from the `/react` entry — the client class required
|
|
7
|
+
importing from the main entry (`@scalemule/conference`).
|
|
8
|
+
|
|
3
9
|
## 0.0.1 — 2026-04-11
|
|
4
10
|
|
|
5
11
|
Initial release — conference calling extracted from `@scalemule/chat`.
|
|
@@ -0,0 +1,165 @@
|
|
|
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
|
+
export { ConferenceClient };
|
|
@@ -0,0 +1,167 @@
|
|
|
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
|
+
exports.ConferenceClient = ConferenceClient;
|
package/dist/index.cjs
CHANGED
|
@@ -1,171 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
}
|
|
3
|
+
var chunkLJ7QRNXU_cjs = require('./chunk-LJ7QRNXU.cjs');
|
|
166
4
|
|
|
167
5
|
// src/index.ts
|
|
168
|
-
var CONFERENCE_VERSION = "0.0.
|
|
6
|
+
var CONFERENCE_VERSION = "0.0.2";
|
|
169
7
|
|
|
8
|
+
Object.defineProperty(exports, "ConferenceClient", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () { return chunkLJ7QRNXU_cjs.ConferenceClient; }
|
|
11
|
+
});
|
|
170
12
|
exports.CONFERENCE_VERSION = CONFERENCE_VERSION;
|
|
171
|
-
exports.ConferenceClient = ConferenceClient;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { ConferenceClient } from './core/ConferenceClient';
|
|
2
2
|
export type { Call, CallParticipant, CallSession, ConferenceClientConfig, CreateCallOptions, ListCallsOptions, } from './core/ConferenceClient';
|
|
3
3
|
export type { ApiResponse, ApiError } from './types';
|
|
4
|
-
export declare const CONFERENCE_VERSION = "0.0.
|
|
4
|
+
export declare const CONFERENCE_VERSION = "0.0.2";
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,168 +1,6 @@
|
|
|
1
|
-
|
|
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
|
-
}
|
|
1
|
+
export { ConferenceClient } from './chunk-22YIR7AY.js';
|
|
164
2
|
|
|
165
3
|
// src/index.ts
|
|
166
|
-
var CONFERENCE_VERSION = "0.0.
|
|
4
|
+
var CONFERENCE_VERSION = "0.0.2";
|
|
167
5
|
|
|
168
|
-
export { CONFERENCE_VERSION
|
|
6
|
+
export { CONFERENCE_VERSION };
|
package/dist/react.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var chunkLJ7QRNXU_cjs = require('./chunk-LJ7QRNXU.cjs');
|
|
3
4
|
var react = require('react');
|
|
4
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
5
6
|
|
|
6
|
-
// src/react/useConference.ts
|
|
7
7
|
var ConferenceContext = react.createContext(null);
|
|
8
8
|
function ConferenceProvider({ client, children }) {
|
|
9
9
|
const [activeSession, setActiveSession] = react.useState(null);
|
|
@@ -989,6 +989,10 @@ function playSound(sound) {
|
|
|
989
989
|
});
|
|
990
990
|
}
|
|
991
991
|
|
|
992
|
+
Object.defineProperty(exports, "ConferenceClient", {
|
|
993
|
+
enumerable: true,
|
|
994
|
+
get: function () { return chunkLJ7QRNXU_cjs.ConferenceClient; }
|
|
995
|
+
});
|
|
992
996
|
exports.CallButton = CallButton;
|
|
993
997
|
exports.CallControls = CallControls;
|
|
994
998
|
exports.CallOverlay = CallOverlay;
|
package/dist/react.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { ConferenceClient } from './core/ConferenceClient';
|
|
1
2
|
export type { Call, CallParticipant, CallSession, ConferenceClientConfig, CreateCallOptions, ListCallsOptions, } from './core/ConferenceClient';
|
|
2
3
|
export { ConferenceProvider, useConference } from './react/useConference';
|
|
3
4
|
export type { CallState } from './react/useConference';
|
package/dist/react.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.tsx"],"names":[],"mappings":"AAkBA,YAAY,EACV,IAAI,EACJ,eAAe,EACf,WAAW,EACX,sBAAsB,EACtB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC1E,YAAY,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,YAAY,EAAE,UAAU,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACxF,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,YAAY,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAGhG,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,YAAY,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,YAAY,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGhD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.tsx"],"names":[],"mappings":"AAkBA,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;AAGjC,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC1E,YAAY,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,YAAY,EAAE,UAAU,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACxF,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,YAAY,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAGhG,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,YAAY,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,YAAY,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGhD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/react.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
export { ConferenceClient } from './chunk-22YIR7AY.js';
|
|
1
2
|
import { createContext, useState, useRef, useCallback, useEffect, createElement, useContext, useMemo } from 'react';
|
|
2
3
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
3
4
|
|
|
4
|
-
// src/react/useConference.ts
|
|
5
5
|
var ConferenceContext = createContext(null);
|
|
6
6
|
function ConferenceProvider({ client, children }) {
|
|
7
7
|
const [activeSession, setActiveSession] = useState(null);
|