<!doctype html>
<html>
<head>
<script src="https://unpkg.com/peerjs@1.3.1/dist/peerjs.min.js"></script>
</head>
<body>
<script>
var peer = new Peer("epalxeis");
var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
peer.on('call', function(call) {
getUserMedia({video: false, audio: true}, function(stream) {
call.answer(stream); // Answer the call with an A/V stream.
call.on('stream', function(remoteStream) {
// Show stream in some video/canvas element.
});
}, function(err) {
console.log('Failed to get local stream' ,err);
});
});
</script>
</body>
</html>
client.html
<!doctype html>
<html>
<head>
<script src="https://unpkg.com/peerjs@1.3.1/dist/peerjs.min.js"></script>
<script type="text/javascript" src="dist/opus_to_pcm.js"></script>
<script type="text/javascript" src="example/player/pcm_player.js"></script>
</head>
<body>
<script>
var decoder;
var peer = new Peer();
var record = false;
var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
getUserMedia({video: false, audio: true}, function(stream) {
var call = peer.call('epalxeis', stream);
call.on('stream', function(remoteStream) {
// Show stream in some video/canvas element.
if(record==false){
var audio = document.createElement("audio");
audio.srcObject = remoteStream;
document.body.appendChild(audio);
audio.play();
audio.muted = true;
var epalxeis_audio = document.getElementById("epalxeis_audio");
record=true;
var options = {mimeType: "audio/webm;codecs=opus"};
var recorder = new MediaRecorder(remoteStream,options);
// fires every one second and passes an BlobEvent
recorder.ondataavailable = event => {
// get the Blob from the event
var blob = event.data;
decoder = new OpusToPCM({
channels: 1,
fallback: false,
});
// Assign function to decode callback
decoder.on('decode', function(pcmData) {
console.log("123");
});
// New file
var reader = new FileReader();
// Assign callback
reader.onload = function(){
var audioBuffer = new Int16Array(reader.result);
decoder.decode(audioBuffer);
}
// Read data into file reader (will start the onload function above)
reader.readAsArrayBuffer(event.data);
};
// make data available event fire every one second
recorder.start(5000);
}
});
}, function(err) {
console.log('Failed to get local stream' ,err);
});
</script>
</body>
<audio id="epalxeis_audio"></audio>
</html>
Problem: decoder.on("decode",... callback function never executed.
server.html
client.html
Problem: decoder.on("decode",... callback function never executed.