XPhone.js
The JS library for develop WebSocket/WebRTC phone apps based on lirax.net (Phone Cloud System)
Download
Installation
In a browser:
CDN:
Using npm:
npm install xphone --save
Usage
Initialization
ES6
;
Make calls
/* Initialization */const phone = ; /* Call to echo-test */phone { phone;}; /* Connection closed */phone console; /* Icomming call */phone { if calltype === phoneINCOMING ; }; /* Handling errors */phone console; /* Change the call parameters */phone { console;}; /* Destroying the call */phone { console;}; /* Authorization to LiraX */phone;
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;
close()
Close the connection
Example
phone;
isOpen()
Check the connection
Returns
Type | Description |
---|---|
Boolean | true if the WebSocket connection is established, false otherwise |
Example
phone && console;
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;
finishCall(line)
Hungup a call
Parameters
Name | Type | Description |
---|---|---|
line | Integer | The number of line |
Example
let line = phone;;
acceptCall(line)
Accept a call
Parameters
Name | Type | Description |
---|---|---|
line | Integer | The number of line |
Example
phone { if calltype === phoneINCOMING ; };
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 { ;};
holdCall(line)
Hold a call
Parameters
Name | Type | Description |
---|---|---|
line | Integer | The number of line |
Example
phone { const line = callline; ;};
conferenceCall(line)
Enable conferencing mode
Parameters
Name | Type | Description |
---|---|---|
line | Integer | The number of line |
Example
phone { const line = callline; ;};
forwardCall(line)
Enable redirection mode
Parameters
Name | Type | Description |
---|---|---|
line | Integer | The number of line |
Example
// Call forwarding 380442388744 to 380442388745const lineFoo = phone;const lineBar = phone; ;
getCalls()
Returns the array of all active calls
Returns
Type | Description |
---|---|
Array | The Array of calls |
Example
console;
Events
onOpen()
Connection is established
Example
phone console;
onClose()
Connection is closed
Example
phone console;
onError(error)
Application error
Parameters
Name | Type | Description |
---|---|---|
error | Object | The Error message |
Example
phone console;
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 { console;};
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 { console;};
onDestroy(call)
Call ended
Parameters
Name | Type | Description |
---|---|---|
call | Object | The Object with call properties (see onCreate event) |
Example
phone { console;};
Instance Variables
wsURL
(String) The URL to which to connect, Default: 'wss://lirax***:1887'
Example
phonewsURL = 'wss://test.com:1887';
callOut
(String) External number, Default: ''
Example
phonecallOut = '380001234567';
reConnect
(Boolean) Automatic reconnection when disconnected, Default: true
Example
phonereConnect = false;