@microsoft/omnichannel-chat-widget 1.4.0 → 1.4.1-main.9bf5e75

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.
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.prepareEndChat = exports.endVoiceVideoCallIfOngoing = exports.endChat = void 0;
6
+ exports.prepareEndChat = exports.endVoiceVideoCallIfOngoing = exports.endChatStateCleanUp = exports.endChat = exports.closeChatStateCleanUp = exports.callingStateCleanUp = void 0;
7
7
  var _Constants = require("../../../common/Constants");
8
8
  var _TelemetryConstants = require("../../../common/telemetry/TelemetryConstants");
9
9
  var _authHelper = require("./authHelper");
@@ -15,8 +15,9 @@ var _LiveChatWidgetActionType = require("../../../contexts/common/LiveChatWidget
15
15
  var _TelemetryHelper = require("../../../common/telemetry/TelemetryHelper");
16
16
  var _WebChatStoreLoader = require("../../webchatcontainerstateful/webchatcontroller/WebChatStoreLoader");
17
17
  var _defaultWebChatContainerStatefulProps = require("../../webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps");
18
+ var _TelemetryManager = require("../../../common/telemetry/TelemetryManager");
18
19
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
- const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, uwid) => {
20
+ const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter) => {
20
21
  try {
21
22
  var _conversationDetails$, _state$domainStates, _state$domainStates2;
22
23
  // Use Case: If call is ongoing, end the call by simulating end call button click
@@ -28,7 +29,7 @@ const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWe
28
29
  var _state$appStates;
29
30
  // If ended by customer, just close chat
30
31
  if ((state === null || state === void 0 ? void 0 : (_state$appStates = state.appStates) === null || _state$appStates === void 0 ? void 0 : _state$appStates.conversationEndedBy) === _Constants.ConversationEndEntity.Customer) {
31
- await endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true, uwid);
32
+ await endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true);
32
33
  }
33
34
  // Use Case: If ended by Agent, stay chat in InActive state
34
35
  return;
@@ -51,7 +52,7 @@ const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWe
51
52
  var _state$appStates2;
52
53
  // For Customer intiated conversations, just close chat widget
53
54
  if ((state === null || state === void 0 ? void 0 : (_state$appStates2 = state.appStates) === null || _state$appStates2 === void 0 ? void 0 : _state$appStates2.conversationEndedBy) === _Constants.ConversationEndEntity.Customer) {
54
- await endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true, uwid);
55
+ await endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true);
55
56
  return;
56
57
  }
57
58
 
@@ -62,7 +63,7 @@ const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWe
62
63
  });
63
64
  return;
64
65
  }
65
- endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, true, true, uwid);
66
+ endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, true, true);
66
67
 
67
68
  // Initiate post chat render
68
69
  if (state !== null && state !== void 0 && (_state$domainStates2 = state.domainStates) !== null && _state$domainStates2 !== void 0 && _state$domainStates2.postChatContext) {
@@ -80,7 +81,7 @@ const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWe
80
81
 
81
82
  //Close chat widget for any failure in embedded to allow to show start chat button
82
83
  if (((_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.hideStartChatButton) === false) {
83
- await endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true, uwid);
84
+ await endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true);
84
85
  }
