Imagine building your own video conferencing app in React. WebRTC, the foundation for real-time communication, can be challenging due to browser-specific implementations and differences in behavior. However, with Daily React, a React library built on Daily's client SDK, you can simplify the process. The library provides components like App, Call, Prejoin, CallControls, and Tile, with only around 30 lines of code each. Just wrap your code with DailyProvider and specify the URL and Username, and you're good to go.
Hey there! Imagine you're having a video chat with a good friend of yours 15 minutes from now, but you forgot to send a meeting link along with the calendar invite. I know, I know. There are solutions to this, but what if you could build your very own video conferencing app in React? My name is Christian, I'm a product engineer at Daily, the WebRTC company for developers. And one of my main focuses in working at Daily is to make our APIs as easy as possible to use for React developers.
Coming back to the build-your-own-video-call-app-in-React problem. The web has how-tos, tutorials, and code-alongs in several formats but pretty much all that I've looked at suffer from the same problems. They require a solid amount of code, both on the client and server side, they usually don't handle more than two or three people on a call, and they require to set up infrastructure far beyond a CDN hosting your front-end bundle. So why is WebRTC, the foundation for all of these, so difficult? WebRTC in itself is an open-source project and provides standard APIs for sending audio, video, and data across the web in real-time. In theory, this means that you can use WebRTC APIs on different browsers and operating systems and you should be good. The issue is that each browser vendor maintains their very own implementation of WebRTC and you know what that means? There we dragon. Usually, a WebRTC app will ask for camera and microphone permission in order to further process the media tracks coming from your audio and video devices. GetUserMedia is probably the first API you see mentioned in articles and videos about WebRTC. This API in itself has already interesting differences in its behavior across browsers. As an example, Chrome allows you to re-prompt for audio and video as many times as you like even when access has been blocked. Safari, however, doesn't allow re-prompting so when a user blocks access your best bet is to have them refresh the page.
Now once you've managed to get a media stream from the users' devices, in order to make your app a video conferencing app you'll need to send the stream across the wires otherwise it would just be a mirror app. The RTC Peer Connection API is the tool of choice here but actually getting that connection set up requires a bunch of information. Who are you connecting to? Which codecs are being used for audio and video? What is the available bandwidth? Setting this connection up also includes a negotiation phase where one client, the first one to connect, sends an offer and the remote client answers with an answer. Furthermore, if you don't have a signaling server setup to identify the clients yourself you likely have to reach out to a stun or tone server on the internet to do the client identification process for you. Eventually, when the connection is negotiated and set up you can add the user's audio and video tracks to the connection and if all went well the media bytes should be flowing from one client to the other. Then finally you'll have to access the remote media tracks from the RTC Pure Connection object, attach the tracks to the media elements in the browser and then the users of your app should see each other on screen.
Up until now we haven't thought about any React code. But we are React developers, right? So while all of the things I just mentioned seem complex and overwhelming, and yes, they are, you don't really have to worry about them. This is where I want to introduce Daily React to you. It's a React library built on top of Daily's client SDK and it provides all the things you need to build a React app with WebRTC capabilities. Coming back to the original problem, how can you build a video conferencing app in React? Here's how. The app only has a few components, App, Call, Prejoin, CallControls, and Tile. They all have around 30 lines of code, including imports. Before you are able to utilize any of Daily React's hooks and components, you'll wrap with DailyProvider. It accepts a bunch of configuration options for Call, but for this case, URL and Username are sufficient.
Comments