When to use WebRTC over WebSockets?

Technology CommunityCategory: WebSocketsWhen to use WebRTC over WebSockets?
VietMX Staff asked 3 years ago
Problem

I’m looking to build a chat app that will allow video, audio, and text. How to to decide which to use, WebRTC or WebSockets?

  • 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 is mainly UDP. Thus main reason of using WebRTC instead of Websocket is latency. With WebRTC you may achive low-latency and smooth playback which is crucial stuff for VoIP communications.
  • With WebRTC the data is end-to-end encrypted and does not pass through a server (except sometimes TURN servers are needed, but they have no access to the body of the messages they forward).
  • WebRTC apps need a service via which they can exchange network and media metadata, a process known as signaling.
  • 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.
  • Websockets use TCP protocol. With websocket streaming you will have either high latency or choppy playback with low latency.
  • With Websockets the data has to go via a central webserver which typically sees all the traffic and can access it.