# @bandwidth/webrtc-browser

> SDK for Bandwidth WebRTC Browser Applications

Latest version **0.13.1** (published 2022-08-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install @bandwidth/webrtc-browser
pnpm add @bandwidth/webrtc-browser
yarn add @bandwidth/webrtc-browser
bun add @bandwidth/webrtc-browser
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.13.1 |
| Published | 2022-08-19 |
| First published | 2020-06-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 8 |
| Unpacked size | 238.9 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 7 |
| Author | edge-services@bandwidth.com |
| Maintainers | jmulford-bandwidth, tbowen, zelitzsi, themikez, nguyer, developerhelp-bandwidth, cejohnson-bw, mhamer-bw |

## Links

- npm: https://www.npmjs.com/package/@bandwidth/webrtc-browser
- Repository: https://github.com/Bandwidth/webrtc-browser
- Homepage: https://github.com/Bandwidth/webrtc-browser#readme
- Issues: https://github.com/Bandwidth/webrtc-browser/issues
- npm.io page: https://npm.io/package/@bandwidth/webrtc-browser

## Dependencies (8)

- [uuid](https://npm.io/package/uuid.md) ^8.3.0
- [jwt-decode](https://npm.io/package/jwt-decode.md) ^3.1.2
- [@types/uuid](https://npm.io/package/@types/uuid.md) ^8.3.0
- [async-mutex](https://npm.io/package/async-mutex.md) ^0.3.1
- [sdp-transform](https://npm.io/package/sdp-transform.md) ^2.14.1
- [rpc-websockets](https://npm.io/package/rpc-websockets.md) ^7.4.14
- [webrtc-adapter](https://npm.io/package/webrtc-adapter.md) ^7.6.2
- [@types/sdp-transform](https://npm.io/package/@types/sdp-transform.md) ^2.4.4

## Recent versions

- 0.13.1 (latest) — 2022-08-19
- 0.12.0-beta.1 (beta) — 2022-07-22
- 0.11.3 — 2022-02-01
- 0.10.0 — 2021-09-20
- 0.10.0-beta.1 — 2021-09-16
- 0.9.2 — 2021-05-24
- 0.9.2-beta.1 — 2021-05-13
- 0.9.1 — 2021-05-05
- 0.9.0 — 2021-05-05
- 0.9.0-beta.4 — 2021-04-19
- 0.9.0-beta.3 — 2021-04-16
- 0.9.0-beta.2 — 2021-04-05
- 0.9.0-beta.1 — 2021-04-02
- 0.9.0-beta.0 — 2021-03-05
- 0.8.0 — 2021-01-19
- … 7 more at https://npm.io/package/@bandwidth/webrtc-browser/versions

## README

# Bandwidth WebRTC Browser SDK Documentation

## Initialize the Bandwidth WebRTC Browser SDK

```javascript
import BandwidthRtc from "@bandwidth/webrtc-browser";

const bandwidthRtc = new BandwidthRtc();
```

## API Methods

### connect

- Params:
  - authParams: the device token to connect with
  - options: optional SDK settings (can be omitted)
    - websocketUrl: override the default Bandwidth RTC connection url (this should not generally be needed)
- Description: connect device to the Bandwidth RTC platform

```javascript
await bandwidthRtc.connect({
  deviceToken: deviceToken,
});
```

### publish

- Params:
  - input: the input to publish; this can be an instance of:
    - constraints: the media stream constraints such as audio, peerIdentity, video
      - Type: MediaStreamConstraints
    - mediaStream: An already existing media stream such as a screen share
      - Type: MediaStream
- Return:
  - rtcStream: a media stream with the supplied media stream constraints
    - Type: RtcStream
- Description: publish media

#### Publish with default settings:

```javascript
let rtcStream: RtcStream = await bandwidthRtc.publish();
```

#### Publish audio only

```javascript
const mediaConstraints: MediaStreamConstraints = {
  audio: true,
  video: false,
};
let rtcStream: RtcStream = await bandwidthRtc.publish(mediaConstraints);
```

#### Publish with customized constraints

```javascript
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 rtcStream: RtcStream = await bandwidthRtc.publish(mediaConstraints);
```

#### Publish with existing media stream

```javascript
let screenShare = await navigator.mediaDevices.getDisplayMedia({
  video: true,
});
let rtcStream: RtcStream = await bandwidthRtc.publish(screenShare);
```

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

- https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamConstraints
- https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints

### disconnect

- Description: disconnect device from the Bandwidth RTC platform

### DTMF

- Description: send a set of VoIP-network-friendly DTMF tones. The tone amplitude and duration can not be controlled
- Params:
  - tone: the digits to send, as a string, chosen from the set of valid DTMF characters [0-9,*,#,\,]
  - streamId (optional): the stream to 'play' the tone on

```javascript
bandwidthRtc.sendDtmf("3");
bandwidthRtc.sendDtmf("313,3211*#");
```

## Event Listeners

### onStreamAvailable

- Description: called when a media stream is available to attach to the UI. This will be called for every independent stream presented to the Participant, meaning that if a new remote Participant is added to a subscribed Session a new stream will be made available to the browser, and will need to be presented to the UI for consumption by the user.

```javascript
bandwidthRtc.onStreamAvailable((event) => {
  console.log(
    `A stream is available with endpointId=${event.endpointId}, its media types are ${event.mediaTypes} and the stream itself is ${event.mediaStream}`
  );
});
```

### onStreamUnavailable

- Description: called when a media stream is now unavailable and should be removed from the UI

```javascript
bandwidthRtc.onStreamUnavailable((event) => {
  console.log(
    `The stream with endpointId=${event.endpointId} is now unavailable and should be removed from the UI because the media is likely to freeze imminently.`
  );
});
```

---
_Source: https://npm.io/package/@bandwidth/webrtc-browser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
