@microsoft/omnichannel-chat-widget 0.1.0-main.bcfe8a3 → 0.1.0-main.cde77ea

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 (75) hide show
  1. package/lib/cjs/common/Constants.js +2 -0
  2. package/lib/cjs/common/telemetry/TelemetryConstants.js +4 -0
  3. package/lib/cjs/common/utils.js +48 -2
  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 +2 -2
  7. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +23 -0
  8. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.js +1 -0
  9. package/lib/cjs/components/livechatwidget/common/ChatAdapterShim.js +70 -0
  10. package/lib/cjs/components/livechatwidget/common/createAdapter.js +9 -1
  11. package/lib/cjs/components/livechatwidget/common/createMarkdown.js +31 -30
  12. package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +4 -1
  13. package/lib/cjs/components/livechatwidget/common/endChat.js +49 -17
  14. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +8 -0
  15. package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +15 -15
  16. package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
  17. package/lib/cjs/components/livechatwidget/common/shareObservable.js +45 -0
  18. package/lib/cjs/components/livechatwidget/common/startChat.js +124 -84
  19. package/lib/cjs/components/livechatwidget/interfaces/IAuthProps.js +1 -0
  20. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +92 -98
  21. package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +4 -8
  22. package/lib/cjs/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +1 -1
  23. package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +2 -0
  24. package/lib/cjs/contexts/common/ConversationState.js +3 -2
  25. package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +0 -1
  26. package/lib/cjs/controller/componentController.js +2 -2
  27. package/lib/esm/common/Constants.js +2 -0
  28. package/lib/esm/common/telemetry/TelemetryConstants.js +4 -0
  29. package/lib/esm/common/utils.js +36 -0
  30. package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +4 -0
  31. package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +0 -1
  32. package/lib/esm/components/headerstateful/HeaderStateful.js +2 -2
  33. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +14 -0
  34. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.js +1 -0
  35. package/lib/esm/components/livechatwidget/common/ChatAdapterShim.js +59 -0
  36. package/lib/esm/components/livechatwidget/common/createAdapter.js +9 -2
  37. package/lib/esm/components/livechatwidget/common/createMarkdown.js +31 -30
  38. package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +4 -1
  39. package/lib/esm/components/livechatwidget/common/endChat.js +50 -18
  40. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +9 -2
  41. package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +17 -16
  42. package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
  43. package/lib/esm/components/livechatwidget/common/shareObservable.js +38 -0
  44. package/lib/esm/components/livechatwidget/common/startChat.js +125 -86
  45. package/lib/esm/components/livechatwidget/interfaces/IAuthProps.js +1 -0
  46. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +92 -97
  47. package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +5 -8
  48. package/lib/esm/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +1 -1
  49. package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +2 -0
  50. package/lib/esm/contexts/common/ConversationState.js +3 -2
  51. package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +0 -1
  52. package/lib/esm/controller/componentController.js +2 -2
  53. package/lib/types/common/Constants.d.ts +1 -0
  54. package/lib/types/common/telemetry/TelemetryConstants.d.ts +4 -1
  55. package/lib/types/common/telemetry/TelemetryHelper.d.ts +1 -1
  56. package/lib/types/common/utils.d.ts +3 -0
  57. package/lib/types/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.d.ts +1 -1
  58. package/lib/types/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.d.ts +5 -0
  59. package/lib/types/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.d.ts +6 -0
  60. package/lib/types/components/livechatwidget/common/ChatAdapterShim.d.ts +7 -0
  61. package/lib/types/components/livechatwidget/common/endChat.d.ts +1 -1
  62. package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +5 -4
  63. package/lib/types/components/livechatwidget/common/setPostChatContextAndLoadSurvey.d.ts +1 -1
  64. package/lib/types/components/livechatwidget/common/shareObservable.d.ts +1 -0
  65. package/lib/types/components/livechatwidget/common/startChat.d.ts +4 -2
  66. package/lib/types/components/livechatwidget/common/startProactiveChat.d.ts +1 -1
  67. package/lib/types/components/livechatwidget/interfaces/IAuthProps.d.ts +4 -0
  68. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +2 -0
  69. package/lib/types/components/reconnectchatpanestateful/interfaces/IReconnectChatPaneStatefulProps.d.ts +0 -1
  70. package/lib/types/components/webchatcontainerstateful/common/mockchatsdk.d.ts +1 -0
  71. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.d.ts +1 -1
  72. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/avatarMiddleware.d.ts +1 -1
  73. package/lib/types/contexts/common/ConversationState.d.ts +3 -2
  74. package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +0 -1
  75. package/package.json +1 -1
