Interact SDK

This page is for developers to implement Interact in other products. Please refer to the following related pages for further guidance:

 

SDK Documentation

Nimbus Interact SDK Documentation - v0.0.21183

Nimbus Interact SDK Documentation - v0.0.21183

Interact SDK

Installation

  • To use Web Interaction SDK on your site:

Add link to Web Interaction SDK .js file to the page

<script src="{path to scripts folder}/luware.Interact.sdkInstance.js">
  • The following steps should be done to use Interact SDK in compressioned state with IIS on your Web site:
    • Add link to Interact SDK .js.gz file to the page
<script src="{path to scripts folder}/luware.Interact.sdkInstance.js.gz">
  • Assign custom header 'Content-encoding: gzip' to response for Interact.sdkInstance.js.gz
  • Add to global config system.webServer > staticContent
<mimeMap fileExtension=".js.gz" mimeType="application/javascript" />
  • IIS Compression can be disabled
<urlCompression doStaticCompression="false" doDynamicCompression="false" dynamicCompressionBeforeCache="false" />

 Usage for several contacts

  1. Provide a valid token if the token authorization is enabled on the tenant
interactSDK.useAuthorization(token);
  1. Initialize the presence before starting the conversation

 let initPresence = {
 widgetKey: "A3A38323F038F9O1DB0B25BF3158F5490",
 apiUrl: "https://ui.interact.stage.nimbdev/v1",
 type: "signalR",
 };
 interactSDK.presence.init(initPresence).then(() => {
 // sdk was inited to work with presences
 });
  1. Check availability
    • Contact
    • Service
  2. Start conversation with modalities (more info can be found in Samples of usage section)

Usage per tenant

  1. Init sdk
let initSettings = {
 widgetKey: "A3A38926G067411DB0B25BF3158F5490",
 apiUrl: "https://ui.interact.stage.nimbdev/v1",
};
const sdkInstance_tenantA = new interactSDK(initSettings);
  1. Provide authorization token. Token could be updated later

sdkInstance_tenantA.setAuthorization(token);
  1. Init presence and subscribe on it

await sdkInstance_tenantA.initPresence("signalR");
  1. Check contact availability
const contactId="21d8b07c-b6bf-480d-bae8-9b17915084e1";
const contactDetails = await sdkInstance_tenantA.getContactStatus(contactId)
  1. Start conversation with modalities (more info can be found in Samples of usage section)

Samples of usage

Presence for several contacts

Subscribe to presences

async function subscribeToPresence() { 
   await interactSDK.presence.on([
       { publicUserId: '21d8b07c-b6bf-480d-bae8-9b17915084e1', 
           callbacks: { onChanged: onPresenceChanged }},
       { publicUserId: 'ec7ceef7-d114-4f46-af0b-9eb9cf5161c5', 
           callbacks: { onChanged: onPresenceChanged }}
   ]);
}
function onPresenceChanged(presence) { }

Unsubscribe to presences


async function unsubscribeToPresence() {
   await interactSDK.presence.off([
       {publicUserId: '21d8b07c-b6bf-480d-bae8-9b17915084e1'},
       {publicUserId: 'ec7ceef7-d114-4f46-af0b-9eb9cf5161c5'},
   ]);
}

Get presence status without Subscription

let initSettings = {
   widgetKey: "A3A38926G067411DB0B25BF3158F5490",            
   apiUrl: "https://ui.interact.stage.nimbdev/v1",
   contactId:"21d8b07c-b6bf-480d-bae8-9b17915084e1"
};
await interactSDK.getContactPresence(initSettings);
 
 

Presence for several contacts from one tenant

Subscribe to presences


async function subscribeToPresence() { 
   await sdkInstance_tenantA.presence.on([
       { publicUserId: '21d8b07c-b6bf-480d-bae8-9b17915084e1', 
           callbacks: { onChanged: onPresenceChanged }},
       { publicUserId: 'ec7ceef7-d114-4f46-af0b-9eb9cf5161c5', 
           callbacks: { onChanged: onPresenceChanged }},
       { publicServiceId: '6fbcf3a8-f390-43b5-9566-9c95ef7e0d31', 
           callbacks: { onChanged: onPresenceChanged }}
       { publicServiceId: '211b64a9-8b27-4ba2-9598-e9f3cad388ad', 
           callbacks: { onChanged: onPresenceChanged }}
   ]);
}
function onPresenceChanged(presence) { }

Unsubscribe to presences


async function unsubscribeToPresence() {
   await sdkInstance_tenantA.presence.off([
       {publicUserId: '21d8b07c-b6bf-480d-bae8-9b17915084e1'},
       {publicUserId: 'ec7ceef7-d114-4f46-af0b-9eb9cf5161c5'},
       {publicServiceId: '6fbcf3a8-f390-43b5-9566-9c95ef7e0d31'},
       {publicServiceId: '211b64a9-8b27-4ba2-9598-e9f3cad388ad'},
   ]);
}

Get presence status without Subscription


await sdkInstance_tenantA.getContactPresence('21d8b07c-b6bf-480d-bae8-9b17915084e1');
 
 

Audio & Video calls

Init sdk instance to work with conversation.
Use this instance in all other steps


