Bandwidth WebRTC Client SDK Documentation
Initialize the Bandwidth WebRTC SDK
import BandwidthRtc from "@bandwidth/bandwidth-rtc-sdk-client";
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
onSubscribe
- Description: Listens for the subscribe event and execute provided callback.
bandwidthRtc.onSubscribe(event => {
console.log(`The stream ${event.streamId} has been subscribed to.`);
});
onUnsubscribe
- Descripton: Listens for the unsubscribe event.
bandwidthRtc.onUnsubscribe(event => {
console.log(`The stream ${event.streamId} has been unsubscribed from.`);
});
onConferenceEnded
- Description: Listens for the conference ended event.
bandwidthRtc.onConferenceEnded(event => {
console.log(`The conference ${event.conferenceId} ended.`);
});