@@ -0,0 +1,59 @@
1
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
+
3
+ import { DefaultActivitySubscriber } from "./ActivitySubscriber/DefaultActivitySubscriber";
4
+ import { shareObservable } from "./shareObservable";
5
+ export class ChatAdapterShim {
6
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
+ constructor(chatAdapter) {
11
+ _defineProperty(this, "chatAdapter", void 0);
12
+
13
+ _defineProperty(this, "activityObserver", void 0);
14
+
15
+ _defineProperty(this, "subscribers", void 0);
16
+
17
+ this.subscribers = [];
18
+ this.chatAdapter = { ...chatAdapter,
19
+ activity$: shareObservable( // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
+ new window.Observable(observer => {
21
+ this.activityObserver = observer; // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
+
23
+ const abortController = new window.AbortController();
24
+
25
+ (async () => {
26
+ try {
27
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
+ for await (let activity of chatAdapter.activities({
29
+ signal: abortController.signal
30
+ })) {
31
+ for (const subscriber of [...this.subscribers, new DefaultActivitySubscriber()]) {
32
+ subscriber.observer = this.activityObserver;
33
+ activity = await subscriber.next(activity);
34
+
35
+ if (!activity) {
36
+ break;
37
+ }
38
+ }
39
+ }
40
+
41
+ observer.complete();
42
+ } catch (error) {
43
+ observer.error(error);
44
+ }
45
+ })();
46
+
47
+ return () => {
48
+ abortController.abort();
49
+ };
50
+ }))
51
+ };
52
+ } // eslint-disable-next-line @typescript-eslint/no-explicit-any
53
+
54
+
55
+ addSubscriber(subscriber) {
56
+ this.subscribers.push(subscriber);
57
+ }
58
+
59
+ }
@@ -1,7 +1,8 @@
1
1
  import { NotificationHandler } from "../../webchatcontainerstateful/webchatcontroller/notification/NotificationHandler";
2
2
  import { NotificationLevel } from "../../webchatcontainerstateful/webchatcontroller/enums/NotificationLevel";
3
3
  import { NotificationScenarios } from "../../webchatcontainerstateful/webchatcontroller/enums/NotificationScenarios";
4
- import { defaultMiddlewareLocalizedTexts } from "../../webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
+ import { defaultMiddlewareLocalizedTexts } from "../../webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts";
5
+ import { ChatAdapterShim } from "./ChatAdapterShim"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
6
 
6
7
  export const createAdapter = async chatSDK => {
7
8
  const chatAdapterOptionalParams = {
@@ -23,5 +24,11 @@ export const createAdapter = async chatSDK => {
23
24
  }
24
25
  }
25
26
  };
26
- return await chatSDK.createChatAdapter(chatAdapterOptionalParams);
27
+ let adapter = await chatSDK.createChatAdapter(chatAdapterOptionalParams); //so far, there is no need to convert to the shim adapter when using visual tests
28
+
29
+ if (chatSDK.isMockModeOn !== true) {
30
+ adapter = new ChatAdapterShim(adapter);
31
+ }
32
+
33
+ return adapter;
27
34
  };
@@ -13,26 +13,40 @@ export const createMarkdown = (disableMarkdownMessageFormatting, disableNewLineM
13
13
  breaks: !disableNewLineMarkdownSupport
14
14
  }); // ToDo: Commenting below usage of plugin until deferred bug is resolved: https://github.com/mayashavin/markdown-it-slack/issues/1
15
15
  // markdown.use(MarkdownSlack);
16
- // Markdown override for open link in new tab
17
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, quotes
16
+ } else {
17
+ markdown = new MarkdownIt(Constants.Zero, {
18
+ html: true,
19
+ linkify: true,
20
+ breaks: !disableNewLineMarkdownSupport
21
+ });
22
+ markdown.enable(["entity", // Rule to process html entity - {, ¯, "
23
+ "linkify", // Rule to replace link-like texts with link nodes
24
+ "html_block", // Rule to process html blocks and paragraphs
25
+ "html_inline", // Rule to process html tags
26
+ "newline" // Rule to proceess '\n'
27
+ ]);
28
+ } // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
29
 
