arvia.chat

1.0.0

ArviaChat

Constructor for Arvia Chat.

new ArviaChat(projectId: string): ArviaChat
Parameters
projectId (string) ID of your arvia.chat project. You can find this in your project overview on your arvia.chat account.
Returns
ArviaChat: Arvia Chat instance
Example
var arviaChat = new ArviaChat('5b4f145ac4dbc95dcf926a52');

setUserId

Set user id.

setUserId(userId: string)
Parameters
userId (string) Uniqe user id of the user. You can use this user id track this user.
Example
arviaChat.setUserId('12345');

getUserId

Get user id of this user.

getUserId(): string
Returns
string: userId The user id set by the setUserId method.
Example
arviaChat.getUserId();
// returns '12345'

setTestUser

Set test user.

setTestUser(testUser: boolean)
Parameters
testUser (boolean) Set this to true while development only.
Example
arviaChat.setTestUser(true);
// Test users will connect to a test room automatically

getTestUser

Get test status of this user.

getTestUser(): boolean
Returns
boolean: If true, this is a test user.
Example
arviaChat.getTestUser();
// returns true

setRoomName

Set room name.

setRoomName(roomName: string)
Parameters
roomName (string) The room name to connect and join
Example
// Top-level room
arviaChat.setRoomName('my-room');

// Dynamic room ([projectId]/[roomName])
arviaChat.setRoomName('5b4f145ac4dbc95dcf926a52/my-room');
// You can also set the dynamic room name using setDynamicRoomName method. setDynamicRoomName method only expects the room name as the parameter. Project id is added automatically as a prefix.

getRoomName

Get room name.

getRoomName(): string
Returns
string: The room name set by the setRoomName method.
Example
arviaChat.getRoomName();
// returns 'my-room' if the room is a top-level room

// if current room is a dynamic room, this method returns [projectId]/[roomName] (E.g: '5b4f145ac4dbc95dcf926a52/my-room')

setDynamicRoomName

Set dynamic room name.

setDynamicRoomName(roomName: string)
Parameters
roomName (string) The dynamic room name suffix to connect and join
Example
arviaChat.setDynamicRoomName('my-room');

// Actual room name will be [projectId]/[roomName] (E.g: '5b4f145ac4dbc95dcf926a52/my-room')

getDynamicRoomName

Get room name.

getDynamicRoomName(): string
Returns
string: The room name set by the setDynamicRoomName method.
Example
arviaChat.getDynamicRoomName();
// returns 'my-room'

// If current room is not a dynamic room, this method returns empty string.

getUserName

Get user name.

getUserName(): string
Returns
string: The user name set by the setUserName method
Example
arviaChat.getUserName();
// returns 'John Smith'

setUserEmail

Set user email.

setUserEmail(userEmail: string)
Parameters
userEmail (string) User email that you can assign to your user
Example
arviaChat.setUserEmail('name@example.com');

getUserEmail

Get user email.

getUserEmail(): string
Returns
string: The user email set by the setUserEmail method
Example
arviaChat.getUserEmail();
// returns 'ame@example.com'

setUserTel

Set user telephone number.

setUserTel(userTel: string)
Parameters
userTel (string) Telephone number that you can assign to your user
Example
arviaChat.setUserTel('+1 (123) 456 78 90');

getUserTel

Get user telephone number.

getUserTel(): string
Returns
string: The telephone number set by the setUserTel method
Example
arviaChat.getUserTel();
// returns '+1 (123) 456 78 90'

setUserDetails

Set user info.

setUserDetails(userDetails: string)
Parameters
userDetails (string) Any details you want to add to this user
Example
arviaChat.setUserDetails('Calling from San Jose. Interested in annual contracts. Requests more info about pricing.');

getUserDetails

Get user info.

getUserDetails(): string
Returns
string: User details set by the setUserDetails method
Example
arviaChat.getUserDetails();
// returns 'Calling from San Jose. Interested in annual contracts. Requests more info about pricing'

setUserTags

Set user tags.

