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

xphone

v1.0.5

Published

The WebSocket/WebRTC library by lirax.ua (PBX Cloud Platform)

Downloads

458

Readme

XPhone.js

The JS library for develop WebSocket/WebRTC phone apps based on lirax.net (Phone Cloud System)

Download

Full build

Installation

In a browser:

<script src="dist/xphone.js"></script>

CDN:

<script src="https://cdn.jsdelivr.net/npm/xphone@latest/dist/xphone.js"></script>

Using npm:

npm install xphone --save

Usage

Initialization

ES6

import XPhone from 'xphone';

Make calls

/* Initialization */
const phone = new XPhone(); 

/* Call to echo-test */
phone.onOpen = () => {
  phone.makeCall("200");
};

/* Connection closed */
phone.onClose = () => console.log("Connection closed");

/* Icomming call */
phone.onCreate = call => {
  if (call.type === phone.INCOMING) {
    setTimeout(() => phone.acceptCall(call.line), 3000);
  }
};

/* Handling errors */
phone.onError = error => console.log("error", error);

/* Change the call parameters */
phone.onChange = call => {
  console.log("change", call);
};

/* Destroying the call */
phone.onDestroy = call => {
  console.log("destroy", call);
};

/* Authorization to LiraX */
phone.init({
  login: "1011011",
  password: "mypassword"
});

Build Setup

# copy config file
cp .env.example.js .env.js

# install dependencies
npm install

# build for production with minification
npm run build

# build for production and view the bundle analyzer report
npm run build --report

# run all tests
npm test

Tests

npm test

Support

Tested in Chrome 54-61, Firefox 49-56

Documentation

Instance Methods

init(credentials)

Connection to the service

Parameters

| Name | Type | Description | |----------------------|--------|------------------------------------| | credentials | Object | Object with parameters (see below) | | credentials.login | String | SIP number | | credentials.password | String | SIP password |

Example

phone.init({
  login: '1111111',
  password: 'secret_password',
});

close()

Close the connection

Example

phone.close();

isOpen()

Check the connection

Returns

| Type | Description | |---------|----------------------------------------------------------------- | | Boolean | true if the WebSocket connection is established, false otherwise |

Example

phone.isOpen() && console.log('Connection established');

makeCall(phoneNumber)

Make a call

Parameters

| Name | Type | Description | |----------------------|--------|--------------- | | phoneNumber | String | A Phone Number |

Returns

| Type | Description | |---------|------------------- | | Integer | The number of line |

Example

let line = phone.makeCall('380442388744');

finishCall(line)

Hungup a call

Parameters

| Name | Type | Description | |---------------|---------|--------------------| | line | Integer | The number of line |

Example

let line = phone.makeCall('380442388744');
setTimeout(() => phone.finishCall(line), 10000);

acceptCall(line)

Accept a call

Parameters

| Name | Type | Description | |---------------|---------|--------------------| | line | Integer | The number of line |

Example

phone.onCreate = call => {
  if (call.type === phone.INCOMING) {
    setTimeout(() => phone.acceptCall(call.line), 10000);
  }
};

sendDTMF(line, symbol)

Send a DTMF

Parameters

| Name | Type | Description | |---------------|---------|-------------------------------------------------| | line | Integer | The number of line | | symbol | String | The symbol 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, *, # |

Example

phone.onCreate = call => {
  setTimeout(() => {
    phone.sendDTMF(call.line, '5');
    phone.sendDTMF(call.line, '7');
    phone.sendDTMF(call.line, '9');
    phone.sendDTMF(call.line, '#');
  }, 5000);
};

holdCall(line)

Hold a call

Parameters

| Name | Type | Description | |---------------|---------|--------------------| | line | Integer | The number of line |

Example

phone.onCreate = call => {
  const line = call.line;
  setTimeout(() => phone.holdCall(line), 10000);
};

conferenceCall(line)

Enable conferencing mode

Parameters

| Name | Type | Description | |---------------|---------|--------------------| | line | Integer | The number of line |

Example

phone.onCreate = call => {
  const line = call.line;
  setTimeout(() => phone.conferenceCall(line), 3000);
};

forwardCall(line)

Enable redirection mode

Parameters

| Name | Type | Description | |---------------|---------|--------------------| | line | Integer | The number of line |

Example

// Call forwarding 380442388744 to 380442388745
const lineFoo = phone.makeCall('380442388744');
const lineBar = phone.makeCall('380442388745');

setTimeout(() => {
  phone.forwardCall(lineFoo);
  phone.forwardCall(lineBar);
}, 5000);

getCalls()

Returns the array of all active calls

Returns

| Type | Description | |-----------|--------------------| | Array | The Array of calls |

Example

console.log(phone.getCalls());

Events

onOpen()

Connection is established

Example

phone.onOpen = () => console.log('Connection is established');

onClose()

Connection is closed

Example

phone.onClose = () => console.log('Connection is closed');

onError(error)

Application error

Parameters

| Name | Type | Description | |----------------|--------|---------------------| | error | Object | The Error message |

Example

phone.onError = error => console.log(error);

onCreate(call)

The call is created

Parameters

| Name | Type | Description | |------------------|---------|--------------------------------------------------------------------------------| | call | Object | The Object with call properties (see below) | | call.line | Integer | The number of line | | call.startDate | Object | The date of start call | | call.connectDate | Object | The date of connection call | | call.phoneNumber | String | The phone number | | call.type | Integer | The type of call (0 - incoming, 1 - outgoing) | | call.hold | Boolean | The hold mode of call, true if the hold mode is enabled, false otherwise | | call.conference | Boolean | The conference mode of call, true if the hold mode is enabled, false otherwise | | call.forward | Boolean | The forward mode of call, true if the hold mode is enabled, false otherwise | | call.file | String | Link to the voice file |

Example

phone.onCreate = call => {
  console.log(call);
};

onChange(call)

The properties of the call have changed

Parameters

| Name | Type | Description | |------------------|---------|-------------------------------------------------------| | call | Object | The Object with call properties (see onCreate event) |

Example

phone.onChange = call => {
  console.log(call);
};

onDestroy(call)

Call ended

Parameters

| Name | Type | Description | |------------------|---------|-------------------------------------------------------| | call | Object | The Object with call properties (see onCreate event) |

Example

phone.onDestroy = call => {
  console.log(call);
};

Instance Variables

wsURL

(String) The URL to which to connect, Default: 'wss://lirax***:1887'

Example

phone.wsURL = 'wss://test.com:1887';

callOut

(String) External number, Default: ''

Example

phone.callOut = '380001234567';

reConnect

(Boolean) Automatic reconnection when disconnected, Default: true

Example

phone.reConnect = false;

Official Site

http://www.lirax.net