@microsoft/omnichannel-chat-widget 1.7.4-main.562254b → 1.7.4-main.8d43b20

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 (88) hide show
  1. package/lib/cjs/common/facades/FacadeChatSDK.js +298 -0
  2. package/lib/cjs/common/facades/types/IFacadeChatSDKInput.js +1 -0
  3. package/lib/cjs/common/telemetry/TelemetryConstants.js +5 -0
  4. package/lib/cjs/common/telemetry/TelemetryHelper.js +10 -0
  5. package/lib/cjs/common/utils.js +2 -2
  6. package/lib/cjs/components/callingcontainerstateful/CallingContainerStateful.js +4 -8
  7. package/lib/cjs/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.js +5 -6
  8. package/lib/cjs/components/footerstateful/FooterStateful.js +4 -5
  9. package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +8 -10
  10. package/lib/cjs/components/livechatwidget/LiveChatWidget.js +26 -3
  11. package/lib/cjs/components/livechatwidget/common/authHelper.js +14 -5
  12. package/lib/cjs/components/livechatwidget/common/createAdapter.js +9 -9
  13. package/lib/cjs/components/livechatwidget/common/endChat.js +21 -22
  14. package/lib/cjs/components/livechatwidget/common/initCallingSdk.js +3 -3
  15. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +3 -3
  16. package/lib/cjs/components/livechatwidget/common/liveChatConfigUtils.js +2 -3
  17. package/lib/cjs/components/livechatwidget/common/persistentChatHelper.js +4 -4
  18. package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +11 -12
  19. package/lib/cjs/components/livechatwidget/common/renderSurveyHelpers.js +5 -5
  20. package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +4 -4
  21. package/lib/cjs/components/livechatwidget/common/startChat.js +42 -36
  22. package/lib/cjs/components/livechatwidget/common/startChatErrorHandler.js +7 -7
  23. package/lib/cjs/components/livechatwidget/common/updateSessionDataForTelemetry.js +8 -8
  24. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +43 -39
  25. package/lib/cjs/components/reconnectchatpanestateful/ReconnectChatPaneStateful.js +4 -2
  26. package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +4 -1
  27. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/typingIndicatorMiddleware.js +4 -4
  28. package/lib/cjs/contexts/FacadeChatSDKStore.js +10 -0
  29. package/lib/cjs/hooks/useFacadeChatSDKStore.js +17 -0
  30. package/lib/cjs/index.js +9 -2
  31. package/lib/cjs/plugins/createChatTranscript.js +2 -2
  32. package/lib/esm/common/facades/FacadeChatSDK.js +291 -0
  33. package/lib/esm/common/facades/types/IFacadeChatSDKInput.js +1 -0
  34. package/lib/esm/common/telemetry/TelemetryConstants.js +5 -0
  35. package/lib/esm/common/telemetry/TelemetryHelper.js +10 -0
  36. package/lib/esm/common/utils.js +2 -2
  37. package/lib/esm/components/callingcontainerstateful/CallingContainerStateful.js +4 -8
  38. package/lib/esm/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.js +5 -6
  39. package/lib/esm/components/footerstateful/FooterStateful.js +4 -5
  40. package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +8 -10
  41. package/lib/esm/components/livechatwidget/LiveChatWidget.js +26 -3
  42. package/lib/esm/components/livechatwidget/common/authHelper.js +14 -5
  43. package/lib/esm/components/livechatwidget/common/createAdapter.js +9 -9
  44. package/lib/esm/components/livechatwidget/common/endChat.js +21 -22
  45. package/lib/esm/components/livechatwidget/common/initCallingSdk.js +3 -3
  46. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +3 -3
  47. package/lib/esm/components/livechatwidget/common/liveChatConfigUtils.js +2 -4
  48. package/lib/esm/components/livechatwidget/common/persistentChatHelper.js +4 -4
  49. package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +11 -12
  50. package/lib/esm/components/livechatwidget/common/renderSurveyHelpers.js +5 -5
  51. package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +4 -4
  52. package/lib/esm/components/livechatwidget/common/startChat.js +42 -36
  53. package/lib/esm/components/livechatwidget/common/startChatErrorHandler.js +7 -7
  54. package/lib/esm/components/livechatwidget/common/updateSessionDataForTelemetry.js +8 -8
  55. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +43 -39
  56. package/lib/esm/components/reconnectchatpanestateful/ReconnectChatPaneStateful.js +4 -2
  57. package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +4 -1
  58. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/typingIndicatorMiddleware.js +4 -4
  59. package/lib/esm/contexts/FacadeChatSDKStore.js +4 -0
  60. package/lib/esm/hooks/useFacadeChatSDKStore.js +10 -0
  61. package/lib/esm/index.js +5 -4
  62. package/lib/esm/plugins/createChatTranscript.js +2 -2
  63. package/lib/types/common/facades/FacadeChatSDK.d.ts +71 -0
  64. package/lib/types/common/facades/types/IFacadeChatSDKInput.d.ts +13 -0
  65. package/lib/types/common/telemetry/TelemetryConstants.d.ts +6 -1
  66. package/lib/types/common/telemetry/TelemetryHelper.d.ts +1 -0
  67. package/lib/types/common/telemetry/definitions/Payload.d.ts +6 -0
  68. package/lib/types/common/utils.d.ts +2 -1
  69. package/lib/types/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.d.ts +3 -2
  70. package/lib/types/components/livechatwidget/common/authHelper.d.ts +14 -1
  71. package/lib/types/components/livechatwidget/common/createAdapter.d.ts +2 -1
  72. package/lib/types/components/livechatwidget/common/endChat.d.ts +4 -3
  73. package/lib/types/components/livechatwidget/common/initCallingSdk.d.ts +2 -1
  74. package/lib/types/components/livechatwidget/common/initWebChatComposer.d.ts +2 -1
  75. package/lib/types/components/livechatwidget/common/liveChatConfigUtils.d.ts +2 -1
  76. package/lib/types/components/livechatwidget/common/persistentChatHelper.d.ts +1 -1
  77. package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +3 -2
  78. package/lib/types/components/livechatwidget/common/renderSurveyHelpers.d.ts +2 -1
  79. package/lib/types/components/livechatwidget/common/setPostChatContextAndLoadSurvey.d.ts +2 -1
  80. package/lib/types/components/livechatwidget/common/startChat.d.ts +5 -4
  81. package/lib/types/components/livechatwidget/common/startChatErrorHandler.d.ts +2 -1
  82. package/lib/types/components/livechatwidget/common/updateSessionDataForTelemetry.d.ts +2 -1
  83. package/lib/types/components/webchatcontainerstateful/common/mockchatsdk.d.ts +2 -1
  84. package/lib/types/contexts/FacadeChatSDKStore.d.ts +1 -0
  85. package/lib/types/hooks/useFacadeChatSDKStore.d.ts +3 -0
  86. package/lib/types/index.d.ts +4 -3
  87. package/lib/types/plugins/createChatTranscript.d.ts +2 -1
  88. package/package.json +1 -1
@@ -26,27 +26,27 @@ let widgetInstanceId;
26
26
  let popoutWidgetInstanceId;
27
27
 
