title: NodeJS and RED 5 media server via RTMP
body: <p>This is more a conceptual question rather than a direct "how to do this". </p>
  
  <p><em>Is it generally possible to implement a flash-like solution to stream the audio (independent of where we get the stream data from, e.g. webRTC or other) in HTML5 and nodeJS/binaryJS. If so, how would you go about this?</em></p>
  
  <p>There has been only one inquire on stackoverflow <a href="https://stackoverflow.com/questions/11891818/rtmp-implementation-in-nodejs-is-possible">found here</a> and its from 2010. NodeJS and HTML5 have grown and matured since then.</p>
  
  <p><strong>What people usually do:</strong>
  When using multimedia streaming (i.e. video or audio) to a server, there is definitely nothing that beats Flash at the current point in time till the full arrival of <a href="http://dev.w3.org/2011/webrtc/editor/getusermedia.html" rel="noreferrer">getUserMedia()</a> - which quite honestly might <a href="http://caniuse.com/#search=getusermedia" rel="noreferrer">take a while</a> till 99% of the browser users will get to use it at all.</p>
  
  <p>General practice to stream data to the server is by using a client Flash or Flex application which is then connecting to a RTMP protocol powered media server like <a href="http://www.red5.org/" rel="noreferrer">RED5</a>, <a href="http://www.adobe.com/products/adobe-media-server-family.html" rel="noreferrer">FMS</a> or <a href="http://www.wowza.com" rel="noreferrer">Wowza</a>. For example, the client app sending the microphone input over RTMP could look like (simplified version)</p>
  
  <pre><code>import flash.net.NetStream;
  
  private var myMic:Microphone;
  private var nc:NetConnection;
  private var ns:NetStream
  
  nc = new NetConnection();    
  ns = new NetStream(nc);
  nc.connect(rtmp://localhost/serverApp);
  myMic = Microphone.getMicrophone();
  ns.attachAudio(myMic);
  </code></pre>
  
  <p>Together with a server application one is easibly able to stream data to the server.</p>
  
  <p><strong>What I would like to do:</strong>
  Have an app server running on <a href="http://nodejs.org/" rel="noreferrer">nodeJS</a> (possibly implementing <a href="http://socket.io/" rel="noreferrer">socketIO</a> and <a href="http://binaryjs.com/" rel="noreferrer">binaryJS</a>) that catches the incoming RTMP stream. Something like</p>
  
  <pre><code>//require
  var rtmp = require('node-rtmp'),
  var fs = require('fs');
  
  //rtmp server address
  var rtmpServer = 'rtmp://localhost';
  
  //create a binary server listening that receives stream data
  var RTMPServer = rtmp.RTMPServer();
  var server = RTMPServer ({port: 1935});
  
  server.on('connection', function(client){
   //check if user is allowed to do so
   rtmp.newStream(client.stream);
  });
  </code></pre>
  
  <p>Possibly it might be better to use socketIO to differentiate between user interactions via eventEmitters.</p>
  
  <p><strong>What might be the advantages:</strong> Generally speaking it seems like a bit overhead to make this kind of approach, but for me there might be advantages and I'd also like you to comment on this.</p>
  
  <ul>
  <li>easy validation of user interaction by running e.g. <a href="http://expressjs.com/" rel="noreferrer">express</a> and socketIO</li>
  <li>hybrid implementation of a flash (via RTMP) and getUserMedia() (via binary transport mechanisms by adding binaryJS and the Mozilla AudioAPI)</li>
  <li>if getUserMedia() gets fully supported, flash implementations can be dropped easily</li>
  <li>more control over the rtmp followup and user interaction in general</li>
  <li>easier implementation into server frameworks</li>
  </ul>
  
  <p><strong>UPDATE:</strong>
  I've talked to Mr. Malcontenti-Wilson who is responsible for the <a href="https://github.com/adammw/node-rtmp" rel="noreferrer">only node-rtmp package</a> that was written but discontinued 8 months ago as it was poorly written and he hit a roadblock. Anyone who used this or was able to check the code?</p>
  
  <p><strong>UPDATE 2:</strong>
  Mr. Malcontenti-Wilson just send me a mail to get my attention to <a href="https://github.com/nalply/mtrude" rel="noreferrer">node-mtrude</a> (kind of an odd name) which is doing kind of what we would probably want. Has anyone work with this kind of package?</p>