@microsoft/omnichannel-chat-widget 0.1.0-main.a7e4e7d → 0.1.0-main.b511ad6

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.
Files changed (110) hide show
  1. package/README.md +32 -0
  2. package/lib/cjs/common/Constants.js +14 -0
  3. package/lib/cjs/common/telemetry/TelemetryConstants.js +20 -2
  4. package/lib/cjs/common/utils.js +49 -3
  5. package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +19 -3
  6. package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +0 -1
  7. package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +10 -1
  8. package/lib/cjs/components/headerstateful/HeaderStateful.js +2 -2
  9. package/lib/cjs/components/livechatwidget/common/ActivityStreamHandler.js +44 -0
  10. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +23 -0
  11. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.js +1 -0
  12. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +39 -0
  13. package/lib/cjs/components/livechatwidget/common/ChatAdapterShim.js +70 -0
  14. package/lib/cjs/components/livechatwidget/common/Deferred.js +42 -0
  15. package/lib/cjs/components/livechatwidget/common/createAdapter.js +13 -1
  16. package/lib/cjs/components/livechatwidget/common/createMarkdown.js +31 -30
  17. package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +9 -3
  18. package/lib/cjs/components/livechatwidget/common/endChat.js +52 -20
  19. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +16 -3
  20. package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +23 -15
  21. package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
  22. package/lib/cjs/components/livechatwidget/common/shareObservable.js +45 -0
  23. package/lib/cjs/components/livechatwidget/common/startChat.js +152 -81
  24. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +180 -89
  25. package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +4 -8
  26. package/lib/cjs/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +17 -1
  27. package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +80 -0
  28. package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +2 -0
  29. package/lib/cjs/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
  30. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +14 -0
  31. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +16 -2
  32. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +52 -0
  33. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +98 -0
  34. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.js +117 -0
  35. package/lib/cjs/contexts/common/ConversationState.js +3 -2
  36. package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +2 -0
  37. package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +2 -2
  38. package/lib/cjs/contexts/createReducer.js +8 -0
  39. package/lib/cjs/controller/componentController.js +3 -3
  40. package/lib/esm/common/Constants.js +14 -0
  41. package/lib/esm/common/telemetry/TelemetryConstants.js +20 -2
  42. package/lib/esm/common/utils.js +37 -1
  43. package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +21 -6
  44. package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +0 -1
  45. package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +8 -2
  46. package/lib/esm/components/headerstateful/HeaderStateful.js +2 -2
  47. package/lib/esm/components/livechatwidget/common/ActivityStreamHandler.js +34 -0
  48. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +14 -0
  49. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.js +1 -0
  50. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +29 -0
  51. package/lib/esm/components/livechatwidget/common/ChatAdapterShim.js +59 -0
  52. package/lib/esm/components/livechatwidget/common/Deferred.js +33 -0
  53. package/lib/esm/components/livechatwidget/common/createAdapter.js +12 -2
  54. package/lib/esm/components/livechatwidget/common/createMarkdown.js +31 -30
  55. package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +9 -3
  56. package/lib/esm/components/livechatwidget/common/endChat.js +53 -20
  57. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +15 -5
  58. package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +23 -15
  59. package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
  60. package/lib/esm/components/livechatwidget/common/shareObservable.js +38 -0
  61. package/lib/esm/components/livechatwidget/common/startChat.js +147 -80
  62. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +175 -91
  63. package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +5 -8
  64. package/lib/esm/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +17 -1
  65. package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +72 -0
  66. package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +2 -0
  67. package/lib/esm/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
  68. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +5 -0
  69. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +16 -2
  70. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +41 -0
  71. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +94 -0
  72. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.js +107 -0
  73. package/lib/esm/contexts/common/ConversationState.js +3 -2
  74. package/lib/esm/contexts/common/LiveChatWidgetActionType.js +2 -0
  75. package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +2 -2
  76. package/lib/esm/contexts/createReducer.js +8 -0
  77. package/lib/esm/controller/componentController.js +3 -3
  78. package/lib/types/common/Constants.d.ts +7 -0
  79. package/lib/types/common/interfaces/IContextDataStore.d.ts +1 -1
  80. package/lib/types/common/telemetry/TelemetryConstants.d.ts +20 -3
  81. package/lib/types/common/telemetry/TelemetryHelper.d.ts +1 -1
  82. package/lib/types/common/utils.d.ts +4 -1
  83. package/lib/types/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.d.ts +1 -1
  84. package/lib/types/components/livechatwidget/common/ActivityStreamHandler.d.ts +14 -0
  85. package/lib/types/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.d.ts +5 -0
  86. package/lib/types/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.d.ts +6 -0
  87. package/lib/types/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.d.ts +7 -0
  88. package/lib/types/components/livechatwidget/common/ChatAdapterShim.d.ts +7 -0
  89. package/lib/types/components/livechatwidget/common/Deferred.d.ts +9 -0
  90. package/lib/types/components/livechatwidget/common/endChat.d.ts +1 -1
  91. package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +5 -4
  92. package/lib/types/components/livechatwidget/common/setPostChatContextAndLoadSurvey.d.ts +1 -1
  93. package/lib/types/components/livechatwidget/common/shareObservable.d.ts +1 -0
  94. package/lib/types/components/livechatwidget/common/startChat.d.ts +4 -2
  95. package/lib/types/components/livechatwidget/common/startProactiveChat.d.ts +1 -1
  96. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +1 -0
  97. package/lib/types/components/reconnectchatpanestateful/interfaces/IReconnectChatPaneStatefulProps.d.ts +0 -1
  98. package/lib/types/components/webchatcontainerstateful/common/mockchatsdk.d.ts +1 -0
  99. package/lib/types/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.d.ts +4 -0
  100. package/lib/types/components/webchatcontainerstateful/interfaces/IWebChatContainerStatefulProps.d.ts +2 -0
  101. package/lib/types/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.d.ts +3 -0
  102. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.d.ts +1 -1
  103. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/avatarMiddleware.d.ts +1 -1
  104. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.d.ts +2 -0
  105. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.d.ts +1 -0
  106. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.d.ts +5 -0
  107. package/lib/types/contexts/common/ConversationState.d.ts +3 -2
  108. package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +1 -1
  109. package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +3 -1
  110. package/package.json +2 -2
