How to customize the toolbar
Last updated
Last updated
Whereby's browser SDK makes it easy to add video calling to your web or mobile application. You can also use our React hooks and components to create a fully-customized UI.
In this tutorial, we'll create a custom toolbar using our video call SDK, React, CSS, and SVG. Before we begin, you'll need a Whereby Embedded account.
You can get started on Whereby for free with 2,000 participant minutes each month — perfect for trying our features.
This tutorial assumes:
Before you begin, create a meeting room from your account dashboard or using Whereby's REST API. Since this is a tutorial, it’s fine to create an unlocked room.
This tutorial will walk you through creating a custom toolbar similar to the one shown below. Icons are SVG images from the Lucide collection.
Once you've set up your React project, add the Whereby Browser SDK and Lucide. If you're using npm, type the following.
Yarn users: use yarn add
to install both packages.
Lucide icons are available as JSX components. It saves the step of making SVG icons compatible with JSX.
To add video calling to your application, you'll first need to add theWherebyProvider
component. WherebyProvider
ensures that all of your components have access to Whereby's internal state.
Update your index.js
file and wrap your main component — App
in this case — in WherebyProvider
. Your code should resemble the example below.
Whereby added WherebyProvider
in version 3.0 of the SDK. This is a significant change from earlier versions. See our migration guide for more.
Add the URL of your meeting room as well. Pass it to App as a roomUrl prop.
Use the SDK’s useRoomConnection
hook to connect to your room. This hook returns a RoomConnectionOptions object containing three properties:
state
, an object that reflects the status and settings of the current room, including the call's participants;
events
, an event emitter object that fires in-room events as they're happening; and
actions
, an object representing the available actions in the room.
useRoomConnection.actions
contains the methods you'll need to join the meeting, and create the toolbar controls.
Invoke the joinRoom
action from React's useEffect hook.
Your App.jsx
file should look a bit like the code above. Now to create each button.
This toolbar needs three controls: one to toggle the user's camera, one to toggle the user's microphone, and one that allows the user to leave the meeting. Start with the CameraToggle
component.
CameraToggle
should include two buttons: one to turn the camera on, and one to turn the camera off. When clicked, it'll show or hide the appropriate button and turn the video stream on or off.
Import the Video
and VideoOff
components from lucide-react
. Use the button
element to create the controls.
To keep track of which button should be visible, you'll also need to manage state. Use the React.useState()
hook to define a hidden
property and set its initial value.
CameraToggle
expects an action
prop, in this case, toggleCamera
. Import CameraToggle
into App.jsx
, then set toggleCamera
as the value of its action
prop.
Now add an onClick
handler to both buttons. Set the value of hidden
and call the toggleCamera
action. A true
argument turns the camera on and false
turns it off.
Each time the participant clicks CameraToggle
, they'll start or stop their video stream, and show or hide the appropriate button. Use the same technique to create a MicrophoneToggle
component with the toggleMicrophone
action.
Creating a Leave
component is much simpler. There's no need to manage state.
Don’t forget to add MicrophoneToggle
and Leave
to App
. Your video and toolbar should resemble the image in Figure 2.
Add a style.css
file to your project and import it into App.jsx
.
As designed, each toolbar button is circle-shaped. Buttons are centered within the toolbar and have an equal amount of space between them. CSS Flexbox works well for this. Add a .toolbar
rule set for style.css
.
The toolbar should now look a bit like Figure 3.
Now let’s style the buttons themselves. Add a .toolbar__button
ruleset to style.css
. Combine it with :not([hidden])
so that hidden buttons remain hidden. Using display: flex
centers the icon within each button.
Figure 4 shows the result.
You're almost there! According to the toolbar's design, each icon should be a bit larger, with a thinner stroke, and off-white color. You can modify some SVG properties including stroke
and stroke-width
with CSS. Add another rule set to style.css
.
Now your toolbar is complete. In real-world applications, remember to add :hover
and :focus
styles to your buttons.
This tutorial walked you through a simple toolbar with a few features. You can, however, add additional controls. For example, the startScreenshare()
action allows participants to share their screen with other attendees. You can also add buttons for meeting hosts that allow a host to mute or remove participants. Since all of Whereby’s meeting room controls are available as actions, you can make your toolbar as robust as you’d like.
Written by Tiffany Brown