19
- markdown.use(MarkdownItForInline, "url_new_win", "link_open", function (tokens, idx, env) {
20
- const targetAttrIndex = tokens[idx].attrIndex(Constants.Target); // Put a transparent pixel instead of the "open in new window" icon, so developers can easily modify the icon in CSS.
21
30
 
22
- const TRANSPARENT_GIF = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
31
+ markdown.use(MarkdownItForInline, "url_new_win", "link_open", function (tokens, idx, env) {
32
+ const targetAttrIndex = tokens[idx].attrIndex(Constants.Target); // Put a transparent pixel instead of the "open in new window" icon, so developers can easily modify the icon in CSS.
23
33
 
24
- if (~targetAttrIndex) {
25
- tokens[idx].attrs[targetAttrIndex][1] = Constants.Blank;
26
- } else {
27
- tokens[idx].attrPush([Constants.Target, Constants.Blank]);
28
- }
34
+ const TRANSPARENT_GIF = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
35
+
36
+ if (~targetAttrIndex) {
37
+ tokens[idx].attrs[targetAttrIndex][1] = Constants.Blank;
38
+ } else {
39
+ tokens[idx].attrPush([Constants.Target, Constants.Blank]);
40
+ }
41
+
42
+ const relAttrIndex = tokens[idx].attrIndex(Constants.TargetRelationship);
29
43
 
30
- const relAttrIndex = tokens[idx].attrIndex(Constants.TargetRelationship);
44
+ if (~relAttrIndex) {
45
+ tokens[idx].attrs[relAttrIndex][1] = Constants.TargetRelationshipAttributes;
46
+ } else {
47
+ tokens[idx].attrPush([Constants.TargetRelationship, Constants.TargetRelationshipAttributes]);
31
48
 
32
- if (~relAttrIndex) {
33
- tokens[idx].attrs[relAttrIndex][1] = Constants.TargetRelationshipAttributes;
34
- } else {
35
- tokens[idx].attrPush([Constants.TargetRelationship, Constants.TargetRelationshipAttributes]);
49
+ if (!disableMarkdownMessageFormatting) {
36
50
  tokens[idx].attrPush([Constants.Title, defaultMarkdownLocalizedTexts.MARKDOWN_EXTERNAL_LINK_ALT]); // eslint-disable-next-line quotes
37
51
 
38
52
  const iconTokens = markdown.parseInline(`![${defaultMarkdownLocalizedTexts.MARKDOWN_EXTERNAL_LINK_ALT}](${TRANSPARENT_GIF})`, env)[0].children;
@@ -42,20 +56,7 @@ export const createMarkdown = (disableMarkdownMessageFormatting, disableNewLineM
42
56
  tokens.splice(idx + 2, 0, ...iconTokens);
43
57
  }
44
58
  }
45
- });
46
- } else {
47
- markdown = new MarkdownIt(Constants.Zero, {
48
- html: true,
49
- linkify: true,
50
- breaks: !disableNewLineMarkdownSupport
51
- });
52
- markdown.enable(["entity", // Rule to process html entity - {, ¯, "
53
- "linkify", // Rule to replace link-like texts with link nodes
54
- "html_block", // Rule to process html blocks and paragraphs
55
- "html_inline", // Rule to process html tags
56
- "newline" // Rule to proceess '\n'
57
- ]);
58
- }
59
-
59
+ }
60
+ });
60
61
  return markdown;
61
62
  };
@@ -1413,7 +1413,6 @@ export const dummyDefaultProps = {
1413
1413
  startNewChatButtonClassName: undefined
1414
1414
  }
1415
1415
  },
1416
- authClientFunction: undefined,
1417
1416
  isReconnectEnabled: undefined,
1418
1417
  reconnectId: undefined,
1419
1418
  redirectInSameWindow: undefined
@@ -1684,5 +1683,9 @@ export const dummyDefaultProps = {
1684
1683
  fwdUrl: ""
1685
1684
  }
1686
1685
  },