@@ -89,16 +89,18 @@ var _useChatContextStore = _interopRequireDefault(require("../../../hooks/useCha
89
89
 
90
90
  var _useChatSDKStore = _interopRequireDefault(require("../../../hooks/useChatSDKStore"));
91
91
 
92
+ var _ActivityStreamHandler = require("../common/ActivityStreamHandler");
93
+
92
94
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
93
95
 
94
96
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
95
97
 
96
98
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
97
99
 
98
- function _extends() { _extends = Object.assign || 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); }
100
+ 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); }
99
101
 
100
102
  const LiveChatWidgetStateful = props => {
101
- var _props$webChatContain, _props$styleProps, _props$controlProps, _props$webChatContain3, _props$webChatContain4, _props$styleProps2, _props$controlProps5, _props$componentOverr, _props$controlProps6, _props$componentOverr2, _props$controlProps7, _props$componentOverr3, _props$controlProps8, _props$componentOverr4, _props$controlProps9, _props$componentOverr5, _props$controlProps10, _props$componentOverr6, _props$controlProps11, _props$componentOverr7, _props$controlProps12, _props$controlProps13, _props$componentOverr8, _props$controlProps14, _props$componentOverr9, _props$controlProps15, _props$componentOverr10, _props$componentOverr11, _props$componentOverr12;
103
+ var _props$webChatContain, _props$styleProps, _props$controlProps, _props$webChatContain3, _props$webChatContain4, _props$styleProps2, _props$controlProps5, _props$controlProps6, _props$componentOverr, _props$controlProps7, _props$componentOverr2, _props$controlProps8, _props$componentOverr3, _props$controlProps9, _props$componentOverr4, _props$controlProps10, _props$componentOverr5, _props$controlProps11, _props$componentOverr6, _props$controlProps12, _props$componentOverr7, _props$controlProps13, _props$controlProps14, _props$componentOverr8, _props$controlProps15, _props$componentOverr9, _props$controlProps16, _props$componentOverr10, _props$componentOverr11, _props$componentOverr12;
102
104
 
103
105
  const [state, dispatch] = (0, _useChatContextStore.default)(); // eslint-disable-next-line @typescript-eslint/no-explicit-any
104
106
 
@@ -113,8 +115,7 @@ const LiveChatWidgetStateful = props => {
113
115
  const {
114
116
  Composer
115
117
  } = _botframeworkWebchat.Components;
116
- const canStartProactiveChat = (0, _react2.useRef)(true);
117
- const canEndChat = (0, _react2.useRef)(true); // Process general styles
118
+ const canStartProactiveChat = (0, _react2.useRef)(true); // Process general styles
118
119
 
119
120
  const generalStyles = {
120
121
  root: Object.assign({}, (0, _getGeneralStylesForButton.getGeneralStylesForButton)(state), (_props$styleProps = props.styleProps) === null || _props$styleProps === void 0 ? void 0 : _props$styleProps.generalStyles)
@@ -122,8 +123,38 @@ const LiveChatWidgetStateful = props => {
122
123
  _TelemetryManager.TelemetryTimers.LcwLoadToChatButtonTimer = (0, _utils.createTimer)();
123
124
  const widgetElementId = ((_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.id) || "oc-lcw";
124
125
  const currentMessageCountRef = (0, _react2.useRef)(0);
126
+ let widgetStateEventName = "";
127
+
128
+ const initiateEndChatOnBrowserUnload = () => {
129
+ var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _DataStoreManager$cli;
130
+
131
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
132
+ Event: _TelemetryConstants.TelemetryEvent.BrowserUnloadEventStarted,
133
+ Description: "Browser unload event received."
134
+ });
135
+
136
+ const persistedState = (0, _utils.getStateFromCache)(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC === void 0 ? void 0 : _chatSDK$omnichannelC.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC2 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC2 === void 0 ? void 0 : _chatSDK$omnichannelC2.widgetId); // End chat if the chat is still active and browser closed
137
+
138
+ if (persistedState.appStates.conversationState === _ConversationState.ConversationState.Active) {
139
+ //Browser close scenario/no room for PCS/so just end chat and notify agent immidiately
140
+ (0, _endChat.endChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, false);
141
+ } // Clean local storage
142
+
143
+
144
+ (_DataStoreManager$cli = _DataStoreManager.DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.removeData(widgetStateEventName, "localStorage"); //Dispose calling instance
145
+
146
+ if (voiceVideoCallingSDK) {
147
+ voiceVideoCallingSDK === null || voiceVideoCallingSDK === void 0 ? void 0 : voiceVideoCallingSDK.close();
148
+ } //Message for clearing window[popouTab]
149
+
150
+
151
+ _omnichannelChatComponents.BroadcastService.postMessage({
152
+ eventName: _TelemetryConstants.BroadcastEvent.ClosePopoutWindow
153
+ });
154
+ };
155
+
125
156
  (0, _react2.useEffect)(() => {
126
- var _props$controlProps2, _props$controlProps3, _props$reconnectChatP, _props$controlProps4, _props$chatConfig, _props$chatConfig$Cha, _state$domainStates;
157
+ var _props$controlProps2, _props$controlProps3, _props$chatConfig, _props$chatConfig$Cha, _props$controlProps4, _props$reconnectChatP, _props$chatConfig2, _props$chatConfig2$Li;
127
158
 
128
159
  (0, _registerTelemetryLoggers.registerTelemetryLoggers)(props, dispatch);
129
160
  (0, _createInternetConnectionChangeHandler.createInternetConnectionChangeHandler)();
@@ -145,38 +176,58 @@ const LiveChatWidgetStateful = props => {
145
176
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_E2VV_ENABLED,
146
177
  payload: true
147
178
  });
179
+ }); // Initialize global dir
180
+
181
+ const globalDir = ((_props$controlProps3 = props.controlProps) === null || _props$controlProps3 === void 0 ? void 0 : _props$controlProps3.dir) ?? (0, _utils.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);
182
+ dispatch({
183
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_GLOBAL_DIR,
184
+ payload: globalDir
148
185
  });
149
186
 
150
- if (!((_props$controlProps3 = props.controlProps) !== null && _props$controlProps3 !== void 0 && _props$controlProps3.skipChatButtonRendering) && (_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.reconnectId) {
187
+ if (!((_props$controlProps4 = props.controlProps) !== null && _props$controlProps4 !== void 0 && _props$controlProps4.skipChatButtonRendering) && (_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.reconnectId) {
151
188
  var _props$reconnectChatP2;
152
189
 
153
- (0, _reconnectChatHelper.startUnauthenticatedReconnectChat)(chatSDK, dispatch, setAdapter, (_props$reconnectChatP2 = props.reconnectChatPaneProps) === null || _props$reconnectChatP2 === void 0 ? void 0 : _props$reconnectChatP2.reconnectId, _startChat.initStartChat);
154
- } // Initialize global dir
190
+ (0, _reconnectChatHelper.startUnauthenticatedReconnectChat)(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, (_props$reconnectChatP2 = props.reconnectChatPaneProps) === null || _props$reconnectChatP2 === void 0 ? void 0 : _props$reconnectChatP2.reconnectId, _startChat.initStartChat);
191
+ return;
192
+ } // Check if auth settings enabled, do not connect to existing chat from cache during refresh/re-load
193
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
194
+
195
+
196
+ 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;
197
+
198
+ if (!isAuthenticationSettingsEnabled) {
199
+ var _state$domainStates;
200
+
201
+ if (!(0, _utils.isUndefinedOrEmpty)((_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : _state$domainStates.liveChatContext) && state.appStates.conversationState === _ConversationState.ConversationState.Active) {
202
+ var _state$domainStates2;
203
+
204
+ const optionalParams = {
205
+ liveChatContext: (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : _state$domainStates2.liveChatContext
206
+ };
207
+ (0, _startChat.initStartChat)(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, optionalParams);
208
+ return;
209
+ }
210
+ } // All other case should show start chat button, skipChatButtonRendering will take care of it own
155
211
 
156
212
 
157
- const globalDir = ((_props$controlProps4 = props.controlProps) === null || _props$controlProps4 === void 0 ? void 0 : _props$controlProps4.dir) ?? (0, _utils.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);
158
213
  dispatch({
159
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_GLOBAL_DIR,
160
- payload: globalDir
214
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
215
+ payload: _ConversationState.ConversationState.Closed
161
216
  });
217
+ }, []); // useEffect for when skip chat button rendering
162
218
 
163
- if ((_state$domainStates = state.domainStates) !== null && _state$domainStates !== void 0 && _state$domainStates.liveChatContext) {
164
- var _state$domainStates2;
165
-
166
- const optionalParams = {
167
- liveChatContext: (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : _state$domainStates2.liveChatContext
168
- };
169
- (0, _startChat.initStartChat)(chatSDK, dispatch, setAdapter, optionalParams);
170
- }
171
- }, []);
172
219
  (0, _react2.useEffect)(() => {
173
220
  if (state.appStates.skipChatButtonRendering) {
174
221
  var _props$reconnectChatP3;
175
222
 
223
+ _omnichannelChatComponents.BroadcastService.postMessage({
224
+ eventName: _TelemetryConstants.BroadcastEvent.ChatInitiated
225
+ });
226
+
176
227
  if ((_props$reconnectChatP3 = props.reconnectChatPaneProps) !== null && _props$reconnectChatP3 !== void 0 && _props$reconnectChatP3.reconnectId && !state.appStates.reconnectId) {
177
228
  var _props$reconnectChatP4, _props$reconnectChatP5;
178
229
 
179
- (0, _reconnectChatHelper.handleUnauthenticatedReconnectChat)(chatSDK, dispatch, setAdapter, (_props$reconnectChatP4 = props.reconnectChatPaneProps) === null || _props$reconnectChatP4 === void 0 ? void 0 : _props$reconnectChatP4.reconnectId, _startChat.initStartChat, (_props$reconnectChatP5 = props.reconnectChatPaneProps) === null || _props$reconnectChatP5 === void 0 ? void 0 : _props$reconnectChatP5.redirectInSameWindow);
230
+ (0, _reconnectChatHelper.handleUnauthenticatedReconnectChat)(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, (_props$reconnectChatP4 = props.reconnectChatPaneProps) === null || _props$reconnectChatP4 === void 0 ? void 0 : _props$reconnectChatP4.reconnectId, _startChat.initStartChat, (_props$reconnectChatP5 = props.reconnectChatPaneProps) === null || _props$reconnectChatP5 === void 0 ? void 0 : _props$reconnectChatP5.redirectInSameWindow);
180
231
  } else {
181
232
  (0, _reconnectChatHelper.getReconnectIdForAuthenticatedChat)(props, chatSDK).then(authReconnectId => {
182
233
  if (authReconnectId && !state.appStates.reconnectId) {
@@ -195,18 +246,15 @@ const LiveChatWidgetStateful = props => {
195
246
 
196
247
  _omnichannelChatComponents.BroadcastService.postMessage(chatStartedSkippingChatButtonRendering);
197
248
 
198
- dispatch({
199
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
200
- payload: _ConversationState.ConversationState.Loading
201
- });
202
- (0, _startChat.initStartChat)(chatSDK, dispatch, setAdapter);
249
+ (0, _startChat.setPreChatAndInitiateChat)(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter);
203
250
  }
204
251
  });
205
252
  }
206
253
  }
207
- }, [state.appStates.skipChatButtonRendering]);
254
+ }, [state.appStates.skipChatButtonRendering]); // useEffect for when skip chat button rendering
255
+
208
256
  (0, _react2.useEffect)(() => {
209
- var _chatSDK$omnichannelC, _chatSDK$omnichannelC2;
257
+ var _chatSDK$omnichannelC7, _chatSDK$omnichannelC8;
210
258
 
211
259
  // Add the custom context on receiving the SetCustomContext event
212
260
  _omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.SetCustomContext).subscribe(msg => {
@@ -221,7 +269,7 @@ const LiveChatWidgetStateful = props => {
221
269
  });
222
270
  });
223
271
 
224
- _omnichannelChatComponents.BroadcastService.getMessageByEventName("StartProactiveChat").subscribe(msg => {
272
+ _omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.StartProactiveChat).subscribe(msg => {
225
273
  _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
226
274
  Event: _TelemetryConstants.TelemetryEvent.StartProactiveChatEventReceived,
227
275
  Description: "Start proactive chat event received."
@@ -237,81 +285,124 @@ const LiveChatWidgetStateful = props => {
237
285
  Description: "Start proactive chat method called, when chat was already triggered."
238
286
  });
239
287
  }
240
- }); // start chat from SDK Event
288
+ }); // Start chat from SDK Event
241
289
 
