Skip to content

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

Notifications You must be signed in to change notification settings

romangit/xphone

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published