1686
+ authProps: {
1687
+ authClientFunction: undefined,
1688
+ setAuthTokenProviderToChatSdk: undefined
1689
+ },
1687
1690
  telemetryConfig: undefined
1688
1691
  };
@@ -7,21 +7,38 @@ import { WebChatStoreLoader } from "../../webchatcontainerstateful/webchatcontro
7
7
  import { defaultWebChatContainerStatefulProps } from "../../webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps";
8
8
  import { PostChatSurveyMode } from "../../postchatsurveypanestateful/enums/PostChatSurveyMode";
9
9
  import { Constants } from "../../../common/Constants";
10
- import { getWidgetEndChatEventName } from "../../../common/utils"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
+ import { addDelayInMs, getWidgetEndChatEventName } from "../../../common/utils"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
11
11
 
12
12
  const prepareEndChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, state) => {
13
- var _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _state$domainStates$l4;
13
+ var _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _state$domainStates$l4, _conversationDetails;
14
14
 
15
15
  const isPostChatEnabled = (_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_postconversationsurveyenable;
16
- const postChatSurveyMode = (_state$domainStates$l3 = state.domainStates.liveChatConfig) === null || _state$domainStates$l3 === void 0 ? void 0 : (_state$domainStates$l4 = _state$domainStates$l3.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l4 === void 0 ? void 0 : _state$domainStates$l4.msdyn_postconversationsurveymode;
17
- const conversationDetails = await chatSDK.getConversationDetails();
16
+ const postChatSurveyMode = (_state$domainStates$l3 = state.domainStates.liveChatConfig) === null || _state$domainStates$l3 === void 0 ? void 0 : (_state$domainStates$l4 = _state$domainStates$l3.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l4 === void 0 ? void 0 : _state$domainStates$l4.msdyn_postconversationsurveymode; // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
17
 
19
- if (isPostChatEnabled === "true" && (conversationDetails === null || conversationDetails === void 0 ? void 0 : conversationDetails.canRenderPostChat) === Constants.truePascal) {
18
+ let conversationDetails = undefined;
19
+
20
+ try {
21
+ conversationDetails = await chatSDK.getConversationDetails();
22
+ } catch (erorr) {
23
+ TelemetryHelper.logActionEvent(LogLevel.ERROR, {
24
+ Event: TelemetryEvent.GetConversationDetailsException,
25
+ ExceptionDetails: {
26
+ exception: `Failed to get conversation details: ${erorr}`
27
+ }
28
+ });
29
+ }
30
+
31
+ if (isPostChatEnabled === "true" && ((_conversationDetails = conversationDetails) === null || _conversationDetails === void 0 ? void 0 : _conversationDetails.canRenderPostChat) === Constants.truePascal) {
20
32
  const skipEndChatSDK = false;
21
33
  const skipCloseChat = true;
22
34
  await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, skipEndChatSDK, skipCloseChat, true);
23
35
 
24
36
  if (postChatSurveyMode === PostChatSurveyMode.Embed) {
37
+ dispatch({
38
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
39
+ payload: ConversationState.PostchatLoading
40
+ });
41
+ await addDelayInMs(Constants.PostChatLoadingDurationInMs);
25
42
  const loadPostChatEvent = {
26
43
  eventName: BroadcastEvent.LoadPostChatSurvey
27
44
  };
@@ -32,9 +49,11 @@ const prepareEndChat = async (props, chatSDK, setAdapter, setWebChatStyles, disp
32
49
  payload: ConversationState.InActive
33
50
  });
34
51
  }
35
- } else {
36
- await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, true);
52
+
53
+ return;
37
54
  }
55
+
56
+ await endChat(props, chatSDK, setAdapter, setWebChatStyles, dispatch, adapter, false, false, true);
38
57
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
39
58
 
40
59
 
@@ -44,16 +63,7 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
44
63
  TelemetryHelper.logSDKEvent(LogLevel.INFO, {
45
64
  Event: TelemetryEvent.EndChatSDKCall
46
65
  });
47
- await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.endChat()); // Need to clear these states immediately when chat ended from OC.
48
-
49
- dispatch({
50
- type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
51
- payload: undefined
52
- });
53
- dispatch({
54
- type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
55
- payload: undefined
56
- });
66
+ await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.endChat());
57
67
  } catch (ex) {
58
68
  TelemetryHelper.logSDKEvent(LogLevel.ERROR, {
59
69
  Event: TelemetryEvent.EndChatSDKCallFailed,
@@ -63,7 +73,21 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
63
73
  });
64
74
  postMessageToOtherTab = false;
65
75
  }
