فهرست منبع

音频消息发送调试

zhangjie 4 سال پیش
والد
کامیت
77952d917e

+ 0 - 4
src/api/invigilation.js

@@ -228,10 +228,6 @@ export function sendWarningMsg(datas) {
   const data = pickBy(datas, paramFilter);
   return httpApp.post("/api/admin/invigilate/notice", data);
 }
-// TODO:接口待定
-export function sendAudioWarningMsg(datas) {
-  return httpApp.post("/api/admin/invigilate/notice", datas);
-}
 
 // reexam-apply
 export function reexamApplyList(datas) {

+ 29 - 6
src/features/invigilation/RealtimeMonitoring/audioRecord/AudioRecordDialog.vue

@@ -59,7 +59,9 @@
 </template>
 
 <script>
-import { sendAudioWarningMsg } from "@/api/invigilation";
+import MD5 from "js-md5";
+import { uploadFile } from "@/api/system-info";
+import { sendWarningMsg } from "@/api/invigilation";
 import AudioRecord from "./audioRecord";
 
 function recordTimeToText(timeNumber) {
@@ -204,11 +206,32 @@ export default {
       if (this.isSubmit) return;
       this.isSubmit = true;
 
-      const fdata = new FormData();
-      fdata.append("content", this.audioBlob);
-      fdata.append("type", "audio");
-      fdata.append("examRecordId", this.recordId);
-      const result = await sendAudioWarningMsg(fdata).catch(() => {});
+      async function blobToArray(blob) {
+        return new Promise((resolve) => {
+          var reader = new FileReader();
+          reader.addEventListener("loadend", function () {
+            resolve(reader.result);
+          });
+          reader.readAsArrayBuffer(blob);
+        });
+      }
+      const ab = await blobToArray(this.audioBlob);
+      const md5 = MD5(ab);
+      const res = await uploadFile({
+        file: this.audioBlob,
+        md5,
+      }).catch(() => {});
+
+      if (!res) {
+        this.isSubmit = false;
+        return;
+      }
+
+      const result = await sendWarningMsg({
+        content: res.data.data.url,
+        type: "audio",
+        examRecordId: this.recordId,
+      }).catch(() => {});
 
       this.isSubmit = false;
       if (!result) return;

+ 6 - 1
src/features/invigilation/RealtimeMonitoring/audioRecord/audioRecord.js

@@ -113,7 +113,12 @@ class AudioRecord {
         audioDataView.setInt16(offset, s < 0 ? s * 0x8000 : s * 0x7fff, true);
       }
     }
-    return new Blob([audioDataView], { type: "audio/mp3" });
+    return new File(
+      [audioDataView],
+      Math.random().toString().slice(-8) + ".mp3",
+      { type: "audio/mpeg3" }
+    );
+    // return new Blob([audioDataView], { type: "audio/mpeg3" });
   }
 
   mediaError(error) {