setUserTags(userTags: Array<string>)
Parameters
userTags (Array<string>) The user tags to group or classify the user. Users can be assigned to specific agents by assigning the same tags to the users and the agents which you add to your projects or rooms on your Arvia Chat account center.
Example
arviaChat.setUserTags(['Speaks-English', 'From-USA', '25-year-old']);

getUserTags

Get user tags.

getUserTags(): Array<string>
Returns
Array<string>: The user tags set by the setUserTags method
Example
arviaChat.getUserTags();
// returns ['Speaks-English', 'From-USA', '25-year-old']

setAuthentication

Set authentication object.

setAuthentication(authentication: object)
Parameters
authentication (object) The authentication object which includes the required login credentials (or token, session id, etc.) to validate your users before allowing them to join your rooms. You need to set the authentication url for your project on your Arvia account center. The authentication url must be a script under your validated website platform.

Variables in this authentication object, will be posted to the authentication url which is set on your account center. On a valid request, your authentication script should return a json string including a 'success' parameter set to true. Any other respone will be considered as a failed authentication.

Please take a look at the Autherntication tab on your Arvia account center for more information and examples.

Example
arviaChat.setAuthentication({token: awqwr7632s76xfew68rhb68hwf8et});

getAuthentication

Get authentication object.

getAuthentication(): object
Returns
object: The authentication object set by the setAuthentication method
Example
arviaChat.getAuthentication();
// returns {token: awqwr7632s76xfew68rhb68hwf8et}

getUserCount

Get the number of users in the room.

getUserCount(): number
Returns
number: The number of users in the room.
Example
arviaChat.getUserCount();
// returns 2

setVideoUserNamesVisibility

Set visibility of the user names on videos.

setVideoUserNamesVisibility(visible: boolean)
Parameters
visible (boolean) If set to true, user names will be shown on videos. If set to false, user names on videos will be hidden.
Example
arviaChat.setVideoUserNamesVisibility(true);

getVideoUserNamesVisibility

Get visibility status of the user names on videos.

getVideoUserNamesVisibility(): boolean
Returns
boolean: The visibility status of the user names on videos set by the setVideoUserNamesVisibility method
Example
arviaChat.getVideoUserNamesVisibility();
// returns true

setLocalMediaButtonsVisibility

Set local media buttons visibility status.

setLocalMediaButtonsVisibility(visible: boolean)
Parameters
visible (boolean) If set to true, camera and microphone buttons will be visible. If set to false, camera and microphone buttons will be hidden.
Example
arviaChat.setLocalMediaButtonsVisibility(true);

getLocalMediaButtonsVisibility

Get local media buttons visibility status.

getLocalMediaButtonsVisibility(): boolean
Returns
boolean: The local media buttons visibility status set by the setLocalMediaButtonsVisibility method
Example
arviaChat.getLocalMediaButtonsVisibility();
// returns true

setRemoteMediaButtonsVisibility

Set visibility status of remote users' media options buttons.

setRemoteMediaButtonsVisibility(visible: boolean)
Parameters
visible (boolean) If set to true, options button, which toggles the incoming video, incoming audio and fullscreen buttos, will be visible. If set to false, these options button will be hidden.
Example
arviaChat.setRemoteMediaButtonsVisibility(true);

getRemoteMediaButtonsVisibility

Get visibility status of remote users' media options buttons.

getRemoteMediaButtonsVisibility(): boolean
Returns
boolean: The visibility status of remote users' media options buttons set by the setRemoteMediaButtonsVisibility method
Example
arviaChat.getRemoteMediaButtonsVisibility();
// returns true

setMessageBoxVisibility

Set visibility status of message box.

setMessageBoxVisibility(visible: boolean)
Parameters
visible (boolean) If set to true, message box will be visible. If set to false, message box will be hidden.
Example
arviaChat.setMessageBoxVisibility(true);

getMessageBoxVisibility

Get visibility status of message box.

getMessageBoxVisibility(): boolean
Returns
boolean: The visibility status of message box set by the setMessageBoxVisibility method.
Example
arviaChat.getMessageBoxVisibility();
// returns true

