@enspiredigital/xlms-headless 0.0.27 → 0.0.28
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/hooks/useSpeaking.d.ts +1 -1
- package/dist/index.js +21 -19
- package/dist/types/common.d.ts +0 -1
- package/dist/types/common.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -26,7 +26,7 @@ export declare function useSpeaking(question: SpeakingQuestionType, uploadHandle
|
|
|
26
26
|
pauseRecording: () => void;
|
|
27
27
|
resumeRecording: () => void;
|
|
28
28
|
stopRecording: () => void;
|
|
29
|
-
toggleRecording: () => void
|
|
29
|
+
toggleRecording: () => void;
|
|
30
30
|
uploadAudio: () => Promise<void>;
|
|
31
31
|
uploadFile: (file: File) => Promise<void>;
|
|
32
32
|
submit: () => SpeakingSubmitPayload;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useState as A, useRef as
|
|
1
|
+
import { useState as A, useRef as F, useEffect as V, useMemo as T, useCallback as R } from "react";
|
|
2
2
|
import { jsx as W, Fragment as z } from "react/jsx-runtime";
|
|
3
3
|
function E() {
|
|
4
4
|
const [t, n] = A(null), [u, f] = A(null), [b, C] = A(0);
|
|
@@ -86,7 +86,7 @@ function Y(t) {
|
|
|
86
86
|
[]
|
|
87
87
|
), [v, w] = A(
|
|
88
88
|
[]
|
|
89
|
-
), m =
|
|
89
|
+
), m = F([]);
|
|
90
90
|
function p(e, s) {
|
|
91
91
|
d((l) => [
|
|
92
92
|
...l.filter(
|
|
@@ -224,12 +224,12 @@ function K(t) {
|
|
|
224
224
|
let r = 0, e = !0, s = 0;
|
|
225
225
|
const l = t.correct_answers.list, g = new Map(o.map((y) => [y.blankIndex, y.itemId]));
|
|
226
226
|
return Object.entries(l).forEach(([y, U]) => {
|
|
227
|
-
const B = y,
|
|
228
|
-
if (!
|
|
227
|
+
const B = y, O = g.get(B);
|
|
228
|
+
if (!O) {
|
|
229
229
|
e = !1;
|
|
230
230
|
return;
|
|
231
231
|
}
|
|
232
|
-
const M = t.options.answers.find((D) => D.id ===
|
|
232
|
+
const M = t.options.answers.find((D) => D.id === O);
|
|
233
233
|
M && String(M.group_position) === String(U) ? (r++, s += M.point) : e = !1;
|
|
234
234
|
}), {
|
|
235
235
|
isCorrect: e,
|
|
@@ -530,8 +530,8 @@ function et(t) {
|
|
|
530
530
|
return Object.entries(r).forEach(([g, y]) => {
|
|
531
531
|
const U = t.options.items.find((M) => M.id === g), B = U ? U.point : 0;
|
|
532
532
|
s += B;
|
|
533
|
-
const
|
|
534
|
-
|
|
533
|
+
const O = o.find((M) => M.itemId === g);
|
|
534
|
+
O && O.categoryId === y && (a += B, c++);
|
|
535
535
|
}), a = Math.round(a * 100) / 100, s = Math.round(s * 100) / 100, {
|
|
536
536
|
isCorrect: c === e && e > 0,
|
|
537
537
|
score: a,
|
|
@@ -668,23 +668,23 @@ function nt(t, n) {
|
|
|
668
668
|
};
|
|
669
669
|
}
|
|
670
670
|
function st(t, n) {
|
|
671
|
-
const { canAnswer: u, submitted: f, attempts: b, submitQuestion: C, resetQuestion: S } = E(), [o, d] = A(void 0), [h, I] = A("idle"), [v, w] = A(0), [m, p] = A(!1), [x, a] = A(void 0), [c, i] = A(!1), r =
|
|
671
|
+
const { canAnswer: u, submitted: f, attempts: b, submitQuestion: C, resetQuestion: S } = E(), [o, d] = A(void 0), [h, I] = A("idle"), [v, w] = A(0), [m, p] = A(!1), [x, a] = A(void 0), [c, i] = A(!1), r = F(null), e = F([]), s = F(null), l = F(null), g = R(async () => {
|
|
672
672
|
i(!0);
|
|
673
673
|
try {
|
|
674
674
|
const Q = await navigator.mediaDevices.getUserMedia({ audio: !0 });
|
|
675
675
|
l.current = Q;
|
|
676
676
|
const k = new MediaRecorder(Q);
|
|
677
|
-
r.current = k, e.current = [], k.ondataavailable = (
|
|
678
|
-
|
|
677
|
+
r.current = k, e.current = [], k.ondataavailable = (_) => {
|
|
678
|
+
_.data.size > 0 && e.current.push(_.data);
|
|
679
679
|
}, k.onstop = () => {
|
|
680
|
-
const
|
|
680
|
+
const _ = new Blob(e.current, {
|
|
681
681
|
type: "audio/webm"
|
|
682
|
-
}), P = URL.createObjectURL(
|
|
682
|
+
}), P = URL.createObjectURL(_);
|
|
683
683
|
d(P);
|
|
684
684
|
}, k.start(), I("recording"), w(0);
|
|
685
|
-
let
|
|
685
|
+
let L = 0;
|
|
686
686
|
s.current = setInterval(() => {
|
|
687
|
-
|
|
687
|
+
L++, w(L), L >= (t.metadata?.max_recording_time || 300) && B();
|
|
688
688
|
}, 1e3);
|
|
689
689
|
} catch (Q) {
|
|
690
690
|
console.error("Failed to start recording:", Q), a("Failed to access microphone");
|
|
@@ -696,15 +696,17 @@ function st(t, n) {
|
|
|
696
696
|
w((Q) => Q + 1);
|
|
697
697
|
}, 1e3));
|
|
698
698
|
}, [h]), B = R(() => {
|
|
699
|
-
r.current && h !== "idle" && (r.current.stop(), I("stopped"), s.current && clearInterval(s.current), l.current && l.current.getTracks().forEach((Q) => Q.stop())
|
|
700
|
-
}, [h]),
|
|
699
|
+
r.current && h !== "idle" && (r.current.stop(), i(!1), I("stopped"), s.current && clearInterval(s.current), l.current && l.current.getTracks().forEach((Q) => Q.stop()));
|
|
700
|
+
}, [h]), O = R(() => {
|
|
701
|
+
c ? B() : g();
|
|
702
|
+
}, [c]), M = R(async () => {
|
|
701
703
|
if (!(!e.current.length || !n)) {
|
|
702
704
|
p(!0), a(void 0);
|
|
703
705
|
try {
|
|
704
706
|
const Q = new Blob(e.current, {
|
|
705
707
|
type: "audio/webm"
|
|
706
|
-
}), k = `speaking-${Date.now()}.webm`,
|
|
707
|
-
|
|
708
|
+
}), k = `speaking-${Date.now()}.webm`, L = await n(Q, k);
|
|
709
|
+
L.success && L.url ? d(L.url) : a(L.error || "Upload failed");
|
|
708
710
|
} catch (Q) {
|
|
709
711
|
console.error("Upload failed:", Q), a(Q instanceof Error ? Q.message : "Upload failed");
|
|
710
712
|
} finally {
|
|
@@ -754,7 +756,7 @@ function st(t, n) {
|
|
|
754
756
|
pauseRecording: y,
|
|
755
757
|
resumeRecording: U,
|
|
756
758
|
stopRecording: B,
|
|
757
|
-
toggleRecording:
|
|
759
|
+
toggleRecording: O,
|
|
758
760
|
uploadAudio: M,
|
|
759
761
|
uploadFile: D,
|
|
760
762
|
submit: $,
|
package/dist/types/common.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/types/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,MAAM,WAAW,KAAK;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,YAAY;IAC3B,
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/types/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,MAAM,WAAW,KAAK;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE;QACP,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,KAAK,CAAC;QACd,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;KAClB,CAAC;IACF,eAAe,EACX;QACE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;KACxB,GACD;QAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,CAAC;IACrC,QAAQ,EAAE;QACR,YAAY,EAAE,MAAM,CAAC;QACrB,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;CACH;AAED,MAAM,WAAW,cAAc,CAAC,IAAI,EAAE,GAAG;IACvC,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,QAAQ,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,SAAS,CAAC;CACnC"}
|