Skip to main content

WebRTC SDK

PIOPIY Client JS SDK for voice

PIOPIY WebRTC SDK allows you to make and receive voice calls, where making voice calls can be made to a public switched telephone network(PSTN), APP to APP calling and browser to browser calling.

Package Installation

Using NPM

npm install piopiyjs

Using YARN

yarn add piopiyjs

Monolithic Import

In Browser

Clone the repository

Use command git clone to clone the SDK from our TeleCMI github repository.

git clone https://github.com/telecmi/piopiy_client_js.git

Add SDK library to your webpage

<script src="dist/piopiy.min.js" type="text/javascript"></script>

In ESM/Typescript

import PIOPIY from 'piopiyjs';

In CommonJS

var PIOPIY = require('piopiyjs');

Get Started

Initializing the PIOPIY SDK Object

var piopiy = new PIOPIY( {
name: 'Display Name',
debug: false,
autoplay: true,
ringTime: 60
} );

Configuration Parameters

Below is the configuration parameters

AttributeDescriptionAllowed ValuesDefault Value
nameYour Display Name in Appstringnone
debugEnable debug message in browser consoleBooleanfalse
autoplayHandle media stream automaticallyBooleantrue
ringTimeYour incoming call ringing time in secondsnumber60

PIOPIY Methods

Login

Using this method user can able to connect with TeleCMI SBC.

piopiy.login('user_id','password','SBC_URI');

Configuration Parameters

Parameter NametypeDescription
user_idstringThe user login ID
passwordstringThe user login Password
SBC_URIurl
  • Asia - sbcsg.telecmi.com
  • Europe - sbcuk.telecmi.com
  • America - sbcus.telecmi.com
  • India - sbcind.telecmi.com

Make call

Using this method user can able to make call to PSTN or Other user extension.

piopiy.call('PHONE_NUMBER');

Configuration Parameters

Parameter NametypeDescription
PHONE_NUMBERstringEnter phone number or user extension number, Phone number start with country code example '13158050050'

Make call with Extra params

Using this method user can able to make call to PSTN or Other user extension with added extra parameters.

piopiy.call('PHONE_NUMBER', { extra_param: 'lead' });

Configuration Parameters

Parameter NametypeDescription
PHONE_NUMBERstringEnter phone number or user extension number, Phone number start with country code example '13158050050'
extra_paramJSON objectAn optional object containing additional parameters for the call.

Get Call Id

Using this method, user's call_id information can be retrieved.

piopiy.getCallId();

Transfer call

Using this method, users can transfer the call to a user extension number or phone number with a country code.

piopiy.transfer('USER_EXTENSION_NUMBER OR PHONE_NUMBER');

Configuration Parameters

Parameter NametypeDescription
USER_EXTENSION_NUMBER OR PHONE_NUMBERstringEnter phone number or user extension number ,Phone number start with country code example '13158050050'

Merge Call

Using this method, the user can merge the transferred call.

piopiy.merge();

Cancel Call

Using this method, user can cancel transfer call.

piopiy.cancel();

Send DTMF

Using this method user can able to send DTMF tone to ongoing call.

piopiy.sendDtmf('DTMF_TONE');

Configuration Parameters

Parameter NametypeDescription
DTMF_TONEstringYour DTMF tone input

Hold Call

Using this method user can able to hold ongoing call.

piopiy.hold();

Unhold Call

Using this method user can able to unhold ongoing call.

piopiy.unHold();

Mute Call

Using this method user can able to mute ongoing call.

piopiy.mute();

Unmute Call

Using this method user can able to unmute ongoing call.

piopiy.unMute();

Answer call

Using this method user can able to answer incoming call.

piopiy.answer();

Reject call

Using this method user can able to reject or disconnect incoming call.

piopiy.reject();

Hangup call

Using this method user can able to hangup ongoing call.

piopiy.terminate();

Logout

Using this method user can able to logout from SBC session.

piopiy.logout();

PIOPIY Call Event Handler

Login

This event will triger when user login sucessfully

piopiy.on( 'login', function ( object ) {

// Data is JSON it contain event and status.
});

Example

piopiy.on( 'login', function ( object ) {

if(object.code == 200) {

// Login successfully and do your stuff here.

}
});

List of event and status

codestatus
200Login Successfully

LoginFailed

This event will trigger when user authentication failed.

piopiy.on( 'loginFailed', function ( object ) {

// Data is JSON it contain event and status.
});

Example

 piopiy.on( 'loginFailed', function ( object ) {

if(object.code == 401) {

// Verify that the user_id and password are correct. 
}
});

