Skip to content

Commit

Permalink
Merge pull request #815 from tannera926/master
Browse files Browse the repository at this point in the history
Refreshing iFrame every ccpLoadTimeout number of seconds, fixing event subscriptions when terminating and re-initializing
  • Loading branch information
tannera926 authored Dec 6, 2023
2 parents 67baab7 + b05ca19 commit 97983f1
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 60 deletions.
2 changes: 1 addition & 1 deletion Documentation-DR.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ To allowlist your pages:

## Importing Streams with npm and ES6

`import "amazon-connect-streams/connect-streams-dr.js";` This will make the `globalConnect` variable available in the current context.
`import "amazon-connect-streams/release/connect-streams-dr.js";` This will make the `globalConnect` variable available in the current context.

## Downloading Streams from Github

Expand Down
12 changes: 11 additions & 1 deletion Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ In version 1.x, we also support `make` for legacy builds. This option was remove
## Overview
The Amazon Connect Streams API (Streams) gives you the power to integrate your existing web applications with Amazon Connect. Streams lets you embed the Contact Control Panel (CCP) and Customer Profiles app UI into your page. It also enables you to handle agent and contact state events directly through an object oriented event driven interface. You can use the built in interface or build your own from scratch: Streams gives you the choice.

This library must be used in conjunction with [amazon-connect-chatjs](https://github.com/amazon-connect/amazon-connect-chatjs) or [amazon-connect-taskjs](https://github.com/amazon-connect/amazon-connect-taskjs) in order to utilize Amazon Connect's Chat or Task functionality.
This library must be used in conjunction with
[amazon-connect-chatjs](https://github.com/amazon-connect/amazon-connect-chatjs),
[amazon-chime-sdk-js](https://github.com/aws/amazon-chime-sdk-js/blob/main/README.md),
or [amazon-connect-taskjs](https://github.com/amazon-connect/amazon-connect-taskjs)
in order to utilize Amazon Connect's Chat, Video or Task functionality.

## Architecture
Click [here](Architecture.md) to view a quick architecture overview of how the
Expand Down Expand Up @@ -316,6 +320,10 @@ this:
Streams only needs ChatJS when it is being used for chat. Note that when including ChatJS,
it must be imported after StreamsJS, or there will be AWS SDK issues
(ChatJS relies on the ConnectParticipant Service, which is not in the Streams AWS SDK).
* If you are building your own video functionalities, please also include
[Amazon Chime SDK JS](https://github.com/aws/amazon-chime-sdk-js) in your code. You can also include
[Amazon Chime SDK Component Library React](https://github.com/aws/amazon-chime-sdk-component-library-react) to
leverage ready-to-use UI and state managements components in React.
* If you are using task functionalities you must include [TaskJS](https://github.com/amazon-connect/amazon-connect-taskjs). TaskJS should be imported after Streams.
* If you'd like access to the WebRTC session to further customize the softphone experience
you can use [connect-rtc-js](https://github.com/aws/connect-rtc-js). Please refer to the connect-rtc-js readme for detailed instructions on integrating connect-rtc-js with Streams.
Expand Down Expand Up @@ -1649,6 +1657,8 @@ Example response:
```

Provides a promise which resolves with the API response from createTransport transportType web_rtc for this connection.
You can use the meeting and attendee info to join a video session. Please refer to
[Amazon Chime SDK JS](https://github.com/aws/amazon-chime-sdk-js/blob/main/README.md) for more info.

#### Multiparty call

Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ In version 1.x, we also support `make` for legacy builds. This option was remove
2. December 2020 — 1.6.0 brings with it the release of a new Agent App API. In addition to the CCP, customers can now embed additional applications using connect.agentApp, including Customer Profiles and Amazon Q Connect. See the [updated documentation](Documentation.md#initialization-for-ccp-customer-profiles-and-amazon-q-connect) for details on usage. We are also introducing a preview release for Amazon Connect Voice ID.
* ### About Amazon Connect Customer Profiles
+ Amazon Connect Customer Profiles provides pre-built integrations so you can quickly combine customer information from multiple external applications, with contact history from Amazon Connect. This allows you to create a customer profile that has all the information agents need during customer interactions in a single place.
* ### About Amazon Connect Amazon Q Connect
* ### About Amazon Q in Connect
+ With Amazon Q Connect, agents can search and find content across multiple repositories, such as frequently asked questions (FAQs), wikis, articles, and step-by-step instructions for handling different customer issues. They can type questions or phrases in a search box (such as, "how long after purchase can handbags be exchanged?") without having to guess which keywords will work.
* ### About Amazon Connect Voice ID (The feature is in preview release for Amazon Connect and is subject to change)
+ Amazon Connect Voice ID provides real-time caller authentication which makes voice interactions in contact centers more secure and efficient. Voice ID uses machine learning to verify the identity of genuine customers by analyzing a caller’s unique voice characteristics. This allows contact centers to use an additional security layer that doesn’t rely on the caller answering multiple security questions, and makes it easy to enroll and verify customers without changing the natural flow of their conversation.
Expand Down Expand Up @@ -287,6 +287,10 @@ this:
Streams only needs ChatJS when it is being used for chat. Note that when including ChatJS,
it must be imported after StreamsJS, or there will be AWS SDK issues
(ChatJS relies on the ConnectParticipant Service, which is not in the Streams AWS SDK).
* If you are building your own video functionalities, please also include
[Amazon Chime SDK JS](https://github.com/aws/amazon-chime-sdk-js) in your code. You can also include
[Amazon Chime SDK Component Library React](https://github.com/aws/amazon-chime-sdk-component-library-react) to
leverage ready-to-use UI and state managements components in React.
* If you are using task functionalities you must include [TaskJS](https://github.com/amazon-connect/amazon-connect-taskjs). TaskJS should be imported after Streams.
* If you'd like access to the WebRTC session to further customize the softphone experience
you can use [connect-rtc-js](https://github.com/aws/connect-rtc-js). Please refer to the connect-rtc-js readme for detailed instructions on integrating connect-rtc-js with Streams.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "amazon-connect-streams",
"version": "2.9.0",
"version": "2.10.0",
"description": "Amazon Connect Streams Library",
"engines": {
"node": ">=12.0.0"
Expand Down
2 changes: 1 addition & 1 deletion release/connect-streams-dr-min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion release/connect-streams-dr.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion release/connect-streams-min.js

Large diffs are not rendered by default.

21 changes: 12 additions & 9 deletions release/connect-streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -26681,7 +26681,7 @@ AWS.apiLoader.services['connect']['2017-02-15'] = require('../apis/connect-2017-

connect.core = {};
connect.core.initialized = false;
connect.version = "2.8.0";
connect.version = "2.10.0";
connect.outerContextStreamsVersion = null;
connect.DEFAULT_BATCH_SIZE = 500;

Expand All @@ -26690,7 +26690,7 @@ AWS.apiLoader.services['connect']['2017-02-15'] = require('../apis/connect-2017-
var CCP_LOAD_TIMEOUT = 5000; // 5 sec
var CCP_IFRAME_REFRESH_INTERVAL = 5000; // 5 sec
var CCP_DR_IFRAME_REFRESH_INTERVAL = 10000; //10 s
var CCP_IFRAME_REFRESH_LIMIT = 6; // 6 attempts
var CCP_IFRAME_REFRESH_LIMIT = 10; // 10 attempts
var CCP_IFRAME_NAME = 'Amazon Connect CCP';
var LEGACY_LOGIN_URL_PATTERN = "https://{alias}.awsapps.com/auth/?client_id={client_id}&redirect_uri={redirect}";
var CLIENT_ID_MAP = {
Expand Down Expand Up @@ -27088,6 +27088,7 @@ AWS.apiLoader.services['connect']['2017-02-15'] = require('../apis/connect-2017-
connect.core.softphoneManager = null;
connect.core.upstream = null;
connect.core.keepaliveManager = null;
connect.storageAccess.resetStorageAccessState();
connect.agent.initialized = false;
connect.core.initialized = false;
};
Expand Down Expand Up @@ -28129,11 +28130,11 @@ AWS.apiLoader.services['connect']['2017-02-15'] = require('../apis/connect-2017-
connect.core._refreshIframeOnTimeout = function(initCCPParams, containerDiv) {
connect.assertNotNull(initCCPParams, 'initCCPParams');
connect.assertNotNull(containerDiv, 'containerDiv');
var ccpIframeRefreshInterval = (initCCPParams.disasterRecoveryOn) ? CCP_DR_IFRAME_REFRESH_INTERVAL : CCP_IFRAME_REFRESH_INTERVAL;
var retryDelay = AWS.util.calculateRetryDelay((connect.core.iframeRefreshAttempt - 1 || 0), { base: 2000 });
// Evaluates to 0 for 0th attempt and 1 for rest (>0) of the refresh attempts
var timeoutFactor = Math.ceil((connect.core.iframeRefreshAttempt || 0) / CCP_IFRAME_REFRESH_LIMIT);
var timeout = (ccpIframeRefreshInterval + retryDelay) * timeoutFactor;
// ccpIframeRefreshInterval is the ccpLoadTimeout passed into initCCP
// if no ccpLoadTimeout is passed in, the interval is the default, which depends on if disaster recovery is on
var ccpIframeRefreshInterval = (initCCPParams.ccpLoadTimeout) ? (initCCPParams.ccpLoadTimeout)
: (initCCPParams.disasterRecoveryOn) ? CCP_DR_IFRAME_REFRESH_INTERVAL
: CCP_IFRAME_REFRESH_INTERVAL;
global.clearTimeout(connect.core.iframeRefreshTimeout);
connect.core.iframeRefreshTimeout = global.setTimeout(function() {
connect.core.iframeRefreshAttempt = (connect.core.iframeRefreshAttempt || 0) + 1;
Expand All @@ -28154,7 +28155,7 @@ AWS.apiLoader.services['connect']['2017-02-15'] = require('../apis/connect-2017-
connect.core.getEventBus().trigger(connect.EventType.IFRAME_RETRIES_EXHAUSTED);
global.clearTimeout(connect.core.iframeRefreshTimeout);
}
}, timeout);
}, ccpIframeRefreshInterval);
}


Expand Down Expand Up @@ -30696,7 +30697,7 @@ AWS.apiLoader.services['connect']['2017-02-15'] = require('../apis/connect-2017-
logger.info(logComponent, 'Destroying mediaController for %s', connectionId);
toBeDestroyed.add(connectionId);
mediaControllers[connectionId]
.then(function () {
.then(function (controller) {
if (typeof controller.cleanUp === 'function') controller.cleanUp();
delete mediaControllers[connectionId];
toBeDestroyed.delete(connectionId);
Expand Down Expand Up @@ -30927,6 +30928,7 @@ AWS.apiLoader.services['connect']['2017-02-15'] = require('../apis/connect-2017-
storageParams = {};
originalCCPUrl = '';
rsaContainer = null;
onGrantCallbackInvoked = false;
};

/**
Expand Down Expand Up @@ -31192,6 +31194,7 @@ AWS.apiLoader.services['connect']['2017-02-15'] = require('../apis/connect-2017-
getRequestStorageAccessUrl,
storageAccessEvents,
resetStorageAccessState,
getOnGrantCallbackInvoked: () => onGrantCallbackInvoked,
getStorageAccessParams: () => storageParams,
onRequest: onRequestHandler,
request: () => {
Expand Down
15 changes: 8 additions & 7 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
var CCP_LOAD_TIMEOUT = 5000; // 5 sec
var CCP_IFRAME_REFRESH_INTERVAL = 5000; // 5 sec
var CCP_DR_IFRAME_REFRESH_INTERVAL = 10000; //10 s
var CCP_IFRAME_REFRESH_LIMIT = 6; // 6 attempts
var CCP_IFRAME_REFRESH_LIMIT = 10; // 10 attempts
var CCP_IFRAME_NAME = 'Amazon Connect CCP';
var LEGACY_LOGIN_URL_PATTERN = "https://{alias}.awsapps.com/auth/?client_id={client_id}&redirect_uri={redirect}";
var CLIENT_ID_MAP = {
Expand Down Expand Up @@ -418,6 +418,7 @@
connect.core.softphoneManager = null;
connect.core.upstream = null;
connect.core.keepaliveManager = null;
connect.storageAccess.resetStorageAccessState();
connect.agent.initialized = false;
connect.core.initialized = false;
};
Expand Down Expand Up @@ -1459,11 +1460,11 @@
connect.core._refreshIframeOnTimeout = function(initCCPParams, containerDiv) {
connect.assertNotNull(initCCPParams, 'initCCPParams');
connect.assertNotNull(containerDiv, 'containerDiv');
var ccpIframeRefreshInterval = (initCCPParams.disasterRecoveryOn) ? CCP_DR_IFRAME_REFRESH_INTERVAL : CCP_IFRAME_REFRESH_INTERVAL;
var retryDelay = AWS.util.calculateRetryDelay((connect.core.iframeRefreshAttempt - 1 || 0), { base: 2000 });
// Evaluates to 0 for 0th attempt and 1 for rest (>0) of the refresh attempts
var timeoutFactor = Math.ceil((connect.core.iframeRefreshAttempt || 0) / CCP_IFRAME_REFRESH_LIMIT);
var timeout = (ccpIframeRefreshInterval + retryDelay) * timeoutFactor;
// ccpIframeRefreshInterval is the ccpLoadTimeout passed into initCCP
// if no ccpLoadTimeout is passed in, the interval is the default, which depends on if disaster recovery is on
var ccpIframeRefreshInterval = (initCCPParams.ccpLoadTimeout) ? (initCCPParams.ccpLoadTimeout)
: (initCCPParams.disasterRecoveryOn) ? CCP_DR_IFRAME_REFRESH_INTERVAL
: CCP_IFRAME_REFRESH_INTERVAL;
global.clearTimeout(connect.core.iframeRefreshTimeout);
connect.core.iframeRefreshTimeout = global.setTimeout(function() {
connect.core.iframeRefreshAttempt = (connect.core.iframeRefreshAttempt || 0) + 1;
Expand All @@ -1484,7 +1485,7 @@
connect.core.getEventBus().trigger(connect.EventType.IFRAME_RETRIES_EXHAUSTED);
global.clearTimeout(connect.core.iframeRefreshTimeout);
}
}, timeout);
}, ccpIframeRefreshInterval);
}


Expand Down
16 changes: 8 additions & 8 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1975,15 +1975,15 @@ declare namespace connect {

/** Returns true if agent's monitoringCapabilities contain MonitoringMode.BARGE state type. */
isBargeEnabled(): boolean;
/** Returns the array of enabled monitor states of this connection. The array will consist of MonitoringMode enum values. */
getMonitorCapabilities(): MonitoringMode[];

/** Returns the array of enabled monitor states of this connection or undefined, if connection doesn't have enabled monitor states. The array will consist of MonitoringMode enum values. */
getMonitorCapabilities(): MonitoringMode[] | undefined;

/**
* Returns the current monitoring state of this connection.
* This value can be one of MonitoringMode enum values if the agent is supervisor, otherwise the monitorStatus will be undefined for the agent.
*/
getMonitorStatus(): MonitoringMode;
* Returns the current monitoring state of this connection.
* This value can be one of MonitoringMode enum values if the agent is supervisor, otherwise the monitorStatus will be null for the agent.
*/
getMonitorStatus(): MonitoringMode | null;

/** Returns true if the connection was forced muted by the manager. */
isForcedMute(): boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/mediaControllers/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
logger.info(logComponent, 'Destroying mediaController for %s', connectionId);
toBeDestroyed.add(connectionId);
mediaControllers[connectionId]
.then(function () {
.then(function (controller) {
if (typeof controller.cleanUp === 'function') controller.cleanUp();
delete mediaControllers[connectionId];
toBeDestroyed.delete(connectionId);
Expand Down
2 changes: 2 additions & 0 deletions src/request-storage-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
storageParams = {};
originalCCPUrl = '';
rsaContainer = null;
onGrantCallbackInvoked = false;
};

/**
Expand Down Expand Up @@ -347,6 +348,7 @@
getRequestStorageAccessUrl,
storageAccessEvents,
resetStorageAccessState,
getOnGrantCallbackInvoked: () => onGrantCallbackInvoked,
getStorageAccessParams: () => storageParams,
onRequest: onRequestHandler,
request: () => {
Expand Down
Loading

0 comments on commit 97983f1

Please sign in to comment.