anynode WebRTC Client API

anynode WebRTC JavaScript Client API for Web Applications

December 17, 2025

1 Abstract

The anynode WebRTC JavaScript Client API for Web applications provides and interface to communicate to anynode and handle incoming and outgoing calls.

The API provides functions encapsulated in classes to create the communication to anynode, to login (register) to anynode and to handle call and media control.

For media handling audio and video is supported, the application selects the media by providing corresponding HTML elements to the API.

2 Usage of the anynode WebRTC Client API

This section gives a short introduction on how to use the anynode WebRTC Client API classes to create applications that create outbound calls and accept incoming calls.

2.1 Accessing the API

To access the anynode JavaScript Client API the application must import the classes and definitions from the file anynode_webrtc.js. This following statement must be placed in the applications JavaScript file.

import
{
    LOGIN_STATES,
    CALL_STATES,
    DISC_REASON,
    anynodeWebRtcInstance,
    anynodeWebRtcCall
} from "./anynode_webrtc.js"

Because the anynode WebRTC Client API is implemented as classes, the JavaScript importing anynode_webrtc.js must be loaded with the type module in the HTML document. The following sample code assumes that the JavaScript main.js imports the file anynode_webrtc.js.

<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>anynode WebRTC Phone</title>
    <link rel="stylesheet" href="css/style.css">
    <!-- Script importing anynode WebRTC client API -->
    <script type="module" src="./js/main.js"></script>
  </head>
</html>

2.2 Application-Startup

The first operation the application must do to use the anynode WebRTC Client API is to create an instance of anynodeWebRTCInstance. Details about anynodeWebRTCInstance are available in section 3.1.

Before calls can be processed the application must login to anynode via the login method. The login parameter depends on the configuration of anynode.

With the login the application provides event handler to receive login status changes (section 3.1.3.1), incoming calls (section 3.1.3.2) and restored calls (section 3.1.3.3).

2.3 Event-Handling

Most processing of application requests is asynchronous. The application must register event handler to get the progress or result of a request. Status changes for login state, call state and media changes are also signaled via event handler.

2.4 Login to anynode

To process any calls the application must login to anynode. With the login a local phone number is assigned to the application, which is required to receive incoming calls

The login parameter depends on the configuration of anynode. If authentication is required, the application must provide username and password. Another option is to authenticate via a token. The token is a JSON Web Token and the accepted signing modes for the token must be configured in anynode.

The local phone number of the application is either assigned by anynode or by the application. This also depends on the configuration of anynode. If anynode assigns the number, the phone number is retrieved from a database using the username to query for the user data. If the configuration assumes that the application specifies the phone number, the application must provide a number, otherwise the login will fail. The number should be specified in E.164 format.

Once the login is completed anynode will pass calls with a destination address that matches the assigned number to the application

If the login is done via a token and the application does not want to receive incoming calls, no username or phone number are required.

2.5 Outgoing Calls

To initiate an outgoing call the application calls createOutgoingCall on the anynodeWebRTCInstance to create an anynodeWebRtcCall instance. The local address information is automatically assigned to the local address of the call instance

Via the method setCallStateHandler an event handler is registered to receive notifications about call state changes. The dialing starts when the application calls the dial method and passes remote address information. The call state handler will be called when the call state changes.

2.6 Incoming Calls

With the application startup an event handler for incoming calls is registered at the anynodeWebRtcInstance. When an incoming call is detected anynodeWebRtcInstance creates an annynodeWebRtcCall instance and sets local and remote address information. Then the applications incoming call handler is called.

If the application is able to receive a call, it calls the method setCallStateHandler to register an event handler to receive notification about call state changes. Once the application calls the answer method the call will be connected, and the state is reported to the call state handler.

If the application is not able to process the call, it calls the decline method on the signaled anynodeWebRtcCall instance.

2.7 Media Resources

The media resources required for the WebRTC media communication are handled inside the anynodeWebRtcCall instance. Input media resources, like microphone and camera, are automatically allocated. The output media resources must be specified by the application by setting the HTML media element of the web page via the functions setAudioElement or setVideoElements.

2.8 Switching between Calls

Multiple calls can be made in parallel on the anynodeWebRtcInstance and they must share the available media resources. The application can switch the media resources between the calls via the hold and retrieve methods of anyodeWebRtcCall.

