From 50bfbb7eb02d34f1dd97d94fa05343c4ba36f860 Mon Sep 17 00:00:00 2001
From: Jeff Lim <32758512+sf-jeff-lim@users.noreply.github.com>
Date: Thu, 19 Nov 2020 16:26:32 +0900
Subject: [PATCH 1/9] Update README.md
---
README.md | 645 ++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 454 insertions(+), 191 deletions(-)
diff --git a/README.md b/README.md
index 9fbb182..2ecc501 100644
--- a/README.md
+++ b/README.md
@@ -1,31 +1,63 @@
-# SendBird Calls for JavaScript
-
+# [Sendbird](https://sendbird.com) Calls SDK for JavaScript
[](https://img.shields.io/bundlephobia/min/sendbird-calls)
[](https://img.shields.io/bundlephobia/minzip/sendbird-calls)
[](https://badge.fury.io/js/sendbird-calls)
[](https://github.com/sendbird/sendbird-calls-javascript/blob/master/LICENSE.md)
+## Table of contents
+
+ 1. [Introduction](#introduction)
+ 1. [Before getting started](#before-getting-started)
+ 1. [Getting started](#getting-started)
+ 1. [Make your first call](#make-your-first-call)
+ 1. [Implementation guide](#implementation-guide)
+ 1. [Appendix](#appendix)
+
+
+
## Introduction
-`SendBird Calls` is the latest addition to our product portfolio. It enables real-time calls between users within a SendBird application. SDKs are provided for iOS, Android, and JavaScript. Using any one of these, developers can quickly integrate voice and video call functions into their own client apps, allowing users to make and receive web-based real-time voice and video calls on the SendBird platform.
-> If you need any helps or have any issue / question, please visit [our community](https://community.sendbird.com)
+**SendBird Calls** is the latest addition to our product portfolio. It enables real-time calls between users within a Sendbird application. SDKs are provided for iOS, Android, and JavaScript. Using any one of these, developers can quickly integrate voice and video call functions into their own client apps, allowing users to make and receive web-based real-time voice and video calls on the Sendbird platform.
+
+> If you need any help in resolving any issues or have questions, please visit [our community](https://community.sendbird.com)
+
+### How it works
+
+Sendbird Calls SDK for JavaScript provides a framework to make and receive voice and video calls. **Direct calls** in the SDK refers to one-to-one calls. To make a direct voice or video call, the caller specifies the user ID of the intended callee, and dials. Upon dialing, all of the callee’s authenticated devices will receive notifications for an incoming call. The callee then can choose to accept the call from any one of the devices. When the call is accepted, a connection is established between the devices of the caller and the callee. This marks the start of a direct call. Call participants can mute themselves, or call with either or both of the audio and video by using output devices such as speaker and microphone for audio, and front, rear camera for video. A call may be ended by either party. The [Sendbird Dashboard](https://dashboard.sendbird.com/auth/signin) displays call logs in the Calls menu for dashboard owners and admins to review.
+
+### For further reference
+
+Find out more about Sendbird Calls for JavaScript on [Calls SDK for JavaScript doc](https://sendbird.com/docs/calls/v1/javascript/getting-started/about-calls-sdk).
+
+
+
+## Before getting started
+
+This section shows the prerequisites you need to check to use Sendbird Calls SDK for JavaScript.
+
+### Requirements
-## Functional Overview
-The SendBird Calls JavaScript SDK provides a framework to make and receive voice and video calls. “Direct calls” in the SDK refers to one-to-one calls, comparable to “direct messages” (DMs) in messaging services. To make a direct voice or video call, the caller specifies the user ID of the intended callee, and dials. Upon dialing, all of the callee’s authenticated devices will receive incoming call notifications. The callee then can choose to accept the call from any one of the devices. When the call is accepted, a connection is established between the caller and the callee. This marks the start of the direct call. Call participants may mute themselves, as well as select the audio and video hardware used in the call. Calls may be ended by either party. The SendBird Dashboard displays call logs in the Calls menu for application owners and admins to review.
+The minimum requirements for Calls SDK for JavaScript are:
-## SDK Prerequisites
-* [Modern browsers implementing WebRTC APIs](https://caniuse.com/#feat=rtcpeerconnection) are supported; IE is not.
-* Edge(<= 44) is not supported, though it might be supported later.
+- [Modern browsers implementing WebRTC APIs](https://caniuse.com/#feat=rtcpeerconnection) are supported; IE is excluded.
+- Edge is not supported as of now.
```javascript
// browser console
(window.RTCPeerConnection) ? console.log('supported') : console.log('not supported')
```
-## Install and configure the SDK
-Download and install the SDK using `npm` or `yarn`.
-```shell script
+
+
+## Getting started
+
+This section gives you information you need to get started with Sendbird Calls SDK for JavaScript.
+
+### Install and configure the SDK
+
+1. Download and install the SDK using `npm` or `yarn`.
+```bash
# npm
npm install sendbird-calls
@@ -33,43 +65,54 @@ npm install sendbird-calls
yarn add sendbird-calls
```
-Import `SendBirdCall` as an es6 module
+2. Import `SendBirdCall` as an es6 module
```javascript
import SendBirdCall from "sendbird-calls";
SendBirdCall.init(APP_ID)
```
-> **Note**: If you are using TypeScript, you have to set ['--esModuleInterop' setting to `true` for 'default import'](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-7.html#support-for-import-d-from-cjs-from-commonjs-modules-with---esmoduleinterop), or use `import * as SendBirdCall from "sendbird-calls"` instead.
+> **Note**: If you are using `TypeScript`, you have to set ['--esModuleInterop' setting to `true` for 'default import'](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-7.html#support-for-import-d-from-cjs-from-commonjs-modules-with---esmoduleinterop), or use `import * as SendBirdCall from "sendbird-calls"` instead.
Or use the minified file to initialize `SendBirdCall` as global variable in the header
```html
```
-## Acquiring Media Device Permissions
-When a user makes or receives a call for the first time on a given website, the browser will prompt the user to grant microphone and camera access permissions. This might also occur when the `SendBirdCall.useMedia()` function is first called. Without these permissions, users will be unable to retrieve a list of available media devices or to retrieve any actual media streams.
+### Grant media device permissions
+
+When a user makes or receives a call for the first time on a given website, the browser will prompt the user to grant microphone and camera access permissions. This might also occur when the `SendBirdCall.useMedia()` function is first called. Without these permissions, users will be unable to retrieve a list of available media devices or to retrieve any actual media streams.
+
+
+
+## Make your first call
+
+Follow the step-by-step instructions below to authenticate and make your first call.
+
+### Step 1: Initialize the SendBirdCall instance in a client app
+
+As shown below, the `SendBirdCall` instance must be initiated when a client app is launched. Initialize the `SendBirdCall` instance with the `APP_ID` of the Sendbird application you would like to use to make a call.
-## Initialize the SendBirdCall instance in a client application
-As shown below, the `SendBirdCall` instance must be initiated when a client app is launched. If another initialization with another `APP_ID` takes place, all existing data will be deleted and the `SendBirdCall` instance will be initialized with the new `APP_ID`.
```javascript
SendBirdCall.init(APP_ID);
```
-## Authenticate a user and connect websocket to server
-In order to make and receive calls, users must first be authenticated on the SendBird server using the `SendBirdCall.authenticate()` function. The `SendBirdCall` object must then be connected to the websocket server using `SendBirdCall.connectWebSocket()` method.
+### Step 2: Authenticate a user and connect websocket to server
+
+In order to make and receive calls, users must first be authenticated on the SendBird server using the `SendBirdCall.authenticate()` function. The `SendBirdCall` object must then be connected to the websocket server using the `SendBirdCall.connectWebSocket()` method.
+
```javascript
// Authentication
const authOption = { userId: USER_ID, accessToken: ACCESS_TOKEN };
SendBirdCall.authenticate(authOption, (res, error) => {
- if (error) {
- // auth failed
- } else {
- // auth succeeded
- }
+ if (error) {
+ // auth failed
+ } else {
+ // auth succeeded
+ }
});
// Websocket Connection
@@ -78,305 +121,522 @@ SendBirdCall.connectWebSocket()
.catch(/* connect failed */);
```
-## Register event handlers
-Two types of event handlers must be registered for various events that client apps may respond to: a device-specific listener and a call-specific listener.
+### Step 3: Add an event handler
+
+There are two types of event handlers the SDK provides for a client app to respond to various events: a device-specific listener and a call-specific listener.
+
+#### - Device-specific Listener
+
+Register a device-specific event handler using the `SendBirdCall.addListener()` method. It is recommended to add the event handler during initialization because it is a prerequisite for detecting an `onRinging()` event. The code below shows the way device-wide events such as incoming calls are handled once device-specific event is added.
-### Device-specific Listener
-Register a device-specific event handler using the `SendBirdCall.addListener()` method. Prior to registering this, the `onRinging()` event cannot be detected. It is therefore recommended that this event handler be added during initialization. After this device-specific event is added, responding to device-wide events (e.g. incoming calls) is handled as shown below:
```javascript
SendBirdCall.addListener(UNIQUE_HANDLER_ID, {
- onRinging: (call) => {
- ...
- },
- onAudioInputDeviceChanged: (currentDevice, availableDevices) => {
- ...
- },
- onAudioOutputDeviceChanged: (currentDevice, availableDevices) => {
- ...
- },
- onVideoInputDeviceChanged: (currentDevice, availableDevices) => {
- ...
- }
+ onRinging: (call) => {
+ ...
+ },
+ onAudioInputDeviceChanged: (currentDevice, availableDevices) => {
+ ...
+ },
+ onAudioOutputDeviceChanged: (currentDevice, availableDevices) => {
+ ...
+ },
+ onVideoInputDeviceChanged: (currentDevice, availableDevices) => {
+ ...
+ }
});
```
-`UNIQUE_HANDLER_ID` is any unique string value (e.g. UUID).
-
-| Event Listener | Invocation Criteria |
-|---------------|------------------------------------------------------------------|
-|onRinging | Incoming calls are received on the callee’s device. |
+`UNIQUE_HANDLER_ID` is any unique string value such as UUID.
+
+| Event listener | Invocation criteria|
+|---|---|
+|onRinging| Incoming calls are received on the callee’s device. |
|onAudioInputDeviceChanged | Audio input devices have changed. |
|onAudioOutputDeviceChanged | Audio output devices have changed. |
|onVideoInputDeviceChanged | Video input devices have changed. |
-### Call-specific Listener
-Register a call-specific event handler by attaching an event handler function directly to the properties of the call object. Responding to call-specific events (e.g. sucessfull call connection) is then handled as shown below:
+#### - Call-specific Listener
+
+Register a call-specific event handler by attaching an event handler function directly to the properties of the call object. Responding to call-specific events such as establishing a successful call connection is then handled as shown below.
```javascript
// call is 'DirectCall' object
call.onEstablished = (call) => {
- ...
+ ..,
};
call.onConnected = (call) => {
- ...
+ ...
};
call.onEnded = (call) => {
- ...
+ ...
};
call.onReconnecting = (call) => {
- ...
+ ...
};
call.onReconnected = (call) => {
- ...
+ ...
};
call.onRemoteAudioSettingsChanged = (call) => {
- ...
+ ...
};
call.onRemoteVideoSettingsChanged = (call) => {
- ...
+ ...
};
call.onCustomItemsUpdated = (call, updatedKeys) => {
- ...
+ ...
};
call.onCustomItemsDeleted = (call, deletedKeys) => {
- ...
+ ...
};
call.onRemoteRecordingStatusChanged = (call) => {
- ...
+ ...
};
```
-| Event Listener | Invocation Criteria |
-|--------------------------------|--------------|
-| onEstablished | The callee accepted the call using the method `call.accept()`, but neither the caller or callee’s devices are as of yet connected to media devices. |
-| onConnected | Media devices (e.g. microphone and speakers) between the caller and callee are connected and the voice or video call can begin. |
-| onEnded | The call has ended on either the caller or the callee’s devices. This is triggered automatically when either party runs the method `call.end()`. This event listener is also invoked if the call is ended for other reasons. See the bottom of this readme for a list of all possible reasons for call termination. |
-| onRemoteAudioSettingsChanged | The other party changed their audio settings. |
-| onRemoteVideoSettingsChanged | The other party changed their video settings. |
-| onCustomItemsUpdated | One or more of `call`’s custom items (metadata) have been updated. |
-| onCustomItemsDeleted | One or more of `call`’s custom items (metadata) have been deleted. |
-| onReconnecting | `call` started attempting to reconnect to the other party after a media connection disruption. |
-| onReconnected | The disrupted media connection reconnected. |
-| onRemoteRecordingStatusChanged | The other user’s recording status has been changed. |
+|Event listener|Invocation criteria |
+|---|---|
+|onEstablished|The callee accepted the call using the method `call.accept()`. However, neither the caller or callee’s devices are connected to media devices yet.|
+|onConnected|A connection is established between the caller and callee’s media devices such as microphones and speakers. The voice or video call can begin.|
+|onEnded | The call has ended on either the caller or the callee’s devices. When the `call.end()` method is used from either party, a call ends. The `call.end()` event listener is also invoked if the call is ended for other reasons. Refer to [Calls result] in Appendix for all possible reasons for call termination. |
+|onRemoteAudioSettingsChanged| The other party changed their audio settings. |
+|onRemoteVideoSettingsChanged| The other party changed their video settings. |
+|onCustomItemsUpdated| One or more of `call`’s custom items that are used to store additional information have been updated.|
+|onCustomItemsDeleted| One or more of `call`’s custom items that are used to store additional information have been deleted.|
+|onReconnecting| `call` started attempting to reconnect to the other party after a media connection disruption. |
+|onReconnected| The disrupted media connection reconnected. |
+|onRemoteRecordingStatusChanged | The other user’s recording status has been changed. |
+### Step 4: Make a call
+First, prepare the `dialParams` call parameter object to initiate a call. This contains the intended callee’s user id and a `callOption` object. The `callOption` is used to set the call’s initial configuration, such as mute or unmute. Once prepared, the `dialParams` object is then passed into the `SendBirdCall.dial()` method to start making a call.
-## Make a call
-Initiate a call by first preparing the `dialParams` call parameter object. This contains the intended callee’s user id, whether or not it is a video call, as well as a `callOption` object. `callOption` is used to set the call’s initial configuration (e.g. muted/unmuted). Once prepared, the `dialParams` object is then passed into the `SendBirdCall.dial()` method to starting making a call.
```javascript
const dialParams = {
- userId: CALLEE_ID,
- isVideoCall: true,
- callOption: {
- localMediaView: document.getElementById('local_video_element_id'),
- remoteMediaView: document.getElementById('remote_video_element_id'),
- audioEnabled: true,
- videoEnabled: true
- }
+ userId: CALLEE_ID,
+ isVideoCall: true,
+ callOption: {
+ localMediaView: document.getElementById('local_video_element_id'),
+ remoteMediaView: document.getElementById('remote_video_element_id'),
+ audioEnabled: true,
+ videoEnabled: true
+ }
};
const call = SendBirdCall.dial(dialParams, (call, error) => {
if (error) {
- // dial failed
+ // dial failed
}
+
// dial succeeded
});
call.onEstablished = (call) => {
- ...
+ ...
};
call.onConnected = (call) => {
- ...
+ ...
};
call.onEnded = (call) => {
- ...
+ ...
};
call.onRemoteAudioSettingsChanged = (call) => {
- ...
+ ...
};
call.onRemoteVideoSettingsChanged = (call) => {
- ...
+ ...
};
```
-> A media viewer is a [HTMLMediaElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement) (e.g. <audio>, <video>) to display media stream. The `remoteMediaView` is required for the remote media stream to be displayed. Setting `autoplay` property of media viewer to `true` is also recommended.
+A media viewer is a [HTMLMediaElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement) such as `