# clevertap-signed-call

> A javaScript sdk for VOIP calling

Latest version **0.0.10** (published 2024-07-29) · ISC license · 0 weekly downloads

## Install

```sh
npm install clevertap-signed-call
pnpm add clevertap-signed-call
yarn add clevertap-signed-call
bun add clevertap-signed-call
```

## 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.0.10 |
| Published | 2024-07-29 |
| First published | 2022-10-31 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 679.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | ayush.sinha@clevertap.com |
| Maintainers | darshanclevertap, kamblesonam, ayush_ct, praveen_d_ct |

## Links

- npm: https://www.npmjs.com/package/clevertap-signed-call
- npm.io page: https://npm.io/package/clevertap-signed-call

## Dependencies (2)

- [jssip](https://npm.io/package/jssip.md) ^3.2.15
- [socket.io-client](https://npm.io/package/socket.io-client.md) ^4.5.1

## Recent versions

- 0.0.10 (latest) — 2024-07-29
- 0.0.9 — 2023-12-13
- 0.0.8 — 2023-10-30
- 0.0.7 — 2023-08-04
- 0.0.5 — 2023-05-24
- 0.0.4 — 2023-03-06
- 0.0.3 — 2023-02-27
- 0.0.2 — 2023-01-12
- 0.0.1 — 2022-10-31

## README

# CleverTap Signed Call Web SDK

## 👋 Introduction
CleverTap provides In-App calls via its Signed Call Web SDK, which means you can make calls on any webpage if a device has an internet connection and the Signed Call Web SDK. This section shows how to integrate the Signed Call Web SDK and manage calls.

## Integrate the Signed Call Web SDK

### Using the Node Package Manager (NPM)
You can add the Signed Call Web SDK as an npm to your web app.

#### Step 1: Use the following npm command to install the package:
```javascript
 npm install clevertap-signed-call --save
```
#### Step 2: Import the installed package as below:

```javascript
import {initSignedCall} from 'clevertap-signed-call'
```
#### Step 3: Initialize and Authenticate the SDK

```javascript
let SignedCallClient

initSignedCall(
  {
    accountId: <string>,
    apikey: <string>,
    cuid: <string>,
    clevertap: <clevertap sdk instance>,
    name: <string / optional>,
    ringtone: <string / optional>
  }
).then(client => SignedCallClient = client)
.catch(err => console.log(err))
```

The options parameter in the `initSignedCall` function expects a JSON object with the following properties:

| Properties | Description |
| --- | ----------- |
| accountId (string, required) | The Account ID is available from the dashboard. |
| apikey (string, required) | The API Key is available from the dashboard |
| cuid (string, required) | Unique user ID of the person making a call.<br>  **Validations**:<br>  - The cuid must range between 5 and 50 characters.<br>- The cuid is case sensitive, and only '_' is allowed as a special character.<br> - The cuid parameter cannot be of the number-number type, that is, - a number followed by another number separated with a special character. For example, org_25 is allowed, but 91_8899555 is not allowed.<br>- You must use a unique cuid for every device.
| clevertap (required)| The Clevertap Web SDK instance.
| name (string, optional)| The name of the initiator.<br> - The name must range between 3 and 50 characters.
| ringtone (string, optional) | The url of the ringtone to be played when the ringer starts.

## Make a Call
The dialing screen displays when the `SignedCallClient` from the `initSignedCall() `function invokes the `call()` method to make an outbound call.
This method returns a promise object whose `then()` and `catch()` can be utilized for the following scenarios:

#### Scenario 1:
When the call is `answered`, the outgoing call screen transitions into the ongoing call screen. After the transition, the `then()` method receives an over status and indicates that the call is completed successfully.

#### Scenario 2:
The `declined` and `missed` statuses received by the `catch()` method indicate whether the receiver rejected the call (decline) or did not answer the call (miss).

The `call()` parameters are as follows:

| Parameter | Description |
| :-------------- | :------------- |
| receiver (required) | It is a string of cuid For example: receiver = 'some_unique_id' |
| context (required) | It specifies the context of the call. For example, Trainer is calling, Grocer is calling, Tutor is calling, and so on.
| callOptions (optional) | It is a JSON object with the following properties:<br>receiver_image (string, optional): This URL displays the receiver's image on the outgoing call screen.<br>initiator_image (string, optional): This URL displays the initiator's image on the incoming call screen.|


## Hangup Call
This functionality depends on user behaviour i.e. if one of the user in a call presses the hangup button on the ongoing call screen, the call termination by default is managed by the sdk.

Only in the case of a metered call, when a business wants to end a call after a specific duration, then they must maintain a timer in the app and call the `SignedCallClient.hangup()` function programatically at an appropriate time.

```javascript
SignedCallClient.hangup()
```

## Logout the SDK
Logout the SignedCallClient via calling `SignedCallClient.logout()` method. It ends all the connections, and to make a new call, you must repeat the Initialization and Authentication steps.
```javascript
SignedCallClient.logout()
```

## Examples

### via NPM
```javascript
  import {initSignedCall} from 'clevertap-signed-call'
  let SignedCallClient
  //initiate the sdk
  initSignedCall({
      accountId, //string, required
      apikey, // string, required
      cuid, // string,required
      clevertap, // clevertap instance, required
      name, // string, optional
      ringtone // string, optional
  }).then(client => SignedCallClient = client).catch(err => console.error(err))

  // make a call
  function call() {
      let callOptions = {
        receiver_image: "", // optional, string
        initiator_image: "" // optional, string
      };

      /**
       * receiver {string, required}: cuid whom you are calling
       * context {reason, required}: reason of call
       * callOptions {optional}
       * */
      SignedCallClient.call(receiver, context,calloptions)
        .then((response) => {
          console.log("Call response : ", response);
        })
        .catch((error) => {
          console.error(error);
        });
    }

    // Hangup a call automatically after 20000ms 
    setTimeout((SignedCallClient.hangup()), 20000)

    // Logout the sdk 
    let logout = function () {
      SignedCallClient.logout();
    }
```

## Errors

| Error | Reason |
| :---------- | :----------------- |
| ERR_MISSING_INITPARAMETERS | One (or more) mandatory parameter is missing in SDK Initialization and Authentication |
| ERR_INVALID_INITPARAMETERS | Parameters are not valid.|
| ERR_MISSING_CT_ACCOUNTID | Signed Call SDK is unable to find the Account ID associated with CleverTap.|
| ERR_MISSING_CT_ID | Signed Call SDK cannot find the CleverTap ID. |
| ERR_INVALID_CREDENTIALS | Signed Call's account ID or API Key is incorrect.
| ERR_ALREADY_SIGNEDIN | The cuid entered is currently connected elsewhere. |
| ERR_MIC_UNAVAILABLE | Microphone permission denied.|
| ERR_OUTGOING_CALL_IN_PROGRESS | If a call is already in progress, then another can only be initiated if the current call is over, missed, declined, or canceled.|
| ERR_INVALID_CALL_PARAMETERS | The parameters provided in Make Call are incorrect.|
| ERR_INTERNET_LOST | The call could not occur successfully because the internet is lost.|
| 404 | The receiver's `cuid` is offline.|

## FAQ

Q. Is Signed Call `accountId` and `apikey` the same as CleverTap's  accountId  and  `token`?
A. No. Signed Call accountId and apikey are different from CleverTap's accountId and token. You can find these details under your dashboard's Signed Call section.

Q. I am getting an `EER_MISSING_CT_ID `error even after passing the correct CleverTap instance to the clevertap-signed-call sdk?

A. This error occurs due to the following reasons:
- The CleverTap SDK's region and accountId parameters are incorrect.
- CleverTap SDK is not initialized.
Recheck these details and if this issue persists, raise an issue at CleverTap Support.

---
_Source: https://npm.io/package/clevertap-signed-call · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
