11

I'm trying to get my head round WebRTC. I need to be able to capture and stream live audio through a web browser.

I'm just having difficulty finding the code examples that I can understand or is up-to-date. If anyone could help me with just first capturing and playing audio in the same browser with HTML5/WebRTC I think that would help me get started and along my way.

Note: I'm only concerned about getting this to work in Chrome (or Chrome Canary for that matter!).

Thanks for any help!

remotesoftwaredev
  • 135
  • 1
  • 1
  • 7

2 Answers2

18

The HTML5 Rocks article on WebRTC is probably the best intro article that explains everything in layman's terms.

For simply capturing local video/audio, you'll want to focus on the MediaStream API (i.e., getUserMedia). Once you get that working, then you'll need to start looking into the RTCPeerConnection API.

The client-side code for the RTCPeerConnection API is pretty straightforward, but the server-side code required for signalling (i.e., establishing a peer-to-peer connection) can be tricky.

I ended up coding my own server-side solution in PHP, but to do so took me about three weeks of banging my head against the wall (i.e., trying to decipher the WebSocket specs) to get it to work properly. If you'd like to see actual code, I can post some of my working code.

If you're up for the challenge, I recommend trying to code the server-side script yourself, but otherwise, I would look into WebSocket libraries like Socket.IO, which do all the tricky server-side stuff for you.

Community
  • 1
  • 1
HartleySan
  • 7,404
  • 14
  • 66
  • 119
  • 2
    I like the HTML5 Rocks article too ;). (Please add comments to it, if anything is unclear, incorrect or doesn't make sense.) I also maintain a guide to WebRTC resources at http://docs.webplatform.org/wiki/tutorials/webrtc_resources. Most of all, look through the HTML5 Rocks walkthrough of the simple W3C RTCPeerConnection example to get your head around signalling versus media/data communication. On the server side, you might want to have a go at using Node.js with WebSocket, using Socket.IO as HartleySan suggests. – Sam Dutton Jan 25 '13 at 10:02
  • @Sam Dutton, thanks for writing that article. I didn't even know WebRTC was a reality until I read your article. The thing that confused me the most was the signalling. I think a little more information about that would have been helpful. Thanks. – HartleySan Jan 26 '13 at 02:04
  • Thanks @HartleySan. I updated the article last month, so there's more about signalling, but I'll try to provide some more information. – Sam Dutton Jan 28 '13 at 10:44
  • 2
    can we see your server side PHP code for webRTC ? – Baba Apr 04 '13 at 23:34
  • +1 to see the server side PHP code to set up a peer connection and establish a stream - I've posted a similar question here: http://stackoverflow.com/questions/16571044/how-to-record-webcam-and-audio-using-webrtc-and-a-server-based-peer-connection – Dave Hilditch May 15 '13 at 17:17
  • This is not the answer to the question, as this article won't help you with broadcasting via WebRTC. This answer might be harmful for anyone, who would like to expand a P2P service with any kind of broadcasting. – igorpavlov Nov 26 '13 at 11:52
  • 1
    wha about broadcasting. WebRTC PeerConnections are kind of P2P as name suggests. Broadcasting with it will require one connection per connection which will not scale soon after more people connect. Broadcasting peer will have to upload many multiples ,tons, of data produced on his/her end. – sçuçu Jul 17 '19 at 11:46
2

If you are talking on WebRTC Live Audio Streaming/Broadcast, not just about peer-to-peer calls, WebRTC is not designed for broadcasts. Check here WebRTC - scalable live stream broadcasting / multicasting

Community
  • 1
  • 1
igorpavlov
  • 3,576
  • 6
  • 29
  • 56