@snapcall/stream-ui 1.26.1 → 1.27.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/dist/stream-ui.js CHANGED
@@ -1,12 +1,12 @@
1
1
  var $jQDcL$reactjsxruntime = require("react/jsx-runtime");
2
2
  var $jQDcL$reactdomclient = require("react-dom/client");
3
3
  var $jQDcL$bowser = require("bowser");
4
+ var $jQDcL$tanstackreactquery = require("@tanstack/react-query");
4
5
  var $jQDcL$reacthottoast = require("react-hot-toast");
5
6
  var $jQDcL$styledcomponents = require("styled-components");
6
7
  var $jQDcL$react = require("react");
7
8
  var $jQDcL$snapcalldesignsystem = require("@snapcall/design-system");
8
9
  require("inobounce");
9
- var $jQDcL$reactquery = require("react-query");
10
10
  var $jQDcL$reacti18next = require("react-i18next");
11
11
  var $jQDcL$i18next = require("i18next");
12
12
  var $jQDcL$reactstately = require("react-stately");
@@ -36,6 +36,7 @@ $parcel$export(module.exports, "streamUI", () => $e68207026aca356b$export$3f9491
36
36
 
37
37
 
38
38
 
39
+
39
40
  // https://github.com/voodoocreation/ts-deepmerge/blob/master/src/index.ts
40
41
  const $6b4cf4c12c735fdf$var$isObject = (obj)=>{
41
42
  if (typeof obj === "object" && obj !== null) {
@@ -1076,18 +1077,45 @@ class $93041e14f6aa3f24$export$22ddc20344c01547 {
1076
1077
 
1077
1078
 
1078
1079
 
1080
+ const $96c060f28b764056$export$8a48322ecc4782be = async (url, streamToken, file)=>{
1081
+ const searchParams = new URLSearchParams({
1082
+ filename: file
1083
+ });
1084
+ const result = await fetch(`${url}/public/streams/${streamToken}/temporary-assets?${searchParams}`, {
1085
+ method: "get",
1086
+ headers: {
1087
+ "Content-Type": "application/json"
1088
+ }
1089
+ }).then((response)=>response.json());
1090
+ return result;
1091
+ };
1092
+ const $96c060f28b764056$export$df987b50509121ea = async (url, streamToken, file)=>{
1093
+ const searchParams = new URLSearchParams({
1094
+ filename: file
1095
+ });
1096
+ const result = await fetch(`${url}/public/streams/${streamToken}/temporary-assets?${searchParams}`, {
1097
+ method: "delete",
1098
+ headers: {
1099
+ "Content-Type": "application/json"
1100
+ }
1101
+ }).then((response)=>response.json());
1102
+ return result;
1103
+ };
1104
+
1105
+
1079
1106
 
1080
1107
  var $7f16567c4f721486$require$Buffer = $jQDcL$buffer.Buffer;
1081
- const $7f16567c4f721486$export$bfc52a1c1f84ba66 = async (apiUrl, { token: token, base64Image: base64Image, session_id: session_id, user_id: user_id, peer_id: peer_id, stepToken: stepToken })=>{
1082
- const filename = `${(0, $jQDcL$uuid.v4)()}.jpeg`;
1108
+ const $7f16567c4f721486$export$bfc52a1c1f84ba66 = async (apiUrl, { token: token, base64Image: base64Image })=>{
1109
+ const file = `${(0, $jQDcL$uuid.v4)()}.jpeg`;
1083
1110
  const uploadBody = $7f16567c4f721486$require$Buffer.from(String(base64Image).replace(/^data:image\/\w+;base64,/, ""), "base64");
1084
- const { url: url, headers: headers } = await fetch(`${apiUrl}/streams/${token}/snapshot`, {
1111
+ const { url: url, headers: headers, filename: filename } = await fetch(`${apiUrl}/public/streams/${token}/events/upload`, {
1085
1112
  method: "POST",
1086
1113
  headers: {
1087
1114
  "Content-Type": "application/json"
1088
1115
  },
1089
1116
  body: JSON.stringify({
1090
- filename: filename,
1117
+ type: "image",
1118
+ filename: file,
1091
1119
  contentLength: uploadBody.length
1092
1120
  })
1093
1121
  }).then((res)=>res.json());
@@ -1100,22 +1128,10 @@ const $7f16567c4f721486$export$bfc52a1c1f84ba66 = async (apiUrl, { token: token,
1100
1128
  },
1101
1129
  body: uploadBody
1102
1130
  });
1103
- const event = await fetch(`${apiUrl}/public/streams/${token}/snapshot-event`, {
1104
- method: "POST",
1105
- headers: {
1106
- "Content-Type": "application/json"
1107
- },
1108
- body: JSON.stringify({
1109
- stepToken: stepToken,
1110
- filename: filename,
1111
- peer_id: peer_id,
1112
- session_id: session_id,
1113
- user_id: user_id
1114
- })
1115
- }).then((res)=>res.json());
1131
+ const { url: assetUrl } = await (0, $96c060f28b764056$export$8a48322ecc4782be)(apiUrl, token, filename);
1116
1132
  return {
1117
- url: event.url,
1118
- assetId: event.id
1133
+ filename: filename,
1134
+ url: assetUrl
1119
1135
  };
1120
1136
  };
1121
1137
 
@@ -1141,7 +1157,9 @@ const $3898fb88b880f5ba$export$de363e709c412c8a = (fn, wait = 300)=>{
1141
1157
  };
1142
1158
 
1143
1159
 
1144
- const $e28f3021384abb82$export$deda6dde1c58aa97 = async (apiUrl, { file: file, token: token, stepToken: stepToken, sessionId: sessionId, userId: userId, peerId: peerId })=>{
1160
+
1161
+
1162
+ const $987c962fd22b0c93$export$6ad2c48011488f7 = async (apiUrl, { file: file, token: token })=>{
1145
1163
  if (!file) throw new Error(`Missing file on "${file}"`);
1146
1164
  const upload = await fetch(`${apiUrl}/public/streams/${token}/events/upload`, {
1147
1165
  method: "POST",
@@ -1163,23 +1181,27 @@ const $e28f3021384abb82$export$deda6dde1c58aa97 = async (apiUrl, { file: file, t
1163
1181
  },
1164
1182
  body: file
1165
1183
  });
1184
+ const { url: assetUrl } = await (0, $96c060f28b764056$export$8a48322ecc4782be)(apiUrl, token, filename);
1166
1185
  if (!uploadResponse.ok) throw new Error("Upload failed");
1167
- const type = file.type.split("/")[0];
1168
- const eventRequest = await fetch(`${apiUrl}/public/streams/${token}/events`, {
1186
+ return {
1187
+ filename: filename,
1188
+ url: assetUrl
1189
+ };
1190
+ };
1191
+
1192
+
1193
+ const $54d9e0891cb8e108$export$c30017717ce2168e = async (apiUrl, token, asset)=>{
1194
+ const event = await fetch(`${apiUrl}/public/streams/${token}/events/batch`, {
1169
1195
  method: "POST",
1170
1196
  headers: {
1171
1197
  "Content-Type": "application/json"
1172
1198
  },
1173
1199
  body: JSON.stringify({
1174
- filename: filename,
1175
- type: type,
1176
- stepToken: stepToken,
1177
- session_id: sessionId,
1178
- user_id: userId,
1179
- peer_id: peerId
1200
+ medias: asset
1180
1201
  })
1181
1202
  });
1182
- return eventRequest.json();
1203
+ if (event.ok) return event.json();
1204
+ throw new Error(` request failed ${event.status} `);
1183
1205
  };
1184
1206
 
1185
1207
 
@@ -1187,6 +1209,7 @@ const $1dedebd5ff3002eb$var$log = new (0, $d0c6baf97675ab49$export$2e2bcd8739ae0
1187
1209
  const $1dedebd5ff3002eb$export$103bedf43ba882db = {
1188
1210
  WEBRTC_FAILED: "WRTC1",
1189
1211
  WEBRTC_RECOVER_ERROR: "WRTC2",
1212
+ WEBRTC_BAD_STATE_ERROR: "WRTC3",
1190
1213
  CREATE_TRANSPORT_FAILED: "TRANS1",
1191
1214
  CONSUME_ERROR: "CONS1",
1192
1215
  SOCKET_LOST: "SOCK1",
@@ -1437,12 +1460,12 @@ class $1dedebd5ff3002eb$export$2e2bcd8739ae039 extends $1dedebd5ff3002eb$var$Str
1437
1460
  this.company = company;
1438
1461
  this.permissions = permissions;
1439
1462
  this.defaultPublicPage = defaultPublicPage;
1440
- if (recordings?.headless === true || recordings?.video === true) permissions.push("record_video_on_demand");
1441
1463
  this.plan = name;
1442
1464
  const searchParams = new URLSearchParams({
1443
1465
  peerId: this.peerId,
1444
1466
  clientId: this.clientId,
1445
- roomId: room
1467
+ roomId: room,
1468
+ events: "0"
1446
1469
  });
1447
1470
  if (options.authKey) searchParams.append("authKey", options.authKey);
1448
1471
  const recorderPath = this.joinOptions.recorder ? "/recorder" : "";
@@ -2327,7 +2350,7 @@ class $1dedebd5ff3002eb$export$2e2bcd8739ae039 extends $1dedebd5ff3002eb$var$Str
2327
2350
  };
2328
2351
  if (capabilities.focusMode) // https://github.com/w3c/mediacapture-image/blob/main/implementation-status.md
2329
2352
  try {
2330
- track.applyConstraints({
2353
+ await track.applyConstraints({
2331
2354
  advanced: [
2332
2355
  {
2333
2356
  focusMode: "continuous"
@@ -2524,26 +2547,28 @@ class $1dedebd5ff3002eb$export$2e2bcd8739ae039 extends $1dedebd5ff3002eb$var$Str
2524
2547
  async saveCapture(base64Image) {
2525
2548
  return (0, $7f16567c4f721486$export$bfc52a1c1f84ba66)(this.config.apiUrl, {
2526
2549
  token: this.roomId,
2527
- base64Image: base64Image,
2528
- peer_id: this.peerId,
2529
- user_id: this.agentIdentity?.id,
2530
- stepToken: this.stepToken
2550
+ base64Image: base64Image
2531
2551
  });
2532
2552
  }
2533
- async uploadEvent(file) {
2534
- return (0, $e28f3021384abb82$export$deda6dde1c58aa97)(this.config.apiUrl, {
2553
+ async uploadAsset(file) {
2554
+ return (0, $987c962fd22b0c93$export$6ad2c48011488f7)(this.config.apiUrl, {
2535
2555
  token: this.roomId,
2536
- file: file,
2537
- peerId: this.peerId,
2538
- userId: this.agentIdentity?.id,
2539
- stepToken: this.stepToken
2556
+ file: file
2540
2557
  });
2541
2558
  }
2542
- async deleteCapture(assetId) {
2543
- const res = await this.protoo?.request("deleteCapture", {
2544
- assetId: assetId
2559
+ createEvents(assets) {
2560
+ const baseEvent = {
2561
+ peer_id: this.peerId,
2562
+ user_id: this.agentIdentity?.id,
2563
+ stepToken: this.stepToken
2564
+ };
2565
+ const events = assets.map((asset)=>{
2566
+ return {
2567
+ ...asset,
2568
+ ...baseEvent
2569
+ };
2545
2570
  });
2546
- return res;
2571
+ return (0, $54d9e0891cb8e108$export$c30017717ce2168e)(this.config.apiUrl, this.roomId, events);
2547
2572
  }
2548
2573
  async captureVideo(videoElement) {
2549
2574
  if (this.permissions.find((permission)=>permission === "instant_picture")) {
@@ -2849,7 +2874,25 @@ class $1dedebd5ff3002eb$export$2e2bcd8739ae039 extends $1dedebd5ff3002eb$var$Str
2849
2874
  return this.permissions;
2850
2875
  }
2851
2876
  async startRecord() {
2852
- await this.protoo?.request("startRecord");
2877
+ if (this.micProducer?.rtpSender?.transport?.iceTransport.state !== "connected") try {
2878
+ this.onCriticalError($1dedebd5ff3002eb$export$103bedf43ba882db.WEBRTC_BAD_STATE_ERROR);
2879
+ const stats = await this.micProducer?.getStats();
2880
+ const dump = {};
2881
+ stats?.forEach((value, key)=>{
2882
+ dump[key] = value;
2883
+ });
2884
+ $jQDcL$sentrybrowser.captureMessage("Start record in bad state", {
2885
+ contexts: {
2886
+ data: {
2887
+ producerState: this.micProducer?.rtpSender?.transport?.iceTransport?.state,
2888
+ dump: JSON.stringify(dump)
2889
+ }
2890
+ }
2891
+ });
2892
+ } catch (err) {
2893
+ $jQDcL$sentrybrowser.captureException(err);
2894
+ }
2895
+ await this.protoo?.request("startRecord", this.micProducer?.rtpSender?.transport?.iceTransport.state);
2853
2896
  }
2854
2897
  async stopRecord() {
2855
2898
  await this.protoo?.request("stopRecord");
@@ -2866,6 +2909,12 @@ class $1dedebd5ff3002eb$export$2e2bcd8739ae039 extends $1dedebd5ff3002eb$var$Str
2866
2909
  if (!this.protoo) throw new Error("not connected");
2867
2910
  return this.protoo?.request("waitingRequests");
2868
2911
  }
2912
+ readAsset(file) {
2913
+ return (0, $96c060f28b764056$export$8a48322ecc4782be)(this.config.apiUrl, this.roomId, file);
2914
+ }
2915
+ deleteAsset(file) {
2916
+ return (0, $96c060f28b764056$export$df987b50509121ea)(this.config.apiUrl, this.roomId, file);
2917
+ }
2869
2918
  }
2870
2919
 
2871
2920
 
@@ -10380,7 +10429,7 @@ const $3d1bfd8f074b99b1$var$feedbackRatings = [
10380
10429
  const $3d1bfd8f074b99b1$var$EndView = ({ state: state })=>{
10381
10430
  const { t: t } = (0, $jQDcL$reacti18next.useTranslation)();
10382
10431
  const { setStreamState: setStreamState, options: options } = (0, $jQDcL$react.useContext)((0, $8b39f32976a7698a$export$2e2bcd8739ae039));
10383
- const sendSessionFeedback = (0, $jQDcL$reactquery.useMutation)({
10432
+ const sendSessionFeedback = (0, $jQDcL$tanstackreactquery.useMutation)({
10384
10433
  mutationFn: ({ rate: rate })=>{
10385
10434
  const { roomId: roomId, peerId: peerId } = (0, $c48c1ecc38fed4e9$export$2f377c2162fd02b2).getState();
10386
10435
  return fetch(`${options.apiUrl}/public/streams/${roomId}/feedback`, {
@@ -10396,7 +10445,7 @@ const $3d1bfd8f074b99b1$var$EndView = ({ state: state })=>{
10396
10445
  }
10397
10446
  });
10398
10447
  const showFeedback = (state === "ended" || state === "terminated") && !options.apiKey;
10399
- const feedbackSent = sendSessionFeedback.isLoading || sendSessionFeedback.isSuccess || sendSessionFeedback.isError;
10448
+ const feedbackSent = sendSessionFeedback.isPending || sendSessionFeedback.isSuccess || sendSessionFeedback.isError;
10400
10449
  const statesData = {
10401
10450
  ended: {
10402
10451
  title: t("endView.callLeft"),
@@ -11376,21 +11425,21 @@ const $ccbd73eb953b0bd0$export$b3fd96a52c80b3af = ()=>{
11376
11425
  try {
11377
11426
  let url;
11378
11427
  let thumbnailUrl;
11379
- let id;
11428
+ let filename;
11380
11429
  if (type === "image") {
11381
11430
  const dataUrl = await $ccbd73eb953b0bd0$var$fileToDataUrl(file);
11382
11431
  const data = await (0, $c48c1ecc38fed4e9$export$2f377c2162fd02b2).saveCapture(dataUrl);
11383
11432
  url = data.url;
11384
- id = data.assetId;
11433
+ filename = data.filename;
11385
11434
  } else {
11386
- const data = await (0, $c48c1ecc38fed4e9$export$2f377c2162fd02b2).uploadEvent(file);
11435
+ const data = await (0, $c48c1ecc38fed4e9$export$2f377c2162fd02b2).uploadAsset(file);
11387
11436
  url = data.url;
11388
- id = data.id;
11437
+ filename = data.filename;
11389
11438
  if (type === "video") thumbnailUrl = await $ccbd73eb953b0bd0$var$generateVideoThumbnail(file);
11390
- if (!url || !id) throw new Error("upload failed");
11439
+ if (!url || !filename) throw new Error("upload failed");
11391
11440
  }
11392
11441
  addAsset({
11393
- id: id,
11442
+ filename: filename,
11394
11443
  mode: mode,
11395
11444
  url: url,
11396
11445
  thumbnailUrl: thumbnailUrl || url,
@@ -11634,7 +11683,7 @@ const $cf45aa5122d1e9ea$export$6aa26f5ebe6471fc = ({ kind: kind, includeDefault:
11634
11683
  });
11635
11684
  return filteredDevices;
11636
11685
  };
11637
- return (0, $jQDcL$reactquery.useQuery)({
11686
+ return (0, $jQDcL$tanstackreactquery.useQuery)({
11638
11687
  queryKey: [
11639
11688
  "mediaDevices",
11640
11689
  kind || "all",
@@ -11651,7 +11700,7 @@ const $cf45aa5122d1e9ea$export$6aa26f5ebe6471fc = ({ kind: kind, includeDefault:
11651
11700
 
11652
11701
 
11653
11702
  const $c1f57aebcca9b882$export$9f1846b6ccad1893 = ()=>{
11654
- return (0, $jQDcL$reactquery.useQuery)({
11703
+ return (0, $jQDcL$tanstackreactquery.useQuery)({
11655
11704
  queryKey: [
11656
11705
  "devicesState"
11657
11706
  ],
@@ -11666,8 +11715,8 @@ const $c1f57aebcca9b882$export$9f1846b6ccad1893 = ()=>{
11666
11715
 
11667
11716
 
11668
11717
  const $e10783d7d081fd73$export$20144d37f30919ab = ()=>{
11669
- const queryClient = (0, $jQDcL$reactquery.useQueryClient)();
11670
- return (0, $jQDcL$reactquery.useMutation)({
11718
+ const queryClient = (0, $jQDcL$tanstackreactquery.useQueryClient)();
11719
+ return (0, $jQDcL$tanstackreactquery.useMutation)({
11671
11720
  mutationFn: (device)=>{
11672
11721
  if (device.kind === "audioinput") return (0, $c48c1ecc38fed4e9$export$2f377c2162fd02b2).switchMicrophone(device.deviceId);
11673
11722
  else if (device.kind === "videoinput") return (0, $c48c1ecc38fed4e9$export$2f377c2162fd02b2).switchWebcam({
@@ -11676,9 +11725,11 @@ const $e10783d7d081fd73$export$20144d37f30919ab = ()=>{
11676
11725
  else if (device.kind === "audiooutput") throw new Error("Audio output not supported");
11677
11726
  throw new Error("Unsupported device info");
11678
11727
  },
11679
- onSettled: ()=>queryClient.invalidateQueries([
11680
- "devicesState"
11681
- ])
11728
+ onSettled: ()=>queryClient.invalidateQueries({
11729
+ queryKey: [
11730
+ "devicesState"
11731
+ ]
11732
+ })
11682
11733
  });
11683
11734
  };
11684
11735
 
@@ -11733,7 +11784,7 @@ const $8229feab219a258c$export$15073df9b5e6c63e = (constraints)=>{
11733
11784
  }, [
11734
11785
  constraints.audio
11735
11786
  ]);
11736
- const query = (0, $jQDcL$reactquery.useQuery)({
11787
+ const query = (0, $jQDcL$tanstackreactquery.useQuery)({
11737
11788
  queryKey: [
11738
11789
  constraints
11739
11790
  ],
@@ -11835,7 +11886,7 @@ const $8dc2b756952b64e5$export$75b44b566abc4e9c = ()=>{
11835
11886
  className: "bg-gray-50",
11836
11887
  id: "microphone",
11837
11888
  children: /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $jQDcL$snapcalldesignsystem.SelectValue), {
11838
- children: updateDevice.isLoading ? /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $jQDcL$reactjsxruntime.Fragment), {
11889
+ children: updateDevice.isPending ? /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $jQDcL$reactjsxruntime.Fragment), {
11839
11890
  children: updateDevice.variables?.label
11840
11891
  }) : undefined
11841
11892
  })
@@ -11895,7 +11946,7 @@ const $2736f94642df39f3$export$40214e6b2a12030d = ()=>{
11895
11946
  id: "camera",
11896
11947
  children: /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $jQDcL$snapcalldesignsystem.SelectValue), {
11897
11948
  placeholder: "/",
11898
- children: updateDevice.isLoading ? /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $jQDcL$reactjsxruntime.Fragment), {
11949
+ children: updateDevice.isPending ? /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $jQDcL$reactjsxruntime.Fragment), {
11899
11950
  children: updateDevice.variables?.label
11900
11951
  }) : undefined
11901
11952
  })
@@ -12372,7 +12423,6 @@ const $c6c03cb1324fb0c3$export$e9b744e15e8fe06f = ()=>{
12372
12423
 
12373
12424
 
12374
12425
 
12375
-
12376
12426
  const $ad0f2e3b2245bd2e$export$f56b3b5841ad32ae = ({ state: state, mode: mode, url: url })=>{
12377
12427
  const { t: t } = (0, $jQDcL$reacti18next.useTranslation)();
12378
12428
  return /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $jQDcL$snapcalldesignsystem.Dialog), {
@@ -12605,7 +12655,7 @@ const $ed315b68f9410130$export$d70ec5859ea7c9bc = ({ asset: asset, canRemove: ca
12605
12655
  }),
12606
12656
  /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $2c9fb579e7fb951f$export$520a0918a6dd04fd), {
12607
12657
  state: assetDeleteModalState,
12608
- onDelete: ()=>removeAsset(asset.id)
12658
+ onDelete: ()=>removeAsset(asset.filename)
12609
12659
  }),
12610
12660
  /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsxs)("div", {
12611
12661
  className: "flex items-center gap-2.5 p-2 border border-gray-200 rounded-lg",
@@ -12646,7 +12696,7 @@ const $ed315b68f9410130$export$d70ec5859ea7c9bc = ({ asset: asset, canRemove: ca
12646
12696
  })
12647
12697
  })
12648
12698
  ]
12649
- }, asset.id),
12699
+ }, asset.filename),
12650
12700
  asset.mode !== "photo" && /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $c42fbc742adf8306$export$1ea93f9eface5983), {
12651
12701
  duration: asset.duration,
12652
12702
  averageAudioLevel: asset.averageAudioLevel
@@ -12657,17 +12707,120 @@ const $ed315b68f9410130$export$d70ec5859ea7c9bc = ({ asset: asset, canRemove: ca
12657
12707
 
12658
12708
 
12659
12709
 
12710
+
12711
+
12712
+ const $8a7a24ac08dbc187$var$getStoredAssets = async ()=>{
12713
+ try {
12714
+ const storedAssets = JSON.parse(localStorage.getItem("snapcall_assets") || "[]");
12715
+ const assets = await Promise.all(storedAssets.map(async (storedAsset)=>{
12716
+ try {
12717
+ let { url: url, thumbnailUrl: thumbnailUrl } = await (0, $c48c1ecc38fed4e9$export$2f377c2162fd02b2).readAsset(storedAsset.filename);
12718
+ if (url) {
12719
+ if (storedAsset.mode === "photo") thumbnailUrl = url;
12720
+ return {
12721
+ ...storedAsset,
12722
+ url: url,
12723
+ thumbnailUrl: thumbnailUrl
12724
+ };
12725
+ }
12726
+ } catch (error) {
12727
+ $8a7a24ac08dbc187$export$df987b50509121ea(storedAsset.filename);
12728
+ }
12729
+ }));
12730
+ return assets.filter((asset)=>Boolean(asset?.filename));
12731
+ } catch (err) {}
12732
+ return [];
12733
+ };
12734
+ const $8a7a24ac08dbc187$export$cfdbe7fcc2578443 = (asset)=>{
12735
+ try {
12736
+ const storedAsset = JSON.parse(localStorage.getItem("snapcall_assets") || "[]");
12737
+ storedAsset.push({
12738
+ ...asset,
12739
+ url: undefined,
12740
+ thumbnailUrl: null
12741
+ });
12742
+ localStorage.setItem("snapcall_assets", JSON.stringify(storedAsset));
12743
+ } catch (err) {}
12744
+ };
12745
+ const $8a7a24ac08dbc187$export$df987b50509121ea = (filename)=>{
12746
+ try {
12747
+ const storedAsset = JSON.parse(localStorage.getItem("snapcall_assets") || "[]");
12748
+ localStorage.setItem("snapcall_assets", JSON.stringify(storedAsset.filter((asset)=>{
12749
+ return asset.filename !== filename;
12750
+ })));
12751
+ } catch (err) {}
12752
+ };
12753
+ const $8a7a24ac08dbc187$export$931d641a2a152cf = ()=>{
12754
+ const storedAssets = (0, $jQDcL$tanstackreactquery.useQuery)({
12755
+ queryKey: [
12756
+ "stored-assets"
12757
+ ],
12758
+ queryFn: ()=>$8a7a24ac08dbc187$var$getStoredAssets(),
12759
+ retry: false,
12760
+ refetchOnMount: false,
12761
+ refetchOnReconnect: false,
12762
+ refetchOnWindowFocus: false,
12763
+ staleTime: Infinity
12764
+ });
12765
+ return storedAssets;
12766
+ };
12767
+
12768
+
12769
+
12770
+
12771
+ const $e399416dd32d3252$var$eventTypes = {
12772
+ screen: "screenshare",
12773
+ photo: "image",
12774
+ video: "video",
12775
+ audio: "audio"
12776
+ };
12660
12777
  const $e399416dd32d3252$export$c01bb29adf88f117 = ({ state: state })=>{
12661
12778
  const { t: t } = (0, $jQDcL$reacti18next.useTranslation)();
12662
12779
  const { assets: assets, incomingAsset: incomingAsset } = (0, $098350f721a0bb52$export$2174f25d572f9f31)();
12663
- const [sent, setSent] = (0, $jQDcL$react.useState)(false);
12780
+ const sendMutation = (0, $jQDcL$tanstackreactquery.useMutation)({
12781
+ mutationFn: async ()=>{
12782
+ try {
12783
+ const events = assets.map((asset)=>{
12784
+ return {
12785
+ filename: asset.filename,
12786
+ type: $e399416dd32d3252$var$eventTypes[asset.mode]
12787
+ };
12788
+ });
12789
+ const results = await (0, $c48c1ecc38fed4e9$export$2f377c2162fd02b2).createEvents(events);
12790
+ let errors = results.filter((result)=>{
12791
+ if (result?.success) {
12792
+ (0, $8a7a24ac08dbc187$export$df987b50509121ea)(result.filename);
12793
+ return false;
12794
+ }
12795
+ return true;
12796
+ });
12797
+ if (errors.length > 0) {
12798
+ reportError({
12799
+ code: "CRE_EV_1",
12800
+ error: "failed to create assets"
12801
+ });
12802
+ throw new Error("some media not saved");
12803
+ }
12804
+ (0, $c48c1ecc38fed4e9$export$2f377c2162fd02b2).release();
12805
+ return results;
12806
+ } catch (error) {
12807
+ reportError({
12808
+ code: "CRE_EV_1",
12809
+ error: "failed to create assets"
12810
+ });
12811
+ console.log(error);
12812
+ throw error;
12813
+ }
12814
+ }
12815
+ });
12816
+ const reportError = (0, $8dfcca373a03b9e8$export$5a5695b638d078e7)();
12664
12817
  const isMedium = window.matchMedia("(min-width: 768px)").matches;
12665
12818
  return /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $9277d94be7423d29$export$56d72fe406945300), {
12666
12819
  type: isMedium ? "dialog" : "sheet",
12667
- showClose: !sent,
12820
+ showClose: !sendMutation.isSuccess,
12668
12821
  children: /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $9277d94be7423d29$export$e943710ec76a9465), {
12669
- open: sent ? true : state.isOpen,
12670
- onOpenChange: sent ? ()=>{} : state.setOpen,
12822
+ open: sendMutation.isSuccess ? true : state.isOpen,
12823
+ onOpenChange: sendMutation.isSuccess ? ()=>{} : state.setOpen,
12671
12824
  children: /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsxs)((0, $9277d94be7423d29$export$4cf67c05c32f37ce), {
12672
12825
  className: "w-full max-h-[90vh] overflow-auto",
12673
12826
  children: [
@@ -12675,7 +12828,7 @@ const $e399416dd32d3252$export$c01bb29adf88f117 = ({ state: state })=>{
12675
12828
  children: [
12676
12829
  /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $9277d94be7423d29$export$5e9fc1357420b7eb), {
12677
12830
  className: "text-left flex items-center gap-2",
12678
- children: sent ? /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsxs)((0, $jQDcL$reactjsxruntime.Fragment), {
12831
+ children: sendMutation.isSuccess ? /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsxs)((0, $jQDcL$reactjsxruntime.Fragment), {
12679
12832
  children: [
12680
12833
  /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $jQDcL$snapcalldesignsystem.CheckCircleIcon), {
12681
12834
  size: 18,
@@ -12690,7 +12843,7 @@ const $e399416dd32d3252$export$c01bb29adf88f117 = ({ state: state })=>{
12690
12843
  count: assets.length
12691
12844
  })
12692
12845
  }),
12693
- sent && /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $9277d94be7423d29$export$51c201eb88940e0f), {
12846
+ sendMutation.isSuccess && /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $9277d94be7423d29$export$51c201eb88940e0f), {
12694
12847
  children: t("recorder.clipSubmissionDescription")
12695
12848
  })
12696
12849
  ]
@@ -12700,8 +12853,8 @@ const $e399416dd32d3252$export$c01bb29adf88f117 = ({ state: state })=>{
12700
12853
  children: [
12701
12854
  assets.map((asset)=>/*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $ed315b68f9410130$export$d70ec5859ea7c9bc), {
12702
12855
  asset: asset,
12703
- canRemove: !sent
12704
- }, asset.id)),
12856
+ canRemove: !sendMutation.isSuccess
12857
+ }, asset.filename)),
12705
12858
  incomingAsset && /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)("div", {
12706
12859
  className: "flex items-center justify-center p-2 border border-gray-200 rounded-lg",
12707
12860
  children: /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $jQDcL$snapcalldesignsystem.SpinnerIcon), {
@@ -12709,10 +12862,10 @@ const $e399416dd32d3252$export$c01bb29adf88f117 = ({ state: state })=>{
12709
12862
  className: "text-blue-700 animate-spin"
12710
12863
  })
12711
12864
  }),
12712
- !sent && /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsxs)((0, $jQDcL$snapcalldesignsystem.Button), {
12865
+ /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsxs)((0, $jQDcL$snapcalldesignsystem.Button), {
12713
12866
  className: "mt-1",
12714
12867
  variant: "secondary",
12715
- onClick: state.close,
12868
+ onClick: sendMutation.isSuccess ? ()=>window.location.reload() : state.close,
12716
12869
  children: [
12717
12870
  /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $jQDcL$snapcalldesignsystem.PlusCircleIcon), {
12718
12871
  size: 18
@@ -12723,14 +12876,16 @@ const $e399416dd32d3252$export$c01bb29adf88f117 = ({ state: state })=>{
12723
12876
  })
12724
12877
  ]
12725
12878
  }),
12726
- !sent && /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsxs)((0, $jQDcL$snapcalldesignsystem.Button), {
12879
+ !sendMutation.isSuccess && /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsxs)((0, $jQDcL$snapcalldesignsystem.Button), {
12727
12880
  className: "w-full",
12728
12881
  onClick: ()=>{
12729
- setSent(true);
12730
- (0, $c48c1ecc38fed4e9$export$2f377c2162fd02b2).release();
12882
+ sendMutation.mutate();
12731
12883
  },
12732
12884
  children: [
12733
- /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $jQDcL$snapcalldesignsystem.Send3Icon), {
12885
+ sendMutation.isPending ? /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $jQDcL$snapcalldesignsystem.SpinnerIcon), {
12886
+ size: 24,
12887
+ className: "text-blue-700 animate-spin"
12888
+ }) : /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $jQDcL$snapcalldesignsystem.Send3Icon), {
12734
12889
  size: 18,
12735
12890
  className: "text-white"
12736
12891
  }),
@@ -12913,9 +13068,9 @@ const $e86e3e83467d5bba$export$f9da3144ae2525a3 = ()=>{
12913
13068
  openAssetsModal();
12914
13069
  try {
12915
13070
  const image = await (0, $c48c1ecc38fed4e9$export$2f377c2162fd02b2).captureVideo(videoElementRef.current);
12916
- const { url: url, assetId: assetId } = await (0, $c48c1ecc38fed4e9$export$2f377c2162fd02b2).saveCapture(image);
13071
+ const { url: url, filename: filename } = await (0, $c48c1ecc38fed4e9$export$2f377c2162fd02b2).saveCapture(image);
12917
13072
  addAsset({
12918
- id: assetId,
13073
+ filename: filename,
12919
13074
  mode: "photo",
12920
13075
  url: url,
12921
13076
  thumbnailUrl: url,
@@ -13248,12 +13403,12 @@ const $8add04fa81adf378$export$b916fa2db97921a4 = ({ state: state, flow: flow, c
13248
13403
  children: /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsxs)((0, $jQDcL$snapcalldesignsystem.AlertDialogContent), {
13249
13404
  className: "w-[334px] md:w-[334px] rounded-xl max-h-screen overflow-y-auto",
13250
13405
  children: [
13251
- flow.steps?.[0]?.image_url ? /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsxs)("div", {
13406
+ flow.steps?.[0]?.config?.image_url ? /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsxs)("div", {
13252
13407
  className: "relative rounded-xl",
13253
13408
  children: [
13254
13409
  /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)("img", {
13255
13410
  className: "w-full h-[200px] object-cover rounded-[inherit]",
13256
- src: flow.steps?.[0]?.image_url,
13411
+ src: flow.steps?.[0]?.config?.image_url,
13257
13412
  alt: ""
13258
13413
  }),
13259
13414
  /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)("div", {
@@ -13302,7 +13457,7 @@ const $8add04fa81adf378$export$b916fa2db97921a4 = ({ state: state, flow: flow, c
13302
13457
  }),
13303
13458
  /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)("p", {
13304
13459
  className: "text-sm text-gray-700 whitespace-pre-line",
13305
- children: flow.steps?.[0]?.translation?.description || flow.steps?.[0]?.description
13460
+ children: flow.steps?.[0]?.translation?.description || flow.steps?.[0]?.config?.description
13306
13461
  }),
13307
13462
  /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $jQDcL$snapcalldesignsystem.AlertDialogFooter), {
13308
13463
  children: /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $jQDcL$snapcalldesignsystem.Button), {
@@ -13430,6 +13585,7 @@ const $ae4a316f3f6b930e$export$54c6bcb39df9c9b9 = ({ state: state, flow: flow })
13430
13585
 
13431
13586
 
13432
13587
 
13588
+
13433
13589
  const $3753c01d669182c5$var$browser = (0, ($parcel$interopDefault($jQDcL$bowser))).parse(window.navigator.userAgent);
13434
13590
  const $3753c01d669182c5$export$336a011955157f9a = ()=>{
13435
13591
  const { clientInitResult: clientInitResult, recorderOptions: recorderOptions } = (0, $jQDcL$react.useContext)((0, $8b39f32976a7698a$export$2e2bcd8739ae039));
@@ -13440,10 +13596,10 @@ const $3753c01d669182c5$export$336a011955157f9a = ()=>{
13440
13596
  const videoRef = (0, $jQDcL$react.useRef)(null);
13441
13597
  const assetsModalState = (0, $jQDcL$reactstately.useOverlayTriggerState)({});
13442
13598
  const flowV0ModalState = (0, $jQDcL$reactstately.useOverlayTriggerState)({
13443
- defaultOpen: Boolean(clientInitResult.flowV0)
13599
+ defaultOpen: Boolean(clientInitResult.flowV0 && !clientInitResult.flow)
13444
13600
  });
13445
13601
  const flowModalState = (0, $jQDcL$reactstately.useOverlayTriggerState)({
13446
- defaultOpen: clientInitResult.flow && !clientInitResult.flowV0
13602
+ defaultOpen: Boolean(clientInitResult.flow)
13447
13603
  });
13448
13604
  const switchToMobileModalState = (0, $jQDcL$reactstately.useOverlayTriggerState)({
13449
13605
  defaultOpen: $3753c01d669182c5$var$browser.platform.type === "desktop" && !clientInitResult.flow && !clientInitResult.flowV0
@@ -13453,16 +13609,31 @@ const $3753c01d669182c5$export$336a011955157f9a = ()=>{
13453
13609
  const devicesState = (0, $c48c1ecc38fed4e9$export$2f377c2162fd02b2).getDevicesState();
13454
13610
  const hasVideo = devicesState.camera.enabled || devicesState.screenshare.enabled;
13455
13611
  const addAsset = (0, $jQDcL$react.useCallback)((asset)=>{
13612
+ (0, $8a7a24ac08dbc187$export$cfdbe7fcc2578443)(asset);
13456
13613
  setAssets((currentAssets)=>[
13457
13614
  ...currentAssets,
13458
13615
  asset
13459
13616
  ]);
13460
13617
  setIncomingAsset(null);
13461
13618
  }, []);
13462
- const removeAsset = async (assetId)=>{
13619
+ const storedAssets = (0, $8a7a24ac08dbc187$export$931d641a2a152cf)();
13620
+ (0, $jQDcL$react.useEffect)(()=>{
13621
+ storedAssets.data?.forEach((storedAsset)=>{
13622
+ try {
13623
+ setAssets((currentAssets)=>[
13624
+ ...currentAssets,
13625
+ storedAsset
13626
+ ]);
13627
+ } catch (error) {}
13628
+ });
13629
+ }, [
13630
+ storedAssets.data
13631
+ ]);
13632
+ const removeAsset = async (filename)=>{
13463
13633
  try {
13464
- await (0, $c48c1ecc38fed4e9$export$2f377c2162fd02b2).deleteCapture(assetId);
13465
- setAssets((currentAssets)=>currentAssets.filter((asset)=>asset.id !== assetId));
13634
+ (0, $8a7a24ac08dbc187$export$df987b50509121ea)(filename);
13635
+ await (0, $c48c1ecc38fed4e9$export$2f377c2162fd02b2).deleteAsset(filename);
13636
+ setAssets((currentAssets)=>currentAssets.filter((asset)=>asset.filename !== filename));
13466
13637
  } catch (error) {
13467
13638
  reportError({
13468
13639
  code: "DEL_CAP_1",
@@ -13471,17 +13642,26 @@ const $3753c01d669182c5$export$336a011955157f9a = ()=>{
13471
13642
  }
13472
13643
  };
13473
13644
  (0, $jQDcL$react.useEffect)(()=>{
13474
- const onRecordStopped = (event)=>{
13475
- const { url: url, assetId: assetId } = event.detail;
13645
+ const onRecordStopped = async (event)=>{
13476
13646
  setIsRecording(false);
13477
- if (incomingAsset) {
13647
+ const { filename: filename, durationMs: durationMs, sizeInBytes: sizeInBytes, success: success } = event.detail;
13648
+ const { url: url } = await (0, $c48c1ecc38fed4e9$export$2f377c2162fd02b2).readAsset(filename);
13649
+ const durationSec = durationMs ? Math.round(durationMs / 1000) : undefined;
13650
+ console.log("onRecordStopped", `size: ${sizeInBytes} bytes`, `duration: ${durationSec} sec`);
13651
+ if (!success || sizeInBytes === 0) {
13652
+ setIncomingAsset(null);
13653
+ reportError({
13654
+ code: "REC_4",
13655
+ error: "error in the recording chain"
13656
+ });
13657
+ } else if (incomingAsset) {
13478
13658
  const averageAudioLevel = (0, $c48c1ecc38fed4e9$export$2f377c2162fd02b2).audioLevel?.stopAverageAnalysis();
13479
13659
  addAsset({
13480
- id: assetId,
13660
+ filename: filename,
13481
13661
  mode: incomingAsset.mode,
13482
13662
  url: url,
13483
13663
  thumbnailUrl: incomingAsset.thumbnailUrl,
13484
- duration: Math.round((Date.now() - incomingAsset.createdAt) / 1000),
13664
+ duration: durationSec,
13485
13665
  averageAudioLevel: averageAudioLevel || 0,
13486
13666
  createdAt: incomingAsset.createdAt
13487
13667
  });
@@ -13493,6 +13673,7 @@ const $3753c01d669182c5$export$336a011955157f9a = ()=>{
13493
13673
  };
13494
13674
  }, [
13495
13675
  addAsset,
13676
+ reportError,
13496
13677
  incomingAsset
13497
13678
  ]);
13498
13679
  (0, $jQDcL$react.useEffect)(()=>{
@@ -13607,7 +13788,6 @@ const $7ce296d839195d38$export$669f6ea7d267feaf = ()=>{
13607
13788
 
13608
13789
 
13609
13790
 
13610
-
13611
13791
  const $4b42d15ba6792d99$export$8d6498a96ae0e73f = ({ className: className, type: type, state: state, onClick: onClick })=>{
13612
13792
  const { t: t } = (0, $jQDcL$reacti18next.useTranslation)();
13613
13793
  const iconEl = type === "camera" ? state === "on" ? /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $jQDcL$snapcalldesignsystem.VideoRecorderIcon), {}) : /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $jQDcL$snapcalldesignsystem.VideoRecorderOffIcon), {}) : state === "on" ? /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $jQDcL$snapcalldesignsystem.Microphone1Icon), {}) : /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $jQDcL$snapcalldesignsystem.MicrophoneOff1Icon), {});
@@ -13874,9 +14054,11 @@ const $317aa81f07421dfd$var$GreetingView = ()=>{
13874
14054
  name: ""
13875
14055
  }
13876
14056
  });
13877
- const publicPage = (0, $jQDcL$reactquery.useQuery)([
13878
- (0, $c48c1ecc38fed4e9$export$2f377c2162fd02b2).defaultPublicPage?.token
13879
- ], ()=>(0, $c48c1ecc38fed4e9$export$2f377c2162fd02b2).getPublicPage((0, $c48c1ecc38fed4e9$export$2f377c2162fd02b2).defaultPublicPage?.token || ""), {
14057
+ const publicPage = (0, $jQDcL$tanstackreactquery.useQuery)({
14058
+ queryKey: [
14059
+ "public-page"
14060
+ ],
14061
+ queryFn: ()=>(0, $c48c1ecc38fed4e9$export$2f377c2162fd02b2).getPublicPage((0, $c48c1ecc38fed4e9$export$2f377c2162fd02b2).defaultPublicPage?.token || ""),
13880
14062
  enabled: Boolean((0, $c48c1ecc38fed4e9$export$2f377c2162fd02b2).defaultPublicPage?.token),
13881
14063
  staleTime: Infinity
13882
14064
  });
@@ -14328,8 +14510,8 @@ const $151f85d85248cda3$var$Bold = ({ children: children })=>/*#__PURE__*/ (0, $
14328
14510
  });
14329
14511
  const $151f85d85248cda3$export$ed71079a84f20635 = ()=>{
14330
14512
  const { t: t } = (0, $jQDcL$reacti18next.useTranslation)();
14331
- const queryClient = (0, $jQDcL$reactquery.useQueryClient)();
14332
- const waitingRequests = (0, $jQDcL$reactquery.useQuery)({
14513
+ const queryClient = (0, $jQDcL$tanstackreactquery.useQueryClient)();
14514
+ const waitingRequests = (0, $jQDcL$tanstackreactquery.useQuery)({
14333
14515
  queryKey: [
14334
14516
  "waitingRequests"
14335
14517
  ],
@@ -14337,21 +14519,25 @@ const $151f85d85248cda3$export$ed71079a84f20635 = ()=>{
14337
14519
  retry: false,
14338
14520
  refetchOnWindowFocus: false
14339
14521
  });
14340
- const acceptWaitingRequest = (0, $jQDcL$reactquery.useMutation)({
14522
+ const acceptWaitingRequest = (0, $jQDcL$tanstackreactquery.useMutation)({
14341
14523
  mutationFn: (id)=>(0, $c48c1ecc38fed4e9$export$2f377c2162fd02b2).acceptAccessRequest(id),
14342
- onSettled: ()=>queryClient.invalidateQueries([
14343
- "waitingRequests"
14344
- ])
14524
+ onSettled: ()=>queryClient.invalidateQueries({
14525
+ queryKey: [
14526
+ "waitingRequests"
14527
+ ]
14528
+ })
14345
14529
  });
14346
- const denyWaitingRequest = (0, $jQDcL$reactquery.useMutation)({
14530
+ const denyWaitingRequest = (0, $jQDcL$tanstackreactquery.useMutation)({
14347
14531
  mutationFn: (id)=>(0, $c48c1ecc38fed4e9$export$2f377c2162fd02b2).denyAccessRequest(id),
14348
- onSettled: ()=>queryClient.invalidateQueries([
14349
- "waitingRequests"
14350
- ])
14532
+ onSettled: ()=>queryClient.invalidateQueries({
14533
+ queryKey: [
14534
+ "waitingRequests"
14535
+ ]
14536
+ })
14351
14537
  });
14352
14538
  const hasWaitingRequests = (waitingRequests.data?.length || 0) > 0;
14353
14539
  const firstWaitingRequest = waitingRequests.data?.[0];
14354
- const isProcessingWaitingRequest = acceptWaitingRequest.isLoading || denyWaitingRequest.isLoading;
14540
+ const isProcessingWaitingRequest = acceptWaitingRequest.isPending || denyWaitingRequest.isPending;
14355
14541
  (0, $jQDcL$react.useEffect)(()=>{
14356
14542
  const onAccessRequest = (event)=>{
14357
14543
  queryClient.setQueryData([
@@ -14438,9 +14624,22 @@ const $151f85d85248cda3$export$ed71079a84f20635 = ()=>{
14438
14624
  };
14439
14625
 
14440
14626
 
14627
+
14628
+ const $b686c3f1638d755f$export$6bd92120cafe6ad8 = (options = {})=>{
14629
+ return (0, $jQDcL$tanstackreactquery.useQuery)({
14630
+ queryKey: [
14631
+ "dashboard-session"
14632
+ ],
14633
+ queryFn: ()=>fetch(`${"https://app.snapcall.io"}/api/user`, {
14634
+ credentials: "include"
14635
+ }).then((response)=>response.json()),
14636
+ ...options
14637
+ });
14638
+ };
14639
+
14640
+
14441
14641
  const $ee8cb448c2c74888$var$currentTheme = (0, $9295e87e6b93e693$export$3bfd0d5209a8006a)();
14442
14642
  const $ee8cb448c2c74888$var$currentLanguage = (0, $393bda1b33846dfc$export$604ba5624273df44)();
14443
- const $ee8cb448c2c74888$var$queryClient = new (0, $jQDcL$reactquery.QueryClient)();
14444
14643
  let $ee8cb448c2c74888$var$timestampCriticalError = -1;
14445
14644
  const $ee8cb448c2c74888$var$endViewStates = [
14446
14645
  "ended",
@@ -14448,8 +14647,9 @@ const $ee8cb448c2c74888$var$endViewStates = [
14448
14647
  "expired",
14449
14648
  "full"
14450
14649
  ];
14451
- const $ee8cb448c2c74888$var$StreamUI = ({ options: options })=>{
14650
+ const $ee8cb448c2c74888$var$StreamUI = ({ options: baseOptions })=>{
14452
14651
  const { t: t } = (0, $jQDcL$reacti18next.useTranslation)();
14652
+ const [options, setOptions] = (0, $jQDcL$react.useState)(baseOptions);
14453
14653
  const [selfPeerId, setSelfPeerId] = (0, $jQDcL$react.useState)(undefined);
14454
14654
  const streamUIContainerRef = (0, $jQDcL$react.useRef)(null);
14455
14655
  const videosContainerRef = (0, $jQDcL$react.useRef)(null);
@@ -14481,6 +14681,14 @@ const $ee8cb448c2c74888$var$StreamUI = ({ options: options })=>{
14481
14681
  const [recorderOptions, setRecorderOptions] = (0, $jQDcL$react.useState)(options.recorder);
14482
14682
  const [clientInitResult, setClientInitResult] = (0, $jQDcL$react.useState)({});
14483
14683
  const isFirstRender = (0, $67040444b405b263$export$5964c316e853650f)();
14684
+ const dashboardSession = (0, $b686c3f1638d755f$export$6bd92120cafe6ad8)({
14685
+ enabled: !options.disableSessionFetching,
14686
+ staleTime: Infinity,
14687
+ retry: false,
14688
+ refetchOnMount: false,
14689
+ refetchOnReconnect: false,
14690
+ refetchOnWindowFocus: false
14691
+ });
14484
14692
  const orientation = (containerWidth || window.screen.width) > (containerHeight || window.screen.height) ? "landscape" : "portrait";
14485
14693
  const styledTheme = theme === "dark" ? (0, $9295e87e6b93e693$export$3e936a8db52a10a0) : (0, $9295e87e6b93e693$export$f30cb9bc4f736419);
14486
14694
  const onWebcamUpdate = (event)=>{
@@ -14711,102 +14919,131 @@ const $ee8cb448c2c74888$var$StreamUI = ({ options: options })=>{
14711
14919
  recorderOptions,
14712
14920
  t
14713
14921
  ]);
14922
+ const initClient = (uiOptions)=>{
14923
+ if (uiOptions.token) (0, $c48c1ecc38fed4e9$export$2f377c2162fd02b2).init(uiOptions.token, {
14924
+ languageCode: uiOptions.language,
14925
+ flowToken: uiOptions.flowToken,
14926
+ recorder: uiOptions.recorder?.enabled,
14927
+ apiKey: uiOptions.apiKey,
14928
+ email: uiOptions.email,
14929
+ profile: uiOptions.profile,
14930
+ authKey: uiOptions.authKey
14931
+ }).catch((err)=>console.error(err));
14932
+ else setStreamState("expired");
14933
+ };
14714
14934
  (0, $jQDcL$react.useEffect)(()=>{
14715
- if (isFirstRender) {
14716
- if (options.token) (0, $c48c1ecc38fed4e9$export$2f377c2162fd02b2).init(options.token, {
14717
- languageCode: options.language,
14718
- flowToken: options.flowToken,
14719
- recorder: options.recorder?.enabled,
14720
- apiKey: options.apiKey,
14721
- email: options.email,
14722
- profile: options.profile,
14723
- authKey: options.authKey
14724
- }).catch((err)=>console.error(err));
14725
- else setStreamState("expired");
14726
- }
14935
+ if (isFirstRender && options.disableSessionFetching) initClient(options);
14727
14936
  }, [
14728
14937
  options,
14729
14938
  isFirstRender
14730
14939
  ]);
14731
- return /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $jQDcL$reactquery.QueryClientProvider), {
14732
- client: $ee8cb448c2c74888$var$queryClient,
14733
- children: /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $8b39f32976a7698a$export$2e2bcd8739ae039).Provider, {
14734
- value: {
14735
- videoRecording: videoRecording,
14736
- setVideoRecording: setVideoRecording,
14737
- headless: Boolean(options.headless),
14738
- plan: plan,
14739
- permissions: permissions,
14740
- selfPeerId: selfPeerId,
14741
- streamUIContainerRef: streamUIContainerRef,
14742
- videosContainerRef: videosContainerRef,
14743
- remoteTilesContainerRef: remoteTilesContainerRef,
14744
- streamState: streamState,
14745
- setStreamState: setStreamState,
14746
- isQuickConnectPopupVisible: isQuickConnectPopupVisible,
14747
- setIsQuickConnectPopupVisible: setIsQuickConnectPopupVisible,
14748
- isSettingsMenuVisible: isSettingsMenuVisible,
14749
- setIsSettingsMenuVisible: setIsSettingsMenuVisible,
14750
- isYoutubePopupVisible: isYoutubePopupVisible,
14751
- setIsYoutubePopupVisible: setIsYoutubePopupVisible,
14752
- isLinksharePopupVisible: isLinksharePopupVisible,
14753
- setIsLinksharePopupVisible: setIsLinksharePopupVisible,
14754
- isVirtualBackgroundPopupVisible: isVirtualBackgroundPopupVisible,
14755
- setIsVirtualBackgroundPopupVisible: setIsVirtualBackgroundPopupVisible,
14756
- isBlockedFeaturePopupOpen: isBlockedFeaturePopupOpen,
14757
- setBlockedFeaturePopupOpen: setBlockedFeaturePopupOpen,
14758
- isRecordingStartPopupOpen: isRecordingStartPopupOpen,
14759
- setRecordingStartPopupOpen: setRecordingStartPopupOpen,
14760
- theme: theme,
14761
- setTheme: setTheme,
14762
- language: language,
14763
- setLanguage: setLanguage,
14764
- options: options,
14765
- profile: profile,
14766
- muted: muted,
14767
- streaming: streaming,
14768
- screensharing: screensharing,
14769
- isAgent: isAgent,
14770
- userInteractionTriggered: userInteractionTriggered,
14771
- orientation: orientation,
14772
- clientInitResult: clientInitResult,
14773
- recorderOptions: recorderOptions
14774
- },
14775
- children: /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsxs)((0, $jQDcL$styledcomponents.ThemeProvider), {
14776
- theme: styledTheme,
14777
- children: [
14778
- /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $e3bb2c5d0e5b45b5$export$20f257fc407da7a3), {}),
14779
- /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $e41262de25602ed2$export$2e2bcd8739ae039), {}),
14780
- /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsxs)((0, $e3bb2c5d0e5b45b5$export$914ddf2021ea8ee6), {
14781
- ref: streamUIContainerRef,
14782
- children: [
14783
- /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $e66cc5db58913155$export$2e2bcd8739ae039), {}),
14784
- /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $jQDcL$snapcalldesignsystem.Toaster), {
14785
- duration: 3000,
14786
- className: "gap-2"
14787
- }),
14788
- /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $5dcd9e6925c7037c$export$2e2bcd8739ae039), {}),
14789
- isBlockedDevicesPopupOpen && /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $77862aeb490f36a3$export$2e2bcd8739ae039), {
14790
- close: ()=>{
14791
- setUserInteractionTriggered(true);
14792
- setBlockedDevicesPopupOpen(false);
14793
- }
14794
- }),
14795
- streamState === "loading" ? /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $7ce296d839195d38$export$669f6ea7d267feaf), {}) : streamState === "greeting" ? /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $317aa81f07421dfd$export$2e2bcd8739ae039), {}) : streamState === "recorder" ? /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $3753c01d669182c5$export$336a011955157f9a), {}) : streamState === "streaming" ? /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsxs)((0, $3f6e908c45fcc5b3$export$74636703cfe1eecf), {
14796
- children: [
14797
- /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $151f85d85248cda3$export$ed71079a84f20635), {}),
14798
- /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $e1930b467e7d8845$export$2e2bcd8739ae039), {}),
14799
- /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $88b23a8428e67b66$export$2e2bcd8739ae039), {}),
14800
- /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $a21b2aa064cb6c32$export$2e2bcd8739ae039), {}),
14801
- /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $5f509eaff0d9c05a$export$2e2bcd8739ae039), {})
14802
- ]
14803
- }) : $ee8cb448c2c74888$var$endViewStates.includes(streamState) ? /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $3d1bfd8f074b99b1$export$2e2bcd8739ae039), {
14804
- state: streamState
14805
- }) : /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $7ce296d839195d38$export$669f6ea7d267feaf), {})
14806
- ]
14807
- })
14808
- ]
14809
- })
14940
+ (0, $jQDcL$react.useEffect)(()=>{
14941
+ if (dashboardSession.isSuccess || dashboardSession.isError) {
14942
+ const newOptions = {
14943
+ ...options,
14944
+ apiKey: dashboardSession.data?.apiKey || options.apiKey,
14945
+ controls: {
14946
+ ...options.controls,
14947
+ camera: {
14948
+ ...options.controls?.camera,
14949
+ enabled: dashboardSession.data?.settings?.stream?.cameraEnabled ?? options.controls?.camera?.enabled
14950
+ },
14951
+ microphone: {
14952
+ ...options.controls?.microphone,
14953
+ enabled: dashboardSession.data?.settings?.stream?.microphoneEnabled ?? options.controls?.microphone?.enabled
14954
+ }
14955
+ },
14956
+ profile: {
14957
+ name: dashboardSession.data?.name || options.profile?.name,
14958
+ image: dashboardSession.data?.settings?.avatar_url || options.profile?.image
14959
+ }
14960
+ };
14961
+ setOptions(newOptions);
14962
+ if (dashboardSession.data?.settings?.language) setLanguage(dashboardSession.data.settings.language);
14963
+ initClient(newOptions);
14964
+ }
14965
+ // eslint-disable-next-line react-hooks/exhaustive-deps
14966
+ }, [
14967
+ dashboardSession.data,
14968
+ dashboardSession.isSuccess,
14969
+ dashboardSession.isError
14970
+ ]);
14971
+ return /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $8b39f32976a7698a$export$2e2bcd8739ae039).Provider, {
14972
+ value: {
14973
+ videoRecording: videoRecording,
14974
+ setVideoRecording: setVideoRecording,
14975
+ headless: Boolean(options.headless),
14976
+ plan: plan,
14977
+ permissions: permissions,
14978
+ selfPeerId: selfPeerId,
14979
+ streamUIContainerRef: streamUIContainerRef,
14980
+ videosContainerRef: videosContainerRef,
14981
+ remoteTilesContainerRef: remoteTilesContainerRef,
14982
+ streamState: streamState,
14983
+ setStreamState: setStreamState,
14984
+ isQuickConnectPopupVisible: isQuickConnectPopupVisible,
14985
+ setIsQuickConnectPopupVisible: setIsQuickConnectPopupVisible,
14986
+ isSettingsMenuVisible: isSettingsMenuVisible,
14987
+ setIsSettingsMenuVisible: setIsSettingsMenuVisible,
14988
+ isYoutubePopupVisible: isYoutubePopupVisible,
14989
+ setIsYoutubePopupVisible: setIsYoutubePopupVisible,
14990
+ isLinksharePopupVisible: isLinksharePopupVisible,
14991
+ setIsLinksharePopupVisible: setIsLinksharePopupVisible,
14992
+ isVirtualBackgroundPopupVisible: isVirtualBackgroundPopupVisible,
14993
+ setIsVirtualBackgroundPopupVisible: setIsVirtualBackgroundPopupVisible,
14994
+ isBlockedFeaturePopupOpen: isBlockedFeaturePopupOpen,
14995
+ setBlockedFeaturePopupOpen: setBlockedFeaturePopupOpen,
14996
+ isRecordingStartPopupOpen: isRecordingStartPopupOpen,
14997
+ setRecordingStartPopupOpen: setRecordingStartPopupOpen,
14998
+ theme: theme,
14999
+ setTheme: setTheme,
15000
+ language: language,
15001
+ setLanguage: setLanguage,
15002
+ options: options,
15003
+ profile: profile,
15004
+ muted: muted,
15005
+ streaming: streaming,
15006
+ screensharing: screensharing,
15007
+ isAgent: isAgent,
15008
+ userInteractionTriggered: userInteractionTriggered,
15009
+ orientation: orientation,
15010
+ clientInitResult: clientInitResult,
15011
+ recorderOptions: recorderOptions
15012
+ },
15013
+ children: /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsxs)((0, $jQDcL$styledcomponents.ThemeProvider), {
15014
+ theme: styledTheme,
15015
+ children: [
15016
+ /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $e3bb2c5d0e5b45b5$export$20f257fc407da7a3), {}),
15017
+ /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $e41262de25602ed2$export$2e2bcd8739ae039), {}),
15018
+ /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsxs)((0, $e3bb2c5d0e5b45b5$export$914ddf2021ea8ee6), {
15019
+ ref: streamUIContainerRef,
15020
+ children: [
15021
+ /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $e66cc5db58913155$export$2e2bcd8739ae039), {}),
15022
+ /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $jQDcL$snapcalldesignsystem.Toaster), {
15023
+ duration: 3000,
15024
+ className: "gap-2"
15025
+ }),
15026
+ /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $5dcd9e6925c7037c$export$2e2bcd8739ae039), {}),
15027
+ isBlockedDevicesPopupOpen && /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $77862aeb490f36a3$export$2e2bcd8739ae039), {
15028
+ close: ()=>{
15029
+ setUserInteractionTriggered(true);
15030
+ setBlockedDevicesPopupOpen(false);
15031
+ }
15032
+ }),
15033
+ streamState === "loading" ? /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $7ce296d839195d38$export$669f6ea7d267feaf), {}) : streamState === "greeting" ? /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $317aa81f07421dfd$export$2e2bcd8739ae039), {}) : streamState === "recorder" ? /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $3753c01d669182c5$export$336a011955157f9a), {}) : streamState === "streaming" ? /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsxs)((0, $3f6e908c45fcc5b3$export$74636703cfe1eecf), {
15034
+ children: [
15035
+ /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $151f85d85248cda3$export$ed71079a84f20635), {}),
15036
+ /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $e1930b467e7d8845$export$2e2bcd8739ae039), {}),
15037
+ /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $88b23a8428e67b66$export$2e2bcd8739ae039), {}),
15038
+ /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $a21b2aa064cb6c32$export$2e2bcd8739ae039), {}),
15039
+ /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $5f509eaff0d9c05a$export$2e2bcd8739ae039), {})
15040
+ ]
15041
+ }) : $ee8cb448c2c74888$var$endViewStates.includes(streamState) ? /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $3d1bfd8f074b99b1$export$2e2bcd8739ae039), {
15042
+ state: streamState
15043
+ }) : /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $7ce296d839195d38$export$669f6ea7d267feaf), {})
15044
+ ]
15045
+ })
15046
+ ]
14810
15047
  })
