@94ai/softphone 5.0.10 → 5.0.12
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/html-softphone-demo/WebrtcDiver.js +320 -0
- package/html-softphone-demo/embed-ui/index.html +77 -0
- package/html-softphone-demo/embed-ui/softphone.js +465 -0
- package/html-softphone-demo/embed-ui/util.js +123 -0
- package/html-softphone-demo/index-channel.html +904 -0
- package/html-softphone-demo/index-local.html +3 -10
- package/html-softphone-demo/index-switch-pcm.html +613 -0
- package/html-softphone-demo/{index-other.html → index-test.html} +10 -3
- package/html-softphone-demo/index.html +46 -27
- package/html-softphone-demo/micro-call-ui/CryptoJS.js +3 -0
- package/html-softphone-demo/micro-call-ui/index.html +75 -0
- package/html-softphone-demo/micro-call-ui/microphone.js +829 -0
- package/html-softphone-demo/micro-call-ui/qiankun.js +2 -0
- package/html-softphone-demo/micro-call-ui/util.js +17 -0
- package/html-softphone-demo/micro-call-ui/wujie.js +3 -0
- package/html-softphone-demo/pcm-server/16bit-44100.pcm +0 -0
- package/html-softphone-demo/pcm-server/index.html +110 -0
- package/html-softphone-demo/pcm-server/server.js +54 -0
- package/html-softphone-demo/softphone.umd.min.js +1 -2
- package/html-softphone-demo.7z +0 -0
- package/lib/index.d.ts +1 -1
- package/lib/softphone.cjs.min.cjs +1 -1
- package/lib/softphone.esm-bundler.min.mjs +1 -1
- package/lib/softphone.umd.min.js +1 -2
- package/package.json +1 -1
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8">
|
|
6
|
+
<title>PCM player</title>
|
|
7
|
+
<style>
|
|
8
|
+
.visualizer{
|
|
9
|
+
width: 400px;
|
|
10
|
+
height:200px;
|
|
11
|
+
}
|
|
12
|
+
</style>
|
|
13
|
+
</head>
|
|
14
|
+
|
|
15
|
+
<body>
|
|
16
|
+
<div id="container"
|
|
17
|
+
style="width: 400px; margin: 0 auto;">
|
|
18
|
+
<button onclick="loadPCM()">PlayPCM</button>
|
|
19
|
+
<input type="range"
|
|
20
|
+
max="1"
|
|
21
|
+
value="0.1"
|
|
22
|
+
min="0"
|
|
23
|
+
id="range"
|
|
24
|
+
onchange="changeVolume(event)"
|
|
25
|
+
step="0.1"><br />
|
|
26
|
+
<button onclick="pause()">PausePlaying</button>
|
|
27
|
+
<button onclick="continuePlay()">ContinuePlaying</button>
|
|
28
|
+
<canvas class="visualizer"></canvas>
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
<script src="./dist/index.js"></script>
|
|
32
|
+
<script>
|
|
33
|
+
let player
|
|
34
|
+
window.loadPCM = function loadPCM() {
|
|
35
|
+
var socketURL = 'ws://23.94.99.218:8899';
|
|
36
|
+
// 这是我搭载自己服务器上的server端,用来接收pcm数据
|
|
37
|
+
// 如果起了example里面的本地server端,改成对应的ws地址就行了
|
|
38
|
+
// var socketURL = 'wss://pkjy.xyz/websocket';
|
|
39
|
+
|
|
40
|
+
player = new PCMPlayer({
|
|
41
|
+
inputCodec: 'Int16',
|
|
42
|
+
channels: 2,
|
|
43
|
+
sampleRate: 44100,
|
|
44
|
+
flushTime: 200
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
var ws = new WebSocket(socketURL);
|
|
48
|
+
ws.binaryType = 'arraybuffer';
|
|
49
|
+
ws.addEventListener('message', function (event) {
|
|
50
|
+
// 可以传 ArrayBuffer 或者 任意TypedArray
|
|
51
|
+
player.feed(event.data);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// 绘制波形图
|
|
55
|
+
const bufferLength = player.analyserNode.frequencyBinCount;
|
|
56
|
+
const dataArray = new Uint8Array(bufferLength);
|
|
57
|
+
player.analyserNode.getByteTimeDomainData(dataArray);
|
|
58
|
+
|
|
59
|
+
function draw() {
|
|
60
|
+
drawVisual = requestAnimationFrame(draw);
|
|
61
|
+
|
|
62
|
+
player.analyserNode.getByteTimeDomainData(dataArray);
|
|
63
|
+
|
|
64
|
+
const canvas = document.querySelector(".visualizer");
|
|
65
|
+
const canvasCtx = canvas.getContext('2d')
|
|
66
|
+
const WIDTH = canvas.width,HEIGHT=canvas.height
|
|
67
|
+
canvasCtx.fillStyle = "rgb(200 200 200)";
|
|
68
|
+
canvasCtx.fillRect(0, 0, WIDTH, HEIGHT);
|
|
69
|
+
|
|
70
|
+
canvasCtx.lineWidth = 2;
|
|
71
|
+
canvasCtx.strokeStyle = "rgb(0 0 0)";
|
|
72
|
+
|
|
73
|
+
canvasCtx.beginPath();
|
|
74
|
+
|
|
75
|
+
const sliceWidth = (WIDTH * 1.0) / bufferLength;
|
|
76
|
+
let x = 0;
|
|
77
|
+
|
|
78
|
+
for (let i = 0; i < bufferLength; i++) {
|
|
79
|
+
const v = dataArray[i] / 128.0;
|
|
80
|
+
const y = (v * HEIGHT) / 2;
|
|
81
|
+
|
|
82
|
+
if (i === 0) {
|
|
83
|
+
canvasCtx.moveTo(x, y);
|
|
84
|
+
} else {
|
|
85
|
+
canvasCtx.lineTo(x, y);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
x += sliceWidth;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
canvasCtx.lineTo(WIDTH, HEIGHT / 2);
|
|
92
|
+
canvasCtx.stroke();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
draw();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
window.changeVolume = function changeVolume(e) {
|
|
99
|
+
player.volume(document.querySelector('#range').value)
|
|
100
|
+
}
|
|
101
|
+
window.pause = async function pause() {
|
|
102
|
+
await player.pause()
|
|
103
|
+
}
|
|
104
|
+
window.continuePlay = function continuePlay() {
|
|
105
|
+
player.continue()
|
|
106
|
+
}
|
|
107
|
+
</script>
|
|
108
|
+
</body>
|
|
109
|
+
|
|
110
|
+
</html>
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const WebSocket = require('ws');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
|
|
4
|
+
const pcm_file = './16bit-44100.pcm';
|
|
5
|
+
let interval = 0,
|
|
6
|
+
sampleRate = 44100,
|
|
7
|
+
bytePerSample = 2,
|
|
8
|
+
channels = 2,
|
|
9
|
+
bytesChunk = (sampleRate * bytePerSample * channels),
|
|
10
|
+
offset = 0,
|
|
11
|
+
pcmData,
|
|
12
|
+
wss;
|
|
13
|
+
|
|
14
|
+
fs.readFile(pcm_file, (err, data) => {
|
|
15
|
+
if (err) throw err;
|
|
16
|
+
pcmData = data;
|
|
17
|
+
openSocket();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
function openSocket() {
|
|
22
|
+
wss = new WebSocket.Server({ port: 8899 });
|
|
23
|
+
console.log('Server ready...');
|
|
24
|
+
wss.on('connection', function connection(ws) {
|
|
25
|
+
ws.on('error', function (error) {
|
|
26
|
+
console.log('disconnected 断开连接')
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
console.log('Socket connected. sending data... ws已连接 发送数据');
|
|
30
|
+
if (interval) {
|
|
31
|
+
clearInterval(interval);
|
|
32
|
+
}
|
|
33
|
+
interval = setInterval(function () {
|
|
34
|
+
sendData();
|
|
35
|
+
}, 500);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function sendData() {
|
|
40
|
+
let payload;
|
|
41
|
+
if (offset >= pcmData.length) {
|
|
42
|
+
clearInterval(interval);
|
|
43
|
+
offset = 0;
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
payload = pcmData.subarray(offset, (offset + bytesChunk));
|
|
48
|
+
offset += bytesChunk;
|
|
49
|
+
wss.clients.forEach(function each(client) {
|
|
50
|
+
if (client.readyState === WebSocket.OPEN) {
|
|
51
|
+
client.send(payload);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|