5

i have create a socket connection and using that connection sending the binary stream data to server and on server side i am getting the binary data now using that data i want to create a video file and save it on server. i am reached successfully up to getting the binary data now not getting any way to convert it in a video file. please help to achieve .

on server side m using node.js to create socket server and from client side javascript

server side code :

var server = http.createServer(function(request, response) {
    //Creating websocket server
});
server.listen(1337, function() { }); // listen to 1337 port

// create the server
wsServer = new WebSocketServer({
    httpServer: server
});

// WebSocket server
wsServer.on('request', function(request) {
    var connection = request.accept(null, request.origin);

    // all messages from client will receive here.
    connection.on('message', function(message) {
      if (message.type === 'utf8') {

      }else if (message.type === 'binary') {
           //here i will get the binary data not want to create the video file using this
      }
    });

    connection.on('close', function(connection) {


    });

})

client side :

window.WebSocket = window.WebSocket || window.MozWebSocket;
    var connection = new WebSocket('ws://localhost:1337');
    connection.binaryType = 'arraybuffer';
    var options = {
      mimeType: 'video/webm;codecs=vp9'
    };

    mediaRecorder = new MediaRecorder(MediaStream, options);
    mediaRecorder.ondataavailable = function(event) {
      if (event.data.size > 0) {
        recordedChunks.push(event.data);
         connection.onopen = function () {
            var byteArray = new Uint8Array(event.data);
            connection.send(byteArray.buffer);
         };
      }
    };
2
  • Is the binary stream from a video file? Commented Nov 24, 2016 at 10:23
  • no i am recording the user action using chrome extension chrome.tabCapture.capture Commented Nov 24, 2016 at 10:25

1 Answer 1

1

i had achieved it successfully creating video file on server i had used recordRTC api to convert the video stream to dataurl and sending to server using socket.io and at server convert the dataurl to base64 and write it to the file.

here is my client side code.

socketio = io("ws://192.168.0.42:1337");
  recordVideo = RecordRTC(MediaStream, {type: 'video'});
  recordVideo.startRecording();
  onStopRecording();
  function onStopRecording(){
      recordVideo.stopRecording(function() {
        recordVideo.getDataURL(function(videoDataURL) {
                  var d = new Date();
                   var files = {
                       video: {
                           type: recordVideo.getBlob().type || 'video/webm',
                           dataURL: videoDataURL,
                           time : d.getTime()
                       }
                   };
                   socketio.emit('message', files);
         })
      });
  }

and from server side:

var server = http.createServer(function(request, response) {
    //Creating websocket server
});
server.listen(1337, function() { }); // listen to 1337 port


var wIoSocket = io.listen(server);
wIoSocket.sockets.on('connection', function (socket) {
    socket.on('message', function (data) {
        if (data.video) {
            writeToDisk(data.video.dataURL, data.video.time+'.webm');
        }
    });
});


function writeToDisk(dataURL, fileName) {
    var dataURL = dataURL.split(',').pop();
    var fileBuffer = new Buffer(dataURL, 'base64');
    fs.writeFileSync(fileName, fileBuffer);
}
Sign up to request clarification or add additional context in comments.

3 Comments

but in this method i still had to dependent for stopping the video recording to send the video stream. i want to send the video stream while recording.
Have you got your solution??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.