1.0.5 • Published 4 years ago

xphone v1.0.5

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

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

NameTypeDescription
credentialsObjectObject with parameters (see below)
credentials.loginStringSIP number
credentials.passwordStringSIP password

Example

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

close()

Close the connection

Example

phone.close();

isOpen()

Check the connection

Returns

TypeDescription
Booleantrue if the WebSocket connection is established, false otherwise

Example

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

makeCall(phoneNumber)

Make a call

Parameters

NameTypeDescription
phoneNumberStringA Phone Number

Returns

TypeDescription
IntegerThe number of line

Example

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

finishCall(line)

Hungup a call

Parameters

NameTypeDescription
lineIntegerThe number of line

Example

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

acceptCall(line)

Accept a call

Parameters

NameTypeDescription
lineIntegerThe 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

NameTypeDescription
lineIntegerThe number of line
symbolStringThe 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

NameTypeDescription
lineIntegerThe number of line

Example

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

conferenceCall(line)

Enable conferencing mode

Parameters

NameTypeDescription
lineIntegerThe number of line

Example

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

forwardCall(line)

Enable redirection mode

Parameters

NameTypeDescription
lineIntegerThe 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

TypeDescription
ArrayThe 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

NameTypeDescription
errorObjectThe Error message

Example

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

onCreate(call)

The call is created

Parameters

NameTypeDescription
callObjectThe Object with call properties (see below)
call.lineIntegerThe number of line
call.startDateObjectThe date of start call
call.connectDateObjectThe date of connection call
call.phoneNumberStringThe phone number
call.typeIntegerThe type of call (0 - incoming, 1 - outgoing)
call.holdBooleanThe hold mode of call, true if the hold mode is enabled, false otherwise
call.conferenceBooleanThe conference mode of call, true if the hold mode is enabled, false otherwise
call.forwardBooleanThe forward mode of call, true if the hold mode is enabled, false otherwise
call.fileStringLink to the voice file

Example

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

onChange(call)

The properties of the call have changed

Parameters

NameTypeDescription
callObjectThe Object with call properties (see onCreate event)

Example

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

onDestroy(call)

Call ended

Parameters

NameTypeDescription
callObjectThe 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

1.0.5

4 years ago

1.0.4

6 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago