The part of the SDK is designed to help you build your own modular plugins, allowing you to extend the functionality of Wazo applications. This documentation will focus on the APIs provided by the SDK for plugins.
After installing the SDK, you must require the app/plugin it with the following lines.
import { App } from '@wazo/euc-plugins-sdk';
const app = new App();
Plugins can be loaded and unloaded depending on some actions inside our product (ex: login/logout, tenant change, etc). Here’s the lifecycle of a plugin with related listeners. That will help you build a robust system based on user actions.
It’s required to call app.initialize() function to registerer and acknowledge your plugin inside our E-UC Application. Please note this method is asynchronous.
await app.initialize();
When the application is initialized, you can retrieve the context surrounding your plugin. A context will give you access to the app information that your plugin will base its logic on it.
import { Context } from '@wazo/euc-plugins-sdk/types';
const context: Context = app.getContext();
Information that the context will give you access to:
{
// Information about the EU-C application
app: {
// The locale code of the application on 2 characters, like `en` or `it`.
locale: 'string',
// Colors used by the EU-C apps. It uses the Material UI theme palette structure, so you can use it directly with `createTheme()` or just pick the color you want in your plugin.
theme: {},
// Contains a `clientType` value that can be `web` / `desktop` / `ios` or `android`
host: 'web|desktop|ios|android',
// Contains extra information about the app context, like the `contact` when you use the `contactTab` manifest context. Among extra parameters, you'll always receive `baseUrl` and `pluginId`
extra: {
// The base url of your `manifest.json` file
baseUrl: 'string',
// The `entityId` of the current plugin.
pluginId: 'string,
// ... and more
}
}
// Information about the connected user
user: {
// UUID of the connect user
uuid: 'string',
// The token that can be used for API calls
token: 'string',
// A refresh token that should be used if the `token` expires
refreshToken: 'string',
// Expiration Date time of the token
expiresAt: 'string',
// Authentication session UUID
sessionUuid: 'string',
// UUID of the user's tenant
tenantUuid: 'string',
// For Web and desktop applications, it's representing the stack hostname where the user is connected
host: 'string',
// ... and more
}
}
:::info
user values depends on the application your building for. See WDASession and the PortalSession types for more information.
:::
It’s at this moment the magic happens, add your own logic inside our products. Depending on which product you’re developing, there are many listeners or action creators that you can use with the SDK.
When a plugin is unloaded because of a user action (ex: logout), this listener app.onPluginUnLoaded() will be called. Other listeners will be disabled when unloaded. To prevent side effects, it’s important to remove any watcher added in the initializing phase.
When the user logs in again, the backgroundScript will be reloaded, please make sure to release everything in onPluginUnLoaded.
:::info If you’re using a background script, it’s important to close any WebSocket or listeners at this cycle of the plugin. :::
onNewSessionEvent when the user session is refreshed. The token of the authenticated user has an expiration date; when the token expires, a session is created with a new token.
app.onNewSession = (session: WDASession | PortalSession) => {}
onLogoutEvent when the user logs out from the application
app.onLogout = () => {};
When a custom tab or iframe is closed or unloaded, it’s important to handle any necessary cleanup or actions. To accommodate this, we have two unloaded events:
onUnLoaded: use this event when your plugin app codeonAppUnLoaded: use this event for your backgroundScript fileonUnLoaded (page)It’s a sugar of window.onunload, useful when you want to store information before page/tab exit. Important: You can’t do an action here like API call because the app (iframe) can be closed before the action will be finished.
app.onUnLoaded = () => {};
onAppUnLoaded (Background Script)Should be used in a backgroundScript to know when a custom tab is unloaded. As app.onUnLoaded is only triggered for tabs (iframes), and this event doesn’t allow sophisticated actions (like sending messages to a background script, API calls, …) we should use onAppUnLoaded to perform an action when a tab is unloaded.
app.onAppUnLoaded = (tabId) => {};
openLeftPanelOpen the left panel of Wazo Web & Desktop
app.openLeftPanel();
closeLeftPanelClose the left panel of Wazo Web & Desktop
app.closeLeftPanel();
Example to keep left pannel closed the app shows a page of your plugin:
await app.initialize();
// Closing the web/desktop left panel when the page is loaded
app.closeLeftPanel();
app.onUnLoaded = () => {
// Re-opening the panel when the page is unloaded
app.openLeftPanel();
};
startCallStarting a call audio or video call
app.startCall({ targets , requestedModalities = ['audio'] });
Example:
app.startCall({ targets: ['8008'], requestedModalities: ['video'] });
openLinkOpening a link in the application, it will move the right page of Wazo app.
app.openLink(url: string);
Example:
// Opening the internal phonebook
app.openLink('/phonebook/internal');
createMeetingCreates an external meeting, that will allow guest to join with by an URL
app.createMeeting(name: string, requireAuthorization = false, persistent = false);
Example of creating a meeting and listening to the event :
app.createMeeting('My meeting from my custom app', true, true);
// Wait for the meeting to be available
app.onMeetingCreated = newMeeting => {};
openMeetingLobbyOpen an meeting lobby
app.openMeetingLobby(extension: string);
Example:
// Open the lobby when a meeting is created
app.onMeetingCreated = newMeeting => {
app.openMeetingLobby(newMeeting.exten);
};
ignoreCallIgnoring an incoming call.
app.onCallIncoming = call => {
app.ignoreCall(call);
};
playNewMessageSoundPlay the sound when we receive a text message.
app.playNewMessageSound();
playIncomingCallSoundPlay the incoming call sound (🔁 loop)
app.playIncomingCallSound();
playProgressSoundPlay the ringback sound when we make a call (🔁 loop)
app.playProgressSound();
playDoubleCallSoundPlay the sound when another call is incoming
app.playDoubleCallSound();
playHangupSoundPlay the hangup sound
app.playHangupSound();
stopCurrentSoundStop the current sound. Sounds marked “🔁 loop” can be stopped only using this method.
app.stopCurrentSound();
configureSoundsConfiguring sounds to use your own sound files in the application, with:
app.configureSounds({
progress: 'http://example/com/progress.mpg', // Played when making an outgoing call (ringback)
ring: 'http://example/com/ring.wav', // Played for the first incoming call
message: 'http://example/com/message.ogg', // Played when the user receives a chat message
hangup: 'http://example/com/hangup.ogg',// Played when the call is hung up
inboundCall: 'http://example/com/inbound.vaw', // Played when we are in call and another call is incoming. Also played in Switchboard.
})
:::info You can omit a value, the default sound will be used. :::
resetSoundsThis method will reset all application sounds to origianl ones.
app.resetSounds();
displayNotificationShow an app notification, will display browser or desktop notification depending on the environment where the app is running.
app.displayNotification(title: string, text: string);
changeNavBarColorChange the navigation bar color with a valid CSS color.
app.changeNavBarColor(color: string);
Example:
app.changeNavBarColor('#8e6a3a');
app.changeNavBarColor('white');
resetNavBarColorReset to the default navigation bar color to defaut color
app.resetNavBarColor();
displayModalWill display a modal in the application, the method must called from the backgroundScript file.
app.displayModal({ url, title, text, htmlText, height, width, hideCloseButton });
url is present, the modal will display an iframe with the content of the url.htmlText is present, the modal will display this text in a html contact, otherwise the text attribute will be used.height and width accept valid CSS values, like 500px or 80%.hideCloseButton (default to false) determines if the close button should be displayed, or if the user should handle closing of the modal in the html content (through app.removeModal() method).Example:
Displaying client data when receiving a call
app.onCallIncoming = async call => {
console.log('background onCallIncoming', call);
const clientData = await fetchClientData(call.number); // Where `fetchClientData` is a method that return client information from an extension
app.displayModal({
title: `Incoming call for ${call.displayName}`,
text: `Last call was: ${clientData.lastCall} for : ${clientData.lastCallSubject}`,
height: '50%',
width: '70%',
});
};
removeModalWill remove the shown modal in the application, the method must be called from the backgroundScript file or within the modal HTML.
app.removeModal();
displayBannerWe can display a mobile banner from the backgroundScript file.
app.displayBanner({ url, height, width, hideCloseButton });
url is present, the modal will display an iframe with the content of the url.height accepts valid CSS values, like 500px or 80%.width accepts valid CSS values, like 500px or 80%, used on Web/Desktop App (min: 300px).hideCloseButton (default to false) determines if the close button should be displayed, or if the user should handle closing of the modal in the html content (through app.removeModal() method).:::note On Web/Desktop App, the banner will be integrated with other banners like incoming calls. Other banners will be displayed below. :::
closeBannerWe can hide a mobile banner from the backgroundScript or within the banner HTML page.
app.closeBanner();
hasLocalVideoStreamCheck if a call has a local video stream.
app.hasLocalVideoStream(call: Call);
Example:
app.onCallAnswered = (call) => {
const hasLocalVideo = app.hasLocalVideoStream(call);
}
getLocalCurrentVideoStreamRetrieving the local video stream of a call.
app.getLocalCurrentVideoStream(call: Call);
Example:
app.onCallAnswered = (call) => {
const stream = app.getLocalCurrentVideoStream(call);
}
hasRemoteVideoStreamChecking if a call has a remote video stream.
app.hasRemoteVideoStream(call: Call);
Example:
app.onCallAnswered = (call) => {
const hasRemoteVideo = app.hasRemoteVideoStream(call);
}
getRemoteCurrentVideoStreamRetrieving the remote video stream of a call.
app.getRemoteCurrentVideoStream(call: Call);
Example:
app.onCallAnswered = (call) => {
const stream = app.getRemoteCurrentVideoStream(call);
}
sendMessageToBackgroundSending a message from the iframe to background script. Receive message from event onBackgroundMessage
// my-plugins.js (Sending message to background)
app.sendMessageToBackground({ value: 'ping' });
// background.js (Receiving a message from the iframe)
app.onBackgroundMessage = msg => {
console.log('onBackgroundMessage', msg);
sendMessageToIframeIn the background script
// background.js (Sending a message to the plugin's iframe)
app.sendMessageToIframe({ value: 'pong' });
// my-plugin.js (Receiving a message from the background script)
app.onIframeMessage = (msg) => {
console.log('onIframeMessage', msg);
}
updateBadgeDisplay a notification next to the navigation bar icon button. It uses MUI’s Badge component to display a notification, generally an integer.
When used in backgroundScript file, it requires entityId as set in a tab in the staticTabs section of manifest.json, and that tab must include “sidebarTab” in its context (entityId should automatically be set when called from the iframe).
app.updateBadge({ badgeContent: number, entityId: string, color?: string = 'error', variant?: string, max?: number, overlap?: string, anchorOrigin?: Object, showZero?: boolean, entityId?: string });
onCallIncomingListener when a call for the current user is incoming. Useful to react on a call event from backgroundScript file.
app.onCallIncoming = (call: Call) => {};
onCallMadeListener when a call is made by the user (eg: outgoing call). Useful to react on a call event from backgroundScript file.
app.onCallMade = (call: Call) => {};
onCallAnsweredListener when an incoming call is answered by the current user. Useful to react on a call event from backgroundScript file.
app.onCallAnswered = (call: Call) => {};
onCallAcceptedListener when a call is answered (by one or the other side). Useful to react on a call event from backgroundScript file.
app.onCallAccepted = (call: Call) => {};
onCallHungUpListener when a call is hung up. Useful to react on a call event from backgroundScript file.
app.onCallHungUp = (call: Call) => {};
onWebsocketMessageListener to Wazo Websocket message(s). Useful to react on a call event from backgroundScript file.
app.onWebsocketMessage = (message: MessageEvent) => {};
onMeetingCreatedListener of meeting creation.
app.onMeetingCreated = (meeting: Meeting) => { };
onRouteChangedListener of navigation changes in the app.
app.onRouteChanged = (location: Object, action: string) => { };
onUserJoinRoomListener when a user enters a room.
app.onUserJoinRoom = (room) => {};
onUserLeaveRoomListener when a user leavers a room.
app.onUserLeaveRoom = (room) => {};
onParticipantJoinRoomListener when a participant enters a room.
app.onParticipantJoinRoom = (room, participant) => {};
onParticipantLeaveRoomListener when a participant leaves a room.
app.onParticipantLeaveRoom = (room, participant) => {};
setMobileHeaderWill change the header inside the app.
app.setMobileHeader({ title?: string | null, callback?: Function | null });
title: Changes the label displayed in the header. Set this value to null to set it back to the default value.callback: Handles the back button click. If a callback is registered, the app will forgo its normal behavior and run it. Setting the value to null reinstates the original behavior.setMobileShowBottomNavDefine whether you want to show or hide the bottom navigation.
app.setMobileShowBottomNav(show: boolean);
startCallStart a new audio or video call
app.startCall({ targets , requestedModalities = ['audio'] });
Example:
app.startCall({ targets: ['8008'], requestedModalities: ['video'] });
playProgressSoundPlay the ringback sound when we make a call (🔁 loop)
app.playProgressSound();
playNewMessageSoundPlay the sound when we receive a text message.
app.playNewMessageSound();
playHangupSoundPlay the hangup sound
app.playHangupSound();
stopCurrentSoundStop the current sound. Sounds marked “🔁 loop” can be stopped only using this method.
app.stopCurrentSound();
displayModalWill display a modal in the application, the method must called from the backgroundScript file.
app.displayModal({ url, title, text, htmlText, height, width, hideCloseButton });
url is present, the modal will display an iframe with the content of the url.htmlText is present, the modal will display this text in a html contact, otherwise the text attribute will be used.height and width accept valid CSS values, like 500px or 80%.hideCloseButton (default to false) determines if the close button should be displayed, or if the user should handle closing of the modal in the html content (through app.removeModal() method).:::note
On mobile, links with a target="_blank" attribute will be opened in the user’s default browser.
:::
Example:
Displaying client data when receiving a call
app.onCallIncoming = async call => {
console.log('background onCallIncoming', call);
const clientData = await fetchClientData(call.number); // Where `fetchClientData` is a method that return client information from an extension
app.displayModal({
title: `Incoming call for ${call.displayName}`,
text: `Last call was: ${clientData.lastCall} for : ${clientData.lastCallSubject}`,
height: '50%',
width: '70%',
});
};
removeModalWill remove the shown modal in the application, the method must called from the backgroundScript file or within the modal HTML.
app.removeModal();
displayBannerWe can display a mobile banner from the backgroundScript file.
app.displayBanner({ url, height, width, hideCloseButton });
url is present, the modal will display an iframe with the content of the url.height accepts valid CSS values, like 500px or 80%.width accepts valid CSS values, like 500px or 80%, used on Web/Desktop App (min: 300px).hideCloseButton (default to false) determines if the close button should be displayed, or if the user should handle closing of the modal in the html content (through app.removeModal() method).:::note
On mobile, links with a target="_blank" attribute will be opened in the user’s default browser.
:::
closeBannerWe can hide a mobile banner fro the backgroundScript or withing the banner HTML page.
app.closeBanner();
updateBadgeDisplay a notification next to the navigation bar icon button. It uses MUI’s Badge component to display a notification, generally an integer.
When used in backgroundScript file, it requires entityId to be set in a tab in the staticTabs section of manifest.json, and that tab must include “sidebarTab” in its context (entityId should automatically be set when called from the iframe).
app.updateBadge({ badgeContent: number, entityId: string });
:::info
On Wazo Mobile, only the field badgeContent: number is used to display the badge.
:::
sendMessageToBackgroundSending a message from the iframe to background script. Receive message from event onBackgroundMessage
// my-plugins.js (Sending message to background)
app.sendMessageToBackground({ value: 'ping' });
// background.js (Receiving a message from the iframe)
app.onBackgroundMessage = msg => {
console.log('onBackgroundMessage', msg);
sendMessageToIframeIn the background script
// background.js (Sending a message to the plugin's iframe)
app.sendMessageToIframe({ value: 'pong' });
// my-plugin.js (Receiving a message from the background script)
app.onIframeMessage = (msg) => {
console.log('onIframeMessage', msg);
}
onCallIncomingListener to detect incoming calls for the current user. Useful to react on a call event from backgroundScript file.
app.onCallIncoming = (call: Call) => {};
onCallMadeListener to detect user’s outgoing calls (eg: made by the user). Useful to react on a call event from backgroundScript file.
app.onCallMade = (call: Call) => {};
onCallAnsweredListener to detect when an incoming call is answered by the current user. Useful to react on a call event from backgroundScript file.
app.onCallAnswered = (call: Call) => {};
onCallAcceptedListener to detect answered calls (by the current user or the other side). Useful to react on a call event from backgroundScript file.
app.onCallAccepted = (call: Call) => {};
onCallHungUpListener to detect hung up calls. Useful to react on a call event from backgroundScript file.
app.onCallHungUp = (call: Call) => {};
onWebsocketMessageListener to Wazo Websocket message(s). Useful to react on a call event from backgroundScript file.
app.onWebsocketMessage = (message: MessageEvent) => {};
changeToolbarDisplayChanges the status/visibility of the toolbar.
app.changeToolbarDisplay(displayed: boolean);
switchPortalResellerSwitches the current portal reseller. The portal will resolve the reseller name from the provided UUID.
app.switchPortalReseller(uuid: string);
switchStackLocationSwitches the current stack location. The portal will resolve the location name from the provided UUID.
app.switchStackLocation(uuid: string);
onConnectedToStackListener to detect when the user successfuly connects to a stack.
app.onConnectedToStack = (stackSession: Object) => {};
onSwitchTenantListener when the user is switching to a stack tenant.
app.onSwitchTenant = (uuid: string, name: string) => {};