66
- }
76
+ } // Need to clear these states immediately when chat ended from OC.
77
+
78
+
79
+ dispatch({
80
+ type: LiveChatWidgetActionType.SET_CUSTOM_CONTEXT,
81
+ payload: undefined
82
+ });
83
+ dispatch({
84
+ type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
85
+ payload: undefined
86
+ });
87
+ dispatch({
88
+ type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
89
+ payload: undefined
90
+ });
67
91
 
68
92
  if (!skipCloseChat) {
69
93
  try {
@@ -95,6 +119,14 @@ const endChat = async (props, chatSDK, setAdapter, setWebChatStyles, dispatch, a
95
119
  type: LiveChatWidgetActionType.SET_UNREAD_MESSAGE_COUNT,
96
120
  payload: 0
97
121
  });
122
+ dispatch({
123
+ type: LiveChatWidgetActionType.SET_PROACTIVE_CHAT_PARAMS,
124
+ payload: {
125
+ proactiveChatBodyTitle: "",
126
+ proactiveChatEnablePrechat: false,
127
+ proactiveChatInNewWindow: false
128
+ }
129
+ });
98
130
 
99
131
  if (postMessageToOtherTab) {
100
132
  var _chatSDK$omnichannelC, _chatSDK$omnichannelC2;
@@ -7,7 +7,7 @@ import { PostChatSurveyMode } from "../../postchatsurveypanestateful/enums/PostC
7
7
  import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
8
8
  import { WebChatStoreLoader } from "../../webchatcontainerstateful/webchatcontroller/WebChatStoreLoader";
9
9
  import attachmentProcessingMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/attachmentProcessingMiddleware";
10
- import { changeLanguageCodeFormatForWebChat } from "../../../common/utils";
10
+ import { addDelayInMs, changeLanguageCodeFormatForWebChat } from "../../../common/utils";
11
11
  import channelDataMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/channelDataMiddleware";
12
12
  import { createActivityMiddleware } from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware";
13
13
  import createAttachmentMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentMiddleware";
@@ -28,7 +28,8 @@ import htmlTextMiddleware from "../../webchatcontainerstateful/webchatcontroller
28
28
  import preProcessingMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/preProcessingMiddleware";
29
29
  import sanitizationMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/sanitizationMiddleware";
30
30
  import { createCardActionMiddleware } from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware";
31
- import createMessageTimeStampMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
+ import createMessageTimeStampMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware";
32
+ import { Constants } from "../../../common/Constants"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
33
 
33
34
  export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatStyles) => {
34
35
  var _props$webChatContain, _props$webChatContain2, _props$webChatContain3, _state$domainStates$l, _state$domainStates$l2, _state$domainStates$l3, _state$domainStates$l4, _state$domainStates$l8, _state$domainStates$l9, _props$webChatContain7, _props$webChatContain8, _state$domainStates$r, _state$domainStates$r2, _props$webChatContain9, _props$webChatContain10, _state$domainStates$r3, _state$domainStates$r4, _props$webChatContain11, _props$webChatContain12, _defaultWebChatContai, _props$webChatContain13, _props$webChatContain14, _props$webChatContain15, _props$webChatContain16, _state$domainStates$r5, _state$domainStates$r6, _props$webChatContain17, _props$webChatContain18, _defaultWebChatContai2, _props$webChatContain19, _props$webChatContain20, _defaultWebChatContai3, _props$webChatContain21, _props$webChatContain22;
@@ -65,6 +66,12 @@ export const initWebChatComposer = (props, chatSDK, state, dispatch, setWebChatS
65
66
 
66
67
  if (isPostChatEnabled === "true") {
67
68
  if (postChatSurveyMode === PostChatSurveyMode.Embed) {
69
+ WebChatStoreLoader.store = null;
70
+ dispatch({
71
+ type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
72
+ payload: ConversationState.PostchatLoading
73
+ });
74
+ await addDelayInMs(Constants.PostChatLoadingDurationInMs);
68
75
  const loadPostChatEvent = {
69
76
  eventName: BroadcastEvent.LoadPostChatSurvey
70
77
  };
@@ -3,8 +3,9 @@ import { BroadcastEvent, LogLevel, TelemetryEvent } from "../../../common/teleme
3
3
  import { BroadcastService } from "@microsoft/omnichannel-chat-components";
4
4
  import { ConversationState } from "../../../contexts/common/ConversationState";
5
5
  import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
6
- import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
+ import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
7
7
 
8
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
9
  const getChatReconnectContext = async (chatSDK, reconnectId) => {
9
10
  try {
10
11
  if (reconnectId) {
@@ -29,9 +30,9 @@ const getChatReconnectContext = async (chatSDK, reconnectId) => {
29
30
 
30
31
 
31
32
  const getReconnectIdForAuthenticatedChat = async (props, chatSDK) => {
32
- var _props$reconnectChatP, _props$reconnectChatP2;
33
+ var _props$reconnectChatP, _props$authProps;
33
34
 
34
- if ((_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.isReconnectEnabled && (_props$reconnectChatP2 = props.reconnectChatPaneProps) !== null && _props$reconnectChatP2 !== void 0 && _props$reconnectChatP2.authClientFunction // TODO: Implement this after storage is in place
35
+ if ((_props$reconnectChatP = props.reconnectChatPaneProps) !== null && _props$reconnectChatP !== void 0 && _props$reconnectChatP.isReconnectEnabled && (_props$authProps = props.authProps) !== null && _props$authProps !== void 0 && _props$authProps.authClientFunction // TODO: Implement this after storage is in place
35
36
 
36
37
  /* && !isLoadWithState() */
37
38
  ) {
@@ -46,27 +47,27 @@ const getReconnectIdForAuthenticatedChat = async (props, chatSDK) => {
46
47
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
48
 
48
49
 
49
- const handleUnauthenticatedReconnectChat = async (chatSDK, dispatch, setAdapter, reconnectId, initStartChat, redirectInSameWindow) => {
50
+ const handleUnauthenticatedReconnectChat = async (chatSDK, authProps, dispatch, setAdapter, reconnectId, initStartChat, redirectInSameWindow) => {
50
51
  const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, reconnectId);
51
52
 
52
53
  if (shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
53
- await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, dispatch, setAdapter, initStartChat, redirectInSameWindow);
54
+ await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, authProps, dispatch, setAdapter, initStartChat, redirectInSameWindow);
54
55
  } else {
55
- await setReconnectIdAndStartChat(chatSDK, dispatch, setAdapter, reconnectId, initStartChat);
56
+ await setReconnectIdAndStartChat(chatSDK, authProps, dispatch, setAdapter, reconnectId, initStartChat);
56
57
  }
57
58
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
58
59
 
59
60
 
60
- const startUnauthenticatedReconnectChat = async (chatSDK, dispatch, setAdapter, reconnectId, initStartChat) => {
61
+ const startUnauthenticatedReconnectChat = async (chatSDK, authProps, dispatch, setAdapter, reconnectId, initStartChat) => {
61
62
  const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, reconnectId);
62
63
 
63
64
  if (!shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
64
- await setReconnectIdAndStartChat(chatSDK, dispatch, setAdapter, reconnectId, initStartChat);
65
+ await setReconnectIdAndStartChat(chatSDK, authProps, dispatch, setAdapter, reconnectId, initStartChat);
65
66
  }
66
67
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
67
68
 
68
69
 
69
- const setReconnectIdAndStartChat = async (chatSDK, dispatch, setAdapter, reconnectId, initStartChat) => {
70
+ const setReconnectIdAndStartChat = async (chatSDK, authProps, dispatch, setAdapter, reconnectId, initStartChat) => {
70
71
  const startUnauthenticatedReconnectChat = {
71
72
  eventName: BroadcastEvent.StartUnauthenticatedReconnectChat
72
73
  };
@@ -82,7 +83,7 @@ const setReconnectIdAndStartChat = async (chatSDK, dispatch, setAdapter, reconne
82
83
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
83
84
  payload: ConversationState.Loading
84
85
  });
85
- await initStartChat(chatSDK, dispatch, setAdapter, optionalParams);
86
+ await initStartChat(chatSDK, authProps, dispatch, setAdapter, optionalParams);
86
87
  };
87
88
 
88
89
  const redirectPage = (redirectURL, redirectInSameWindow) => {
@@ -104,7 +105,7 @@ const shouldRedirectOrStartNewChat = reconnectAvailabilityResponse => {
104
105
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
105
106
 
106
107
 
107
- const startNewChatEmptyRedirectionUrl = async (chatSDK, dispatch, setAdapter, initStartChat) => {
108
+ const startNewChatEmptyRedirectionUrl = async (chatSDK, authProps, dispatch, setAdapter, initStartChat) => {
108
109
  const startUnauthenticatedReconnectChat = {
109
110
  eventName: BroadcastEvent.StartUnauthenticatedReconnectChat
110
111
  };
@@ -127,25 +128,25 @@ const startNewChatEmptyRedirectionUrl = async (chatSDK, dispatch, setAdapter, in
127
128
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
128
129
  payload: ConversationState.Loading
129
130
  });
130
- await initStartChat(chatSDK, dispatch, setAdapter);
131
+ await initStartChat(chatSDK, authProps, dispatch, setAdapter);
131
132
  }
132
133
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
133
134
 
134
135
 
135
- const handleRedirectUnauthenticatedReconnectChat = async (chatSDK, dispatch, setAdapter, initStartChat, reconnectId, redirectInSameWindow) => {
136
+ const handleRedirectUnauthenticatedReconnectChat = async (chatSDK, authProps, dispatch, setAdapter, initStartChat, reconnectId, redirectInSameWindow) => {
136
137
  const reconnectAvailabilityResponse = await getChatReconnectContext(chatSDK, reconnectId);
137
138
 
138
139
  if (shouldRedirectOrStartNewChat(reconnectAvailabilityResponse)) {
139
- await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, dispatch, setAdapter, initStartChat, redirectInSameWindow);
140
+ await redirectOrStartNewChat(reconnectAvailabilityResponse, chatSDK, authProps, dispatch, setAdapter, initStartChat, redirectInSameWindow);
140
141
  }
141
142
  }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
142
143
 
143
144
 
144
- const redirectOrStartNewChat = async (reconnectAvailabilityResponse, chatSDK, dispatch, setAdapter, initStartChat, redirectInSameWindow) => {
145
+ const redirectOrStartNewChat = async (reconnectAvailabilityResponse, chatSDK, authProps, dispatch, setAdapter, initStartChat, redirectInSameWindow) => {
145
146
  if (reconnectAvailabilityResponse.redirectURL) {
146
147
  redirectPage(reconnectAvailabilityResponse.redirectURL, redirectInSameWindow);
147
148
  } else {
148
- await startNewChatEmptyRedirectionUrl(chatSDK, dispatch, setAdapter, initStartChat);
149
+ await startNewChatEmptyRedirectionUrl(chatSDK, authProps, dispatch, setAdapter, initStartChat);
149
150
  }
150
151
  };
151
152
 
@@ -29,10 +29,6 @@ export const setPostChatContextAndLoadSurvey = async (chatSDK, dispatch, persist
29
29
 
30
30
 
31
31
  BroadcastService.getMessageByEventName("LoadPostChatSurvey").subscribe(msg => {
32
- dispatch({
33
- type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
34
- payload: ConversationState.Loading
35
- });
36
32
  dispatch({
37
33
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
38
34
  payload: ConversationState.Postchat
@@ -0,0 +1,38 @@
1
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2
+ export function shareObservable(observable) {
3
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
+ let observers = []; // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
+
6
+ let subscription; // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
+
8
+ return new window.Observable(observer => {
9
+ if (!subscription) {
10
+ subscription = observable.subscribe({
11
+ complete() {
12
+ observers.forEach(observer => observer.complete());
13
+ },
14
+
15
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
+ error(err) {
17
+ observers.forEach(observer => observer.error(err));
18
+ },
19
+
20
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
+ next(value) {
22
+ observers.forEach(observer => observer.next(value));
23
+ }
24
+
25
+ });
26
+ }
27
+
28
+ observers.push(observer);
29
+ return () => {
30
+ observers = observers.filter(o => o !== observer);
31
+
32
+ if (!observers.length) {
33
+ subscription.unsubscribe();
34
+ subscription = null;
35
+ }
36
+ };
37
+ });
38
+ }