@microsoft/omnichannel-chat-widget 0.1.0-main.c2417f9 → 0.1.0-main.ce08f21

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 (81) hide show
  1. package/lib/cjs/common/Constants.js +4 -0
  2. package/lib/cjs/common/telemetry/TelemetryConstants.js +7 -0
  3. package/lib/cjs/common/utils.js +58 -5
  4. package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +4 -0
  5. package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +0 -1
  6. package/lib/cjs/components/headerstateful/HeaderStateful.js +4 -3
  7. package/lib/cjs/components/livechatwidget/common/ActivityStreamHandler.js +44 -0
  8. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +23 -0
  9. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.js +1 -0
  10. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +39 -0
  11. package/lib/cjs/components/livechatwidget/common/ChatAdapterShim.js +70 -0
  12. package/lib/cjs/components/livechatwidget/common/Deferred.js +42 -0
  13. package/lib/cjs/components/livechatwidget/common/createAdapter.js +13 -1
  14. package/lib/cjs/components/livechatwidget/common/createMarkdown.js +31 -30
  15. package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +2 -2
  16. package/lib/cjs/components/livechatwidget/common/endChat.js +52 -20
  17. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +8 -0
  18. package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +23 -15
  19. package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
  20. package/lib/cjs/components/livechatwidget/common/shareObservable.js +45 -0
  21. package/lib/cjs/components/livechatwidget/common/startChat.js +152 -81
  22. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +167 -112
  23. package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +4 -8
  24. package/lib/cjs/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +1 -1
  25. package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +2 -0
  26. package/lib/cjs/contexts/common/ConversationState.js +3 -2
  27. package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +1 -0
  28. package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +2 -2
  29. package/lib/cjs/contexts/createReducer.js +8 -0
  30. package/lib/cjs/controller/componentController.js +3 -3
  31. package/lib/esm/common/Constants.js +4 -0
  32. package/lib/esm/common/telemetry/TelemetryConstants.js +7 -0
  33. package/lib/esm/common/utils.js +45 -3
  34. package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +4 -0
  35. package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +0 -1
  36. package/lib/esm/components/headerstateful/HeaderStateful.js +4 -3
  37. package/lib/esm/components/livechatwidget/common/ActivityStreamHandler.js +34 -0
  38. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +14 -0
  39. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.js +1 -0
  40. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +29 -0
  41. package/lib/esm/components/livechatwidget/common/ChatAdapterShim.js +59 -0
  42. package/lib/esm/components/livechatwidget/common/Deferred.js +33 -0
  43. package/lib/esm/components/livechatwidget/common/createAdapter.js +12 -2
  44. package/lib/esm/components/livechatwidget/common/createMarkdown.js +31 -30
  45. package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +2 -2
  46. package/lib/esm/components/livechatwidget/common/endChat.js +53 -21
  47. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +9 -2
  48. package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +23 -15
  49. package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
  50. package/lib/esm/components/livechatwidget/common/shareObservable.js +38 -0
  51. package/lib/esm/components/livechatwidget/common/startChat.js +147 -80
  52. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +164 -112
  53. package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +5 -8
  54. package/lib/esm/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +1 -1
  55. package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +2 -0
  56. package/lib/esm/contexts/common/ConversationState.js +3 -2
  57. package/lib/esm/contexts/common/LiveChatWidgetActionType.js +1 -0
  58. package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +2 -2
  59. package/lib/esm/contexts/createReducer.js +8 -0
  60. package/lib/esm/controller/componentController.js +3 -3
  61. package/lib/types/common/Constants.d.ts +2 -0
  62. package/lib/types/common/telemetry/TelemetryConstants.d.ts +7 -1
  63. package/lib/types/common/utils.d.ts +6 -3
  64. package/lib/types/components/headerstateful/interfaces/IHeaderStatefulParams.d.ts +2 -1
  65. package/lib/types/components/livechatwidget/common/ActivityStreamHandler.d.ts +14 -0
  66. package/lib/types/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.d.ts +5 -0
  67. package/lib/types/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.d.ts +6 -0
  68. package/lib/types/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.d.ts +7 -0
  69. package/lib/types/components/livechatwidget/common/ChatAdapterShim.d.ts +7 -0
  70. package/lib/types/components/livechatwidget/common/Deferred.d.ts +9 -0
  71. package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +4 -3
  72. package/lib/types/components/livechatwidget/common/shareObservable.d.ts +1 -0
  73. package/lib/types/components/livechatwidget/common/startChat.d.ts +4 -2
  74. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetControlProps.d.ts +1 -0
  75. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +1 -0
  76. package/lib/types/components/reconnectchatpanestateful/interfaces/IReconnectChatPaneStatefulProps.d.ts +0 -1
  77. package/lib/types/components/webchatcontainerstateful/common/mockchatsdk.d.ts +1 -0
  78. package/lib/types/contexts/common/ConversationState.d.ts +3 -2
  79. package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +1 -1
  80. package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +2 -1
  81. package/package.json +4 -3
