@bandwidth/webrtc-browser-sdkdeprecated

SDK for Bandwidth WebRTC Browser Applications

Usage no npm install needed!

<script type="module">
  import bandwidthWebrtcBrowserSdk from 'https://cdn.skypack.dev/@bandwidth/webrtc-browser-sdk';
</script>

README

Bandwidth WebRTC Client SDK Documentation

Initialize the Bandwidth WebRTC SDK

import BandwidthRtc from "@bandwidth/webrtc-browser-sdk";

const bandwidthRtc = new BandwidthRtc();

API Methods

connect

  • Params:
    • authParams: The conferenceId and participantId.
    • options: Optional SDK settings (can be omitted).
      • websocketUrl: override the default Bandwidth RTC connection url (this should not generally be needed)
  • Description: Connect participant to a conference.
await bandwidthRtc.connect({
  conferenceId: conferenceId,
  participantId: participantId,
});

publish

  • Params:
    • constraints: The media stream constraints such as audio, peerIdentity, video
      • Type: MediaStreamConstraints
  • Return:
    • userMedia: A media stream with the supplied media stream constraints.
  • Description: Publish media

Publish with default settings:

let localStream: MediaStream = await bandwidthRtc.publish();

Publish audio only

const mediaConstraints: MediaStreamConstraints = {
  audio: true,
  video: false,
};
let localStream: MediaStream = await bandwidthRtc.publish(mediaConstraints);

Publish with customized constraints

const mediaConstraints: MediaStreamConstraints = {
  audio: {
    autoGainControl: true,
    channelCount: 1,
    deviceId: "default",
    echoCancellation: true,
    latency: 0.01,
    noiseSuppression: true,
    sampleRate: 48000,
    sampleSize: 16,
  },
  video: {
    aspectRatio: 1.3333333333333333,
    frameRate: 30,
    width: { min: 640, ideal: 1280 },
    height: { min: 480, ideal: 720 },
    resizeMode: "none",
  },
};
let localStream: MediaStream = await bandwidthRtc.publish(mediaConstraints);

Please see the following resources for more information on MediaStreamConstraints and MediaTrackConstraints that can be specified here:

disconnect

  • Description: Disconnect from conference.

Event Listeners

onUnpublished

  • Description: Listens for the unpublished event.
bandwidthRtc.onUnpublished((event) => {
  console.log(`The stream ${event.streamId} has been unpublished.`);
});

onSubscribe

  • Description: Listens for the subscribe event.
bandwidthRtc.onSubscribe((event) => {
  console.log(`The stream ${event.streamId} has been subscribed to.`);
});

onUnsubscribed

  • Descripton: Listens for the unsubscribed event.
bandwidthRtc.onUnsubscribed((event) => {
  console.log(`The stream ${event.streamId} has been unsubscribed from.`);
});

onRemoved

  • Description: Listens for the removed from conference event.
bandwidth.onRemoved((event) => {
  console.log(`Participant ${event.participantId} has been removed from the conference.`);
});

onConferenceEnded

  • Description: Listens for the conference ended event.
bandwidthRtc.onConferenceEnded((event) => {
  console.log(`The conference ${event.conferenceId} ended.`);
});