apnsdk
v1.0.45
Published
APN Javascript SIP sofware development kit, ported from JsSIP (https://jssip.net/) javascript SIP library.
Downloads
8
Readme
Overview
- APN --add description here
- JsSIP as a core SIP library
Note
Getting Started
Function
apnsdk - initialize the sdk
/**
* @param {Object} credentials (Mandatory)
* credentials - {
* url: '<api_url>',
* config: {
* account_id: '<your-account-id>',
* token: '<token>',
* api_token: '<api_token>'
* },
* audio: { // optional
* ringing: '<your_custom_ringing_audio>', // mp3 or base64
* ended: '<your_custom_ended_audio>', // mp3 or base64
* busy: '<your_custom_busy_audio>', // mp3 or base64
* },
* auto_register: false, // for auto authenticate the user
* }
*/
apnsdk(credentials).then(/* callback function */).catch(/* callback function*/)
voiceCall - Makes an outgoing voice call.
/**
* https://jssip.net/documentation/api/ua/#method_call
* @param {String} target (Mandatory) - Destination sip username or phone number.
* @param {Object} options (Optional)
* @param {Object} html_id (Optional) - HTML element <audio> id where the media will be attached.
* html_id - { 'audio': '<element_id>' }
*/
voiceCall(target, options, html_id)
videoCall - Makes an outgoing multimedia call.
/**
* https://jssip.net/documentation/api/ua/#method_call
* @param {String} target (Mandatory) - Destination sip username or phone number.
* @param {Object} options (Optional)
* @param {Object} html_id (Optional) - HTML element <audio> and <video> id where the media will be attached.
* html_id - {
* 'audio': '<element_id>',
* 'remote_video': '<video_element_id>',
* 'local_video' : '<video_element_id>'
* }
*/
videoCall(target, options, html_id)
callAnswer - Answer the incoming call. This method is available for incoming sessions only.
/**
* https://jssip.net/documentation/api/session/#method_answer
* @param {Object} options (Optional)
*/
callAnswer(options)
callHangup - Terminate the current session regardless its direction or state.
/**
* https://jssip.net/documentation/api/session/#method_terminate
* @param {Object} options (Optional)
*/
callHangup(options)
refer - Transfer an ongoing call to another party.
/**
* https://jssip.net/documentation/api/session/#method_refer
* @param {String} target (Mandatory) - Destination sip username or phone number.
* @param {Object} options (Optional)
*/
refer(target, options)
uaUnregister - Unregister the user agent.
/**
* https://jssip.net/documentation/api/ua/#method_unregister
* @param {Object} options (Optional)
*/
uaUnregister(options)
uaRegister - Register the user agent.
/**
* https://jssip.net/documentation/api/ua/#method_register
*/
uaRegister(options)
mute - Mutes the local audio and/or video.
/**
* https://jssip.net/documentation/api/session/#method_mute
* @param {Object} options (Optional)
* options - {
* 'audio': true, // Local audio is muted
* 'video': false // Local audio is not muted
* }
*/
mute(options)
unmute - Unmutes the local audio and/or video.
/**
* https://jssip.net/documentation/api/session/#method_unmute
* @param {Object} options (Optional)
* options - {
* 'audio': true, // Local audio is unmuted
* 'video': false // Local audio is muted
* }
*/
unmute(options)
holdCall - Puts the call on hold.
/**
* https://jssip.net/documentation/api/session/#method_hold
* @param {Object} options (Optional)
* @param {Function} callback (Optional) - Function called once the renegotiation has succeeded.
*/
holdCall(options, callback)
unHoldCall - Resumes the call from hold.
/**
* https://jssip.net/documentation/api/session/#method_unhold
* @param {Object} options (Optional)
* @param {Function} callback (Optional) - Function called once the renegotiation has succeeded.
*/
unHoldCall(options, callback)
Usage
Using import
import * as sdk from 'apnsdk'
let config = {
url: '<api url>',
config: {
token: '<your-account-token>',
account_id: '<your-account-id>',
},
auto_register: false,
}
sdk.apnsdk(config)
.then(/*callback function*/)
.catch(/*error handler function*/)
// OR
import {apnsdk, voiceCall} from 'apnsdk'
let config = {
url: '<api url>',
config: {
token: '<your-account-token>',
account_id: '<your-account-id>',
},
auto_register: false,
}
apnsdk(config)
.then(/*callback function*/)
.catch(/*error handler function*/)
Bundled minified
<script src="<your-path>/apnsdk.min.js"></script>
<script type="text/javascript">
apnsdk({
url: '<api url>',
config: {
token: '<your-account-token>',
account_id: '<your-account-id>',
},
auto_register: false,
})
.then(/*callback function*/)
.catch(/*error handler function*/)
</script>
Sample
// Initialize the sdk
apnsdk({
url: 'https://test.com',
config: {
account_id: '80668D7D-8965-4BFD-BF1D-EDCA66FC2024',
token: '9e9a4dd202fe02455ec08e5037719506f78fee5e8704089718835df9d5f3ec24'
},
auto_register: false,
}).then((ua) => {
/**
* Update UI here
*/
// (https://jssip.net/documentation/api/ua/)
this.ua = ua.user_agent
// (https://jssip.net/documentation/api/ua/#section_events)
this.ua.on('connected', (e) => {
// console.log('User connected.')
})
this.ua.on('disconnected', (e) => {
// console.log('User disconnected.');
});
this.ua.on('registered', (e) => {
// console.log('User registered.');
});
this.ua.on('unregistered', (e) => {
// console.log('User unregistered.')
});
this.ua.on('registrationFailed', (e) => {
// causes - https://jssip.net/documentation/api/causes/
// console.log('Registration failed, ' + e.cause)
})
// (https://jssip.net/documentation/api/session/)
this.ua.on('newRTCSession', (e) => {
let session = e.session;
let completeSession = () => {
session = null;
// console.log('Session ended.')
};
if(session.direction === 'incoming'){
// event for inbound call
}
// (https://jssip.net/documentation/api/session/#section_events)
session.on('ended', (e) => {
// https://jssip.net/documentation/api/causes/
// console.log('Ended: ', e.cause)
completeSession()
});
session.on('failed', (e) => {
// https://jssip.net/documentation/api/causes/
console.log('Failed: ', e.cause)
completeSession()
});
session.on('accepted', (e) => {
// when outbound call is answered
});
})
}).catch((error) => {
// TODO: Update UI here etc.
})