Using commands
Now that you've mastered attributes, let's move onto using custom commands!
The <whereby-embed> web component exposes a set of methods your application can invoke to perform actions in the room. This is ideal for implementing custom controls for your Whereby component-based video call functionality. In this article, we'll show you how to recreate the bottom toolbar, which we hid at the end of the Configuring with attributes guide.
Prerequisites
This guide assumes that you’ve already created a Whereby Embedded account and a meeting room, and have joined it by adding the <whereby-embed> component to a web app.
If you’ve not created a Whereby Embedded account and a meeting room, you can do so by following the Whereby Embedded initial setup guide.
If you've not created a video call web app using
<whereby-embed>, you can clone our finished web component quickstart web app with attributes on GitHub.
Getting started
Open your example web app in your browser and your code editor.
If you're using your own example, make sure you've got the
bottomToolbar="off"attribute set on your<whereby-embed>attribute.From your account dashboard, go to "Configure" > "API". Under the Allowed domains panel, add the domain where your web app is running. In general, this must be
https, buthttp://localhostdomains are allowed for testing purposes. Your app domain must be present here; otherwise, the Whereby commands will not work.Press the
Savebutton that appears under the text field.
Adding control buttons
In this article, we are going to re-implement our own custom versions of the Camera, Microphone, Chat, People, and Leave controls. The first thing we need to achieve this is an HTML button bar.
Add the following HTML snippet to your document, above the <whereby-embed> element:
<section id="button-bar">
<button id="camera">Mute video</button>
<button id="mic">Mute audio</button>
<button id="chat">Show chat</button>
<button id="people">Show people</button>
<button id="leave">Leave meeting</button>
</section>Styling the button bar
Let's give our buttons some style.
Add the following CSS to your stylesheet to make sure the
<body>element spans the full height of the screen, but the<whereby-embed>element leaves a gap at the bottom to make space for the button bar. If you are starting from our finished web component quickstart web app with attributes example, you'll also want to remove the current CSS rule that targetsbodyandwhereby-embed.Next, add the following rule to place the button bar in the gap at the bottom of the screen, center the buttons, and get things looking neat:
Adding button functionality
Now we'll get our buttons working.
Add the following line to the bottom of your HTML
<head>:Create an
index.jsfile in your app directory and add the following statements to grab references to your control buttons and the<whereby-embed>element:Add the following event handler functions to perform the expected actions when you press those buttons:
Note: You can find our finished web component quickstart web app with commands example on GitHub.
See also
Command reference: contains a table detailing every available event.
Last updated
Was this helpful?

