@sawport/react-sdk 0.1.0-alpha.74 → 0.1.0-alpha.77

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.js CHANGED
@@ -1,3 +1,9 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value2) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value: value2 }) : obj[key] = value2;
3
+ var __publicField = (obj, key, value2) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value2);
5
+ return value2;
6
+ };
1
7
  function _mergeNamespaces(n2, m2) {
2
8
  for (var i2 = 0; i2 < m2.length; i2++) {
3
9
  const e2 = m2[i2];
@@ -1369,7 +1375,7 @@ var reactIs_production_min = {};
1369
1375
  * This source code is licensed under the MIT license found in the
1370
1376
  * LICENSE file in the root directory of this source tree.
1371
1377
  */
1372
- var b$1 = "function" === typeof Symbol && Symbol.for, c$2 = b$1 ? Symbol.for("react.element") : 60103, d$1 = b$1 ? Symbol.for("react.portal") : 60106, e$4 = b$1 ? Symbol.for("react.fragment") : 60107, f$2 = b$1 ? Symbol.for("react.strict_mode") : 60108, g$1 = b$1 ? Symbol.for("react.profiler") : 60114, h$3 = b$1 ? Symbol.for("react.provider") : 60109, k$3 = b$1 ? Symbol.for("react.context") : 60110, l$5 = b$1 ? Symbol.for("react.async_mode") : 60111, m$4 = b$1 ? Symbol.for("react.concurrent_mode") : 60111, n$6 = b$1 ? Symbol.for("react.forward_ref") : 60112, p$5 = b$1 ? Symbol.for("react.suspense") : 60113, q$4 = b$1 ? Symbol.for("react.suspense_list") : 60120, r$4 = b$1 ? Symbol.for("react.memo") : 60115, t$6 = b$1 ? Symbol.for("react.lazy") : 60116, v$3 = b$1 ? Symbol.for("react.block") : 60121, w$2 = b$1 ? Symbol.for("react.fundamental") : 60117, x$1 = b$1 ? Symbol.for("react.responder") : 60118, y$1 = b$1 ? Symbol.for("react.scope") : 60119;
1378
+ var b$1 = "function" === typeof Symbol && Symbol.for, c$2 = b$1 ? Symbol.for("react.element") : 60103, d$1 = b$1 ? Symbol.for("react.portal") : 60106, e$3 = b$1 ? Symbol.for("react.fragment") : 60107, f$2 = b$1 ? Symbol.for("react.strict_mode") : 60108, g$1 = b$1 ? Symbol.for("react.profiler") : 60114, h$3 = b$1 ? Symbol.for("react.provider") : 60109, k$3 = b$1 ? Symbol.for("react.context") : 60110, l$5 = b$1 ? Symbol.for("react.async_mode") : 60111, m$4 = b$1 ? Symbol.for("react.concurrent_mode") : 60111, n$6 = b$1 ? Symbol.for("react.forward_ref") : 60112, p$5 = b$1 ? Symbol.for("react.suspense") : 60113, q$4 = b$1 ? Symbol.for("react.suspense_list") : 60120, r$4 = b$1 ? Symbol.for("react.memo") : 60115, t$6 = b$1 ? Symbol.for("react.lazy") : 60116, v$3 = b$1 ? Symbol.for("react.block") : 60121, w$2 = b$1 ? Symbol.for("react.fundamental") : 60117, x$1 = b$1 ? Symbol.for("react.responder") : 60118, y$1 = b$1 ? Symbol.for("react.scope") : 60119;
1373
1379
  function z$2(a2) {
1374
1380
  if ("object" === typeof a2 && null !== a2) {
1375
1381
  var u2 = a2.$$typeof;
@@ -1378,7 +1384,7 @@ function z$2(a2) {
1378
1384
  switch (a2 = a2.type, a2) {
1379
1385
  case l$5:
1380
1386
  case m$4:
1381
- case e$4:
1387
+ case e$3:
1382
1388
  case g$1:
1383
1389
  case f$2:
1384
1390
  case p$5:
@@ -1409,7 +1415,7 @@ reactIs_production_min.ContextConsumer = k$3;
1409
1415
  reactIs_production_min.ContextProvider = h$3;
1410
1416
  reactIs_production_min.Element = c$2;
1411
1417
  reactIs_production_min.ForwardRef = n$6;
1412
- reactIs_production_min.Fragment = e$4;
1418
+ reactIs_production_min.Fragment = e$3;
1413
1419
  reactIs_production_min.Lazy = t$6;
1414
1420
  reactIs_production_min.Memo = r$4;
1415
1421
  reactIs_production_min.Portal = d$1;
@@ -1433,7 +1439,7 @@ reactIs_production_min.isForwardRef = function(a2) {
1433
1439
  return z$2(a2) === n$6;
1434
1440
  };
1435
1441
  reactIs_production_min.isFragment = function(a2) {
1436
- return z$2(a2) === e$4;
1442
+ return z$2(a2) === e$3;
1437
1443
  };
1438
1444
  reactIs_production_min.isLazy = function(a2) {
1439
1445
  return z$2(a2) === t$6;
@@ -1454,7 +1460,7 @@ reactIs_production_min.isSuspense = function(a2) {
1454
1460
  return z$2(a2) === p$5;
1455
1461
  };
1456
1462
  reactIs_production_min.isValidElementType = function(a2) {
1457
- return "string" === typeof a2 || "function" === typeof a2 || a2 === e$4 || a2 === m$4 || a2 === g$1 || a2 === f$2 || a2 === p$5 || a2 === q$4 || "object" === typeof a2 && null !== a2 && (a2.$$typeof === t$6 || a2.$$typeof === r$4 || a2.$$typeof === h$3 || a2.$$typeof === k$3 || a2.$$typeof === n$6 || a2.$$typeof === w$2 || a2.$$typeof === x$1 || a2.$$typeof === y$1 || a2.$$typeof === v$3);
1463
+ return "string" === typeof a2 || "function" === typeof a2 || a2 === e$3 || a2 === m$4 || a2 === g$1 || a2 === f$2 || a2 === p$5 || a2 === q$4 || "object" === typeof a2 && null !== a2 && (a2.$$typeof === t$6 || a2.$$typeof === r$4 || a2.$$typeof === h$3 || a2.$$typeof === k$3 || a2.$$typeof === n$6 || a2.$$typeof === w$2 || a2.$$typeof === x$1 || a2.$$typeof === y$1 || a2.$$typeof === v$3);
1458
1464
  };
1459
1465
  reactIs_production_min.typeOf = z$2;
1460
1466
  {
@@ -26868,8 +26874,8 @@ function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
26868
26874
  }
26869
26875
  }
26870
26876
  var eventsExports = events.exports;
26871
- const e$3 = /* @__PURE__ */ getDefaultExportFromCjs(eventsExports);
26872
- var t$5 = new e$3(), o$3 = function(n2, e2) {
26877
+ const EventEmitter$1 = /* @__PURE__ */ getDefaultExportFromCjs(eventsExports);
26878
+ var t$5 = new EventEmitter$1(), o$3 = function(n2, e2) {
26873
26879
  var o2 = n2.listeners, i2 = void 0 === o2 ? {} : o2, u2 = n2.removeListeners, a2 = void 0 === u2 ? {} : u2, v2 = n2.params, c2 = void 0 === v2 ? {} : v2;
26874
26880
  return void 0 === e2 && (e2 = []), reactExports.useLayoutEffect(function() {
26875
26881
  var r2 = Object.keys(i2);
@@ -70830,9 +70836,6 @@ const Schedules = reactExports.memo(function({
70830
70836
  }
70831
70837
  }]
70832
70838
  });
70833
- const {
70834
- socket: socket2
70835
- } = useSocket();
70836
70839
  const join2 = reactExports.useCallback(async ({
70837
70840
  conversation
70838
70841
  }) => {
@@ -70854,18 +70857,10 @@ const Schedules = reactExports.memo(function({
70854
70857
  companyClosed: false,
70855
70858
  isScheduling: false
70856
70859
  });
70857
- socket2.emit("customer-joined-conversation", {
70858
- conversation: {
70859
- id: conversation == null ? void 0 : conversation.id
70860
- },
70861
- customer: {
70862
- id: customer == null ? void 0 : customer.id
70863
- }
70864
- });
70865
70860
  } catch (error) {
70866
70861
  console.log(error);
70867
70862
  }
70868
- }, [dataRef, customer, socket2]);
70863
+ }, [dataRef, customer]);
70869
70864
  const reschedule = reactExports.useCallback(async ({
70870
70865
  id: id2
70871
70866
  }) => {
@@ -75294,6 +75289,9 @@ function ChatWidgetScreen({
75294
75289
  setPopupVisible
75295
75290
  }) {
75296
75291
  var _a, _b, _c, _d, _e, _f, _g;
75292
+ const {
75293
+ socket: socket2
75294
+ } = useSocket();
75297
75295
  const bottomRef = reactExports.useRef();
75298
75296
  const timeoutRef = reactExports.useRef();
75299
75297
  const [{
@@ -75447,6 +75445,17 @@ function ChatWidgetScreen({
75447
75445
  return () => clearInterval(intervalId);
75448
75446
  }
75449
75447
  }, [(_g = company == null ? void 0 : company.options) == null ? void 0 : _g.schedulePopUpTime, agentDetails]);
75448
+ reactExports.useEffect(() => {
75449
+ var _a2, _b2, _c2;
75450
+ socket2.connected && socket2.emit("customer-joined-conversation", {
75451
+ conversation: {
75452
+ id: (_a2 = dataRef.current) == null ? void 0 : _a2.wait.conversation.id
75453
+ },
75454
+ customer: {
75455
+ id: (_c2 = (_b2 = dataRef.current) == null ? void 0 : _b2.customer) == null ? void 0 : _c2.id
75456
+ }
75457
+ });
75458
+ }, [socket2.connected]);
75450
75459
  return /* @__PURE__ */ jsxs("div", {
75451
75460
  className: "widget-chat-container",
75452
75461
  children: [/* @__PURE__ */ jsxs("div", {
@@ -75925,7 +75934,7 @@ function WidgetOfflineHeader({
75925
75934
  company
75926
75935
  }) {
75927
75936
  return /* @__PURE__ */ jsxs("div", {
75928
- className: "d-flex flex-column justify-content-between align-items-center w-100 py-3 px-2 text-center position-relative",
75937
+ className: "flex flex-col justify-between items-center py-3 px-2 text-center relative",
75929
75938
  style: {
75930
75939
  fontSize: 16,
75931
75940
  color: "#fff"
@@ -76385,6 +76394,64 @@ var MultiStreamsMixer$1 = { exports: {} };
76385
76394
  })(MultiStreamsMixer$1);
76386
76395
  var MultiStreamsMixerExports = MultiStreamsMixer$1.exports;
76387
76396
  const MultiStreamsMixer = /* @__PURE__ */ getDefaultExportFromCjs(MultiStreamsMixerExports);
76397
+ class Transcriber extends EventEmitter$1 {
76398
+ constructor(track, lang2 = navigator.language) {
76399
+ super();
76400
+ __publicField(this, "track", null);
76401
+ __publicField(this, "trackId", null);
76402
+ __publicField(this, "recognition", null);
76403
+ __publicField(this, "recognizing", false);
76404
+ __publicField(this, "transcripts", []);
76405
+ __publicField(this, "startTime", 0);
76406
+ __publicField(this, "endTime", 0);
76407
+ __publicField(this, "currentStamp", 0);
76408
+ __publicField(this, "start", () => {
76409
+ this.recognition.start();
76410
+ this.recognition.stream = this.track;
76411
+ this.recognizing = true;
76412
+ this.startTime = performance.now();
76413
+ return this;
76414
+ });
76415
+ __publicField(this, "stop", () => {
76416
+ this.recognition.stop();
76417
+ this.recognizing = false;
76418
+ this.endTime = performance.now();
76419
+ return this;
76420
+ });
76421
+ if ("webkitSpeechRecognition" in window || "SpeechRecognition" in window) {
76422
+ this.recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
76423
+ this.recognition.continuous = true;
76424
+ this.recognition.interimResults = true;
76425
+ this.recognition.lang = lang2;
76426
+ this.track = track;
76427
+ this.recognition.onstart = this.emit("start");
76428
+ this.recognition.onend = () => this.emit("end");
76429
+ this.recognition.onresult = (event) => {
76430
+ const { results, resultIndex: i2 } = event;
76431
+ let interimTranscript = "";
76432
+ if (results[i2].isFinal && results[i2][0].transcript) {
76433
+ const data2 = {
76434
+ sentence: results[i2][0].transcript,
76435
+ confidence: results[i2][0].confidence,
76436
+ timeStamp: this.currentStamp,
76437
+ endTimeStamp: (/* @__PURE__ */ new Date()).getTime()
76438
+ };
76439
+ this.transcripts.push(data2);
76440
+ this.emit("sentence", data2);
76441
+ } else {
76442
+ this.currentStamp = (/* @__PURE__ */ new Date()).getTime();
76443
+ interimTranscript += results[i2][0].transcript;
76444
+ this.emit("interim", {
76445
+ sentence: interimTranscript,
76446
+ timeStamp: this.currentStamp
76447
+ });
76448
+ }
76449
+ this.emit("result", event);
76450
+ };
76451
+ }
76452
+ }
76453
+ }
76454
+ const createTranscript = (params) => api("transcripts", params, "post");
76388
76455
  const peerConnectionConfig = {
76389
76456
  offerToReceiveAudio: true,
76390
76457
  offerToReceiveVideo: true,
@@ -76426,7 +76493,8 @@ function useVideoCalling({ userId, conversation_id }) {
76426
76493
  isInit: false,
76427
76494
  localVideoTrack: null,
76428
76495
  connected: false,
76429
- localICECandidates: []
76496
+ localICECandidates: [],
76497
+ localTranscriber: null
76430
76498
  });
76431
76499
  const localVideoRef = reactExports.useRef(null);
76432
76500
  const remoteVideoRef = reactExports.useRef(null);
@@ -76550,6 +76618,7 @@ function useVideoCalling({ userId, conversation_id }) {
76550
76618
  };
76551
76619
  const initPeer = reactExports.useCallback(
76552
76620
  ({ response }) => {
76621
+ var _a;
76553
76622
  try {
76554
76623
  ref.current.peerConnection = new RTCPeerConnection({
76555
76624
  iceServers: response.iceServers,
@@ -76561,12 +76630,12 @@ function useVideoCalling({ userId, conversation_id }) {
76561
76630
  alert("Error initializing connection");
76562
76631
  }
76563
76632
  ref.current.peerConnection.onicecandidate = (event) => {
76564
- var _a;
76633
+ var _a2;
76565
76634
  if (event.candidate) {
76566
76635
  if (ref.current.connected) {
76567
76636
  socket2.emit("candidate", {
76568
76637
  candidate: event.candidate,
76569
- to: (_a = ref.current.data) == null ? void 0 : _a.from,
76638
+ to: (_a2 = ref.current.data) == null ? void 0 : _a2.from,
76570
76639
  from: userId
76571
76640
  });
76572
76641
  } else {
@@ -76574,7 +76643,8 @@ function useVideoCalling({ userId, conversation_id }) {
76574
76643
  }
76575
76644
  }
76576
76645
  };
76577
- ref.current.localStream && ref.current.peerConnection.addStream(ref.current.localStream);
76646
+ if (ref.current.localStream)
76647
+ (_a = ref.current.localStream) == null ? void 0 : _a.getTracks().map((track) => ref.current.peerConnection.addTrack(track, ref.current.localStream));
76578
76648
  ref.current.peerConnection.onconnectionstatechange = async () => {
76579
76649
  const connection = ref.current.peerConnection;
76580
76650
  switch (connection.connectionState) {
@@ -76588,10 +76658,10 @@ function useVideoCalling({ userId, conversation_id }) {
76588
76658
  sender.replaceTrack(localVideoTrack);
76589
76659
  }
76590
76660
  ref.current.localICECandidates.forEach((candidate) => {
76591
- var _a;
76661
+ var _a2;
76592
76662
  socket2.emit("candidate", {
76593
76663
  candidate,
76594
- to: (_a = ref.current.data) == null ? void 0 : _a.from,
76664
+ to: (_a2 = ref.current.data) == null ? void 0 : _a2.from,
76595
76665
  from: userId
76596
76666
  });
76597
76667
  });
@@ -76895,13 +76965,15 @@ function useVideoCalling({ userId, conversation_id }) {
76895
76965
  };
76896
76966
  }, [ref, stateRef, conversation_id, socket2.connected]);
76897
76967
  const stopRecording = reactExports.useCallback(() => {
76898
- var _a;
76968
+ var _a, _b;
76899
76969
  ref.current.mixer.releaseStreams();
76900
76970
  ref.current.recorder.stop();
76971
+ (_a = ref.current.localTranscriber) == null ? void 0 : _a.stop();
76901
76972
  socket2.emit("Recording.end", {
76902
76973
  conversation: { id: conversation_id },
76903
- to: ((_a = ref.current.data) == null ? void 0 : _a.from) || stateRef.current.callUserId,
76904
- recording: { id: ref.current.recordingData.id, filename: ref.current.recordingData.filename }
76974
+ to: ((_b = ref.current.data) == null ? void 0 : _b.from) || stateRef.current.callUserId,
76975
+ recording: { id: ref.current.recordingData.id, filename: ref.current.recordingData.filename },
76976
+ transcripts: ref.current.localTranscriber.transcripts
76905
76977
  });
76906
76978
  setState({ recording: false });
76907
76979
  }, [ref, stateRef, conversation_id, socket2.connected]);
@@ -76923,8 +76995,19 @@ function useVideoCalling({ userId, conversation_id }) {
76923
76995
  "Recording.start": () => {
76924
76996
  toast.info("This call is being recorded");
76925
76997
  setState({ recording: true });
76998
+ ref.current.localTranscriber = new Transcriber(ref.current.localStream);
76999
+ ref.current.localTranscriber.start();
76926
77000
  },
76927
- "Recording.end": () => setState({ recording: false })
77001
+ "Recording.end": ({ recording: recording3 }) => {
77002
+ var _a, _b, _c, _d;
77003
+ setState({ recording: false });
77004
+ (_a = ref.current.localTranscriber) == null ? void 0 : _a.stop();
77005
+ ((_c = (_b = ref.current.localTranscriber) == null ? void 0 : _b.transcripts) == null ? void 0 : _c.length) && createTranscript({
77006
+ recording_id: recording3 == null ? void 0 : recording3.id,
77007
+ transcripts: (_d = ref.current.localTranscriber) == null ? void 0 : _d.transcripts,
77008
+ user_id: userId
77009
+ });
77010
+ }
76928
77011
  }
76929
77012
  });
76930
77013
  return {
@@ -77508,16 +77591,16 @@ function UnwrapWidget({
77508
77591
  } = company;
77509
77592
  const companyIsClosed = reactExports.useMemo(() => {
77510
77593
  if (!isLoadingCompany && (company == null ? void 0 : company.name)) {
77511
- const companyDate = hooks.tz(company.timezone);
77512
- const time2 = hooks(companyDate, "HH:mm");
77594
+ const companyDate = hooks().tz(company.timezone).utc();
77595
+ const time2 = companyDate.clone();
77513
77596
  const day = companyDate.format("dddd");
77514
77597
  const workHours = company.work_hours || defaultWorkHours;
77515
77598
  const workingDay = workHours[day];
77516
77599
  if (workingDay.closed)
77517
77600
  return true;
77518
77601
  for (const [startTimeStr, endTimeStr] of workingDay.times) {
77519
- const startTime = hooks.tz(startTimeStr, "HH:mm", company.timezone);
77520
- const endTime = hooks.tz(endTimeStr, "HH:mm", company.timezone);
77602
+ const startTime = hooks(startTimeStr, "HH:mm").tz(company.timezone).utc();
77603
+ const endTime = hooks(endTimeStr, "HH:mm").tz(company.timezone).utc();
77521
77604
  if (time2.isBetween(startTime, endTime, null, "[]"))
77522
77605
  return false;
77523
77606
  }
@@ -77629,7 +77712,6 @@ const WidgetFormDisplay = reactExports.memo(({
77629
77712
  hex_code
77630
77713
  }) => {
77631
77714
  var _a, _b, _c, _d, _e, _f, _g, _h;
77632
- useSocket();
77633
77715
  const dataRef = reactExports.useRef();
77634
77716
  const videoRef = reactExports.useRef();
77635
77717
  const [{
@@ -77831,7 +77913,6 @@ const WidgetFormDisplay = reactExports.memo(({
77831
77913
  agent,
77832
77914
  videoRef,
77833
77915
  customer,
77834
- calendar: calendar2,
77835
77916
  quickStopChat
77836
77917
  })
77837
77918
  }), /* @__PURE__ */ jsx(Footer, {})]
@@ -77848,7 +77929,6 @@ const ChatMode = reactExports.memo(({
77848
77929
  setChatClose,
77849
77930
  videoRef,
77850
77931
  customer,
77851
- calendar: calendar2,
77852
77932
  quickStopChat
77853
77933
  }) => {
77854
77934
  var _a, _b;