react_hsbc_teller 2.0.25 → 2.0.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,6 +4,17 @@
4
4
  http://jedwatson.github.io/classnames
5
5
  */
6
6
 
7
+ /*!
8
+ *
9
+ * js-audio-recorder - js audio recorder plugin
10
+ *
11
+ * @version v0.5.7
12
+ * @homepage https://github.com/2fps/recorder
13
+ * @author 2fps <echoweb@126.com> (https://www.zhuyuntao.cn)
14
+ * @license MIT
15
+ *
16
+ */
17
+
7
18
  /*!
8
19
  * Determine if an object is a Buffer
9
20
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react_hsbc_teller",
3
- "version": "2.0.25",
3
+ "version": "2.0.26",
4
4
  "description": "React",
5
5
  "private": false,
6
6
  "main": "lib/hsbc.js",
@@ -89,6 +89,7 @@
89
89
  "axios": "0.19.0",
90
90
  "crypto-js": "^4.1.1",
91
91
  "html2canvas": "^1.4.0",
92
+ "js-audio-recorder": "^0.5.7",
92
93
  "qrcode.react": "^3.1.0",
93
94
  "react": "^17.0.1",
94
95
  "react-canvas-draw": "^1.1.1",
@@ -33,7 +33,7 @@ roomId
33
33
  // resourcePath: 'https://counter-web.leimondata.cn:7199',
34
34
  // resourcePath:'http://121.196.19.70:8027/',
35
35
  roomServerUrl: 'wss://app.uat.dsp.hsbcfts.com.cn/mpaas/mrtc/ws',
36
- baseURL:'https://zuul.uat.dsp.hsbcfts.com.cn/wealth/zuul/api/leimon-counter-api',
36
+ baseURL:'https://zuul.uat.dsp.hsbcfts.com.cn/wealth/zuulsit/api/leimon-counter-api',
37
37
  resourcePath:'https://zuul.uat.dsp.hsbcfts.com.cn/wealth/js/',
38
38
  prohibitPrompt: '无客户',
39
39
  titleBackground: '#40a9ff',
@@ -7,7 +7,7 @@ import API from '../../api/api';
7
7
  import { BoardOperate } from '../../common/index.esm.js';
8
8
  import './video.less'
9
9
  import { compressImage, isLight } from '../../utils/utils'
10
- import Recorder from "../../utils/recorder";
10
+ import Recorder from "js-audio-recorder";
11
11
  import MyAsrController from '../../utils/asrController'
12
12
  import Header from '../header/header.jsx'
13
13
  import Foot from '../foot/foot.jsx'
@@ -58,7 +58,7 @@ import MultiModule from '../multiModule/multiModule'//签字、抄录
58
58
  import axios from 'axios';
59
59
  import CryptoJS from "crypto-js";
60
60
 
61
- const SDK_VERISON = '2.0.25'
61
+ const SDK_VERISON = '2.0.26'
62
62
  const IDtypeFront = '请客户在其设备后置摄像头下展示证件正面(如:身份证照片页面)'
63
63
  const IDtypeBack = '请在后置摄像头下展示证件反面(如:身份证国徽页)'
64
64
  const { Option } = Select;
@@ -93,6 +93,7 @@ let muteJson = new Map()
93
93
  // let dateTime = 0
94
94
  let messageValue = ''
95
95
  let messageValueMap = new Map()
96
+ let videoMessageMap = new Map() // 画中画消息数据
96
97
  let third_id_Map = new Map()
97
98
  // let beautyType = false
98
99
  // let beautyNum = 0 // 0-关闭 1--弱 2--中 5---高
@@ -590,6 +591,8 @@ class Video extends Component {
590
591
  this.test_controller.InitRoomConfig(config_param)
591
592
  this.saveLog('mrtc InitRoomConfig start')
592
593
  // 预热摄像头
594
+ config_param.videoSource = this.state.cameraValue
595
+ config_param.audioSource = this.state.microphoneValue
593
596
  this.test_controller.PreOpenLocalMedia(config_param)
594
597
  };
595
598
  rateAll = async () => {
@@ -1002,13 +1005,17 @@ class Video extends Component {
1002
1005
  this.messageClick('当前暂无客户', 'error')
1003
1006
  }
1004
1007
  }
1005
- messageClick = (value, tipType) => {
1008
+ messageClick = (value, tipType, userId) => {
1006
1009
  console.log('messageClick', value, tipType)
1010
+
1011
+ if (userId) {
1012
+ // 画中画实时消息
1013
+ this.addPictureMessage(value, userId)
1014
+ }
1007
1015
  const intervalSec = 5 // 相同提示触发间隔
1008
1016
  const durationSec = 4.5 // 提示持续时间
1009
1017
  if (messageValueMap.get(value) == undefined) {
1010
1018
  // map中没有相同消息
1011
- messageValue = value
1012
1019
  messageValueMap.set(value, setTimeout(() => {
1013
1020
  messageValueMap.delete(value)
1014
1021
  }, intervalSec * 1000))
@@ -1030,12 +1037,45 @@ class Video extends Component {
1030
1037
  duration: durationSec
1031
1038
  })
1032
1039
  }
1033
- clearTimeout(this.messageClearTimer)
1034
- this.messageClearTimer = setTimeout(() => {
1035
- messageValue = ''
1036
- }, durationSec * 1000);
1040
+ if (!userId) {
1041
+ // 坐席消息
1042
+ messageValue = value
1043
+
1044
+ clearTimeout(this.messageClearTimer)
1045
+ this.messageClearTimer = setTimeout(() => {
1046
+ messageValue = ''
1047
+ }, durationSec * 1000);
1048
+ }
1037
1049
  }
1050
+ }
1051
+ // 画中画内消息
1052
+ addPictureMessage = (value, userId) => {
1053
+ console.log('addPictureMessage', value, userId)
1054
+
1055
+ const intervalSec = 5 // 相同提示触发间隔
1056
+ const durationSec = 4.5 // 提示持续时间
1057
+ let mapItem = videoMessageMap.get(userId)
1058
+ if (!mapItem) {
1059
+ mapItem = {
1060
+ messageValue: value,
1061
+ clearTimer: null,
1062
+ valueMap: new Map()
1063
+ }
1064
+ }
1065
+ const valueMap = mapItem.valueMap
1066
+ if (valueMap.get(value) == undefined) {
1067
+ // map中没有相同消息
1068
+ valueMap.set(value, setTimeout(() => {
1069
+ valueMap.delete(value)
1070
+ }, intervalSec * 1000))
1038
1071
 
1072
+ mapItem.messageValue = value
1073
+ clearTimeout(mapItem.clearTimer)
1074
+ mapItem.clearTimer = setTimeout(() => {
1075
+ mapItem.messageValue = ''
1076
+ }, durationSec * 1000)
1077
+ videoMessageMap.set(userId, mapItem)
1078
+ }
1039
1079
  }
1040
1080
  // 人脸识别
1041
1081
  facialRecognition = () => {
@@ -1201,7 +1241,8 @@ class Video extends Component {
1201
1241
  name: 'video' + sortedlist[i-1].idIndex,
1202
1242
  title: sortedlist[i-1].videoName,
1203
1243
  mute: sortedlist[i-1].mute,
1204
- noVideo: sortedlist[i-1].noVideo
1244
+ noVideo: sortedlist[i-1].noVideo,
1245
+ userId: sortedlist[i-1].userId,
1205
1246
  })
1206
1247
  }
1207
1248
  }
@@ -1243,6 +1284,10 @@ class Video extends Component {
1243
1284
  cobj.clearRect(0, 0, 640, 360 * this.state.listVideoPicture.length + baseStartHeight);
1244
1285
  canvas.width = 640;
1245
1286
  canvas.height = 360 * this.state.listVideoPicture.length + baseStartHeight;
1287
+ if (this.state.listVideoPicture.length == 0) {
1288
+ // 画中画设置最小高度,避免没有人时 宽度被拉得很大
1289
+ canvas.height = 360 + baseStartHeight
1290
+ }
1246
1291
  for (let i = 0; i < this.state.listVideoPicture.length; i++) {
1247
1292
 
1248
1293
  let videoId = this.state.listVideoPicture[i].name;
@@ -1378,6 +1423,23 @@ class Video extends Component {
1378
1423
 
1379
1424
  }
1380
1425
 
1426
+ // 绘制消息
1427
+ if (videoMessageMap.get(this.state.listVideoPicture[i].userId)) {
1428
+ let str = videoMessageMap.get(this.state.listVideoPicture[i].userId).messageValue
1429
+ if (str) {
1430
+ cobj.fillStyle = '#F8F2F3';
1431
+ cobj.font = "normal lighter 30px sans-serif";
1432
+ // const textWidth = Math.min(cobj.measureText(str).width, 610)
1433
+ const startY = 360 * i + baseStartHeight
1434
+ cobj.fillRect(0, startY, 640, messageBoxHeight)
1435
+ cobj.textAlign = 'center';
1436
+ cobj.strokeStyle = 'black';
1437
+ cobj.lineWidth = 2
1438
+ cobj.strokeText(str, 320, startY + messageBoxHeight - 15);
1439
+ cobj.stroke();
1440
+ }
1441
+ }
1442
+
1381
1443
  }
1382
1444
  cobj.fillStyle = '#333333';
1383
1445
  cobj.fillRect(0, 0, 640, baseStartHeight)
@@ -1570,7 +1632,7 @@ class Video extends Component {
1570
1632
  }, ()=>{
1571
1633
  this.pictureInPicture('Refresh')
1572
1634
  })
1573
- this.messageClick('客户切换其他软件', 'error')
1635
+ this.messageClick('客户切换其他软件', 'error', Mival.data.userId)
1574
1636
  }
1575
1637
  }
1576
1638
  else if (Mival.typeId == 3003) { // app进入前台
@@ -1592,7 +1654,7 @@ class Video extends Component {
1592
1654
  if (Mival.data && Mival.data.userId) {
1593
1655
  TITLE = this.getUserTitle(Mival.data.userId)
1594
1656
  }
1595
- this.messageClick(TITLE+'人脸已离框', 'error')
1657
+ this.messageClick(TITLE+'人脸已离框', 'error', Mival.data.userId)
1596
1658
  // this.saveVideoPoint('ffd', '客户人脸离框');
1597
1659
  }
1598
1660
  else if (Mival.typeId == 5002) { // 客户端背光
@@ -1600,7 +1662,7 @@ class Video extends Component {
1600
1662
  if (Mival.data && Mival.data.userId) {
1601
1663
  TITLE = this.getUserTitle(Mival.data.userId)
1602
1664
  }
1603
- this.messageClick(TITLE+'背光、曝光过度', 'error')
1665
+ this.messageClick(TITLE+'背光、曝光过度', 'error', Mival.data.userId)
1604
1666
  // this.saveVideoPoint('env', '客户端背光、曝光过度');
1605
1667
  }
1606
1668
  else if (Mival.typeId == 5003) { // 客户端弱网
@@ -1608,11 +1670,11 @@ class Video extends Component {
1608
1670
  if (Mival.data && Mival.data.userId) {
1609
1671
  TITLE = this.getUserTitle(Mival.data.userId)
1610
1672
  }
1611
- this.messageClick(TITLE+'当前网络较弱', 'error')
1673
+ this.messageClick(TITLE+'当前网络较弱', 'error', Mival.data.userId)
1612
1674
  // this.saveVideoPoint('wnd', '客户端弱网');
1613
1675
  }
1614
1676
  else if (Mival.typeId == 5004) { // ipad低电量
1615
- this.messageClick('IPAD电量过低', 'error')
1677
+ this.messageClick('IPAD电量过低', 'error', Mival.data.userId)
1616
1678
 
1617
1679
  this.setState({
1618
1680
  ipadLowPowerErrorModalVisible: true,
@@ -1628,6 +1690,13 @@ class Video extends Component {
1628
1690
  }
1629
1691
  setTimeout(this.ipadLowPowerPlay, 0);
1630
1692
  }
1693
+ else if (Mival.typeId == 5005) { // 客户端人脸数量变化
1694
+ let TITLE = '客户'
1695
+ if (Mival.data && Mival.data.userId) {
1696
+ TITLE = this.getUserTitle(Mival.data.userId)
1697
+ }
1698
+ this.messageClick(TITLE+'人脸数量发生变化', 'error', Mival.data.userId)
1699
+ }
1631
1700
  else if (Mival.typeId == 1220) {
1632
1701
  // 一炒多的图片 1214
1633
1702
  if (Mival.sessionId == this.state.sessionId) {
@@ -1912,7 +1981,7 @@ class Video extends Component {
1912
1981
  img.onload = () => {
1913
1982
  const origin = cv.imread(img)
1914
1983
  // let start = new Date().getTime()
1915
- const res = isLight(origin)
1984
+ const res = isLight(origin, this.props.lightSensitivity)
1916
1985
  if (res==1 || res== -1){
1917
1986
  // 背景曝光过度
1918
1987
  this.messageClick('检测到当前背光、曝光过度', 'error')
@@ -1937,7 +2006,7 @@ class Video extends Component {
1937
2006
  img.onload = () => {
1938
2007
  const origin = cv.imread(img)
1939
2008
  // let start = new Date().getTime()
1940
- const res = isLight(origin)
2009
+ const res = isLight(origin, this.props.lightSensitivity)
1941
2010
  if (res==1 || res==-1){
1942
2011
  // 背景曝光过度
1943
2012
  this.state.envInfo.lightResult = '不合格'
@@ -2708,6 +2777,7 @@ class Video extends Component {
2708
2777
 
2709
2778
  }
2710
2779
  if (sid == document.getElementById('publish_streamId1').name || !document.getElementById('publish_streamId1').name) {
2780
+ console.log('OnUnPublishSucc clearStreamRemain!!!')
2711
2781
  clearStreamRemain()
2712
2782
  }
2713
2783
  };
@@ -3499,7 +3569,7 @@ class Video extends Component {
3499
3569
  componentWillUnmount() {
3500
3570
  this.saveLog('Exit meeting')
3501
3571
  if (this.test_controller && this.state.sessionType) {
3502
- clearStreamRemain()
3572
+ // clearStreamRemain() // 谨慎使用,有页面crash问题
3503
3573
  this.test_controller.LeaveRoom()
3504
3574
  this.test_controller.Disconnect()
3505
3575
  try {
@@ -7050,6 +7120,7 @@ Video.defaultProps = {
7050
7120
  whetherNeedAsr: false, // 是否在双录时开启违禁词检测
7051
7121
  faceDetectInterval: 6, // 人脸检测间隔(秒)
7052
7122
  lightDetectInterval: 6, // 背光检测间隔(秒)
7123
+ lightSensitivity: 1, // 光线敏感度系数,默认1
7053
7124
  userSide: 2,
7054
7125
  meetingDuration: null, // 会议时长,单位小时
7055
7126
  recordMode: 1, // 录制模式 1远程录制 2网点录制
@@ -2,7 +2,6 @@
2
2
  // import Recorder from "js-audio-recorder";
3
3
  // import Recorder from "./recorder";
4
4
 
5
- import header from "../pages/header/header";
6
5
 
7
6
  // console.log(Recorder)
8
7
  //生成32位随机数UUID
@@ -213,7 +212,7 @@ export default class MyAsrController {
213
212
  getPCMAndSend() {
214
213
  //获取音频信息
215
214
  let NextData = this.recorderInstance.getNextData();
216
- let blob = new Blob([NextData])
215
+ let blob = new Blob(NextData)
217
216
  let blob_size = blob.size;
218
217
  // console.log("获取音频信息,并发送,blob_size:"+blob_size , blob);
219
218
 
@@ -49,7 +49,7 @@ function debounce(fn, delay = 500) {
49
49
  },delay)
50
50
  }
51
51
  }
52
- function isLight(src) {
52
+ function isLight(src, sensitivity = 1) {
53
53
  let gray = new cv.Mat()
54
54
  cv.cvtColor(src, gray, cv.COLOR_BGR2GRAY)
55
55
  let sum = 0;
@@ -84,8 +84,16 @@ function isLight(src) {
84
84
  gray.delete();
85
85
 
86
86
  console.log('亮度值:', cast)
87
+ if (typeof sensitivity == 'number') {
88
+ console.log('灵敏系数:', sensitivity)
89
+ console.log('计算值(<1正常):', cast * sensitivity)
90
+ } else {
91
+ console.error('sensitivity param should be type of number')
92
+ sensitivity = 1
93
+ }
94
+
87
95
  //std::cout << "亮度异常值:" << cast << std::endl;
88
- if (cast > 1)
96
+ if (cast * sensitivity > 1)
89
97
  {
90
98
  if (avg > 0)
91
99
  {
@@ -1,289 +0,0 @@
1
- /*!
2
- *
3
- * js-audio-recorder - js audio recorder plugin
4
- *
5
- * @version v0.5.7
6
- * @homepage https://github.com/2fps/recorder
7
- * @author 2fps <echoweb@126.com> (https://www.zhuyuntao.cn)
8
- * @license MIT
9
- *
10
- */
11
- !function (t, e) {
12
- "object" == typeof exports && "object" == typeof module ? module.exports = e() : "function" == typeof define && define.amd ? define([], e) : "object" == typeof exports ? exports.Recorder = e() : t.Recorder = e()
13
- }(this, function () {
14
- return function (t) {
15
- var e = {};
16
-
17
- function i(n) {
18
- if (e[n]) return e[n].exports;
19
- var r = e[n] = {
20
- i: n,
21
- l: !1,
22
- exports: {}
23
- };
24
- return t[n].call(r.exports, r, r.exports, i), r.l = !0, r.exports
25
- }
26
-
27
- return i.m = t, i.c = e, i.d = function (t, e, n) {
28
- i.o(t, e) || Object.defineProperty(t, e, {
29
- enumerable: !0,
30
- get: n
31
- })
32
- }, i.r = function (t) {
33
- "undefined" != typeof Symbol && Symbol.toStringTag && Object.defineProperty(t, Symbol.toStringTag, {
34
- value: "Module"
35
- }), Object.defineProperty(t, "__esModule", {
36
- value: !0
37
- })
38
- }, i.t = function (t, e) {
39
- if (1 & e && (t = i(t)), 8 & e) return t;
40
- if (4 & e && "object" == typeof t && t && t.__esModule) return t;
41
- var n = Object.create(null);
42
- if (i.r(n), Object.defineProperty(n, "default", {
43
- enumerable: !0,
44
- value: t
45
- }), 2 & e && "string" != typeof t)
46
- for (var r in t) i.d(n, r, function (e) {
47
- return t[e]
48
- }.bind(null, r));
49
- return n
50
- }, i.n = function (t) {
51
- var e = t && t.__esModule ? function () {
52
- return t.default
53
- } : function () {
54
- return t
55
- };
56
- return i.d(e, "a", e), e
57
- }, i.o = function (t, e) {
58
- return Object.prototype.hasOwnProperty.call(t, e)
59
- }, i.p = "", i(i.s = 0)
60
- }([function (t, e, i) {
61
- "use strict";
62
- Object.defineProperty(e, "__esModule", {
63
- value: !0
64
- });
65
- var n = function () {
66
- function t(e) {
67
- void 0 === e && (e = {}), this.isplaying = !1, this.lBuffer = [], this.rBuffer = [], this.tempPCM = [], this.inputSampleBits = 16, this.playStamp = 0, this.playTime = 0, this.totalPlayTime = 0, this.offset = 0, this.fileSize = 0;
68
- var i, n = new (window.AudioContext || window.webkitAudioContext);
69
- this.inputSampleRate = n.sampleRate, this.config = {
70
- sampleBits: ~[8, 16].indexOf(e.sampleBits) ? e.sampleBits : 16,
71
- sampleRate: ~[8e3, 11025, 16e3, 22050, 24e3, 44100, 48e3].indexOf(e.sampleRate) ? e.sampleRate : this.inputSampleRate,
72
- numChannels: ~[1, 2].indexOf(e.numChannels) ? e.numChannels : 1,
73
- compiling: !!e.compiling || !1
74
- }, this.outputSampleRate = this.config.sampleRate, this.oututSampleBits = this.config.sampleBits, this.littleEdian = (i = new ArrayBuffer(2), new DataView(i).setInt16(0, 256, !0), 256 === new Int16Array(i)[0]), t.initUserMedia()
75
- }
76
-
77
- return t.prototype.initRecorder = function () {
78
- var t = this;
79
- this.context && this.destroy(), this.context = new (window.AudioContext || window.webkitAudioContext), this.analyser = this.context.createAnalyser(), this.analyser.fftSize = 2048;
80
- var e = this.context.createScriptProcessor || this.context.createJavaScriptNode;
81
- this.recorder = e.apply(this.context, [4096, this.config.numChannels, this.config.numChannels]), this.recorder.onaudioprocess = function (e) {
82
- if (t.isrecording && !t.ispause) {
83
- var i, n = e.inputBuffer.getChannelData(0),
84
- r = null;
85
- if (t.lBuffer.push(new Float32Array(n)), t.size += n.length, 2 === t.config.numChannels && (r = e.inputBuffer.getChannelData(1), t.rBuffer.push(new Float32Array(r)), t.size += r.length), t.config.compiling) {
86
- var o = t.transformIntoPCM(n, r);
87
- t.tempPCM.push(o), t.fileSize = o.byteLength * t.tempPCM.length
88
- } else t.fileSize = Math.floor(t.size / Math.max(t.inputSampleRate / t.outputSampleRate, 1)) * (t.oututSampleBits / 8);
89
- i = 100 * Math.max.apply(Math, n), t.duration += 4096 / t.inputSampleRate, t.onprocess && t.onprocess(t.duration), t.onprogress && t.onprogress({
90
- duration: t.duration,
91
- fileSize: t.fileSize,
92
- vol: i,
93
- data: t.tempPCM
94
- })
95
- }
96
- }
97
- }, t.prototype.start = function () {
98
- var t = this;
99
- if (!this.isrecording) return this.clear(), this.initRecorder(), this.isrecording = !0, navigator.mediaDevices.getUserMedia({
100
- audio: !0
101
- }).then(function (e) {
102
- t.audioInput = t.context.createMediaStreamSource(e), t.stream = e
103
- }).then(function () {
104
- t.audioInput.connect(t.analyser), t.analyser.connect(t.recorder), t.recorder.connect(t.context.destination)
105
- })
106
- }, t.prototype.pause = function () {
107
- this.isrecording && !this.ispause && (this.ispause = !0)
108
- }, t.prototype.resume = function () {
109
- this.isrecording && this.ispause && (this.ispause = !1)
110
- }, t.prototype.stop = function () {
111
- this.isrecording = !1, this.audioInput && this.audioInput.disconnect(), this.recorder.disconnect()
112
- }, t.prototype.play = function () {
113
- this.stop(), this.source && this.source.stop(), this.isplaying = !0, this.playTime = 0, this.playAudioData()
114
- }, t.prototype.getPlayTime = function () {
115
- var t = 0;
116
- return (t = this.isplaying ? this.context.currentTime - this.playStamp + this.playTime : this.playTime) >= this.totalPlayTime && (t = this.totalPlayTime), t
117
- }, t.prototype.pausePlay = function () {
118
- !this.isrecording && this.isplaying && (this.source && this.source.disconnect(), this.playTime += this.context.currentTime - this.playStamp, this.isplaying = !1)
119
- }, t.prototype.resumePlay = function () {
120
- this.isrecording || this.isplaying || 0 === this.playTime || (this.isplaying = !0, this.playAudioData())
121
- }, t.prototype.stopPlay = function () {
122
- this.isrecording || (this.playTime = 0, this.isplaying = !1, this.source && this.source.stop())
123
- }, t.prototype.getWholeData = function () {
124
-
125
- return this.tempPCM
126
- }, t.prototype.getNextData = function () {
127
- var t1 = this.tempPCM.length,
128
- e1 = this.tempPCM.slice(this.offset)
129
-
130
- if (e1.length) {
131
- var e = new ArrayBuffer(e1.length * e1[0].byteLength),
132
- i = new DataView(e),
133
- n = 0;
134
- e1.forEach(function (t) {
135
- for (var e = 0, r = t.byteLength; e < r; ++e) i.setInt8(n, t.getInt8(e)), n++
136
- }), this.PCM = i, this.tempPCM = []
137
- }
138
- if (this.PCM) return this.PCM;
139
- var r = this.flat();
140
- r = t.compress(r, this.inputSampleRate, this.outputSampleRate), this.PCM = t.encodePCM(r, this.oututSampleBits, this.littleEdian)
141
- this.offset = t1
142
- return new Blob([r])
143
- // return e1
144
- }, t.prototype.playAudioData = function () {
145
- var e = this;
146
- this.context.decodeAudioData(this.getWAV().buffer, function (t) {
147
- e.source = e.context.createBufferSource(), e.source.buffer = t, e.totalPlayTime = e.source.buffer.duration, e.source.connect(e.analyser), e.analyser.connect(e.context.destination), e.source.start(0, e.playTime), e.playStamp = e.context.currentTime
148
- }, function (e) {
149
- t.throwError(e)
150
- })
151
- }, t.prototype.getRecordAnalyseData = function () {
152
- if (this.ispause) return this.prevDomainData;
153
- var t = new Uint8Array(this.analyser.frequencyBinCount);
154
- return this.analyser.getByteTimeDomainData(t), this.prevDomainData = t
155
- }, t.prototype.getPlayAnalyseData = function () {
156
- return this.getRecordAnalyseData()
157
- }, t.prototype.getPCM = function () {
158
- if (this.tempPCM.length) {
159
- var e = new ArrayBuffer(this.tempPCM.length * this.tempPCM[0].byteLength),
160
- i = new DataView(e),
161
- n = 0;
162
- this.tempPCM.forEach(function (t) {
163
- for (var e = 0, r = t.byteLength; e < r; ++e) i.setInt8(n, t.getInt8(e)), n++
164
- }), this.PCM = i, this.tempPCM = []
165
- }
166
- if (this.PCM) return this.PCM;
167
- var r = this.flat();
168
- return r = t.compress(r, this.inputSampleRate, this.outputSampleRate), this.PCM = t.encodePCM(r, this.oututSampleBits, this.littleEdian)
169
- }, t.prototype.getPCMBlob = function () {
170
- return this.stop(), new Blob([this.getPCM()])
171
- }, t.prototype.downloadPCM = function (t) {
172
- void 0 === t && (t = "recorder");
173
- var e = this.getPCMBlob();
174
- this.download(e, t, "pcm")
175
- }, t.prototype.getWAV = function () {
176
- var e = this.getPCM();
177
- return t.encodeWAV(e, this.inputSampleRate, this.outputSampleRate, this.config.numChannels, this.oututSampleBits, this.littleEdian)
178
- }, t.prototype.getWAVBlob = function () {
179
- return this.stop(), new Blob([this.getWAV()], {
180
- type: "audio/wav"
181
- })
182
- }, t.prototype.downloadWAV = function (t) {
183
- void 0 === t && (t = "recorder");
184
- var e = this.getWAVBlob();
185
- this.download(e, t, "wav")
186
- }, t.prototype.transformIntoPCM = function (e, i) {
187
- var n = new Float32Array(e),
188
- r = new Float32Array(i),
189
- o = t.compress({
190
- left: n,
191
- right: r
192
- }, this.inputSampleRate, this.outputSampleRate);
193
- return t.encodePCM(o, this.oututSampleBits, this.littleEdian)
194
- }, t.prototype.destroy = function () {
195
- return this.stopStream(), this.closeAudioContext()
196
- }, t.prototype.stopStream = function () {
197
- this.stream && this.stream.getTracks && (this.stream.getTracks().forEach(function (t) {
198
- return t.stop()
199
- }), this.stream = null)
200
- }, t.prototype.closeAudioContext = function () {
201
- return this.context && this.context.close && "closed" !== this.context.state ? this.context.close() : new Promise(function (t) {
202
- t()
203
- })
204
- }, t.prototype.download = function (e, i, n) {
205
- try {
206
- var r = document.createElement("a");
207
- r.href = window.URL.createObjectURL(e), r.download = i + "." + n, r.click()
208
- } catch (e) {
209
- t.throwError(e)
210
- }
211
- }, t.prototype.clear = function () {
212
- this.lBuffer.length = 0, this.rBuffer.length = 0, this.size = 0, this.fileSize = 0, this.PCM = null, this.audioInput = null, this.duration = 0, this.ispause = !1, this.isplaying = !1, this.playTime = 0, this.totalPlayTime = 0, this.source && (this.source.stop(), this.source = null)
213
- }, t.prototype.flat = function () {
214
- var t = null,
215
- e = new Float32Array(0);
216
- 1 === this.config.numChannels ? t = new Float32Array(this.size) : (t = new Float32Array(this.size / 2), e = new Float32Array(this.size / 2));
217
- for (var i = 0, n = 0; n < this.lBuffer.length; n++) t.set(this.lBuffer[n], i), i += this.lBuffer[n].length;
218
- i = 0;
219
- for (n = 0; n < this.rBuffer.length; n++) e.set(this.rBuffer[n], i), i += this.rBuffer[n].length;
220
- return {
221
- left: t,
222
- right: e
223
- }
224
- }, t.playAudio = function (t) {
225
- var e = document.createElement("audio");
226
- e.src = window.URL.createObjectURL(t), e.play()
227
- }, t.compress = function (t, e, i) {
228
- for (var n = e / i, r = Math.max(n, 1), o = t.left, s = t.right, a = Math.floor((o.length + s.length) / n), u = new Float32Array(a), h = 0, c = 0; h < a;) {
229
- var l = Math.floor(c);
230
- u[h] = o[l], h++, s.length && (u[h] = s[l], h++), c += r
231
- }
232
- return u
233
- }, t.encodePCM = function (t, e, i) {
234
- void 0 === i && (i = !0);
235
- var n = 0,
236
- r = t.length * (e / 8),
237
- o = new ArrayBuffer(r),
238
- s = new DataView(o);
239
- if (8 === e)
240
- for (var a = 0; a < t.length; a++, n++) {
241
- var u = (h = Math.max(-1, Math.min(1, t[a]))) < 0 ? 128 * h : 127 * h;
242
- u = +u + 128, s.setInt8(n, u)
243
- } else
244
- for (a = 0; a < t.length; a++, n += 2) {
245
- var h = Math.max(-1, Math.min(1, t[a]));
246
- s.setInt16(n, h < 0 ? 32768 * h : 32767 * h, i)
247
- }
248
- return s
249
- }, t.encodeWAV = function (t, e, i, n, o, s) {
250
- void 0 === s && (s = !0);
251
- var a = i > e ? e : i,
252
- u = o,
253
- h = new ArrayBuffer(44 + t.byteLength),
254
- c = new DataView(h),
255
- l = n,
256
- p = 0;
257
- r(c, p, "RIFF"), p += 4, c.setUint32(p, 36 + t.byteLength, s), r(c, p += 4, "WAVE"), r(c, p += 4, "fmt "), p += 4, c.setUint32(p, 16, s), p += 4, c.setUint16(p, 1, s), p += 2, c.setUint16(p, l, s), p += 2, c.setUint32(p, a, s), p += 4, c.setUint32(p, l * a * (u / 8), s), p += 4, c.setUint16(p, l * (u / 8), s), p += 2, c.setUint16(p, u, s), r(c, p += 2, "data"), p += 4, c.setUint32(p, t.byteLength, s), p += 4;
258
- for (var f = 0; f < t.byteLength;) c.setUint8(p, t.getUint8(f)), p++, f++;
259
- return c
260
- }, t.throwError = function (t) {
261
- throw new Error(t)
262
- }, t.initUserMedia = function () {
263
- void 0 === navigator.mediaDevices && (navigator.mediaDevices = {}), void 0 === navigator.mediaDevices.getUserMedia && (navigator.mediaDevices.getUserMedia = function (t) {
264
- var e = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
265
- return e ? new Promise(function (i, n) {
266
- e.call(navigator, t, i, n)
267
- }) : Promise.reject(new Error("浏览器不支持 getUserMedia !"))
268
- })
269
- }, t.getPermission = function () {
270
- return this.initUserMedia(), navigator.mediaDevices.getUserMedia({
271
- audio: !0
272
- }).then(function (t) {
273
- t.getTracks().forEach(function (t) {
274
- return t.stop()
275
- })
276
- })
277
- }, t
278
- }();
279
-
280
- function r(t, e, i) {
281
- for (var n = 0; n < i.length; n++) t.setUint8(e + n, i.charCodeAt(n))
282
- }
283
-
284
- e.default = n
285
- }]).default
286
- });
287
-
288
-
289
-