ソースを参照

评测流程修改

liushengqiang 1 年間 前
コミット
b4b676579d
3 ファイル変更40 行追加21 行削除
  1. 8 0
      src/helpers/communication.ts
  2. 30 20
      src/view/evaluating/index.tsx
  3. 2 1
      vite.config.ts

+ 8 - 0
src/helpers/communication.ts

@@ -69,6 +69,14 @@ export const api_proxyServiceMessage = (content: any): Promise<IPostMessage | un
 	if (!storeData.isApp) return Promise.resolve({} as any);
 	return promisefiyPostMessage({ api: "proxyServiceMessage", content });
 };
+/** 监听app真正开始录音 */
+export const api_recordStartTime = (callback: CallBack) => {
+	listenerMessage("sendResult", callback);
+}
+/** 卸载监听app真正开始录音 */
+export const api_remove_recordStartTime = (callback: CallBack) => {
+	removeListenerMessage("sendResult", callback);
+}
 
 /** 上传评测 音 视频 */
 export const api_videoUpdate = () => {

+ 30 - 20
src/view/evaluating/index.tsx

@@ -15,10 +15,15 @@ import {
 	api_openWebView,
 	api_startRecording,
 	api_stopRecording,
+	api_recordStartTime,
+	api_remove_recordStartTime,
 } from "/src/helpers/communication";
 import state, { clearSelection, handleStopPlay, resetPlaybackToStart, togglePlay } from "/src/state";
 import { IPostMessage } from "/src/utils/native-message";
 import { usePageVisibility } from "@vant/use";
+import { browser } from "/src/utils";
+
+const browserInfo = browser();
 export const evaluatingData = reactive({
 	/** 评测数据 */
 	contentData: {} as any,
@@ -59,26 +64,20 @@ export const handleStartEvaluat = () => {
 };
 
 /** 开始播放发送延迟时间 */
-export const sendEvaluatingOffsetTime = (currentTime: number) => {
+export const sendEvaluatingOffsetTime = async (currentTime: number) => {
 	const nowTime = Date.now();
-	// console.log("第一次播放时间", evaluatingData.backtime);
-	// console.log("已播放时长: ", currentTime,  currentTime * 1000);
-	// console.log("不减掉已播放时间: ", nowTime - evaluatingData.backtime , currentTime);
-	const delayTime = (nowTime - evaluatingData.backtime - currentTime * 1000) / 1000;
-	console.log("真正播放延迟", delayTime / 1000);
-	// 蓝牙耳机延迟一点发送消息确保在录音后面
-	setTimeout(async () => {
-		await api_proxyServiceMessage({
-			header: {
-				commond: "audioPlayStart",
-				type: "SOUND_COMPARE",
-			},
-			body: {
-				offsetTime: delayTime < 0 ? 0 : delayTime,
-			},
-		});
-		evaluatingData.backtime = 0;
-	}, 220);
+	const delayTime = nowTime - evaluatingData.backtime - currentTime * 1000;
+	console.log("真正播放延迟", delayTime);
+	await api_proxyServiceMessage({
+		header: {
+			commond: "audioPlayStart",
+			type: "SOUND_COMPARE",
+		},
+		body: {
+			offsetTime: delayTime < 0 ? 0 : delayTime,
+		},
+	});
+	evaluatingData.backtime = 0;
 };
 
 /** 检测耳机 */
@@ -181,7 +180,7 @@ export const handleStartBegin = async () => {
 	evaluatingData.startBegin = true;
 	evaluatingData.evaluatings = {};
 	evaluatingData.resultData = {};
-	evaluatingData.backtime = Date.now();
+	evaluatingData.backtime = 0;
 	resetPlaybackToStart();
 	try {
 		console.log("🚀 ~ content:", evaluatingData.contentData, JSON.stringify(evaluatingData.contentData));
@@ -194,6 +193,15 @@ export const handleStartBegin = async () => {
 	}
 	// 开始录音
 	api_startRecording();
+};
+
+/** 录音开始,开始播放音频 */
+const recordedPlayMusic = async (res?: IPostMessage) => {
+	let inteveral = res?.content?.inteveral || 0;
+	if (browserInfo.ios) {
+		inteveral *= 1000;
+	}
+	evaluatingData.backtime = inteveral || Date.now();
 	const playState = await togglePlay("play");
 	// 取消播放
 	if (!playState) {
@@ -299,12 +307,14 @@ export default defineComponent({
 			evaluatingData.checkStep = 0;
 			evaluatingData.rendered = true;
 			sendResult(handleScoreResult);
+			api_recordStartTime(recordedPlayMusic);
 			if (!state.isSelectMeasureMode) {
 				clearSelection();
 			}
 		});
 		onUnmounted(() => {
 			removeResult(handleScoreResult);
+			api_remove_recordStartTime(recordedPlayMusic);
 		});
 		return () => <div></div>;
 	},

+ 2 - 1
vite.config.ts

@@ -58,7 +58,8 @@ export default defineConfig({
 				rewrite: (path) => path.replace(/^\/gym/, ""),
 			},
 			"^/colexiu/.*": {
-				target: "https://online.colexiu.com",
+				target: "https://dev.colexiu.com",
+				// target: "https://online.colexiu.com",
 				changeOrigin: true,
 				rewrite: (path) => path.replace(/^\/colexiu/, ""),
 			},