85
86
  } finally {
86
87
  //Chat token clean up
@@ -90,8 +91,7 @@ const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWe
90
91
 
91
92
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
92
93
  exports.prepareEndChat = prepareEndChat;
93
- const endChat = async function (props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab) {
94
- let uwid = arguments.length > 10 && arguments[10] !== undefined ? arguments[10] : "";
94
+ const endChat = async (props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab) => {
95
95
  if (!skipEndChatSDK && chatSDK.conversation) {
96
96
  try {
97
97
  _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
@@ -143,11 +143,13 @@ const endChat = async function (props, chatSDK, state, dispatch, setAdapter, set
143
143
  closeChatWidget(dispatch, props, state);
144
144
  }
145
145
  }
146
- if (postMessageToOtherTab && !(0, _utils.isNullOrEmptyString)(uwid)) {
146
+ if (postMessageToOtherTab) {
147
147
  const endChatEventName = await getEndChatEventName(chatSDK, props);
148
148
  _omnichannelChatComponents.BroadcastService.postMessage({
149
149
  eventName: endChatEventName,
150
- payload: uwid
150
+ payload: {
151
+ runtimeId: _TelemetryManager.TelemetryManager.InternalTelemetryData.lcwRuntimeId
152
+ }
151
153
  });
152
154
  }
153
155
  };
@@ -174,6 +176,7 @@ const callingStateCleanUp = async dispatch => {
174
176
  payload: true
175
177
  });
176
178
  };
179
+ exports.callingStateCleanUp = callingStateCleanUp;
177
180
  const endChatStateCleanUp = async dispatch => {
178
181
  // Need to clear these states immediately when chat ended from OC.
179
182
  dispatch({
@@ -189,6 +192,7 @@ const endChatStateCleanUp = async dispatch => {
189
192
  payload: false
190
193
  });
191
194
  };
195
+ exports.endChatStateCleanUp = endChatStateCleanUp;
192
196
  const closeChatStateCleanUp = async dispatch => {
193
197
  dispatch({
194
198
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CHAT_TOKEN,
@@ -226,6 +230,7 @@ const closeChatStateCleanUp = async dispatch => {
226
230
  };
227
231
 
228
232
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
233
+ exports.closeChatStateCleanUp = closeChatStateCleanUp;
229
234
  const endVoiceVideoCallIfOngoing = async (chatSDK, dispatch) => {
230
235
  let callId = "";
231
236
  try {
@@ -55,6 +55,7 @@ var _useChatAdapterStore = _interopRequireDefault(require("../../../hooks/useCha
55
55
  var _useChatContextStore = _interopRequireDefault(require("../../../hooks/useChatContextStore"));
56
56
  var _useChatSDKStore = _interopRequireDefault(require("../../../hooks/useChatSDKStore"));
57
57
  var _defaultAdaptiveCardStyles = require("../../webchatcontainerstateful/common/defaultStyles/defaultAdaptiveCardStyles");
58
+ var _omnichannelChatSdk = require("@microsoft/omnichannel-chat-sdk");
58
59
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
59
60
  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); }
60
61
  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; }
@@ -93,8 +94,6 @@ const LiveChatWidgetStateful = props => {
93
94
  const lastLWICheckTimeRef = (0, _react2.useRef)(0);
94
95
  let optionalParams;
95
96
  let activeCachedChatExist = false;
96
- const uwid = (0, _react2.useRef)(""); // its an uniqueid per chatr instance
97
-
98
97
  const setOptionalParams = () => {
99
98
  var _state$appStates, _state$domainStates, _state$appStates3;
100
99
  if (!(0, _utils.isUndefinedOrEmpty)((_state$appStates = state.appStates) === null || _state$appStates === void 0 ? void 0 : _state$appStates.reconnectId)) {
@@ -195,7 +194,6 @@ const LiveChatWidgetStateful = props => {
195
194
  setupClientDataStore();
196
195
  (0, _registerTelemetryLoggers.registerTelemetryLoggers)(props, dispatch);
197
196
  (0, _createInternetConnectionChangeHandler.createInternetConnectionChangeHandler)();
198
- uwid.current = (0, _utils.newGuid)();
199
197
  dispatch({
200
198
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_WIDGET_ELEMENT_ID,
201
199
  payload: widgetElementId
@@ -328,23 +326,27 @@ const LiveChatWidgetStateful = props => {
328
326
 
329
327
  // Start chat from SDK Event
330
328
  _omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.StartChat).subscribe(msg => {
331
- var _msg$payload4;
329
+ var _msg$payload4, _msg$payload5, _msg$payload6;
330
+ // If the startChat event is not initiated by the same tab. Ignore the call
331
+ if (!(0, _utils.isNullOrUndefined)(msg === null || msg === void 0 ? void 0 : (_msg$payload4 = msg.payload) === null || _msg$payload4 === void 0 ? void 0 : _msg$payload4.runtimeId) && (msg === null || msg === void 0 ? void 0 : (_msg$payload5 = msg.payload) === null || _msg$payload5 === void 0 ? void 0 : _msg$payload5.runtimeId) !== _TelemetryManager.TelemetryManager.InternalTelemetryData.lcwRuntimeId) {
332
+ return;
333
+ }
332
334
  let stateWithUpdatedContext = state;
333
- if (msg !== null && msg !== void 0 && (_msg$payload4 = msg.payload) !== null && _msg$payload4 !== void 0 && _msg$payload4.customContext) {
334
- var _msg$payload5, _msg$payload6;
335
+ if (msg !== null && msg !== void 0 && (_msg$payload6 = msg.payload) !== null && _msg$payload6 !== void 0 && _msg$payload6.customContext) {
336
+ var _msg$payload7, _msg$payload8;
335
337
  _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
336
338
  Event: _TelemetryConstants.TelemetryEvent.CustomContextReceived,
337
339
  Description: "CustomContext received through startChat event."
338
340
  });
339
341
  dispatch({
340
342
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CUSTOM_CONTEXT,
341
- payload: msg === null || msg === void 0 ? void 0 : (_msg$payload5 = msg.payload) === null || _msg$payload5 === void 0 ? void 0 : _msg$payload5.customContext
343
+ payload: msg === null || msg === void 0 ? void 0 : (_msg$payload7 = msg.payload) === null || _msg$payload7 === void 0 ? void 0 : _msg$payload7.customContext
342
344
  });
343
345
  stateWithUpdatedContext = {
344
346
  ...state,
345
347
  domainStates: {
346
348
  ...state.domainStates,
347
- customContext: msg === null || msg === void 0 ? void 0 : (_msg$payload6 = msg.payload) === null || _msg$payload6 === void 0 ? void 0 : _msg$payload6.customContext
349
+ customContext: msg === null || msg === void 0 ? void 0 : (_msg$payload8 = msg.payload) === null || _msg$payload8 === void 0 ? void 0 : _msg$payload8.customContext
348
350
  }
349
351
  };
350
352
  }
@@ -422,9 +424,16 @@ const LiveChatWidgetStateful = props => {
422
424
  // Listen to end chat event from other tabs
423
425
  const endChatEventName = (0, _utils.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$controlProps10 = props.controlProps) === null || _props$controlProps10 === void 0 ? void 0 : _props$controlProps10.widgetInstanceId) ?? "");
424
426
  _omnichannelChatComponents.BroadcastService.getMessageByEventName(endChatEventName).subscribe(msg => {
425
- console.log("Receiving end chat event", JSON.stringify(msg.payload));
426
- if (msg.payload !== uwid.current) {
427
+ var _msg$payload9;
428
+ if ((msg === null || msg === void 0 ? void 0 : (_msg$payload9 = msg.payload) === null || _msg$payload9 === void 0 ? void 0 : _msg$payload9.runtimeId) !== _TelemetryManager.TelemetryManager.InternalTelemetryData.lcwRuntimeId) {
427
429
  (0, _endChat.endChat)(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, true, false, false);
430
+ (0, _endChat.endChatStateCleanUp)(dispatch);
431
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
432
+ chatSDK.requestId = (0, _omnichannelChatSdk.uuidv4)();
433
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
434
+ chatSDK.chatToken = {};
435
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
436
+ chatSDK.reconnectId = null;
428
437
  return;
429
438
  }
430
439
  });
@@ -552,13 +561,13 @@ const LiveChatWidgetStateful = props => {
552
561
 
553
562
  // If start chat failed, and C2 is trying to close chat widget
554
563
  if (state !== null && state !== void 0 && (_state$appStates9 = state.appStates) !== null && _state$appStates9 !== void 0 && _state$appStates9.startChatFailed || (state === null || state === void 0 ? void 0 : (_state$appStates10 = state.appStates) === null || _state$appStates10 === void 0 ? void 0 : _state$appStates10.conversationState) === _ConversationState.ConversationState.Postchat) {
555
- (0, _endChat.endChat)(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, true, false, true, uwid.current);
564
+ (0, _endChat.endChat)(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, true, false, true);
556
565
  return;
557
566
  }
558
567
 
559
568
  // Scenario -> Chat was InActive and closing the chat (Refresh scenario on post chat)
560
569
  if ((state === null || state === void 0 ? void 0 : (_state$appStates11 = state.appStates) === null || _state$appStates11 === void 0 ? void 0 : _state$appStates11.conversationState) === _ConversationState.ConversationState.InActive) {
561
- (0, _endChat.endChat)(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true, uwid.current);
570
+ (0, _endChat.endChat)(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true);
562
571
  return;
563
572
  }
564
573
  if ((state === null || state === void 0 ? void 0 : (_state$appStates12 = state.appStates) === null || _state$appStates12 === void 0 ? void 0 : _state$appStates12.conversationEndedBy) === _Constants.ConversationEndEntity.Agent || (state === null || state === void 0 ? void 0 : (_state$appStates13 = state.appStates) === null || _state$appStates13 === void 0 ? void 0 : _state$appStates13.conversationEndedBy) === _Constants.ConversationEndEntity.Bot) {
@@ -569,7 +578,7 @@ const LiveChatWidgetStateful = props => {
569
578
  }
570
579
 
571
580
  // All other cases
572
- (0, _endChat.prepareEndChat)(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, uwid.current);
581
+ (0, _endChat.prepareEndChat)(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter);
573
582
  }, [state === null || state === void 0 ? void 0 : (_state$appStates14 = state.appStates) === null || _state$appStates14 === void 0 ? void 0 : _state$appStates14.conversationEndedBy]);
574
583
 
575
584
  // Publish chat widget state
@@ -627,13 +636,13 @@ const LiveChatWidgetStateful = props => {
627
636
  };
628
637
  const setPostChatContextRelay = () => (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch);
629
638
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
630
- const endChatRelay = (adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab) => (0, _endChat.endChat)(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab, uwid.current);
639
+ const endChatRelay = (adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab) => (0, _endChat.endChat)(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab);
631
640
  const prepareStartChatRelay = () => (0, _startChat.prepareStartChat)(props, chatSDK, state, dispatch, setAdapter);
632
641
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
633
642
  const initStartChatRelay = (optionalParams, persistedState) => (0, _startChat.initStartChat)(chatSDK, dispatch, setAdapter, state, props, optionalParams, persistedState);
634
643
  const confirmationPaneProps = (0, _initConfirmationPropsComposer.initConfirmationPropsComposer)(props);
635
644
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
636
- const prepareEndChatRelay = () => (0, _endChat.prepareEndChat)(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, uwid.current);
645
+ const prepareEndChatRelay = () => (0, _endChat.prepareEndChat)(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter);
637
646
  const webChatProps = (0, _initWebChatComposer.initWebChatComposer)(props, state, dispatch, chatSDK, endChatRelay);
638
647
  const downloadTranscriptProps = (0, _createDownloadTranscriptProps.default)(props.downloadTranscriptProps, {
639
648
  ...(_defaultWebChatContainerStatefulProps.defaultWebChatContainerStatefulProps === null || _defaultWebChatContainerStatefulProps.defaultWebChatContainerStatefulProps === void 0 ? void 0 : _defaultWebChatContainerStatefulProps.defaultWebChatContainerStatefulProps.webChatStyles),
@@ -1,7 +1,7 @@
1
1
  import { ConfirmationState, Constants, ConversationEndEntity, ParticipantType } from "../../../common/Constants";
2
2
  import { LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
3
3
  import { getAuthClientFunction, handleAuthentication } from "./authHelper";
4
- import { getConversationDetailsCall, getWidgetEndChatEventName, isNullOrEmptyString } from "../../../common/utils";
4
+ import { getConversationDetailsCall, getWidgetEndChatEventName } from "../../../common/utils";
5
5
  import { getPostChatContext, initiatePostChat } from "./renderSurveyHelpers";
6
6
  import { BroadcastService } from "@microsoft/omnichannel-chat-components";
7
7
  import { ConversationState } from "../../../contexts/common/ConversationState";
@@ -9,9 +9,10 @@ import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidge
9
9
  import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
10
10
  import { WebChatStoreLoader } from "../../webchatcontainerstateful/webchatcontroller/WebChatStoreLoader";
11
11
  import { defaultWebChatContainerStatefulProps } from "../../webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps";
12
+ import { TelemetryManager } from "../../../common/telemetry/TelemetryManager";
12
13
 
13
14
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
- const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, uwid) => {
15
+ const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter) => {
15
16
  try {
16
17
  var _conversationDetails$, _state$domainStates, _state$domainStates2;
17
18
  // Use Case: If call is ongoing, end the call by simulating end call button click
@@ -23,7 +24,7 @@ const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWe
23
24
  var _state$appStates;
24
25
  // If ended by customer, just close chat
25
26
  if ((state === null || state === void 0 ? void 0 : (_state$appStates = state.appStates) === null || _state$appStates === void 0 ? void 0 : _state$appStates.conversationEndedBy) === ConversationEndEntity.Customer) {
26
- await endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true, uwid);
27
+ await endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true);
27
28
  }
28
29
  // Use Case: If ended by Agent, stay chat in InActive state
29
30
  return;
@@ -46,7 +47,7 @@ const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWe
46
47
  var _state$appStates2;
47
48
  // For Customer intiated conversations, just close chat widget
48
49
  if ((state === null || state === void 0 ? void 0 : (_state$appStates2 = state.appStates) === null || _state$appStates2 === void 0 ? void 0 : _state$appStates2.conversationEndedBy) === ConversationEndEntity.Customer) {
49
- await endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true, uwid);
50
+ await endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true);
50
51
  return;
51
52
  }
52
53
 
@@ -57,7 +58,7 @@ const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWe
57
58
  });
58
59
  return;
59
60
  }
60
- endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, true, true, uwid);
61
+ endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, true, true);
61
62
 
62
63
  // Initiate post chat render
63
64
  if (state !== null && state !== void 0 && (_state$domainStates2 = state.domainStates) !== null && _state$domainStates2 !== void 0 && _state$domainStates2.postChatContext) {
@@ -75,7 +76,7 @@ const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWe
75
76
 
76
77
  //Close chat widget for any failure in embedded to allow to show start chat button
77
78
  if (((_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.hideStartChatButton) === false) {
78
- await endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true, uwid);
79
+ await endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true);
79
80
  }
80
81
  } finally {
81
82
  //Chat token clean up
@@ -84,8 +85,7 @@ const prepareEndChat = async (props, chatSDK, state, dispatch, setAdapter, setWe
84
85
  };
85
86
 
86
87
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
87
- const endChat = async function (props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab) {
88
- let uwid = arguments.length > 10 && arguments[10] !== undefined ? arguments[10] : "";
88
+ const endChat = async (props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab) => {
89
89
  if (!skipEndChatSDK && chatSDK.conversation) {
90
90
  try {
91
91
  TelemetryHelper.logSDKEvent(LogLevel.INFO, {
@@ -137,15 +137,17 @@ const endChat = async function (props, chatSDK, state, dispatch, setAdapter, set
137
137
  closeChatWidget(dispatch, props, state);
138
138
  }
139
139
  }
140
- if (postMessageToOtherTab && !isNullOrEmptyString(uwid)) {
140
+ if (postMessageToOtherTab) {
141
141
  const endChatEventName = await getEndChatEventName(chatSDK, props);
142
142
  BroadcastService.postMessage({
143
143
  eventName: endChatEventName,
144
- payload: uwid
144
+ payload: {
145
+ runtimeId: TelemetryManager.InternalTelemetryData.lcwRuntimeId
146
+ }
145
147
  });
146
148
  }
147
149
  };
148
- const callingStateCleanUp = async dispatch => {
150
+ export const callingStateCleanUp = async dispatch => {
149
151
  dispatch({
150
152
  type: LiveChatWidgetActionType.SHOW_CALLING_CONTAINER,
151
153
  payload: false
@@ -167,7 +169,7 @@ const callingStateCleanUp = async dispatch => {
167
169
  payload: true
168
170
  });
169
171
  };
170
- const endChatStateCleanUp = async dispatch => {
172
+ export const endChatStateCleanUp = async dispatch => {
171
173
  // Need to clear these states immediately when chat ended from OC.
172
174
  dispatch({
173
175
  type: LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
@@ -182,7 +184,7 @@ const endChatStateCleanUp = async dispatch => {
182
184
  payload: false
183
185
  });
184
186
  };
185
- const closeChatStateCleanUp = async dispatch => {
187
+ export const closeChatStateCleanUp = async dispatch => {
186
188
  dispatch({
187
189
  type: LiveChatWidgetActionType.SET_CHAT_TOKEN,
188
190
  payload: undefined
@@ -6,9 +6,9 @@ import { ConfirmationState, Constants, ConversationEndEntity, E2VVOptions, LiveW
6
6
  import { Stack } from "@fluentui/react";
7
7
  import React, { useEffect, useRef, useState } from "react";
8
8
  import { checkIfConversationStillValid, initStartChat, prepareStartChat, setPreChatAndInitiateChat } from "../common/startChat";
9
- import { createTimer, getBroadcastChannelName, getConversationDetailsCall, getLocaleDirection, getStateFromCache, getWidgetCacheIdfromProps, getWidgetEndChatEventName, isNullOrEmptyString, isUndefinedOrEmpty, newGuid } from "../../../common/utils";
9
+ import { createTimer, getBroadcastChannelName, getConversationDetailsCall, getLocaleDirection, getStateFromCache, getWidgetCacheIdfromProps, getWidgetEndChatEventName, isNullOrEmptyString, isNullOrUndefined, isUndefinedOrEmpty } from "../../../common/utils";
10
10
  import { defaultClientDataStoreProvider, isCookieAllowed } from "../../../common/storage/default/defaultClientDataStoreProvider";
11
- import { endChat, prepareEndChat } from "../common/endChat";
11
+ import { endChat, endChatStateCleanUp, prepareEndChat } from "../common/endChat";
12
12
  import { handleChatReconnect, isPersistentEnabled, isReconnectEnabled } from "../common/reconnectChatHelper";
13
13
  import { shouldShowCallingContainer, shouldShowChatButton, shouldShowConfirmationPane, shouldShowEmailTranscriptPane, shouldShowHeader, shouldShowLoadingPane, shouldShowOutOfOfficeHoursPane, shouldShowPostChatLoadingPane, shouldShowPostChatSurveyPane, shouldShowPreChatSurveyPane, shouldShowProactiveChatPane, shouldShowReconnectChatPane, shouldShowWebChatContainer } from "../../../controller/componentController";
14
14
  import { ActivityStreamHandler } from "../common/ActivityStreamHandler";
@@ -30,7 +30,7 @@ import PreChatSurveyPaneStateful from "../../prechatsurveypanestateful/PreChatSu
30
30
  import ProactiveChatPaneStateful from "../../proactivechatpanestateful/ProactiveChatPaneStateful";
31
31
  import ReconnectChatPaneStateful from "../../reconnectchatpanestateful/ReconnectChatPaneStateful";
32
32
  import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
33
- import { TelemetryTimers } from "../../../common/telemetry/TelemetryManager";
33
+ import { TelemetryManager, TelemetryTimers } from "../../../common/telemetry/TelemetryManager";
34
34
  import WebChatContainerStateful from "../../webchatcontainerstateful/WebChatContainerStateful";
35
35
  import createDownloadTranscriptProps from "../common/createDownloadTranscriptProps";
36
36
  import { createFooter } from "../common/createFooter";
@@ -51,6 +51,7 @@ import useChatAdapterStore from "../../../hooks/useChatAdapterStore";
51
51
  import useChatContextStore from "../../../hooks/useChatContextStore";
52
52
  import useChatSDKStore from "../../../hooks/useChatSDKStore";
53
53
  import { defaultAdaptiveCardStyles } from "../../webchatcontainerstateful/common/defaultStyles/defaultAdaptiveCardStyles";
54
+ import { uuidv4 } from "@microsoft/omnichannel-chat-sdk";
54
55
  export const LiveChatWidgetStateful = props => {
55
56
  var _props$webChatContain, _props$styleProps, _chatSDK$omnichannelC, _props$controlProps, _props$controlProps2, _state$appStates7, _props$webChatContain5, _state$appStates14, _props$webChatContain6, _props$controlProps11, _props$draggableChatW, _props$draggableChatW2, _props$draggableChatW3, _props$draggableChatW4, _props$draggableChatW5, _props$webChatContain7, _props$webChatContain8, _props$webChatContain9, _props$webChatContain10, _livechatProps$webCha, _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$contro10, _livechatProps$compon8, _livechatProps$contro11, _livechatProps$compon9, _livechatProps$contro12, _livechatProps$compon10, _livechatProps$compon11, _livechatProps$compon12;
56
57
  const [state, dispatch] = useChatContextStore();
@@ -85,8 +86,6 @@ export const LiveChatWidgetStateful = props => {
85
86
  const lastLWICheckTimeRef = useRef(0);
86
87
  let optionalParams;
87
88
  let activeCachedChatExist = false;
88
- const uwid = useRef(""); // its an uniqueid per chatr instance
89
-
90
89
  const setOptionalParams = () => {
91
90
  var _state$appStates, _state$domainStates, _state$appStates3;
92
91
  if (!isUndefinedOrEmpty((_state$appStates = state.appStates) === null || _state$appStates === void 0 ? void 0 : _state$appStates.reconnectId)) {
@@ -187,7 +186,6 @@ export const LiveChatWidgetStateful = props => {
187
186
  setupClientDataStore();
188
187
  registerTelemetryLoggers(props, dispatch);
189
188
  createInternetConnectionChangeHandler();
190
- uwid.current = newGuid();
191
189
  dispatch({
192
190
  type: LiveChatWidgetActionType.SET_WIDGET_ELEMENT_ID,
193
191
  payload: widgetElementId
@@ -320,23 +318,27 @@ export const LiveChatWidgetStateful = props => {
320
318
 
321
319
  // Start chat from SDK Event
322
320
  BroadcastService.getMessageByEventName(BroadcastEvent.StartChat).subscribe(msg => {
323
- var _msg$payload4;
321
+ var _msg$payload4, _msg$payload5, _msg$payload6;
322
+ // If the startChat event is not initiated by the same tab. Ignore the call
323
+ if (!isNullOrUndefined(msg === null || msg === void 0 ? void 0 : (_msg$payload4 = msg.payload) === null || _msg$payload4 === void 0 ? void 0 : _msg$payload4.runtimeId) && (msg === null || msg === void 0 ? void 0 : (_msg$payload5 = msg.payload) === null || _msg$payload5 === void 0 ? void 0 : _msg$payload5.runtimeId) !== TelemetryManager.InternalTelemetryData.lcwRuntimeId) {
324
+ return;
325
+ }
324
326
  let stateWithUpdatedContext = state;
325
- if (msg !== null && msg !== void 0 && (_msg$payload4 = msg.payload) !== null && _msg$payload4 !== void 0 && _msg$payload4.customContext) {
326
- var _msg$payload5, _msg$payload6;
327
+ if (msg !== null && msg !== void 0 && (_msg$payload6 = msg.payload) !== null && _msg$payload6 !== void 0 && _msg$payload6.customContext) {
328
+ var _msg$payload7, _msg$payload8;
327
329
  TelemetryHelper.logActionEvent(LogLevel.INFO, {
328
330
  Event: TelemetryEvent.CustomContextReceived,
329
331
  Description: "CustomContext received through startChat event."
330
332
  });
331
333
  dispatch({
332
334
  type: LiveChatWidgetActionType.SET_CUSTOM_CONTEXT,
333
- payload: msg === null || msg === void 0 ? void 0 : (_msg$payload5 = msg.payload) === null || _msg$payload5 === void 0 ? void 0 : _msg$payload5.customContext
335
+ payload: msg === null || msg === void 0 ? void 0 : (_msg$payload7 = msg.payload) === null || _msg$payload7 === void 0 ? void 0 : _msg$payload7.customContext
334
336
  });
335
337
  stateWithUpdatedContext = {
336
338
  ...state,
337
339
  domainStates: {
338
340
  ...state.domainStates,
339
- customContext: msg === null || msg === void 0 ? void 0 : (_msg$payload6 = msg.payload) === null || _msg$payload6 === void 0 ? void 0 : _msg$payload6.customContext
341
+ customContext: msg === null || msg === void 0 ? void 0 : (_msg$payload8 = msg.payload) === null || _msg$payload8 === void 0 ? void 0 : _msg$payload8.customContext
340
342
  }
341
343
  };
342
344
  }
@@ -414,9 +416,16 @@ export const LiveChatWidgetStateful = props => {
414
416
  // Listen to end chat event from other tabs
415
417
  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$controlProps10 = props.controlProps) === null || _props$controlProps10 === void 0 ? void 0 : _props$controlProps10.widgetInstanceId) ?? "");
416
418
  BroadcastService.getMessageByEventName(endChatEventName).subscribe(msg => {
417
- console.log("Receiving end chat event", JSON.stringify(msg.payload));
418
- if (msg.payload !== uwid.current) {
419
+ var _msg$payload9;
420
+ if ((msg === null || msg === void 0 ? void 0 : (_msg$payload9 = msg.payload) === null || _msg$payload9 === void 0 ? void 0 : _msg$payload9.runtimeId) !== TelemetryManager.InternalTelemetryData.lcwRuntimeId) {
419
421
  endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, true, false, false);
422
+ endChatStateCleanUp(dispatch);
423
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
424
+ chatSDK.requestId = uuidv4();
425
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
426
+ chatSDK.chatToken = {};
427
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
428
+ chatSDK.reconnectId = null;
420
429
  return;
421
430
  }
422
431
  });
@@ -544,13 +553,13 @@ export const LiveChatWidgetStateful = props => {
544
553
 
545
554
  // If start chat failed, and C2 is trying to close chat widget
546
555
  if (state !== null && state !== void 0 && (_state$appStates9 = state.appStates) !== null && _state$appStates9 !== void 0 && _state$appStates9.startChatFailed || (state === null || state === void 0 ? void 0 : (_state$appStates10 = state.appStates) === null || _state$appStates10 === void 0 ? void 0 : _state$appStates10.conversationState) === ConversationState.Postchat) {
547
- endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, true, false, true, uwid.current);
556
+ endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, true, false, true);
548
557
  return;
549
558
  }
550
559
 
551
560
  // Scenario -> Chat was InActive and closing the chat (Refresh scenario on post chat)
552
561
  if ((state === null || state === void 0 ? void 0 : (_state$appStates11 = state.appStates) === null || _state$appStates11 === void 0 ? void 0 : _state$appStates11.conversationState) === ConversationState.InActive) {
553
- endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true, uwid.current);
562
+ endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, false, false, true);
554
563
  return;
555
564
  }
556
565
  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) {
@@ -561,7 +570,7 @@ export const LiveChatWidgetStateful = props => {
561
570
  }
562
571
 
563
572
  // All other cases
564
- prepareEndChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, uwid.current);
573
+ prepareEndChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter);
565
574
  }, [state === null || state === void 0 ? void 0 : (_state$appStates14 = state.appStates) === null || _state$appStates14 === void 0 ? void 0 : _state$appStates14.conversationEndedBy]);
566
575
 
567
576
  // Publish chat widget state
@@ -619,13 +628,13 @@ export const LiveChatWidgetStateful = props => {
619
628
  };
620
629
  const setPostChatContextRelay = () => setPostChatContextAndLoadSurvey(chatSDK, dispatch);
621
630
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
622
- const endChatRelay = (adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab) => endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab, uwid.current);
631
+ const endChatRelay = (adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab) => endChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, skipEndChatSDK, skipCloseChat, postMessageToOtherTab);
623
632
  const prepareStartChatRelay = () => prepareStartChat(props, chatSDK, state, dispatch, setAdapter);
624
633
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
625
634
  const initStartChatRelay = (optionalParams, persistedState) => initStartChat(chatSDK, dispatch, setAdapter, state, props, optionalParams, persistedState);
626
635
  const confirmationPaneProps = initConfirmationPropsComposer(props);
627
636
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
628
- const prepareEndChatRelay = () => prepareEndChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter, uwid.current);
637
+ const prepareEndChatRelay = () => prepareEndChat(props, chatSDK, state, dispatch, setAdapter, setWebChatStyles, adapter);
629
638
  const webChatProps = initWebChatComposer(props, state, dispatch, chatSDK, endChatRelay);
630
639
  const downloadTranscriptProps = createDownloadTranscriptProps(props.downloadTranscriptProps, {
631
640
  ...(defaultWebChatContainerStatefulProps === null || defaultWebChatContainerStatefulProps === void 0 ? void 0 : defaultWebChatContainerStatefulProps.webChatStyles),
@@ -2,7 +2,10 @@ import { Dispatch } from "react";
2
2
  import { ILiveChatWidgetAction } from "../../../contexts/common/ILiveChatWidgetAction";
3
3
  import { ILiveChatWidgetContext } from "../../../contexts/common/ILiveChatWidgetContext";
4
4
  import { ILiveChatWidgetProps } from "../interfaces/ILiveChatWidgetProps";
5
- declare const prepareEndChat: (props: ILiveChatWidgetProps, chatSDK: any, state: ILiveChatWidgetContext, dispatch: Dispatch<ILiveChatWidgetAction>, setAdapter: any, setWebChatStyles: any, adapter: any, uwid: string) => Promise<void>;
6
- declare const endChat: (props: ILiveChatWidgetProps, chatSDK: any, state: ILiveChatWidgetContext, dispatch: Dispatch<ILiveChatWidgetAction>, setAdapter: any, setWebChatStyles: any, adapter: any, skipEndChatSDK?: boolean | undefined, skipCloseChat?: boolean | undefined, postMessageToOtherTab?: boolean | undefined, uwid?: string) => Promise<void>;
5
+ declare const prepareEndChat: (props: ILiveChatWidgetProps, chatSDK: any, state: ILiveChatWidgetContext, dispatch: Dispatch<ILiveChatWidgetAction>, setAdapter: any, setWebChatStyles: any, adapter: any) => Promise<void>;
6
+ declare const endChat: (props: ILiveChatWidgetProps, chatSDK: any, state: ILiveChatWidgetContext, dispatch: Dispatch<ILiveChatWidgetAction>, setAdapter: any, setWebChatStyles: any, adapter: any, skipEndChatSDK?: boolean | undefined, skipCloseChat?: boolean | undefined, postMessageToOtherTab?: boolean | undefined) => Promise<void>;
7
+ export declare const callingStateCleanUp: (dispatch: Dispatch<ILiveChatWidgetAction>) => Promise<void>;
8
+ export declare const endChatStateCleanUp: (dispatch: Dispatch<ILiveChatWidgetAction>) => Promise<void>;
9
+ export declare const closeChatStateCleanUp: (dispatch: Dispatch<ILiveChatWidgetAction>) => Promise<void>;
7
10
  export declare const endVoiceVideoCallIfOngoing: (chatSDK: any, dispatch: Dispatch<ILiveChatWidgetAction>) => Promise<void>;
8
11
  export { prepareEndChat, endChat };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/omnichannel-chat-widget",
3
- "version": "1.4.0",
3
+ "version": "1.4.1-main.9bf5e75",
4
4
  "description": "Microsoft Omnichannel Chat Widget",
5
5
  "main": "lib/cjs/index.js",
6
6
  "types": "lib/types/index.d.ts",
@@ -74,7 +74,7 @@
74
74
  "webpack-cli": "^4.9.2"
75
75
  },
76
76
  "dependencies": {
77
- "@microsoft/omnichannel-chat-components": "^1.0.7",
77
+ "@microsoft/omnichannel-chat-components": "^1.0.8",
78
78
  "@microsoft/omnichannel-chat-sdk": "1.5.4",
79
79
  "abort-controller-es5": "^2.0.1",
80
80
  "dompurify": "^2.3.4",