cnhis-design-vue 3.3.1-release.4 → 3.3.1-release.5
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.
- package/es/components/ai-chat/src/hooks/useChartAudioContext.js +1 -1
- package/es/components/audio-sdk/index.d.ts +37 -6
- package/es/components/audio-sdk/index.js +1 -0
- package/es/components/audio-sdk/src/Index.vue.d.ts +35 -6
- package/es/components/audio-sdk/src/Index.vue2.js +12 -4
- package/es/components/audio-sdk/src/audioSDK.d.ts +3 -4
- package/es/components/audio-sdk/src/audioSDK.js +12 -6
- package/es/components/audio-sdk/src/components/recording-modal.vue.d.ts +17 -3
- package/es/components/audio-sdk/src/components/recording.vue.d.ts +17 -3
- package/es/components/audio-sdk/src/components/recording.vue2.js +9 -6
- package/es/components/audio-sdk/src/utils/recorder/fft.js +75 -0
- package/es/components/audio-sdk/src/utils/recorder/index.d.ts +3 -0
- package/es/components/audio-sdk/src/utils/recorder/index.js +12 -0
- package/es/components/audio-sdk/src/utils/recorder/mp3-engine.js +12435 -0
- package/es/components/audio-sdk/src/utils/recorder/mp3.js +343 -0
- package/es/components/audio-sdk/src/utils/recorder/recorder.js +1324 -0
- package/es/components/audio-sdk/src/utils/recorder/wave.js +258 -0
- package/es/components/field-set/src/FieldColor.vue.d.ts +1 -1
- package/es/components/field-set/src/FieldFilter.vue.d.ts +1 -1
- package/es/components/field-set/src/FieldSet.vue.d.ts +1 -1
- package/es/components/field-set/src/components/table-row.vue.d.ts +1 -1
- package/es/components/index.js +1 -0
- package/es/components/select-person/src/SelectPerson.vue2.js +18 -9
- package/es/components/table-filter/src/components/render-widget/enums.d.ts +2 -0
- package/es/components/table-filter/src/components/render-widget/enums.js +2 -1
- package/es/components/table-filter/src/components/render-widget/helpers/dateExtraMap.js +8 -0
- package/es/components/table-filter/src/components/render-widget/helpers/enums.d.ts +1 -0
- package/es/components/table-filter/src/components/render-widget/helpers/enums.js +2 -1
- package/es/components/table-filter/src/components/render-widget/helpers/presetValToTimestamp.js +4 -2
- package/es/components/table-filter/src/tool/baseOptions.js +3 -0
- package/es/shared/package.json.js +1 -1
- package/es/shared/utils/index.js +3 -2
- package/package.json +1 -2
@@ -0,0 +1,1324 @@
|
|
1
|
+
var NOOP = function() {
|
2
|
+
};
|
3
|
+
var Recorder = function(set) {
|
4
|
+
return new initFn(set);
|
5
|
+
};
|
6
|
+
Recorder.LM = "2023-07-01 20:46";
|
7
|
+
var RecTxt = "Recorder";
|
8
|
+
var getUserMediaTxt = "getUserMedia";
|
9
|
+
var srcSampleRateTxt = "srcSampleRate";
|
10
|
+
var sampleRateTxt = "sampleRate";
|
11
|
+
var CatchTxt = "catch";
|
12
|
+
Recorder.IsOpen = function() {
|
13
|
+
var stream = Recorder.Stream;
|
14
|
+
if (stream) {
|
15
|
+
var tracks = stream.getTracks && stream.getTracks() || stream.audioTracks || [];
|
16
|
+
var track = tracks[0];
|
17
|
+
if (track) {
|
18
|
+
var state = track.readyState;
|
19
|
+
return state == "live" || state == track.LIVE;
|
20
|
+
}
|
21
|
+
}
|
22
|
+
return false;
|
23
|
+
};
|
24
|
+
Recorder.BufferSize = 4096;
|
25
|
+
Recorder.Destroy = function() {
|
26
|
+
CLog(RecTxt + " Destroy");
|
27
|
+
Disconnect();
|
28
|
+
for (var k in DestroyList) {
|
29
|
+
DestroyList[k]();
|
30
|
+
}
|
31
|
+
};
|
32
|
+
var DestroyList = {};
|
33
|
+
Recorder.BindDestroy = function(key, call) {
|
34
|
+
DestroyList[key] = call;
|
35
|
+
};
|
36
|
+
Recorder.Support = function() {
|
37
|
+
var scope = navigator.mediaDevices || {};
|
38
|
+
if (!scope[getUserMediaTxt]) {
|
39
|
+
scope = navigator;
|
40
|
+
scope[getUserMediaTxt] || (scope[getUserMediaTxt] = scope.webkitGetUserMedia || scope.mozGetUserMedia || scope.msGetUserMedia);
|
41
|
+
}
|
42
|
+
if (!scope[getUserMediaTxt]) {
|
43
|
+
return false;
|
44
|
+
}
|
45
|
+
Recorder.Scope = scope;
|
46
|
+
if (!Recorder.GetContext()) {
|
47
|
+
return false;
|
48
|
+
}
|
49
|
+
return true;
|
50
|
+
};
|
51
|
+
Recorder.GetContext = function(tryNew) {
|
52
|
+
var AC = window.AudioContext;
|
53
|
+
if (!AC) {
|
54
|
+
AC = window.webkitAudioContext;
|
55
|
+
}
|
56
|
+
if (!AC) {
|
57
|
+
return null;
|
58
|
+
}
|
59
|
+
var ctx = Recorder.Ctx;
|
60
|
+
if (!ctx || ctx.state == "closed") {
|
61
|
+
ctx = Recorder.Ctx = new AC();
|
62
|
+
Recorder.NewCtxs = Recorder.NewCtxs || [];
|
63
|
+
Recorder.BindDestroy("Ctx", function() {
|
64
|
+
var ctx2 = Recorder.Ctx;
|
65
|
+
if (ctx2 && ctx2.close) {
|
66
|
+
ctx2.close();
|
67
|
+
Recorder.Ctx = 0;
|
68
|
+
}
|
69
|
+
var arr = Recorder.NewCtxs;
|
70
|
+
Recorder.NewCtxs = [];
|
71
|
+
for (var i = 0; i < arr.length; i++)
|
72
|
+
arr[i].close();
|
73
|
+
});
|
74
|
+
}
|
75
|
+
if (tryNew && ctx.close) {
|
76
|
+
try {
|
77
|
+
ctx = new AC();
|
78
|
+
Recorder.NewCtxs.push(ctx);
|
79
|
+
} catch (e) {
|
80
|
+
CLog("GetContext tryNew\u5F02\u5E38", 1, e);
|
81
|
+
}
|
82
|
+
}
|
83
|
+
return ctx;
|
84
|
+
};
|
85
|
+
Recorder.CloseNewCtx = function(ctx) {
|
86
|
+
if (ctx && ctx != Recorder.Ctx) {
|
87
|
+
ctx.close && ctx.close();
|
88
|
+
var arr = Recorder.NewCtxs || [], L = arr.length;
|
89
|
+
for (var i = 0; i < arr.length; i++) {
|
90
|
+
if (arr[i] == ctx) {
|
91
|
+
arr.splice(i, 1);
|
92
|
+
break;
|
93
|
+
}
|
94
|
+
}
|
95
|
+
CLog("\u5269" + L + "-1=" + arr.length + "\u4E2AGetContext\u672Aclose", arr.length ? 3 : 0);
|
96
|
+
}
|
97
|
+
};
|
98
|
+
var CtxState = function(ctx) {
|
99
|
+
var v = ctx.state, msg = "ctx.state=" + v;
|
100
|
+
if (v == "suspended")
|
101
|
+
msg += "\uFF08\u6CE8\u610F\uFF1Actx\u4E0D\u662Frunning\u72B6\u6001\uFF0Crec.open\u548Cstart\u81F3\u5C11\u8981\u6709\u4E00\u4E2A\u5728\u7528\u6237\u64CD\u4F5C(\u89E6\u6478\u3001\u70B9\u51FB\u7B49)\u65F6\u8FDB\u884C\u8C03\u7528\uFF0C\u5426\u5219\u5C06\u5728rec.start\u65F6\u5C1D\u8BD5\u8FDB\u884Cctx.resume\uFF0C\u53EF\u80FD\u4F1A\u4EA7\u751F\u517C\u5BB9\u6027\u95EE\u9898(\u4EC5iOS)\uFF0C\u8BF7\u53C2\u9605\u6587\u6863\u4E2DrunningContext\u914D\u7F6E\uFF09";
|
102
|
+
return msg;
|
103
|
+
};
|
104
|
+
var ConnectEnableWebM = "ConnectEnableWebM";
|
105
|
+
Recorder[ConnectEnableWebM] = true;
|
106
|
+
var ConnectEnableWorklet = "ConnectEnableWorklet";
|
107
|
+
Recorder[ConnectEnableWorklet] = false;
|
108
|
+
var Connect = function(streamStore, isUserMedia) {
|
109
|
+
var bufferSize = streamStore.BufferSize || Recorder.BufferSize;
|
110
|
+
var stream = streamStore.Stream;
|
111
|
+
var ctx = stream._RC || stream._c || Recorder.GetContext(true);
|
112
|
+
stream._c = ctx;
|
113
|
+
var mediaConn = function(node) {
|
114
|
+
var media = stream._m = ctx.createMediaStreamSource(stream);
|
115
|
+
var ctxDest = ctx.destination, cmsdTxt = "createMediaStreamDestination";
|
116
|
+
if (ctx[cmsdTxt]) {
|
117
|
+
ctxDest = stream._d = ctx[cmsdTxt]();
|
118
|
+
}
|
119
|
+
media.connect(node);
|
120
|
+
node.connect(ctxDest);
|
121
|
+
};
|
122
|
+
var isWebM, isWorklet, badInt, webMTips = "";
|
123
|
+
var calls = stream._call;
|
124
|
+
var onReceive = function(float32Arr) {
|
125
|
+
for (var k0 in calls) {
|
126
|
+
var size = float32Arr.length;
|
127
|
+
var pcm = new Int16Array(size);
|
128
|
+
var sum = 0;
|
129
|
+
for (var j = 0; j < size; j++) {
|
130
|
+
var s = Math.max(-1, Math.min(1, float32Arr[j]));
|
131
|
+
s = s < 0 ? s * 32768 : s * 32767;
|
132
|
+
pcm[j] = s;
|
133
|
+
sum += Math.abs(s);
|
134
|
+
}
|
135
|
+
for (var k in calls) {
|
136
|
+
calls[k](pcm, sum);
|
137
|
+
}
|
138
|
+
return;
|
139
|
+
}
|
140
|
+
};
|
141
|
+
var scriptProcessor = "ScriptProcessor";
|
142
|
+
var audioWorklet = "audioWorklet";
|
143
|
+
var recAudioWorklet = RecTxt + " " + audioWorklet;
|
144
|
+
var RecProc = "RecProc";
|
145
|
+
var MediaRecorderTxt = "MediaRecorder";
|
146
|
+
var MRWebMPCM = MediaRecorderTxt + ".WebM.PCM";
|
147
|
+
var oldFn = ctx.createScriptProcessor || ctx.createJavaScriptNode;
|
148
|
+
var oldIsBest = "\u3002\u7531\u4E8E" + audioWorklet + "\u5185\u90E81\u79D2375\u6B21\u56DE\u8C03\uFF0C\u5728\u79FB\u52A8\u7AEF\u53EF\u80FD\u4F1A\u6709\u6027\u80FD\u95EE\u9898\u5BFC\u81F4\u56DE\u8C03\u4E22\u5931\u5F55\u97F3\u53D8\u77ED\uFF0CPC\u7AEF\u65E0\u5F71\u54CD\uFF0C\u6682\u4E0D\u5EFA\u8BAE\u5F00\u542F" + audioWorklet + "\u3002";
|
149
|
+
var oldScript = function() {
|
150
|
+
isWorklet = stream.isWorklet = false;
|
151
|
+
_Disconn_n(stream);
|
152
|
+
CLog(
|
153
|
+
"Connect\u91C7\u7528\u8001\u7684" + scriptProcessor + "\uFF0C" + (Recorder[ConnectEnableWorklet] ? "\u4F46\u5DF2" : "\u53EF") + "\u8BBE\u7F6E" + RecTxt + "." + ConnectEnableWorklet + "=true\u5C1D\u8BD5\u542F\u7528" + audioWorklet + webMTips + oldIsBest,
|
154
|
+
3
|
155
|
+
);
|
156
|
+
var process = stream._p = oldFn.call(ctx, bufferSize, 1, 1);
|
157
|
+
mediaConn(process);
|
158
|
+
process.onaudioprocess = function(e) {
|
159
|
+
var arr = e.inputBuffer.getChannelData(0);
|
160
|
+
onReceive(arr);
|
161
|
+
};
|
162
|
+
};
|
163
|
+
var connWorklet = function() {
|
164
|
+
isWebM = stream.isWebM = false;
|
165
|
+
_Disconn_r(stream);
|
166
|
+
isWorklet = stream.isWorklet = !oldFn || Recorder[ConnectEnableWorklet];
|
167
|
+
var AwNode = window.AudioWorkletNode;
|
168
|
+
if (!(isWorklet && ctx[audioWorklet] && AwNode)) {
|
169
|
+
oldScript();
|
170
|
+
return;
|
171
|
+
}
|
172
|
+
var clazzUrl = function() {
|
173
|
+
var xf = function(f) {
|
174
|
+
return f.toString().replace(/^function|DEL_/g, "").replace(/\$RA/g, recAudioWorklet);
|
175
|
+
};
|
176
|
+
var clazz = "class " + RecProc + " extends AudioWorkletProcessor{";
|
177
|
+
clazz += "constructor " + xf(function(option) {
|
178
|
+
DEL_super(option);
|
179
|
+
var This = this, bufferSize2 = option.processorOptions.bufferSize;
|
180
|
+
This.bufferSize = bufferSize2;
|
181
|
+
This.buffer = new Float32Array(bufferSize2 * 2);
|
182
|
+
This.pos = 0;
|
183
|
+
This.port.onmessage = function(e) {
|
184
|
+
if (e.data.kill) {
|
185
|
+
This.kill = true;
|
186
|
+
$C.log("$RA kill call");
|
187
|
+
}
|
188
|
+
};
|
189
|
+
$C.log("$RA .ctor call", option);
|
190
|
+
});
|
191
|
+
clazz += "process " + xf(function(input, b, c) {
|
192
|
+
var This = this, bufferSize2 = This.bufferSize;
|
193
|
+
var buffer = This.buffer, pos = This.pos;
|
194
|
+
input = (input[0] || [])[0] || [];
|
195
|
+
if (input.length) {
|
196
|
+
buffer.set(input, pos);
|
197
|
+
pos += input.length;
|
198
|
+
var len = ~~(pos / bufferSize2) * bufferSize2;
|
199
|
+
if (len) {
|
200
|
+
this.port.postMessage({ val: buffer.slice(0, len) });
|
201
|
+
var more = buffer.subarray(len, pos);
|
202
|
+
buffer = new Float32Array(bufferSize2 * 2);
|
203
|
+
buffer.set(more);
|
204
|
+
pos = more.length;
|
205
|
+
This.buffer = buffer;
|
206
|
+
}
|
207
|
+
This.pos = pos;
|
208
|
+
}
|
209
|
+
return !This.kill;
|
210
|
+
});
|
211
|
+
clazz += '}try{registerProcessor("' + RecProc + '", ' + RecProc + ')}catch(e){$C.error("' + recAudioWorklet + '\u6CE8\u518C\u5931\u8D25",e)}';
|
212
|
+
clazz = clazz.replace(/\$C\./g, "console.");
|
213
|
+
return "data:text/javascript;base64," + btoa(unescape(encodeURIComponent(clazz)));
|
214
|
+
};
|
215
|
+
var awNext = function() {
|
216
|
+
return isWorklet && stream._na;
|
217
|
+
};
|
218
|
+
var nodeAlive = stream._na = function() {
|
219
|
+
if (badInt !== "") {
|
220
|
+
clearTimeout(badInt);
|
221
|
+
badInt = setTimeout(function() {
|
222
|
+
badInt = 0;
|
223
|
+
if (awNext()) {
|
224
|
+
CLog(audioWorklet + "\u672A\u8FD4\u56DE\u4EFB\u4F55\u97F3\u9891\uFF0C\u6062\u590D\u4F7F\u7528" + scriptProcessor, 3);
|
225
|
+
oldFn && oldScript();
|
226
|
+
}
|
227
|
+
}, 500);
|
228
|
+
}
|
229
|
+
};
|
230
|
+
var createNode = function() {
|
231
|
+
if (!awNext())
|
232
|
+
return;
|
233
|
+
var node = stream._n = new AwNode(ctx, RecProc, {
|
234
|
+
processorOptions: { bufferSize }
|
235
|
+
});
|
236
|
+
mediaConn(node);
|
237
|
+
node.port.onmessage = function(e) {
|
238
|
+
if (badInt) {
|
239
|
+
clearTimeout(badInt);
|
240
|
+
badInt = "";
|
241
|
+
}
|
242
|
+
if (awNext()) {
|
243
|
+
onReceive(e.data.val);
|
244
|
+
} else if (!isWorklet) {
|
245
|
+
CLog(audioWorklet + "\u591A\u4F59\u56DE\u8C03", 3);
|
246
|
+
}
|
247
|
+
};
|
248
|
+
CLog(
|
249
|
+
"Connect\u91C7\u7528" + audioWorklet + "\uFF0C\u8BBE\u7F6E" + RecTxt + "." + ConnectEnableWorklet + "=false\u53EF\u6062\u590D\u8001\u5F0F" + scriptProcessor + webMTips + oldIsBest,
|
250
|
+
3
|
251
|
+
);
|
252
|
+
};
|
253
|
+
ctx.resume()[calls && "finally"](function() {
|
254
|
+
if (!awNext())
|
255
|
+
return;
|
256
|
+
if (ctx[RecProc]) {
|
257
|
+
createNode();
|
258
|
+
return;
|
259
|
+
}
|
260
|
+
var url = clazzUrl();
|
261
|
+
ctx[audioWorklet].addModule(url).then(function(e) {
|
262
|
+
if (!awNext())
|
263
|
+
return;
|
264
|
+
ctx[RecProc] = 1;
|
265
|
+
createNode();
|
266
|
+
if (badInt) {
|
267
|
+
nodeAlive();
|
268
|
+
}
|
269
|
+
})[CatchTxt](function(e) {
|
270
|
+
CLog(audioWorklet + ".addModule\u5931\u8D25", 1, e);
|
271
|
+
awNext() && oldScript();
|
272
|
+
});
|
273
|
+
});
|
274
|
+
};
|
275
|
+
var connWebM = function() {
|
276
|
+
var MR = window[MediaRecorderTxt];
|
277
|
+
var onData = "ondataavailable";
|
278
|
+
var webmType = "audio/webm; codecs=pcm";
|
279
|
+
isWebM = stream.isWebM = Recorder[ConnectEnableWebM];
|
280
|
+
var supportMR = MR && onData in MR.prototype && MR.isTypeSupported(webmType);
|
281
|
+
webMTips = supportMR ? "" : "\uFF08\u6B64\u6D4F\u89C8\u5668\u4E0D\u652F\u6301" + MRWebMPCM + "\uFF09";
|
282
|
+
if (!isUserMedia || !isWebM || !supportMR) {
|
283
|
+
connWorklet();
|
284
|
+
return;
|
285
|
+
}
|
286
|
+
var mrNext = function() {
|
287
|
+
return isWebM && stream._ra;
|
288
|
+
};
|
289
|
+
stream._ra = function() {
|
290
|
+
if (badInt !== "") {
|
291
|
+
clearTimeout(badInt);
|
292
|
+
badInt = setTimeout(function() {
|
293
|
+
if (mrNext()) {
|
294
|
+
CLog(MediaRecorderTxt + "\u672A\u8FD4\u56DE\u4EFB\u4F55\u97F3\u9891\uFF0C\u964D\u7EA7\u4F7F\u7528" + audioWorklet, 3);
|
295
|
+
connWorklet();
|
296
|
+
}
|
297
|
+
}, 500);
|
298
|
+
}
|
299
|
+
};
|
300
|
+
var mrSet = Object.assign({ mimeType: webmType }, Recorder.ConnectWebMOptions);
|
301
|
+
var mr = stream._r = new MR(stream, mrSet);
|
302
|
+
var webmData = stream._rd = { sampleRate: ctx[sampleRateTxt] };
|
303
|
+
mr[onData] = function(e) {
|
304
|
+
var reader = new FileReader();
|
305
|
+
reader.onloadend = function() {
|
306
|
+
if (mrNext()) {
|
307
|
+
var f32arr = WebM_Extract(new Uint8Array(reader.result), webmData);
|
308
|
+
if (!f32arr)
|
309
|
+
return;
|
310
|
+
if (f32arr == -1) {
|
311
|
+
connWorklet();
|
312
|
+
return;
|
313
|
+
}
|
314
|
+
if (badInt) {
|
315
|
+
clearTimeout(badInt);
|
316
|
+
badInt = "";
|
317
|
+
}
|
318
|
+
onReceive(f32arr);
|
319
|
+
} else if (!isWebM) {
|
320
|
+
CLog(MediaRecorderTxt + "\u591A\u4F59\u56DE\u8C03", 3);
|
321
|
+
}
|
322
|
+
};
|
323
|
+
reader.readAsArrayBuffer(e.data);
|
324
|
+
};
|
325
|
+
mr.start(~~(bufferSize / 48));
|
326
|
+
CLog(
|
327
|
+
"Connect\u91C7\u7528" + MRWebMPCM + "\uFF0C\u8BBE\u7F6E" + RecTxt + "." + ConnectEnableWebM + "=false\u53EF\u6062\u590D\u4F7F\u7528" + audioWorklet + "\u6216\u8001\u5F0F" + scriptProcessor
|
328
|
+
);
|
329
|
+
};
|
330
|
+
connWebM();
|
331
|
+
};
|
332
|
+
var ConnAlive = function(stream) {
|
333
|
+
if (stream._na)
|
334
|
+
stream._na();
|
335
|
+
if (stream._ra)
|
336
|
+
stream._ra();
|
337
|
+
};
|
338
|
+
var _Disconn_n = function(stream) {
|
339
|
+
stream._na = null;
|
340
|
+
if (stream._n) {
|
341
|
+
stream._n.port.postMessage({ kill: true });
|
342
|
+
stream._n.disconnect();
|
343
|
+
stream._n = null;
|
344
|
+
}
|
345
|
+
};
|
346
|
+
var _Disconn_r = function(stream) {
|
347
|
+
stream._ra = null;
|
348
|
+
if (stream._r) {
|
349
|
+
stream._r.stop();
|
350
|
+
stream._r = null;
|
351
|
+
}
|
352
|
+
};
|
353
|
+
var Disconnect = function(streamStore) {
|
354
|
+
streamStore = streamStore || Recorder;
|
355
|
+
var isGlobal = streamStore == Recorder;
|
356
|
+
var stream = streamStore.Stream;
|
357
|
+
if (stream) {
|
358
|
+
if (stream._m) {
|
359
|
+
stream._m.disconnect();
|
360
|
+
stream._m = null;
|
361
|
+
}
|
362
|
+
if (!stream._RC && stream._c) {
|
363
|
+
Recorder.CloseNewCtx(stream._c);
|
364
|
+
}
|
365
|
+
stream._RC = null;
|
366
|
+
stream._c = null;
|
367
|
+
if (stream._d) {
|
368
|
+
StopS_(stream._d.stream);
|
369
|
+
stream._d = null;
|
370
|
+
}
|
371
|
+
if (stream._p) {
|
372
|
+
stream._p.disconnect();
|
373
|
+
stream._p.onaudioprocess = stream._p = null;
|
374
|
+
}
|
375
|
+
_Disconn_n(stream);
|
376
|
+
_Disconn_r(stream);
|
377
|
+
if (isGlobal) {
|
378
|
+
StopS_(stream);
|
379
|
+
}
|
380
|
+
}
|
381
|
+
streamStore.Stream = 0;
|
382
|
+
};
|
383
|
+
var StopS_ = Recorder.StopS_ = function(stream) {
|
384
|
+
var tracks = stream.getTracks && stream.getTracks() || stream.audioTracks || [];
|
385
|
+
for (var i = 0; i < tracks.length; i++) {
|
386
|
+
var track = tracks[i];
|
387
|
+
track.stop && track.stop();
|
388
|
+
}
|
389
|
+
stream.stop && stream.stop();
|
390
|
+
};
|
391
|
+
Recorder.SampleData = function(pcmDatas, pcmSampleRate, newSampleRate, prevChunkInfo, option) {
|
392
|
+
var Txt = "SampleData";
|
393
|
+
prevChunkInfo || (prevChunkInfo = {});
|
394
|
+
var index = prevChunkInfo.index || 0;
|
395
|
+
var offset = prevChunkInfo.offset || 0;
|
396
|
+
var filter = prevChunkInfo.filter;
|
397
|
+
if (filter && filter.fn && filter.sr != pcmSampleRate) {
|
398
|
+
filter = null;
|
399
|
+
CLog(Txt + "\u7684filter\u91C7\u6837\u7387\u53D8\u4E86\uFF0C\u91CD\u8BBE\u6EE4\u6CE2", 3);
|
400
|
+
}
|
401
|
+
if (!filter) {
|
402
|
+
var freq = newSampleRate > pcmSampleRate * 3 / 4 ? 0 : newSampleRate / 2 * 3 / 4;
|
403
|
+
filter = { fn: freq ? Recorder.IIRFilter(true, pcmSampleRate, freq) : 0 };
|
404
|
+
}
|
405
|
+
filter.sr = pcmSampleRate;
|
406
|
+
var filterFn = filter.fn;
|
407
|
+
var frameNext = prevChunkInfo.frameNext || [];
|
408
|
+
option || (option = {});
|
409
|
+
var frameSize = option.frameSize || 1;
|
410
|
+
if (option.frameType) {
|
411
|
+
frameSize = option.frameType == "mp3" ? 1152 : 1;
|
412
|
+
}
|
413
|
+
var nLen = pcmDatas.length;
|
414
|
+
if (index > nLen + 1) {
|
415
|
+
CLog(Txt + "\u4F3C\u4E4E\u4F20\u5165\u4E86\u672A\u91CD\u7F6Echunk " + index + ">" + nLen, 3);
|
416
|
+
}
|
417
|
+
var size = 0;
|
418
|
+
for (var i = index; i < nLen; i++) {
|
419
|
+
size += pcmDatas[i].length;
|
420
|
+
}
|
421
|
+
size = Math.max(0, size - Math.floor(offset));
|
422
|
+
var step = pcmSampleRate / newSampleRate;
|
423
|
+
if (step > 1) {
|
424
|
+
size = Math.floor(size / step);
|
425
|
+
} else {
|
426
|
+
step = 1;
|
427
|
+
newSampleRate = pcmSampleRate;
|
428
|
+
}
|
429
|
+
size += frameNext.length;
|
430
|
+
var res = new Int16Array(size);
|
431
|
+
var idx = 0;
|
432
|
+
for (var i = 0; i < frameNext.length; i++) {
|
433
|
+
res[idx] = frameNext[i];
|
434
|
+
idx++;
|
435
|
+
}
|
436
|
+
for (; index < nLen; index++) {
|
437
|
+
var o = pcmDatas[index];
|
438
|
+
var i = offset, il = o.length;
|
439
|
+
var F = filterFn && filterFn.Embed, F1 = 0, F2 = 0, Fx = 0, Fy = 0;
|
440
|
+
for (var i0 = 0, i2 = 0; i0 < il; i0++, i2++) {
|
441
|
+
if (i2 < il) {
|
442
|
+
if (F) {
|
443
|
+
Fx = o[i2];
|
444
|
+
Fy = F.b0 * Fx + F.b1 * F.x1 + F.b0 * F.x2 - F.a1 * F.y1 - F.a2 * F.y2;
|
445
|
+
F.x2 = F.x1;
|
446
|
+
F.x1 = Fx;
|
447
|
+
F.y2 = F.y1;
|
448
|
+
F.y1 = Fy;
|
449
|
+
} else {
|
450
|
+
Fy = filterFn ? filterFn(o[i2]) : o[i2];
|
451
|
+
}
|
452
|
+
}
|
453
|
+
F1 = F2;
|
454
|
+
F2 = Fy;
|
455
|
+
if (i2 == 0) {
|
456
|
+
i0--;
|
457
|
+
continue;
|
458
|
+
}
|
459
|
+
var before = Math.floor(i);
|
460
|
+
if (i0 != before)
|
461
|
+
continue;
|
462
|
+
var after = Math.ceil(i);
|
463
|
+
var atPoint = i - before;
|
464
|
+
var beforeVal = F1;
|
465
|
+
var afterVal = after < il ? F2 : beforeVal;
|
466
|
+
res[idx] = beforeVal + (afterVal - beforeVal) * atPoint;
|
467
|
+
idx++;
|
468
|
+
i += step;
|
469
|
+
}
|
470
|
+
offset = Math.max(0, i - il);
|
471
|
+
}
|
472
|
+
frameNext = null;
|
473
|
+
var frameNextSize = res.length % frameSize;
|
474
|
+
if (frameNextSize > 0) {
|
475
|
+
var u8Pos = (res.length - frameNextSize) * 2;
|
476
|
+
frameNext = new Int16Array(res.buffer.slice(u8Pos));
|
477
|
+
res = new Int16Array(res.buffer.slice(0, u8Pos));
|
478
|
+
}
|
479
|
+
return {
|
480
|
+
index,
|
481
|
+
offset,
|
482
|
+
filter,
|
483
|
+
frameNext,
|
484
|
+
sampleRate: newSampleRate,
|
485
|
+
data: res
|
486
|
+
};
|
487
|
+
};
|
488
|
+
Recorder.IIRFilter = function(useLowPass, sampleRate, freq) {
|
489
|
+
var ov = 2 * Math.PI * freq / sampleRate;
|
490
|
+
var sn = Math.sin(ov);
|
491
|
+
var cs = Math.cos(ov);
|
492
|
+
var alpha = sn / 2;
|
493
|
+
var a0 = 1 + alpha;
|
494
|
+
var a1 = -2 * cs / a0;
|
495
|
+
var a2 = (1 - alpha) / a0;
|
496
|
+
if (useLowPass) {
|
497
|
+
var b0 = (1 - cs) / 2 / a0;
|
498
|
+
var b1 = (1 - cs) / a0;
|
499
|
+
} else {
|
500
|
+
var b0 = (1 + cs) / 2 / a0;
|
501
|
+
var b1 = -(1 + cs) / a0;
|
502
|
+
}
|
503
|
+
var x1 = 0, x2 = 0, y = 0, y1 = 0, y2 = 0;
|
504
|
+
var fn = function(x) {
|
505
|
+
y = b0 * x + b1 * x1 + b0 * x2 - a1 * y1 - a2 * y2;
|
506
|
+
x2 = x1;
|
507
|
+
x1 = x;
|
508
|
+
y2 = y1;
|
509
|
+
y1 = y;
|
510
|
+
return y;
|
511
|
+
};
|
512
|
+
fn.Embed = { x1: 0, x2: 0, y1: 0, y2: 0, b0, b1, a1, a2 };
|
513
|
+
return fn;
|
514
|
+
};
|
515
|
+
Recorder.PowerLevel = function(pcmAbsSum, pcmLength) {
|
516
|
+
var power = pcmAbsSum / pcmLength || 0;
|
517
|
+
var level;
|
518
|
+
if (power < 1251) {
|
519
|
+
level = Math.round(power / 1250 * 10);
|
520
|
+
} else {
|
521
|
+
level = Math.round(Math.min(100, Math.max(0, (1 + Math.log(power / 1e4) / Math.log(10)) * 100)));
|
522
|
+
}
|
523
|
+
return level;
|
524
|
+
};
|
525
|
+
Recorder.PowerDBFS = function(maxSample) {
|
526
|
+
var val = Math.max(0.1, maxSample || 0), Pref = 32767;
|
527
|
+
val = Math.min(val, Pref);
|
528
|
+
val = 20 * Math.log(val / Pref) / Math.log(10);
|
529
|
+
return Math.max(-100, Math.round(val));
|
530
|
+
};
|
531
|
+
Recorder.CLog = function(msg, err) {
|
532
|
+
var now = new Date();
|
533
|
+
var t = ("0" + now.getMinutes()).substr(-2) + ":" + ("0" + now.getSeconds()).substr(-2) + "." + ("00" + now.getMilliseconds()).substr(-3);
|
534
|
+
var recID = this && this.envIn && this.envCheck && this.id;
|
535
|
+
var arr = ["[" + t + " " + RecTxt + (recID ? ":" + recID : "") + "]" + msg];
|
536
|
+
var a = arguments, console2 = window.console || {};
|
537
|
+
var i = 2, fn = console2.log;
|
538
|
+
if (typeof err == "number") {
|
539
|
+
fn = err == 1 ? console2.error : err == 3 ? console2.warn : fn;
|
540
|
+
} else {
|
541
|
+
i = 1;
|
542
|
+
}
|
543
|
+
for (; i < a.length; i++) {
|
544
|
+
arr.push(a[i]);
|
545
|
+
}
|
546
|
+
if (IsLoser) {
|
547
|
+
fn && fn("[IsLoser]" + arr[0], arr.length > 1 ? arr : "");
|
548
|
+
} else {
|
549
|
+
fn.apply(console2, arr);
|
550
|
+
}
|
551
|
+
};
|
552
|
+
var CLog = function() {
|
553
|
+
Recorder.CLog.apply(this, arguments);
|
554
|
+
};
|
555
|
+
var IsLoser = true;
|
556
|
+
try {
|
557
|
+
IsLoser = !console.log.apply;
|
558
|
+
} catch (e) {
|
559
|
+
}
|
560
|
+
var ID = 0;
|
561
|
+
function initFn(set) {
|
562
|
+
this.id = ++ID;
|
563
|
+
Traffic();
|
564
|
+
var o = {
|
565
|
+
type: "mp3",
|
566
|
+
bitRate: 16,
|
567
|
+
sampleRate: 16e3,
|
568
|
+
onProcess: NOOP
|
569
|
+
};
|
570
|
+
for (var k in set) {
|
571
|
+
o[k] = set[k];
|
572
|
+
}
|
573
|
+
this.set = o;
|
574
|
+
this._S = 9;
|
575
|
+
this.Sync = { O: 9, C: 9 };
|
576
|
+
}
|
577
|
+
Recorder.Sync = { O: 9, C: 9 };
|
578
|
+
Recorder.prototype = initFn.prototype = {
|
579
|
+
CLog,
|
580
|
+
_streamStore: function() {
|
581
|
+
if (this.set.sourceStream) {
|
582
|
+
return this;
|
583
|
+
} else {
|
584
|
+
return Recorder;
|
585
|
+
}
|
586
|
+
},
|
587
|
+
_streamCtx: function() {
|
588
|
+
var m = this._streamStore().Stream;
|
589
|
+
return m && m._c;
|
590
|
+
},
|
591
|
+
open: function(True, False) {
|
592
|
+
var This = this, set = This.set, streamStore = This._streamStore(), newCtx = 0;
|
593
|
+
True = True || NOOP;
|
594
|
+
var failCall = function(errMsg, isUserNotAllow) {
|
595
|
+
isUserNotAllow = !!isUserNotAllow;
|
596
|
+
This.CLog("\u5F55\u97F3open\u5931\u8D25\uFF1A" + errMsg + ",isUserNotAllow:" + isUserNotAllow, 1);
|
597
|
+
if (newCtx)
|
598
|
+
Recorder.CloseNewCtx(newCtx);
|
599
|
+
False && False(errMsg, isUserNotAllow);
|
600
|
+
};
|
601
|
+
var ok = function() {
|
602
|
+
This.CLog("open ok id:" + This.id);
|
603
|
+
True();
|
604
|
+
This._SO = 0;
|
605
|
+
};
|
606
|
+
var Lock = streamStore.Sync;
|
607
|
+
var lockOpen = ++Lock.O, lockClose = Lock.C;
|
608
|
+
This._O = This._O_ = lockOpen;
|
609
|
+
This._SO = This._S;
|
610
|
+
var lockFail = function() {
|
611
|
+
if (lockClose != Lock.C || !This._O) {
|
612
|
+
var err = "open\u88AB\u53D6\u6D88";
|
613
|
+
if (lockOpen == Lock.O) {
|
614
|
+
This.close();
|
615
|
+
} else {
|
616
|
+
err = "open\u88AB\u4E2D\u65AD";
|
617
|
+
}
|
618
|
+
failCall(err);
|
619
|
+
return true;
|
620
|
+
}
|
621
|
+
};
|
622
|
+
var checkMsg = This.envCheck({ envName: "H5", canProcess: true });
|
623
|
+
if (checkMsg) {
|
624
|
+
failCall("\u4E0D\u80FD\u5F55\u97F3\uFF1A" + checkMsg);
|
625
|
+
return;
|
626
|
+
}
|
627
|
+
if (set.sourceStream) {
|
628
|
+
if (!Recorder.GetContext()) {
|
629
|
+
failCall("\u4E0D\u652F\u6301\u6B64\u6D4F\u89C8\u5668\u4ECE\u6D41\u4E2D\u83B7\u53D6\u5F55\u97F3");
|
630
|
+
return;
|
631
|
+
}
|
632
|
+
Disconnect(streamStore);
|
633
|
+
var stream = This.Stream = set.sourceStream;
|
634
|
+
stream._RC = set.runningContext;
|
635
|
+
stream._call = {};
|
636
|
+
try {
|
637
|
+
Connect(streamStore);
|
638
|
+
} catch (e) {
|
639
|
+
Disconnect(streamStore);
|
640
|
+
failCall("\u4ECE\u6D41\u4E2D\u6253\u5F00\u5F55\u97F3\u5931\u8D25\uFF1A" + e.message);
|
641
|
+
return;
|
642
|
+
}
|
643
|
+
ok();
|
644
|
+
return;
|
645
|
+
}
|
646
|
+
var codeFail = function(code, msg) {
|
647
|
+
try {
|
648
|
+
window.top.a;
|
649
|
+
} catch (e) {
|
650
|
+
failCall('\u65E0\u6743\u5F55\u97F3(\u8DE8\u57DF\uFF0C\u8BF7\u5C1D\u8BD5\u7ED9iframe\u6DFB\u52A0\u9EA6\u514B\u98CE\u8BBF\u95EE\u7B56\u7565\uFF0C\u5982allow="camera;microphone")');
|
651
|
+
return;
|
652
|
+
}
|
653
|
+
if (/Permission|Allow/i.test(code)) {
|
654
|
+
failCall("\u7528\u6237\u62D2\u7EDD\u4E86\u5F55\u97F3\u6743\u9650", true);
|
655
|
+
} else if (window.isSecureContext === false) {
|
656
|
+
failCall("\u6D4F\u89C8\u5668\u7981\u6B62\u4E0D\u5B89\u5168\u9875\u9762\u5F55\u97F3\uFF0C\u53EF\u5F00\u542Fhttps\u89E3\u51B3");
|
657
|
+
} else if (/Found/i.test(code)) {
|
658
|
+
failCall(msg + "\uFF0C\u65E0\u53EF\u7528\u9EA6\u514B\u98CE");
|
659
|
+
} else {
|
660
|
+
failCall(msg);
|
661
|
+
}
|
662
|
+
};
|
663
|
+
if (Recorder.IsOpen()) {
|
664
|
+
ok();
|
665
|
+
return;
|
666
|
+
}
|
667
|
+
if (!Recorder.Support()) {
|
668
|
+
codeFail("", "\u6B64\u6D4F\u89C8\u5668\u4E0D\u652F\u6301\u5F55\u97F3");
|
669
|
+
return;
|
670
|
+
}
|
671
|
+
var ctx = set.runningContext;
|
672
|
+
if (!ctx)
|
673
|
+
ctx = newCtx = Recorder.GetContext(true);
|
674
|
+
var f1 = function(stream2) {
|
675
|
+
setTimeout(function() {
|
676
|
+
stream2._call = {};
|
677
|
+
var oldStream = Recorder.Stream;
|
678
|
+
if (oldStream) {
|
679
|
+
Disconnect();
|
680
|
+
stream2._call = oldStream._call;
|
681
|
+
}
|
682
|
+
Recorder.Stream = stream2;
|
683
|
+
stream2._c = ctx;
|
684
|
+
stream2._RC = set.runningContext;
|
685
|
+
if (lockFail())
|
686
|
+
return;
|
687
|
+
if (Recorder.IsOpen()) {
|
688
|
+
if (oldStream)
|
689
|
+
This.CLog("\u53D1\u73B0\u540C\u65F6\u591A\u6B21\u8C03\u7528open", 1);
|
690
|
+
Connect(streamStore, 1);
|
691
|
+
ok();
|
692
|
+
} else {
|
693
|
+
failCall("\u5F55\u97F3\u529F\u80FD\u65E0\u6548\uFF1A\u65E0\u97F3\u9891\u6D41");
|
694
|
+
}
|
695
|
+
}, 100);
|
696
|
+
};
|
697
|
+
var f2 = function(e) {
|
698
|
+
var code = e.name || e.message || e.code + ":" + e;
|
699
|
+
This.CLog("\u8BF7\u6C42\u5F55\u97F3\u6743\u9650\u9519\u8BEF", 1, e);
|
700
|
+
codeFail(code, "\u65E0\u6CD5\u5F55\u97F3\uFF1A" + code);
|
701
|
+
};
|
702
|
+
var trackSet = set.audioTrackSet || {};
|
703
|
+
trackSet[sampleRateTxt] = ctx[sampleRateTxt];
|
704
|
+
var mSet = { audio: trackSet };
|
705
|
+
try {
|
706
|
+
var pro = Recorder.Scope[getUserMediaTxt](mSet, f1, f2);
|
707
|
+
} catch (e) {
|
708
|
+
This.CLog(getUserMediaTxt, 3, e);
|
709
|
+
mSet = { audio: true };
|
710
|
+
pro = Recorder.Scope[getUserMediaTxt](mSet, f1, f2);
|
711
|
+
}
|
712
|
+
This.CLog(
|
713
|
+
getUserMediaTxt + "(" + JSON.stringify(mSet) + ") " + CtxState(ctx) + "\uFF0C\u4E00\u822C\u9ED8\u8BA4\u4F1A\u964D\u566A\u548C\u56DE\u58F0\u6D88\u9664\uFF0C\u79FB\u52A8\u7AEF\u53EF\u80FD\u4F1A\u964D\u4F4E\u7CFB\u7EDF\u64AD\u653E\u97F3\u91CF\uFF0C\u8BF7\u53C2\u9605\u6587\u6863\u4E2DaudioTrackSet\u914D\u7F6E"
|
714
|
+
);
|
715
|
+
if (pro && pro.then) {
|
716
|
+
pro.then(f1)[CatchTxt](f2);
|
717
|
+
}
|
718
|
+
},
|
719
|
+
close: function(call) {
|
720
|
+
call = call || NOOP;
|
721
|
+
var This = this, streamStore = This._streamStore();
|
722
|
+
This._stop();
|
723
|
+
var Lock = streamStore.Sync;
|
724
|
+
This._O = 0;
|
725
|
+
if (This._O_ != Lock.O) {
|
726
|
+
This.CLog("close\u88AB\u5FFD\u7565\uFF08\u56E0\u4E3A\u540C\u65F6open\u4E86\u591A\u4E2Arec\uFF0C\u53EA\u6709\u6700\u540E\u4E00\u4E2A\u4F1A\u771F\u6B63close\uFF09", 3);
|
727
|
+
call();
|
728
|
+
return;
|
729
|
+
}
|
730
|
+
Lock.C++;
|
731
|
+
Disconnect(streamStore);
|
732
|
+
This.CLog("close");
|
733
|
+
call();
|
734
|
+
},
|
735
|
+
mock: function(pcmData, pcmSampleRate) {
|
736
|
+
var This = this;
|
737
|
+
This._stop();
|
738
|
+
This.isMock = 1;
|
739
|
+
This.mockEnvInfo = null;
|
740
|
+
This.buffers = [pcmData];
|
741
|
+
This.recSize = pcmData.length;
|
742
|
+
This[srcSampleRateTxt] = pcmSampleRate;
|
743
|
+
return This;
|
744
|
+
},
|
745
|
+
envCheck: function(envInfo) {
|
746
|
+
var errMsg, This = this, set = This.set;
|
747
|
+
var tag = "CPU_BE";
|
748
|
+
if (!errMsg && !Recorder[tag] && window.Int8Array && !new Int8Array(new Int32Array([1]).buffer)[0]) {
|
749
|
+
Traffic(tag);
|
750
|
+
errMsg = "\u4E0D\u652F\u6301" + tag + "\u67B6\u6784";
|
751
|
+
}
|
752
|
+
if (!errMsg) {
|
753
|
+
var type = set.type;
|
754
|
+
if (This[type + "_envCheck"]) {
|
755
|
+
errMsg = This[type + "_envCheck"](envInfo, set);
|
756
|
+
} else {
|
757
|
+
if (set.takeoffEncodeChunk) {
|
758
|
+
errMsg = type + "\u7C7B\u578B" + (This[type] ? "" : "(\u672A\u52A0\u8F7D\u7F16\u7801\u5668)") + "\u4E0D\u652F\u6301\u8BBE\u7F6EtakeoffEncodeChunk";
|
759
|
+
}
|
760
|
+
}
|
761
|
+
}
|
762
|
+
return errMsg || "";
|
763
|
+
},
|
764
|
+
envStart: function(mockEnvInfo, sampleRate) {
|
765
|
+
var This = this, set = This.set;
|
766
|
+
This.isMock = mockEnvInfo ? 1 : 0;
|
767
|
+
This.mockEnvInfo = mockEnvInfo;
|
768
|
+
This.buffers = [];
|
769
|
+
This.recSize = 0;
|
770
|
+
This.envInLast = 0;
|
771
|
+
This.envInFirst = 0;
|
772
|
+
This.envInFix = 0;
|
773
|
+
This.envInFixTs = [];
|
774
|
+
var setSr = set[sampleRateTxt];
|
775
|
+
if (setSr > sampleRate) {
|
776
|
+
set[sampleRateTxt] = sampleRate;
|
777
|
+
} else {
|
778
|
+
setSr = 0;
|
779
|
+
}
|
780
|
+
This[srcSampleRateTxt] = sampleRate;
|
781
|
+
This.CLog(
|
782
|
+
srcSampleRateTxt + ": " + sampleRate + " set." + sampleRateTxt + ": " + set[sampleRateTxt] + (setSr ? " \u5FFD\u7565" + setSr : ""),
|
783
|
+
setSr ? 3 : 0
|
784
|
+
);
|
785
|
+
This.engineCtx = 0;
|
786
|
+
if (This[set.type + "_start"]) {
|
787
|
+
var engineCtx = This.engineCtx = This[set.type + "_start"](set);
|
788
|
+
if (engineCtx) {
|
789
|
+
engineCtx.pcmDatas = [];
|
790
|
+
engineCtx.pcmSize = 0;
|
791
|
+
}
|
792
|
+
}
|
793
|
+
},
|
794
|
+
envResume: function() {
|
795
|
+
this.envInFixTs = [];
|
796
|
+
},
|
797
|
+
envIn: function(pcm, sum) {
|
798
|
+
var This = this, set = This.set, engineCtx = This.engineCtx;
|
799
|
+
var bufferSampleRate = This[srcSampleRateTxt];
|
800
|
+
var size = pcm.length;
|
801
|
+
var powerLevel = Recorder.PowerLevel(sum, size);
|
802
|
+
var buffers = This.buffers;
|
803
|
+
var bufferFirstIdx = buffers.length;
|
804
|
+
buffers.push(pcm);
|
805
|
+
var buffersThis = buffers;
|
806
|
+
var bufferFirstIdxThis = bufferFirstIdx;
|
807
|
+
var now = Date.now();
|
808
|
+
var pcmTime = Math.round(size / bufferSampleRate * 1e3);
|
809
|
+
This.envInLast = now;
|
810
|
+
if (This.buffers.length == 1) {
|
811
|
+
This.envInFirst = now - pcmTime;
|
812
|
+
}
|
813
|
+
var envInFixTs = This.envInFixTs;
|
814
|
+
envInFixTs.splice(0, 0, { t: now, d: pcmTime });
|
815
|
+
var tsInStart = now, tsPcm = 0;
|
816
|
+
for (var i = 0; i < envInFixTs.length; i++) {
|
817
|
+
var o = envInFixTs[i];
|
818
|
+
if (now - o.t > 3e3) {
|
819
|
+
envInFixTs.length = i;
|
820
|
+
break;
|
821
|
+
}
|
822
|
+
tsInStart = o.t;
|
823
|
+
tsPcm += o.d;
|
824
|
+
}
|
825
|
+
var tsInPrev = envInFixTs[1];
|
826
|
+
var tsIn = now - tsInStart;
|
827
|
+
var lost = tsIn - tsPcm;
|
828
|
+
if (lost > tsIn / 3 && (tsInPrev && tsIn > 1e3 || envInFixTs.length >= 6)) {
|
829
|
+
var addTime = now - tsInPrev.t - pcmTime;
|
830
|
+
if (addTime > pcmTime / 5) {
|
831
|
+
var fixOpen = !set.disableEnvInFix;
|
832
|
+
This.CLog("[" + now + "]" + (fixOpen ? "" : "\u672A") + "\u8865\u507F" + addTime + "ms", 3);
|
833
|
+
This.envInFix += addTime;
|
834
|
+
if (fixOpen) {
|
835
|
+
var addPcm = new Int16Array(addTime * bufferSampleRate / 1e3);
|
836
|
+
size += addPcm.length;
|
837
|
+
buffers.push(addPcm);
|
838
|
+
}
|
839
|
+
}
|
840
|
+
}
|
841
|
+
var sizeOld = This.recSize, addSize = size;
|
842
|
+
var bufferSize = sizeOld + addSize;
|
843
|
+
This.recSize = bufferSize;
|
844
|
+
if (engineCtx) {
|
845
|
+
var chunkInfo = Recorder.SampleData(buffers, bufferSampleRate, set[sampleRateTxt], engineCtx.chunkInfo);
|
846
|
+
engineCtx.chunkInfo = chunkInfo;
|
847
|
+
sizeOld = engineCtx.pcmSize;
|
848
|
+
addSize = chunkInfo.data.length;
|
849
|
+
bufferSize = sizeOld + addSize;
|
850
|
+
engineCtx.pcmSize = bufferSize;
|
851
|
+
buffers = engineCtx.pcmDatas;
|
852
|
+
bufferFirstIdx = buffers.length;
|
853
|
+
buffers.push(chunkInfo.data);
|
854
|
+
bufferSampleRate = chunkInfo[sampleRateTxt];
|
855
|
+
}
|
856
|
+
var duration = Math.round(bufferSize / bufferSampleRate * 1e3);
|
857
|
+
var bufferNextIdx = buffers.length;
|
858
|
+
var bufferNextIdxThis = buffersThis.length;
|
859
|
+
var asyncEnd = function() {
|
860
|
+
var num = asyncBegin ? 0 : -addSize;
|
861
|
+
var hasClear2 = buffers[0] == null;
|
862
|
+
for (var i2 = bufferFirstIdx; i2 < bufferNextIdx; i2++) {
|
863
|
+
var buffer = buffers[i2];
|
864
|
+
if (buffer == null) {
|
865
|
+
hasClear2 = 1;
|
866
|
+
} else {
|
867
|
+
num += buffer.length;
|
868
|
+
if (engineCtx && buffer.length) {
|
869
|
+
This[set.type + "_encode"](engineCtx, buffer);
|
870
|
+
}
|
871
|
+
}
|
872
|
+
}
|
873
|
+
if (hasClear2 && engineCtx) {
|
874
|
+
var i2 = bufferFirstIdxThis;
|
875
|
+
if (buffersThis[0]) {
|
876
|
+
i2 = 0;
|
877
|
+
}
|
878
|
+
for (; i2 < bufferNextIdxThis; i2++) {
|
879
|
+
buffersThis[i2] = null;
|
880
|
+
}
|
881
|
+
}
|
882
|
+
if (hasClear2) {
|
883
|
+
num = asyncBegin ? addSize : 0;
|
884
|
+
buffers[0] = null;
|
885
|
+
}
|
886
|
+
if (engineCtx) {
|
887
|
+
engineCtx.pcmSize += num;
|
888
|
+
} else {
|
889
|
+
This.recSize += num;
|
890
|
+
}
|
891
|
+
};
|
892
|
+
var asyncBegin = 0, procTxt = "rec.set.onProcess";
|
893
|
+
try {
|
894
|
+
asyncBegin = set.onProcess(buffers, powerLevel, duration, bufferSampleRate, bufferFirstIdx, asyncEnd);
|
895
|
+
} catch (e) {
|
896
|
+
console.error(procTxt + "\u56DE\u8C03\u51FA\u9519\u662F\u4E0D\u5141\u8BB8\u7684\uFF0C\u9700\u4FDD\u8BC1\u4E0D\u4F1A\u629B\u5F02\u5E38", e);
|
897
|
+
}
|
898
|
+
var slowT = Date.now() - now;
|
899
|
+
if (slowT > 10 && This.envInFirst - now > 1e3) {
|
900
|
+
This.CLog(procTxt + "\u4F4E\u6027\u80FD\uFF0C\u8017\u65F6" + slowT + "ms", 3);
|
901
|
+
}
|
902
|
+
if (asyncBegin === true) {
|
903
|
+
var hasClear = 0;
|
904
|
+
for (var i = bufferFirstIdx; i < bufferNextIdx; i++) {
|
905
|
+
if (buffers[i] == null) {
|
906
|
+
hasClear = 1;
|
907
|
+
} else {
|
908
|
+
buffers[i] = new Int16Array(0);
|
909
|
+
}
|
910
|
+
}
|
911
|
+
if (hasClear) {
|
912
|
+
This.CLog("\u672A\u8FDB\u5165\u5F02\u6B65\u524D\u4E0D\u80FD\u6E05\u9664buffers", 3);
|
913
|
+
} else {
|
914
|
+
if (engineCtx) {
|
915
|
+
engineCtx.pcmSize -= addSize;
|
916
|
+
} else {
|
917
|
+
This.recSize -= addSize;
|
918
|
+
}
|
919
|
+
}
|
920
|
+
} else {
|
921
|
+
asyncEnd();
|
922
|
+
}
|
923
|
+
},
|
924
|
+
start: function() {
|
925
|
+
var This = this;
|
926
|
+
var isOpen = 1;
|
927
|
+
if (This.set.sourceStream) {
|
928
|
+
if (!This.Stream) {
|
929
|
+
isOpen = 0;
|
930
|
+
}
|
931
|
+
} else if (!Recorder.IsOpen()) {
|
932
|
+
isOpen = 0;
|
933
|
+
}
|
934
|
+
if (!isOpen) {
|
935
|
+
This.CLog("\u672Aopen", 1);
|
936
|
+
return;
|
937
|
+
}
|
938
|
+
var ctx = This._streamCtx();
|
939
|
+
This.CLog("start \u5F00\u59CB\u5F55\u97F3 " + CtxState(ctx));
|
940
|
+
This._stop();
|
941
|
+
This.state = 3;
|
942
|
+
This.envStart(null, ctx[sampleRateTxt]);
|
943
|
+
if (This._SO && This._SO + 1 != This._S) {
|
944
|
+
This.CLog("start\u88AB\u4E2D\u65AD", 3);
|
945
|
+
return;
|
946
|
+
}
|
947
|
+
This._SO = 0;
|
948
|
+
var end = function() {
|
949
|
+
if (This.state == 3) {
|
950
|
+
This.state = 1;
|
951
|
+
This.resume();
|
952
|
+
}
|
953
|
+
};
|
954
|
+
if (ctx.state == "suspended") {
|
955
|
+
var tag = "AudioContext resume: ";
|
956
|
+
This.CLog(tag + "wait...");
|
957
|
+
ctx.resume().then(function() {
|
958
|
+
This.CLog(tag + ctx.state);
|
959
|
+
end();
|
960
|
+
})[CatchTxt](function(e) {
|
961
|
+
This.CLog(tag + ctx.state + " \u53EF\u80FD\u65E0\u6CD5\u5F55\u97F3\uFF1A" + e.message, 1, e);
|
962
|
+
end();
|
963
|
+
});
|
964
|
+
} else {
|
965
|
+
end();
|
966
|
+
}
|
967
|
+
},
|
968
|
+
pause: function() {
|
969
|
+
var This = this;
|
970
|
+
if (This.state) {
|
971
|
+
This.state = 2;
|
972
|
+
This.CLog("pause");
|
973
|
+
delete This._streamStore().Stream._call[This.id];
|
974
|
+
}
|
975
|
+
},
|
976
|
+
resume: function() {
|
977
|
+
var This = this;
|
978
|
+
if (This.state) {
|
979
|
+
This.state = 1;
|
980
|
+
This.CLog("resume");
|
981
|
+
This.envResume();
|
982
|
+
var stream = This._streamStore().Stream;
|
983
|
+
stream._call[This.id] = function(pcm, sum) {
|
984
|
+
if (This.state == 1) {
|
985
|
+
This.envIn(pcm, sum);
|
986
|
+
}
|
987
|
+
};
|
988
|
+
ConnAlive(stream);
|
989
|
+
}
|
990
|
+
},
|
991
|
+
_stop: function(keepEngine) {
|
992
|
+
var This = this, set = This.set;
|
993
|
+
if (!This.isMock) {
|
994
|
+
This._S++;
|
995
|
+
}
|
996
|
+
if (This.state) {
|
997
|
+
This.pause();
|
998
|
+
This.state = 0;
|
999
|
+
}
|
1000
|
+
if (!keepEngine && This[set.type + "_stop"]) {
|
1001
|
+
This[set.type + "_stop"](This.engineCtx);
|
1002
|
+
This.engineCtx = 0;
|
1003
|
+
}
|
1004
|
+
},
|
1005
|
+
stop: function(True, False, autoClose) {
|
1006
|
+
var This = this, set = This.set, t1;
|
1007
|
+
var envInMS = This.envInLast - This.envInFirst, envInLen = envInMS && This.buffers.length;
|
1008
|
+
This.CLog(
|
1009
|
+
"stop \u548Cstart\u65F6\u5DEE" + (envInMS ? envInMS + "ms \u8865\u507F" + This.envInFix + "ms envIn:" + envInLen + " fps:" + (envInLen / envInMS * 1e3).toFixed(1) : "-") + " LM:" + Recorder.LM
|
1010
|
+
);
|
1011
|
+
var end = function() {
|
1012
|
+
This._stop();
|
1013
|
+
if (autoClose) {
|
1014
|
+
This.close();
|
1015
|
+
}
|
1016
|
+
};
|
1017
|
+
var err = function(msg) {
|
1018
|
+
This.CLog("\u7ED3\u675F\u5F55\u97F3\u5931\u8D25\uFF1A" + msg, 1);
|
1019
|
+
False && False(msg);
|
1020
|
+
end();
|
1021
|
+
};
|
1022
|
+
var ok = function(blob, duration2) {
|
1023
|
+
This.CLog("\u7ED3\u675F\u5F55\u97F3 \u7F16\u7801\u82B1" + (Date.now() - t1) + "ms \u97F3\u9891\u65F6\u957F" + duration2 + "ms \u6587\u4EF6\u5927\u5C0F" + blob.size + "b");
|
1024
|
+
if (set.takeoffEncodeChunk) {
|
1025
|
+
This.CLog("\u542F\u7528takeoffEncodeChunk\u540Estop\u8FD4\u56DE\u7684blob\u957F\u5EA6\u4E3A0\u4E0D\u63D0\u4F9B\u97F3\u9891\u6570\u636E", 3);
|
1026
|
+
} else if (blob.size < Math.max(100, duration2 / 2)) {
|
1027
|
+
err("\u751F\u6210\u7684" + set.type + "\u65E0\u6548");
|
1028
|
+
return;
|
1029
|
+
}
|
1030
|
+
True && True(blob, duration2);
|
1031
|
+
end();
|
1032
|
+
};
|
1033
|
+
if (!This.isMock) {
|
1034
|
+
var isCtxWait = This.state == 3;
|
1035
|
+
if (!This.state || isCtxWait) {
|
1036
|
+
err("\u672A\u5F00\u59CB\u5F55\u97F3" + (isCtxWait ? "\uFF0C\u5F00\u59CB\u5F55\u97F3\u524D\u65E0\u7528\u6237\u4EA4\u4E92\u5BFC\u81F4AudioContext\u672A\u8FD0\u884C" : ""));
|
1037
|
+
return;
|
1038
|
+
}
|
1039
|
+
This._stop(true);
|
1040
|
+
}
|
1041
|
+
var size = This.recSize;
|
1042
|
+
if (!size) {
|
1043
|
+
err("\u672A\u91C7\u96C6\u5230\u5F55\u97F3");
|
1044
|
+
return;
|
1045
|
+
}
|
1046
|
+
if (!This.buffers[0]) {
|
1047
|
+
err("\u97F3\u9891buffers\u88AB\u91CA\u653E");
|
1048
|
+
return;
|
1049
|
+
}
|
1050
|
+
if (!This[set.type]) {
|
1051
|
+
err("\u672A\u52A0\u8F7D" + set.type + "\u7F16\u7801\u5668");
|
1052
|
+
return;
|
1053
|
+
}
|
1054
|
+
if (This.isMock) {
|
1055
|
+
var checkMsg = This.envCheck(This.mockEnvInfo || { envName: "mock", canProcess: false });
|
1056
|
+
if (checkMsg) {
|
1057
|
+
err("\u5F55\u97F3\u9519\u8BEF\uFF1A" + checkMsg);
|
1058
|
+
return;
|
1059
|
+
}
|
1060
|
+
}
|
1061
|
+
var engineCtx = This.engineCtx;
|
1062
|
+
if (This[set.type + "_complete"] && engineCtx) {
|
1063
|
+
var duration = Math.round(engineCtx.pcmSize / set[sampleRateTxt] * 1e3);
|
1064
|
+
t1 = Date.now();
|
1065
|
+
This[set.type + "_complete"](
|
1066
|
+
engineCtx,
|
1067
|
+
function(blob) {
|
1068
|
+
ok(blob, duration);
|
1069
|
+
},
|
1070
|
+
err
|
1071
|
+
);
|
1072
|
+
return;
|
1073
|
+
}
|
1074
|
+
t1 = Date.now();
|
1075
|
+
var chunk = Recorder.SampleData(This.buffers, This[srcSampleRateTxt], set[sampleRateTxt]);
|
1076
|
+
set[sampleRateTxt] = chunk[sampleRateTxt];
|
1077
|
+
var res = chunk.data;
|
1078
|
+
var duration = Math.round(res.length / set[sampleRateTxt] * 1e3);
|
1079
|
+
This.CLog("\u91C7\u6837" + size + "->" + res.length + " \u82B1:" + (Date.now() - t1) + "ms");
|
1080
|
+
setTimeout(function() {
|
1081
|
+
t1 = Date.now();
|
1082
|
+
This[set.type](
|
1083
|
+
res,
|
1084
|
+
function(blob) {
|
1085
|
+
ok(blob, duration);
|
1086
|
+
},
|
1087
|
+
function(msg) {
|
1088
|
+
err(msg);
|
1089
|
+
}
|
1090
|
+
);
|
1091
|
+
});
|
1092
|
+
}
|
1093
|
+
};
|
1094
|
+
var WebM_Extract = function(inBytes, scope) {
|
1095
|
+
if (!scope.pos) {
|
1096
|
+
scope.pos = [0];
|
1097
|
+
scope.tracks = {};
|
1098
|
+
scope.bytes = [];
|
1099
|
+
}
|
1100
|
+
var tracks = scope.tracks, position = [scope.pos[0]];
|
1101
|
+
var endPos = function() {
|
1102
|
+
scope.pos[0] = position[0];
|
1103
|
+
};
|
1104
|
+
var sBL = scope.bytes.length;
|
1105
|
+
var bytes = new Uint8Array(sBL + inBytes.length);
|
1106
|
+
bytes.set(scope.bytes);
|
1107
|
+
bytes.set(inBytes, sBL);
|
1108
|
+
scope.bytes = bytes;
|
1109
|
+
if (!scope._ht) {
|
1110
|
+
readMatroskaVInt(bytes, position);
|
1111
|
+
readMatroskaBlock(bytes, position);
|
1112
|
+
if (!BytesEq(readMatroskaVInt(bytes, position), [24, 83, 128, 103])) {
|
1113
|
+
return;
|
1114
|
+
}
|
1115
|
+
readMatroskaVInt(bytes, position);
|
1116
|
+
while (position[0] < bytes.length) {
|
1117
|
+
var eid0 = readMatroskaVInt(bytes, position);
|
1118
|
+
var bytes0 = readMatroskaBlock(bytes, position);
|
1119
|
+
var pos0 = [0], audioIdx = 0;
|
1120
|
+
if (!bytes0)
|
1121
|
+
return;
|
1122
|
+
if (BytesEq(eid0, [22, 84, 174, 107])) {
|
1123
|
+
while (pos0[0] < bytes0.length) {
|
1124
|
+
var eid1 = readMatroskaVInt(bytes0, pos0);
|
1125
|
+
var bytes1 = readMatroskaBlock(bytes0, pos0);
|
1126
|
+
var pos1 = [0], track = { channels: 0, sampleRate: 0 };
|
1127
|
+
if (BytesEq(eid1, [174])) {
|
1128
|
+
while (pos1[0] < bytes1.length) {
|
1129
|
+
var eid2 = readMatroskaVInt(bytes1, pos1);
|
1130
|
+
var bytes2 = readMatroskaBlock(bytes1, pos1);
|
1131
|
+
var pos2 = [0];
|
1132
|
+
if (BytesEq(eid2, [215])) {
|
1133
|
+
var val = BytesInt(bytes2);
|
1134
|
+
track.number = val;
|
1135
|
+
tracks[val] = track;
|
1136
|
+
} else if (BytesEq(eid2, [131])) {
|
1137
|
+
var val = BytesInt(bytes2);
|
1138
|
+
if (val == 1)
|
1139
|
+
track.type = "video";
|
1140
|
+
else if (val == 2) {
|
1141
|
+
track.type = "audio";
|
1142
|
+
if (!audioIdx)
|
1143
|
+
scope.track0 = track;
|
1144
|
+
track.idx = audioIdx++;
|
1145
|
+
} else
|
1146
|
+
track.type = "Type-" + val;
|
1147
|
+
} else if (BytesEq(eid2, [134])) {
|
1148
|
+
var str = "";
|
1149
|
+
for (var i = 0; i < bytes2.length; i++) {
|
1150
|
+
str += String.fromCharCode(bytes2[i]);
|
1151
|
+
}
|
1152
|
+
track.codec = str;
|
1153
|
+
} else if (BytesEq(eid2, [225])) {
|
1154
|
+
while (pos2[0] < bytes2.length) {
|
1155
|
+
var eid3 = readMatroskaVInt(bytes2, pos2);
|
1156
|
+
var bytes3 = readMatroskaBlock(bytes2, pos2);
|
1157
|
+
if (BytesEq(eid3, [181])) {
|
1158
|
+
var val = 0, arr = new Uint8Array(bytes3.reverse()).buffer;
|
1159
|
+
if (bytes3.length == 4)
|
1160
|
+
val = new Float32Array(arr)[0];
|
1161
|
+
else if (bytes3.length == 8)
|
1162
|
+
val = new Float64Array(arr)[0];
|
1163
|
+
else
|
1164
|
+
CLog("WebM Track !Float", 1, bytes3);
|
1165
|
+
track[sampleRateTxt] = Math.round(val);
|
1166
|
+
} else if (BytesEq(eid3, [98, 100]))
|
1167
|
+
track.bitDepth = BytesInt(bytes3);
|
1168
|
+
else if (BytesEq(eid3, [159]))
|
1169
|
+
track.channels = BytesInt(bytes3);
|
1170
|
+
}
|
1171
|
+
}
|
1172
|
+
}
|
1173
|
+
}
|
1174
|
+
}
|
1175
|
+
scope._ht = 1;
|
1176
|
+
CLog("WebM Tracks", tracks);
|
1177
|
+
endPos();
|
1178
|
+
break;
|
1179
|
+
}
|
1180
|
+
}
|
1181
|
+
}
|
1182
|
+
var track0 = scope.track0;
|
1183
|
+
if (!track0)
|
1184
|
+
return;
|
1185
|
+
if (track0.bitDepth == 16 && /FLOAT/i.test(track0.codec)) {
|
1186
|
+
track0.bitDepth = 32;
|
1187
|
+
CLog("WebM 16\u653932\u4F4D", 3);
|
1188
|
+
}
|
1189
|
+
if (track0[sampleRateTxt] != scope[sampleRateTxt] || track0.bitDepth != 32 || track0.channels < 1 || !/(\b|_)PCM\b/i.test(track0.codec)) {
|
1190
|
+
scope.bytes = [];
|
1191
|
+
if (!scope.bad)
|
1192
|
+
CLog("WebM Track\u975E\u9884\u671F", 3, scope);
|
1193
|
+
scope.bad = 1;
|
1194
|
+
return -1;
|
1195
|
+
}
|
1196
|
+
var datas = [], dataLen = 0;
|
1197
|
+
while (position[0] < bytes.length) {
|
1198
|
+
var eid1 = readMatroskaVInt(bytes, position);
|
1199
|
+
var bytes1 = readMatroskaBlock(bytes, position);
|
1200
|
+
if (!bytes1)
|
1201
|
+
break;
|
1202
|
+
if (BytesEq(eid1, [163])) {
|
1203
|
+
var trackNo = bytes1[0] & 15;
|
1204
|
+
var track = tracks[trackNo];
|
1205
|
+
if (!track) {
|
1206
|
+
CLog("WebM !Track" + trackNo, 1, tracks);
|
1207
|
+
} else if (track.idx === 0) {
|
1208
|
+
var u8arr = new Uint8Array(bytes1.length - 4);
|
1209
|
+
for (var i = 4; i < bytes1.length; i++) {
|
1210
|
+
u8arr[i - 4] = bytes1[i];
|
1211
|
+
}
|
1212
|
+
datas.push(u8arr);
|
1213
|
+
dataLen += u8arr.length;
|
1214
|
+
}
|
1215
|
+
}
|
1216
|
+
endPos();
|
1217
|
+
}
|
1218
|
+
if (dataLen) {
|
1219
|
+
var more = new Uint8Array(bytes.length - scope.pos[0]);
|
1220
|
+
more.set(bytes.subarray(scope.pos[0]));
|
1221
|
+
scope.bytes = more;
|
1222
|
+
scope.pos[0] = 0;
|
1223
|
+
var u8arr = new Uint8Array(dataLen);
|
1224
|
+
for (var i = 0, i2 = 0; i < datas.length; i++) {
|
1225
|
+
u8arr.set(datas[i], i2);
|
1226
|
+
i2 += datas[i].length;
|
1227
|
+
}
|
1228
|
+
var arr = new Float32Array(u8arr.buffer);
|
1229
|
+
if (track0.channels > 1) {
|
1230
|
+
var arr2 = [];
|
1231
|
+
for (var i = 0; i < arr.length; ) {
|
1232
|
+
arr2.push(arr[i]);
|
1233
|
+
i += track0.channels;
|
1234
|
+
}
|
1235
|
+
arr = new Float32Array(arr2);
|
1236
|
+
}
|
1237
|
+
return arr;
|
1238
|
+
}
|
1239
|
+
};
|
1240
|
+
var BytesEq = function(bytes1, bytes2) {
|
1241
|
+
if (!bytes1 || bytes1.length != bytes2.length)
|
1242
|
+
return false;
|
1243
|
+
if (bytes1.length == 1)
|
1244
|
+
return bytes1[0] == bytes2[0];
|
1245
|
+
for (var i = 0; i < bytes1.length; i++) {
|
1246
|
+
if (bytes1[i] != bytes2[i])
|
1247
|
+
return false;
|
1248
|
+
}
|
1249
|
+
return true;
|
1250
|
+
};
|
1251
|
+
var BytesInt = function(bytes) {
|
1252
|
+
var s = "";
|
1253
|
+
for (var i = 0; i < bytes.length; i++) {
|
1254
|
+
var n = bytes[i];
|
1255
|
+
s += (n < 16 ? "0" : "") + n.toString(16);
|
1256
|
+
}
|
1257
|
+
return parseInt(s, 16) || 0;
|
1258
|
+
};
|
1259
|
+
var readMatroskaVInt = function(arr, pos, trim) {
|
1260
|
+
var i = pos[0];
|
1261
|
+
if (i >= arr.length)
|
1262
|
+
return;
|
1263
|
+
var b0 = arr[i], b2 = ("0000000" + b0.toString(2)).substr(-8);
|
1264
|
+
var m = /^(0*1)(\d*)$/.exec(b2);
|
1265
|
+
if (!m)
|
1266
|
+
return;
|
1267
|
+
var len = m[1].length, val = [];
|
1268
|
+
if (i + len > arr.length)
|
1269
|
+
return;
|
1270
|
+
for (var i2 = 0; i2 < len; i2++) {
|
1271
|
+
val[i2] = arr[i];
|
1272
|
+
i++;
|
1273
|
+
}
|
1274
|
+
if (trim)
|
1275
|
+
val[0] = parseInt(m[2] || "0", 2);
|
1276
|
+
pos[0] = i;
|
1277
|
+
return val;
|
1278
|
+
};
|
1279
|
+
var readMatroskaBlock = function(arr, pos) {
|
1280
|
+
var lenVal = readMatroskaVInt(arr, pos, 1);
|
1281
|
+
if (!lenVal)
|
1282
|
+
return;
|
1283
|
+
var len = BytesInt(lenVal);
|
1284
|
+
var i = pos[0], val = [];
|
1285
|
+
if (len < 2147483647) {
|
1286
|
+
if (i + len > arr.length)
|
1287
|
+
return;
|
1288
|
+
for (var i2 = 0; i2 < len; i2++) {
|
1289
|
+
val[i2] = arr[i];
|
1290
|
+
i++;
|
1291
|
+
}
|
1292
|
+
}
|
1293
|
+
pos[0] = i;
|
1294
|
+
return val;
|
1295
|
+
};
|
1296
|
+
Recorder.TrafficImgUrl = "//ia.51.la/go1?id=20469973&pvFlag=1";
|
1297
|
+
var Traffic = Recorder.Traffic = function(report) {
|
1298
|
+
report = report ? "/" + RecTxt + "/Report/" + report : "";
|
1299
|
+
var imgUrl = Recorder.TrafficImgUrl;
|
1300
|
+
if (imgUrl) {
|
1301
|
+
var data = Recorder.Traffic;
|
1302
|
+
var m = /^(https?:..[^\/#]*\/?)[^#]*/i.exec(location.href) || [];
|
1303
|
+
var host = m[1] || "http://file/";
|
1304
|
+
var idf = (m[0] || host) + report;
|
1305
|
+
if (imgUrl.indexOf("//") == 0) {
|
1306
|
+
if (/^https:/i.test(idf)) {
|
1307
|
+
imgUrl = "https:" + imgUrl;
|
1308
|
+
} else {
|
1309
|
+
imgUrl = "http:" + imgUrl;
|
1310
|
+
}
|
1311
|
+
}
|
1312
|
+
if (report) {
|
1313
|
+
imgUrl = imgUrl + "&cu=" + encodeURIComponent(host + report);
|
1314
|
+
}
|
1315
|
+
if (!data[idf]) {
|
1316
|
+
data[idf] = 1;
|
1317
|
+
var img = new Image();
|
1318
|
+
img.src = imgUrl;
|
1319
|
+
CLog("Traffic Analysis Image: " + (report || RecTxt + ".TrafficImgUrl=" + Recorder.TrafficImgUrl));
|
1320
|
+
}
|
1321
|
+
}
|
1322
|
+
};
|
1323
|
+
|
1324
|
+
export { Recorder as default };
|