2.9 Call Transfer

Calls can be transferred by the WebRTC client. Based on two existing anynodeWebRtcCall instances, that are in the connected or hold state, the call transfer can be initiated by calling the transfer method of anynodeWebRtcCall. The call transfer will be handled by anynode and for both call instances the disconnect will be reported via the call state handler.

2.10 Web Page reload

When the web page is reloaded the connection to anynode is closed and must be reestablished. The reestablishment normally requires a new login providing the credentials. The anynode WebRTC Client API and anynode provide a mechanism to reestablish the connection and login via a session identifier. For security reasons the time a session identifier remains valid can be configured in the anynode configuration.

With the successful login the application can retrieve the session identifier via the method getLoginIdentifier. The application should store the session identifier in the cookies of the web page. When the web page is reloaded, the application can restore the identifier and call the method tryRestoreLogin. If anynode accepts the session identifier the login status handler is called with the status set to LOGIN_STATES.SUCCESS.

If any call was active when the web page was reloaded, anynode signals the status of the call to the restore call handler, passed to tryRestoreLogin, is called. The application must set the event handler for call state notification and set the HTML media element for media output.

If anynode does not accept the session identifier, the login status handler is called with the status set to LOGIN_STATES.LOGIN_RESTORE_FAILED.

2.11 Background Notification

The WebRTC client running on a mobile device or as web-browser application may not be in foreground when a call should be routed to the client. In this case no connection between the WebRTC client and anynode may exist to signal the call to the client. Via the configuration a messaging service can be configured and anynode will send a notification via the messaging service to the client. The client will then establish the connection using a token provided with the notification. Via the token the client is assigned to the existing registration instance. Once the client is registered again anynode will signal the call.

The notification is currently supported via Google Firebase Cloud Messaging (FCM), more systems like Windows Push Notification Services (WNS) may follow.

The usage of background notification is controlled by the JavaScript application. The method login and tryRestoreLogin contain a boolean parameter indicating if background notification is enabled or not. The parameter to register with Google Firebase are configured in anynode and handled inside anynodeWebRtcInstance.

For notification signaled when the web page is closed Google Firebase requires a file called firebase-messaging-sw.js in the root of the web application. A sample file is delivered with the anynode WebRTC JavaScript Client API. The parameter to register with Google Firebase must be entered in the file and replace the keywords.

const firebaseConfig = {
    apiKey: "<YOUR API_KEY>",
    authDomain: "<YOUR AUTH_DOMAIN>",
    projectId: "<YOUR PROJECT_ID>",
    storageBucket: "<YOUR STORAGE_BUCKET>",
    messagingSenderId: "<YOUR MESSAGING_SENDER_ID>",
    appId: "<YOUR APP_ID>",
    measurementId: "<YOUR MEASUREMENT_ID>"
};

2.12 Communication to anynode

The communication between the WebRTC client and anynode is currently done via a WebSocket connection initiated by the WebRTC client. Other communication protocols like HTTP long poll may be added in the future.

The anynodeWebRtcInstance and anynodeWebRtcCall classes are independent from the used communication protocol. The access to the communication module is abstracted via the interface anynodeCommInterface. The implementation of anynodeCommInterface for WebSocket is implemented in the class anynodeComm located in the file anynode_comm.js.

2.13 Diagnostic

For diagnostic the JavaScript classes can write messages to the debug console of the browser. By default, no messages are written. The application can control writing messages via the method controlLogging.

3 API-Documentation

3.1 anynodeWebRtcInstance

The class anynodeWeRtcInstanceestablishes the communication to anynode and provides login services. Outgoing call instances are created based on the instance and incoming calls are signaled. When creating any instance of anynodeWebRtcInstance the application provides handler for login status and incoming call notification.

3.1.1 Constructor

anynodeWebRtcInstance(onLoginStatus, onIncomingCall, clientDescription)

Creates a new instance of anynodeWebRtcInstance.

Parameters

onLoginStatus

Handler provided by the application and called when the login status changes.

onIncomingCall

Handler provided by the application and called to signal an incoming call.

clientDescription

The symbolic description of the WebRTC client. The parameter is optional, if set to null the default anynode WebRTC JavaScript <VERSION> is used.

Return value

