WebRTC vs Websockets: If WebRTC can do Video, Audio, and Data, why do I need Websockets?

1ManStartup picture 1ManStartup · Sep 14, 2013 · Viewed 103.6k times · Source

So I'm looking to build a chat app that will allow video, audio, and text. I spent some time researching into Websockets and WebRTC to decide which to use. Since there are plenty of video and audio apps with WebRTC, this sounds like a reasonable choice, but are there other things I should consider? Feel free to share your thoughts.

Things like:

  • Due to being new WebRTC is available only on some browsers, while WebSockets seems to be in more browsers.

  • Scalability - Websockets uses a server for session and WebRTC seems to be p2p.

  • Multiplexing/multiple chatrooms - Used in Google+ Hangouts, and I'm still viewing demo apps on how to implement.

  • Server - Websockets needs RedisSessionStore or RabbitMQ to scale across multiple machines.

Answer

Sam Dutton picture Sam Dutton · Sep 16, 2013

WebRTC is designed for high-performance, high quality communication of video, audio and arbitrary data. In other words, for apps exactly like what you describe.

WebRTC apps need a service via which they can exchange network and media metadata, a process known as signaling. However, once signaling has taken place, video/audio/data is streamed directly between clients, avoiding the performance cost of streaming via an intermediary server.

WebSocket on the other hand is designed for bi-directional communication between client and server. It is possible to stream audio and video over WebSocket (see here for example), but the technology and APIs are not inherently designed for efficient, robust streaming in the way that WebRTC is.

As other replies have said, WebSocket can be used for signaling.

I maintain a list of WebRTC resources: strongly recommend you start by looking at the 2013 Google I/O presentation about WebRTC.