List of event and status

codestatus
401invalid user

Trying

This event will trigger when user make call to phone number or extension (Destination Number)

piopiy.on( 'trying', function ( object ) {

// Data is JSON it contain event and status.
});

Example

piopiy.on( 'trying', function ( object ) {

if(object.code == 100 ) {

// The outgoing call is currently being started.
}
});

List of event and status

codestatustype
100tryingoutgoing

Ringing

This event will trigger when call start ringing.

piopiy.on( 'ringing', function ( object ) {

// Data is JSON it contain event and status.
});

Example

piopiy.on( 'ringing', function ( object ) {

if(object.code == 183) {

// An incoming or outgoing call is ringing.
}
});

List of event and status

codestatustype
183ringingoutgoing & incoming

Answered

This event will trigger when ongoing call was answered.

piopiy.on( 'answered', function ( object ) {

// Data is JSON it contain event and status.
});

Example

piopiy.on( 'answered', function ( object ) {

if(object.code == 200) {

// An incoming or outgoing call is answered.
}
});

List of event and status

codestatus
200answered

CallStream

This event will trigger when mediastream established.

piopiy.on( 'callStream', function ( object ) {

// Data is JSON it contain event and status.
});

Example

piopiy.on( 'callStream', function ( object ) {

// MediaStream has been established.
});

List of event and status

codestream
200MediaStream

Transfer

This event will be triggered when a user transfers a call to a user extension number or a phone number with a country code.

piopiy.on( 'transfer', function ( object ) {

// Data is JSON it contain event and status.
});

Example

piopiy.on( 'transfer', function ( object ) {

if(object.code == 100) {

// An incoming or outgoing call is transfered.
}
});

List of event and status

codeglobalstate
100trueinit,started,bridged,ended

InComingCall

This event will trigger when user recive incmoing call.

piopiy.on( 'inComingCall', function ( object ) {

// Data is JSON it contain event and status.
});

Hangup

This event will trigger when user reject or hangup incmoing call.

piopiy.on( 'hangup', function ( object ) {

// Data is JSON it contain event and status.
});

Example

piopiy.on( 'hangup', function ( object ) {

if(object.code == 200 ) {

// to hangup the incoming and ongoing calls.
}
});

List of event and status

codestatus
200call hangup

Ended

This event will trigger when ongoing call end.

piopiy.on( 'ended', function ( object ) {

// Data is JSON it contain event and status.
});

Example

piopiy.on( 'ended', function ( object ) {

if(object.code == 200 ) {

// An incoming or outgoing call is ended.
}
});

List of event and status

codestatus
200call ended
408Request Timeout
480Temporarily Unavailable
484Address Incomplete
486Busy Here

Hold

This event will trigger when ongoing call on hold.

piopiy.on( 'hold', function ( object ) {

// Data is JSON it contain event and status.
});

Example

piopiy.on( 'hold', function ( object ) {

if(object.code == 200 ) {

// The call is now being hold.
}
});

List of event and status

codestatuswhom
200call on holdmyself

UnHold

This event will trigger when ongoing call on unhold.

piopiy.on( 'unhold', function ( object ) {

// Data is JSON it contain event and status.
});

Example

piopiy.on( 'unhold', function ( object ) {

if(object.code == 200 ) {

// The call is now being released.
}
});

List of event and status

codestatuswhom
200call on activemyself

RTCStats

This event will trigger when user RTCStats .

piopiy.on( 'RTCStats', function ( object ) {

// Data is JSON it contain event and status.
});

Example

piopiy.on( 'RTCStats', function ( object ) {

if(object.codec == “audio/PCMU) {

// The user logged out successfully. 
}
});

List of event and status

ParatameterValue
codec“audio/PCMU”
delay0.042
fractionLost0
jitter0.000125
network“wifi”
packetLostRate0
rountTrip0.07360799999999999
totalPacketLost1

Error

This event will trigger when error will occurr.

piopiy.on( 'error', function ( object ) {

// Data is JSON it contain event and status.
});

Example

piopiy.on( 'error', function ( object ) {

if(object.code == 1001 || object.code == 1002) {

// If there are any incorrect commands in the function, displays error.
}
});

List of event and status

codestatus
1001 & 1002common error

Logout

This event will trigger when user logout .

piopiy.on( 'logout', function ( object ) {

// Data is JSON it contain event and status.
});

Example

piopiy.on( 'logout', function ( object ) {

if(object.code == 200 ) {

// The user logged out successfully. 
}
});

List of event and status

codestatus
200logout successfully