242
290
 
243
- _omnichannelChatComponents.BroadcastService.getMessageByEventName("StartChat").subscribe(() => {
291
+ _omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.StartChat).subscribe(() => {
292
+ var _chatSDK$omnichannelC3, _chatSDK$omnichannelC4;
293
+
244
294
  _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
245
295
  Event: _TelemetryConstants.TelemetryEvent.StartChatEventRecevied,
246
296
  Description: "Start chat event received."
247
297
  });
248
298
 
249
- if (state.appStates.isMinimized) {
299
+ const persistedState = (0, _utils.getStateFromCache)(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC3 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC3 === void 0 ? void 0 : _chatSDK$omnichannelC3.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC4 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC4 === void 0 ? void 0 : _chatSDK$omnichannelC4.widgetId);
300
+
301
+ if (persistedState && (persistedState.appStates.conversationState === _ConversationState.ConversationState.Closed || persistedState.appStates.conversationState === _ConversationState.ConversationState.InActive || persistedState.appStates.conversationState === _ConversationState.ConversationState.Postchat)) {
302
+ // Embedded mode
303
+ _omnichannelChatComponents.BroadcastService.postMessage({
304
+ eventName: _TelemetryConstants.BroadcastEvent.ChatInitiated
305
+ });
306
+
307
+ (0, _startChat.prepareStartChat)(props, chatSDK, state, dispatch, setAdapter);
308
+ } else {
309
+ var _persistedState$domai, _persistedState$domai2, _persistedState$domai3, _persistedState$domai4;
310
+
311
+ // Minimize to Maximize
250
312
  dispatch({
251
313
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_MINIMIZED,
252
314
  payload: false
253
315
  });
254
- } else {
255
- (0, _startChat.prepareStartChat)(props, chatSDK, state, dispatch, setAdapter);
316
+
317
+ _omnichannelChatComponents.BroadcastService.postMessage({
318
+ eventName: _TelemetryConstants.BroadcastEvent.MaximizeChat,
319
+ payload: {
320
+ 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,
321
+ 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
322
+ }
323
+ });
256
324
  }
257
- }); // end chat from SDK Event
325
+ }); // End chat
258
326
 
