Class: Application

Application(SDK, params)

new Application(SDK, params)

Core application class for the SDK. Application is the parent object holding the list of conversations, the session object. Provides methods to create conversations and retrieve a list of the user's conversations, while it holds the listeners for user's invitations
Parameters:
Name Type Description
SDK ConversationClient session Object
params object
Source:
Fires:
Example

Accessing the list of conversations

  rtc.login(token).then((application) => {
      console.log(application.conversations);
      console.log(application.me.name, application.me.id);
  });

Methods

call(usernames) → {Call}

Creates a call to specified user/s.
Parameters:
Name Type Description
usernames Array.<string> the user names for those we want to call
Source:
Returns:
a Call object with all the call properties
Type
Call

callPhone(phoneNumber) → {Promise.<Call>}

Creates a call to phone a number. The call object is created under application.calls when the call has started. listen for it with application.on("call:status:changed") You don't need to start the stream, the SDK will play the audio for you
Parameters:
Name Type Description
phoneNumber string the number you want to call
Source:
Returns:
Type
Promise.<Call>
Example

Create a call to a phone

       application.on("call:status:changed", (call) => {
			if (call.status === call.CALL_STATUS.STARTED) {
				console.log('the call has started');
		}
application.callPhone(phone_number).then(() => {
                console.log('Calling phone ' + phone_number);
     });

getConversation(id) → {Promise.<Conversation>}

Query the service to see if this conversation exists with the logged in user as a member and retrieve the data object Result added (or updated) in this.conversations
Parameters:
Name Type Description
id string the id of the conversation to fetch
Source:
Returns:
- the requested conversation
Type
Promise.<Conversation>

getConversations() → {Promise.<Object.<Conversation>>}

Query the service to obtain a complete list of conversations of which the logged-in user is a member with a state of `JOINED` or `INVITED`.
Source:
Returns:
- Populate Application.conversations.
Type
Promise.<Object.<Conversation>>

getUser(idopt) → {Promise.<User>}

Get Details of a user
Parameters:
Name Type Attributes Description
id string <optional>
the id of the user to fetch, if skipped, it returns your own user details
Source:
Returns:
Type
Promise.<User>

newConversation(paramsopt) → {Promise.<Conversation>}

Query the service to create a new conversation The conversation name must be unique per application.
Parameters:
Name Type Attributes Description
params object <optional>
leave empty to get a GUID as name
Properties
Name Type Description
name string the name of the conversation. A UID will be assigned if this is skipped
display_name string the display_name of the conversation.
Source:
Returns:
- the created Conversation
Type
Promise.<Conversation>
Example

Create a conversation and join

application.newConversation().then((conversation) => {

        //join the created conversation
        conversation.join().then((member) => {
            //Get the user's member belonging in this conversation.
            //You can also access it via conversation.me

                console.log("Joined as " + member.user.name);
            });

    }).catch((error) => {
    console.log(error);
});

newConversationAndJoin(paramsopt) → {Promise.<Conversation>}

Query the service to create a new conversation and join it The conversation name must be unique per application.
Parameters:
Name Type Attributes Description
params object <optional>
leave empty to get a GUID as name
Properties
Name Type Description
name string the name of the conversation. A UID will be assigned if this is skipped
display_name string the display_name of the conversation.
Source:
Returns:
- the created Conversation
Type
Promise.<Conversation>
Example

Create a conversation and join

application.newConversationAndJoin().then((conversation) => {
        //join the created conversation
        conversation.join().then((member) => {
            //Get the user's member belonging in this conversation.
            //You can also access it via conversation.me
                console.log("Joined as " + member.user.name);
            });
    }).catch((error) => {
    console.log(error);
});

updateToken(token) → {Promise}

update user's token
Parameters:
Name Type Description
token string the new token
Source:
Returns:
Type
Promise

Events

call:status:changed

Call listening for call status changed events.
Properties:
Name Type Description
call Call the actual event
Source:
Example

listen for call status events

 application.on("call:status:changed",(call) => {
             console.log("call: " + call.status);
      });
  });

NXM-errors

Application listening for joins.
Properties:
Name Type Description
error ConversationClientError
Source:
Examples

listen for errors

application.on('*', 'NXM-errors', (error) => {
   console.log('Error thrown with type ' + error.type);
 });

Update the token on expired-token error

application.on('system:error:expired-token', 'NXM-errors', (error) => {
	console.log('token expired');
	application.updateToken(<token>);
});

member:call

Application listening for calls.
Properties:
Name Type Description
member Member the member that initiated the call
call Call resolves the call object
Source:
Example

listen for calls in Application level

 application.on("member:call", (member, call) => {
             console.log("Call ", call);
             });
     });

member:invited

Application listening for invites.
Properties:
Name Type Description
member Member The invited member
event Event The invitation event
Source:
Example

listen for your invites

application.on("member:invited",(member, event) => {
     console.log("Invited to the conversation: " + event.conversation.display_name || event.conversation.name);

//identify the sender.
console.log("Invited by: " + member.invited_by);

//accept an invitation.
 application.conversations.get(event.conversation.id).join();

//decline the invitation.
	 application.conversations.get(event.conversation.id).leave();

member:joined

Application listening for joins.
Properties:
Name Type Description
member Member the member that joined the conversation
event Event the join event
Source:
Example

listen join events in Application level

 application.on("member:joined",(member, event) => {
             console.log("JOINED", "Joined conversation: " + event.conversation.display_name || event.conversation.name);
             });
     });

rtcstats:report

Application listening for RTC stats.
Properties:
Name Type Description
MOS number the calculated MOS score
report Object the stats report from WebRTC | when the call has ended this is null, see the mos_report for final MOS summary
Conversation Conversation the conversation the report belongs to
mos_report Object a report for the MOS values
Properties
Name Type Description
min string the minimum MOS value during the stream
max string the maximum MOS value during the stream
last string the last MOS value during the stream
average string the average MOS value during the stream
Source:
Example

listening for quality mos score

 application.on("rtcstats:report",(mos, report, conversation, mos_report) => {
             console.log("call quality (MOS)", mos);
             if (mos_report) {
             console.log('mos_report', mos_report);
              }
          });

sync:progress

Application listening sync status.
Properties:
Name Type Description
status.sync_progress number Percentage of fetched conversations
Source:
Example

listening for changes in the synchronisation progress

 application.on("sync:progress",(status) => {
			console.log(data.sync_progress);
      });
 });