1.0.45 • Published 1 month ago

apnsdk v1.0.45

Weekly downloads
-
License
ISC
Repository
-
Last release
1 month ago

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.
    })
1.0.44

1 month ago

1.0.43

1 month ago

1.0.45

1 month ago

1.0.42

3 months ago

1.0.41

3 months ago

1.0.38

3 months ago

1.0.40

3 months ago

1.0.29

3 months ago

1.0.33

3 months ago

1.0.32

3 months ago

1.0.31

3 months ago

1.0.30

3 months ago

1.0.37

3 months ago

1.0.36

3 months ago

1.0.35

3 months ago

1.0.34

3 months ago

1.0.26

3 months ago

1.0.25

3 months ago

1.0.24

3 months ago

1.0.28

3 months ago

1.0.27

3 months ago

1.0.19

3 months ago

1.0.18

3 months ago

1.0.17

3 months ago

1.0.22

3 months ago

1.0.21

3 months ago

1.0.20

3 months ago

1.0.23

3 months ago

1.0.16

3 months ago

1.0.9

3 months ago

1.0.8

3 months ago

1.0.7

3 months ago

1.0.6

3 months ago

1.0.11

3 months ago

1.0.10

3 months ago

1.0.15

3 months ago

1.0.14

3 months ago

1.0.13

3 months ago

1.0.12

3 months ago

1.0.5

3 months ago

1.0.4

3 months ago

1.0.3

3 months ago

1.0.2

3 months ago

1.0.1

3 months ago

1.0.0

4 months ago