summaryrefslogblamecommitdiffstats
path: root/_build/static/archives/extend/attachments/20140929/84fe21a4/attachment-0001.html
blob: d8a3a0b0ea9310f7f21038e2ece06d48e2bb472d (plain) (tree)
1
2
3
4
5




                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
<tt>
&lt;div&nbsp;dir=&quot;ltr&quot;&gt;&lt;div&gt;Hello&nbsp;list,&nbsp;I&nbsp;hope&nbsp;this&nbsp;is&nbsp;the&nbsp;right&nbsp;place&nbsp;to&nbsp;ask&nbsp;this.&lt;br&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;I&#39;m&nbsp;learning&nbsp;Erlang,&nbsp;and&nbsp;I&nbsp;wanted&nbsp;to&nbsp;create&nbsp;a&nbsp;Cowboy&nbsp;app&nbsp;to&nbsp;record&nbsp;audio&nbsp;from&nbsp;a&nbsp;web&nbsp;browser.&lt;br&gt;&lt;br&gt;Based&nbsp;on&nbsp;the&nbsp;websocket&nbsp;example&nbsp;in&nbsp;the&nbsp;Cowboy&nbsp;source&nbsp;code,&nbsp;I&nbsp;get&nbsp;the&nbsp;user&nbsp;mic&nbsp;input&nbsp;and&nbsp;send&nbsp;this&nbsp;input&nbsp;to&nbsp;the&nbsp;websocket.&lt;br&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;I&nbsp;created&nbsp;a&nbsp;&quot;recorder&quot;&nbsp;module,&nbsp;which&nbsp;functionality&nbsp;is&nbsp;to&nbsp;save&nbsp;the&nbsp;data&nbsp;to&nbsp;the&nbsp;a&nbsp;file.&lt;br&gt;&lt;br&gt;&lt;b&gt;#rawe_handler.erl&lt;br&gt;&lt;/b&gt;-module(rawec_handler).&lt;br&gt;-behaviour(cowboy_websocket_handler).&lt;br&gt;......&lt;br&gt;init(_,&nbsp;_,&nbsp;_)&nbsp;-&gt;&lt;br&gt; &nbsp;case&nbsp;whereis(recorder)&nbsp;of&lt;br&gt;   &nbsp;undefined&nbsp;-&gt;&lt;br&gt;       &nbsp;RecorderPid&nbsp;=&nbsp;recorder:start(),&lt;br&gt;       &nbsp;register(recorder,&nbsp;RecorderPid);&lt;br&gt;   &nbsp;_&nbsp;-&gt;&nbsp;ok&lt;br&gt; &nbsp;end,&lt;br&gt;   &nbsp;{upgrade,&nbsp;protocol,&nbsp;cowboy_websocket}.&lt;br&gt;.....&lt;br&gt;websocket_handle(_Frame,&nbsp;Req,&nbsp;State)&nbsp;-&gt;&lt;br&gt; &nbsp;RecorderPid&nbsp;=&nbsp;whereis(recorder),&lt;br&gt; &nbsp;RecorderPid&nbsp;!&nbsp;{rec,&nbsp;_Frame/binary},&lt;br&gt;   &nbsp;{ok,&nbsp;Req,&nbsp;State}.&lt;br&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;#recorder.erl&lt;/b&gt;&lt;br&gt;-module(recorder).&lt;br&gt;&lt;br&gt;-export([start/0,&nbsp;recorder_fun/1]).&lt;br&gt;-compile([debug_info]).&lt;br&gt;&lt;br&gt;recorder_fun(IoDevice)&nbsp;-&gt;&nbsp;&lt;br&gt; &nbsp;receive&lt;br&gt;   &nbsp;{rec,&nbsp;Data}&nbsp;-&gt;&lt;br&gt;     &nbsp;ok&nbsp;=&nbsp;file:write(IoDevice,&nbsp;Data),&lt;br&gt;     &nbsp;io:format(Data),&lt;br&gt;     &nbsp;recorder_fun(IoDevice);&lt;br&gt;   &nbsp;{stop,&nbsp;_}&nbsp;-&gt;&lt;br&gt;     &nbsp;%%Close&nbsp;file&lt;br&gt;     &nbsp;file:close(IoDevice)&lt;br&gt;   &nbsp;end.&lt;br&gt;   &nbsp;&lt;br&gt;start()&nbsp;-&gt;&lt;br&gt; &nbsp;{ok,&nbsp;IoDevice}&nbsp;=&nbsp;file:open(&quot;/tmp/test_binary.wav&quot;,&nbsp;[write,&nbsp;binary]),         &nbsp;&lt;br&gt; &nbsp;spawn(recorder,&nbsp;recorder_fun,&nbsp;[IoDevice]).&lt;br&gt; &nbsp;&lt;br&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;When&nbsp;I&nbsp;start&nbsp;the&nbsp;console,&nbsp;and&nbsp;allow&nbsp;the&nbsp;microphone&nbsp;on&nbsp;the&nbsp;browser,&nbsp;I&nbsp;see&nbsp;this&nbsp;error&nbsp;on&nbsp;the&nbsp;console:&lt;br&gt;&lt;br&gt;=ERROR&nbsp;REPORT====&nbsp;29-Sep-2014::18:13:03&nbsp;===&lt;br&gt;Ranch&nbsp;listener&nbsp;http&nbsp;had&nbsp;connection&nbsp;process&nbsp;started&nbsp;with&nbsp;cowboy_protocol:start_link/4&nbsp;at&nbsp;&lt;0.178.0&gt;&nbsp;exit&nbsp;with&nbsp;reason:&nbsp;&lt;b&gt;{[{reason,badarith},{mfa,{rawec_handler,websocket_handle,3&lt;/b&gt;}},{stacktrace,[{rawec_handler,websocket_handle,3,[{file,&quot;src/rawec_handler.erl&quot;},{line,35}]},{cowboy_websocket,handler_call,7,[{file,&quot;src/cowboy_websocket.erl&quot;},{line,588}]},{cowboy_protocol,execute,4,[{file,&quot;src/cowboy_protocol.erl&quot;},{line,435}]}]},{msg,{binary,&lt;&lt;0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0....(ETC,&nbsp;DATA&nbsp;STREAM&nbsp;CONTINUES)&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;Probably&nbsp;my&nbsp;approach&nbsp;to&nbsp;do&nbsp;this&nbsp;is&nbsp;totally&nbsp;wrong.&nbsp;I&nbsp;there&nbsp;any&nbsp;obvious&nbsp;problem&nbsp;here?&lt;br&gt;&lt;/div&gt;&lt;div&gt;Can&nbsp;someone&nbsp;point&nbsp;me&nbsp;to&nbsp;a&nbsp;right&nbsp;direction?.&nbsp;Maybe&nbsp;I&nbsp;should&nbsp;write&nbsp;directly&nbsp;to&nbsp;a&nbsp;file&nbsp;in&nbsp;the&nbsp;&lt;b&gt;websocket_handle&nbsp;&lt;/b&gt;funcion,&nbsp;but&nbsp;how&nbsp;can&nbsp;I&nbsp;keep&nbsp;a&nbsp;file&nbsp;opened&nbsp;during&nbsp;the&nbsp;streaming?&lt;br&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;The&nbsp;github&nbsp;repo&nbsp;is&nbsp;here:&nbsp;&lt;a&nbsp;href=&quot;https://github.com/jmrepetti/rawec&quot;&gt;https://github.com/jmrepetti/rawec&lt;/a&gt;&nbsp;with&nbsp;the&nbsp;whole&nbsp;source&nbsp;code&nbsp;if&nbsp;you&nbsp;want&nbsp;to&nbsp;take&nbsp;a&nbsp;look.&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;Thanks&nbsp;in&nbsp;advance,&lt;br&gt;&lt;/div&gt;&lt;div&gt;Matias.&lt;br&gt;<br>
&lt;/div&gt;&lt;/div&gt;<br>

</tt>