Plugins APIs
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.
Initilizationβ
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();
Lifecycleβ
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.
Initializingβ
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();
Getting the Contextβ
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
}
}
user
values depends on the application your building for. See WDASession
and the PortalSession
types for moreΒ information.
Runningβ
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.
Unloadingβ
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
.
If you're using a background script, it's important to close any WebSocket or listeners at this cycle of the plugin.
Global Eventsβ
onNewSession
β
Event 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) => {}
onLogout
β
Event when the user logs out from the application
app.onLogout = () => {};
Unloaded Eventsβ
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 yourbackgroundScript
file
onUnLoaded
(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) => {};
E-UC Apps (Web and Desktop)β
Methodsβ
openLeftPanel
β
Open the left panel of Wazo Web & Desktop
app.openLeftPanel();
closeLeftPanel
β
Close 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();
};
startCall
β
Starting a call audio or video call
app.startCall({ targets , requestedModalities = ['audio'] });
Example:
app.startCall({ targets: ['8008'], requestedModalities: ['video'] });
openLink
β
Opening 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');
createMeeting
β
Creates 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 => {};
openMeetingLobby
β
Open an meeting lobby
app.openMeetingLobby(extension: string);
Example:
// Open the lobby when a meeting is created
app.onMeetingCreated = newMeeting => {
app.openMeetingLobby(newMeeting.exten);
};
ignoreCall
β
Ignoring an incoming call.
app.onCallIncoming = call => {
app.ignoreCall(call);
};
playNewMessageSound
β
Play the sound when we receive a text message.
app.playNewMessageSound();
playIncomingCallSound
β
Play the incoming call sound (π loop)
app.playIncomingCallSound();
playProgressSound
β
Play the ringback sound when we make a call (π loop)
app.playProgressSound();
playDoubleCallSound
β
Play the sound when another call is incoming
app.playDoubleCallSound();
playHangupSound
β
Play the hangup sound
app.playHangupSound();
stopCurrentSound
β
Stop the current sound. Sounds marked "π loop" can be stopped only using this method.
app.stopCurrentSound();
configureSounds
β
Configuring 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.
})
You can omit a value, the default sound will be used.
resetSounds
β
This method will reset all application sounds to origianl ones.
app.resetSounds();
displayNotification
β
Show an app notification, will display browser or desktop notification depending on the environment where the app is running.
app.displayNotification(title: string, text: string);
changeNavBarColor
β
Change the navigation bar color with a valid CSS color.
app.changeNavBarColor(color: string);
Example:
app.changeNavBarColor('#8e6a3a');
app.changeNavBarColor('white');
resetNavBarColor
β
Reset to the default navigation bar color to defaut color
app.resetNavBarColor();
displayModal
β
Will display a modal in the application, the method must called from the backgroundScript
file.
app.displayModal({ url, title, text, htmlText, height, width, hideCloseButton });
- If
url
is present, the modal will display an iframe with the content of the url. - If
htmlText
is present, the modal will display this text in a html contact, otherwise thetext
attribute will be used. height
andwidth
accept valid CSS values, like500px
or80%
.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 (throughapp.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%',
});
};
removeModal
β
Will remove the shown modal in the application, the method must be called from the backgroundScript
file or within the modal HTML.
app.removeModal();
displayBanner
β
We can display a mobile banner from the backgroundScript
file.
app.displayBanner({ url, height, width, hideCloseButton });
- If
url
is present, the modal will display an iframe with the content of the url. height
accepts valid CSS values, like500px
or80%
.width
accepts valid CSS values, like500px
or80%
, 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 (throughapp.removeModal()
method).
On Web/Desktop App, the banner will be integrated with other banners like incoming calls. Other banners will be displayed below.
closeBanner
β
We can hide a mobile banner from the backgroundScript
or within the banner HTML page.
app.closeBanner();
hasLocalVideoStream
β
Check if a call has a local video stream.
app.hasLocalVideoStream(call: Call);
Example:
app.onCallAnswered = (call) => {
const hasLocalVideo = app.hasLocalVideoStream(call);
}
getLocalCurrentVideoStream
β
Retrieving the local video stream of a call.
app.getLocalCurrentVideoStream(call: Call);
Example:
app.onCallAnswered = (call) => {
const stream = app.getLocalCurrentVideoStream(call);
}
hasRemoteVideoStream
β
Checking if a call has a remote video stream.
app.hasRemoteVideoStream(call: Call);
Example:
app.onCallAnswered = (call) => {
const hasRemoteVideo = app.hasRemoteVideoStream(call);
}
getRemoteCurrentVideoStream
β
Retrieving the remote video stream of a call.
app.getRemoteCurrentVideoStream(call: Call);
Example:
app.onCallAnswered = (call) => {
const stream = app.getRemoteCurrentVideoStream(call);
}
sendMessageToBackground
β
Sending 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);
sendMessageToIframe
β
In 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);
}
updateBadge
β
Display 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 });
Eventsβ
onCallIncoming
β
Listener when a call for the current user is incoming. Useful to react on a call event from backgroundScript
file.
app.onCallIncoming = (call: Call) => {};
onCallMade
β
Listener 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) => {};
onCallAnswered
β
Listener when an incoming call is answered by the current user. Useful to react on a call event from backgroundScript
file.
app.onCallAnswered = (call: Call) => {};
onCallAccepted
β
Listener 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) => {};
onCallHungUp
β
Listener when a call is hung up. Useful to react on a call event from backgroundScript
file.
app.onCallHungUp = (call: Call) => {};
onWebsocketMessage
β
Listener to Wazo Websocket message(s). Useful to react on a call event from backgroundScript
file.
app.onWebsocketMessage = (message: MessageEvent) => {};
onMeetingCreated
β
Listener of meeting creation.
app.onMeetingCreated = (meeting: Meeting) => { };
onRouteChanged
β
Listener of navigation changes in the app.
app.onRouteChanged = (location: Object, action: string) => { };
onUserJoinRoom
β
Listener when a user enters a room.
app.onUserJoinRoom = (room) => {};
onUserLeaveRoom
β
Listener when a user leavers a room.
app.onUserLeaveRoom = (room) => {};
onParticipantJoinRoom
β
Listener when a participant enters a room.
app.onParticipantJoinRoom = (room, participant) => {};
onParticipantLeaveRoom
β
Listener when a participant leaves a room.
app.onParticipantLeaveRoom = (room, participant) => {};
E-UC Mobileβ
Methodsβ
setMobileHeader
β
Will 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 tonull
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 tonull
reinstates the original behavior.
setMobileShowBottomNav
β
Define whether you want to show or hide the bottom navigation.
app.setMobileShowBottomNav(show: boolean);
startCall
β
Start a new audio or video call
app.startCall({ targets , requestedModalities = ['audio'] });
Example:
app.startCall({ targets: ['8008'], requestedModalities: ['video'] });
playProgressSound
β
Play the ringback sound when we make a call (π loop)
app.playProgressSound();
playNewMessageSound
β
Play the sound when we receive a text message.
app.playNewMessageSound();
playHangupSound
β
Play the hangup sound
app.playHangupSound();
stopCurrentSound
β
Stop the current sound. Sounds marked "π loop" can be stopped only using this method.
app.stopCurrentSound();
displayModal
β
Will display a modal in the application, the method must called from the backgroundScript
file.
app.displayModal({ url, title, text, htmlText, height, width, hideCloseButton });
- If
url
is present, the modal will display an iframe with the content of the url. - If
htmlText
is present, the modal will display this text in a html contact, otherwise thetext
attribute will be used. height
andwidth
accept valid CSS values, like500px
or80%
.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 (throughapp.removeModal()
method).
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%',
});
};
removeModal
β
Will remove the shown modal in the application, the method must called from the backgroundScript
file or within the modal HTML.
app.removeModal();
displayBanner
β
We can display a mobile banner from the backgroundScript
file.
app.displayBanner({ url, height, width, hideCloseButton });
- If
url
is present, the modal will display an iframe with the content of the url. height
accepts valid CSS values, like500px
or80%
.width
accepts valid CSS values, like500px
or80%
, 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 (throughapp.removeModal()
method).
On mobile, links with a target="_blank"
attribute will be opened in the user's default browser.
closeBanner
β
We can hide a mobile banner fro the backgroundScript
or withing the banner HTML page.
app.closeBanner();
updateBadge
β
Display 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 });
On Wazo Mobile, only the field badgeContent: number
is used to display the badge.
sendMessageToBackground
β
Sending 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);
sendMessageToIframe
β
In 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);
}
Eventsβ
onCallIncoming
β
Listener to detect incoming calls for the current user. Useful to react on a call event from backgroundScript
file.
app.onCallIncoming = (call: Call) => {};
onCallMade
β
Listener 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) => {};
onCallAnswered
β
Listener 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) => {};
onCallAccepted
β
Listener 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) => {};
onCallHungUp
β
Listener to detect hung up calls. Useful to react on a call event from backgroundScript
file.
app.onCallHungUp = (call: Call) => {};
onWebsocketMessage
β
Listener to Wazo Websocket message(s). Useful to react on a call event from backgroundScript
file.
app.onWebsocketMessage = (message: MessageEvent) => {};
E-UC Portalβ
Methodsβ
changeToolbarDisplay
β
Changes the status/visibility of the toolbar.
app.changeToolbarDisplay(displayed: boolean);
Eventsβ
onConnectedToStack
β
Listener to detect when the user successfuly connects to a stack.
app.onConnectedToStack = (stackSession: Object) => {};
onSwitchTenant
β
Listener when the user is switching to a stack tenant.
app.onSwitchTenant = (uuid: string, name: string) => {};