28
28
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
- const setAuthenticationIfApplicable = async (props, chatSDK) => {
29
+ const setAuthenticationIfApplicable = async (props, facadeChatSDK) => {
30
30
  const chatConfig = props === null || props === void 0 ? void 0 : props.chatConfig;
31
31
  const getAuthToken = props === null || props === void 0 ? void 0 : props.getAuthToken;
32
32
  const authClientFunction = getAuthClientFunction(chatConfig);
33
33
  if (getAuthToken && authClientFunction) {
34
34
  // set auth token to chat sdk before start chat
35
- const authSuccess = await handleAuthentication(chatSDK, chatConfig, getAuthToken);
36
- if (!authSuccess) {
35
+ const authSuccess = await handleAuthentication(facadeChatSDK.getChatSDK(), chatConfig, getAuthToken);
36
+ if (!authSuccess.result) {
37
37
  throw new Error(WidgetLoadCustomErrorString.AuthenticationFailedErrorString);
38
38
  }
39
39
  }
40
40
  };
41
41
 
42
42
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
43
- const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) => {
43
+ const prepareStartChat = async (props, facadeChatSDK, state, dispatch, setAdapter) => {
44
44
  optionalParams = {}; //Resetting to ensure no stale values
45
45
  widgetInstanceId = getWidgetCacheIdfromProps(props);
46
46
 
47
47
  // reconnect > chat from cache
48
48
  if (isReconnectEnabled(props.chatConfig) === true && !isPersistentEnabled(props.chatConfig)) {
49
- const shouldStartChatNormally = await handleChatReconnect(chatSDK, props, dispatch, setAdapter, initStartChat, state);
49
+ const shouldStartChatNormally = await handleChatReconnect(facadeChatSDK, props, dispatch, setAdapter, initStartChat, state);
50
50
  if (!shouldStartChatNormally) {
51
51
  return;
52
52
  }
@@ -58,7 +58,7 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
58
58
  }
59
59
 
60
60
  // Can connect to existing chat session
61
- if (await canConnectToExistingChat(props, chatSDK, state, dispatch, setAdapter)) {
61
+ if (await canConnectToExistingChat(props, facadeChatSDK, state, dispatch, setAdapter)) {
62
62
  return;
63
63
  }
64
64
 
@@ -68,26 +68,30 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
68
68
 
69
69
  // Setting auth settings to OC API to retrieve existing persistent chat session before start chat if any
70
70
  if (isPersistentEnabled(props.chatConfig)) {
71
- await setAuthenticationIfApplicable(props, chatSDK);
71
+ await setAuthenticationIfApplicable(props, facadeChatSDK);
72
72
  }
73
73
 
74
74
  //Setting PreChat and intiate chat
75
- await setPreChatAndInitiateChat(chatSDK, dispatch, setAdapter, isProactiveChat, isPreChatEnabledInProactiveChat, state, props);
75
+ await setPreChatAndInitiateChat(facadeChatSDK, dispatch, setAdapter, isProactiveChat, isPreChatEnabledInProactiveChat, state, props);
76
76
  };
77
77
 
78
78
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
79
- const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProactiveChat, proactiveChatEnablePrechatState, state, props) => {
79
+ const setPreChatAndInitiateChat = async (facadeChatSDK, dispatch, setAdapter, isProactiveChat, proactiveChatEnablePrechatState, state, props) => {
80
80
  var _props$preChatSurveyP, _props$preChatSurveyP2, _props$controlProps, _state$domainStates, _state$domainStates$l, _state$domainStates$l2;
81
- //Handle reconnect scenario
81
+ // This reset needs to be done before to load prechat, because the conversation state changes from close to prechat
82
+ if ((state === null || state === void 0 ? void 0 : state.appStates.conversationState) === ConversationState.Closed) {
83
+ // Preventive reset to avoid starting chat with previous requestId which could potentially cause problems
84
+ chatSDKStateCleanUp(facadeChatSDK.getChatSDK());
85
+ }
82
86
 
83
87
  // Getting prechat Survey Context
84
88
  const parseToJson = false;
85
- const preChatSurveyResponse = (props === null || props === void 0 ? void 0 : (_props$preChatSurveyP = props.preChatSurveyPaneProps) === null || _props$preChatSurveyP === void 0 ? void 0 : (_props$preChatSurveyP2 = _props$preChatSurveyP.controlProps) === null || _props$preChatSurveyP2 === void 0 ? void 0 : _props$preChatSurveyP2.payload) ?? (await chatSDK.getPreChatSurvey(parseToJson));
89
+ const preChatSurveyResponse = (props === null || props === void 0 ? void 0 : (_props$preChatSurveyP = props.preChatSurveyPaneProps) === null || _props$preChatSurveyP === void 0 ? void 0 : (_props$preChatSurveyP2 = _props$preChatSurveyP.controlProps) === null || _props$preChatSurveyP2 === void 0 ? void 0 : _props$preChatSurveyP2.payload) ?? (await facadeChatSDK.getPreChatSurvey(parseToJson));
86
90
  let showPrechat = isProactiveChat ? preChatSurveyResponse && proactiveChatEnablePrechatState : preChatSurveyResponse && !(props !== null && props !== void 0 && (_props$controlProps = props.controlProps) !== null && _props$controlProps !== void 0 && _props$controlProps.hidePreChatSurveyPane);
87
- showPrechat = await shouldSetPreChatIfPersistentChat(chatSDK, state === null || state === void 0 ? void 0 : (_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : (_state$domainStates$l = _state$domainStates.liveChatConfig) === null || _state$domainStates$l === void 0 ? void 0 : (_state$domainStates$l2 = _state$domainStates$l.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l2 === void 0 ? void 0 : _state$domainStates$l2.msdyn_conversationmode, showPrechat);
91
+ showPrechat = await shouldSetPreChatIfPersistentChat(facadeChatSDK.getChatSDK(), state === null || state === void 0 ? void 0 : (_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : (_state$domainStates$l = _state$domainStates.liveChatConfig) === null || _state$domainStates$l === void 0 ? void 0 : (_state$domainStates$l2 = _state$domainStates$l.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l2 === void 0 ? void 0 : _state$domainStates$l2.msdyn_conversationmode, showPrechat);
88
92
  if (showPrechat) {
89
93
  var _state$domainStates2, _state$domainStates2$, _state$domainStates2$2, _state$domainStates2$3;
90
- const isOutOfOperatingHours = (state === null || state === void 0 ? void 0 : (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : (_state$domainStates2$ = _state$domainStates2.liveChatConfig) === null || _state$domainStates2$ === void 0 ? void 0 : (_state$domainStates2$2 = _state$domainStates2$.LiveWSAndLiveChatEngJoin) === null || _state$domainStates2$2 === void 0 ? void 0 : (_state$domainStates2$3 = _state$domainStates2$2.OutOfOperatingHours) === null || _state$domainStates2$3 === void 0 ? void 0 : _state$domainStates2$3.toLowerCase()) === "true";
94
+ const isOutOfOperatingHours = (state === null || state === void 0 ? void 0 : (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : (_state$domainStates2$ = _state$domainStates2.liveChatConfig) === null || _state$domainStates2$ === void 0 ? void 0 : (_state$domainStates2$2 = _state$domainStates2$.LiveWSAndLiveChatEngJoin) === null || _state$domainStates2$2 === void 0 ? void 0 : (_state$domainStates2$3 = _state$domainStates2$2.OutOfOperatingHours) === null || _state$domainStates2$3 === void 0 ? void 0 : _state$domainStates2$3.toString().toLowerCase()) === "true";
91
95
  if (isOutOfOperatingHours) {
92
96
  (state === null || state === void 0 ? void 0 : state.appStates.isMinimized) && dispatch({
93
97
  type: LiveChatWidgetActionType.SET_MINIMIZED,
@@ -138,17 +142,17 @@ const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProact
138
142
  const optionalParams = {
139
143
  isProactiveChat
140
144
  };
141
- await initStartChat(chatSDK, dispatch, setAdapter, state, props, optionalParams);
145
+ await initStartChat(facadeChatSDK, dispatch, setAdapter, state, props, optionalParams);
142
146
  };
143
147
 
144
148
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
145
- const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params, persistedState) => {
149
+ const initStartChat = async (facadeChatSDK, dispatch, setAdapter, state, props, params, persistedState) => {
146
150
  var _state$domainStates5, _state$domainStates5$, _state$domainStates5$2;
147
151
  let isStartChatSuccessful = false;
148
152
  const persistentChatEnabled = await isPersistentChatEnabled(state === null || state === void 0 ? void 0 : (_state$domainStates5 = state.domainStates) === null || _state$domainStates5 === void 0 ? void 0 : (_state$domainStates5$ = _state$domainStates5.liveChatConfig) === null || _state$domainStates5$ === void 0 ? void 0 : (_state$domainStates5$2 = _state$domainStates5$.LiveWSAndLiveChatEngJoin) === null || _state$domainStates5$2 === void 0 ? void 0 : _state$domainStates5$2.msdyn_conversationmode);
149
153
  if ((state === null || state === void 0 ? void 0 : state.appStates.conversationState) === ConversationState.Closed) {
150
154
  // Preventive reset to avoid starting chat with previous requestId which could potentially cause problems
151
- chatSDKStateCleanUp(chatSDK);
155
+ chatSDKStateCleanUp(facadeChatSDK.getChatSDK());
152
156
  }
153
157
  try {
154
158
  var _state$appStates2;
@@ -166,7 +170,7 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
166
170
  });
167
171
 
168
172
  // Auth token retrieval needs to happen during start chat to support pop-out chat
169
- await setAuthenticationIfApplicable(props, chatSDK);
173
+ await setAuthenticationIfApplicable(props, facadeChatSDK);
170
174
 
171
175
  //Check if chat retrieved from cache
172
176
  if (persistedState || params !== null && params !== void 0 && params.liveChatContext) {
@@ -189,7 +193,7 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
189
193
  portalContactId: (_window$Microsoft = window.Microsoft) === null || _window$Microsoft === void 0 ? void 0 : (_window$Microsoft$Dyn = _window$Microsoft.Dynamic365) === null || _window$Microsoft$Dyn === void 0 ? void 0 : (_window$Microsoft$Dyn2 = _window$Microsoft$Dyn.Portal) === null || _window$Microsoft$Dyn2 === void 0 ? void 0 : (_window$Microsoft$Dyn3 = _window$Microsoft$Dyn2.User) === null || _window$Microsoft$Dyn3 === void 0 ? void 0 : _window$Microsoft$Dyn3.contactId
190
194
  };
191
195
  const startChatOptionalParams = Object.assign({}, params, optionalParams, defaultOptionalParams);
192
- await chatSDK.startChat(startChatOptionalParams);
196
+ await facadeChatSDK.startChat(startChatOptionalParams);
193
197
  isStartChatSuccessful = true;
194
198
  } catch (error) {
195
199
  checkContactIdError(error);
@@ -208,7 +212,7 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
208
212
  isStartChatSuccessful = false;
209
213
  throw error;
210
214
  }
211
- await createAdapterAndSubscribe(chatSDK, dispatch, setAdapter, props);
215
+ await createAdapterAndSubscribe(facadeChatSDK, dispatch, setAdapter, props);
212
216
 
213
217
  // Set app state to Active
214
218
  if (isStartChatSuccessful) {
@@ -230,14 +234,14 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
230
234
  });
231
235
  logWidgetLoadComplete(WidgetLoadTelemetryMessage.PersistedStateRetrievedMessage);
232
236
  // Set post chat context in state, load in background to do not block the load
233
- setPostChatContextAndLoadSurvey(chatSDK, dispatch, true);
237
+ setPostChatContextAndLoadSurvey(facadeChatSDK, dispatch, true);
234
238
  return;
235
239
  }
236
240
 
237
241
  // Persistent Chat relies on the `reconnectId` retrieved from reconnectablechats API to reconnect upon start chat and not `liveChatContext`
238
242
  if (!persistentChatEnabled) {
239
243
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
240
- const liveChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
244
+ const liveChatContext = await (facadeChatSDK === null || facadeChatSDK === void 0 ? void 0 : facadeChatSDK.getCurrentLiveChatContext());
241
245
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
242
246
  dispatch({
243
247
  type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
@@ -246,11 +250,11 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
246
250
  }
247
251
  logWidgetLoadComplete();
248
252
  // Set post chat context in state, load in background to do not block the load
249
- setPostChatContextAndLoadSurvey(chatSDK, dispatch);
253
+ setPostChatContextAndLoadSurvey(facadeChatSDK, dispatch);
250
254
  // Updating chat session detail for telemetry
251
- await updateTelemetryData(chatSDK, dispatch);
255
+ await updateTelemetryData(facadeChatSDK, dispatch);
252
256
  } catch (ex) {
253
- handleStartChatError(dispatch, chatSDK, props, ex, isStartChatSuccessful);
257
+ handleStartChatError(dispatch, facadeChatSDK, props, ex, isStartChatSuccessful);
254
258
  } finally {
255
259
  optionalParams = {};
256
260
  widgetInstanceId = "";
@@ -258,20 +262,22 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, state, props, params
258
262
  };
259
263
 
260
264
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
261
- const createAdapterAndSubscribe = async (chatSDK, dispatch, setAdapter, props) => {
262
- var _newAdapter$activity$;
265
+ const createAdapterAndSubscribe = async (facadeChatSDK, dispatch, setAdapter, props) => {
263
266
  // New adapter creation
264
- const newAdapter = await createAdapter(chatSDK, props);
267
+ const newAdapter = await createAdapter(facadeChatSDK, props);
265
268
  setAdapter(newAdapter);
266
- const chatToken = await chatSDK.getChatToken();
269
+ const chatToken = await (facadeChatSDK === null || facadeChatSDK === void 0 ? void 0 : facadeChatSDK.getChatToken());
267
270
  dispatch({
268
271
  type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
269
272
  payload: chatToken
270
273
  });
271
- newAdapter === null || newAdapter === void 0 ? void 0 : (_newAdapter$activity$ = newAdapter.activity$) === null || _newAdapter$activity$ === void 0 ? void 0 : _newAdapter$activity$.subscribe(createOnNewAdapterActivityHandler(chatToken === null || chatToken === void 0 ? void 0 : chatToken.chatId, chatToken === null || chatToken === void 0 ? void 0 : chatToken.visitorId));
274
+ if (chatToken !== null && chatToken !== void 0 && chatToken.chatId && chatToken !== null && chatToken !== void 0 && chatToken.visitorId) {
275
+ var _newAdapter$activity$;
276
+ newAdapter === null || newAdapter === void 0 ? void 0 : (_newAdapter$activity$ = newAdapter.activity$) === null || _newAdapter$activity$ === void 0 ? void 0 : _newAdapter$activity$.subscribe(createOnNewAdapterActivityHandler(chatToken.chatId, chatToken.visitorId));
277
+ }
272
278
  };
273
279
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
274
- const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdapter) => {
280
+ const canConnectToExistingChat = async (props, facadeChatSDK, state, dispatch, setAdapter) => {
275
281
  var _state$appStates3, _persistedState$domai6, _persistedState$appSt;
276
282
  // By pass this function in case of popout chat
277
283
  if ((state === null || state === void 0 ? void 0 : (_state$appStates3 = state.appStates) === null || _state$appStates3 === void 0 ? void 0 : _state$appStates3.hideStartChatButton) === true) {
@@ -289,7 +295,7 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
289
295
  const optionalParams = {
290
296
  liveChatContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai7 = persistedState.domainStates) === null || _persistedState$domai7 === void 0 ? void 0 : _persistedState$domai7.liveChatContext
291
297
  };
292
- await initStartChat(chatSDK, dispatch, setAdapter, state, props, optionalParams, persistedState);
298
+ await initStartChat(facadeChatSDK, dispatch, setAdapter, state, props, optionalParams, persistedState);
293
299
  return true;
294
300
  }
295
301
  return false;
@@ -354,28 +360,28 @@ const canStartPopoutChat = async props => {
354
360
  };
355
361
 
356
362
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
357
- const checkIfConversationStillValid = async (chatSDK, dispatch, state) => {
363
+ const checkIfConversationStillValid = async (facadeChatSDK, dispatch, state) => {
358
364
  var _state$domainStates8, _state$domainStates8$, _state$domainStates9;
359
365
  const requestIdFromCache = (_state$domainStates8 = state.domainStates) === null || _state$domainStates8 === void 0 ? void 0 : (_state$domainStates8$ = _state$domainStates8.liveChatContext) === null || _state$domainStates8$ === void 0 ? void 0 : _state$domainStates8$.requestId;
360
366
  const liveChatContext = state === null || state === void 0 ? void 0 : (_state$domainStates9 = state.domainStates) === null || _state$domainStates9 === void 0 ? void 0 : _state$domainStates9.liveChatContext;
361
367
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
362
368
  let conversationDetails = undefined;
363
369
  // Preserve current requestId
364
- const currentRequestId = chatSDK.requestId ?? "";
370
+ const currentRequestId = facadeChatSDK.getChatSDK().requestId ?? "";
365
371
  dispatch({
366
372
  type: LiveChatWidgetActionType.SET_INITIAL_CHAT_SDK_REQUEST_ID,
367
373
  payload: currentRequestId
368
374
  });
369
375
  try {
370
- chatSDK.requestId = requestIdFromCache;
371
- conversationDetails = await getConversationDetailsCall(chatSDK, liveChatContext);
376
+ facadeChatSDK.getChatSDK().requestId = requestIdFromCache;
377
+ conversationDetails = await getConversationDetailsCall(facadeChatSDK, liveChatContext);
372
378
  if (Object.keys(conversationDetails).length === 0 || isNullOrUndefined(conversationDetails.state) || conversationDetails.state === LiveWorkItemState.Closed || conversationDetails.state === LiveWorkItemState.WrapUp) {
373
379
  dispatch({
374
380
  type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
375
381
  payload: undefined
376
382
  });
377
383
  if (currentRequestId) {
378
- chatSDK.requestId = currentRequestId;
384
+ facadeChatSDK.getChatSDK().requestId = currentRequestId;
379
385
  }
380
386
  return false;
381
387
  }
@@ -11,7 +11,7 @@ import { TelemetryTimers } from "../../../common/telemetry/TelemetryManager";
11
11
  import { getWidgetCacheIdfromProps } from "../../../common/utils";
12
12
 
13
13
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
- export const handleStartChatError = (dispatch, chatSDK, props, ex, isStartChatSuccessful) => {
14
+ export const handleStartChatError = (dispatch, facadeChatSDK, props, ex, isStartChatSuccessful) => {
15
15
  var _props$controlProps;
16
16
  if (!ex) {
17
17
  logWidgetLoadFailed();
@@ -59,7 +59,7 @@ export const handleStartChatError = (dispatch, chatSDK, props, ex, isStartChatSu
59
59
  break;
60
60
  case ChatSDKErrorName.InvalidConversation:
61
61
  case ChatSDKErrorName.ClosedConversation:
62
- handleInvalidOrClosedConversation(dispatch, chatSDK, props, ex);
62
+ handleInvalidOrClosedConversation(dispatch, facadeChatSDK, props, ex);
63
63
  return;
64
64
  default:
65
65
  logWidgetLoadFailed(ex);
@@ -94,7 +94,7 @@ export const handleStartChatError = (dispatch, chatSDK, props, ex, isStartChatSu
94
94
  // If sessionInit was successful but LCW startchat failed due to some reason e.g adapter didn't load
95
95
  // we need to directly endChat to avoid leaving ghost chats in OC, not disturbing any other UI state
96
96
  if (isStartChatSuccessful === true) {
97
- forceEndChat(chatSDK);
97
+ forceEndChat(facadeChatSDK);
98
98
  }
99
99
  };
100
100
  const logWidgetLoadFailed = ex => {
@@ -142,7 +142,7 @@ const logWidgetLoadCompleteWithError = ex => {
142
142
  };
143
143
 
144
144
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
145
- const forceEndChat = chatSDK => {
145
+ const forceEndChat = facadeChatSDK => {
146
146
  TelemetryHelper.logSDKEvent(LogLevel.INFO, {
147
147
  Event: TelemetryEvent.PrepareEndChat,
148
148
  Description: PrepareEndChatDescriptionConstants.WidgetLoadFailedAfterSessionInit
@@ -150,7 +150,7 @@ const forceEndChat = chatSDK => {
150
150
  TelemetryHelper.logSDKEvent(LogLevel.INFO, {
151
151
  Event: TelemetryEvent.EndChatSDKCall
152
152
  });
153
- chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.endChat();
153
+ facadeChatSDK === null || facadeChatSDK === void 0 ? void 0 : facadeChatSDK.getChatSDK().endChat();
154
154
  };
155
155
  const handleWidgetUseOutsideOperatingHour = dispatch => {
156
156
  dispatch({
@@ -203,7 +203,7 @@ const handleUninitializedChatSDK = ex => {
203
203
  };
204
204
 
205
205
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
206
- const handleInvalidOrClosedConversation = (dispatch, chatSDK, props, ex) => {
206
+ const handleInvalidOrClosedConversation = (dispatch, facadeChatSDK, props, ex) => {
207
207
  var _DataStoreManager$cli;
208
208
  logWidgetLoadCompleteWithError(ex);
209
209
 
@@ -211,7 +211,7 @@ const handleInvalidOrClosedConversation = (dispatch, chatSDK, props, ex) => {
211
211
  callingStateCleanUp(dispatch);
212
212
  endChatStateCleanUp(dispatch);
213
213
  closeChatStateCleanUp(dispatch);
214
- chatSDKStateCleanUp(chatSDK);
214
+ chatSDKStateCleanUp(facadeChatSDK.getChatSDK());
215
215
  (_DataStoreManager$cli = DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.removeData(getWidgetCacheIdfromProps(props));
216
216
 
217
217
  // Starts new chat
@@ -6,16 +6,16 @@ import { TelemetryManager } from "../../../common/telemetry/TelemetryManager";
6
6
  import { getConversationDetailsCall } from "../../../common/utils";
7
7
 
8
8
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
- export const updateTelemetryData = async (chatSDK, dispatch) => {
9
+ export const updateTelemetryData = async (facadeChatSDK, dispatch) => {
10
10
  // load it concurrently, this will reduce the load time
11
- await Promise.all([updateSessionDataForTelemetry(chatSDK, dispatch), updateConversationDataForTelemetry(chatSDK, dispatch)]);
11
+ await Promise.all([updateSessionDataForTelemetry(facadeChatSDK, dispatch), updateConversationDataForTelemetry(facadeChatSDK, dispatch)]);
12
12
  };
13
13
 
14
14
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
- const updateSessionDataForTelemetry = async (chatSDK, dispatch) => {
16
- if (chatSDK) {
15
+ const updateSessionDataForTelemetry = async (facadeChatSDK, dispatch) => {
16
+ if (facadeChatSDK && facadeChatSDK.getChatSDK()) {
17
17
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
- const chatSession = await chatSDK.getCurrentLiveChatContext();
18
+ const chatSession = await facadeChatSDK.getCurrentLiveChatContext();
19
19
  const telemetryData = TelemetryHelper.addSessionDataToTelemetry(chatSession, TelemetryManager.InternalTelemetryData);
20
20
  dispatch({
21
21
  type: LiveChatWidgetActionType.SET_TELEMETRY_DATA,
@@ -31,10 +31,10 @@ const updateSessionDataForTelemetry = async (chatSDK, dispatch) => {
31
31
  };
32
32
 
33
33
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
- const updateConversationDataForTelemetry = async (chatSDK, dispatch) => {
35
- if (chatSDK) {
34
+ const updateConversationDataForTelemetry = async (facadeChatSDK, dispatch) => {
35
+ if (facadeChatSDK && facadeChatSDK.getChatSDK()) {
36
36
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
- const liveWorkItem = await getConversationDetailsCall(chatSDK);
37
+ const liveWorkItem = await getConversationDetailsCall(facadeChatSDK);
38
38
  const telemetryData = TelemetryHelper.addConversationDataToTelemetry(liveWorkItem, TelemetryManager.InternalTelemetryData);
39
39
  dispatch({
40
40
  type: LiveChatWidgetActionType.SET_TELEMETRY_DATA,
@@ -53,7 +53,7 @@ import { setPostChatContextAndLoadSurvey } from "../common/setPostChatContextAnd
53
53
  import { startProactiveChat } from "../common/startProactiveChat";
54
54
  import useChatAdapterStore from "../../../hooks/useChatAdapterStore";
55
55
  import useChatContextStore from "../../../hooks/useChatContextStore";
56
- import useChatSDKStore from "../../../hooks/useChatSDKStore";
56
+ import useFacadeSDKStore from "../../../hooks/useFacadeChatSDKStore";
57
57
  export const LiveChatWidgetStateful = props => {
58
58
  var _props$webChatContain, _props$styleProps, _props$controlProps, _props$controlProps3, _state$appStates7, _props$webChatContain5, _state$appStates14, _props$webChatContain7, _props$webChatContain8, _props$controlProps12, _props$draggableChatW, _props$draggableChatW2, _props$draggableChatW3, _props$draggableChatW4, _props$draggableChatW5, _livechatProps$webCha, _props$webChatContain9, _props$webChatContain10, _props$webChatContain11, _props$webChatContain12, _livechatProps$styleP, _livechatProps$contro, _livechatProps$contro2, _livechatProps$compon, _livechatProps$contro3, _livechatProps$compon2, _livechatProps$contro4, _livechatProps$compon3, _livechatProps$contro5, _livechatProps$compon4, _livechatProps$contro6, _livechatProps$compon5, _livechatProps$contro7, _livechatProps$compon6, _livechatProps$contro8, _livechatProps$compon7, _livechatProps$contro9, _livechatProps$compon8, _livechatProps$contro10, _livechatProps$contro11, _livechatProps$compon9, _livechatProps$contro12, _livechatProps$compon10, _livechatProps$contro13, _livechatProps$compon11, _livechatProps$compon12, _livechatProps$compon13;
59
59
  const [state, dispatch] = useChatContextStore();
@@ -64,7 +64,7 @@ export const LiveChatWidgetStateful = props => {
64
64
  ...((_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : _props$webChatContain.webChatStyles)
65
65
  });
66
66
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
67
- const chatSDK = useChatSDKStore();
67
+ const [facadeChatSDK] = useFacadeSDKStore();
68
68
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
69
69
  const [voiceVideoCallingSDK, setVoiceVideoCallingSDK] = useState(undefined);
70
70
  const {
@@ -82,8 +82,8 @@ export const LiveChatWidgetStateful = props => {
82
82
 
83
83
  // In case the broadcast channel is already initialized elsewhere; One tab can only hold 1 instance
84
84
  if ((props === null || props === void 0 ? void 0 : (_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.skipBroadcastChannelInit) !== true) {
85
- var _chatSDK$omnichannelC, _props$controlProps2;
86
- const broadcastServiceChannelName = getBroadcastChannelName(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC === void 0 ? void 0 : _chatSDK$omnichannelC.widgetId, ((_props$controlProps2 = props.controlProps) === null || _props$controlProps2 === void 0 ? void 0 : _props$controlProps2.widgetInstanceId) ?? "");
85
+ var _facadeChatSDK$getCha, _facadeChatSDK$getCha2, _props$controlProps2;
86
+ const broadcastServiceChannelName = getBroadcastChannelName((_facadeChatSDK$getCha = facadeChatSDK.getChatSDK()) === null || _facadeChatSDK$getCha === void 0 ? void 0 : (_facadeChatSDK$getCha2 = _facadeChatSDK$getCha.omnichannelConfig) === null || _facadeChatSDK$getCha2 === void 0 ? void 0 : _facadeChatSDK$getCha2.widgetId, ((_props$controlProps2 = props.controlProps) === null || _props$controlProps2 === void 0 ? void 0 : _props$controlProps2.widgetInstanceId) ?? "");
87
87
  BroadcastServiceInitialize(broadcastServiceChannelName);
88
88
  }
89
89
  TelemetryTimers.LcwLoadToChatButtonTimer = createTimer();
@@ -118,7 +118,7 @@ export const LiveChatWidgetStateful = props => {
118
118
  const startChat = async (props, localState) => {
119
119
  const isReconnectTriggered = async () => {
120
120
  if (isReconnectEnabled(props.chatConfig) === true && !isPersistentEnabled(props.chatConfig)) {
121
- const noValidReconnectId = await handleChatReconnect(chatSDK, props, dispatch, setAdapter, initStartChat, state);
121
+ const noValidReconnectId = await handleChatReconnect(facadeChatSDK, props, dispatch, setAdapter, initStartChat, state);
122
122
  const inMemoryState = executeReducer(state, {
123
123
  type: LiveChatWidgetActionType.GET_IN_MEMORY_STATE,
124
124
  payload: null
@@ -139,11 +139,11 @@ export const LiveChatWidgetStateful = props => {
139
139
  });
140
140
 
141
141
  //Check if conversation state is not in wrapup or closed state
142
- isChatValid = await checkIfConversationStillValid(chatSDK, dispatch, state);
142
+ isChatValid = await checkIfConversationStillValid(facadeChatSDK, dispatch, state);
143
143
  if (isChatValid === true) {
144
144
  const reconnectTriggered = await isReconnectTriggered();
145
145
  if (!reconnectTriggered) {
146
- await initStartChat(chatSDK, dispatch, setAdapter, state, props, optionalParams);
146
+ await initStartChat(facadeChatSDK, dispatch, setAdapter, state, props, optionalParams);
147
147
  }
148
148
  return;
149
149
  }
@@ -163,7 +163,7 @@ export const LiveChatWidgetStateful = props => {
163
163
  type: LiveChatWidgetActionType.GET_IN_MEMORY_STATE,
164
164
  payload: null
165
165
  });
166
- await setPreChatAndInitiateChat(chatSDK, dispatch, setAdapter, undefined, undefined, inMemoryState, props);
166
+ await setPreChatAndInitiateChat(facadeChatSDK, dispatch, setAdapter, undefined, undefined, inMemoryState, props);
167
167
  }
168
168
  return;
169
169
  } else {
@@ -233,7 +233,7 @@ export const LiveChatWidgetStateful = props => {
233
233
  });
234
234
  }
235
235
  if (((_props$chatConfig = props.chatConfig) === null || _props$chatConfig === void 0 ? void 0 : (_props$chatConfig$Liv = _props$chatConfig.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig$Liv === void 0 ? void 0 : _props$chatConfig$Liv.msdyn_callingoptions) !== E2VVOptions.NoCalling) {
236
- initCallingSdk(chatSDK, setVoiceVideoCallingSDK).then(sdkCreated => {
236
+ initCallingSdk(facadeChatSDK, setVoiceVideoCallingSDK).then(sdkCreated => {
237
237
  sdkCreated && dispatch({
238
238
  type: LiveChatWidgetActionType.SET_E2VV_ENABLED,
239
239
  payload: true
@@ -265,9 +265,9 @@ export const LiveChatWidgetStateful = props => {
265
265
  useEffect(() => {
266
266
  var _state$appStates6;
267
267
  if ((state === null || state === void 0 ? void 0 : (_state$appStates6 = state.appStates) === null || _state$appStates6 === void 0 ? void 0 : _state$appStates6.hideStartChatButton) === true) {
268
- var _props$chatConfig3, _props$chatConfig3$Li;
268
+ var _props$chatConfig3, _props$chatConfig3$Li, _props$chatConfig4, _props$chatConfig4$Li;
269
269
  //handle OOH pane
270
- if ((props === null || props === void 0 ? void 0 : (_props$chatConfig3 = props.chatConfig) === null || _props$chatConfig3 === void 0 ? void 0 : (_props$chatConfig3$Li = _props$chatConfig3.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig3$Li === void 0 ? void 0 : _props$chatConfig3$Li.OutOfOperatingHours.toLowerCase()) === "true") {
270
+ if (typeof (props === null || props === void 0 ? void 0 : (_props$chatConfig3 = props.chatConfig) === null || _props$chatConfig3 === void 0 ? void 0 : (_props$chatConfig3$Li = _props$chatConfig3.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig3$Li === void 0 ? void 0 : _props$chatConfig3$Li.OutOfOperatingHours) === "string" && (props === null || props === void 0 ? void 0 : (_props$chatConfig4 = props.chatConfig) === null || _props$chatConfig4 === void 0 ? void 0 : (_props$chatConfig4$Li = _props$chatConfig4.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig4$Li === void 0 ? void 0 : _props$chatConfig4$Li.OutOfOperatingHours.toLowerCase()) === "true") {
271
271
  dispatch({
272
272
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
273
273
  payload: ConversationState.OutOfOffice
@@ -290,7 +290,7 @@ export const LiveChatWidgetStateful = props => {
290
290
 
291
291
  // useEffect for custom context
292
292
  useEffect(() => {
293
- var _chatSDK$omnichannelC2, _chatSDK$omnichannelC3, _props$controlProps11;
293
+ var _facadeChatSDK$getCha3, _facadeChatSDK$getCha4, _facadeChatSDK$getCha5, _facadeChatSDK$getCha6, _props$controlProps11;
294
294
  // Add the custom context on receiving the SetCustomContext event
295
295
  BroadcastService.getMessageByEventName(BroadcastEvent.SetCustomContext).subscribe(msg => {
296
296
  TelemetryHelper.logActionEvent(LogLevel.INFO, {
@@ -343,7 +343,7 @@ export const LiveChatWidgetStateful = props => {
343
343
  if (callInProgress.current === false && dateNow - lastLWICheckTimeRef.current > Constants.LWICheckOnVisibilityTimeout) {
344
344
  lastLWICheckTimeRef.current = dateNow;
345
345
  callInProgress.current = true;
346
- const conversationDetails = await getConversationDetailsCall(chatSDK);
346
+ const conversationDetails = await getConversationDetailsCall(facadeChatSDK);
347
347
  if ((conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.state) === LiveWorkItemState.WrapUp || (conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.state) === LiveWorkItemState.Closed) {
348
348
  dispatch({
349
349
  type: LiveChatWidgetActionType.SET_CHAT_DISCONNECT_EVENT_RECEIVED,
@@ -359,11 +359,15 @@ export const LiveChatWidgetStateful = props => {
359
359
  }
360
360
  });
361
361
  BroadcastService.getMessageByEventName(BroadcastEvent.NetworkReconnected).subscribe(async () => {
362
- var _window2, _window2$location;
363
- if (isThisSessionPopout((_window2 = window) === null || _window2 === void 0 ? void 0 : (_window2$location = _window2.location) === null || _window2$location === void 0 ? void 0 : _window2$location.href)) {
362
+ var _window2, _window2$location, _inMemoryState$appSta;
363
+ const inMemoryState = executeReducer(state, {
364
+ type: LiveChatWidgetActionType.GET_IN_MEMORY_STATE,
365
+ payload: null
366
+ });
367
+ if (isThisSessionPopout((_window2 = window) === null || _window2 === void 0 ? void 0 : (_window2$location = _window2.location) === null || _window2$location === void 0 ? void 0 : _window2$location.href) || (inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$appSta = inMemoryState.appStates) === null || _inMemoryState$appSta === void 0 ? void 0 : _inMemoryState$appSta.conversationState) !== ConversationState.Active) {
364
368
  return;
365
369
  }
366
- const conversationDetails = await getConversationDetailsCall(chatSDK);
370
+ const conversationDetails = await getConversationDetailsCall(facadeChatSDK);
367
371
  if ((conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.state) === LiveWorkItemState.WrapUp || (conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.state) === LiveWorkItemState.Closed) {
368
372
  dispatch({
369
373
  type: LiveChatWidgetActionType.SET_CHAT_DISCONNECT_EVENT_RECEIVED,
@@ -397,9 +401,9 @@ export const LiveChatWidgetStateful = props => {
397
401
 
398
402
  // Start chat from SDK Event
399
403
  BroadcastService.getMessageByEventName(BroadcastEvent.StartChat).subscribe(msg => {
400
- var _props$chatConfig4, _props$chatConfig4$Li, _msg$payload5, _msg$payload6, _msg$payload7, _msg$payload9, _inMemoryState$appSta, _inMemoryState$appSta2, _inMemoryState$appSta3, _inMemoryState$appSta4;
404
+ var _props$chatConfig5, _props$chatConfig5$Li, _props$chatConfig6, _props$chatConfig6$Li, _msg$payload5, _msg$payload6, _msg$payload7, _msg$payload9, _inMemoryState$appSta2, _inMemoryState$appSta3, _inMemoryState$appSta4, _inMemoryState$appSta5;
401
405
  // If chat is out of operating hours chat widget sets the conversation state to OutOfOffice.
402
- if ((props === null || props === void 0 ? void 0 : (_props$chatConfig4 = props.chatConfig) === null || _props$chatConfig4 === void 0 ? void 0 : (_props$chatConfig4$Li = _props$chatConfig4.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig4$Li === void 0 ? void 0 : _props$chatConfig4$Li.OutOfOperatingHours.toLowerCase()) === "true") {
406
+ if (typeof (props === null || props === void 0 ? void 0 : (_props$chatConfig5 = props.chatConfig) === null || _props$chatConfig5 === void 0 ? void 0 : (_props$chatConfig5$Li = _props$chatConfig5.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig5$Li === void 0 ? void 0 : _props$chatConfig5$Li.OutOfOperatingHours) === "string" && (props === null || props === void 0 ? void 0 : (_props$chatConfig6 = props.chatConfig) === null || _props$chatConfig6 === void 0 ? void 0 : (_props$chatConfig6$Li = _props$chatConfig6.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig6$Li === void 0 ? void 0 : _props$chatConfig6$Li.OutOfOperatingHours.toLowerCase()) === "true") {
403
407
  (state === null || state === void 0 ? void 0 : state.appStates.isMinimized) && dispatch({
404
408
  type: LiveChatWidgetActionType.SET_MINIMIZED,
405
409
  payload: false
@@ -436,16 +440,16 @@ export const LiveChatWidgetStateful = props => {
436
440
  inMemoryState.domainStates.customContext = msg === null || msg === void 0 ? void 0 : (_msg$payload9 = msg.payload) === null || _msg$payload9 === void 0 ? void 0 : _msg$payload9.customContext;
437
441
 
438
442
  // Only initiate new chat if widget runtime state is one of the followings
439
- if (((_inMemoryState$appSta = inMemoryState.appStates) === null || _inMemoryState$appSta === void 0 ? void 0 : _inMemoryState$appSta.conversationState) === ConversationState.Closed || ((_inMemoryState$appSta2 = inMemoryState.appStates) === null || _inMemoryState$appSta2 === void 0 ? void 0 : _inMemoryState$appSta2.conversationState) === ConversationState.InActive || ((_inMemoryState$appSta3 = inMemoryState.appStates) === null || _inMemoryState$appSta3 === void 0 ? void 0 : _inMemoryState$appSta3.conversationState) === ConversationState.Postchat) {
443
+ if (((_inMemoryState$appSta2 = inMemoryState.appStates) === null || _inMemoryState$appSta2 === void 0 ? void 0 : _inMemoryState$appSta2.conversationState) === ConversationState.Closed || ((_inMemoryState$appSta3 = inMemoryState.appStates) === null || _inMemoryState$appSta3 === void 0 ? void 0 : _inMemoryState$appSta3.conversationState) === ConversationState.InActive || ((_inMemoryState$appSta4 = inMemoryState.appStates) === null || _inMemoryState$appSta4 === void 0 ? void 0 : _inMemoryState$appSta4.conversationState) === ConversationState.Postchat) {
440
444
  BroadcastService.postMessage({
441
445
  eventName: BroadcastEvent.ChatInitiated
442
446
  });
443
- prepareStartChat(props, chatSDK, inMemoryState, dispatch, setAdapter);
447
+ prepareStartChat(props, facadeChatSDK, inMemoryState, dispatch, setAdapter);
444
448
  return;
445
449
  }
446
450
 
447
451
  // If minimized, maximize the chat
448
- if ((inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$appSta4 = inMemoryState.appStates) === null || _inMemoryState$appSta4 === void 0 ? void 0 : _inMemoryState$appSta4.isMinimized) === true) {
452
+ if ((inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$appSta5 = inMemoryState.appStates) === null || _inMemoryState$appSta5 === void 0 ? void 0 : _inMemoryState$appSta5.isMinimized) === true) {
449
453
  var _inMemoryState$domain, _inMemoryState$domain2, _inMemoryState$domain3, _inMemoryState$domain4;
450
454
  dispatch({
451
455
  type: LiveChatWidgetActionType.SET_MINIMIZED,
@@ -492,7 +496,7 @@ export const LiveChatWidgetStateful = props => {
492
496
  Event: TelemetryEvent.PrepareEndChat,
493
497
  Description: PrepareEndChatDescriptionConstants.InitiateEndChatReceived
494
498
  });
495
- endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, skipEndChatSDK, skipCloseChat);
499
+ endChat(props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, skipEndChatSDK, skipCloseChat);
496
500
  }
497
501
  BroadcastService.postMessage({
498
502
  eventName: BroadcastEvent.CloseChat
@@ -505,7 +509,7 @@ export const LiveChatWidgetStateful = props => {
505
509
  });
506
510
 
507
511
  // Listen to end chat event from other tabs
508
- const endChatEventName = getWidgetEndChatEventName(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC2 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC2 === void 0 ? void 0 : _chatSDK$omnichannelC2.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC3 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC3 === void 0 ? void 0 : _chatSDK$omnichannelC3.widgetId, ((_props$controlProps11 = props.controlProps) === null || _props$controlProps11 === void 0 ? void 0 : _props$controlProps11.widgetInstanceId) ?? "");
512
+ const endChatEventName = getWidgetEndChatEventName((_facadeChatSDK$getCha3 = facadeChatSDK.getChatSDK()) === null || _facadeChatSDK$getCha3 === void 0 ? void 0 : (_facadeChatSDK$getCha4 = _facadeChatSDK$getCha3.omnichannelConfig) === null || _facadeChatSDK$getCha4 === void 0 ? void 0 : _facadeChatSDK$getCha4.orgId, (_facadeChatSDK$getCha5 = facadeChatSDK.getChatSDK()) === null || _facadeChatSDK$getCha5 === void 0 ? void 0 : (_facadeChatSDK$getCha6 = _facadeChatSDK$getCha5.omnichannelConfig) === null || _facadeChatSDK$getCha6 === void 0 ? void 0 : _facadeChatSDK$getCha6.widgetId, ((_props$controlProps11 = props.controlProps) === null || _props$controlProps11 === void 0 ? void 0 : _props$controlProps11.widgetInstanceId) ?? "");
509
513
  BroadcastService.getMessageByEventName(endChatEventName).subscribe(msg => {
510
514
  var _msg$payload10;
511
515
  if ((msg === null || msg === void 0 ? void 0 : (_msg$payload10 = msg.payload) === null || _msg$payload10 === void 0 ? void 0 : _msg$payload10.runtimeId) !== TelemetryManager.InternalTelemetryData.lcwRuntimeId) {
@@ -513,9 +517,9 @@ export const LiveChatWidgetStateful = props => {
513
517
  Event: TelemetryEvent.PrepareEndChat,
514
518
  Description: "Received EndChat BroadcastEvent from other tabs. Closing this chat."
515
519
  });
516
- endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, true, false, false);
520
+ endChat(props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, true, false, false);
517
521
  endChatStateCleanUp(dispatch);
518
- chatSDKStateCleanUp(chatSDK);
522
+ chatSDKStateCleanUp(facadeChatSDK.getChatSDK());
519
523
  return;
520
524
  }
521
525
  });
@@ -557,7 +561,7 @@ export const LiveChatWidgetStateful = props => {
557
561
  useEffect(() => {
558
562
  // On new message
559
563
  if (state.appStates.conversationState === ConversationState.Active) {
560
- chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.onNewMessage(() => {
564
+ facadeChatSDK === null || facadeChatSDK === void 0 ? void 0 : facadeChatSDK.onNewMessage(() => {
561
565
  // Track the message count
562
566
  currentMessageCountRef.current++;
563
567
  dispatch({
@@ -645,7 +649,7 @@ export const LiveChatWidgetStateful = props => {
645
649
  Event: TelemetryEvent.PrepareEndChat,
646
650
  Description: PrepareEndChatDescriptionConstants.CustomerCloseChatOnFailureOrPostChat
647
651
  });
648
- endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, true, false, true);
652
+ endChat(props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, true, false, true);
649
653
  return;
650
654
  }
651
655
 
@@ -655,7 +659,7 @@ export const LiveChatWidgetStateful = props => {
655
659
  Event: TelemetryEvent.PrepareEndChat,
656
660
  Description: PrepareEndChatDescriptionConstants.CustomerCloseInactiveChat
657
661
  });
658
- endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true);
662
+ endChat(props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true);
659
663
  return;
660
664
  }
661
665
  if ((state === null || state === void 0 ? void 0 : (_state$appStates12 = state.appStates) === null || _state$appStates12 === void 0 ? void 0 : _state$appStates12.conversationEndedBy) === ConversationEndEntity.Agent || (state === null || state === void 0 ? void 0 : (_state$appStates13 = state.appStates) === null || _state$appStates13 === void 0 ? void 0 : _state$appStates13.conversationEndedBy) === ConversationEndEntity.Bot) {
@@ -666,7 +670,7 @@ export const LiveChatWidgetStateful = props => {
666
670
  }
667
671
 
668
672
  // All other cases
669
- prepareEndChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter);
673
+ prepareEndChat(props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter);
670
674
  }, [state === null || state === void 0 ? void 0 : (_state$appStates14 = state.appStates) === null || _state$appStates14 === void 0 ? void 0 : _state$appStates14.conversationEndedBy]);
671
675
 
672
676
  // Publish chat widget state
@@ -699,13 +703,13 @@ export const LiveChatWidgetStateful = props => {
699
703
 
700
704
  // Handle Chat disconnect cases
701
705
  useEffect(() => {
702
- var _inMemoryState$appSta5;
706
+ var _inMemoryState$appSta6;
703
707
  const inMemoryState = executeReducer(state, {
704
708
  type: LiveChatWidgetActionType.GET_IN_MEMORY_STATE,
705
709
  payload: null
706
710
  });
707
711
  handleChatDisconnect(props, inMemoryState, setWebChatStyles);
708
- const chatDisconnectState = inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$appSta5 = inMemoryState.appStates) === null || _inMemoryState$appSta5 === void 0 ? void 0 : _inMemoryState$appSta5.chatDisconnectEventReceived;
712
+ const chatDisconnectState = inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$appSta6 = inMemoryState.appStates) === null || _inMemoryState$appSta6 === void 0 ? void 0 : _inMemoryState$appSta6.chatDisconnectEventReceived;
709
713
  if (chatDisconnectState && adapter) {
710
714
  try {
711
715
  adapter.end();
@@ -737,7 +741,7 @@ export const LiveChatWidgetStateful = props => {
737
741
  Event: TelemetryEvent.PrepareEndChat,
738
742
  Description: PrepareEndChatDescriptionConstants.BrowserUnload
739
743
  });
740
- endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, false);
744
+ endChat(props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, false);
741
745
  // Clean local storage
742
746
  (_DataStoreManager$cli = DataStoreManager.clientDataStore) === null || _DataStoreManager$cli === void 0 ? void 0 : _DataStoreManager$cli.removeData(widgetStateEventId);
743
747
 
@@ -750,16 +754,16 @@ export const LiveChatWidgetStateful = props => {
750
754
  eventName: BroadcastEvent.ClosePopoutWindow
751
755
  });
752
756
  };
753
- const setPostChatContextRelay = () => setPostChatContextAndLoadSurvey(chatSDK, dispatch);
757
+ const setPostChatContextRelay = () => setPostChatContextAndLoadSurvey(facadeChatSDK, dispatch);
754
758
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
755
- const endChatRelay = (adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab) => endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab);
756
- const prepareStartChatRelay = () => prepareStartChat(props, chatSDK, state, dispatch, setAdapter);
759
+ const endChatRelay = (adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab) => endChat(props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab);
760
+ const prepareStartChatRelay = () => prepareStartChat(props, facadeChatSDK, state, dispatch, setAdapter);
757
761
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
758
- const initStartChatRelay = (optionalParams, persistedState) => initStartChat(chatSDK, dispatch, setAdapter, state, props, optionalParams, persistedState);
762
+ const initStartChatRelay = (optionalParams, persistedState) => initStartChat(facadeChatSDK, dispatch, setAdapter, state, props, optionalParams, persistedState);
759
763
  const confirmationPaneProps = initConfirmationPropsComposer(props);
760
764
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
761
- const prepareEndChatRelay = () => prepareEndChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter);
762
- const webChatProps = initWebChatComposer(props, state, dispatch, chatSDK, endChatRelay);
765
+ const prepareEndChatRelay = () => prepareEndChat(props, facadeChatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter);
766
+ const webChatProps = initWebChatComposer(props, state, dispatch, facadeChatSDK, endChatRelay);
763
767
  const downloadTranscriptProps = createDownloadTranscriptProps(props.downloadTranscriptProps, {
764
768
  ...(defaultWebChatContainerStatefulProps === null || defaultWebChatContainerStatefulProps === void 0 ? void 0 : defaultWebChatContainerStatefulProps.webChatStyles),
765
769
  ...((_props$webChatContain8 = props.webChatContainerProps) === null || _props$webChatContain8 === void 0 ? void 0 : _props$webChatContain8.webChatStyles)
@@ -785,7 +789,7 @@ export const LiveChatWidgetStateful = props => {
785
789
  };
786
790
 
787
791
  // Add 'omnichannel-chat-widget' OC User Agent if not already set
788
- setOcUserAgent(chatSDK);
792
+ setOcUserAgent(facadeChatSDK.getChatSDK());
789
793
  const directLine = ((_livechatProps$webCha = livechatProps.webChatContainerProps) === null || _livechatProps$webCha === void 0 ? void 0 : _livechatProps$webCha.directLine) ?? adapter ?? defaultWebChatContainerStatefulProps.directLine;
790
794
  const userID = directLine.getState ? directLine === null || directLine === void 0 ? void 0 : directLine.getState("acs.userId") : "teamsvisitor";
791
795
 
@@ -6,11 +6,13 @@ import { ReconnectChatPane } from "@microsoft/omnichannel-chat-components";
6
6
  import { TelemetryHelper } from "../../common/telemetry/TelemetryHelper";
7
7
  import { setFocusOnElement } from "../../common/utils";
8
8
  import useChatContextStore from "../../hooks/useChatContextStore";
9
- import useChatSDKStore from "../../hooks/useChatSDKStore";
9
+ import useFacadeChatSDKStore from "../../hooks/useFacadeChatSDKStore";
10
10
  export const ReconnectChatPaneStateful = props => {
11
11
  const [state, dispatch] = useChatContextStore();
12
12
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
- const chatSDK = useChatSDKStore();
13
+ //const chatSDK: any = useChatSDKStore();
14
+ const [facadeChatSDK] = useFacadeChatSDKStore();
15
+ const chatSDK = facadeChatSDK.getChatSDK();
14
16
  const {
15
17
  reconnectChatProps,
16
18
  initStartChat