sabha-meetings-react 0.1.4 → 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/dist/index.d.mts +23 -4
- package/dist/index.d.ts +23 -4
- package/dist/index.js +177 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +171 -35
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -2,10 +2,11 @@ import * as react from 'react';
|
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
|
|
4
4
|
type SabhaTokens = {
|
|
5
|
-
/**
|
|
5
|
+
/** Bearer access token from login `token` (Postman `accessToken`). */
|
|
6
6
|
accessToken?: string;
|
|
7
|
+
/** Refresh token from login `refreshToken` (Postman). */
|
|
7
8
|
refreshToken?: string;
|
|
8
|
-
/**
|
|
9
|
+
/** Optional legacy `vm_session` cookie / x-sabha-session bridge. */
|
|
9
10
|
sessionCookie?: string;
|
|
10
11
|
};
|
|
11
12
|
type SabhaConfig = {
|
|
@@ -19,8 +20,13 @@ type SabhaConfig = {
|
|
|
19
20
|
/** Optional bearer access token */
|
|
20
21
|
accessToken?: string;
|
|
21
22
|
refreshToken?: string;
|
|
22
|
-
/**
|
|
23
|
+
/** Optional legacy `vm_session` (also sent as x-sabha-session for proxies). */
|
|
23
24
|
sessionCookie?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Persist access/refresh tokens (and optional vm_session) after login and restore on configure.
|
|
27
|
+
* Matches Postman collection variables. Default true.
|
|
28
|
+
*/
|
|
29
|
+
persistSession?: boolean;
|
|
24
30
|
/** Send cookies (`credentials: "include"`). Default true. */
|
|
25
31
|
withCredentials?: boolean;
|
|
26
32
|
socketPath?: string;
|
|
@@ -342,6 +348,8 @@ declare class SabhaClient {
|
|
|
342
348
|
getConnection(): MeetingConnection | null;
|
|
343
349
|
leaveMeeting(): Promise<void>;
|
|
344
350
|
private applySession;
|
|
351
|
+
private persistTokens;
|
|
352
|
+
private persistSessionCookie;
|
|
345
353
|
private tryRefresh;
|
|
346
354
|
private getOrigin;
|
|
347
355
|
private ensureConfigured;
|
|
@@ -427,5 +435,16 @@ declare function toSabhaError(error: unknown, fallback?: string): SabhaError;
|
|
|
427
435
|
|
|
428
436
|
declare function normalizeMeeting(raw: unknown): Meeting;
|
|
429
437
|
|
|
430
|
-
|
|
438
|
+
/** Readable session bridge header (browsers cannot set the Cookie request header). */
|
|
439
|
+
declare const SABHA_SESSION_HEADER = "x-sabha-session";
|
|
440
|
+
/** @deprecated Prefer SABHA_TOKENS_STORAGE_KEY — kept for one-time migration. */
|
|
441
|
+
declare const SABHA_SESSION_STORAGE_KEY = "sabha_vm_session";
|
|
442
|
+
/** Persists Postman-style `accessToken` / `refreshToken` (+ optional vm_session). */
|
|
443
|
+
declare const SABHA_TOKENS_STORAGE_KEY = "sabha_auth_tokens";
|
|
444
|
+
declare function readStoredTokens(): SabhaTokens | null;
|
|
445
|
+
declare function writeStoredTokens(tokens: SabhaTokens | null): void;
|
|
446
|
+
declare function readStoredSessionCookie(): string | null;
|
|
447
|
+
declare function writeStoredSessionCookie(value: string | null): void;
|
|
448
|
+
|
|
449
|
+
export { ContentProtection, DEFAULT_BASE_URL, DEFAULT_MEDIA_POLICY, MediaController, MeetingConnection, SABHA_SESSION_HEADER, SABHA_SESSION_STORAGE_KEY, SABHA_TOKENS_STORAGE_KEY, SabhaClient, SabhaError, SabhaProvider, createSabhaClient, normalizeMeeting, readStoredSessionCookie, readStoredTokens, toSabhaError, useSabha, useSabhaMeetings, writeStoredSessionCookie, writeStoredTokens };
|
|
431
450
|
export type { AuthSession, AuthUser, CaptureAttemptType, CreateMeetingInput, LocalMediaState, LoginInput, MediaPolicy, MediaTrackKind, Meeting, MeetingConnectionOptions, MeetingConnectionState, MeetingInvitee, MeetingOrganizer, MeetingParticipant, MeetingRoomEventMap, RegisterInput, SabhaClientStatus, SabhaConfig, SabhaContextValue, SabhaOrg, SabhaProviderProps, SabhaSocketEvents, SabhaTokens, UpdateMeetingInput, VerifyEmailInput };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,10 +2,11 @@ import * as react from 'react';
|
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
|
|
4
4
|
type SabhaTokens = {
|
|
5
|
-
/**
|
|
5
|
+
/** Bearer access token from login `token` (Postman `accessToken`). */
|
|
6
6
|
accessToken?: string;
|
|
7
|
+
/** Refresh token from login `refreshToken` (Postman). */
|
|
7
8
|
refreshToken?: string;
|
|
8
|
-
/**
|
|
9
|
+
/** Optional legacy `vm_session` cookie / x-sabha-session bridge. */
|
|
9
10
|
sessionCookie?: string;
|
|
10
11
|
};
|
|
11
12
|
type SabhaConfig = {
|
|
@@ -19,8 +20,13 @@ type SabhaConfig = {
|
|
|
19
20
|
/** Optional bearer access token */
|
|
20
21
|
accessToken?: string;
|
|
21
22
|
refreshToken?: string;
|
|
22
|
-
/**
|
|
23
|
+
/** Optional legacy `vm_session` (also sent as x-sabha-session for proxies). */
|
|
23
24
|
sessionCookie?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Persist access/refresh tokens (and optional vm_session) after login and restore on configure.
|
|
27
|
+
* Matches Postman collection variables. Default true.
|
|
28
|
+
*/
|
|
29
|
+
persistSession?: boolean;
|
|
24
30
|
/** Send cookies (`credentials: "include"`). Default true. */
|
|
25
31
|
withCredentials?: boolean;
|
|
26
32
|
socketPath?: string;
|
|
@@ -342,6 +348,8 @@ declare class SabhaClient {
|
|
|
342
348
|
getConnection(): MeetingConnection | null;
|
|
343
349
|
leaveMeeting(): Promise<void>;
|
|
344
350
|
private applySession;
|
|
351
|
+
private persistTokens;
|
|
352
|
+
private persistSessionCookie;
|
|
345
353
|
private tryRefresh;
|
|
346
354
|
private getOrigin;
|
|
347
355
|
private ensureConfigured;
|
|
@@ -427,5 +435,16 @@ declare function toSabhaError(error: unknown, fallback?: string): SabhaError;
|
|
|
427
435
|
|
|
428
436
|
declare function normalizeMeeting(raw: unknown): Meeting;
|
|
429
437
|
|
|
430
|
-
|
|
438
|
+
/** Readable session bridge header (browsers cannot set the Cookie request header). */
|
|
439
|
+
declare const SABHA_SESSION_HEADER = "x-sabha-session";
|
|
440
|
+
/** @deprecated Prefer SABHA_TOKENS_STORAGE_KEY — kept for one-time migration. */
|
|
441
|
+
declare const SABHA_SESSION_STORAGE_KEY = "sabha_vm_session";
|
|
442
|
+
/** Persists Postman-style `accessToken` / `refreshToken` (+ optional vm_session). */
|
|
443
|
+
declare const SABHA_TOKENS_STORAGE_KEY = "sabha_auth_tokens";
|
|
444
|
+
declare function readStoredTokens(): SabhaTokens | null;
|
|
445
|
+
declare function writeStoredTokens(tokens: SabhaTokens | null): void;
|
|
446
|
+
declare function readStoredSessionCookie(): string | null;
|
|
447
|
+
declare function writeStoredSessionCookie(value: string | null): void;
|
|
448
|
+
|
|
449
|
+
export { ContentProtection, DEFAULT_BASE_URL, DEFAULT_MEDIA_POLICY, MediaController, MeetingConnection, SABHA_SESSION_HEADER, SABHA_SESSION_STORAGE_KEY, SABHA_TOKENS_STORAGE_KEY, SabhaClient, SabhaError, SabhaProvider, createSabhaClient, normalizeMeeting, readStoredSessionCookie, readStoredTokens, toSabhaError, useSabha, useSabhaMeetings, writeStoredSessionCookie, writeStoredTokens };
|
|
431
450
|
export type { AuthSession, AuthUser, CaptureAttemptType, CreateMeetingInput, LocalMediaState, LoginInput, MediaPolicy, MediaTrackKind, Meeting, MeetingConnectionOptions, MeetingConnectionState, MeetingInvitee, MeetingOrganizer, MeetingParticipant, MeetingRoomEventMap, RegisterInput, SabhaClientStatus, SabhaConfig, SabhaContextValue, SabhaOrg, SabhaProviderProps, SabhaSocketEvents, SabhaTokens, UpdateMeetingInput, VerifyEmailInput };
|
package/dist/index.js
CHANGED
|
@@ -163,6 +163,83 @@ function toSabhaError(error, fallback = "Sabha request failed") {
|
|
|
163
163
|
return new SabhaError(fallback, { details: error });
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
+
// src/session.ts
|
|
167
|
+
var SABHA_SESSION_HEADER = "x-sabha-session";
|
|
168
|
+
var SABHA_SESSION_STORAGE_KEY = "sabha_vm_session";
|
|
169
|
+
var SABHA_TOKENS_STORAGE_KEY = "sabha_auth_tokens";
|
|
170
|
+
function readJson(key) {
|
|
171
|
+
try {
|
|
172
|
+
if (typeof localStorage === "undefined") return null;
|
|
173
|
+
const raw = localStorage.getItem(key);
|
|
174
|
+
if (!raw) return null;
|
|
175
|
+
return JSON.parse(raw);
|
|
176
|
+
} catch {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
function writeJson(key, value) {
|
|
181
|
+
try {
|
|
182
|
+
if (typeof localStorage === "undefined") return;
|
|
183
|
+
if (value == null) localStorage.removeItem(key);
|
|
184
|
+
else localStorage.setItem(key, JSON.stringify(value));
|
|
185
|
+
} catch {
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
function readStoredTokens() {
|
|
189
|
+
const parsed = readJson(SABHA_TOKENS_STORAGE_KEY);
|
|
190
|
+
if (parsed && typeof parsed === "object") {
|
|
191
|
+
const record = parsed;
|
|
192
|
+
const tokens = {
|
|
193
|
+
accessToken: typeof record.accessToken === "string" ? record.accessToken : void 0,
|
|
194
|
+
refreshToken: typeof record.refreshToken === "string" ? record.refreshToken : void 0,
|
|
195
|
+
sessionCookie: typeof record.sessionCookie === "string" ? record.sessionCookie : void 0
|
|
196
|
+
};
|
|
197
|
+
if (tokens.accessToken || tokens.refreshToken || tokens.sessionCookie) {
|
|
198
|
+
return tokens;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
const legacy = readStoredSessionCookie();
|
|
202
|
+
if (legacy) {
|
|
203
|
+
const migrated = { sessionCookie: legacy };
|
|
204
|
+
writeStoredTokens(migrated);
|
|
205
|
+
return migrated;
|
|
206
|
+
}
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
function writeStoredTokens(tokens) {
|
|
210
|
+
if (!tokens || !tokens.accessToken && !tokens.refreshToken && !tokens.sessionCookie) {
|
|
211
|
+
writeJson(SABHA_TOKENS_STORAGE_KEY, null);
|
|
212
|
+
writeStoredSessionCookie(null);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
writeJson(SABHA_TOKENS_STORAGE_KEY, {
|
|
216
|
+
accessToken: tokens.accessToken,
|
|
217
|
+
refreshToken: tokens.refreshToken,
|
|
218
|
+
sessionCookie: tokens.sessionCookie
|
|
219
|
+
});
|
|
220
|
+
writeStoredSessionCookie(tokens.sessionCookie ?? null);
|
|
221
|
+
}
|
|
222
|
+
function readStoredSessionCookie() {
|
|
223
|
+
try {
|
|
224
|
+
if (typeof localStorage === "undefined") return null;
|
|
225
|
+
return localStorage.getItem(SABHA_SESSION_STORAGE_KEY);
|
|
226
|
+
} catch {
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
function writeStoredSessionCookie(value) {
|
|
231
|
+
try {
|
|
232
|
+
if (typeof localStorage === "undefined") return;
|
|
233
|
+
if (!value) localStorage.removeItem(SABHA_SESSION_STORAGE_KEY);
|
|
234
|
+
else localStorage.setItem(SABHA_SESSION_STORAGE_KEY, value);
|
|
235
|
+
} catch {
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
function parseVmSession(cookieHeader) {
|
|
239
|
+
const match = /(?:^|,\s*)vm_session=([^;]+)/i.exec(cookieHeader);
|
|
240
|
+
return match?.[1] ? decodeURIComponent(match[1].trim()) : null;
|
|
241
|
+
}
|
|
242
|
+
|
|
166
243
|
// src/http/client.ts
|
|
167
244
|
function joinUrl(baseUrl, path) {
|
|
168
245
|
const base = baseUrl.replace(/\/+$/, "");
|
|
@@ -196,15 +273,21 @@ function messageFromBody(body, fallback) {
|
|
|
196
273
|
if (typeof record.error === "string") return record.error;
|
|
197
274
|
return fallback;
|
|
198
275
|
}
|
|
199
|
-
function
|
|
276
|
+
function isBrowser() {
|
|
277
|
+
const runtime = globalThis;
|
|
278
|
+
return typeof runtime.window !== "undefined" && typeof runtime.document !== "undefined";
|
|
279
|
+
}
|
|
280
|
+
function readSessionFromResponse(response) {
|
|
281
|
+
const bridged = response.headers.get(SABHA_SESSION_HEADER);
|
|
282
|
+
if (bridged?.trim()) return bridged.trim();
|
|
200
283
|
const anyHeaders = response.headers;
|
|
201
284
|
const list = typeof anyHeaders.getSetCookie === "function" ? anyHeaders.getSetCookie() : (() => {
|
|
202
285
|
const single = response.headers.get("set-cookie");
|
|
203
286
|
return single ? [single] : [];
|
|
204
287
|
})();
|
|
205
288
|
for (const entry of list) {
|
|
206
|
-
const
|
|
207
|
-
if (
|
|
289
|
+
const value = parseVmSession(entry);
|
|
290
|
+
if (value) return value;
|
|
208
291
|
}
|
|
209
292
|
return null;
|
|
210
293
|
}
|
|
@@ -218,10 +301,8 @@ var HttpClient = class {
|
|
|
218
301
|
Accept: "application/json",
|
|
219
302
|
...options.headers
|
|
220
303
|
};
|
|
221
|
-
const runtime = globalThis;
|
|
222
|
-
const isBrowser = typeof runtime.window !== "undefined" && typeof runtime.document !== "undefined";
|
|
223
304
|
const origin = this.options.getOrigin();
|
|
224
|
-
if (!isBrowser && origin) headers.Origin = origin;
|
|
305
|
+
if (!isBrowser() && origin) headers.Origin = origin;
|
|
225
306
|
const tokens = this.options.getTokens();
|
|
226
307
|
const needsAuth = options.auth !== false;
|
|
227
308
|
if (tokens?.accessToken) {
|
|
@@ -233,7 +314,10 @@ var HttpClient = class {
|
|
|
233
314
|
);
|
|
234
315
|
}
|
|
235
316
|
if (tokens?.sessionCookie) {
|
|
236
|
-
headers
|
|
317
|
+
headers[SABHA_SESSION_HEADER] = tokens.sessionCookie;
|
|
318
|
+
if (!isBrowser()) {
|
|
319
|
+
headers.Cookie = `vm_session=${tokens.sessionCookie}`;
|
|
320
|
+
}
|
|
237
321
|
}
|
|
238
322
|
if (options.body !== void 0) {
|
|
239
323
|
headers["Content-Type"] = "application/json";
|
|
@@ -247,7 +331,7 @@ var HttpClient = class {
|
|
|
247
331
|
credentials: this.options.withCredentials ? "include" : "same-origin"
|
|
248
332
|
}
|
|
249
333
|
);
|
|
250
|
-
const session =
|
|
334
|
+
const session = readSessionFromResponse(response);
|
|
251
335
|
if (session) this.options.onSessionCookie?.(session);
|
|
252
336
|
const body = await parseBody(response);
|
|
253
337
|
if (response.status === 401 && needsAuth && !retried && this.options.onUnauthorized) {
|
|
@@ -832,6 +916,7 @@ var SabhaClient = class {
|
|
|
832
916
|
);
|
|
833
917
|
this.config = {
|
|
834
918
|
withCredentials: true,
|
|
919
|
+
persistSession: true,
|
|
835
920
|
...this.config,
|
|
836
921
|
...config,
|
|
837
922
|
baseUrl
|
|
@@ -840,18 +925,19 @@ var SabhaClient = class {
|
|
|
840
925
|
...DEFAULT_MEDIA_POLICY,
|
|
841
926
|
...this.config.mediaPolicy
|
|
842
927
|
};
|
|
928
|
+
const stored = this.config.persistSession !== false ? readStoredTokens() : null;
|
|
843
929
|
this.tokens = {
|
|
844
|
-
accessToken: config.accessToken ?? this.tokens?.accessToken,
|
|
845
|
-
refreshToken: config.refreshToken ?? this.tokens?.refreshToken,
|
|
846
|
-
sessionCookie: config.sessionCookie ?? this.tokens?.sessionCookie
|
|
930
|
+
accessToken: config.accessToken ?? this.tokens?.accessToken ?? stored?.accessToken,
|
|
931
|
+
refreshToken: config.refreshToken ?? this.tokens?.refreshToken ?? stored?.refreshToken,
|
|
932
|
+
sessionCookie: config.sessionCookie ?? this.tokens?.sessionCookie ?? stored?.sessionCookie ?? void 0
|
|
847
933
|
};
|
|
848
|
-
if (!this.tokens.accessToken && !this.tokens.sessionCookie && !this.tokens.refreshToken) {
|
|
849
|
-
if (!config.accessToken && !config.sessionCookie && !config.refreshToken) ;
|
|
850
|
-
}
|
|
851
934
|
const hasAnyToken = Boolean(
|
|
852
935
|
this.tokens.accessToken || this.tokens.sessionCookie || this.tokens.refreshToken
|
|
853
936
|
);
|
|
854
937
|
if (!hasAnyToken) this.tokens = null;
|
|
938
|
+
else if (this.config.persistSession !== false) {
|
|
939
|
+
this.persistTokens(this.tokens);
|
|
940
|
+
}
|
|
855
941
|
this.http = new HttpClient({
|
|
856
942
|
baseUrl,
|
|
857
943
|
withCredentials: this.config.withCredentials !== false,
|
|
@@ -859,12 +945,12 @@ var SabhaClient = class {
|
|
|
859
945
|
getTokens: () => this.tokens,
|
|
860
946
|
setTokens: (tokens) => {
|
|
861
947
|
this.tokens = tokens;
|
|
948
|
+
if (this.config.persistSession !== false) {
|
|
949
|
+
this.persistTokens(tokens);
|
|
950
|
+
}
|
|
862
951
|
},
|
|
863
952
|
onSessionCookie: (cookie) => {
|
|
864
|
-
this.
|
|
865
|
-
...this.tokens ?? {},
|
|
866
|
-
sessionCookie: cookie ?? void 0
|
|
867
|
-
};
|
|
953
|
+
this.persistSessionCookie(cookie);
|
|
868
954
|
},
|
|
869
955
|
onUnauthorized: () => this.tryRefresh()
|
|
870
956
|
});
|
|
@@ -901,11 +987,12 @@ var SabhaClient = class {
|
|
|
901
987
|
}
|
|
902
988
|
setTokens(tokens) {
|
|
903
989
|
this.ensureConfigured();
|
|
904
|
-
this.tokens
|
|
990
|
+
this.persistTokens(tokens);
|
|
905
991
|
}
|
|
906
992
|
clearSession() {
|
|
907
993
|
this.tokens = null;
|
|
908
994
|
this.user = null;
|
|
995
|
+
this.persistTokens(null);
|
|
909
996
|
this.activeConnection?.disconnect();
|
|
910
997
|
this.activeConnection = null;
|
|
911
998
|
}
|
|
@@ -916,18 +1003,27 @@ var SabhaClient = class {
|
|
|
916
1003
|
const me = await this.auth().me();
|
|
917
1004
|
this.user = me;
|
|
918
1005
|
session.user = me;
|
|
1006
|
+
session.accessToken = this.tokens?.accessToken;
|
|
1007
|
+
session.refreshToken = this.tokens?.refreshToken;
|
|
1008
|
+
session.sessionCookie = this.tokens?.sessionCookie;
|
|
1009
|
+
return session;
|
|
919
1010
|
} catch (error) {
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
"Login returned a user profile but no auth credential (Postman contract). Sabha-API.postman_collection.json requires /api/auth/login to return `token` (stored as accessToken) for Bearer auth on POST /api/meetings. Live API currently returns neither `token` nor Set-Cookie vm_session, so meetings fail with 401 Sign in first. Fix sabha-api login to return JWT `token`/`refreshToken` (preferred) or set HttpOnly vm_session (SameSite=None; Secure).",
|
|
923
|
-
{
|
|
924
|
-
code: "SESSION_NOT_ESTABLISHED",
|
|
925
|
-
status: 401,
|
|
926
|
-
cause: error
|
|
927
|
-
}
|
|
1011
|
+
const hasCredential = Boolean(
|
|
1012
|
+
this.tokens?.accessToken || this.tokens?.sessionCookie
|
|
928
1013
|
);
|
|
1014
|
+
if (!hasCredential) {
|
|
1015
|
+
this.clearSession();
|
|
1016
|
+
throw new SabhaError(
|
|
1017
|
+
"Login returned a user profile but no auth credential. Need JWT `token` (+ optional `refreshToken`) from /api/auth/login as in Sabha-API Postman (Auth \u2192 Login). Without that, POST /api/meetings returns 401 Sign in first.",
|
|
1018
|
+
{
|
|
1019
|
+
code: "SESSION_NOT_ESTABLISHED",
|
|
1020
|
+
status: 401,
|
|
1021
|
+
cause: error
|
|
1022
|
+
}
|
|
1023
|
+
);
|
|
1024
|
+
}
|
|
1025
|
+
throw error;
|
|
929
1026
|
}
|
|
930
|
-
return session;
|
|
931
1027
|
}
|
|
932
1028
|
/** Throws if /api/auth/me fails — call before create/start meeting. */
|
|
933
1029
|
async ensureAuthenticated() {
|
|
@@ -935,7 +1031,7 @@ var SabhaClient = class {
|
|
|
935
1031
|
return await this.me();
|
|
936
1032
|
} catch (error) {
|
|
937
1033
|
throw new SabhaError(
|
|
938
|
-
"Not signed in to Sabha. Call login() first
|
|
1034
|
+
"Not signed in to Sabha. Call login() first so Authorization: Bearer <accessToken> is sent (Postman Auth \u2192 Login stores json.token).",
|
|
939
1035
|
{
|
|
940
1036
|
code: "UNAUTHENTICATED",
|
|
941
1037
|
status: 401,
|
|
@@ -1057,13 +1153,36 @@ var SabhaClient = class {
|
|
|
1057
1153
|
refreshToken: session.refreshToken ?? this.tokens?.refreshToken,
|
|
1058
1154
|
sessionCookie: session.sessionCookie ?? this.tokens?.sessionCookie
|
|
1059
1155
|
};
|
|
1156
|
+
this.persistTokens(this.tokens);
|
|
1157
|
+
}
|
|
1158
|
+
persistTokens(tokens) {
|
|
1159
|
+
this.tokens = tokens;
|
|
1160
|
+
if (this.config.persistSession !== false) {
|
|
1161
|
+
writeStoredTokens(tokens);
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
persistSessionCookie(cookie) {
|
|
1165
|
+
if (cookie) {
|
|
1166
|
+
this.persistTokens({
|
|
1167
|
+
...this.tokens ?? {},
|
|
1168
|
+
sessionCookie: cookie
|
|
1169
|
+
});
|
|
1170
|
+
return;
|
|
1171
|
+
}
|
|
1172
|
+
if (!this.tokens) {
|
|
1173
|
+
this.persistTokens(null);
|
|
1174
|
+
return;
|
|
1175
|
+
}
|
|
1176
|
+
const { sessionCookie: _removed, ...rest } = this.tokens;
|
|
1177
|
+
this.persistTokens(Object.keys(rest).length ? rest : null);
|
|
1060
1178
|
}
|
|
1061
1179
|
async tryRefresh() {
|
|
1062
1180
|
if (!this.tokens?.refreshToken) return false;
|
|
1063
1181
|
if (this.refreshPromise) return this.refreshPromise;
|
|
1064
1182
|
this.refreshPromise = (async () => {
|
|
1065
1183
|
try {
|
|
1066
|
-
await this.refreshSession();
|
|
1184
|
+
const tokens = await this.refreshSession();
|
|
1185
|
+
this.persistTokens({ ...this.tokens ?? {}, ...tokens });
|
|
1067
1186
|
return true;
|
|
1068
1187
|
} catch {
|
|
1069
1188
|
return false;
|
|
@@ -1119,6 +1238,7 @@ function SabhaProvider({
|
|
|
1119
1238
|
const resolvedConfig = {
|
|
1120
1239
|
baseUrl: DEFAULT_BASE_URL,
|
|
1121
1240
|
withCredentials: true,
|
|
1241
|
+
persistSession: true,
|
|
1122
1242
|
...config
|
|
1123
1243
|
};
|
|
1124
1244
|
const client = react.useMemo(
|
|
@@ -1143,8 +1263,10 @@ function SabhaProvider({
|
|
|
1143
1263
|
const [error, setError] = react.useState(null);
|
|
1144
1264
|
react.useEffect(() => {
|
|
1145
1265
|
client.configure(resolvedConfig);
|
|
1146
|
-
setAuthenticated(
|
|
1147
|
-
setUser(
|
|
1266
|
+
setAuthenticated(false);
|
|
1267
|
+
setUser(null);
|
|
1268
|
+
setError(null);
|
|
1269
|
+
setMeetings([]);
|
|
1148
1270
|
setReady(true);
|
|
1149
1271
|
}, [
|
|
1150
1272
|
client,
|
|
@@ -1187,12 +1309,26 @@ function SabhaProvider({
|
|
|
1187
1309
|
}, [client]);
|
|
1188
1310
|
react.useEffect(() => {
|
|
1189
1311
|
if (!ready || !autoLoadMeetings) return;
|
|
1190
|
-
|
|
1312
|
+
let cancelled = false;
|
|
1313
|
+
void client.me().then(async (me) => {
|
|
1314
|
+
if (cancelled) return;
|
|
1191
1315
|
setUser(me);
|
|
1192
1316
|
setAuthenticated(true);
|
|
1193
|
-
|
|
1317
|
+
try {
|
|
1318
|
+
await refreshMeetings();
|
|
1319
|
+
} catch {
|
|
1320
|
+
}
|
|
1194
1321
|
}).catch(() => {
|
|
1322
|
+
if (cancelled) return;
|
|
1323
|
+
client.clearSession();
|
|
1324
|
+
setAuthenticated(false);
|
|
1325
|
+
setUser(null);
|
|
1326
|
+
setMeetings([]);
|
|
1327
|
+
setError(null);
|
|
1195
1328
|
});
|
|
1329
|
+
return () => {
|
|
1330
|
+
cancelled = true;
|
|
1331
|
+
};
|
|
1196
1332
|
}, [ready, autoLoadMeetings, client, refreshMeetings]);
|
|
1197
1333
|
const createMeeting = react.useCallback(
|
|
1198
1334
|
async (input) => {
|
|
@@ -1456,13 +1592,20 @@ exports.DEFAULT_BASE_URL = DEFAULT_BASE_URL;
|
|
|
1456
1592
|
exports.DEFAULT_MEDIA_POLICY = DEFAULT_MEDIA_POLICY;
|
|
1457
1593
|
exports.MediaController = MediaController;
|
|
1458
1594
|
exports.MeetingConnection = MeetingConnection;
|
|
1595
|
+
exports.SABHA_SESSION_HEADER = SABHA_SESSION_HEADER;
|
|
1596
|
+
exports.SABHA_SESSION_STORAGE_KEY = SABHA_SESSION_STORAGE_KEY;
|
|
1597
|
+
exports.SABHA_TOKENS_STORAGE_KEY = SABHA_TOKENS_STORAGE_KEY;
|
|
1459
1598
|
exports.SabhaClient = SabhaClient;
|
|
1460
1599
|
exports.SabhaError = SabhaError;
|
|
1461
1600
|
exports.SabhaProvider = SabhaProvider;
|
|
1462
1601
|
exports.createSabhaClient = createSabhaClient;
|
|
1463
1602
|
exports.normalizeMeeting = normalizeMeeting;
|
|
1603
|
+
exports.readStoredSessionCookie = readStoredSessionCookie;
|
|
1604
|
+
exports.readStoredTokens = readStoredTokens;
|
|
1464
1605
|
exports.toSabhaError = toSabhaError;
|
|
1465
1606
|
exports.useSabha = useSabha;
|
|
1466
1607
|
exports.useSabhaMeetings = useSabhaMeetings;
|
|
1608
|
+
exports.writeStoredSessionCookie = writeStoredSessionCookie;
|
|
1609
|
+
exports.writeStoredTokens = writeStoredTokens;
|
|
1467
1610
|
//# sourceMappingURL=index.js.map
|
|
1468
1611
|
//# sourceMappingURL=index.js.map
|