in source/web_site/js/connectCCP.js [20454:20564]
connect.core.initCCP = function(containerDiv, paramsIn) {
connect.core.checkNotInitialized();
if (connect.core.initialized) {
return;
}
// For backwards compatibility, when instead of taking a params object
// as input we only accepted ccpUrl.
var params = {};
if (typeof(paramsIn) === 'string') {
params.ccpUrl = paramsIn;
} else {
params = paramsIn;
}
var softphoneParams = params.softphone || null;
connect.assertNotNull(containerDiv, 'containerDiv');
connect.assertNotNull(params.ccpUrl, 'params.ccpUrl');
// Create the CCP iframe and append it to the container div.
var iframe = document.createElement('iframe');
iframe.src = params.ccpUrl;
iframe.allow = "microphone";
iframe.style = "width: 100%; height: 100%";
containerDiv.appendChild(iframe);
// Initialize the event bus and agent data providers.
// NOTE: Setting logEvents here to FALSE in order to avoid duplicating
// events which are logged in CCP.
connect.core.eventBus = new connect.EventBus({logEvents: false});
connect.core.agentDataProvider = new AgentDataProvider(connect.core.getEventBus());
// Build the upstream conduit communicating with the CCP iframe.
var conduit = new connect.IFrameConduit(params.ccpUrl, window, iframe);
// Set the global upstream conduit for external use.
connect.core.upstream = conduit;
conduit.onAllUpstream(connect.core.getEventBus().bridge());
// Initialize the keepalive manager.
connect.core.keepaliveManager = new KeepaliveManager(conduit,
connect.core.getEventBus(),
params.ccpSynTimeout || CCP_SYN_TIMEOUT,
params.ccpAckTimeout || CCP_ACK_TIMEOUT);
connect.core.iframeRefreshInterval = null;
// Allow 10 sec (default) before receiving the first ACK from the CCP.
connect.core.ccpLoadTimeoutInstance = global.setTimeout(function() {
connect.core.ccpLoadTimeoutInstance = null;
connect.core.getEventBus().trigger(connect.EventType.ACK_TIMEOUT);
}, params.ccpLoadTimeout || CCP_LOAD_TIMEOUT);
// Once we receive the first ACK, setup our upstream API client and establish
// the SYN/ACK refresh flow.
conduit.onUpstream(connect.EventType.ACKNOWLEDGE, function() {
connect.getLog().info("Acknowledged by the CCP!");
connect.core.client = new connect.UpstreamConduitClient(conduit);
connect.core.masterClient = new connect.UpstreamConduitMasterClient(conduit);
connect.core.initialized = true;
if (softphoneParams) {
// Send configuration up to the CCP.
conduit.sendUpstream(connect.EventType.CONFIGURE, {
softphone: softphoneParams
});
}
if (connect.core.ccpLoadTimeoutInstance) {
global.clearTimeout(connect.core.ccpLoadTimeoutInstance);
connect.core.ccpLoadTimeoutInstance = null;
}
connect.core.keepaliveManager.start();
this.unsubscribe();
});
// Add any logs from the upstream to our own logger.
conduit.onUpstream(connect.EventType.LOG, function(logEntry) {
connect.getLog().addLogEntry(connect.LogEntry.fromObject(logEntry));
});
// Pop a login page when we encounter an ACK timeout.
connect.core.getEventBus().subscribe(connect.EventType.ACK_TIMEOUT, function() {
// loginPopup is true by default, only false if explicitly set to false.
if (params.loginPopup !== false) {
try {
var loginUrl = createLoginUrl(params);
connect.getLog().warn("ACK_TIMEOUT occurred, attempting to pop the login page if not already open.");
connect.core.getPopupManager().open(loginUrl, connect.MasterTopics.LOGIN_POPUP);
} catch (e) {
connect.getLog().error("ACK_TIMEOUT occurred but we are unable to open the login popup.").withException(e);
}
}
if (connect.core.iframeRefreshInterval == null) {
connect.core.iframeRefreshInterval = window.setInterval(function() {
iframe.src = params.ccpUrl;
}, CCP_IFRAME_REFRESH_INTERVAL);
conduit.onUpstream(connect.EventType.ACKNOWLEDGE, function() {
this.unsubscribe();
global.clearInterval(connect.core.iframeRefreshInterval);
connect.core.iframeRefreshInterval = null;
connect.core.getPopupManager().clear(connect.MasterTopics.LOGIN_POPUP);
});
}
});
};