npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@whereby.com/browser-sdk

v3.10.9

Published

Modules for integration Whereby video in web apps

Downloads

20,148

Readme

@whereby.com/browser-sdk

The Whereby browser SDK is a library for seamless integration of Whereby video calls into your web application. You can use it to build a completely custom integration of Whereby-powered video calls using React Hooks, or you can also embed pre-built Whereby rooms in a web application using a Web Component.

Installation

npm install @whereby.com/browser-sdk

or

yarn add @whereby.com/browser-sdk

Usage

[!IMPORTANT] In order to make use of this functionality, you must have a Whereby account from which you can create room URLs, either manually or through the Whereby API.

React hooks

useLocalMedia

The useLocalMedia hook enables preview and selection of local devices (camera & microphone) prior to establishing a connection within a Whereby room. Use this hook to build rich pre-call experiences, allowing end users to confirm their device selection up-front. This hook works seamlessly with the useRoomConnection hook described below.

import { useLocalMedia, VideoView } from "@whereby.com/browser-sdk/react";

function MyPreCallUX() {
    const localMedia = useLocalMedia({ audio: false, video: true });

    const { currentCameraDeviceId, cameraDevices, localStream } = localMedia.state;
    const { setCameraDevice, toggleCameraEnabled } = localMedia.actions;

    return (
        <div className="preCallView">
            {/* Render any UI, making use of state */}
            {cameraDevices.map((d) => (
                <p
                    key={d.deviceId}
                    onClick={() => {
                        if (d.deviceId !== currentCameraDeviceId) {
                            setCameraDevice(d.deviceId);
                        }
                    }}
                >
                    {d.label}
                </p>
            ))}
            <VideoView muted stream={localStream} />
        </div>
    );
}

useRoomConnection

The useRoomConnection hook provides a way to connect participants in a given room, subscribe to state updates, and perform actions on the connection, like toggling camera or microphone.

Note: from V3 this requires the WherebyProvder as a parent of this component. See the docs for details

import { useEffect } from "react"
import { useRoomConnection } from "@whereby.com/browser-sdk/react";

function MyCallUX( { roomUrl, localStream }) {
    const { state, actions, components } = useRoomConnection(
        "<room_url>"
        {
            localMedia: null, // Supply localMedia from `useLocalMedia` hook, or constraints
            localMediaConstraints: {
                audio: true,
                video: true,
            }
        }
    );

    const { connectionState, remoteParticipants } = state;
    const { toggleCamera, toggleMicrophone, joinRoom, leaveRoom } = actions;
    const { VideoView } = components;
    
    useEffect(() => {
        /* join the room when this component renders */
        joinRoom()
        return () => leaveRoom()
    }, [])

    return <div className="videoGrid">
        { /* Render any UI, making use of state */ }
        { remoteParticipants.map((p) => (
            <VideoView key={p.id} stream={p.stream} />
        )) }
    </div>;
}

Usage with Next.js

If you are integrating these React hooks with Next.js, you need to ensure your custom video experience components are rendered client side, as the underlying APIs we use are only available in the browser context. Simply add "use client"; to the top of component, like in the following example:

"use client";

import { VideoView, useLocalMedia } from "@whereby.com/browser-sdk/react";

export default function MyNextVideoExperience() {
    const { state, actions } = useLocalMedia({ audio: false, video: true });

    return <p>{state.localStream && <VideoView muted stream={state.localStream} />}</p>;
}

Web component for embedding

Use the <whereby-embed /> web component to make use of Whereby's pre-built responsive UI. Refer to our guide and Web Component Reference to learn which attributes are supported, how to listen to events, and send commands.

React

import "@whereby.com/browser-sdk/embed";

const MyComponent = ({ roomUrl }) => {
    return <whereby-embed chat="off" room={roomUrl} />;
};

export default MyComponent;

In plain HTML

You can import it in your project as follows:

import "@whereby.com/browser-sdk/embed"

And embed rooms using the Web Component.

<html>
    <body>
        <div class="container">
            <whereby-embed room="some-room" />
        </div>
    </body>
</html>

[!NOTE] Although we have just higlighted two combinations of how to load and use the web component, it should be possible to use this library with all the major frontend frameworks and bundlers.

If you don't want to use a bundler, you can use a script tag, like so:

<script src="https://cdn.srv.whereby.com/embed/v2-embed.js"></script>

Migrating from v1 to v2

Migration from v1 to v2 is only relevant for users of the <whereby-embed /> web component. The following changes are necessary when upgrading to v2:

  • If you import the web component in your app, you need to add /embed to the import path, like so import "whereby.com/browser-sdk/embed"
  • If you load the web component using a <script> tag, the src needs to be changed to https://cdn.srv.whereby.com/embed/v2-embed.js. In addition, the type="module" attribute is no longer required and can be removed.

The functionality of the web component should be exactly as the latest version on the v1 branch, but a TypeScript definition is now available for projects using this language.

Migrating from version v2.x to v3

Version 3 of the browser-sdk contains three breaking changes:

  • WherebyProvider is now required to be rendered, and all usage of browser-sdk needs to be in children of the provider.
  • useRoomConnection does not automatically join the room any longer. It's required to manually call joinRoom() from useRoomConnection.actions
  • useRoomConnection.components is deprecated.

See here for more details