259
327
 
260
- _omnichannelChatComponents.BroadcastService.getMessageByEventName("EndChat").subscribe(async () => {
261
- _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
262
- Event: _TelemetryConstants.TelemetryEvent.EndChatEventReceived,
263
- Description: "End chat event received."
264
- });
328
+ _omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.InitiateEndChat).subscribe(async () => {
329
+ if (state.appStates.skipChatButtonRendering !== true) {
330
+ var _chatSDK$omnichannelC5, _chatSDK$omnichannelC6;
265
331
 
266
- if (canEndChat.current) {
267
- (0, _endChat.prepareEndChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state);
268
- } else {
269
- const skipEndChatSDK = true;
270
- const skipCloseChat = false;
271
- (0, _endChat.endChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat);
332
+ // This is to ensure to get latest state from cache in multitab
333
+ const persistedState = (0, _utils.getStateFromCache)(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC5 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC5 === void 0 ? void 0 : _chatSDK$omnichannelC5.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC6 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC6 === void 0 ? void 0 : _chatSDK$omnichannelC6.widgetId);
334
+
335
+ if (persistedState && persistedState.appStates.conversationState === _ConversationState.ConversationState.Active) {
336
+ (0, _endChat.prepareEndChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state);
337
+ } else {
338
+ const skipEndChatSDK = true;
339
+ const skipCloseChat = false;
340
+ (0, _endChat.endChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat);
341
+ }
272
342
  }
343
+
344
+ _omnichannelChatComponents.BroadcastService.postMessage({
345
+ eventName: _TelemetryConstants.BroadcastEvent.CloseChat
346
+ });
347
+ }); // End chat on browser unload
348
+
349
+
350
+ _omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.InitiateEndChatOnBrowserUnload).subscribe(() => {
351
+ initiateEndChatOnBrowserUnload();
273
352
  }); // Listen to end chat event from other tabs
274
353
 
275
354
 
276
- const endChatEventName = (0, _utils.getWidgetEndChatEventName)(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC === void 0 ? void 0 : _chatSDK$omnichannelC.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC2 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC2 === void 0 ? void 0 : _chatSDK$omnichannelC2.widgetId);
355
+ const endChatEventName = (0, _utils.getWidgetEndChatEventName)(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC7 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC7 === void 0 ? void 0 : _chatSDK$omnichannelC7.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC8 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC8 === void 0 ? void 0 : _chatSDK$omnichannelC8.widgetId);
277
356
 
278
357
  _omnichannelChatComponents.BroadcastService.getMessageByEventName(endChatEventName).subscribe(async () => {
279
358
  (0, _endChat.endChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, false);
280
- });
359
+ }); // When conversation ended by agent
281
360
 