An instance of anynodeWebRtcInstance.

Example

function onLoad() {
    anynodeInst = new anynodeWebRtcInstance(onLoginStatus, onIncomingCall, null);
}
function onLoginStatus(status) {
    console.log('Login state: ' + status);
}
function onIncomingCall(call) {
    console.log('onIncomingCall');
}

3.1.2 Methods

3.1.2.1 login

login(server, secure, notification, username, password, number)

Called by the application to login to anynode and register a phone number to listen.

Parameters

server

String parameter containing the URL to connect to anynode.

secure

Boolean parameter to specify if the connection uses a secure mode (e.g. TLS). It is recommended to use a secure mode.

notification

Boolean parameter to specify if the client should register for background notification.

username

String parameter containing the username for authentication.

password

String parameter containing the password for authentication.

number

Optional string parameter containing the number to register with anynode. It depends on the configuration of anynode, if this parameter is required.

Return value

None

Remarks

The method initiates the connection to anynode using the given parameter for authentication. The method returns immediately, the progress is reported via the onLoginStatus handler (section 3.1.3.1) registered when the anynodeWebRtcInstance was created (section 3.1).

Example

function onLogin() {
    let url = document.getElementById(nameLoginUrl);
    let username = document.getElementById(nameLoginUsername);
    let password = document.getElementById(nameLoginPwd);
    let number = document.getElementById(nameLoginNumber);
    anynodeInst.login(url.value, true, false, username.value,
                     password.value, number.value);
}

3.1.2.2 loginWithToken

loginWithToken(server, secure, token, username, number)

Called by the application to login via token to anynode and optionally register a phone number to listen.

Parameters

server

String parameter containing the URL to connect to anynode.

secure

Boolean parameter to specify if the connection uses a secure mode (e.g. TLS). It is recommended to use a secure mode.

token

String parameter containing the token for authentication.

username

Optional string parameter containing the username for phone number assignment.

number

Optional string parameter containing the number to register for incoming calls.

Return value

None

Remarks

The method initiates the connection to anynode using the given token for authentication. The method returns immediately, the progress is reported via the onLoginStatus handler (section 3.1.3.1) registered when the anynodeWebRtcInstance was created (section 3.1).

Applications that authenticate via token and doing only outgoing calls, like Call Me applications, do not need to specify a username of phone number. In this case no phone number is assigned, and no incoming calls are routed.

The token is a JSON web token. The requirements for signing the token are configured in anynode.

Example

let anynodeInst = null;
let anynodeCall = null;
function onCallme() {
    let url = document.getElementById(nameLoginUrl);
    let token = getTokenCreatedByWebServer();
    anynodeInst = new anynodeWebRtcInstance(onLoginStatus, null, null);
    anynodeInst.loginWithToken(url.value, true, token, null, null);
}
function onLoginStatus(status) {
    if(status === LOGIN_STATES.SUCCESS) {
        anynodeCall = anynodeInst.createOutgoingCall();
        anynodeCall.setCallStateHandler(onCallState);
        anynodeCall.dial('+4953638195999', '');
    }
}

3.1.2.3 logout

logout()

Called by the application to terminate an existing login.

Parameters

None

Return value

None

Remarks

The method initiates the logout from anynode and releases the connection to anynode once done. The method returns immediately, the progress is reported by the onLoginStatus handler (section 3.1.3.1) registered when the anynodeWebRtcInstance was created (section 3.1).

Example

function onLogout() {
    anynodeInst.logout();
}

3.1.2.4 tryRestoreLogin

tryRestoreLogin(server, secure, notification, identifier, onRestoreCall)

Called by the application to restore a previous login, e.g. after a page reload.

Parameters

server

String parameter containing the URL to connect to anynode.

secure

Boolean parameter to specify if the connection uses a secure mode (e.g. TLS). It is recommended to use a secure mode.

notification

Boolean parameter to specify if the client should register for background notification.

identifier

String parameter containing the identifier provided with the initial login.

Return value

True if the restore is initiated.

Remarks

The method initiates the restore of the login e.g. after a refresh of the Web page. The required identifier was provided with the initial login and the application should store this identifier in a cookie.

The method returns immediately, the progress is reported by the onLoginStatus handler (section 3.1.3.1) registered when the anynodeWebRtcInstance was created (section 3.1).

