Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@wazo/euc-plugins-sdk

Package Overview
Dependencies
Maintainers
5
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wazo/euc-plugins-sdk - npm Package Compare versions

Comparing version 0.0.8 to 0.0.9

141

lib/cjs/app.js

@@ -12,7 +12,14 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
// Global
const EVENT_ON_LOADED = 'wazo/ON_LOADED';
const EVENT_APP_UNLOADED = 'wazo/EVENT_APP_UNLOADED';
const EVENT_APP_INITIALIZE = 'wazo/EVENT_APP_INITIALIZE';
const EVENT_ON_LOGOUT = 'wazo/EVENT_ON_LOGOUT';
const EVENT_SEND_IFRAME_MESSAGE = 'wazo/EVENT_SEND_IFRAME_MESSAGE';
const EVENT_SEND_BACKGROUND_MESSAGE = 'wazo/EVENT_SEND_BACKGROUND_MESSAGE';
const EVENT_ON_IFRAME_MESSAGE = 'wazo/EVENT_ON_IFRAME_MESSAGE';
const EVENT_ON_BACKGROUND_MESSAGE = 'wazo/EVENT_ON_BACKGROUND_MESSAGE';
// WDA
const EVENT_APP_INITIALIZE = 'wazo/EVENT_APP_INITIALIZE';
const EVENT_CLOSE_LEFT_PANEL = 'wazo/EVENT_CLOSE_LEFT_PANEL';
const EVENT_OPEN_LEFT_PANEL = 'wazo/EVENT_OPEN_LEFT_PANEL';
const EVENT_ON_LOADED = 'wazo/ON_LOADED';
const EVENT_START_CALL = 'wazo/START_CALL';

@@ -29,3 +36,2 @@ const EVENT_ON_CALL_INCOMING = 'wazo/EVENT_ON_CALL_INCOMING';

const EVENT_ROUTE_CHANGE = 'wazo/EVENT_ROUTE_CHANGE';
const EVENT_ON_LOGOUT = 'wazo/EVENT_ON_LOGOUT';
const EVENT_WS_MESSAGE = 'wazo/EVENT_WS_MESSAGE';

@@ -43,2 +49,6 @@ const EVENT_PLAY_PROGRESS_SOUND = 'wazo/EVENT_PLAY_PROGRESS_SOUND';

const EVENT_REMOVE_MODAL = 'wazo/EVENT_REMOVE_MODAL';
const EVENT_USER_JOIN_ROOM = 'wazo/EVENT_USER_JOIN_ROOM';
const EVENT_USER_LEAVE_ROOM = 'wazo/EVENT_USER_LEAVE_ROOM';
const EVENT_PARTICIPANT_JOIN_ROOM = 'wazo/EVENT_PARTICIPANT_JOIN_ROOM';
const EVENT_PARTICIPANT_LEAVE_ROOM = 'wazo/EVENT_PARTICIPANT_LEAVE_ROOM';
// Portal

@@ -50,5 +60,8 @@ const EVENT_ON_CONNECTED_TO_STACK = 'wazo/EVENT_ON_CONNECTED_TO_STACK';