282
- window.addEventListener("beforeunload", () => {
283
- (0, _disposeTelemetryLoggers.disposeTelemetryLoggers)();
284
- });
285
361
 
286
362
  if (state.appStates.conversationEndedByAgent) {
287
363
  (0, _endChat.endChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter);
288
- }
289
- }, []);
290
- (0, _react2.useEffect)(() => {
291
- canStartProactiveChat.current = state.appStates.conversationState === _ConversationState.ConversationState.Closed;
292
- canEndChat.current = state.appStates.conversationState === _ConversationState.ConversationState.Active;
364
+ } //Listen to WidgetSize, used for minimize to maximize
293
365
 
294
- if (state.appStates.conversationState === _ConversationState.ConversationState.Active) {
295
- chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.onNewMessage(() => {
296
- _omnichannelChatComponents.BroadcastService.postMessage({
297
- eventName: _TelemetryConstants.BroadcastEvent.NewMessageNotification
298
- });
299
- });
300
- } // Track the message count
301
366
 
367
+ _omnichannelChatComponents.BroadcastService.getMessageByEventName("WidgetSize").subscribe(msg => {
368
+ dispatch({
369
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_WIDGET_SIZE,
370
+ payload: msg === null || msg === void 0 ? void 0 : msg.payload
371
+ });
372
+ });
302
373
 
374
+ return () => {
375
+ (0, _disposeTelemetryLoggers.disposeTelemetryLoggers)();
376
+ };
377
+ }, []);
378
+ (0, _react2.useEffect)(() => {
379
+ // On new message
303
380
  if (state.appStates.conversationState === _ConversationState.ConversationState.Active) {
304
381
  chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.onNewMessage(() => {
382
+ // Track the message count
305
383
  currentMessageCountRef.current++;
306
384
  dispatch({
307
385
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_UNREAD_MESSAGE_COUNT,
308
386
  payload: currentMessageCountRef.current + 1
387
+ }); // New message notification
388
+
389
+ _omnichannelChatComponents.BroadcastService.postMessage({
390
+ eventName: _TelemetryConstants.BroadcastEvent.NewMessageNotification
309
391
  });
310
392
  });
311
393
  }
312
- }, [state.appStates.conversationState]); // Reset the UnreadMessageCount when minimized is toggled and broadcast it.
394
+ }, [state.appStates.conversationState]);
395
+ (0, _react2.useEffect)(() => {
396
+ canStartProactiveChat.current = state.appStates.conversationState === _ConversationState.ConversationState.Closed && !state.appStates.proactiveChatStates.proactiveChatInNewWindow;
397
+ }, [state.appStates.conversationState, state.appStates.proactiveChatStates.proactiveChatInNewWindow]); // Reset the UnreadMessageCount when minimized is toggled and broadcast it.
313
398
 