let initSettings = {
   widgetKey: "A3A38926G067411DB0B25BF3158F5490",            
   apiUrl: "https://ui.interact.stage.nimbdev/v1" 
};
let sdkInstance_tenantA = new interactSDK(initSettings);
               

Provide authorization token
Token could be updated later


sdkInstance_tenantA.setAuthorization(token);
               

Start conversation and subscribe to conversation events


let userDetails = {
   userName: userName,
   email: email,
   disclaimer: true
}
const contactId = "21d8b07c-b6bf-480d-bae8-9b17915084e1";
const sessionId = await sdkInstance_tenantA.startConversation(userDetails, contactId);
         
sdkInstance_tenantA.conversation.chat.on({ onMessageReceived, onTypingParticipantAdded, onTypingParticipantRemoved });
sdkInstance_tenantA.conversation.callChanged.on({ 
   onStart: () => startCallback(first), 
   onStop: stopCallback, 
   onRemoteVideo: onRemoteParticipantVideChanged, 
   inLobby: onClientJoinLobby });
sdkInstance_tenantA.conversation.participantsChanged.on({ onAdded, onRemoved });
sdkInstance_tenantA.conversation.errors.on(onError);
sdkInstance_tenantA.conversation.screenSharing.on({ onScreenSharing, onRemoteScreenSharing });
               

Start call as Audio (muted self video)

Call could be extended to video with calling unmute video


let options = {
   devices: {
       audioId: audio != 0 ? audio : 'default'
   },
   selfVideoId: "self-video-id",
   videoId: ""remote-video-id",
   screenSharingId: "screensharing-id"
}
await sdkInstance_tenantA.startCall(options);

Start call as video


let options = {
   devices: {
       videoId: video != 0 ? video : 'default',
       audioId: audio != 0 ? audio : 'default',
   },
   selfVideoId: "self-video-id",
   videoId: "remote-video-id",
   screenSharingId: "screensharing-id"
}
await sdkInstance_tenantA.startCall(options);

Stop call and unsubscribe from all conversation events


await sdkInstance_tenantA.stopCall();
sdkInstance_tenantA.conversation.chat.off();
sdkInstance_tenantA.conversation.callChanged.off();
sdkInstance_tenantA.conversation.participantsChanged.off();
sdkInstance_tenantA.conversation.errors.off();
sdkInstance_tenantA.conversation.screenSharing.off();
               

Mute/unmute audio

await sdkInstance_tenantA.toggleMute(muted);

Mute/unmute video

await sdkInstance_tenantA.toggleVideo();

Change camera to the next available

await sdkInstance_tenantA.changeCamera();

Update media devices which are used for a call


let options = {
   devices: {
           videoId: video != 0 ? video : 'default',
           audioId: audio != 0 ? audio : 'default',
       },
   }
await sdkInstance_tenantA.updateDevices(options);
 
 

Chat in Audio/Video call

Subscribe to chat events

sdkInstance_tenantA.conversation.chat.on({ onTypingParticipantAdded, onTypingParticipantRemoved });

Start call, then send message

//returns id of sent Message
let id = await sdkInstance_tenantA.sendMessage({ text: message });
 
 

Chat only conversation

Init sdk instance to work with conversation.
Use this instance in all other steps

let initSettings = {
   widgetKey: "A3A38926G067411DB0B25BF3158F5490",
   apiUrl: "https://ui.interact.stage.nimbdev/v1" 
};
let sdkInstance_tenantA = new interactSDK(initSettings);

Provide authorization token
Token could be updated later

sdkInstance_tenantA.setAuthorization(token);

Start conversation and subscribe to conversation events


let userDetails = {
   userName: userName,
   email: email,
   disclaimer: true
}
const contactId = "21d8b07c-b6bf-480d-bae8-9b17915084e1";
const sessionId = await sdkInstance_tenantA.startChatConversation(userDetails, contactId);
sdkInstance_tenantA.conversation.chat.on({ onMessageReceived, onStopChat });          

//returns id of sent Message
let id = await sdkInstance_tenantA.sendMessage({ text: message });

Stop chat and unsubscribe from all conversation events

await sdkInstance_tenantA.stopChat();
 
 

Participants

Subscribe to conversation participants changes

sdkInstance_tenantA.conversation.participantsChanged.on({ onAdded, onRemoved });
 
 

Screen sharing

Subscribe to screen sharing events

interactSDK.conversation.screenSharing.on({ onSelfScreenSharing, onRemoteScreenSharing });

With starting call options provide the id of the element where incoming screen sharing stream will be placed. Screen sharing stream will be automatically added/removed to the div.

toggleScreenSharing to start/stop self screen or application sharing

let isActiveSharing = true;
await sdkInstance_tenantA.toggleScreenSharing(!activeScreenSharing);
 
 

Restore conversation

Restore conversation on the page reloading

Conversation could be restored in time configured in the Tenant settings (20 sec by default)

On reload:

Provide a valid token if it is necessary

interactSDK.useAuthorization(token);

Initialize the presence before starting the conversation

interactSDK.presence.init(initPresence).then(() => { 
       // sdk was inited to work with presences
});
       

Get contact status

const contactStatus = await interactSDK.getContactStatus(initSettings);
if(status.isMeetingAlive){    
   startCall();
}        
 
 

Table of Contents