Quick Start

The following code snippets show a basic example of using the core sdk to join and leave a room.

  1. Create client

import { WherebyClient } from "@whereby.com/core";

const client = new WherebyClient();
const roomConnection = client.getRoomConnection();
const localMedia = client.getLocalMedia();
  1. Join room

 type JoinRoomOptions = {
	 roomUrl: string;
	 audio?: boolean;
	 video?: boolean;
 }
 
 async function joinRoom({roomUrl, audio = false, video = false}: JoinRoomOptions) {
 
 /** If sending media, you need to start local media before initialising, for example: 
        async function startLocalMedia(stream: MediaStream) {
	await localMedia.startMedia(stream);
		}
 **/
        roomConnection.initialize({
            localMediaOptions: {
                audio,
                video,
            },
            roomUrl,
        });
        
        try {
            await roomConnection.joinRoom();
        } catch(error) {
            console.error("Could not join room", error);
            return;
        }
   }
  1. Subscribe to remote participants

  1. Minimal sample: Join for 10 seconds and then leave

This demonstrates the most basic functionality of the library. From this example, you can go on to implement more advanced functionality that is explained in more detail in the next sections of the documentation:

Last updated

Was this helpful?