@@ -89,16 +89,20 @@ 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
+
94
+ var _Constants = require("../../../common/Constants");
95
+
92
96
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
93
97
 
94
98
  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
99
 
96
100
  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
101
 
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); }
102
+ 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
103
 
100
104
  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;
105
+ var _props$webChatContain, _props$styleProps, _props$controlProps, _props$webChatContain3, _props$webChatContain4, _props$styleProps2, _props$controlProps13, _props$controlProps14, _props$componentOverr, _props$controlProps15, _props$componentOverr2, _props$controlProps16, _props$componentOverr3, _props$controlProps17, _props$componentOverr4, _props$controlProps18, _props$componentOverr5, _props$controlProps19, _props$componentOverr6, _props$controlProps20, _props$componentOverr7, _props$controlProps21, _props$controlProps22, _props$componentOverr8, _props$controlProps23, _props$componentOverr9, _props$controlProps24, _props$componentOverr10, _props$componentOverr11, _props$componentOverr12;
102
106
 
103
107
  const [state, dispatch] = (0, _useChatContextStore.default)(); // eslint-disable-next-line @typescript-eslint/no-explicit-any
104
108
 
@@ -113,8 +117,7 @@ const LiveChatWidgetStateful = props => {
113
117
  const {
114
118
  Composer
115
119
  } = _botframeworkWebchat.Components;
116
- const canStartProactiveChat = (0, _react2.useRef)(true);
117
- const canEndChat = (0, _react2.useRef)(true); // Process general styles
120
+ const canStartProactiveChat = (0, _react2.useRef)(true); // Process general styles
118
121
 
119
122
  const generalStyles = {
120
123
  root: Object.assign({}, (0, _getGeneralStylesForButton.getGeneralStylesForButton)(state), (_props$styleProps = props.styleProps) === null || _props$styleProps === void 0 ? void 0 : _props$styleProps.generalStyles)
@@ -123,9 +126,33 @@ const LiveChatWidgetStateful = props => {
123
126
  const widgetElementId = ((_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.id) || "oc-lcw";
124
127
  const currentMessageCountRef = (0, _react2.useRef)(0);
125
128
  let widgetStateEventName = "";
129
+
130
+ const initiateEndChatOnBrowserUnload = () => {
131
+ var _DataStoreManager$cli;
132
+
133
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
134
+ Event: _TelemetryConstants.TelemetryEvent.BrowserUnloadEventStarted,
135
+ Description: "Browser unload event received."
136
+ });
137
+
138
+ (0, _endChat.endChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, false); // Clean local storage
139
+
140
+ (_DataStoreManager$cli = _DataStoreManager.DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.removeData(widgetStateEventName, "localStorage"); //Dispose calling instance
141
+
142
+ if (voiceVideoCallingSDK) {
143
+ voiceVideoCallingSDK === null || voiceVideoCallingSDK === void 0 ? void 0 : voiceVideoCallingSDK.close();
144
+ } //Message for clearing window[popouTab]
145
+
146
+
147
+ _omnichannelChatComponents.BroadcastService.postMessage({
148
+ eventName: _TelemetryConstants.BroadcastEvent.ClosePopoutWindow
149
+ });
150
+ };
151
+
126
152
  (0, _react2.useEffect)(() => {
127
- var _props$controlProps2, _props$controlProps3, _props$reconnectChatP, _props$controlProps4, _props$chatConfig, _props$chatConfig$Cha, _state$domainStates;
153
+ var _props$chatSDK, _props$chatSDK$omnich, _props$controlProps2, _props$controlProps3, _props$controlProps4, _props$controlProps6, _props$chatConfig, _props$chatConfig$Cha, _props$controlProps7, _props$reconnectChatP, _props$chatConfig2, _props$chatConfig2$Li;
128
154
 
155
+ (0, _omnichannelChatComponents.BroadcastServiceInitialize)((_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.widgetId);
129
156
  (0, _registerTelemetryLoggers.registerTelemetryLoggers)(props, dispatch);
130
157
  (0, _createInternetConnectionChangeHandler.createInternetConnectionChangeHandler)();
131
158
  _DataStoreManager.DataStoreManager.clientDataStore = props.contextDataStore ?? undefined;
@@ -141,44 +168,73 @@ const LiveChatWidgetStateful = props => {
141
168
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_E2VV_ENABLED,
142
169
  payload: false
143
170
  });
171
+
172
+ if ((_props$controlProps3 = props.controlProps) !== null && _props$controlProps3 !== void 0 && _props$controlProps3.widgetInstanceId && !(0, _utils.isNullOrEmptyString)((_props$controlProps4 = props.controlProps) === null || _props$controlProps4 === void 0 ? void 0 : _props$controlProps4.widgetInstanceId)) {
173
+ var _props$controlProps5;
174
+
175
+ dispatch({
176
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_WIDGET_INSTANCE_ID,
177
+ payload: (_props$controlProps5 = props.controlProps) === null || _props$controlProps5 === void 0 ? void 0 : _props$controlProps5.widgetInstanceId
178
+ });
179
+ }
180
+
144
181
  (0, _initCallingSdk.initCallingSdk)(chatSDK, setVoiceVideoCallingSDK).then(sdkCreated => {
145
182
  sdkCreated && dispatch({
146
183
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_E2VV_ENABLED,
147
184
  payload: true
148
185
  });
186
+ }); // Initialize global dir
187
+
188
+ const globalDir = ((_props$controlProps6 = props.controlProps) === null || _props$controlProps6 === void 0 ? void 0 : _props$controlProps6.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);
189
+ dispatch({
190
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_GLOBAL_DIR,
191
+ payload: globalDir
149
192
  });
150
193
 
151
- 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) {
194
+ if (!((_props$controlProps7 = props.controlProps) !== null && _props$controlProps7 !== void 0 && _props$controlProps7.skipChatButtonRendering) && (_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.reconnectId) {
152
195
  var _props$reconnectChatP2;
153
196
 
154
- (0, _reconnectChatHelper.startUnauthenticatedReconnectChat)(chatSDK, dispatch, setAdapter, (_props$reconnectChatP2 = props.reconnectChatPaneProps) === null || _props$reconnectChatP2 === void 0 ? void 0 : _props$reconnectChatP2.reconnectId, _startChat.initStartChat);
155
- } // Initialize global dir
197
+ (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);
198
+ return;
199
+ } // Check if auth settings enabled, do not connect to existing chat from cache during refresh/re-load
200
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
156
201
 
157
202
 
158
- 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);
159
- dispatch({
160
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_GLOBAL_DIR,
161
- payload: globalDir
162
- });
203
+ 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;
163
204
 
164
- if ((_state$domainStates = state.domainStates) !== null && _state$domainStates !== void 0 && _state$domainStates.liveChatContext) {
165
- var _state$domainStates2;
205
+ if (isAuthenticationSettingsEnabled === false) {
206
+ var _state$domainStates;
166
207
 
167
- const optionalParams = {
168
- liveChatContext: (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : _state$domainStates2.liveChatContext
169
- };
170
- (0, _startChat.initStartChat)(chatSDK, dispatch, setAdapter, optionalParams);
171
- }
208
+ if (!(0, _utils.isUndefinedOrEmpty)((_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : _state$domainStates.liveChatContext) && state.appStates.conversationState === _ConversationState.ConversationState.Active) {
209
+ var _state$domainStates2;
210
+
211
+ const optionalParams = {
212
+ liveChatContext: (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : _state$domainStates2.liveChatContext
213
+ };
214
+ (0, _startChat.initStartChat)(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, optionalParams);
215
+ return;
216
+ }
217
+ } // All other case should show start chat button, skipChatButtonRendering will take care of it own
218
+
219
+
220
+ dispatch({
221
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
222
+ payload: _ConversationState.ConversationState.Closed
223
+ });
172
224
  }, []); // useEffect for when skip chat button rendering
173
225
 
174
226
  (0, _react2.useEffect)(() => {
175
227
  if (state.appStates.skipChatButtonRendering) {
176
228
  var _props$reconnectChatP3;
177
229
 
230
+ _omnichannelChatComponents.BroadcastService.postMessage({
231
+ eventName: _TelemetryConstants.BroadcastEvent.ChatInitiated
232
+ });
233
+
178
234
  if ((_props$reconnectChatP3 = props.reconnectChatPaneProps) !== null && _props$reconnectChatP3 !== void 0 && _props$reconnectChatP3.reconnectId && !state.appStates.reconnectId) {
179
235
  var _props$reconnectChatP4, _props$reconnectChatP5;
180
236
 
181
- (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);
237
+ (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);
182
238
  } else {
183
239
  (0, _reconnectChatHelper.getReconnectIdForAuthenticatedChat)(props, chatSDK).then(authReconnectId => {
184
240
  if (authReconnectId && !state.appStates.reconnectId) {
@@ -197,11 +253,7 @@ const LiveChatWidgetStateful = props => {
197
253
 
198
254
  _omnichannelChatComponents.BroadcastService.postMessage(chatStartedSkippingChatButtonRendering);
199
255
 
200
- dispatch({
201
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
202
- payload: _ConversationState.ConversationState.Loading
203
- });
204
- (0, _startChat.initStartChat)(chatSDK, dispatch, setAdapter);
256
+ (0, _startChat.setPreChatAndInitiateChat)(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter);
205
257
  }
206
258
  });
207
259
  }
@@ -209,7 +261,7 @@ const LiveChatWidgetStateful = props => {
209
261
  }, [state.appStates.skipChatButtonRendering]); // useEffect for when skip chat button rendering
210
262
 
211
263
  (0, _react2.useEffect)(() => {
212
- var _chatSDK$omnichannelC3, _chatSDK$omnichannelC4;
264
+ var _chatSDK$omnichannelC5, _chatSDK$omnichannelC6, _props$controlProps10;
213
265
 
214
266
  // Add the custom context on receiving the SetCustomContext event
215
267
  _omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.SetCustomContext).subscribe(msg => {
@@ -244,27 +296,39 @@ const LiveChatWidgetStateful = props => {
244
296
 
245
297
 
246
298
  _omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.StartChat).subscribe(() => {
247
- var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _DataStoreManager$cli;
299
+ var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _props$controlProps8;
248
300
 
249
301
  _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
250
302
  Event: _TelemetryConstants.TelemetryEvent.StartChatEventRecevied,
251
303
  Description: "Start chat event received."
252
- }); // Getting updated state from cache
253
-
304
+ });
254
305
 
255
- const widgetStateEventName = (0, _utils.getWidgetCacheId)((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) ?? "");
256
- const widgetStateFromCache = (_DataStoreManager$cli = _DataStoreManager.DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.getData(widgetStateEventName, "localStorage");
257
- const persistedState = widgetStateFromCache ? JSON.parse(widgetStateFromCache) : undefined;
306
+ 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, (props === null || props === void 0 ? void 0 : (_props$controlProps8 = props.controlProps) === null || _props$controlProps8 === void 0 ? void 0 : _props$controlProps8.widgetInstanceId) ?? ""); // Chat not found in cache
258
307
 
259
- if (persistedState.appStates.conversationState === _ConversationState.ConversationState.Closed || persistedState.appStates.conversationState === _ConversationState.ConversationState.InActive || persistedState.appStates.conversationState === _ConversationState.ConversationState.Postchat) {
308
+ if (persistedState === undefined) {
260
309
  _omnichannelChatComponents.BroadcastService.postMessage({
261
310
  eventName: _TelemetryConstants.BroadcastEvent.ChatInitiated
262
311
  });
263
312
 
264
313
  (0, _startChat.prepareStartChat)(props, chatSDK, state, dispatch, setAdapter);
265
- } else {
314
+ return;
315
+ } // Chat exist in cache
316
+
317
+
318
+ if (persistedState) {
266
319
  var _persistedState$domai, _persistedState$domai2, _persistedState$domai3, _persistedState$domai4;
267
320
 
321
+ // Only initiate new chat if widget state in cache in one of the followings
322
+ if (persistedState.appStates.conversationState === _ConversationState.ConversationState.Closed || persistedState.appStates.conversationState === _ConversationState.ConversationState.InActive || persistedState.appStates.conversationState === _ConversationState.ConversationState.Postchat) {
323
+ _omnichannelChatComponents.BroadcastService.postMessage({
324
+ eventName: _TelemetryConstants.BroadcastEvent.ChatInitiated
325
+ });
326
+
327
+ (0, _startChat.prepareStartChat)(props, chatSDK, state, dispatch, setAdapter);
328
+ return;
329
+ } // If minimized, maximize the chat
330
+
331
+
268
332
  dispatch({
269
333
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_MINIMIZED,
270
334
  payload: false
@@ -281,73 +345,44 @@ const LiveChatWidgetStateful = props => {
281
345
  }); // End chat
282
346
 
283
347
 
284
- _omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.InitiateEndChat).subscribe(async msg => {
285
- var _msg$payload4, _msg$payload5;
286
-
287
- const isChatUnloading = ((_msg$payload4 = msg.payload) === null || _msg$payload4 === void 0 ? void 0 : _msg$payload4.chatUnloading) ?? false;
288
- const isSdkCall = ((_msg$payload5 = msg.payload) === null || _msg$payload5 === void 0 ? void 0 : _msg$payload5.isSdkCall) ?? false;
289
- const eventDescription = isChatUnloading ? "End chat event received from unload." : "End chat event received.";
290
-
291
- _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
292
- Event: _TelemetryConstants.TelemetryEvent.EndChatEventReceived,
293
- Description: eventDescription
294
- });
295
-
296
- if (isChatUnloading) {
297
- var _DataStoreManager$cli2;
298
-
299
- //Browser close scenario/no room for PCS/so just end chat and notify agent immidiately
300
- (0, _endChat.endChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, false); // Clean local storage
301
-
302
- (_DataStoreManager$cli2 = _DataStoreManager.DataStoreManager.clientDataStore) === null || _DataStoreManager$cli2 === void 0 ? void 0 : _DataStoreManager$cli2.removeData(widgetStateEventName, "localStorage");
303
- } else if (canEndChat.current) {
304
- (0, _endChat.prepareEndChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state);
305
- } else {
306
- const skipEndChatSDK = true;
307
- const skipCloseChat = false;
308
- (0, _endChat.endChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat);
309
- } // Raise chatClose for SDK events
348
+ _omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.InitiateEndChat).subscribe(async () => {
349
+ if (state.appStates.skipChatButtonRendering !== true) {
350
+ var _chatSDK$omnichannelC3, _chatSDK$omnichannelC4, _props$controlProps9;
310
351
 
352
+ // This is to ensure to get latest state from cache in multitab
353
+ 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, (props === null || props === void 0 ? void 0 : (_props$controlProps9 = props.controlProps) === null || _props$controlProps9 === void 0 ? void 0 : _props$controlProps9.widgetInstanceId) ?? "");
311
354
 
312
- if (isSdkCall) {
313
- _omnichannelChatComponents.BroadcastService.postMessage({
314
- eventName: _TelemetryConstants.BroadcastEvent.CloseChat
315
- });
355
+ if (persistedState && persistedState.appStates.conversationState === _ConversationState.ConversationState.Active) {
356
+ (0, _endChat.prepareEndChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state);
357
+ } else {
358
+ const skipEndChatSDK = true;
359
+ const skipCloseChat = false;
360
+ (0, _endChat.endChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat);
361
+ }
316
362
  }
317
- }); // reset proactive chat params
318
-
319
363
 
320
- _omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.ResetProactiveChatParams).subscribe(async () => {
321
- dispatch({
322
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_PROACTIVE_CHAT_PARAMS,
323
- payload: {
324
- proactiveChatBodyTitle: "",
325
- proactiveChatEnablePrechat: false,
326
- proactiveChatInNewWindow: false
327
- }
364
+ _omnichannelChatComponents.BroadcastService.postMessage({
365
+ eventName: _TelemetryConstants.BroadcastEvent.CloseChat
328
366
  });
367
+ }); // End chat on browser unload
368
+
369
+
370
+ _omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.InitiateEndChatOnBrowserUnload).subscribe(() => {
371
+ initiateEndChatOnBrowserUnload();
329
372
  }); // Listen to end chat event from other tabs
330
373
 
331
374
 
332
- const endChatEventName = (0, _utils.getWidgetEndChatEventName)(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);
375
+ const endChatEventName = (0, _utils.getWidgetEndChatEventName)(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, ((_props$controlProps10 = props.controlProps) === null || _props$controlProps10 === void 0 ? void 0 : _props$controlProps10.widgetInstanceId) ?? "");
333
376
 
334
377
  _omnichannelChatComponents.BroadcastService.getMessageByEventName(endChatEventName).subscribe(async () => {
335
378
  (0, _endChat.endChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, false);
336
- }); // Close popout window
379
+ return;
380
+ }); // When conversation ended by agent
337
381
 
338
382
 
339
- window.addEventListener("beforeunload", () => {
340
- _TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.INFO, {
341
- Event: _TelemetryConstants.TelemetryEvent.WindowClosed,
342
- Description: "Closed window."
343
- });
344
-
345
- (0, _disposeTelemetryLoggers.disposeTelemetryLoggers)();
346
- });
347
-
348
383
  if (state.appStates.conversationEndedByAgent) {
349
384
  (0, _endChat.endChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter);
350
- } //Listen to WidgetSize
385
+ } //Listen to WidgetSize, used for minimize to maximize
351
386
 
352
387
 
353
388
  _omnichannelChatComponents.BroadcastService.getMessageByEventName("WidgetSize").subscribe(msg => {
@@ -356,25 +391,24 @@ const LiveChatWidgetStateful = props => {
356
391
  payload: msg === null || msg === void 0 ? void 0 : msg.payload
357
392
  });
358
393
  });
394
+
395
+ return () => {
396
+ (0, _disposeTelemetryLoggers.disposeTelemetryLoggers)();
397
+ };
359
398
  }, []);
360
399
  (0, _react2.useEffect)(() => {
361
- canEndChat.current = state.appStates.conversationState === _ConversationState.ConversationState.Active;
362
-
363
- if (state.appStates.conversationState === _ConversationState.ConversationState.Active) {
364
- chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.onNewMessage(() => {
365
- _omnichannelChatComponents.BroadcastService.postMessage({
366
- eventName: _TelemetryConstants.BroadcastEvent.NewMessageNotification
367
- });
368
- });
369
- } // Track the message count
370
-
371
-
400
+ // On new message
372
401
  if (state.appStates.conversationState === _ConversationState.ConversationState.Active) {
373
402
  chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.onNewMessage(() => {
403
+ // Track the message count
374
404
  currentMessageCountRef.current++;
375
405
  dispatch({
376
406
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_UNREAD_MESSAGE_COUNT,
377
407
  payload: currentMessageCountRef.current + 1
408
+ }); // New message notification
409
+
410
+ _omnichannelChatComponents.BroadcastService.postMessage({
411
+ eventName: _TelemetryConstants.BroadcastEvent.NewMessageNotification
378
412
  });
379
413
  });
380
414
  }
@@ -384,6 +418,12 @@ const LiveChatWidgetStateful = props => {
384
418
  }, [state.appStates.conversationState, state.appStates.proactiveChatStates.proactiveChatInNewWindow]); // Reset the UnreadMessageCount when minimized is toggled and broadcast it.
385
419
 
386
420
  (0, _react2.useEffect)(() => {
421
+ if (state.appStates.isMinimized) {
422
+ _ActivityStreamHandler.ActivityStreamHandler.cork();
423
+ } else {
424
+ setTimeout(() => _ActivityStreamHandler.ActivityStreamHandler.uncork(), 500);
425
+ }
426
+
387
427
  currentMessageCountRef.current = -1;
388
428
  dispatch({
389
429
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_UNREAD_MESSAGE_COUNT,
@@ -399,7 +439,7 @@ const LiveChatWidgetStateful = props => {
399
439
  }, [state.appStates.isMinimized]); // Broadcast the UnreadMessageCount state on any change.
400
440
 
401
441
  (0, _react2.useEffect)(() => {
402
- if (state.appStates.isMinimized && state.appStates.unreadMessageCount > 0) {
442
+ if (state.appStates.isMinimized === true && state.appStates.unreadMessageCount > 0) {
403
443
  const customEvent = {
404
444
  elementType: _omnichannelChatComponents.ElementType.Custom,
405
445
  eventName: _TelemetryConstants.BroadcastEvent.UnreadMessageCount,
@@ -418,9 +458,24 @@ const LiveChatWidgetStateful = props => {
418
458
  }, [(_props$webChatContain3 = props.webChatContainerProps) === null || _props$webChatContain3 === void 0 ? void 0 : _props$webChatContain3.webChatStyles]); // Publish chat widget state
419
459
 
420
460
  (0, _react2.useEffect)(() => {
421
- var _props$chatSDK, _props$chatSDK$omnich, _props$chatSDK2, _props$chatSDK2$omnic;
461
+ var _props$controlProps11, _props$chatSDK2, _props$chatSDK2$omnic, _props$chatSDK3, _props$chatSDK3$omnic, _props$controlProps12;
462
+
463
+ // Only activate these windows events when conversation state is active and chat widget is in popout mode
464
+ // Ghost chat scenarios
465
+ if (state.appStates.conversationState === _ConversationState.ConversationState.Active && ((_props$controlProps11 = props.controlProps) === null || _props$controlProps11 === void 0 ? void 0 : _props$controlProps11.skipChatButtonRendering) === true) {
466
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
467
+ window.onbeforeunload = function () {
468
+ const prompt = _Constants.Constants.BrowserUnloadConfirmationMessage;
469
+ return prompt;
470
+ }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
422
471
 
423
- 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);
472
+
473
+ window.onunload = function () {
474
+ initiateEndChatOnBrowserUnload();
475
+ };
476
+ }
477
+
478
+ widgetStateEventName = (0, _utils.getWidgetCacheId)(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.orgId, props === null || props === void 0 ? void 0 : (_props$chatSDK3 = props.chatSDK) === null || _props$chatSDK3 === void 0 ? void 0 : (_props$chatSDK3$omnic = _props$chatSDK3.omnichannelConfig) === null || _props$chatSDK3$omnic === void 0 ? void 0 : _props$chatSDK3$omnic.widgetId, (props === null || props === void 0 ? void 0 : (_props$controlProps12 = props.controlProps) === null || _props$controlProps12 === void 0 ? void 0 : _props$controlProps12.widgetInstanceId) ?? "");
424
479
  const chatWidgetStateChangeEvent = {
425
480
  eventName: widgetStateEventName,
426
481
  payload: { ...state
@@ -428,13 +483,13 @@ const LiveChatWidgetStateful = props => {
428
483
  };
429
484
 
430
485
  _omnichannelChatComponents.BroadcastService.postMessage(chatWidgetStateChangeEvent);
431
- }, [state]);
486
+ }, [state.appStates.conversationState]);
432
487
  const webChatProps = (0, _initWebChatComposer.initWebChatComposer)(props, chatSDK, state, dispatch, setWebChatStyles);
433
488
 
434
489
  const setPostChatContextRelay = () => (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch); // eslint-disable-next-line @typescript-eslint/no-explicit-any
435
490
 
436
491
 
437
- const endChatRelay = (adapter, skipEndChatSDK, skipCloseChat) => (0, _endChat.endChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat); // eslint-disable-next-line @typescript-eslint/no-explicit-any
492
+ const endChatRelay = (adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab) => (0, _endChat.endChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab); // eslint-disable-next-line @typescript-eslint/no-explicit-any
438
493
 
439
494
 
440
495
  const prepareEndChatRelay = (adapter, state) => (0, _endChat.prepareEndChat)(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state);
@@ -442,7 +497,7 @@ const LiveChatWidgetStateful = props => {
442
497
  const prepareStartChatRelay = () => (0, _startChat.prepareStartChat)(props, chatSDK, state, dispatch, setAdapter); // eslint-disable-next-line @typescript-eslint/no-explicit-any
443
498
 
444
499
 
445
- const initStartChatRelay = (optionalParams, persistedState) => (0, _startChat.initStartChat)(chatSDK, dispatch, setAdapter, optionalParams, persistedState);
500
+ const initStartChatRelay = (optionalParams, persistedState) => (0, _startChat.initStartChat)(chatSDK, props.chatConfig, props.getAuthToken, dispatch, setAdapter, optionalParams, persistedState);
446
501
 
447
502
  const confirmationPaneProps = (0, _initConfirmationPropsComposer.initConfirmationPropsComposer)(props);
448
503
  return /*#__PURE__*/_react2.default.createElement(Composer, _extends({}, webChatProps, {
@@ -452,29 +507,29 @@ const LiveChatWidgetStateful = props => {
452
507
  id: widgetElementId,
453
508
  styles: generalStyles,
454
509
  className: (_props$styleProps2 = props.styleProps) === null || _props$styleProps2 === void 0 ? void 0 : _props$styleProps2.className
455
- }, !((_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, {
510
+ }, !((_props$controlProps13 = props.controlProps) !== null && _props$controlProps13 !== void 0 && _props$controlProps13.hideChatButton) && !((_props$controlProps14 = props.controlProps) !== null && _props$controlProps14 !== void 0 && _props$controlProps14.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, {
456
511
  buttonProps: props.chatButtonProps,
457
512
  outOfOfficeButtonProps: props.outOfOfficeChatButtonProps,
458
513
  startChat: prepareStartChatRelay
459
- })), !((_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, {
514
+ })), !((_props$controlProps15 = props.controlProps) !== null && _props$controlProps15 !== void 0 && _props$controlProps15.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, {
460
515
  proactiveChatProps: props.proactiveChatPaneProps,
461
516
  startChat: prepareStartChatRelay
462
- })), !((_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, {
517
+ })), !((_props$controlProps16 = props.controlProps) !== null && _props$controlProps16 !== void 0 && _props$controlProps16.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, {
463
518
  headerProps: props.headerProps,
464
519
  outOfOfficeHeaderProps: props.outOfOfficeHeaderProps,
465
520
  endChat: endChatRelay
466
- })), !((_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, {
521
+ })), !((_props$controlProps17 = props.controlProps) !== null && _props$controlProps17 !== void 0 && _props$controlProps17.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$controlProps18 = props.controlProps) !== null && _props$controlProps18 !== void 0 && _props$controlProps18.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$controlProps19 = props.controlProps) !== null && _props$controlProps19 !== void 0 && _props$controlProps19.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, {
467
522
  reconnectChatProps: props.reconnectChatPaneProps,
468
523
  initStartChat: initStartChatRelay
469
- })), !((_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, {
524
+ })), !((_props$controlProps20 = props.controlProps) !== null && _props$controlProps20 !== void 0 && _props$controlProps20.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, {
470
525
  surveyProps: props.preChatSurveyPaneProps,
471
526
  initStartChat: initStartChatRelay
472
- })), !((_props$controlProps12 = props.controlProps) !== null && _props$controlProps12 !== void 0 && _props$controlProps12.hideCallingContainer) && (0, _componentController.shouldShowCallingContainer)(state) && /*#__PURE__*/_react2.default.createElement(_CallingContainerStateful.default, _extends({
527
+ })), !((_props$controlProps21 = props.controlProps) !== null && _props$controlProps21 !== void 0 && _props$controlProps21.hideCallingContainer) && (0, _componentController.shouldShowCallingContainer)(state) && /*#__PURE__*/_react2.default.createElement(_CallingContainerStateful.default, _extends({
473
528
  voiceVideoCallingSdk: voiceVideoCallingSDK
474
- }, 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, {
529
+ }, props.callingContainerProps)), !((_props$controlProps22 = props.controlProps) !== null && _props$controlProps22 !== void 0 && _props$controlProps22.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$controlProps23 = props.controlProps) !== null && _props$controlProps23 !== void 0 && _props$controlProps23.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, {
475
530
  setPostChatContext: setPostChatContextRelay,
476
531
  prepareEndChat: prepareEndChatRelay
477
- }))), !((_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))));
532
+ }))), !((_props$controlProps24 = props.controlProps) !== null && _props$controlProps24 !== void 0 && _props$controlProps24.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))));
478
533
  };
