From 55f2bf0f7335db14f5a84eb47c4ad84d4bde670a Mon Sep 17 00:00:00 2001
From: shuishen <1109946754@qq.com>
Date: Mon, 01 Feb 2021 13:53:24 +0800
Subject: [PATCH] 一键通话相关修改

---
 src/views/realTimePolice/real.vue |  104 ++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 80 insertions(+), 24 deletions(-)

diff --git a/src/views/realTimePolice/real.vue b/src/views/realTimePolice/real.vue
index 944fcc7..e9066a9 100644
--- a/src/views/realTimePolice/real.vue
+++ b/src/views/realTimePolice/real.vue
@@ -481,7 +481,8 @@
         ]
       },
       data: [],
-      isActive: false
+      isActive: false,
+      recorder: null
     };
   },
   computed: {
@@ -504,6 +505,13 @@
   },
   created() {
     this.dateTime = this.getDate();
+
+    this.recorder = new Recorder({
+      sampleBits: 16, // 采样位数,支持 8 或 16,默认是16
+      sampleRate: 16000, // 采样率,支持 11025、16000、22050、24000、44100、48000,根据浏览器默认值,我的chrome是48000
+      numChannels: 1 // 声道,支持 1 或 2, 默认是1
+      // compiling: false,(0.x版本中生效,1.x增加中)  // 是否边录边转换,默认是false
+    });
   },
   methods: {
     rowSave(row, done, loading) {
@@ -900,7 +908,7 @@
     queryOldVideo(data) {
       console.log(data);
       var newAxios = axios.create({
-        baseURL: "http://s16s652780.51mypc.cn",
+        baseURL: "https://s16s652780.51mypc.cn",
         withCredentials: false,
         headers: {
           "Content-type": "application/x-www-form-urlencoded"
@@ -991,41 +999,89 @@
       }
     },
     aKeyToCall(e, form) {
+      var newAxios = axios.create({
+        baseURL: "https://s16s652780.51mypc.cn",
+        withCredentials: false,
+        headers: {
+          "Content-Type": "application/json;"
+        }
+      });
+
       // 一键呼叫相关函数
       if (this.isActive == true) {
         this.isActive = false;
+
+        newAxios
+          .post(
+            `/api_control`,
+            {},
+            {
+              params: {
+                param: { PktType: "GetAccessToken" }
+              }
+            }
+          )
+          .then(result => {
+            console.log(result, 11111111);
+            var formData = new FormData();
+            var blob = this.recorder.getPCMBlob() //获取wav格式音频数据
+            //此处获取到blob对象后需要设置fileName满足当前项目上传需求,其它项目可直接传把blob作为file塞入formData
+            var newbolb = new Blob([blob], { type: "audio/pcm" });
+            var fileOfBlob = new File([newbolb], new Date().getTime() + ".pcm");
+            formData.append("file", fileOfBlob);
+
+            console.log(blob, newbolb, fileOfBlob, 99999);
+
+            newAxios
+              .post(`/api_control`, formData, {
+                params: {
+                  param: {
+                    PktType: "Talk",
+                    accessToken: result.data.data.accessToken,
+                    deviceCode: form.channelNumber
+                  }
+                }
+              })
+              .then(result => {
+                console.log(result);
+              });
+          });
       } else {
         this.isActive = true;
 
-        let recorder = new Recorder({
-          sampleBits: 16, // 采样位数,支持 8 或 16,默认是16
-          sampleRate: 16000, // 采样率,支持 11025、16000、22050、24000、44100、48000,根据浏览器默认值,我的chrome是48000
-          numChannels: 1 // 声道,支持 1 或 2, 默认是1
-          // compiling: false,(0.x版本中生效,1.x增加中)  // 是否边录边转换,默认是false
-        });
+        Recorder.getPermission().then(
+          () => {
+            console.log("给权限了");
+
+            this.recorder.start().then(
+              () => {
+                // 开始录音
+                console.log("开始录音了");
+              },
+              error => {
+                // 出错了
+                console.log(`${error.name} : ${error.message}`);
+              }
+            );
+          },
+          error => {
+            console.log(`${error.name} : ${error.message}`);
+          }
+        );
 
         var newAxios = axios.create({
-          baseURL: "http://s16s652780.51mypc.cn",
+          baseURL: "https://s16s652780.51mypc.cn",
           withCredentials: false,
           headers: {
-            "Content-type": "application/x-www-form-urlencoded"
+            "Content-Type": "application/json;"
           }
         });
 
-
-        //    newAxios
-        //       .post(
-        //         `/talk?deviceCode=${form.channelNumber}`,
-        //         '12345',
-        //       )
-        //       .then(result => {
-
-        //           console.log(result)
-
-        //       });
-
-
-
+        newAxios
+          .post(`/talk?deviceCode=${form.channelNumber}`, "12345")
+          .then(result => {
+            console.log(result);
+          });
       }
     }
   }

--
Gitblit v1.9.3