314
399
  (0, _react2.useEffect)(() => {
400
+ if (state.appStates.isMinimized) {
401
+ _ActivityStreamHandler.ActivityStreamHandler.cork();
402
+ } else {
403
+ setTimeout(() => _ActivityStreamHandler.ActivityStreamHandler.uncork(), 500);
404
+ }
405
+
315
406
  currentMessageCountRef.current = -1;
316
407
  dispatch({
317
408
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_UNREAD_MESSAGE_COUNT,
@@ -327,7 +418,7 @@ const LiveChatWidgetStateful = props => {
327
418
  }, [state.appStates.isMinimized]); // Broadcast the UnreadMessageCount state on any change.
328
419
 
329
420
  (0, _react2.useEffect)(() => {
330
- if (state.appStates.isMinimized && state.appStates.unreadMessageCount > 0) {
421
+ if (state.appStates.isMinimized === true && state.appStates.unreadMessageCount > 0) {
331
422
  const customEvent = {
332
423
  elementType: _omnichannelChatComponents.ElementType.Custom,
333
424
  eventName: _TelemetryConstants.BroadcastEvent.UnreadMessageCount,
@@ -343,7 +434,20 @@ const LiveChatWidgetStateful = props => {
343
434
  setWebChatStyles({ ...webChatStyles,
344
435
  ...((_props$webChatContain2 = props.webChatContainerProps) === null || _props$webChatContain2 === void 0 ? void 0 : _props$webChatContain2.webChatStyles)
345
436
  });
346
- }, [(_props$webChatContain3 = props.webChatContainerProps) === null || _props$webChatContain3 === void 0 ? void 0 : _props$webChatContain3.webChatStyles]);
437
+ }, [(_props$webChatContain3 = props.webChatContainerProps) === null || _props$webChatContain3 === void 0 ? void 0 : _props$webChatContain3.webChatStyles]); // Publish chat widget state
438
+
439
+ (0, _react2.useEffect)(() => {
440
+ var _props$chatSDK, _props$chatSDK$omnich, _props$chatSDK2, _props$chatSDK2$omnic;
441
+
442
+ widgetStateEventName = (0, _utils.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);
443
+ const chatWidgetStateChangeEvent = {
444
+ eventName: widgetStateEventName,
445
+ payload: { ...state
446
+ }
447
+ };
448
+
449
+ _omnichannelChatComponents.BroadcastService.postMessage(chatWidgetStateChangeEvent);
450
+ }, [state]);
347
451
  const webChatProps = (0, _initWebChatComposer.initWebChatComposer)(props, chatSDK, state, dispatch, setWebChatStyles);
348
452
 
349
453
  const setPostChatContextRelay = () => (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch); // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -357,22 +461,9 @@ const LiveChatWidgetStateful = props => {
357
461
  const prepareStartChatRelay = () => (0, _startChat.prepareStartChat)(props, chatSDK, state, dispatch, setAdapter); // eslint-disable-next-line @typescript-eslint/no-explicit-any
358
462
 
359
463
 
360
- const initStartChatRelay = (optionalParams, persistedState) => (0, _startChat.initStartChat)(chatSDK, dispatch, setAdapter, optionalParams, persistedState);
361
-
362
- const confirmationPaneProps = (0, _initConfirmationPropsComposer.initConfirmationPropsComposer)(props); // publish chat widget state
464
+ const initStartChatRelay = (optionalParams, persistedState) => (0, _startChat.initStartChat)(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, optionalParams, persistedState);
363
465
 
364
- (0, _react2.useEffect)(() => {
365
- var _props$chatSDK, _props$chatSDK$omnich, _props$chatSDK2, _props$chatSDK2$omnic;
366
-
367
- const widgetStateEventName = (0, _utils.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);
368
- const chatWidgetStateChangeEvent = {
369
- eventName: widgetStateEventName,
370
- payload: { ...state
371
- }
372
- };
373
-
374
- _omnichannelChatComponents.BroadcastService.postMessage(chatWidgetStateChangeEvent);
375
- }, [state]);
466
+ const confirmationPaneProps = (0, _initConfirmationPropsComposer.initConfirmationPropsComposer)(props);
376
467
  return /*#__PURE__*/_react2.default.createElement(Composer, _extends({}, webChatProps, {
377
468
  styleOptions: webChatStyles,
378
469
  directLine: ((_props$webChatContain4 = props.webChatContainerProps) === null || _props$webChatContain4 === void 0 ? void 0 : _props$webChatContain4.directLine) ?? adapter ?? _defaultWebChatContainerStatefulProps.defaultWebChatContainerStatefulProps.directLine
@@ -380,29 +471,29 @@ const LiveChatWidgetStateful = props => {
380
471
  id: widgetElementId,
381
472
  styles: generalStyles,
382
473
  className: (_props$styleProps2 = props.styleProps) === null || _props$styleProps2 === void 0 ? void 0 : _props$styleProps2.className
383
- }, !((_props$controlProps5 = props.controlProps) !== null && _props$controlProps5 !== void 0 && _props$controlProps5.hideChatButton) && (0, _componentController.shouldShowChatButton)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr = props.componentOverrides) === null || _props$componentOverr === void 0 ? void 0 : _props$componentOverr.chatButton) || /*#__PURE__*/_react2.default.createElement(_ChatButtonStateful.default, {
474
+ }, !((_props$controlProps5 = props.controlProps) !== null && _props$controlProps5 !== void 0 && _props$controlProps5.hideChatButton) && !((_props$controlProps6 = props.controlProps) !== null && _props$controlProps6 !== void 0 && _props$controlProps6.skipChatButtonRendering) && (0, _componentController.shouldShowChatButton)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr = props.componentOverrides) === null || _props$componentOverr === void 0 ? void 0 : _props$componentOverr.chatButton) || /*#__PURE__*/_react2.default.createElement(_ChatButtonStateful.default, {
384
475
  buttonProps: props.chatButtonProps,
385
476
  outOfOfficeButtonProps: props.outOfOfficeChatButtonProps,
386
477
  startChat: prepareStartChatRelay
387
- })), !((_props$controlProps6 = props.controlProps) !== null && _props$controlProps6 !== void 0 && _props$controlProps6.hideProactiveChatPane) && (0, _componentController.shouldShowProactiveChatPane)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr2 = props.componentOverrides) === null || _props$componentOverr2 === void 0 ? void 0 : _props$componentOverr2.proactiveChatPane) || /*#__PURE__*/_react2.default.createElement(_ProactiveChatPaneStateful.default, {
478
+ })), !((_props$controlProps7 = props.controlProps) !== null && _props$controlProps7 !== void 0 && _props$controlProps7.hideProactiveChatPane) && (0, _componentController.shouldShowProactiveChatPane)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr2 = props.componentOverrides) === null || _props$componentOverr2 === void 0 ? void 0 : _props$componentOverr2.proactiveChatPane) || /*#__PURE__*/_react2.default.createElement(_ProactiveChatPaneStateful.default, {
388
479
  proactiveChatProps: props.proactiveChatPaneProps,
389
480
  startChat: prepareStartChatRelay
390
- })), !((_props$controlProps7 = props.controlProps) !== null && _props$controlProps7 !== void 0 && _props$controlProps7.hideHeader) && (0, _componentController.shouldShowHeader)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr3 = props.componentOverrides) === null || _props$componentOverr3 === void 0 ? void 0 : _props$componentOverr3.header) || /*#__PURE__*/_react2.default.createElement(_HeaderStateful.default, {
481
+ })), !((_props$controlProps8 = props.controlProps) !== null && _props$controlProps8 !== void 0 && _props$controlProps8.hideHeader) && (0, _componentController.shouldShowHeader)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr3 = props.componentOverrides) === null || _props$componentOverr3 === void 0 ? void 0 : _props$componentOverr3.header) || /*#__PURE__*/_react2.default.createElement(_HeaderStateful.default, {
391
482
  headerProps: props.headerProps,
392
483
  outOfOfficeHeaderProps: props.outOfOfficeHeaderProps,
393
484
  endChat: endChatRelay
394
- })), !((_props$controlProps8 = props.controlProps) !== null && _props$controlProps8 !== void 0 && _props$controlProps8.hideLoadingPane) && (0, _componentController.shouldShowLoadingPane)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr4 = props.componentOverrides) === null || _props$componentOverr4 === void 0 ? void 0 : _props$componentOverr4.loadingPane) || /*#__PURE__*/_react2.default.createElement(_LoadingPaneStateful.default, props.loadingPaneProps)), !((_props$controlProps9 = props.controlProps) !== null && _props$controlProps9 !== void 0 && _props$controlProps9.hideOutOfOfficeHoursPane) && (0, _componentController.shouldShowOutOfOfficeHoursPane)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr5 = props.componentOverrides) === null || _props$componentOverr5 === void 0 ? void 0 : _props$componentOverr5.outOfOfficeHoursPane) || /*#__PURE__*/_react2.default.createElement(_OOOHPaneStateful.default, props.outOfOfficeHoursPaneProps)), !((_props$controlProps10 = props.controlProps) !== null && _props$controlProps10 !== void 0 && _props$controlProps10.hideReconnectChatPane) && (0, _componentController.shouldShowReconnectChatPane)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr6 = props.componentOverrides) === null || _props$componentOverr6 === void 0 ? void 0 : _props$componentOverr6.reconnectChatPane) || /*#__PURE__*/_react2.default.createElement(_ReconnectChatPaneStateful.default, {
485
+ })), !((_props$controlProps9 = props.controlProps) !== null && _props$controlProps9 !== void 0 && _props$controlProps9.hideLoadingPane) && (0, _componentController.shouldShowLoadingPane)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr4 = props.componentOverrides) === null || _props$componentOverr4 === void 0 ? void 0 : _props$componentOverr4.loadingPane) || /*#__PURE__*/_react2.default.createElement(_LoadingPaneStateful.default, props.loadingPaneProps)), !((_props$controlProps10 = props.controlProps) !== null && _props$controlProps10 !== void 0 && _props$controlProps10.hideOutOfOfficeHoursPane) && (0, _componentController.shouldShowOutOfOfficeHoursPane)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr5 = props.componentOverrides) === null || _props$componentOverr5 === void 0 ? void 0 : _props$componentOverr5.outOfOfficeHoursPane) || /*#__PURE__*/_react2.default.createElement(_OOOHPaneStateful.default, props.outOfOfficeHoursPaneProps)), !((_props$controlProps11 = props.controlProps) !== null && _props$controlProps11 !== void 0 && _props$controlProps11.hideReconnectChatPane) && (0, _componentController.shouldShowReconnectChatPane)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr6 = props.componentOverrides) === null || _props$componentOverr6 === void 0 ? void 0 : _props$componentOverr6.reconnectChatPane) || /*#__PURE__*/_react2.default.createElement(_ReconnectChatPaneStateful.default, {
395
486
  reconnectChatProps: props.reconnectChatPaneProps,
396
487
  initStartChat: initStartChatRelay
397
- })), !((_props$controlProps11 = props.controlProps) !== null && _props$controlProps11 !== void 0 && _props$controlProps11.hidePreChatSurveyPane) && (0, _componentController.shouldShowPreChatSurveyPane)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr7 = props.componentOverrides) === null || _props$componentOverr7 === void 0 ? void 0 : _props$componentOverr7.preChatSurveyPane) || /*#__PURE__*/_react2.default.createElement(_PreChatSurveyPaneStateful.default, {
488
+ })), !((_props$controlProps12 = props.controlProps) !== null && _props$controlProps12 !== void 0 && _props$controlProps12.hidePreChatSurveyPane) && (0, _componentController.shouldShowPreChatSurveyPane)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr7 = props.componentOverrides) === null || _props$componentOverr7 === void 0 ? void 0 : _props$componentOverr7.preChatSurveyPane) || /*#__PURE__*/_react2.default.createElement(_PreChatSurveyPaneStateful.default, {
398
489
  surveyProps: props.preChatSurveyPaneProps,
399
490
  initStartChat: initStartChatRelay
400
- })), !((_props$controlProps12 = props.controlProps) !== null && _props$controlProps12 !== void 0 && _props$controlProps12.hideCallingContainer) && (0, _componentController.shouldShowCallingContainer)(state) && /*#__PURE__*/_react2.default.createElement(_CallingContainerStateful.default, _extends({
491
+ })), !((_props$controlProps13 = props.controlProps) !== null && _props$controlProps13 !== void 0 && _props$controlProps13.hideCallingContainer) && (0, _componentController.shouldShowCallingContainer)(state) && /*#__PURE__*/_react2.default.createElement(_CallingContainerStateful.default, _extends({
401
492
  voiceVideoCallingSdk: voiceVideoCallingSDK
402
- }, props.callingContainerProps)), !((_props$controlProps13 = props.controlProps) !== null && _props$controlProps13 !== void 0 && _props$controlProps13.hideWebChatContainer) && (0, _componentController.shouldShowWebChatContainer)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr8 = props.componentOverrides) === null || _props$componentOverr8 === void 0 ? void 0 : _props$componentOverr8.webChatContainer) || /*#__PURE__*/_react2.default.createElement(_WebChatContainerStateful.default, props.webChatContainerProps)), !((_props$controlProps14 = props.controlProps) !== null && _props$controlProps14 !== void 0 && _props$controlProps14.hideConfirmationPane) && (0, _componentController.shouldShowConfirmationPane)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr9 = props.componentOverrides) === null || _props$componentOverr9 === void 0 ? void 0 : _props$componentOverr9.confirmationPane) || /*#__PURE__*/_react2.default.createElement(_ConfirmationPaneStateful.default, _extends({}, confirmationPaneProps, {
493
+ }, props.callingContainerProps)), !((_props$controlProps14 = props.controlProps) !== null && _props$controlProps14 !== void 0 && _props$controlProps14.hideWebChatContainer) && (0, _componentController.shouldShowWebChatContainer)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr8 = props.componentOverrides) === null || _props$componentOverr8 === void 0 ? void 0 : _props$componentOverr8.webChatContainer) || /*#__PURE__*/_react2.default.createElement(_WebChatContainerStateful.default, props.webChatContainerProps)), !((_props$controlProps15 = props.controlProps) !== null && _props$controlProps15 !== void 0 && _props$controlProps15.hideConfirmationPane) && (0, _componentController.shouldShowConfirmationPane)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr9 = props.componentOverrides) === null || _props$componentOverr9 === void 0 ? void 0 : _props$componentOverr9.confirmationPane) || /*#__PURE__*/_react2.default.createElement(_ConfirmationPaneStateful.default, _extends({}, confirmationPaneProps, {
403
494
  setPostChatContext: setPostChatContextRelay,
404
495
  prepareEndChat: prepareEndChatRelay
405
- }))), !((_props$controlProps15 = props.controlProps) !== null && _props$controlProps15 !== void 0 && _props$controlProps15.hidePostChatLoadingPane) && (0, _componentController.shouldShowPostChatLoadingPane)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr10 = props.componentOverrides) === null || _props$componentOverr10 === void 0 ? void 0 : _props$componentOverr10.postChatLoadingPane) || /*#__PURE__*/_react2.default.createElement(_PostChatLoadingPaneStateful.default, props.postChatLoadingPaneProps)), (0, _componentController.shouldShowPostChatSurveyPane)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr11 = props.componentOverrides) === null || _props$componentOverr11 === void 0 ? void 0 : _props$componentOverr11.postChatSurveyPane) || /*#__PURE__*/_react2.default.createElement(_PostChatSurveyPaneStateful.default, _extends({}, props.postChatSurveyPaneProps, props.chatSDK))), (0, _createFooter.createFooter)(props, state), (0, _componentController.shouldShowEmailTranscriptPane)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr12 = props.componentOverrides) === null || _props$componentOverr12 === void 0 ? void 0 : _props$componentOverr12.emailTranscriptPane) || /*#__PURE__*/_react2.default.createElement(_EmailTranscriptPaneStateful.default, props.emailTranscriptPane))));
496
+ }))), !((_props$controlProps16 = props.controlProps) !== null && _props$controlProps16 !== void 0 && _props$controlProps16.hidePostChatLoadingPane) && (0, _componentController.shouldShowPostChatLoadingPane)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr10 = props.componentOverrides) === null || _props$componentOverr10 === void 0 ? void 0 : _props$componentOverr10.postChatLoadingPane) || /*#__PURE__*/_react2.default.createElement(_PostChatLoadingPaneStateful.default, props.postChatLoadingPaneProps)), (0, _componentController.shouldShowPostChatSurveyPane)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr11 = props.componentOverrides) === null || _props$componentOverr11 === void 0 ? void 0 : _props$componentOverr11.postChatSurveyPane) || /*#__PURE__*/_react2.default.createElement(_PostChatSurveyPaneStateful.default, _extends({}, props.postChatSurveyPaneProps, props.chatSDK))), (0, _createFooter.createFooter)(props, state), (0, _componentController.shouldShowEmailTranscriptPane)(state) && ((0, _omnichannelChatComponents.decodeComponentString)((_props$componentOverr12 = props.componentOverrides) === null || _props$componentOverr12 === void 0 ? void 0 : _props$componentOverr12.emailTranscriptPane) || /*#__PURE__*/_react2.default.createElement(_EmailTranscriptPaneStateful.default, props.emailTranscriptPane))));
406
497
  };