If any call was active for the instance the onRestoreCall handler (section 3.1.3.3) is called for each call to report the status and to restore the media.

Example

function onLoad() {
    let restoreActive = false;
    let id = tryGetCookie('loginIdentifier');
    if(id !== null) {
        let url = document.getElementById(nameLoginUrl);
        if(url !== null) {
            restoreActive = anynodeInst.tryRestoreLogin(url.value, true, false, id, onRestoreCall);
        }loginIdentifier
    }
}

3.1.2.5 getLoginIdentifier

getLoginIdentifier()

Called by the application to retrieve the login identifier assigned by anynode.

Parameters

None

Return value

The login identifier assigned by anynode

Remarks

The method returns the login identifier assigned by anynode. The identifier is used to restore a login via tryRestoreLogin (section 3.1.2.4 after web page reload.

Example

function onLoginStatus(status) {
    if(status === LOGIN_STATES.SUCCESS) {
      identifier = anynodeInst.getLoginIdentifier();
    }
}

3.1.2.6 getLocalDisplayName

getLocalDisplayName()

Called by the application to get the local display name assigned by anynode during login.

Parameters

None

Return value

The name of the logged in user. See remarks for details.

Remarks

The local display name depends on the anynode configuration. If the number to listen for is assigned by the WebRTC client, this is the username from the login credentials. If anynode assigns the number, the display name might be overwritten from the database. The display name is used as local display name in outgoing calls.

Example

function onLoginStatus(status) {
    if(status === LOGIN_STATES.SUCCESS) {
      name = anynodeInst.getLocalDisplayName();
    }
}

3.1.2.7 getLocalDialString

getLocalDialString()

Called by the application to get the local dial string (phone number) assigned by the application or anynode during login.

Parameters

None

Return value

The phone number (dial string) of the logged in user. See remarks for details.

Remarks

The assignment of the phone number (dial string) to listen for incoming calls depends on the anynode configuration and is either specified by the application during login or by anynode from the configured database. The phone number is used as local number in outgoing calls.

Example

function onLoginStatus(status) {
    if(status === LOGIN_STATES.SUCCESS) {
      number = anynodeInst.getLocalDialString();
    }
}

3.1.2.8 createOutgoingCall

createOutgoingCall()

Called by the application to an outgoing call instance.

Parameters

None

Return value

An instance of anynodeWebRtcCall (section 3.2)

Remarks

The method creates an instance of anynodeWebRtcCall and initializes local address information. The instance can be used to initiate an outgoing call.

Example

function onButtonDial() {
    anynodeCall = anynnodeInst.CreateOutgoingCall();
    anynodeCall.setCallStateHandler(onCallState);
    anynodeCall.dial(number, '');
}
function onCallState(call, state) {
}

3.1.2.9 controlLogging

controlLogging()

Called by the application to enable of disable writing of diagnostic messages.

Parameters

enable

Boolean parameter, if set to true diagnostic messages are written.

Return value

none

Remarks

The method controls the writing of diagnostic messages to the debug console of the browser. The method can be called at any time.

Example

function onLoad() {
    anynodeInst = new anynodeWebRtcInstance(onLoginStatus, onIncomingCall, null);
    anynodeInst.controlLogging(true);
}

3.1.3 Events

3.1.3.1 onLoginState

onLoginStatus(status)

Called by anynodeWebRtcInstance when the login status changed.

Parameters

status

The new login status.

Return value

None.

Remarks

The method is called when the login status changed. Possible values of the status parameter are:

CONNECTING

The connection to anynode is initiated

SUCCESS

The login to anynode was successful. The registered phone number and display name can be retrieved via...

SERVER_ACCESS

The connection to anynode failed. Reasons might be an invalid server address, a certificate issue or an authentication issue.

DIAL_STRING_MISSING

The configuration of anynode requires that a phone number is provided with the login.

NO_DIAL_STRING_FOR_USER

For the given user anynode could not retrieve a phone number.

CONNECTION_LOST

The connection to anynode is lost

LOGGED_OUT_IMPLICIT

The user was logged out by anynode.

LOGGED_OUT_EXPLICIT

The logout was initiated by the application.

LOGIN_RESTORE_FAILED

Restoring the login after a page reload failed. This might depend on timeout parameter configured in anynode.

Example

function onLoginStatus(status) {
    console.log('Login state: ' + status);
    if(status === SUCCESS) {
        setCookie('loginIdentifier', anynodeInst.getLoginIdentifier());
    }
}

3.1.3.2 onIncomingCall

onIncomingCall(call)

Called by anynodeWebRtcInstance when an incoming call is signaled.

Parameters

call

An instance of anynodeWegRtcCall. For more information refer to section 3.2

Return value

None.

Remarks

The method is called when an incoming call is signaled by anynode. The application may retrieve any remote address information. A call state handler should be assigned to get information about call state changes.

Example

function onIncomingCall(call) {
    console.log('onIncomingCall');
    anynodeCall.setCallStateHandler(onCallState);
}
function onCallState(call, state) {
}

3.1.3.3 onRestoreCall

onRestoreCall(call)

Called by anynodeWebRtcInstance when a call was active, and the Web page was refreshed.

Parameters

call

An instance of anynodeWegRtcCall. For more information refer to section 3.2

Return value

None.

Remarks

The method is called for each active call when a refresh of the web page occurred. The application may read call related information to refresh the display. A call state handler should be assigned to get information about call state changes. The current call state will be signaled to the call state handler and if the call was connected this implicitly establishes the media.

Example

function onRestoreCall(call) {
    console.log('onRestoreCall');
    anynodeCall.setCallStateHandler(onCallState);
}
function onCallState(call, state) {
}

3.2 anynodeWebRtcCall

The class anynodeWeRtcCall handles an incoming or outgoing call. An instance of anynodeWeRtcCall is either created by the application by calling createOutgoingCall (section 3.1.2.8) or by anynodeWeRtcInstance when an incoming call is signaled.

3.2.1 Constructor

Instances of anynodeWeRtcCall are only created by the class anynodeWeRtcInstance. The application should not create an instance directly. Therefore the constructor is not documented here.

3.2.2 Methods

3.2.2.1 setCallStateHandler

setCallStateHandler(onCallState)

Called by the application to set a handler that receives call state notification.

Parameters

onCallState

Handler provided by the application and called when the call status changes.

Return value

None

Remarks

The method assigns an event handler to be called when the state of the call changes. For details on call states refer to onCallState (section 3.2.3.1).

Example

function onButtonDial() {
    anynodeCall = anynnodeInst.CreateOutgoingCall();
    anynodeCall.setCallStateHandler(onCallState);
    anynodeCall.dial(number, '');
}
function onCallState(call, state) {
}

3.2.2.2 setAudioElement

setAudioElement(element)

Called by the application to set the the element for audio output.

Parameters

element

The HTML audio element, must be of type HTMLAudioElement.

Return value

None

Remarks

The method assigns the HTML audio element to play the received audio data. This automatically allocates the microphone and starts media negotiation.

Example

function onCallState(call, state) {
    if(state === CALL_STATES.CONNECTED) {
        if( !call.hasAudioElement() ) {
            anynodeCall.setAudioElement(document.getElementById('localAudio') as HTMLMediaElement);
        }
    }
}

3.2.2.3 hasAudioElement

hasAudioElement()

Called by the application to check if a audio element is already assigned.

Parameters

None

Return value

True if the audio element is already set, false if not.

Example

For an example refer to setAudioElement(section 3.2.2.2).

3.2.2.4 setVideoElements

setVideoElements(localElement, remoteElement)

Called by the application to set the the element for audio output.

Parameters

localElement

The HTML video element to stream the local video, must be of type HTMLVideoElement.

remoteElement

The HTML video element to stream the remote video, must be of type HTMLVideoElement.

Return value

None

Remarks

The method assigns the HTML video elements to stream local and remote video and audio data. This automatically allocates the camera and microphone and starts media negotiation.

Example

function onCallState(call, state) {
    if(state === CALL_STATES.CONNECTED) {
        if( !call.hasVideoElements() ) {
            anynodeCall.setVideoElements(document.getElementById('localVideo'),
                                         document.getElementById('remoteVideo'));
        }
    }
}

3.2.2.5 hasVideoElements

hasVideoElements()

Called by the application to check if local and remote video element are already assigned.

Parameters

None

Return value

True if the video elements are already set, false if not.

Example

For an example refer to setVideoElements(section 3.2.2.4).

3.2.2.6 setMediaStateHandler

setMediaStateHandler(handler)

Called by the application to set a handler that receives media state notification.

Parameters

handler

Handler provided by the application and called when the negotiated media changes to video.

Return value

None

Remarks

The method assigns an event handler to be called when the media negotiation is finished and video is negotiated. The media state handler is only required for applications using video.

Example

function onButtonDial() {
    anynodeCall = anynnodeInst.CreateOutgoingCall();
    anynodeCall.setCallStateHandler(onCallState);
    anynodeCall.setMediaStateHandler(onMediaState);
    anynodeCall.dial(number, '');
}
function onMediaState(call) {
    if(call.getMediaVideoActive()) {
        // switch view to video
    }
}

3.2.2.7 dial

dial(number, name)

Called by the application to initiate an outgoing call.

Parameters

number

The number to dial.

name

Optional display name.

Return value

None

Remarks

The method initiates an outgoing call. The call state will be reported to the handler assigned by setCallStateHandler.

Example

For an example refer to setCallStateHandler(section 3.2.2.1).

3.2.2.8 accept

accept()

Called by the application to accept an incoming call.

Parameters

None

Return value

None

Remarks

The method accepts an incoming call, which places the call into ringing state. The call state will be reported to the peer and to the handler assigned by setCallStateHandler.

Example

function onIncomingCall(call) {
    if(anynodeCall === null) {
        anynodeCall = call;
        anynodeCall.setCallStateHandler(onCallState);
        anynodeCall.accept();
    } else {
        call.decline();
    }
}

3.2.2.9 answer

answer()

Called by the application to answer an incoming call.

Parameters

None

Return value

None

Remarks

The method answers an incoming call. The call state will be reported to the handler assigned by setCallStateHandler.

Example

function onIncomingCall(call) {
    if(anynodeCall === null) {
        anynodeCall = call;
        anynodeCall.setCallStateHandler(onCallState);
        anynodeCall.answer();
    } else {
        call.decline();
    }
}

3.2.2.10 decline

decline()

Called by the application to decline an incoming call.

Parameters

None

Return value

None

Remarks

The method declines an incoming call.

Example

For an example refer to answer (section 3.2.2.9).

3.2.2.11 disconnect

disconnect()

Parameters

None

Return value

None

Remarks

The method disconnects a call. The call state handler will be called with the state set to DISCONNECTED once anynode confirms the termination of the call.

Example

function onButtonDisconnect() {
    if(anynodeCall !== null) {
        anynodeCall.disconnect();
    }
}

3.2.2.12 hold

hold()

Called by the application to place a call on hold.

Parameters

None

Return value

None

Remarks

The method places a call on hold. The call state handler will be called with the state set to HELD and the media channel is removed.

Example

function onButtonHold() {
    if(anynodeCall !== null) {
        anynodeCall.hold();
    }
}

3.2.2.13 retrieve

retrieve()

Called by the application to retrieve a call.

Parameters

None

Return value

None

Remarks

The method retrieves a call previously placed on hold. The call state handler will be called with the state set to CONNECTED and the media channel is established.

Example

function onButtonRetrieve() {
    if(anynodeCall !== null) {
        anynodeCall.hold();
    }
}

3.2.2.14 transfer

transfer(transferCall)

Called by the application to transfer two calls.

Parameters

transferCall

The call instance to complete the transfer.

Return value

None

Remarks

The method transfers the call to the transferCall. Once anynode completes the transfer both calls will be disconnected and the call state handler will be called with the state set to DISCONNECTED.

Example

function onButtonTransfer() {
    if((anynodeCallOne !== null) && (anynodeCallTwo !== null)) {
        anynodeCallOne.transfer(anynodeCallTwo);
    }
}

3.2.2.15 sendDigit

sendDigit(digit)

Called by the application to send a digit via DTMF.

Parameters

digit

The digit to send.

Return value

None

Remarks

The method sends a digit via DTMF. The call must be in the CONNECTED state and the media channel must be active.

Example

function onButtonDigitOne() {
    if(anynodeCall !== null) {
        anynodeCallOne.sendDigit('1');
    }
}

3.2.2.16 getState

getState()

Called by the application to get the current call state.

Parameters

None

Return value

The current call state.

Remarks

The method returns the current call state. For a list of available call states refer to onCallState (section 3.2.3.1).

3.2.2.17 getDisconnectReason

getDisconnectReason()

Called by the application to get the reason for the call termination.

Parameters

None

Return value

The disconnect reason.

Remarks

The method returns the disconnect reasons. Possible values for the DISC_REASON are:

SUCCESS

The call was successfully connected.

DIALSTRING

The call could not be completed, because the dial string is not valid.

PERMISSION

The call could not be completed because of insufficient permission.

CONGESTION

The call could not be completed because of a congestion situation.

EQUIPMENT

The call could not be completed because required equipment could not be allocated.

BUSY

The remote party was busy.

REDIRECTED

The call was redirected.

NOTRESPONDING

The called party did not respond to the call.

NOTSELECTED

The call was signaled to multiple endpoints and another one answered.

REJECTED

The remote party rejected the call.

USERTERMINATED

The call was terminated by the application.

MEDIA

The call could not be completed because of a media error.

ERROR

An unspecified error occurred.

3.2.2.18 getLocalNumber

getLocalNumber()

Called by the application to get the local number of the call.

Parameters

None

Return value

String containing the local number.

3.2.2.19 getLocalName

getLocalName()

Called by the application to get the local display name of the call.

Parameters

None

Return value

String containing the local display name.

3.2.2.20 getRemoteNumber

getRemoteNumber()

Called by the application to get the remote number of the call.

Parameters

None

Return value

String containing the remote number.

3.2.2.21 getRemoteName

getRemoteName()

Called by the application to get the remote display name of the call.

Parameters

None

Return value

String containing the remote display name.

3.2.2.22 getMediaVideoActive

getMediaVideoActive()

Called by the application to check if video has been negotiated.

Parameters

None

Return value

Boolean value set to true, if video has been negotiated.

3.2.3 Events

3.2.3.1 onCallState

onCallState(call, status)

Called by anynodeWebRtcCall when the call status changed.

Parameters

call

The call instance of anynodeWebRtcCall which state changed.

status

The new call status.

Return value

None.

Remarks

The method is called when the call status changed. The call instance is identified by the parameter call. Possible values of the status parameter are:

IDLE

The call is created for an outgoing call and dialing has not yet started.

DIALING

The dialing has been initiated by the application. No response from anynode so far.

OFFERING

The call is created for an incoming call and is not yet accepted or answered by the application.

RINGING

The call is ringing.

CONNECTED

For call is connected, media can be exchanged.

HOLDING

The is placed on hold by the anynode

HELD

The call is placed on hold by the application. The media channel has been terminated.

DISCONNECTED

The call has ended.

Example

function onCallStatus(call, status) {
    console.log('Call state: ' + status);
    if( anynodeCall === call) {
      if(status === CONNECTED) {
        let number = call.getRemoteNumber();
        setElementText(nameCallStatus, 'Connected to ' + number);
    }
}

3.2.3.2 onMediaState

onMediaState(call)

Called by anynodeWebRtcCall when the media status changed between audio and video.

Parameters

call

The call instance of anynodeWebRtcCall which state changed.

Return value

None.

Remarks

The method is called when the media status changed between audio and video. The call instance is identified by the parameter call. The application may switch the display accordingly.

Example

For an example refer to hasVideoElements (section 3.2.2.5).

Appendix A Phone applications

Two phone applications based on the anynode JavaScript WebRTC API are installed with anynode. They structure of both applications is the same, only difference is, one is an audio only phone and the other also supports video.

The directory structure and the file names of both applications is identical.

css
  style.css
js
  anynode_comm.js
  anynode_webrtc.js
  phone.js
  firebase-messaging-sw.js
index.html

style.css

Contains the style sheet to format the phone implemented in index.html

anynode_comm.js

Contains the communication part of the anynode WebRTC Client API. Currenlty a WebSocket connection is used.

anynode_webrtc.js

Contains the classes implementing the anynode WebRTC Client API.

phone.js

Contains the JavaScript part of the phone application.

firebase-messaging-sw.js

Contains the initialization for background notification. This file is only required if firebase messaging notification is used. The file must be in the root of the application.

index.html

Contains the HTML part of the phone application.