14811
15048
  });
14812
15049
  };
@@ -14828,6 +15065,7 @@ $9833f4335ab609cd$exports = "*, :before, :after {\n box-sizing: border-box;\n
14828
15065
 
14829
15066
 
14830
15067
  const $e68207026aca356b$var$browser = (0, ($parcel$interopDefault($jQDcL$bowser))).parse(window.navigator.userAgent);
15068
+ const $e68207026aca356b$var$queryClient = new (0, $jQDcL$tanstackreactquery.QueryClient)();
14831
15069
  const $e68207026aca356b$var$defaultOptions = {
14832
15070
  headless: false,
14833
15071
  recorder: {
@@ -14924,8 +15162,11 @@ const $e68207026aca356b$export$3f94917203ab7078 = {
14924
15162
  rel: "stylesheet",
14925
15163
  href: "https://rsms.me/inter/inter.css"
14926
15164
  }),
14927
- /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $ee8cb448c2c74888$export$2e2bcd8739ae039), {
14928
- options: mergedOptions
15165
+ /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $jQDcL$tanstackreactquery.QueryClientProvider), {
15166
+ client: $e68207026aca356b$var$queryClient,
15167
+ children: /*#__PURE__*/ (0, $jQDcL$reactjsxruntime.jsx)((0, $ee8cb448c2c74888$export$2e2bcd8739ae039), {
15168
+ options: mergedOptions
15169
+ })
14929
15170
  })
14930
15171
  ]
14931
15172
  }));