Skip to content

Commit

Permalink
Address dinkzilla's PR comments
Browse files Browse the repository at this point in the history
Update Readme and rebuild release files
This commit restores original boolean values for `loginPopup` and
`loginPopupAutoClose`. The `loginOptions` param is added to give
the option to open login in new window instead of new tab.
  • Loading branch information
JayWelborn authored and h3adache committed Sep 15, 2020
1 parent 6133413 commit a170f25
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 60 deletions.
46 changes: 20 additions & 26 deletions Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ everything set up correctly and that you are able to listen for events.
// initialize the ccp
connect.core.initCCP(containerDiv, {
ccpUrl: instanceURL, // REQUIRED
loginPopup: { // optional, default TRUE
autoClose: ture, // optional, default FALSE
forceWindow: true, // optional, default FALSE
height: 600, // optional
width: 400, // optional
top: 0, // optional, centered by default
left: 0 // optional, centered by default
loginPopup: true, // optional, defaults to `true`
loginOptions: { // optional, if provided opens login in new window
autoClose: true, // optional, defaults to `false`
height: 600, // optional, defaults to 578
width: 400, // optional, defaults to 433
top: 0, // optional, defaults to 0
left: 0 // optional, defaults to 0
},
region: "eu-central-1", // REQUIRED for `CHAT`, optional otherwise
softphone: { // optional
Expand All @@ -168,27 +168,21 @@ and made available to your JS client code.
in order to use the CCP in a standalone page, it is different for each
instance.
* `region`: Amazon connect instance region. ex: `us-west-2`. only required for chat channel.
* `loginPopup`: Optional. Set to `false` to disable the login popup which is
shown when the user's authentication expires. Provide an object with the
following options to provide settings for this window:
* `loginPopup`: Optional, defaults to `true`. Set to `false` to disable the login popup
which is shown when the user's authentication expires.
* `loginOptions`: Optional, only valid when `loginPopup` is set to `true`.
Provide an object with the following properties to open loginpopup in a new window instead of a
new tab.
* `autoClose`: Optional, defaults to `false`. Set to `true` to automatically
close the login popup after the user logs in.
* `forceWindow`: Optional, defaults to `false`. Set to `true` to force the
login popup to open in a centered pop-up window. When `false`, the popup
will behave according to the user's browser settings, which often defaults
to opening in a new tab.
* `height`: Optional, only valid when `forceWindow` is set to `true`. This
allows you to define the height of the login pop-up window if you do not
like the default.
* `width`: Optional, only valid when `forceWindow` is set to `true`. This
allows you to define the width of the login pop-up window if you do not
like the default.
* `top`: Optional, only valid when `forceWindow` is set to `true`. This
allows you to define the top of the login pop-up window if you do not
like the default.
* `left`: Optional, only valid when `forceWindow` is set to `true`. This
allows you to define the left of the login pop-up window if you do not
like the default.
* `height`: This allows you to define the height of the login pop-up window.
* `width`: This allows you to define the width of the login pop-up window.
* `top`: This allows you to define the top of the login pop-up window.
* `left`: This allows you to define the left of the login pop-up window.
* `loginPopupAutoClose`: Optional, defaults to `false`. Set to `true` in conjunction with the
`loginPopup` parameter to automatically close the login Popup window once the authentication step
has completed. If the login page opened in a new tab, this parameter will also auto-close that
tab. This can also be set in `loginOptions` if those options are used.
* `loginUrl`: Optional. Allows custom URL to be used to initiate the ccp, as in
the case of SAML authentication.
* `softphone`: This object is optional and allows you to specify some settings
Expand Down
27 changes: 22 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ everything setup correctly and that you will be able to listen for events.
connect.core.initCCP(containerDiv, {
ccpUrl: instanceURL, // REQUIRED
loginPopup: true, // optional, defaults to `true`
loginOptions: { // optional, if provided opens login in new window
autoClose: true, // optional, defaults to `false`
height: 600, // optional, defaults to 578
width: 400, // optional, defaults to 433
top: 0, // optional, defaults to 0
left: 0 // optional, defaults to 0
},
region: "eu-central-1", // REQUIRED for `CHAT`, optional otherwise
softphone: { // optional
allowFramedSoftphone: true, // optional
Expand All @@ -163,11 +170,21 @@ and made available to your JS client code.
in order to use the CCP in a standalone page, it is different for each
instance.
* `region`: Amazon connect instance region. ex: `us-west-2`. only required for chat channel.
* `loginPopup`: Optional, defaults to `true`. Set to `false` to disable the login
popup which is shown when the user's authentication expires.
* `loginPopupAutoClose`: Optional, defaults to `false`. Set to `true` in conjunction with the `loginPopup` parameter
to automatically close the login Popup window once the authentication step has completed.
If the login page opened in a new tab, this parameter will also auto-close that tab.
* `loginPopup`: Optional, defaults to `true`. Set to `false` to disable the login popup
which is shown when the user's authentication expires.
* `loginOptions`: Optional, only valid when `loginPopup` is set to `true`.
Provide an object with the following properties to open loginpopup in a new window instead of a
new tab.
* `autoClose`: Optional, defaults to `false`. Set to `true` to automatically
close the login popup after the user logs in.
* `height`: This allows you to define the height of the login pop-up window.
* `width`: This allows you to define the width of the login pop-up window.
* `top`: This allows you to define the top of the login pop-up window.
* `left`: This allows you to define the left of the login pop-up window.
* `loginPopupAutoClose`: Optional, defaults to `false`. Set to `true` in conjunction with the
`loginPopup` parameter to automatically close the login Popup window once the authentication step
has completed. If the login page opened in a new tab, this parameter will also auto-close that
tab. This can also be set in `loginOptions` if those options are used.
* `loginUrl`: Optional. Allows custom URL to be used to initiate the ccp, as in
the case of SAML authentication.
* `softphone`: This object is optional and allows you to specify some settings
Expand Down
2 changes: 1 addition & 1 deletion release/connect-streams-min.js

Large diffs are not rendered by default.

35 changes: 25 additions & 10 deletions release/connect-streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -21666,6 +21666,8 @@

var userAgent = navigator.userAgent;
var ONE_DAY_MILLIS = 24 * 60 * 60 * 1000;
var DEFAULT_POPUP_HEIGHT = 578;
var DEFAULT_POPUP_WIDTH = 433;

/**
* Unpollute sprintf functions from the global namespace.
Expand Down Expand Up @@ -22061,19 +22063,32 @@
*/
connect.PopupManager = function () { };

connect.PopupManager.prototype.open = function(url, name) {
connect.PopupManager.prototype.open = function (url, name, options) {
var then = this._getLastOpenedTimestamp(name);
var now = new Date().getTime();
var win = null;
var win = null;
if (now - then > ONE_DAY_MILLIS) {
win = window.open('', name);
if (win.location !== url) {
if (options) {
// default values are chosen to provide a minimum height without scrolling
// and a uniform margin based on the css of the ccp login page
var height = options.height || DEFAULT_POPUP_HEIGHT;
var width = options.width || DEFAULT_POPUP_WIDTH;
var top = options.top || 0;
var left = options.left || 0;
win = window.open('', name, "width="+width+", height="+height+", top="+top+", left="+left);
if (win.location !== url) {
win = window.open(url, name, "width="+width+", height="+height+", top="+top+", left="+left);
}
} else {
win = window.open('', name);
if (win.location !== url) {
win = window.open(url, name);
}
this._setLastOpenedTimestamp(name, now);
}
}
this._setLastOpenedTimestamp(name, now);
}
return win;
};
};

connect.PopupManager.prototype.clear = function (name) {
var key = this._getLocalStorageKey(name);
Expand Down Expand Up @@ -25059,8 +25074,7 @@
if (params.loginUrl) {
connect.core.getPopupManager().clear(connect.MasterTopics.LOGIN_POPUP);
}
connect.core.loginWindow = connect.core.getPopupManager().open(loginUrl, connect.MasterTopics.LOGIN_POPUP);

connect.core.loginWindow = connect.core.getPopupManager().open(loginUrl, connect.MasterTopics.LOGIN_POPUP, params.loginOptions);
} catch (e) {
connect.getLog().error("ACK_TIMEOUT occurred but we are unable to open the login popup.").withException(e);
}
Expand All @@ -25076,7 +25090,8 @@
global.clearInterval(connect.core.iframeRefreshInterval);
connect.core.iframeRefreshInterval = null;
connect.core.getPopupManager().clear(connect.MasterTopics.LOGIN_POPUP);
if (params.loginPopupAutoClose && connect.core.loginWindow) {
if ((params.loginPopupAutoClose || (params.loginOptions && params.loginOptions.autoClose)) &&
connect.core.loginWindow) {
connect.core.loginWindow.close();
connect.core.loginWindow = null;
}
Expand Down
6 changes: 3 additions & 3 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,7 @@
if (params.loginUrl) {
connect.core.getPopupManager().clear(connect.MasterTopics.LOGIN_POPUP);
}
var options = params.loginPopup && params.loginPopup.forceWindow ? params.loginPopup : {}
connect.core.loginWindow = connect.core.getPopupManager().open(loginUrl, connect.MasterTopics.LOGIN_POPUP, options);
connect.core.loginWindow = connect.core.getPopupManager().open(loginUrl, connect.MasterTopics.LOGIN_POPUP, params.loginOptions);
} catch (e) {
connect.getLog().error("ACK_TIMEOUT occurred but we are unable to open the login popup.").withException(e);
}
Expand All @@ -541,7 +540,8 @@
global.clearInterval(connect.core.iframeRefreshInterval);
connect.core.iframeRefreshInterval = null;
connect.core.getPopupManager().clear(connect.MasterTopics.LOGIN_POPUP);
if (params.loginPopup && params.loginPopup.autoClose && connect.core.loginWindow) {
if ((params.loginPopupAutoClose || (params.loginOptions && params.loginOptions.autoClose)) &&
connect.core.loginWindow) {
connect.core.loginWindow.close();
connect.core.loginWindow = null;
}
Expand Down
20 changes: 15 additions & 5 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,6 @@ declare namespace connect {
* Whether to auto close the login prompt.
*/
autoClose?: boolean,
/*
* Whether to force to login prompt into a new window.
*/
forceWindow?: boolean,
/*
* The height of the login prompt window.
*/
Expand Down Expand Up @@ -200,7 +196,21 @@ declare namespace connect {
* Set to `false` to disable the login popup which is shown when the user's authentication expires.
* @default true
*/
loginPopup?: boolean | LoginOptions;
readonly loginPopup?: boolean;

/**
* Options to open login popup in a new window instead of a new tab. If loginPopup is set to
* `false`, these options will be ignored.
*/
readonly loginOptions?: LoginOptions;

/**
* Set to `true` in conjunction with the `loginPopup` parameter to automatically close the login
* Popup window once the authentication step has completed. If the login page opened in a new
* tab, this parameter will also auto-close that tab.
* @default false
*/
readonly loginPopupAutoClose?: boolean;

/** Allows custom URL to be used to initiate the ccp, as in the case of SAML authentication. */
readonly loginUrl?: string;
Expand Down
1 change: 0 additions & 1 deletion src/lib/amazon-connect-websocket-manager.js

Large diffs are not rendered by default.

20 changes: 11 additions & 9 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

var userAgent = navigator.userAgent;
var ONE_DAY_MILLIS = 24 * 60 * 60 * 1000;
var DEFAULT_POPUP_HEIGHT = 578;
var DEFAULT_POPUP_WIDTH = 433;

/**
* Unpollute sprintf functions from the global namespace.
Expand Down Expand Up @@ -411,16 +413,16 @@
var now = new Date().getTime();
var win = null;
if (now - then > ONE_DAY_MILLIS) {
if (options && options.forceWindow === true) {
// default values below are chosen to provide a minimum height without scrolling
// and a unform margin based on the css of the ccp login page
var height = options.height ? options.height : 578;
var width = options.width ? options.width : 433;
var y = isNaN(options.top) ? window.top.outerHeight / 2 + window.top.screenY - (height / 2) : options.top;
var x = isNaN(options.left) ? window.top.outerWidth / 2 + window.top.screenX - (width / 2) : options.left;
win = window.open('', name, "width="+width+", height="+height+", top="+y+", left="+x);
if (options) {
// default values are chosen to provide a minimum height without scrolling
// and a uniform margin based on the css of the ccp login page
var height = options.height || DEFAULT_POPUP_HEIGHT;
var width = options.width || DEFAULT_POPUP_WIDTH;
var top = options.top || 0;
var left = options.left || 0;
win = window.open('', name, "width="+width+", height="+height+", top="+top+", left="+left);
if (win.location !== url) {
win = window.open(url, name, "width="+width+", height="+height+", top="+y+", left="+x);
win = window.open(url, name, "width="+width+", height="+height+", top="+top+", left="+left);
}
} else {
win = window.open('', name);
Expand Down

0 comments on commit a170f25

Please sign in to comment.