setMediaMessageButtonVisibility

Set visibility status of media message button.

setMediaMessageButtonVisibility(visible: boolean)
Parameters
visible (boolean) If set to true, media message button will be visible. If set to false, media message button will be hidden.
Example
arviaChat.setMediaMessageButtonVisibility(true);

getMediaMessageButtonVisibility

Get visibility status of media message button.

getMediaMessageButtonVisibility(): boolean
Returns
boolean: The visibility status of media message button set by the setMediaMessageButtonVisibility method.
Example
arviaChat.getMediaMessageButtonVisibility();
// returns true

setEndCallButtonVisibility

Set visibility status of end call button.

setEndCallButtonVisibility(visible: boolean)
Parameters
visible (boolean) If set to true, end call button will be visible. If set to false, end call button will be hidden.
Example
arviaChat.setEndCallButtonButtonVisibility(true);

getEndCallButtonVisibility

Get visibility status of end call button.

getEndCallButtonVisibility(): boolean
Returns
boolean: The visibility status of end call button set by the setEndCallButtonVisibility method.
Example
arviaChat.getEndCallButtonVisibility();
// returns true

setDefaultNotificationsEnabled

Enable or disable default notifications which are sent by the SDK.

setDefaultNotificationsEnabled(enabled: boolean)
Parameters
enabled (boolean) If set to true, default notifications are enabled. If false, default notifications are disabled.
Example
arviaChat.setDefaultNotificationsEnabled(true);

getDefaultNotificationsEnabled

Get if the default notifications are enabled or not.

getDefaultNotificationsEnabled(): boolean
Returns
boolean: If returns true, default notifications are enabled. If returns false, default notifications are disabled.
Example
arviaChat.getDefaultNotificationsEnabled();
// returns true

getDeviceInfo

Get device info. Audio/video input and output sources.

getDeviceInfo(): object
Returns
object: Device info object which includes audio and video sources.
Example
arviaChat.getDeviceInfo();
// ArviaChatEvent.DEVICE_INFO event is dispatched when device info is generated.
arviaChat.on(ArviaChatEvent.DEVICE_INFO, 
  function (e) {
    console.log(e);
  }
);

init

Create the chat interface in the target div element.

init(targetElement: (string | object))
Parameters
targetElement ((string | object)) Id (or DOM Object) of the target div element
Example
arviaChat.init('arviaChatDiv');

connect

Connect and join the room.

connect()
Example
arviaChat.connect();

switchAudioOutput

Switch the audio output to next available speaker/earphone.

switchAudioOutput()
Example
arviaChat.switchAudioOutput();

switchMicrophone

Switch the audio input to next available microphone.

switchMicrophone()
Example
arviaChat.switchMicrophone();

getMicrophone

Get the outgoing audio stream source device id .

getMicrophone(): (boolean | string)
Returns
(boolean | string): false or Microphone Id of the outgoing audio stream source. arviaChat.getMicrophone();

switchCamera

Switch the video input to next available camera.

switchCamera()
Example
arviaChat.switchCamera();

getCamera

Get the outgoing video stream source device id .

getCamera(): (boolean | string)
Returns
(boolean | string): false or Camera Id of the outgoing video stream source.
Example
arviaChat.getCamera();

toggleScreenSharing

Toggles sharing screen start/stop.

toggleScreenSharing()
Example
arviaChat.toggleScreenSharing();

close

Disconnect and terminate the chat interface.

close(closeRoom: any)
Parameters
closeRoom (any)
Example
arviaChat.close();

setUserName

Set user name.

setUserName(userName: string)
Parameters
userName (string) Name that you can assign to your user
Example
arviaChat.setUserName('John Smith');

setMicrophone

Set the outgoing audio stream source device.

setMicrophone(microphone: (boolean | string))
Parameters
microphone ((boolean | string)) True/False or Microphone Id to enable or disable video stream. Available Microphone Ids can be obtained by the getDeviceInfo method.
Example
arviaChat.setMicrophone(true);

