title: How to send video (from getUserMedia) to Node.js server?
body: <p>I'm looking to build a chat/live stream application (video + text chat). I'm not settled on an approach at the moment, but I'm moving forward with one, and I've gotten stuck.</p>
  
  <p>I'm trying to grab the video stream using getUserMedia, and send it to my Node.js server over Socket.io.</p>
  
  <p>So far I've got the blob url: <code>"mediastream:http://192.168.1.20:3000/1c267861-a2da-41df-9a83-ae69fdfd883b"</code> but I'm not sure how to grab the data from it to send over socket.io.</p>
  
  <p>Any help would rock.</p>
  
  <p>Server:</p>
  
  <pre><code>// server.js
  
  var http = require('http');
  var socketio = require('socket.io')
  var fs = require('fs');
  
  var server = http.createServer(function (req, res) {
    if (req.url ==='/') {
      fs.readFile('index.html', function (err, html) {
        res.writeHeader(200, {"Content-Type": "text/html"});
        res.write(html);
        return res.end();
      });
    } else {
      res.end('hi!');
    }
  });
  
  var io = socketio(server);
  
  server.listen(8000, function () {
    console.log('Jumping on port 8000!');
  });
  
  io.on('connection', function (socket) {
    socket.emit('news', { hello: 'world' });
    socket.on('my other event', function (data) {
      console.log(data);
    });
    socket.on('video', function (video) {
      console.log(video);
    });
  });
  </code></pre>
  
  <p>Client:</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html lang="en"&gt;
    &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;title&gt;Video Café&lt;/title&gt;
      &lt;meta name="description" content="A place online where we can get together and chat..."&gt;
      &lt;meta name="viewport" content="width=device-width"&gt;
      &lt;style type="text/css"&gt;
        *, *::before, *::after {box-sizing: border-box}
        body {padding: 1em;}
        h1, div {text-align: center; margin: 1em auto;}
        #localVideo {
          width: calc(50% - 2em);
          margin: 1em auto;
        }
      &lt;/style&gt;
      &lt;script src="/socket.io/socket.io.js"&gt;&lt;/script&gt;
      &lt;script&gt;
        ;(function () {
          "use strict";
          window.addEventListener('load', function (event) {
            var socket = io('http://localhost');
            socket.on('news', function (data) {
              console.log(data);
              socket.emit('my other event', { my: 'data' });
            });
  
            // Shims
            var PeerConnection = window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
            var IceCandidate = window.mozRTCIceCandidate || window.RTCIceCandidate;
            var SessionDescription = window.mozRTCSessionDescription || window.RTCSessionDescription;
            navigator.getUserMedia = navigator.getUserMedia || navigator.mozGetUserMedia || navigator.webkitGetUserMedia;
  
            document.getElementById('startButton').addEventListener('click', function (event) {
              console.log('working...');
              navigator.getUserMedia({
                video: true,
                audio: true
              }, function (localMediaStream) {
                var blob = window.URL.createObjectURL(localMediaStream);
                window.stream = localMediaStream; // stream available to console
                var video = document.getElementById('localVideo');
                video.src = blob;
                video.play();
                // Send localstream to node
                console.log(blob);
                socket.emit('video', { my: blob });
              }, function (error){
                console.log("navigator.getUserMedia error: ", error);
              });
            }, false);
  
            // var pc = new RTCPeerConnection(null);
            // pc.onaddstream = gotRemoteStream;
            // pc.addStream(localStream);
            // pc.createOffer(gotOffer);
  
            // function gotOffer(desc) {
            //   pc.setLocalDescription(desc);
            //   sendOffer(desc);
            // }
  
            // function gotAnswer(desc) {
            //   pc.setRemoteDescription(desc);
            // }
  
            // function gotRemoteStream(e) {
            //   attachMediaStream(remoteVideo, e.stream);
            // }
  
  
          }, false);
        }());
      &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;h1&gt;Video Café&lt;/h1&gt;
      &lt;video id="localVideo" muted autoplay&gt;&lt;/video&gt;
      &lt;video id="remoteVideo" autoplay&gt;&lt;/video&gt;
      &lt;div&gt;
        &lt;button id="startButton"&gt;Start&lt;/button&gt;
        &lt;button id="callButton"&gt;Call&lt;/button&gt;
        &lt;button id="hangupButton"&gt;Hang Up&lt;/button&gt;
      &lt;/div&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>