npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@justcall/justcall-dialer-sdk

v1.3.1

Published

SDK for seamless integration and communication with the JustCall Dialer across diverse web environments.

Downloads

157

Readme

JustCall SDK

This repository contains the TypeScript code for the JustCall Dialer SDK, which allows integration of JustCall Dialer functionality into web applications.

You need a JustCall account to be able to use the dialer and the following features.

Installation

Install the SDK package using npm, yarn or pnpm:

npm install @justcall/justcall-dialer-sdk

or

yarn add @justcall/justcall-dialer-sdk

or pnpm

pnpm add @justcall/justcall-dialer-sdk

Constructor

To use the JustCall Dialer SDK, you need to create an instance of the JustCallDialer class using its constructor. The constructor accepts an object with the following parameters:

  • dialerId: The id of the HTML element where the JustCall Dialer iframe will be embedded.
  • onLogin: A callback function triggered when the user logs in. It receives user details and integration settings, if any.
  • onLogout: A callback function triggered when the user logs out.
  • onReady: A callback function triggered when the JustCall Dialer is ready for use.

Example:

import { JustCallDialer } from "@justcall/justcall-dialer-sdk";

const dialer = new JustCallDialer({
  dialerId: "justcall-dialer",
  onLogin: (data) => {
    console.log("Client receiving Logged in data: ", data);
  },
  onLogout: () => {
    console.log("Client receiving Logged out");
  },
  onReady: () => {
    console.log("Client received on ready callback");
  },
});

on Methods

The on method of the JustCallDialer class allows you to listen for events emitted by the JustCall Dialer. It takes two parameters:

  • event: The type of event you want to listen for. Currently supported events are:

    • call-ringing: Triggered when an incoming/outgoing call starts ringing.
    • call-answered: Triggered when an incoming/outgoing call is answered.
    • call-ended: Triggered when a incoming/outgoing call ends.
  • callback: A callback function that will be executed when the specified event occurs. The function receives event data as a parameter.

Example:

dialer.on("call-ringing", (data) => {
  console.log("Client receiving call-ringing data: ", data);
});

dialer.on("call-answered", (data) => {
  console.log("Client receiving call-answered data: ", data);
});

dialer.on("call-ended", function (data) {
  console.log("Client receiving call-ended data: ", data);
});

unsubscribe(event: JustCallDialerEmittableEvent) method:

Unsubscribes from a specific event emitted by the JustCall dialer that you are currently listening to.

Parameters

  • event: The name of the event that is already subscribed to.

Example

dialer.unsubscribe("call-ringing");

unsubscribeAll() method

Unsubscribes from all events that you are currently listening to, emitted by the JustCall dialer.

Example

dialer.unsubscribeAll();

ready method

The ready method of the JustCallDialer class ensures that the JustCall Dialer is ready for use before executing specific actions. It returns a Promise that resolves when the dialer is ready.

// Ensure the dialer is ready before using isLoggedIn and dialNumber methods
await dialer.ready();
const isLoggedIn = await dialer.isLoggedIn(); // returns true or false
dialer.dialNumber("+1234567890");

isLoggedIn Method

The isLoggedIn method of the JustCallDialer class checks whether the user is logged in to JustCall Dialer. It returns a Promise that resolves to a boolean value indicating the login status.

Note: Ensure that the dialer is in a ready state before calling this method.

Example:

await dialer.ready();
const isLoggedIn = await dialer.isLoggedIn(); // returns true or false

dialNumber Method

The dialNumber method of the JustCallDialer class prepopulates the dialer with the provided phone number. It takes one parameter:

  • number (string): The phone number to dial. It should be in the format accepted by the JustCall Dialer.

Note: Ensure that the dialer is in a ready state before calling this method.

Example:

await dialer.ready();
dialer.dialNumber("+1234567890");

destroy Method

