|
@@ -9,9 +9,7 @@ import FaceTracking from "./FaceTracking.vue";
|
|
// import FaceId from "./FaceId.vue";
|
|
// import FaceId from "./FaceId.vue";
|
|
// import FaceMotion from "./FaceMotion/FaceMotion";
|
|
// import FaceMotion from "./FaceMotion/FaceMotion";
|
|
import FaceRecognition from "../FaceRecognition.vue";
|
|
import FaceRecognition from "../FaceRecognition.vue";
|
|
-// import { openWS, closeWsWithoutReconnect } from "./ws.js";
|
|
+import { STRICT_CHECK_HOSTS, WEBSOCKET_FOR_AUDIO } from "@/constants/constants";
|
|
-
|
|
|
|
-import { STRICT_CHECK_HOSTS } from "@/constants/constants";
|
|
|
|
import { httpApp } from "@/plugins/axiosApp";
|
|
import { httpApp } from "@/plugins/axiosApp";
|
|
import { useTimers } from "@/setups/useTimers";
|
|
import { useTimers } from "@/setups/useTimers";
|
|
import { checkMainExe } from "@/utils/nativeMethods";
|
|
import { checkMainExe } from "@/utils/nativeMethods";
|
|
@@ -22,6 +20,9 @@ import { store } from "@/store/store";
|
|
import { useRemoteAppChecker } from "@/features/UserLogin/useRemoteAppChecker";
|
|
import { useRemoteAppChecker } from "@/features/UserLogin/useRemoteAppChecker";
|
|
import { ExamQuestion, PaperStruct, Store } from "@/types/student-client";
|
|
import { ExamQuestion, PaperStruct, Store } from "@/types/student-client";
|
|
import router from "@/router";
|
|
import router from "@/router";
|
|
|
|
+import { useWebSocket } from "@/setups/useWebSocket";
|
|
|
|
+
|
|
|
|
+const { startWS } = useWebSocket();
|
|
|
|
|
|
type PRACTICE_TYPE = "IN_PRACTICE" | "NO_ANSWER";
|
|
type PRACTICE_TYPE = "IN_PRACTICE" | "NO_ANSWER";
|
|
|
|
|
|
@@ -518,13 +519,73 @@ async function initData() {
|
|
// console.log(examQuestionList);
|
|
// console.log(examQuestionList);
|
|
// console.log(examQuestionList.find(v => v.answerType === "SINGLE_AUDIO"));
|
|
// console.log(examQuestionList.find(v => v.answerType === "SINGLE_AUDIO"));
|
|
|
|
|
|
- // const shouldOpenWS = exam.WEIXIN_ANSWER_ENABLED;
|
|
+ function onAudioAnswer(event: MessageEvent<string>) {
|
|
-
|
|
+ let res: {
|
|
- // if (shouldOpenWS) {
|
|
+ eventType: string;
|
|
- // // console.log("have single");
|
|
+ isSuccess: boolean;
|
|
- // const examRecordDataId = examRecordDataId;
|
|
+ errorMessage: string;
|
|
- // openWS({ examRecordDataId });
|
|
+ data: { order: number; fileUrl: string; transferFileType: string };
|
|
- // }
|
|
+ };
|
|
|
|
+ try {
|
|
|
|
+ res = JSON.parse(event.data).content;
|
|
|
|
+ } catch (error) {
|
|
|
|
+ logger({ cnl: ["server"], act: "JSON.parse出错", possibleError: error });
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if (!res) {
|
|
|
|
+ logger({
|
|
|
|
+ cnl: ["server"],
|
|
|
|
+ act: "onAudioAnswer",
|
|
|
|
+ dtl: "ws message format error",
|
|
|
|
+ ext: { event: JSON.stringify(event) },
|
|
|
|
+ });
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if (res.eventType && res.eventType !== "HEARTBEAT" && !res.isSuccess) {
|
|
|
|
+ $message.error(res.errorMessage, { duration: 10, closable: true });
|
|
|
|
+ logger({
|
|
|
|
+ cnl: ["server"],
|
|
|
|
+ act: "onAudioAnswer",
|
|
|
|
+ dtl: "error from server",
|
|
|
|
+ stk: res.errorMessage,
|
|
|
|
+ });
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ switch (res.eventType) {
|
|
|
|
+ case "HEARTBEAT":
|
|
|
|
+ logger({
|
|
|
|
+ cnl: ["server"],
|
|
|
|
+ lvl: "debug",
|
|
|
|
+ act: "ws heartbeat response from server",
|
|
|
|
+ });
|
|
|
|
+ break;
|
|
|
|
+ case "SCAN_QR_CODE":
|
|
|
|
+ logger({ cnl: ["server"], act: "二维码被扫描" });
|
|
|
|
+ store.setQuestionQrCodeScanned({ order: res.data.order });
|
|
|
|
+ break;
|
|
|
|
+ case "GET_FILE_ANSWER":
|
|
|
|
+ console.log("get file url", res);
|
|
|
|
+ logger({ cnl: ["server"], act: "获得音频地址" });
|
|
|
|
+ store.setQuestionFileAnswerUrl(res.data);
|
|
|
|
+ break;
|
|
|
|
+ case "SYSTEM_ERROR":
|
|
|
|
+ console.log("ws get error", res);
|
|
|
|
+ logger({
|
|
|
|
+ cnl: ["server"],
|
|
|
|
+ act: "ws get error",
|
|
|
|
+ ejn: JSON.stringify(res),
|
|
|
|
+ });
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (exam.WEIXIN_ANSWER_ENABLED) {
|
|
|
|
+ // init data
|
|
|
|
+ store.exam.questionAnswerFileUrl = [];
|
|
|
|
+ startWS(
|
|
|
|
+ WEBSOCKET_FOR_AUDIO + `?key=${store.user.key}&token=${store.user.token}`,
|
|
|
|
+ onAudioAnswer
|
|
|
|
+ );
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
// async function updateQuestion(next) {
|
|
// async function updateQuestion(next) {
|