setCamera

Set the outgoing video stream source device.

setCamera(camera: (boolean | string))
Parameters
camera ((boolean | string)) True/False or Camera Id to enable or disable video stream. Available Camera Ids can be obtained by the getDeviceInfo method.
Example
arviaChat.setCamera(true);

shareScreen

Start or stop sharing screen.

shareScreen(share: boolean)
Parameters
share (boolean) If set to true, screen sharing starts. If set to false, sceeen sharing stops.
Example
arviaChat.shareScreen(true);

stopAudioVideo

Stops broadcasting audio and video.

stopAudioVideo()
Example
arviaChat.stopAudioVideo();

disconnect

Disconnect and exit the room.

disconnect()
Example
arviaChat.disconnect();

turnOnMicrophone

Turn on microphone and broadcast your audio.

turnOnMicrophone()
Example
arviaChat.turnOnMicrophone();

turnOffMicrophone

Turn off microphone and mute your audio.

turnOffMicrophone()
Example
arviaChat.turnOffMicrophone();

turnOnCamera

Turn on camera and broadcast your video.

turnOnCamera()
Example
arviaChat.turnOnCamera();

turnOffCamera

Turn off camera and put outgoing video on hold.

turnOffCamera()
Example
arviaChat.turnOffCamera();

resize

Call this method to update chat if the size of the target div element is changed.

resize()
Example
arviaChat.resize();

showNotification

Show a notification using the Arvia Chat's built in notifications.

showNotification(text: string, type: string)
Parameters
text (string) Text to display
type (string) Type of the notification ('base', 'success', 'error', 'info', 'warn')
Example
arviaChat.showNotification('Please wait while connecting...');

ArviaChatEvent.ROOM_FULL

Dispatched when the room you are trying to join is full.

ArviaChatEvent.ROOM_FULL
Example
arviaChat.on(ArviaChatEvent.ROOM_FULL, 
 function (e) {
   arviaChat.showNotification('This room is full');
   console.log(e);
 }
);

ArviaChatEvent.CONNECTING

Dispatched when trying to connect.

ArviaChatEvent.CONNECTING
Example
arviaChat.on(ArviaChatEvent.CONNECTING, 
 function (e) {
   arviaChat.showNotification('Please wait while connecting...');
 }
);

ArviaChatEvent.CONNECT_ERROR

Dispatched when connect failed.

ArviaChatEvent.CONNECT_ERROR
Example
arviaChat.on(ArviaChatEvent.CONNECT_ERROR, 
 function (e) {
   arviaChat.showNotification('Connect error!');
   console.log(e);
 }
);

ArviaChatEvent.DISCONNECT

Dispatched when disconnected.

ArviaChatEvent.DISCONNECT
Example
arviaChat.on(ArviaChatEvent.DISCONNECT, 
 function (e) {
   arviaChat.showNotification('Disconnected from server!');
 }
);

ArviaChatEvent.JOIN_REQUEST

Dispatched when the room is locked, someone wants to join the room and you are the room agent.

ArviaChatEvent.JOIN_REQUEST
Example
arviaChat.on(ArviaChatEvent.JOIN_REQUEST, 
 function (e) {
   arviaChat.showNotification('Someone wants to join the room');
   console.log(e);
 }
);

ArviaChatEvent.JOIN_ROOM_ERROR

Dispatched when you can not enter the room.

ArviaChatEvent.JOIN_ROOM_ERROR
Example
arviaChat.on(ArviaChatEvent.JOIN_ROOM_ERROR, 
 function (e) {
   arviaChat.showNotification('Can not join the room');
   console.log(e);
 }
);

ArviaChatEvent.USER_JOIN

Dispatched when a user joins room.

ArviaChatEvent.USER_JOIN
Example
arviaChat.on(ArviaChatEvent.USER_JOIN, 
 function (e) {
   arviaChat.showNotification('Someone joined the room');
   console.log(e);
 }
);

ArviaChatEvent.USER_LIST

Dispatched when the user joins or leaves the room.