The destroy method of the JustCallDialer class is used to clean up and release resources when the JustCall Dialer instance is no longer needed. It performs the following actions:

  • Unsubscribes from all events that the instance is currently listening to.
  • Removes the JustCall Dialer iframe from the DOM.
  • Resets internal state variables and event listeners.

Example:

dialer.destroy();

Event Data Types (Received in Respective Callbacks):

LoggedInEventData

This data object is passed to the onLogin callback function when the user logs in. It contains the following properties:

  • logged_in (boolean): Indicates whether the user is logged in or not.
  • login_numbers (string[]): An array of phone numbers associated with the user.
  • user_info (object): An object containing user information, including:
    • email (string): The email address of the user.
    • name (string): The name of the user.
{
  "logged_in": true,
  "login_numbers": ["+1234567890", "+1987654321"],
  "user_info": {
    "email": "[email protected]",
    "name": "John Doe"
  }
}

CallRingingEventData

This data object is passed to the callback function when an incoming call starts ringing. It contains the following properties:

  • direction (CallDirection): Specifies the direction of the call, either "inbound" or "outbound".
  • from (string): The phone number of the caller.
  • to (string): The phone number being called.
  • call_sid (string): The unique identifier for the call session.
{
  "direction": "inbound",
  "from": "+1234567890",
  "to": "+1987654321",
  "call_sid": "abcdefgh123456"
}

CallAnsweredEventData

This data object is passed to the callback function when an incoming call is answered. It contains the following properties:

  • call_sid (string): The unique identifier for the call session.
  • direction (CallDirection): Specifies the direction of the call, either "inbound" or "outbound".
  • answered_status (string): Indicates the status of the call when answered.
{
  "call_sid": "CAdemocallsid21345",
  "direction": "inbound",
  "answered_status": "answered"
}

CallEndedEventData

This data object is passed to the callback function when a call ends. It contains the following properties:

  • call_sid (string): The unique identifier for the call session.
  • direction (CallDirection): Specifies the direction of the call, either "inbound" or "outbound".
  • duration (number): The duration of the call session in seconds.
{
  "call_sid": "CAdemocallsid21345",
  "direction": "inbound",
  "duration": 120
}

Justcall Dialer Error Codes

The JustcallDialerErrorCode enum provides error codes for handling various scenarios in the JustCall Dialer SDK.

Error Codes:

  • invalid_event_name: This error occurs when an invalid event name is provided.
  • no_event_name: This error occurs when no event name is provided.
  • dialer_not_ready: This error occurs when the JustCall Dialer is not ready for use.
  • not_subscribed_to_event: This error occurs when attempting to unsubscribe from an event that you were not subscribed to in the first place.
  • no_dialer_id: This error occurs when no dialer ID is provided.
  • dialer_id_not_found: This error occurs when the specified dialer ID is not found.
  • browser_environment_required: This error occurs when the JustCall Dialer SDK is run in non-browser environments.
  • unknown_error: This error occurs when an unknown error is encountered during the operation of the JustCall Dialer SDK.

These error codes are useful for identifying and handling different error scenarios in the JustCall Dialer SDK.

Authorizations for <iframe>

Please note that @justcall/justcall-dialer-sdk will produce an iframe with the following permissions granted:

<iframe
  allow="microphone; autoplay; clipboard-read; clipboard-write; hid"
  src="ttps://app.justcall.io/app/macapp/dialer_events"
  style="width='365px' height='610px'"
>
</iframe>

Contribution

We welcome contributions from the community to improve the JustCall Dialer SDK. To contribute, follow these steps:

  1. Make sure you have PNPM installed on your machine.

  2. Run the following command to create a changeset and generate a changelog:

    pnpm changeset
  3. This command will prompt you to select the type of update you're pushing (patch, minor, or major), and provide a description of the changes made.

  4. After creating the changeset and changelog, commit your changes using Git:

    git add .
    git commit -m "Your commit message"
  5. Push your changes to your fork of the repository and create PR.

Code coverage

Find our code coverage report here: https://saaslabsco.github.io/justcall-dialer-sdk/coverage/