南昌市物联网技防平台-前端
shuishen
2021-02-01 55f2bf0f7335db14f5a84eb47c4ad84d4bde670a
一键通话相关修改
1 files modified
104 ■■■■ changed files
src/views/realTimePolice/real.vue 104 ●●●● patch | view | raw | blame | history
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);
          });
      }
    }
  }