{"id":3402,"date":"2014-03-24T01:26:43","date_gmt":"2014-03-24T01:26:43","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/24\/nodejs-and-red-5-media-server-via-rtmp-collection-of-common-programming-errors\/"},"modified":"2014-03-24T01:26:43","modified_gmt":"2014-03-24T01:26:43","slug":"nodejs-and-red-5-media-server-via-rtmp-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/24\/nodejs-and-red-5-media-server-via-rtmp-collection-of-common-programming-errors\/","title":{"rendered":"NodeJS and RED 5 media server via RTMP-Collection of common programming errors"},"content":{"rendered":"<p>This is more a conceptual question rather than a direct &#8220;how to do this&#8221;.<\/p>\n<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>\n<p>There has been only one inquire on stackoverflow found here and its from 2010. NodeJS and HTML5 have grown and matured since then.<\/p>\n<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 getUserMedia() &#8211; which quite honestly might take a while till 99% of the browser users will get to use it at all.<\/p>\n<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 RED5, FMS or Wowza. For example, the client app sending the microphone input over RTMP could look like (simplified version)<\/p>\n<pre><code>import flash.net.NetStream;\n\nprivate var myMic:Microphone;\nprivate var nc:NetConnection;\nprivate var ns:NetStream\n\nnc = new NetConnection();    \nns = new NetStream(nc);\nnc.connect(rtmp:\/\/localhost\/serverApp);\nmyMic = Microphone.getMicrophone();\nns.attachAudio(myMic);\n<\/code><\/pre>\n<p>Together with a server application one is easibly able to stream data to the server.<\/p>\n<p><strong>What I would like to do:<\/strong> Have an app server running on nodeJS (possibly implementing socketIO and binaryJS) that catches the incoming RTMP stream. Something like<\/p>\n<pre><code>\/\/require\nvar rtmp = require('node-rtmp'),\nvar fs = require('fs');\n\n\/\/rtmp server address\nvar rtmpServer = 'rtmp:\/\/localhost';\n\n\/\/create a binary server listening that receives stream data\nvar RTMPServer = rtmp.RTMPServer();\nvar server = RTMPServer ({port: 1935});\n\nserver.on('connection', function(client){\n \/\/check if user is allowed to do so\n rtmp.newStream(client.stream);\n});\n<\/code><\/pre>\n<p>Possibly it might be better to use socketIO to differentiate between user interactions via eventEmitters.<\/p>\n<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&#8217;d also like you to comment on this.<\/p>\n<ul>\n<li>easy validation of user interaction by running e.g. express and socketIO<\/li>\n<li>hybrid implementation of a flash (via RTMP) and getUserMedia() (via binary transport mechanisms by adding binaryJS and the Mozilla AudioAPI)<\/li>\n<li>if getUserMedia() gets fully supported, flash implementations can be dropped easily<\/li>\n<li>more control over the rtmp followup and user interaction in general<\/li>\n<li>easier implementation into server frameworks<\/li>\n<\/ul>\n<p><strong>UPDATE:<\/strong> I&#8217;ve talked to Mr. Malcontenti-Wilson who is responsible for the only node-rtmp package 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>\n<p><strong>UPDATE 2:<\/strong> Mr. Malcontenti-Wilson just send me a mail to get my attention to node-mtrude (kind of an odd name) which is doing kind of what we would probably want. Has anyone work with this kind of package?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is more a conceptual question rather than a direct &#8220;how to do this&#8221;. 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? There has been [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3402","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3402","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3402"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3402\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3402"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3402"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3402"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}