ArviaChatEvent.USER_LIST
Example
arviaChat.on(ArviaChatEvent.USER_LIST, 
 function (e) {
   arviaChat.showNotification('User list updated');
   console.log(e);
 }
);

ArviaChatEvent.WAITING_FOR_PERMISSION

Dispatched when the room you are trying to join is locked and waiting for the agent to let you in.

ArviaChatEvent.WAITING_FOR_PERMISSION
Example
arviaChat.on(ArviaChatEvent.WAITING_FOR_PERMISSION, 
 function (e) {
   arviaChat.showNotification('Waiting for permission from the room agent');
   console.log(e);
 }
);

ArviaChatEvent.CONNECT

Dispatched when connected.

ArviaChatEvent.CONNECT
Example
arviaChat.on(ArviaChatEvent.CONNECT, 
 function (e) {
   arviaChat.showNotification('Connected to room');
 }
);

ArviaChatEvent.DEVICE_INFO

Dispatched after the getDeviceInfo is called and when the device info is generated.

ArviaChatEvent.DEVICE_INFO
Example
arviaChat.getDeviceInfo();
// ArviaChatEvent.DEVICE_INFO event is dispatched when device info is generated.
arviaChat.on(ArviaChatEvent.DEVICE_INFO, 
  function (e) {
    console.log(e);
  }
);

ArviaChatEvent.DEVICE_INFO_ERROR

Dispatched after the getDeviceInfo is called and when the device info can not be generated.

ArviaChatEvent.DEVICE_INFO_ERROR
Example
arviaChat.getDeviceInfo();
// ArviaChatEvent.DEVICE_INFO_ERROR event is dispatched when device info can not be generated.
arviaChat.on(ArviaChatEvent.DEVICE_INFO_ERROR, 
  function (e) {
    console.log('Can not get device info!');
  }
);

ArviaChatEvent.LOCAL_STREAM

Dispatched when the camera access granted.

ArviaChatEvent.LOCAL_STREAM
Example
arviaChat.on(ArviaChatEvent.LOCAL_STREAM, 
 function (e) {
   arviaChat.showNotification('Got video stream from the camera.');
   console.log(e);
 }
);

ArviaChatEvent.LOCAL_STREAM_ERROR

Dispatched if the camera can not be accessed.

ArviaChatEvent.LOCAL_STREAM_ERROR
Example
arviaChat.on(ArviaChatEvent.LOCAL_STREAM_ERROR, 
 function (e) {
   arviaChat.showNotification('Can not access camera.');
   console.log(e);
 }
);

ArviaChatEvent.SCREEN_SHARE

Dispatched when the screen access granted.

ArviaChatEvent.SCREEN_SHARE
Example
arviaChat.on(ArviaChatEvent.SCREEN_SHARE, 
 function (e) {
   arviaChat.showNotification('Got screen display to share.');
   console.log(e);
 }
);

ArviaChatEvent.SCREEN_SHARE_ERROR

Dispatched if the screen can not be shared.

ArviaChatEvent.SCREEN_SHARE_ERROR
Example
arviaChat.on(ArviaChatEvent.SCREEN_SHARE_ERROR, 
 function (e) {
   arviaChat.showNotification('Can not get screen display.');
   console.log(e);
 }
);

ArviaChatEvent.MESSAGE

Dispatched when a message is received.

ArviaChatEvent.MESSAGE
Example
arviaChat.on(ArviaChatEvent.MESSAGE, 
 function (e) {
   arviaChat.showNotification('Message received.');
   console.log(e.detail.userName);
   console.log(e.detail.userId);
   console.log(e.detail.message);
   console.log(e.detail.date);
 }
);

ArviaChatEvent.AUTHENTICATION_ERROR

Dispatched if the authentication fails.

ArviaChatEvent.AUTHENTICATION_ERROR
Example
arviaChat.on(ArviaChatEvent.AUTHENTICATION_ERROR, 
 function (e) {
   arviaChat.showNotification('Authentication failed.');
   console.log(e);
 }
);