class App {
onUnLoaded(e) { }
;
constructor() {
// Global
this.onUnLoaded = (e) => { };
this.onAppUnLoaded = (tabId) => { };
this.onIframeMessage = (message) => { };
this.onBackgroundMessage = (message) => { };
// WDA

@@ -64,2 +77,6 @@ this.onLogout = () => { };

this.onRouteChanged = (location, action) => { };
this.onUserJoinRoom = (room) => { };
this.onUserLeaveRoom = (room) => { };
this.onParticipantJoinRoom = (room, participant) => { };
this.onParticipantLeaveRoom = (room, participant) => { };
// Portal

@@ -74,14 +91,18 @@ this.onConnectedToStack = (stackSession) => { };

return new Promise((resolve, reject) => {
this._sendMessage(EVENT_APP_INITIALIZE);
this.initializeTimeout = setTimeout(() => {
this.initializeTimeout = null;
this._sendMessage(EVENT_APP_INITIALIZE, { bg: this._isBackground });
this._initializeTimeout = setTimeout(() => {
this._initializeTimeout = null;
reject('SDK initialize timeout');
}, initializationTimeoutInMs);
this.initializeResolve = resolve;
this._initializeResolve = resolve;
});
});
this.isInitialized = () => {
return this.initializeCompleted;
return this._initializeCompleted;
};
// Global
this.getContext = () => this.context;
this.sendMessageToIframe = (payload) => this._sendMessage(EVENT_SEND_IFRAME_MESSAGE, { payload });
this.sendMessageToBackground = (payload) => this._sendMessage(EVENT_SEND_BACKGROUND_MESSAGE, { payload });
// WDA
this.startCall = ({ targets, requestedModalities = ['audio'] }) => {

@@ -115,5 +136,9 @@ this._sendMessage(EVENT_START_CALL, { targets, requestedModalities });

this.displayModal = ({ url, title, text, htmlText, height, width }) => this._sendMessage(EVENT_DISPLAY_MODAL, { url, title, text, htmlText, height, width });
this.removeModal = () => this._sendMessage(EVENT_REMOVE_MODAL);
this.hasLocalVideoStream = (call) => Wazo.Phone.phone.hasALocalVideoTrack(call);
this.getLocalCurrentVideoStream = (call) => Wazo.Phone.phone.getLocalVideoStream(call);
this.hasRemoveVideoStream = (call) => Wazo.Phone.phone.hasRemoteVideo(call);
this.getRemoteVideoStream = (call) => Wazo.Phone.phone.getRemoteVideoStream(call);
// Portal
this.changeToolbarDisplay = (display) => this._sendMessage(EVENT_CHANGE_TOOLBAR_DISPLAY, { display });
this.removeModal = () => this._sendMessage(EVENT_REMOVE_MODAL);
this._onMessage = (event) => {

@@ -124,6 +149,36 @@ if (!event.data) {

switch (event.data.type) {
// WDA
// Global
case EVENT_ON_LOADED:
this._onLoaded(event.data.session, event.data.theme, event.data.locale, event.data.extra);
break;
case EVENT_APP_UNLOADED:
this.onAppUnLoaded(event.data.tabId);
break;
case EVENT_ON_LOGOUT:
this.onLogout();
this._resetEvents();
break;
case EVENT_ON_IFRAME_MESSAGE:
if (event.data._pluginId === this._pluginId) {
this.onIframeMessage(event.data.payload);
}
break;
case EVENT_ON_BACKGROUND_MESSAGE:
if (event.data._pluginId === this._pluginId) {
this.onBackgroundMessage(event.data.payload);
}
break;
case EVENT_USER_JOIN_ROOM:
this.onUserJoinRoom(event.data.room);
break;
case EVENT_USER_LEAVE_ROOM:
this.onUserLeaveRoom(event.data.room);
break;
case EVENT_PARTICIPANT_JOIN_ROOM:
this.onParticipantJoinRoom(event.data.room, event.data.participant);
break;
case EVENT_PARTICIPANT_LEAVE_ROOM:
this.onParticipantLeaveRoom(event.data.room, event.data.participant);
break;
// WDA
case EVENT_WS_MESSAGE:

@@ -150,5 +205,2 @@ this.onWebsocketMessage(event.data.message);

break;
case EVENT_ON_LOGOUT:
this.onLogout();
break;
// Portal

@@ -167,15 +219,24 @@ case EVENT_ON_CONNECTED_TO_STACK:

this._sendMessage = (type, payload = {}) => {
if (!this.isInitialized() && type !== EVENT_APP_INITIALIZE) {
this._queuedMessages.push({ type, payload });
return;
}
// @ts-ignore
if (window.ReactNativeWebView) {
// @ts-ignore (Mobile)
return window.ReactNativeWebView.postMessage(JSON.stringify(Object.assign({ type }, payload)));
return window.ReactNativeWebView.postMessage(JSON.stringify(Object.assign({ type, _pluginId: this._pluginId }, payload)));
}
window.parent.postMessage(Object.assign({ type }, payload), '*');
window.parent.postMessage(Object.assign({ type, _pluginId: this._pluginId }, payload), '*');
};
this._sendQueuedMessages = () => {
this._queuedMessages.forEach(({ type, payload }) => {
this._sendMessage(type, payload);
});
};
this._onLoaded = (session, theme, locale, extra) => {
if (this.initializeTimeout === null) {
if (this._initializeTimeout === null || this.isInitialized()) {
return;
}
clearTimeout(this.initializeTimeout);
this.initializeCompleted = true;
clearTimeout(this._initializeTimeout);
this._initializeCompleted = true;
this.context.app = {

@@ -190,9 +251,33 @@ locale,

this.context.user = session;
if (this.initializeResolve) {
this.initializeResolve();
if (this._initializeResolve) {
this._initializeResolve();
}
this._sendQueuedMessages();
};
this.initializeCompleted = false;
this.initializeResolve = null;
this.initializeTimeout = null;
this._setPluginId = (pluginId) => {
this._pluginId = pluginId;
};
this._resetEvents = () => {
this.onUnLoaded = (e) => { };
// WDA
this.onLogout = () => { };
this.onCallIncoming = (call) => { };
this.onCallMade = (call) => { };
this.onCallAnswered = (call) => { };
this.onCallHangedUp = (call) => { };
this.onUnHandledEvent = (event) => { };
this.onWebsocketMessage = (message) => { };
this.onMeetingCreated = (meeting) => { };
this.onRouteChanged = (location, action) => { };
// Portal
this.onConnectedToStack = (stackSession) => { };
this.onSwitchTenant = (uuid, name) => { };
};
this._resetEvents();
this._initializeCompleted = false;
this._initializeResolve = null;
this._initializeTimeout = null;
this._pluginId = null;
this._isBackground = false;
this._queuedMessages = [];
this.context = {

@@ -213,4 +298,10 @@ app: {

};
// Used to fetch pluginId when loaded in an iframe
if (window.name) {
this._setPluginId(window.name);
}
// Used in background script, we expose a global method to be used in the <script> tag directly after importing the backgroundScript url
globalThis._setPluginId = this._setPluginId;
}
}
exports.default = new App();

@@ -1,8 +0,22 @@

import { Call, Context, Meeting, UserInfo, Extra, ModalParameter } from './types';
import { Call, Room, Contact, Context, Meeting, UserInfo, Extra, ModalParameter } from './types';
declare global {
var _setPluginId: Function;
var Wazo: any;
}
type DelayedMessage = {
type: string;
payload: Object;
};
declare class App {
context: Context;
initializeCompleted: boolean;
initializeResolve: Function | null;
initializeTimeout: ReturnType<typeof setTimeout> | null;
onUnLoaded(e: Event): void;
_initializeCompleted: boolean;
_initializeResolve: Function | null;
_initializeTimeout: ReturnType<typeof setTimeout> | null;
_pluginId: string | null;
_queuedMessages: DelayedMessage[];
_isBackground: boolean;
onUnLoaded: (e: Event) => void;
onAppUnLoaded: (tabId: string) => void;
onIframeMessage: (message: Object) => void;
onBackgroundMessage: (message: Object) => void;
onLogout: () => void;

@@ -17,2 +31,6 @@ onCallIncoming: (call: Call) => void;

onRouteChanged: (location: Object, action: string) => void;
onUserJoinRoom: (room: Room) => void;
onUserLeaveRoom: (room: Room) => void;
onParticipantJoinRoom: (room: Room, participant: Contact) => void;
onParticipantLeaveRoom: (room: Room, participant: Contact) => void;
onConnectedToStack: (stackSession: Object) => void;

@@ -24,2 +42,4 @@ onSwitchTenant: (uuid: string, name: string) => void;

getContext: () => Context;
sendMessageToIframe: (payload: Object) => any;
sendMessageToBackground: (payload: Object) => any;
startCall: ({ targets, requestedModalities }: {

@@ -45,7 +65,14 @@ targets: string[];

displayModal: ({ url, title, text, htmlText, height, width }: ModalParameter) => any;
removeModal: () => any;
hasLocalVideoStream: (call: Call) => any;
getLocalCurrentVideoStream: (call: Call) => any;
hasRemoveVideoStream: (call: Call) => any;
getRemoteVideoStream: (call: Call) => any;
changeToolbarDisplay: (display: boolean) => any;
removeModal: () => any;
_onMessage: (event: MessageEvent) => void;
_sendMessage: (type: string, payload?: {}) => any;
_sendQueuedMessages: () => void;
_onLoaded: (session: UserInfo, theme: Object, locale: string, extra: Extra | null) => void;
_setPluginId: (pluginId: string) => void;
_resetEvents: () => void;
}

@@ -52,0 +79,0 @@ declare const _default: App;

@@ -133,2 +133,24 @@ export declare enum HostClientType {

}
export interface Contact {
id: string;
name: string;
number: string;
email: string;
favorited?: boolean;
address: string;
mobile?: boolean;
personalStatus?: string;
sessions?: Array<{
uuid: string;
mobile: boolean;
}>;
connected?: boolean;
doNotDisturb?: boolean;
}
export interface Room {
id: string;
name: string;
connectedCall: Call;
participants: Contact[];
}
export interface MeetingAuthorization {

@@ -135,0 +157,0 @@ meetingUuid: string;

@@ -0,6 +1,13 @@

// Global
const EVENT_ON_LOADED = 'wazo/ON_LOADED';
const EVENT_APP_UNLOADED = 'wazo/EVENT_APP_UNLOADED';
const EVENT_APP_INITIALIZE = 'wazo/EVENT_APP_INITIALIZE';
const EVENT_ON_LOGOUT = 'wazo/EVENT_ON_LOGOUT';
const EVENT_SEND_IFRAME_MESSAGE = 'wazo/EVENT_SEND_IFRAME_MESSAGE';
const EVENT_SEND_BACKGROUND_MESSAGE = 'wazo/EVENT_SEND_BACKGROUND_MESSAGE';
const EVENT_ON_IFRAME_MESSAGE = 'wazo/EVENT_ON_IFRAME_MESSAGE';
const EVENT_ON_BACKGROUND_MESSAGE = 'wazo/EVENT_ON_BACKGROUND_MESSAGE';
// WDA
const EVENT_APP_INITIALIZE = 'wazo/EVENT_APP_INITIALIZE';
const EVENT_CLOSE_LEFT_PANEL = 'wazo/EVENT_CLOSE_LEFT_PANEL';
const EVENT_OPEN_LEFT_PANEL = 'wazo/EVENT_OPEN_LEFT_PANEL';
const EVENT_ON_LOADED = 'wazo/ON_LOADED';
const EVENT_START_CALL = 'wazo/START_CALL';

@@ -17,3 +24,2 @@ const EVENT_ON_CALL_INCOMING = 'wazo/EVENT_ON_CALL_INCOMING';

const EVENT_ROUTE_CHANGE = 'wazo/EVENT_ROUTE_CHANGE';
const EVENT_ON_LOGOUT = 'wazo/EVENT_ON_LOGOUT';
const EVENT_WS_MESSAGE = 'wazo/EVENT_WS_MESSAGE';

@@ -31,2 +37,6 @@ const EVENT_PLAY_PROGRESS_SOUND = 'wazo/EVENT_PLAY_PROGRESS_SOUND';

const EVENT_REMOVE_MODAL = 'wazo/EVENT_REMOVE_MODAL';
const EVENT_USER_JOIN_ROOM = 'wazo/EVENT_USER_JOIN_ROOM';
const EVENT_USER_LEAVE_ROOM = 'wazo/EVENT_USER_LEAVE_ROOM';
const EVENT_PARTICIPANT_JOIN_ROOM = 'wazo/EVENT_PARTICIPANT_JOIN_ROOM';
const EVENT_PARTICIPANT_LEAVE_ROOM = 'wazo/EVENT_PARTICIPANT_LEAVE_ROOM';
// Portal

@@ -38,5 +48,8 @@ const EVENT_ON_CONNECTED_TO_STACK = 'wazo/EVENT_ON_CONNECTED_TO_STACK';

class App {
onUnLoaded(e) { }
;
constructor() {
// Global
this.onUnLoaded = (e) => { };
this.onAppUnLoaded = (tabId) => { };
this.onIframeMessage = (message) => { };
this.onBackgroundMessage = (message) => { };
// WDA

@@ -52,2 +65,6 @@ this.onLogout = () => { };

this.onRouteChanged = (location, action) => { };
this.onUserJoinRoom = (room) => { };
this.onUserLeaveRoom = (room) => { };
this.onParticipantJoinRoom = (room, participant) => { };
this.onParticipantLeaveRoom = (room, participant) => { };
// Portal

@@ -62,14 +79,18 @@ this.onConnectedToStack = (stackSession) => { };

return new Promise((resolve, reject) => {
this._sendMessage(EVENT_APP_INITIALIZE);
this.initializeTimeout = setTimeout(() => {
this.initializeTimeout = null;
this._sendMessage(EVENT_APP_INITIALIZE, { bg: this._isBackground });
this._initializeTimeout = setTimeout(() => {
this._initializeTimeout = null;
reject('SDK initialize timeout');
}, initializationTimeoutInMs);
this.initializeResolve = resolve;
this._initializeResolve = resolve;
});
};
this.isInitialized = () => {
return this.initializeCompleted;
return this._initializeCompleted;
};
// Global
this.getContext = () => this.context;
this.sendMessageToIframe = (payload) => this._sendMessage(EVENT_SEND_IFRAME_MESSAGE, { payload });
this.sendMessageToBackground = (payload) => this._sendMessage(EVENT_SEND_BACKGROUND_MESSAGE, { payload });
// WDA
this.startCall = ({ targets, requestedModalities = ['audio'] }) => {

@@ -103,5 +124,9 @@ this._sendMessage(EVENT_START_CALL, { targets, requestedModalities });

this.displayModal = ({ url, title, text, htmlText, height, width }) => this._sendMessage(EVENT_DISPLAY_MODAL, { url, title, text, htmlText, height, width });
this.removeModal = () => this._sendMessage(EVENT_REMOVE_MODAL);
this.hasLocalVideoStream = (call) => Wazo.Phone.phone.hasALocalVideoTrack(call);
this.getLocalCurrentVideoStream = (call) => Wazo.Phone.phone.getLocalVideoStream(call);
this.hasRemoveVideoStream = (call) => Wazo.Phone.phone.hasRemoteVideo(call);
this.getRemoteVideoStream = (call) => Wazo.Phone.phone.getRemoteVideoStream(call);
// Portal
this.changeToolbarDisplay = (display) => this._sendMessage(EVENT_CHANGE_TOOLBAR_DISPLAY, { display });
this.removeModal = () => this._sendMessage(EVENT_REMOVE_MODAL);
this._onMessage = (event) => {

@@ -112,6 +137,36 @@ if (!event.data) {

switch (event.data.type) {
// WDA
// Global
case EVENT_ON_LOADED:
this._onLoaded(event.data.session, event.data.theme, event.data.locale, event.data.extra);
break;
case EVENT_APP_UNLOADED:
this.onAppUnLoaded(event.data.tabId);
break;
case EVENT_ON_LOGOUT:
this.onLogout();
this._resetEvents();
break;
case EVENT_ON_IFRAME_MESSAGE:
if (event.data._pluginId === this._pluginId) {
this.onIframeMessage(event.data.payload);
}
break;
case EVENT_ON_BACKGROUND_MESSAGE:
if (event.data._pluginId === this._pluginId) {
this.onBackgroundMessage(event.data.payload);
}
break;
case EVENT_USER_JOIN_ROOM:
this.onUserJoinRoom(event.data.room);
break;
case EVENT_USER_LEAVE_ROOM:
this.onUserLeaveRoom(event.data.room);
break;
case EVENT_PARTICIPANT_JOIN_ROOM:
this.onParticipantJoinRoom(event.data.room, event.data.participant);
break;
case EVENT_PARTICIPANT_LEAVE_ROOM:
this.onParticipantLeaveRoom(event.data.room, event.data.participant);
break;
// WDA
case EVENT_WS_MESSAGE:

@@ -138,5 +193,2 @@ this.onWebsocketMessage(event.data.message);

break;
case EVENT_ON_LOGOUT:
this.onLogout();
break;
// Portal

@@ -155,15 +207,24 @@ case EVENT_ON_CONNECTED_TO_STACK:

this._sendMessage = (type, payload = {}) => {
if (!this.isInitialized() && type !== EVENT_APP_INITIALIZE) {
this._queuedMessages.push({ type, payload });
return;
}
// @ts-ignore
if (window.ReactNativeWebView) {
// @ts-ignore (Mobile)
return window.ReactNativeWebView.postMessage(JSON.stringify({ type, ...payload }));
return window.ReactNativeWebView.postMessage(JSON.stringify({ type, _pluginId: this._pluginId, ...payload }));
}
window.parent.postMessage({ type, ...payload }, '*');
window.parent.postMessage({ type, _pluginId: this._pluginId, ...payload }, '*');
};
this._sendQueuedMessages = () => {
this._queuedMessages.forEach(({ type, payload }) => {
this._sendMessage(type, payload);
});
};
this._onLoaded = (session, theme, locale, extra) => {
if (this.initializeTimeout === null) {
if (this._initializeTimeout === null || this.isInitialized()) {
return;
}
clearTimeout(this.initializeTimeout);
this.initializeCompleted = true;
clearTimeout(this._initializeTimeout);
this._initializeCompleted = true;
this.context.app = {

@@ -178,9 +239,33 @@ locale,

this.context.user = session;
if (this.initializeResolve) {
this.initializeResolve();
if (this._initializeResolve) {
this._initializeResolve();
}
this._sendQueuedMessages();
};
this.initializeCompleted = false;
this.initializeResolve = null;
this.initializeTimeout = null;
this._setPluginId = (pluginId) => {
this._pluginId = pluginId;
};
this._resetEvents = () => {
this.onUnLoaded = (e) => { };
// WDA
this.onLogout = () => { };
this.onCallIncoming = (call) => { };
this.onCallMade = (call) => { };
this.onCallAnswered = (call) => { };
this.onCallHangedUp = (call) => { };
this.onUnHandledEvent = (event) => { };
this.onWebsocketMessage = (message) => { };
this.onMeetingCreated = (meeting) => { };
this.onRouteChanged = (location, action) => { };
// Portal
this.onConnectedToStack = (stackSession) => { };
this.onSwitchTenant = (uuid, name) => { };
};
this._resetEvents();
this._initializeCompleted = false;
this._initializeResolve = null;
this._initializeTimeout = null;
this._pluginId = null;
this._isBackground = false;
this._queuedMessages = [];
this.context = {

@@ -201,4 +286,10 @@ app: {

};
// Used to fetch pluginId when loaded in an iframe
if (window.name) {
this._setPluginId(window.name);
}
// Used in background script, we expose a global method to be used in the <script> tag directly after importing the backgroundScript url
globalThis._setPluginId = this._setPluginId;
}
}
export default new App();

@@ -1,8 +0,22 @@

import { Call, Context, Meeting, UserInfo, Extra, ModalParameter } from './types';
import { Call, Room, Contact, Context, Meeting, UserInfo, Extra, ModalParameter } from './types';
declare global {
var _setPluginId: Function;
var Wazo: any;
}
type DelayedMessage = {
type: string;
payload: Object;
};
declare class App {
context: Context;
initializeCompleted: boolean;
initializeResolve: Function | null;
initializeTimeout: ReturnType<typeof setTimeout> | null;
onUnLoaded(e: Event): void;
_initializeCompleted: boolean;
_initializeResolve: Function | null;
_initializeTimeout: ReturnType<typeof setTimeout> | null;
_pluginId: string | null;
_queuedMessages: DelayedMessage[];
_isBackground: boolean;
onUnLoaded: (e: Event) => void;
onAppUnLoaded: (tabId: string) => void;
onIframeMessage: (message: Object) => void;
onBackgroundMessage: (message: Object) => void;
onLogout: () => void;

@@ -17,2 +31,6 @@ onCallIncoming: (call: Call) => void;

onRouteChanged: (location: Object, action: string) => void;
onUserJoinRoom: (room: Room) => void;
onUserLeaveRoom: (room: Room) => void;
onParticipantJoinRoom: (room: Room, participant: Contact) => void;
onParticipantLeaveRoom: (room: Room, participant: Contact) => void;
onConnectedToStack: (stackSession: Object) => void;

@@ -24,2 +42,4 @@ onSwitchTenant: (uuid: string, name: string) => void;

getContext: () => Context;
sendMessageToIframe: (payload: Object) => any;
sendMessageToBackground: (payload: Object) => any;
startCall: ({ targets, requestedModalities }: {

@@ -45,7 +65,14 @@ targets: string[];

displayModal: ({ url, title, text, htmlText, height, width }: ModalParameter) => any;
removeModal: () => any;
hasLocalVideoStream: (call: Call) => any;
getLocalCurrentVideoStream: (call: Call) => any;
hasRemoveVideoStream: (call: Call) => any;
getRemoteVideoStream: (call: Call) => any;
changeToolbarDisplay: (display: boolean) => any;
removeModal: () => any;
_onMessage: (event: MessageEvent) => void;
_sendMessage: (type: string, payload?: {}) => any;
_sendQueuedMessages: () => void;
_onLoaded: (session: UserInfo, theme: Object, locale: string, extra: Extra | null) => void;
_setPluginId: (pluginId: string) => void;
_resetEvents: () => void;
}

@@ -52,0 +79,0 @@ declare const _default: App;

@@ -133,2 +133,24 @@ export declare enum HostClientType {

}
export interface Contact {
id: string;
name: string;
number: string;
email: string;
favorited?: boolean;
address: string;
mobile?: boolean;
personalStatus?: string;
sessions?: Array<{
uuid: string;
mobile: boolean;
}>;
connected?: boolean;
doNotDisturb?: boolean;
}
export interface Room {
id: string;
name: string;
connectedCall: Call;
participants: Contact[];
}
export interface MeetingAuthorization {

@@ -135,0 +157,0 @@ meetingUuid: string;

2

package.json
{
"name": "@wazo/euc-plugins-sdk",
"version": "0.0.8",
"version": "0.0.9",
"description": "Wazo's Unified Enterprise Communication JavaScript Software Development Kit.",

@@ -5,0 +5,0 @@ "author": "Wazo (http://wazo.io)",

@@ -1,8 +0,22 @@

import { Call, Context, Meeting, UserInfo, Extra, ModalParameter } from './types';
/* global Wazo */
import { Call, Room, Contact, Context, Meeting, UserInfo, Extra, ModalParameter } from './types';
declare global {
var _setPluginId: Function;
var Wazo: any;
}
// Global
const EVENT_ON_LOADED = 'wazo/ON_LOADED';
const EVENT_APP_UNLOADED = 'wazo/EVENT_APP_UNLOADED';
const EVENT_APP_INITIALIZE = 'wazo/EVENT_APP_INITIALIZE';
const EVENT_ON_LOGOUT = 'wazo/EVENT_ON_LOGOUT';
const EVENT_SEND_IFRAME_MESSAGE = 'wazo/EVENT_SEND_IFRAME_MESSAGE';
const EVENT_SEND_BACKGROUND_MESSAGE = 'wazo/EVENT_SEND_BACKGROUND_MESSAGE';
const EVENT_ON_IFRAME_MESSAGE = 'wazo/EVENT_ON_IFRAME_MESSAGE';
const EVENT_ON_BACKGROUND_MESSAGE = 'wazo/EVENT_ON_BACKGROUND_MESSAGE';
// WDA
const EVENT_APP_INITIALIZE = 'wazo/EVENT_APP_INITIALIZE';
const EVENT_CLOSE_LEFT_PANEL = 'wazo/EVENT_CLOSE_LEFT_PANEL';
const EVENT_OPEN_LEFT_PANEL = 'wazo/EVENT_OPEN_LEFT_PANEL';
const EVENT_ON_LOADED = 'wazo/ON_LOADED';
const EVENT_START_CALL = 'wazo/START_CALL';

@@ -19,3 +33,2 @@ const EVENT_ON_CALL_INCOMING = 'wazo/EVENT_ON_CALL_INCOMING';

const EVENT_ROUTE_CHANGE = 'wazo/EVENT_ROUTE_CHANGE';
const EVENT_ON_LOGOUT = 'wazo/EVENT_ON_LOGOUT';
const EVENT_WS_MESSAGE = 'wazo/EVENT_WS_MESSAGE';

@@ -33,2 +46,6 @@ const EVENT_PLAY_PROGRESS_SOUND = 'wazo/EVENT_PLAY_PROGRESS_SOUND';

const EVENT_REMOVE_MODAL = 'wazo/EVENT_REMOVE_MODAL';
const EVENT_USER_JOIN_ROOM = 'wazo/EVENT_USER_JOIN_ROOM';
const EVENT_USER_LEAVE_ROOM = 'wazo/EVENT_USER_LEAVE_ROOM';
const EVENT_PARTICIPANT_JOIN_ROOM = 'wazo/EVENT_PARTICIPANT_JOIN_ROOM';
const EVENT_PARTICIPANT_LEAVE_ROOM = 'wazo/EVENT_PARTICIPANT_LEAVE_ROOM';

@@ -42,9 +59,21 @@ // Portal

type DelayedMessage = {
type: string;
payload: Object;
};
class App {
context: Context;
initializeCompleted: boolean;
initializeResolve: Function | null;
initializeTimeout: ReturnType<typeof setTimeout> | null;
_initializeCompleted: boolean;
_initializeResolve: Function | null;
_initializeTimeout: ReturnType<typeof setTimeout> | null;
_pluginId: string | null;
_queuedMessages: DelayedMessage[];
_isBackground: boolean;
onUnLoaded(e: Event) {};
// Global
onUnLoaded = (e: Event) => {};
onAppUnLoaded = (tabId: string) => {};
onIframeMessage = (message: Object) => { };
onBackgroundMessage = (message: Object) => { };

@@ -61,2 +90,6 @@ // WDA

onRouteChanged = (location: Object, action: string) => {};
onUserJoinRoom = (room: Room) => {};
onUserLeaveRoom = (room: Room) => {};
onParticipantJoinRoom = (room: Room, participant: Contact) => {};
onParticipantLeaveRoom = (room: Room, participant: Contact) => {};

@@ -68,5 +101,9 @@ // Portal

constructor() {
this.initializeCompleted = false;
this.initializeResolve = null;
this.initializeTimeout = null;
this._resetEvents();
this._initializeCompleted = false;
this._initializeResolve = null;
this._initializeTimeout = null;
this._pluginId = null;
this._isBackground = false;
this._queuedMessages = [];

@@ -89,2 +126,10 @@ this.context = {

}
// Used to fetch pluginId when loaded in an iframe
if (window.name) {
this._setPluginId(window.name);
}
// Used in background script, we expose a global method to be used in the <script> tag directly after importing the backgroundScript url
globalThis._setPluginId = this._setPluginId;
}

@@ -100,10 +145,10 @@

return new Promise((resolve, reject) => {
this._sendMessage(EVENT_APP_INITIALIZE);
this._sendMessage(EVENT_APP_INITIALIZE, { bg: this._isBackground });
this.initializeTimeout = setTimeout(() => {
this.initializeTimeout = null;
this._initializeTimeout = setTimeout(() => {
this._initializeTimeout = null;
reject('SDK initialize timeout');
}, initializationTimeoutInMs);
this.initializeResolve = resolve;
this._initializeResolve = resolve;
});

@@ -113,7 +158,13 @@ };

isInitialized = () => {
return this.initializeCompleted;
return this._initializeCompleted;
};
// Global
getContext = () => this.context;
sendMessageToIframe = (payload: Object) => this._sendMessage(EVENT_SEND_IFRAME_MESSAGE, { payload });
sendMessageToBackground = (payload: Object) => this._sendMessage(EVENT_SEND_BACKGROUND_MESSAGE, { payload });
// WDA
startCall = ({ targets , requestedModalities = ['audio'] }: { targets: string[], requestedModalities: string[] }) => {

@@ -165,7 +216,15 @@ this._sendMessage(EVENT_START_CALL, { targets, requestedModalities });

removeModal = () => this._sendMessage(EVENT_REMOVE_MODAL);
hasLocalVideoStream = (call: Call) => Wazo.Phone.phone.hasALocalVideoTrack(call);
getLocalCurrentVideoStream = (call: Call) => Wazo.Phone.phone.getLocalVideoStream(call);
hasRemoveVideoStream = (call: Call) => Wazo.Phone.phone.hasRemoteVideo(call);
getRemoteVideoStream = (call: Call) => Wazo.Phone.phone.getRemoteVideoStream(call);
// Portal
changeToolbarDisplay = (display: boolean) => this._sendMessage(EVENT_CHANGE_TOOLBAR_DISPLAY, { display });
removeModal = () => this._sendMessage(EVENT_REMOVE_MODAL);
_onMessage = (event: MessageEvent) => {

@@ -177,6 +236,37 @@ if (!event.data) {

switch (event.data.type) {
// WDA
// Global
case EVENT_ON_LOADED:
this._onLoaded(event.data.session, event.data.theme, event.data.locale, event.data.extra);
break;
case EVENT_APP_UNLOADED:
this.onAppUnLoaded(event.data.tabId);
break;
case EVENT_ON_LOGOUT:
this.onLogout();
this._resetEvents();
break;
case EVENT_ON_IFRAME_MESSAGE:
if (event.data._pluginId === this._pluginId) {
this.onIframeMessage(event.data.payload);
}
break;
case EVENT_ON_BACKGROUND_MESSAGE:
if (event.data._pluginId === this._pluginId) {
this.onBackgroundMessage(event.data.payload);
}
break;
case EVENT_USER_JOIN_ROOM:
this.onUserJoinRoom(event.data.room);
break;
case EVENT_USER_LEAVE_ROOM:
this.onUserLeaveRoom(event.data.room);
break;
case EVENT_PARTICIPANT_JOIN_ROOM:
this.onParticipantJoinRoom(event.data.room, event.data.participant);
break;
case EVENT_PARTICIPANT_LEAVE_ROOM:
this.onParticipantLeaveRoom(event.data.room, event.data.participant);
break;
// WDA
case EVENT_WS_MESSAGE:

@@ -203,5 +293,2 @@ this.onWebsocketMessage(event.data.message);

break;
case EVENT_ON_LOGOUT:
this.onLogout();
break;

@@ -224,19 +311,30 @@ // Portal

_sendMessage = (type: string, payload = {}) => {
if (!this.isInitialized() && type !== EVENT_APP_INITIALIZE) {
this._queuedMessages.push({ type, payload });
return;
}
// @ts-ignore
if (window.ReactNativeWebView) {
// @ts-ignore (Mobile)
return window.ReactNativeWebView.postMessage(JSON.stringify({ type, ...payload }));
return window.ReactNativeWebView.postMessage(JSON.stringify({ type, _pluginId: this._pluginId, ...payload }));
}
window.parent.postMessage({ type, ...payload }, '*');
window.parent.postMessage({ type, _pluginId: this._pluginId, ...payload }, '*');
}
_sendQueuedMessages = () => {
this._queuedMessages.forEach(({ type, payload }: DelayedMessage) => {
this._sendMessage(type, payload);
});
};
_onLoaded = (session: UserInfo, theme: Object, locale: string, extra: Extra | null) => {
if (this.initializeTimeout === null) {
if (this._initializeTimeout === null || this.isInitialized()) {
return;
}
clearTimeout(this.initializeTimeout);
clearTimeout(this._initializeTimeout);
this.initializeCompleted = true;
this._initializeCompleted = true;

@@ -254,8 +352,33 @@ this.context.app = {

if (this.initializeResolve) {
this.initializeResolve();
if (this._initializeResolve) {
this._initializeResolve();
}
this._sendQueuedMessages();
};
_setPluginId = (pluginId: string) => {
this._pluginId = pluginId;
}
_resetEvents = () => {
this.onUnLoaded = (e: Event) => {};
// WDA
this.onLogout = () => {};
this.onCallIncoming = (call: Call) => {};
this.onCallMade = (call: Call) => {};
this.onCallAnswered = (call: Call) => {};
this.onCallHangedUp = (call: Call) => {};
this.onUnHandledEvent = (event: MessageEvent) => {};
this.onWebsocketMessage = (message: MessageEvent) => {};
this.onMeetingCreated = (meeting: Meeting) => {};
this.onRouteChanged = (location: Object, action: string) => {};
// Portal
this.onConnectedToStack = (stackSession: Object) => {};
this.onSwitchTenant = (uuid: string, name: string) => {};
};
}
export default new App();

@@ -129,2 +129,26 @@ export enum HostClientType {

export interface Contact {
id: string;
name: string;
number: string;
email: string;
favorited?: boolean;
address: string;
mobile?: boolean;
personalStatus?: string;
sessions?: Array<{
uuid: string;
mobile: boolean;
}>;
connected?: boolean;
doNotDisturb?: boolean;
}
export interface Room {
id: string;
name: string;
connectedCall: Call;
participants: Contact[];
}
export interface MeetingAuthorization {

@@ -131,0 +155,0 @@ meetingUuid: string;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc