title: node.js - share sync mp3 stream to several clients
body: <p>I'm using binary.js (<a href="http://binaryjs.com/" rel="nofollow">http://binaryjs.com/</a>) to stream mp3 file to several clients. </p>
  
  <p>Server just starts to stream mp3 and what I want to achieve is that when client connects it starts to broadcast the stream not from the beginning but from the specific point of time in which playback is currently positioned. Some kind of synchronized playback for all clients.</p>
  
  <p>Server:</p>
  
  <pre><code>var BinaryServer = require('binaryjs').BinaryServer;
  var fs = require('fs');
  var server = require('http').createServer(handler);
  
  server.listen(9000);
  
  function handler (req, res) {
    fs.readFile(__dirname + '/index.html',
    function (err, data) {
      if (err) {
        res.writeHead(500);
        return res.end('Error loading index.html');
      }
      res.writeHead(200);
      res.end(data);
    });
  }
  
  var binaryserver = BinaryServer({server: server});
  binaryserver.on('connection', function (client) {
    var trackStream = fs.createReadStream(__dirname + '/longAudio.mp3');
    client.send(trackStream);
  });
  </code></pre>
  
  <p>Client:</p>
  
  <pre><code>var client = new BinaryClient('ws://localhost:9000');
  client.on('stream', function (stream, meta) {
    var parts = [];
    stream.on('data', function(data){
      parts.push(data);
    });
    stream.on('end', function () {
      var audio = document.createElement('audio');
      audio.src = (window.URL || window.webkitURL).createObjectURL(new Blob(parts));
      audio.controls = 'controls';
      document.body.appendChild(audio);
    });
  });
  </code></pre>
  
  <p>Is there a way to implement this?</p>