I am trying to send video and audio trought socket.io but I geting Buffer on the end how should I handle it?
Here is my code:
SERVER, HERE I RECIVE BUFFER:
io.on('connection', function (socket) {
socket.on('radio', function (image) {
socket.broadcast.emit('radio-reciver', {count: 1, buff: image});
})
})
http.listen(port, function () {
console.log('Server started!')
});
CLIENT:
//PART FOR SENDING VIDEO/AUDIO
navigator.getUserMedia({ video: true, audio: true }, loadCam, loadFail)
function loadCam(stream) {
video.src = window.URL.createObjectURL(stream);
var media = new MediaRecorder(stream);
media.ondataavailable = function (e) {
socket.emit('radio', e.data);
}
media.start(1000)
logger("Cam is ok")
}
//PART FOR RECIVING, HERE I RECIVE BUFFER
socket.on('radio-reciver', function (image) {
var sourceStream = MediaSourceStream({ // Creates a writable stream
mimeType: 'video/webm; codecs="opus,vp8"'
})
image.pipe(sourceStream)
var img = document.getElementById('play');
img.src = window.URL.createObjectURL(sourceStream.mediaSource);
$('#logger').text(image);
})
As you see I am using media recorder to transfer data but not working... Any example how to fix this?
Rather than doing image.pipe()
, you should probably use:
sourceStream.write(image);
You're going to be receiving chunks here, as Buffer objects. Not a stream.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With