479
534
 
480
535
  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) ?? "", state.domainStates.widgetInstanceId ?? "");
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 = {
@@ -133,7 +133,7 @@ const ProactiveChatPaneStateful = props => {
133
133
  });
134
134
  },
135
135
  ...(proactiveChatProps === null || proactiveChatProps === void 0 ? void 0 : proactiveChatProps.controlProps),
136
- 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
137
137
  };
138
138
  (0, _react.useEffect)(() => {
139
139
  (0, _utils.setFocusOnElement)(document.getElementById(controlProps.id + "-startbutton"));
@@ -14,6 +14,8 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
14
14
  class MockChatSDK {
15
15
  constructor() {
16
16
  _defineProperty(this, "sleep", ms => new Promise(r => setTimeout(r, ms)));
17
+
18
+ _defineProperty(this, "isMockModeOn", true);
17
19
  }
18
20
 
19
21
  async startChat() {
@@ -15,6 +15,7 @@ exports.ConversationState = ConversationState;
15
15
  ConversationState[ConversationState["ProactiveChat"] = 4] = "ProactiveChat";
16
16
  ConversationState[ConversationState["Active"] = 5] = "Active";
17
17
  ConversationState[ConversationState["InActive"] = 6] = "InActive";
18
- ConversationState[ConversationState["Postchat"] = 7] = "Postchat";
19
- ConversationState[ConversationState["Closed"] = 8] = "Closed";
18
+ ConversationState[ConversationState["PostchatLoading"] = 7] = "PostchatLoading";
19
+ ConversationState[ConversationState["Postchat"] = 8] = "Postchat";
20
+ ConversationState[ConversationState["Closed"] = 9] = "Closed";
20
21
  })(ConversationState || (exports.ConversationState = ConversationState = {}));
@@ -41,4 +41,5 @@ exports.LiveChatWidgetActionType = LiveChatWidgetActionType;
41
41
  LiveChatWidgetActionType[LiveChatWidgetActionType["SET_LIVE_CHAT_CONTEXT"] = 30] = "SET_LIVE_CHAT_CONTEXT";
42
42
  LiveChatWidgetActionType[LiveChatWidgetActionType["SET_BOT_OAUTH_SIGNIN_ID"] = 31] = "SET_BOT_OAUTH_SIGNIN_ID";
43
43
  LiveChatWidgetActionType[LiveChatWidgetActionType["SET_WIDGET_SIZE"] = 32] = "SET_WIDGET_SIZE";
44
+ LiveChatWidgetActionType[LiveChatWidgetActionType["SET_WIDGET_INSTANCE_ID"] = 33] = "SET_WIDGET_INSTANCE_ID";
44
45
  })(LiveChatWidgetActionType || (exports.LiveChatWidgetActionType = LiveChatWidgetActionType = {}));
@@ -29,14 +29,14 @@ const getLiveChatWidgetContextInitialState = props => {
29
29
  globalDir: "ltr",
30
30
  liveChatContext: undefined,
31
31
  customContext: undefined,
32
- widgetSize: undefined
32
+ widgetSize: undefined,
33
+ widgetInstanceId: ""
33
34
  },
34
35
  appStates: {
35
36
  conversationState: _ConversationState.ConversationState.Closed,
36
37
  isMinimized: false,
37
38
  previousElementOnFocusBeforeModalOpen: null,
38
39
  outsideOperatingHours: false,
39
- shouldShowPostChat: false,
40
40
  preChatResponseEmail: "",
41
41
  isAudioMuted: null,
42
42
  newMessage: false,
@@ -243,6 +243,14 @@ const createReducer = () => {
243
243
  }
244
244
  };
245
245
 
246
+ case _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_WIDGET_INSTANCE_ID:
247
+ return { ...state,
248
+ domainStates: { ...state.domainStates,
249
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
250
+ widgetInstanceId: action.payload
251
+ }
252
+ };
253
+
246
254
  default:
247
255
  return state;
248
256
  }