@microsoft/omnichannel-chat-widget 0.1.0-main.c461296 → 0.1.0-main.c9a643a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -11
- package/lib/cjs/common/Constants.js +50 -6
- package/lib/cjs/common/telemetry/TelemetryConstants.js +42 -3
- package/lib/cjs/common/telemetry/TelemetryHelper.js +13 -0
- package/lib/cjs/common/telemetry/TelemetryManager.js +16 -5
- package/lib/cjs/common/telemetry/defaultConfigs/defaultAriaConfig.js +1 -1
- package/lib/cjs/common/telemetry/defaultConfigs/defaultTelemetryConfiguration.js +4 -1
- package/lib/cjs/common/telemetry/loggers/ariaTelemetryLogger.js +33 -13
- package/lib/cjs/common/telemetry/loggers/consoleLogger.js +6 -5
- package/lib/cjs/common/utils.js +89 -2
- package/lib/cjs/components/callingcontainerstateful/CallingContainerStateful.js +14 -0
- package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +20 -4
- package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +4 -40
- package/lib/cjs/components/footerstateful/FooterStateful.js +1 -2
- package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +11 -2
- package/lib/cjs/components/headerstateful/HeaderStateful.js +5 -10
- package/lib/cjs/components/livechatwidget/common/ActivityStreamHandler.js +44 -0
- package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +23 -0
- package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.js +1 -0
- package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +39 -0
- package/lib/cjs/components/livechatwidget/common/ChatAdapterShim.js +70 -0
- package/lib/cjs/components/livechatwidget/common/Deferred.js +42 -0
- package/lib/cjs/components/livechatwidget/common/authHelper.js +65 -0
- package/lib/cjs/components/livechatwidget/common/createAdapter.js +13 -1
- package/lib/cjs/components/livechatwidget/common/createInternetConnectionChangeHandler.js +12 -0
- package/lib/cjs/components/livechatwidget/common/createMarkdown.js +31 -30
- package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +19 -17
- package/lib/cjs/components/livechatwidget/common/endChat.js +93 -10
- package/lib/cjs/components/livechatwidget/common/initCallingSdk.js +1 -1
- package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +27 -3
- package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +144 -39
- package/lib/cjs/components/livechatwidget/common/registerTelemetryLoggers.js +6 -17
- package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
- package/lib/cjs/components/livechatwidget/common/shareObservable.js +45 -0
- package/lib/cjs/components/livechatwidget/common/startChat.js +166 -50
- package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +284 -71
- package/lib/cjs/components/postchatloadingpanestateful/PostChatLoadingPaneStateful.js +8 -0
- package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +5 -10
- package/lib/cjs/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +17 -1
- package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +91 -0
- package/lib/cjs/components/webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps.js +4 -1
- package/lib/cjs/components/webchatcontainerstateful/common/defaultStyles/defaultAdaptiveCardStyles.js +11 -0
- package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +2 -0
- package/lib/cjs/components/webchatcontainerstateful/interfaces/IAdaptiveCardStyles.js +1 -0
- package/lib/cjs/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +14 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +16 -2
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.js +2 -1
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +52 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +98 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.js +117 -0
- package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.js +45 -0
- package/lib/cjs/contexts/common/ConversationState.js +3 -2
- package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +10 -7
- package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +4 -2
- package/lib/cjs/contexts/createReducer.js +24 -10
- package/lib/cjs/controller/componentController.js +3 -3
- package/lib/cjs/plugins/newMessageEventHandler.js +10 -13
- package/lib/esm/common/Constants.js +46 -5
- package/lib/esm/common/telemetry/TelemetryConstants.js +42 -3
- package/lib/esm/common/telemetry/TelemetryHelper.js +13 -1
- package/lib/esm/common/telemetry/TelemetryManager.js +14 -5
- package/lib/esm/common/telemetry/defaultConfigs/defaultAriaConfig.js +1 -1
- package/lib/esm/common/telemetry/defaultConfigs/defaultTelemetryConfiguration.js +4 -1
- package/lib/esm/common/telemetry/loggers/ariaTelemetryLogger.js +36 -14
- package/lib/esm/common/telemetry/loggers/consoleLogger.js +6 -5
- package/lib/esm/common/utils.js +64 -1
- package/lib/esm/components/callingcontainerstateful/CallingContainerStateful.js +14 -0
- package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +22 -7
- package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +7 -38
- package/lib/esm/components/footerstateful/FooterStateful.js +1 -2
- package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +9 -3
- package/lib/esm/components/headerstateful/HeaderStateful.js +5 -10
- package/lib/esm/components/livechatwidget/common/ActivityStreamHandler.js +34 -0
- package/lib/esm/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +14 -0
- package/lib/esm/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.js +1 -0
- package/lib/esm/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +29 -0
- package/lib/esm/components/livechatwidget/common/ChatAdapterShim.js +59 -0
- package/lib/esm/components/livechatwidget/common/Deferred.js +33 -0
- package/lib/esm/components/livechatwidget/common/authHelper.js +50 -0
- package/lib/esm/components/livechatwidget/common/createAdapter.js +12 -2
- package/lib/esm/components/livechatwidget/common/createInternetConnectionChangeHandler.js +8 -0
- package/lib/esm/components/livechatwidget/common/createMarkdown.js +31 -30
- package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +19 -18
- package/lib/esm/components/livechatwidget/common/endChat.js +89 -11
- package/lib/esm/components/livechatwidget/common/initCallingSdk.js +1 -1
- package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +25 -5
- package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +134 -41
- package/lib/esm/components/livechatwidget/common/registerTelemetryLoggers.js +5 -14
- package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
- package/lib/esm/components/livechatwidget/common/shareObservable.js +38 -0
- package/lib/esm/components/livechatwidget/common/startChat.js +161 -53
- package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +272 -76
- package/lib/esm/components/postchatloadingpanestateful/PostChatLoadingPaneStateful.js +6 -0
- package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +7 -11
- package/lib/esm/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +17 -1
- package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +82 -0
- package/lib/esm/components/webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps.js +3 -1
- package/lib/esm/components/webchatcontainerstateful/common/defaultStyles/defaultAdaptiveCardStyles.js +4 -0
- package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +2 -0
- package/lib/esm/components/webchatcontainerstateful/interfaces/IAdaptiveCardStyles.js +1 -0
- package/lib/esm/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +5 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +16 -2
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.js +2 -1
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +41 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +94 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.js +107 -0
- package/lib/esm/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.js +32 -0
- package/lib/esm/contexts/common/ConversationState.js +3 -2
- package/lib/esm/contexts/common/LiveChatWidgetActionType.js +10 -7
- package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +4 -2
- package/lib/esm/contexts/createReducer.js +24 -9
- package/lib/esm/controller/componentController.js +3 -3
- package/lib/esm/plugins/newMessageEventHandler.js +10 -12
- package/lib/types/common/Constants.d.ts +25 -2
- package/lib/types/common/interfaces/IContextDataStore.d.ts +2 -2
- package/lib/types/common/telemetry/TelemetryConstants.d.ts +34 -5
- package/lib/types/common/telemetry/TelemetryHelper.d.ts +2 -0
- package/lib/types/common/telemetry/definitions/Payload.d.ts +12 -9
- package/lib/types/common/telemetry/interfaces/ITelemetryConfig.d.ts +3 -3
- package/lib/types/common/utils.d.ts +8 -1
- package/lib/types/components/confirmationpanestateful/interfaces/IConfirmationPaneStatefulParams.d.ts +4 -4
- package/lib/types/components/footerstateful/audionotificationstateful/interfaces/IAudioNotificationStatefulParams.d.ts +0 -1
- package/lib/types/components/headerstateful/interfaces/IHeaderStatefulParams.d.ts +2 -1
- package/lib/types/components/livechatwidget/common/ActivityStreamHandler.d.ts +14 -0
- package/lib/types/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.d.ts +5 -0
- package/lib/types/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.d.ts +6 -0
- package/lib/types/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.d.ts +7 -0
- package/lib/types/components/livechatwidget/common/ChatAdapterShim.d.ts +7 -0
- package/lib/types/components/livechatwidget/common/Deferred.d.ts +9 -0
- package/lib/types/components/livechatwidget/common/authHelper.d.ts +5 -0
- package/lib/types/components/livechatwidget/common/endChat.d.ts +4 -1
- package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +6 -2
- package/lib/types/components/livechatwidget/common/shareObservable.d.ts +1 -0
- package/lib/types/components/livechatwidget/common/startChat.d.ts +4 -2
- package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetComponentOverrides.d.ts +1 -0
- package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetControlProps.d.ts +1 -0
- package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +2 -1
- package/lib/types/components/reconnectchatpanestateful/interfaces/IReconnectChatPaneStatefulProps.d.ts +1 -1
- package/lib/types/components/webchatcontainerstateful/common/defaultStyles/defaultAdaptiveCardStyles.d.ts +2 -0
- package/lib/types/components/webchatcontainerstateful/common/mockchatsdk.d.ts +1 -0
- package/lib/types/components/webchatcontainerstateful/interfaces/IAdaptiveCardStyles.d.ts +4 -0
- package/lib/types/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.d.ts +4 -0
- package/lib/types/components/webchatcontainerstateful/interfaces/IWebChatContainerStatefulProps.d.ts +4 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.d.ts +3 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.d.ts +1 -1
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.d.ts +2 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.d.ts +1 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.d.ts +5 -0
- package/lib/types/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.d.ts +1 -0
- package/lib/types/contexts/common/ConversationState.d.ts +3 -2
- package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +3 -1
- package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +11 -8
- package/package.json +8 -8
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
function _extends() { _extends = Object.assign
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
2
|
|
|
3
3
|
import { BroadcastEvent, LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
|
|
4
|
-
import { BroadcastService, decodeComponentString } from "@microsoft/omnichannel-chat-components";
|
|
4
|
+
import { BroadcastService, decodeComponentString, BroadcastServiceInitialize } from "@microsoft/omnichannel-chat-components";
|
|
5
5
|
import { Stack } from "@fluentui/react";
|
|
6
6
|
import React, { useEffect, useRef, useState } from "react";
|
|
7
|
-
import { createTimer, getLocaleDirection } from "../../../common/utils";
|
|
8
|
-
import { getReconnectIdForAuthenticatedChat, handleUnauthenticatedReconnectChat } from "../common/reconnectChatHelper";
|
|
9
|
-
import { initStartChat, prepareStartChat } from "../common/startChat";
|
|
7
|
+
import { createTimer, getBroadcastChannelName, getLocaleDirection, getStateFromCache, getWidgetCacheId, getWidgetEndChatEventName, isNullOrEmptyString, isUndefinedOrEmpty } from "../../../common/utils";
|
|
8
|
+
import { getReconnectIdForAuthenticatedChat, handleUnauthenticatedReconnectChat, startUnauthenticatedReconnectChat } from "../common/reconnectChatHelper";
|
|
9
|
+
import { initStartChat, prepareStartChat, setPreChatAndInitiateChat } from "../common/startChat";
|
|
10
10
|
import { shouldShowCallingContainer, shouldShowChatButton, shouldShowConfirmationPane, shouldShowEmailTranscriptPane, shouldShowHeader, shouldShowLoadingPane, shouldShowOutOfOfficeHoursPane, shouldShowPostChatLoadingPane, shouldShowPostChatSurveyPane, shouldShowPreChatSurveyPane, shouldShowProactiveChatPane, shouldShowReconnectChatPane, shouldShowWebChatContainer } from "../../../controller/componentController";
|
|
11
11
|
import CallingContainerStateful from "../../callingcontainerstateful/CallingContainerStateful";
|
|
12
12
|
import ChatButtonStateful from "../../chatbuttonstateful/ChatButtonStateful";
|
|
@@ -32,7 +32,7 @@ import { createFooter } from "../common/createFooter";
|
|
|
32
32
|
import { createInternetConnectionChangeHandler } from "../common/createInternetConnectionChangeHandler";
|
|
33
33
|
import { defaultWebChatContainerStatefulProps } from "../../webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps";
|
|
34
34
|
import { disposeTelemetryLoggers } from "../common/disposeTelemetryLoggers";
|
|
35
|
-
import { endChat } from "../common/endChat";
|
|
35
|
+
import { endChat, prepareEndChat } from "../common/endChat";
|
|
36
36
|
import { getGeneralStylesForButton } from "../common/getGeneralStylesForButton";
|
|
37
37
|
import { initCallingSdk } from "../common/initCallingSdk";
|
|
38
38
|
import { initConfirmationPropsComposer } from "../common/initConfirmationPropsComposer";
|
|
@@ -43,8 +43,10 @@ import { startProactiveChat } from "../common/startProactiveChat";
|
|
|
43
43
|
import useChatAdapterStore from "../../../hooks/useChatAdapterStore";
|
|
44
44
|
import useChatContextStore from "../../../hooks/useChatContextStore";
|
|
45
45
|
import useChatSDKStore from "../../../hooks/useChatSDKStore";
|
|
46
|
+
import { ActivityStreamHandler } from "../common/ActivityStreamHandler";
|
|
47
|
+
import { Constants } from "../../../common/Constants";
|
|
46
48
|
export const LiveChatWidgetStateful = props => {
|
|
47
|
-
var _props$webChatContain, _props$styleProps, _props$controlProps, _props$webChatContain3, _props$webChatContain4, _props$styleProps2, _props$
|
|
49
|
+
var _props$webChatContain, _props$styleProps, _chatSDK$omnichannelC, _props$controlProps, _props$controlProps2, _props$webChatContain3, _props$webChatContain4, _props$styleProps2, _props$controlProps14, _props$controlProps15, _props$componentOverr, _props$controlProps16, _props$componentOverr2, _props$controlProps17, _props$componentOverr3, _props$controlProps18, _props$componentOverr4, _props$controlProps19, _props$componentOverr5, _props$controlProps20, _props$componentOverr6, _props$controlProps21, _props$componentOverr7, _props$controlProps22, _props$controlProps23, _props$componentOverr8, _props$controlProps24, _props$componentOverr9, _props$controlProps25, _props$componentOverr10, _props$componentOverr11, _props$componentOverr12;
|
|
48
50
|
|
|
49
51
|
const [state, dispatch] = useChatContextStore(); // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
50
52
|
|
|
@@ -53,7 +55,8 @@ export const LiveChatWidgetStateful = props => {
|
|
|
53
55
|
...((_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : _props$webChatContain.webChatStyles)
|
|
54
56
|
}); // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
55
57
|
|
|
56
|
-
const chatSDK = useChatSDKStore();
|
|
58
|
+
const chatSDK = useChatSDKStore(); // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
59
|
+
|
|
57
60
|
const [voiceVideoCallingSDK, setVoiceVideoCallingSDK] = useState(undefined);
|
|
58
61
|
const {
|
|
59
62
|
Composer
|
|
@@ -63,11 +66,36 @@ export const LiveChatWidgetStateful = props => {
|
|
|
63
66
|
const generalStyles = {
|
|
64
67
|
root: Object.assign({}, getGeneralStylesForButton(state), (_props$styleProps = props.styleProps) === null || _props$styleProps === void 0 ? void 0 : _props$styleProps.generalStyles)
|
|
65
68
|
};
|
|
69
|
+
const broadcastServiceChannelName = getBroadcastChannelName(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC === void 0 ? void 0 : _chatSDK$omnichannelC.widgetId, ((_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.widgetInstanceId) ?? "");
|
|
70
|
+
BroadcastServiceInitialize(broadcastServiceChannelName);
|
|
66
71
|
TelemetryTimers.LcwLoadToChatButtonTimer = createTimer();
|
|
67
|
-
const widgetElementId = ((_props$
|
|
72
|
+
const widgetElementId = ((_props$controlProps2 = props.controlProps) === null || _props$controlProps2 === void 0 ? void 0 : _props$controlProps2.id) || "oc-lcw";
|
|
68
73
|
const currentMessageCountRef = useRef(0);
|
|
74
|
+
let widgetStateEventName = "";
|
|
75
|
+
|
|
76
|
+
const initiateEndChatOnBrowserUnload = () => {
|
|
77
|
+
var _DataStoreManager$cli;
|
|
78
|
+
|
|
79
|
+
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
80
|
+
Event: TelemetryEvent.BrowserUnloadEventStarted,
|
|
81
|
+
Description: "Browser unload event received."
|
|
82
|
+
});
|
|
83
|
+
endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, false); // Clean local storage
|
|
84
|
+
|
|
85
|
+
(_DataStoreManager$cli = DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.removeData(widgetStateEventName, "localStorage"); //Dispose calling instance
|
|
86
|
+
|
|
87
|
+
if (voiceVideoCallingSDK) {
|
|
88
|
+
voiceVideoCallingSDK === null || voiceVideoCallingSDK === void 0 ? void 0 : voiceVideoCallingSDK.close();
|
|
89
|
+
} //Message for clearing window[popouTab]
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
BroadcastService.postMessage({
|
|
93
|
+
eventName: BroadcastEvent.ClosePopoutWindow
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
|
|
69
97
|
useEffect(() => {
|
|
70
|
-
var _props$
|
|
98
|
+
var _props$controlProps3, _props$controlProps4, _props$controlProps5, _props$controlProps7, _props$chatConfig, _props$chatConfig$Cha, _props$controlProps8, _props$reconnectChatP, _props$chatConfig2, _props$chatConfig2$Li, _props$reconnectChatP4, _state$domainStates;
|
|
71
99
|
|
|
72
100
|
registerTelemetryLoggers(props, dispatch);
|
|
73
101
|
createInternetConnectionChangeHandler();
|
|
@@ -78,47 +106,92 @@ export const LiveChatWidgetStateful = props => {
|
|
|
78
106
|
});
|
|
79
107
|
dispatch({
|
|
80
108
|
type: LiveChatWidgetActionType.SET_SKIP_CHAT_BUTTON_RENDERING,
|
|
81
|
-
payload: ((_props$
|
|
109
|
+
payload: ((_props$controlProps3 = props.controlProps) === null || _props$controlProps3 === void 0 ? void 0 : _props$controlProps3.skipChatButtonRendering) || false
|
|
82
110
|
});
|
|
111
|
+
dispatch({
|
|
112
|
+
type: LiveChatWidgetActionType.SET_E2VV_ENABLED,
|
|
113
|
+
payload: false
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
if ((_props$controlProps4 = props.controlProps) !== null && _props$controlProps4 !== void 0 && _props$controlProps4.widgetInstanceId && !isNullOrEmptyString((_props$controlProps5 = props.controlProps) === null || _props$controlProps5 === void 0 ? void 0 : _props$controlProps5.widgetInstanceId)) {
|
|
117
|
+
var _props$controlProps6;
|
|
118
|
+
|
|
119
|
+
dispatch({
|
|
120
|
+
type: LiveChatWidgetActionType.SET_WIDGET_INSTANCE_ID,
|
|
121
|
+
payload: (_props$controlProps6 = props.controlProps) === null || _props$controlProps6 === void 0 ? void 0 : _props$controlProps6.widgetInstanceId
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
83
125
|
initCallingSdk(chatSDK, setVoiceVideoCallingSDK).then(sdkCreated => {
|
|
84
126
|
sdkCreated && dispatch({
|
|
85
127
|
type: LiveChatWidgetActionType.SET_E2VV_ENABLED,
|
|
86
128
|
payload: true
|
|
87
129
|
});
|
|
88
|
-
});
|
|
130
|
+
}); // Initialize global dir
|
|
89
131
|
|
|
90
|
-
|
|
91
|
-
var _props$reconnectChatP2;
|
|
92
|
-
|
|
93
|
-
handleUnauthenticatedReconnectChat(dispatch, (_props$reconnectChatP2 = props.reconnectChatPaneProps) === null || _props$reconnectChatP2 === void 0 ? void 0 : _props$reconnectChatP2.reconnectId, initStartChat);
|
|
94
|
-
} // Initialize global dir
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const globalDir = ((_props$controlProps4 = props.controlProps) === null || _props$controlProps4 === void 0 ? void 0 : _props$controlProps4.dir) ?? getLocaleDirection((_props$chatConfig = props.chatConfig) === null || _props$chatConfig === void 0 ? void 0 : (_props$chatConfig$Cha = _props$chatConfig.ChatWidgetLanguage) === null || _props$chatConfig$Cha === void 0 ? void 0 : _props$chatConfig$Cha.msdyn_localeid);
|
|
132
|
+
const globalDir = ((_props$controlProps7 = props.controlProps) === null || _props$controlProps7 === void 0 ? void 0 : _props$controlProps7.dir) ?? getLocaleDirection((_props$chatConfig = props.chatConfig) === null || _props$chatConfig === void 0 ? void 0 : (_props$chatConfig$Cha = _props$chatConfig.ChatWidgetLanguage) === null || _props$chatConfig$Cha === void 0 ? void 0 : _props$chatConfig$Cha.msdyn_localeid);
|
|
98
133
|
dispatch({
|
|
99
134
|
type: LiveChatWidgetActionType.SET_GLOBAL_DIR,
|
|
100
135
|
payload: globalDir
|
|
101
136
|
});
|
|
102
137
|
|
|
103
|
-
if ((
|
|
138
|
+
if (!((_props$controlProps8 = props.controlProps) !== null && _props$controlProps8 !== void 0 && _props$controlProps8.skipChatButtonRendering) && (_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.reconnectId) {
|
|
139
|
+
var _props$reconnectChatP2, _props$reconnectChatP3;
|
|
140
|
+
|
|
141
|
+
startUnauthenticatedReconnectChat(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, (_props$reconnectChatP2 = props.reconnectChatPaneProps) === null || _props$reconnectChatP2 === void 0 ? void 0 : _props$reconnectChatP2.isReconnectEnabled, (_props$reconnectChatP3 = props.reconnectChatPaneProps) === null || _props$reconnectChatP3 === void 0 ? void 0 : _props$reconnectChatP3.reconnectId, initStartChat);
|
|
142
|
+
return;
|
|
143
|
+
} // Checks if reconnectId is present for auth chat. If it is present, then it shows reconnect chat pane,
|
|
144
|
+
// where customer can choose to continue previous conversation or start new conversation
|
|
145
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
const isAuthenticationSettingsEnabled = (_props$chatConfig2 = props.chatConfig) !== null && _props$chatConfig2 !== void 0 && (_props$chatConfig2$Li = _props$chatConfig2.LiveChatConfigAuthSettings) !== null && _props$chatConfig2$Li !== void 0 && _props$chatConfig2$Li.msdyn_javascriptclientfunction ? true : false;
|
|
149
|
+
|
|
150
|
+
if (!state.appStates.skipChatButtonRendering && state.appStates.conversationState === ConversationState.Active && isAuthenticationSettingsEnabled === true && (_props$reconnectChatP4 = props.reconnectChatPaneProps) !== null && _props$reconnectChatP4 !== void 0 && _props$reconnectChatP4.isReconnectEnabled) {
|
|
151
|
+
getReconnectIdForAuthenticatedChat(props, chatSDK).then(authReconnectId => {
|
|
152
|
+
if (authReconnectId && !state.appStates.reconnectId) {
|
|
153
|
+
dispatch({
|
|
154
|
+
type: LiveChatWidgetActionType.SET_RECONNECT_ID,
|
|
155
|
+
payload: authReconnectId
|
|
156
|
+
});
|
|
157
|
+
dispatch({
|
|
158
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
159
|
+
payload: ConversationState.ReconnectChat
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (!state.appStates.skipChatButtonRendering && !isUndefinedOrEmpty((_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : _state$domainStates.liveChatContext) && state.appStates.conversationState === ConversationState.Active) {
|
|
104
167
|
var _state$domainStates2;
|
|
105
168
|
|
|
106
169
|
const optionalParams = {
|
|
107
|
-
liveChatContext:
|
|
108
|
-
chatToken: (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : _state$domainStates2.chatToken
|
|
109
|
-
}
|
|
170
|
+
liveChatContext: (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : _state$domainStates2.liveChatContext
|
|
110
171
|
};
|
|
111
|
-
initStartChat(chatSDK, dispatch, setAdapter, optionalParams);
|
|
112
|
-
|
|
113
|
-
|
|
172
|
+
initStartChat(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, optionalParams);
|
|
173
|
+
return;
|
|
174
|
+
} // All other case should show start chat button, skipChatButtonRendering will take care of it own
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
dispatch({
|
|
178
|
+
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
179
|
+
payload: ConversationState.Closed
|
|
180
|
+
});
|
|
181
|
+
}, []); // useEffect for when skip chat button rendering
|
|
182
|
+
|
|
114
183
|
useEffect(() => {
|
|
115
184
|
if (state.appStates.skipChatButtonRendering) {
|
|
116
|
-
var _props$
|
|
185
|
+
var _props$reconnectChatP5;
|
|
117
186
|
|
|
118
|
-
|
|
119
|
-
|
|
187
|
+
BroadcastService.postMessage({
|
|
188
|
+
eventName: BroadcastEvent.ChatInitiated
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
if ((_props$reconnectChatP5 = props.reconnectChatPaneProps) !== null && _props$reconnectChatP5 !== void 0 && _props$reconnectChatP5.reconnectId && !state.appStates.reconnectId) {
|
|
192
|
+
var _props$reconnectChatP6, _props$reconnectChatP7, _props$reconnectChatP8;
|
|
120
193
|
|
|
121
|
-
handleUnauthenticatedReconnectChat(dispatch, (_props$
|
|
194
|
+
handleUnauthenticatedReconnectChat(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, (_props$reconnectChatP6 = props.reconnectChatPaneProps) === null || _props$reconnectChatP6 === void 0 ? void 0 : _props$reconnectChatP6.isReconnectEnabled, (_props$reconnectChatP7 = props.reconnectChatPaneProps) === null || _props$reconnectChatP7 === void 0 ? void 0 : _props$reconnectChatP7.reconnectId, initStartChat, (_props$reconnectChatP8 = props.reconnectChatPaneProps) === null || _props$reconnectChatP8 === void 0 ? void 0 : _props$reconnectChatP8.redirectInSameWindow);
|
|
122
195
|
} else {
|
|
123
196
|
getReconnectIdForAuthenticatedChat(props, chatSDK).then(authReconnectId => {
|
|
124
197
|
if (authReconnectId && !state.appStates.reconnectId) {
|
|
@@ -131,24 +204,38 @@ export const LiveChatWidgetStateful = props => {
|
|
|
131
204
|
payload: ConversationState.ReconnectChat
|
|
132
205
|
});
|
|
133
206
|
} else {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
207
|
+
const chatStartedSkippingChatButtonRendering = {
|
|
208
|
+
eventName: BroadcastEvent.StartChatSkippingChatButtonRendering
|
|
209
|
+
};
|
|
210
|
+
BroadcastService.postMessage(chatStartedSkippingChatButtonRendering);
|
|
211
|
+
setPreChatAndInitiateChat(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter);
|
|
139
212
|
}
|
|
140
213
|
});
|
|
141
214
|
}
|
|
142
215
|
}
|
|
143
|
-
}, [state.appStates.skipChatButtonRendering]);
|
|
216
|
+
}, [state.appStates.skipChatButtonRendering]); // useEffect for when skip chat button rendering
|
|
217
|
+
|
|
144
218
|
useEffect(() => {
|
|
145
|
-
|
|
219
|
+
var _chatSDK$omnichannelC6, _chatSDK$omnichannelC7, _props$controlProps11;
|
|
220
|
+
|
|
221
|
+
// Add the custom context on receiving the SetCustomContext event
|
|
222
|
+
BroadcastService.getMessageByEventName(BroadcastEvent.SetCustomContext).subscribe(msg => {
|
|
223
|
+
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
224
|
+
Event: TelemetryEvent.CustomContextReceived,
|
|
225
|
+
Description: "CustomContext received."
|
|
226
|
+
});
|
|
227
|
+
dispatch({
|
|
228
|
+
type: LiveChatWidgetActionType.SET_CUSTOM_CONTEXT,
|
|
229
|
+
payload: msg === null || msg === void 0 ? void 0 : msg.payload
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
BroadcastService.getMessageByEventName(BroadcastEvent.StartProactiveChat).subscribe(msg => {
|
|
146
233
|
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
147
234
|
Event: TelemetryEvent.StartProactiveChatEventReceived,
|
|
148
235
|
Description: "Start proactive chat event received."
|
|
149
236
|
});
|
|
150
237
|
|
|
151
|
-
if (canStartProactiveChat.current) {
|
|
238
|
+
if (canStartProactiveChat.current === true) {
|
|
152
239
|
var _msg$payload, _msg$payload2, _msg$payload3;
|
|
153
240
|
|
|
154
241
|
startProactiveChat(dispatch, msg === null || msg === void 0 ? void 0 : (_msg$payload = msg.payload) === null || _msg$payload === void 0 ? void 0 : _msg$payload.notificationConfig, msg === null || msg === void 0 ? void 0 : (_msg$payload2 = msg.payload) === null || _msg$payload2 === void 0 ? void 0 : _msg$payload2.enablePreChat, msg === null || msg === void 0 ? void 0 : (_msg$payload3 = msg.payload) === null || _msg$payload3 === void 0 ? void 0 : _msg$payload3.inNewWindow);
|
|
@@ -158,39 +245,127 @@ export const LiveChatWidgetStateful = props => {
|
|
|
158
245
|
Description: "Start proactive chat method called, when chat was already triggered."
|
|
159
246
|
});
|
|
160
247
|
}
|
|
161
|
-
});
|
|
162
|
-
window.addEventListener("beforeunload", () => {
|
|
163
|
-
disposeTelemetryLoggers();
|
|
164
|
-
});
|
|
248
|
+
}); // Start chat from SDK Event
|
|
165
249
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}
|
|
169
|
-
}, []);
|
|
170
|
-
useEffect(() => {
|
|
171
|
-
canStartProactiveChat.current = state.appStates.conversationState === ConversationState.Closed;
|
|
250
|
+
BroadcastService.getMessageByEventName(BroadcastEvent.StartChat).subscribe(() => {
|
|
251
|
+
var _chatSDK$omnichannelC2, _chatSDK$omnichannelC3, _props$controlProps9;
|
|
172
252
|
|
|
173
|
-
|
|
174
|
-
|
|
253
|
+
TelemetryHelper.logActionEvent(LogLevel.INFO, {
|
|
254
|
+
Event: TelemetryEvent.StartChatEventRecevied,
|
|
255
|
+
Description: "Start chat event received."
|
|
256
|
+
});
|
|
257
|
+
const persistedState = getStateFromCache(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC2 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC2 === void 0 ? void 0 : _chatSDK$omnichannelC2.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC3 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC3 === void 0 ? void 0 : _chatSDK$omnichannelC3.widgetId, (props === null || props === void 0 ? void 0 : (_props$controlProps9 = props.controlProps) === null || _props$controlProps9 === void 0 ? void 0 : _props$controlProps9.widgetInstanceId) ?? ""); // Chat not found in cache
|
|
258
|
+
|
|
259
|
+
if (persistedState === undefined) {
|
|
175
260
|
BroadcastService.postMessage({
|
|
176
|
-
eventName: BroadcastEvent.
|
|
261
|
+
eventName: BroadcastEvent.ChatInitiated
|
|
177
262
|
});
|
|
263
|
+
prepareStartChat(props, chatSDK, state, dispatch, setAdapter);
|
|
264
|
+
return;
|
|
265
|
+
} // Chat exist in cache
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
if (persistedState) {
|
|
269
|
+
var _persistedState$domai, _persistedState$domai2, _persistedState$domai3, _persistedState$domai4;
|
|
270
|
+
|
|
271
|
+
// Only initiate new chat if widget state in cache in one of the followings
|
|
272
|
+
if (persistedState.appStates.conversationState === ConversationState.Closed || persistedState.appStates.conversationState === ConversationState.InActive || persistedState.appStates.conversationState === ConversationState.Postchat) {
|
|
273
|
+
BroadcastService.postMessage({
|
|
274
|
+
eventName: BroadcastEvent.ChatInitiated
|
|
275
|
+
});
|
|
276
|
+
prepareStartChat(props, chatSDK, state, dispatch, setAdapter);
|
|
277
|
+
return;
|
|
278
|
+
} // If minimized, maximize the chat
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
dispatch({
|
|
282
|
+
type: LiveChatWidgetActionType.SET_MINIMIZED,
|
|
283
|
+
payload: false
|
|
284
|
+
});
|
|
285
|
+
BroadcastService.postMessage({
|
|
286
|
+
eventName: BroadcastEvent.MaximizeChat,
|
|
287
|
+
payload: {
|
|
288
|
+
height: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai = persistedState.domainStates) === null || _persistedState$domai === void 0 ? void 0 : (_persistedState$domai2 = _persistedState$domai.widgetSize) === null || _persistedState$domai2 === void 0 ? void 0 : _persistedState$domai2.height,
|
|
289
|
+
width: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai3 = persistedState.domainStates) === null || _persistedState$domai3 === void 0 ? void 0 : (_persistedState$domai4 = _persistedState$domai3.widgetSize) === null || _persistedState$domai4 === void 0 ? void 0 : _persistedState$domai4.width
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
}); // End chat
|
|
294
|
+
|
|
295
|
+
BroadcastService.getMessageByEventName(BroadcastEvent.InitiateEndChat).subscribe(async () => {
|
|
296
|
+
if (state.appStates.skipChatButtonRendering !== true) {
|
|
297
|
+
var _chatSDK$omnichannelC4, _chatSDK$omnichannelC5, _props$controlProps10;
|
|
298
|
+
|
|
299
|
+
// This is to ensure to get latest state from cache in multitab
|
|
300
|
+
const persistedState = getStateFromCache(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC4 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC4 === void 0 ? void 0 : _chatSDK$omnichannelC4.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC5 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC5 === void 0 ? void 0 : _chatSDK$omnichannelC5.widgetId, (props === null || props === void 0 ? void 0 : (_props$controlProps10 = props.controlProps) === null || _props$controlProps10 === void 0 ? void 0 : _props$controlProps10.widgetInstanceId) ?? "");
|
|
301
|
+
|
|
302
|
+
if (persistedState && persistedState.appStates.conversationState === ConversationState.Active) {
|
|
303
|
+
prepareEndChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state);
|
|
304
|
+
} else {
|
|
305
|
+
const skipEndChatSDK = true;
|
|
306
|
+
const skipCloseChat = false;
|
|
307
|
+
endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
BroadcastService.postMessage({
|
|
312
|
+
eventName: BroadcastEvent.CloseChat
|
|
178
313
|
});
|
|
179
|
-
} //
|
|
314
|
+
}); // End chat on browser unload
|
|
315
|
+
|
|
316
|
+
BroadcastService.getMessageByEventName(BroadcastEvent.InitiateEndChatOnBrowserUnload).subscribe(() => {
|
|
317
|
+
initiateEndChatOnBrowserUnload();
|
|
318
|
+
}); // Listen to end chat event from other tabs
|
|
180
319
|
|
|
320
|
+
const endChatEventName = getWidgetEndChatEventName(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC6 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC6 === void 0 ? void 0 : _chatSDK$omnichannelC6.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC7 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC7 === void 0 ? void 0 : _chatSDK$omnichannelC7.widgetId, ((_props$controlProps11 = props.controlProps) === null || _props$controlProps11 === void 0 ? void 0 : _props$controlProps11.widgetInstanceId) ?? "");
|
|
321
|
+
BroadcastService.getMessageByEventName(endChatEventName).subscribe(async () => {
|
|
322
|
+
endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, false);
|
|
323
|
+
return;
|
|
324
|
+
}); // When conversation ended by agent
|
|
181
325
|
|
|
326
|
+
if (state.appStates.conversationEndedByAgent) {
|
|
327
|
+
endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter);
|
|
328
|
+
} //Listen to WidgetSize, used for minimize to maximize
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
BroadcastService.getMessageByEventName("WidgetSize").subscribe(msg => {
|
|
332
|
+
dispatch({
|
|
333
|
+
type: LiveChatWidgetActionType.SET_WIDGET_SIZE,
|
|
334
|
+
payload: msg === null || msg === void 0 ? void 0 : msg.payload
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
return () => {
|
|
338
|
+
disposeTelemetryLoggers();
|
|
339
|
+
};
|
|
340
|
+
}, []);
|
|
341
|
+
useEffect(() => {
|
|
342
|
+
// On new message
|
|
182
343
|
if (state.appStates.conversationState === ConversationState.Active) {
|
|
183
344
|
chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.onNewMessage(() => {
|
|
345
|
+
// Track the message count
|
|
184
346
|
currentMessageCountRef.current++;
|
|
185
347
|
dispatch({
|
|
186
348
|
type: LiveChatWidgetActionType.SET_UNREAD_MESSAGE_COUNT,
|
|
187
349
|
payload: currentMessageCountRef.current + 1
|
|
350
|
+
}); // New message notification
|
|
351
|
+
|
|
352
|
+
BroadcastService.postMessage({
|
|
353
|
+
eventName: BroadcastEvent.NewMessageNotification
|
|
188
354
|
});
|
|
189
355
|
});
|
|
190
356
|
}
|
|
191
|
-
}, [state.appStates.conversationState]);
|
|
357
|
+
}, [state.appStates.conversationState]);
|
|
358
|
+
useEffect(() => {
|
|
359
|
+
canStartProactiveChat.current = state.appStates.conversationState === ConversationState.Closed && !state.appStates.proactiveChatStates.proactiveChatInNewWindow;
|
|
360
|
+
}, [state.appStates.conversationState, state.appStates.proactiveChatStates.proactiveChatInNewWindow]); // Reset the UnreadMessageCount when minimized is toggled and broadcast it.
|
|
192
361
|
|
|
193
362
|
useEffect(() => {
|
|
363
|
+
if (state.appStates.isMinimized) {
|
|
364
|
+
ActivityStreamHandler.cork();
|
|
365
|
+
} else {
|
|
366
|
+
setTimeout(() => ActivityStreamHandler.uncork(), 500);
|
|
367
|
+
}
|
|
368
|
+
|
|
194
369
|
currentMessageCountRef.current = -1;
|
|
195
370
|
dispatch({
|
|
196
371
|
type: LiveChatWidgetActionType.SET_UNREAD_MESSAGE_COUNT,
|
|
@@ -205,7 +380,7 @@ export const LiveChatWidgetStateful = props => {
|
|
|
205
380
|
}, [state.appStates.isMinimized]); // Broadcast the UnreadMessageCount state on any change.
|
|
206
381
|
|
|
207
382
|
useEffect(() => {
|
|
208
|
-
if (state.appStates.isMinimized && state.appStates.unreadMessageCount > 0) {
|
|
383
|
+
if (state.appStates.isMinimized === true && state.appStates.unreadMessageCount > 0) {
|
|
209
384
|
const customEvent = {
|
|
210
385
|
elementType: ElementType.Custom,
|
|
211
386
|
eventName: BroadcastEvent.UnreadMessageCount,
|
|
@@ -220,29 +395,50 @@ export const LiveChatWidgetStateful = props => {
|
|
|
220
395
|
setWebChatStyles({ ...webChatStyles,
|
|
221
396
|
...((_props$webChatContain2 = props.webChatContainerProps) === null || _props$webChatContain2 === void 0 ? void 0 : _props$webChatContain2.webChatStyles)
|
|
222
397
|
});
|
|
223
|
-
}, [(_props$webChatContain3 = props.webChatContainerProps) === null || _props$webChatContain3 === void 0 ? void 0 : _props$webChatContain3.webChatStyles]);
|
|
224
|
-
const webChatProps = initWebChatComposer(props, chatSDK, state, dispatch, setWebChatStyles);
|
|
398
|
+
}, [(_props$webChatContain3 = props.webChatContainerProps) === null || _props$webChatContain3 === void 0 ? void 0 : _props$webChatContain3.webChatStyles]); // Publish chat widget state
|
|
225
399
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
const endChatRelay = (adapter, skipEndChatSDK, skipCloseChat) => endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat);
|
|
230
|
-
|
|
231
|
-
const prepareStartChatRelay = () => prepareStartChat(props, chatSDK, state, dispatch, setAdapter); // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
400
|
+
useEffect(() => {
|
|
401
|
+
var _props$controlProps12, _props$chatSDK, _props$chatSDK$omnich, _props$chatSDK2, _props$chatSDK2$omnic, _props$controlProps13;
|
|
232
402
|
|
|
403
|
+
// Only activate these windows events when conversation state is active and chat widget is in popout mode
|
|
404
|
+
// Ghost chat scenarios
|
|
405
|
+
if (state.appStates.conversationState === ConversationState.Active && ((_props$controlProps12 = props.controlProps) === null || _props$controlProps12 === void 0 ? void 0 : _props$controlProps12.skipChatButtonRendering) === true) {
|
|
406
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
407
|
+
window.onbeforeunload = function () {
|
|
408
|
+
const prompt = Constants.BrowserUnloadConfirmationMessage;
|
|
409
|
+
return prompt;
|
|
410
|
+
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
233
411
|
|
|
234
|
-
const initStartChatRelay = (optionalParams, persistedState) => initStartChat(chatSDK, dispatch, setAdapter, optionalParams, persistedState);
|
|
235
412
|
|
|
236
|
-
|
|
413
|
+
window.onunload = function () {
|
|
414
|
+
initiateEndChatOnBrowserUnload();
|
|
415
|
+
};
|
|
416
|
+
}
|
|
237
417
|
|
|
238
|
-
|
|
418
|
+
widgetStateEventName = getWidgetCacheId(props === null || props === void 0 ? void 0 : (_props$chatSDK = props.chatSDK) === null || _props$chatSDK === void 0 ? void 0 : (_props$chatSDK$omnich = _props$chatSDK.omnichannelConfig) === null || _props$chatSDK$omnich === void 0 ? void 0 : _props$chatSDK$omnich.orgId, props === null || props === void 0 ? void 0 : (_props$chatSDK2 = props.chatSDK) === null || _props$chatSDK2 === void 0 ? void 0 : (_props$chatSDK2$omnic = _props$chatSDK2.omnichannelConfig) === null || _props$chatSDK2$omnic === void 0 ? void 0 : _props$chatSDK2$omnic.widgetId, (props === null || props === void 0 ? void 0 : (_props$controlProps13 = props.controlProps) === null || _props$controlProps13 === void 0 ? void 0 : _props$controlProps13.widgetInstanceId) ?? "");
|
|
239
419
|
const chatWidgetStateChangeEvent = {
|
|
240
|
-
eventName:
|
|
420
|
+
eventName: widgetStateEventName,
|
|
241
421
|
payload: { ...state
|
|
242
422
|
}
|
|
243
423
|
};
|
|
244
424
|
BroadcastService.postMessage(chatWidgetStateChangeEvent);
|
|
245
425
|
}, [state]);
|
|
426
|
+
const webChatProps = initWebChatComposer(props, chatSDK, state, dispatch, setWebChatStyles);
|
|
427
|
+
|
|
428
|
+
const setPostChatContextRelay = () => setPostChatContextAndLoadSurvey(chatSDK, dispatch); // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
const endChatRelay = (adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab) => endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab); // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
const prepareEndChatRelay = (adapter, state) => prepareEndChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state);
|
|
435
|
+
|
|
436
|
+
const prepareStartChatRelay = () => prepareStartChat(props, chatSDK, state, dispatch, setAdapter); // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
const initStartChatRelay = (optionalParams, persistedState) => initStartChat(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, optionalParams, persistedState);
|
|
440
|
+
|
|
441
|
+
const confirmationPaneProps = initConfirmationPropsComposer(props);
|
|
246
442
|
return /*#__PURE__*/React.createElement(Composer, _extends({}, webChatProps, {
|
|
247
443
|
styleOptions: webChatStyles,
|
|
248
444
|
directLine: ((_props$webChatContain4 = props.webChatContainerProps) === null || _props$webChatContain4 === void 0 ? void 0 : _props$webChatContain4.directLine) ?? adapter ?? defaultWebChatContainerStatefulProps.directLine
|
|
@@ -250,28 +446,28 @@ export const LiveChatWidgetStateful = props => {
|
|
|
250
446
|
id: widgetElementId,
|
|
251
447
|
styles: generalStyles,
|
|
252
448
|
className: (_props$styleProps2 = props.styleProps) === null || _props$styleProps2 === void 0 ? void 0 : _props$styleProps2.className
|
|
253
|
-
}, !((_props$
|
|
449
|
+
}, !((_props$controlProps14 = props.controlProps) !== null && _props$controlProps14 !== void 0 && _props$controlProps14.hideChatButton) && !((_props$controlProps15 = props.controlProps) !== null && _props$controlProps15 !== void 0 && _props$controlProps15.skipChatButtonRendering) && shouldShowChatButton(state) && (decodeComponentString((_props$componentOverr = props.componentOverrides) === null || _props$componentOverr === void 0 ? void 0 : _props$componentOverr.chatButton) || /*#__PURE__*/React.createElement(ChatButtonStateful, {
|
|
254
450
|
buttonProps: props.chatButtonProps,
|
|
255
451
|
outOfOfficeButtonProps: props.outOfOfficeChatButtonProps,
|
|
256
452
|
startChat: prepareStartChatRelay
|
|
257
|
-
})), !((_props$
|
|
453
|
+
})), !((_props$controlProps16 = props.controlProps) !== null && _props$controlProps16 !== void 0 && _props$controlProps16.hideProactiveChatPane) && shouldShowProactiveChatPane(state) && (decodeComponentString((_props$componentOverr2 = props.componentOverrides) === null || _props$componentOverr2 === void 0 ? void 0 : _props$componentOverr2.proactiveChatPane) || /*#__PURE__*/React.createElement(ProactiveChatPaneStateful, {
|
|
258
454
|
proactiveChatProps: props.proactiveChatPaneProps,
|
|
259
455
|
startChat: prepareStartChatRelay
|
|
260
|
-
})), !((_props$
|
|
456
|
+
})), !((_props$controlProps17 = props.controlProps) !== null && _props$controlProps17 !== void 0 && _props$controlProps17.hideHeader) && shouldShowHeader(state) && (decodeComponentString((_props$componentOverr3 = props.componentOverrides) === null || _props$componentOverr3 === void 0 ? void 0 : _props$componentOverr3.header) || /*#__PURE__*/React.createElement(HeaderStateful, {
|
|
261
457
|
headerProps: props.headerProps,
|
|
262
458
|
outOfOfficeHeaderProps: props.outOfOfficeHeaderProps,
|
|
263
459
|
endChat: endChatRelay
|
|
264
|
-
})), !((_props$
|
|
460
|
+
})), !((_props$controlProps18 = props.controlProps) !== null && _props$controlProps18 !== void 0 && _props$controlProps18.hideLoadingPane) && shouldShowLoadingPane(state) && (decodeComponentString((_props$componentOverr4 = props.componentOverrides) === null || _props$componentOverr4 === void 0 ? void 0 : _props$componentOverr4.loadingPane) || /*#__PURE__*/React.createElement(LoadingPaneStateful, props.loadingPaneProps)), !((_props$controlProps19 = props.controlProps) !== null && _props$controlProps19 !== void 0 && _props$controlProps19.hideOutOfOfficeHoursPane) && shouldShowOutOfOfficeHoursPane(state) && (decodeComponentString((_props$componentOverr5 = props.componentOverrides) === null || _props$componentOverr5 === void 0 ? void 0 : _props$componentOverr5.outOfOfficeHoursPane) || /*#__PURE__*/React.createElement(OutOfOfficeHoursPaneStateful, props.outOfOfficeHoursPaneProps)), !((_props$controlProps20 = props.controlProps) !== null && _props$controlProps20 !== void 0 && _props$controlProps20.hideReconnectChatPane) && shouldShowReconnectChatPane(state) && (decodeComponentString((_props$componentOverr6 = props.componentOverrides) === null || _props$componentOverr6 === void 0 ? void 0 : _props$componentOverr6.reconnectChatPane) || /*#__PURE__*/React.createElement(ReconnectChatPaneStateful, {
|
|
265
461
|
reconnectChatProps: props.reconnectChatPaneProps,
|
|
266
462
|
initStartChat: initStartChatRelay
|
|
267
|
-
})), !((_props$
|
|
463
|
+
})), !((_props$controlProps21 = props.controlProps) !== null && _props$controlProps21 !== void 0 && _props$controlProps21.hidePreChatSurveyPane) && shouldShowPreChatSurveyPane(state) && (decodeComponentString((_props$componentOverr7 = props.componentOverrides) === null || _props$componentOverr7 === void 0 ? void 0 : _props$componentOverr7.preChatSurveyPane) || /*#__PURE__*/React.createElement(PreChatSurveyPaneStateful, {
|
|
268
464
|
surveyProps: props.preChatSurveyPaneProps,
|
|
269
465
|
initStartChat: initStartChatRelay
|
|
270
|
-
}), !((_props$
|
|
466
|
+
})), !((_props$controlProps22 = props.controlProps) !== null && _props$controlProps22 !== void 0 && _props$controlProps22.hideCallingContainer) && shouldShowCallingContainer(state) && /*#__PURE__*/React.createElement(CallingContainerStateful, _extends({
|
|
271
467
|
voiceVideoCallingSdk: voiceVideoCallingSDK
|
|
272
|
-
}, props.callingContainerProps)), !((_props$
|
|
468
|
+
}, props.callingContainerProps)), !((_props$controlProps23 = props.controlProps) !== null && _props$controlProps23 !== void 0 && _props$controlProps23.hideWebChatContainer) && shouldShowWebChatContainer(state) && (decodeComponentString((_props$componentOverr8 = props.componentOverrides) === null || _props$componentOverr8 === void 0 ? void 0 : _props$componentOverr8.webChatContainer) || /*#__PURE__*/React.createElement(WebChatContainerStateful, props.webChatContainerProps)), !((_props$controlProps24 = props.controlProps) !== null && _props$controlProps24 !== void 0 && _props$controlProps24.hideConfirmationPane) && shouldShowConfirmationPane(state) && (decodeComponentString((_props$componentOverr9 = props.componentOverrides) === null || _props$componentOverr9 === void 0 ? void 0 : _props$componentOverr9.confirmationPane) || /*#__PURE__*/React.createElement(ConfirmationPaneStateful, _extends({}, confirmationPaneProps, {
|
|
273
469
|
setPostChatContext: setPostChatContextRelay,
|
|
274
|
-
|
|
275
|
-
}))), !((_props$
|
|
470
|
+
prepareEndChat: prepareEndChatRelay
|
|
471
|
+
}))), !((_props$controlProps25 = props.controlProps) !== null && _props$controlProps25 !== void 0 && _props$controlProps25.hidePostChatLoadingPane) && shouldShowPostChatLoadingPane(state) && (decodeComponentString((_props$componentOverr10 = props.componentOverrides) === null || _props$componentOverr10 === void 0 ? void 0 : _props$componentOverr10.postChatLoadingPane) || /*#__PURE__*/React.createElement(PostChatLoadingPaneStateful, props.postChatLoadingPaneProps)), shouldShowPostChatSurveyPane(state) && (decodeComponentString((_props$componentOverr11 = props.componentOverrides) === null || _props$componentOverr11 === void 0 ? void 0 : _props$componentOverr11.postChatSurveyPane) || /*#__PURE__*/React.createElement(PostChatSurveyPaneStateful, _extends({}, props.postChatSurveyPaneProps, props.chatSDK))), createFooter(props, state), shouldShowEmailTranscriptPane(state) && (decodeComponentString((_props$componentOverr12 = props.componentOverrides) === null || _props$componentOverr12 === void 0 ? void 0 : _props$componentOverr12.emailTranscriptPane) || /*#__PURE__*/React.createElement(EmailTranscriptPaneStateful, props.emailTranscriptPane))));
|
|
276
472
|
};
|
|
277
473
|
export default LiveChatWidgetStateful;
|
|
@@ -3,6 +3,8 @@ import { LoadingPane } from "@microsoft/omnichannel-chat-components";
|
|
|
3
3
|
import { defaultGeneralPostChatLoadingPaneStyleProps } from "./common/defaultgeneralPostChatLoadingPaneStyleProps";
|
|
4
4
|
import { findAllFocusableElement } from "../../common/utils";
|
|
5
5
|
import useChatContextStore from "../../hooks/useChatContextStore";
|
|
6
|
+
import { TelemetryHelper } from "../../common/telemetry/TelemetryHelper";
|
|
7
|
+
import { LogLevel, TelemetryEvent } from "../../common/telemetry/TelemetryConstants";
|
|
6
8
|
export const PostChatLoadingPaneStateful = props => {
|
|
7
9
|
var _props$styleProps;
|
|
8
10
|
|
|
@@ -28,6 +30,10 @@ export const PostChatLoadingPaneStateful = props => {
|
|
|
28
30
|
if (firstElement && firstElement[0]) {
|
|
29
31
|
firstElement[0].focus();
|
|
30
32
|
}
|
|
33
|
+
|
|
34
|
+
TelemetryHelper.logLoadingEvent(LogLevel.INFO, {
|
|
35
|
+
Event: TelemetryEvent.PostChatSurveyLoadingPaneLoaded
|
|
36
|
+
});
|
|
31
37
|
}, []);
|
|
32
38
|
return /*#__PURE__*/React.createElement(LoadingPane, {
|
|
33
39
|
componentOverrides: props.componentOverrides,
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HtmlAttributeNames, Regex } from "../../common/Constants";
|
|
2
2
|
import { LogLevel, TelemetryEvent } from "../../common/telemetry/TelemetryConstants";
|
|
3
3
|
import React, { useEffect } from "react";
|
|
4
|
-
import { extractPreChatSurveyResponseValues, findAllFocusableElement, parseAdaptiveCardPayload } from "../../common/utils";
|
|
4
|
+
import { extractPreChatSurveyResponseValues, findAllFocusableElement, getStateFromCache, isUndefinedOrEmpty, parseAdaptiveCardPayload } from "../../common/utils";
|
|
5
5
|
import { ConversationState } from "../../contexts/common/ConversationState";
|
|
6
|
-
import { DataStoreManager } from "../../common/contextDataStore/DataStoreManager";
|
|
7
6
|
import { LiveChatWidgetActionType } from "../../contexts/common/LiveChatWidgetActionType";
|
|
8
7
|
import { PreChatSurveyPane } from "@microsoft/omnichannel-chat-components";
|
|
9
8
|
import { TelemetryHelper } from "../../common/telemetry/TelemetryHelper";
|
|
@@ -67,13 +66,12 @@ export const PreChatSurveyPaneStateful = props => {
|
|
|
67
66
|
});
|
|
68
67
|
|
|
69
68
|
try {
|
|
70
|
-
var
|
|
69
|
+
var _state$domainStates, _state$domainStates$t, _state$domainStates$t2, _persistedState$domai, _persistedState$appSt;
|
|
71
70
|
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
let optionalParams = {};
|
|
71
|
+
const persistedState = getStateFromCache(((_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : (_state$domainStates$t = _state$domainStates.telemetryInternalData) === null || _state$domainStates$t === void 0 ? void 0 : _state$domainStates$t.orgId) ?? "", ((_state$domainStates$t2 = state.domainStates.telemetryInternalData) === null || _state$domainStates$t2 === void 0 ? void 0 : _state$domainStates$t2.widgetId) ?? "", state.domainStates.widgetInstanceId ?? "");
|
|
72
|
+
let optionalParams = {}; //Connect to Active chats and chat is not popout
|
|
75
73
|
|
|
76
|
-
if (persistedState
|
|
74
|
+
if (persistedState && !isUndefinedOrEmpty(persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai = persistedState.domainStates) === null || _persistedState$domai === void 0 ? void 0 : _persistedState$domai.liveChatContext) && (persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$appSt = persistedState.appStates) === null || _persistedState$appSt === void 0 ? void 0 : _persistedState$appSt.conversationState) === ConversationState.Active && !state.appStates.skipChatButtonRendering) {
|
|
77
75
|
var _persistedState$domai2;
|
|
78
76
|
|
|
79
77
|
optionalParams = {
|
|
@@ -83,9 +81,7 @@ export const PreChatSurveyPaneStateful = props => {
|
|
|
83
81
|
} else {
|
|
84
82
|
const prechatResponseValues = extractPreChatSurveyResponseValues(state.domainStates.preChatSurveyResponse, values);
|
|
85
83
|
optionalParams = {
|
|
86
|
-
|
|
87
|
-
preChatResponse: prechatResponseValues
|
|
88
|
-
}
|
|
84
|
+
preChatResponse: prechatResponseValues
|
|
89
85
|
};
|
|
90
86
|
setPreChatResponseEmail(values);
|
|
91
87
|
await initStartChat(optionalParams);
|
|
@@ -24,6 +24,14 @@ export const ProactiveChatPaneStateful = props => {
|
|
|
24
24
|
const handleProactiveChatInviteTimeout = () => {
|
|
25
25
|
if (!timeoutRemoved) {
|
|
26
26
|
setTimeoutRemoved(true);
|
|
27
|
+
dispatch({
|
|
28
|
+
type: LiveChatWidgetActionType.SET_PROACTIVE_CHAT_PARAMS,
|
|
29
|
+
payload: {
|
|
30
|
+
proactiveChatBodyTitle: "",
|
|
31
|
+
proactiveChatEnablePrechat: false,
|
|
32
|
+
proactiveChatInNewWindow: false
|
|
33
|
+
}
|
|
34
|
+
});
|
|
27
35
|
dispatch({
|
|
28
36
|
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
29
37
|
payload: ConversationState.Closed
|
|
@@ -81,13 +89,21 @@ export const ProactiveChatPaneStateful = props => {
|
|
|
81
89
|
Event: TelemetryEvent.ProactiveChatClosed,
|
|
82
90
|
Description: "Proactive chat closed."
|
|
83
91
|
});
|
|
92
|
+
dispatch({
|
|
93
|
+
type: LiveChatWidgetActionType.SET_PROACTIVE_CHAT_PARAMS,
|
|
94
|
+
payload: {
|
|
95
|
+
proactiveChatBodyTitle: "",
|
|
96
|
+
proactiveChatEnablePrechat: false,
|
|
97
|
+
proactiveChatInNewWindow: false
|
|
98
|
+
}
|
|
99
|
+
});
|
|
84
100
|
dispatch({
|
|
85
101
|
type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
|
|
86
102
|
payload: ConversationState.Closed
|
|
87
103
|
});
|
|
88
104
|
},
|
|
89
105
|
...(proactiveChatProps === null || proactiveChatProps === void 0 ? void 0 : proactiveChatProps.controlProps),
|
|
90
|
-
bodyTitleText: state.appStates.proactiveChatStates.proactiveChatBodyTitle
|
|
106
|
+
bodyTitleText: state.appStates.proactiveChatStates.proactiveChatBodyTitle ? state.appStates.proactiveChatStates.proactiveChatBodyTitle : proactiveChatProps === null || proactiveChatProps === void 0 ? void 0 : (_proactiveChatProps$c = proactiveChatProps.controlProps) === null || _proactiveChatProps$c === void 0 ? void 0 : _proactiveChatProps$c.bodyTitleText
|
|
91
107
|
};
|
|
92
108
|
useEffect(() => {
|
|
93
109
|
setFocusOnElement(document.getElementById(controlProps.id + "-startbutton"));
|