407
498
 
408
499
  exports.LiveChatWidgetStateful = LiveChatWidgetStateful;
@@ -15,8 +15,6 @@ var _utils = require("../../common/utils");
15
15
 
16
16
  var _ConversationState = require("../../contexts/common/ConversationState");
17
17
 
18
- var _DataStoreManager = require("../../common/contextDataStore/DataStoreManager");
19
-
20
18
  var _LiveChatWidgetActionType = require("../../contexts/common/LiveChatWidgetActionType");
21
19
 
22
20
  var _omnichannelChatComponents = require("@microsoft/omnichannel-chat-components");
@@ -93,14 +91,12 @@ const PreChatSurveyPaneStateful = props => {
93
91
  });
94
92
 
95
93
  try {
96
- var _state$domainStates, _state$domainStates$t, _state$domainStates$t2, _DataStoreManager$cli, _persistedState$domai;
94
+ var _state$domainStates, _state$domainStates$t, _state$domainStates$t2, _persistedState$domai, _persistedState$appSt;
97
95
 
98
- const widgetStateCacheId = (0, _utils.getWidgetCacheId)(((_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) ?? "");
99
- const widgetStateFromCache = (_DataStoreManager$cli = _DataStoreManager.DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.getData(widgetStateCacheId, "localStorage");
100
- const persistedState = widgetStateFromCache ? JSON.parse(widgetStateFromCache) : undefined;
101
- let optionalParams = {};
96
+ const persistedState = (0, _utils.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) ?? "");
97
+ let optionalParams = {}; //Connect to Active chats and chat is not popout
102
98
 
103
- if (persistedState !== null && persistedState !== void 0 && (_persistedState$domai = persistedState.domainStates) !== null && _persistedState$domai !== void 0 && _persistedState$domai.liveChatContext) {
99
+ if (persistedState && !(0, _utils.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.ConversationState.Active && !state.appStates.skipChatButtonRendering) {
104
100
  var _persistedState$domai2;
105
101
 
106
102
  optionalParams = {
@@ -46,6 +46,14 @@ const ProactiveChatPaneStateful = props => {
46
46
  const handleProactiveChatInviteTimeout = () => {
47
47
  if (!timeoutRemoved) {
48
48
  setTimeoutRemoved(true);
49
+ dispatch({
50
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_PROACTIVE_CHAT_PARAMS,
51
+ payload: {
52
+ proactiveChatBodyTitle: "",
53
+ proactiveChatEnablePrechat: false,
54
+ proactiveChatInNewWindow: false
55
+ }
56
+ });
49
57
  dispatch({
50
58
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
51
59
  payload: _ConversationState.ConversationState.Closed
@@ -111,13 +119,21 @@ const ProactiveChatPaneStateful = props => {
111
119
  Description: "Proactive chat closed."
112
120
  });
113
121
 
122
+ dispatch({
123
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_PROACTIVE_CHAT_PARAMS,
124
+ payload: {
125
+ proactiveChatBodyTitle: "",
126
+ proactiveChatEnablePrechat: false,
127
+ proactiveChatInNewWindow: false
128
+ }
129
+ });
114
130
  dispatch({
115
131
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
116
132
  payload: _ConversationState.ConversationState.Closed
117
133
  });
118
134
  },
119
135
  ...(proactiveChatProps === null || proactiveChatProps === void 0 ? void 0 : proactiveChatProps.controlProps),
120
- bodyTitleText: 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)
136
+ 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
121
137
  };
122
138
  (0, _react.useEffect)(() => {
123
139
  (0, _utils.setFocusOnElement)(document.getElementById(controlProps.id + "-startbutton"));