@xapp/chat-widget 1.40.3 → 1.41.0
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.
- package/dist/components/FailureMessage/FailureMessage.d.ts +2 -2
- package/dist/index.css +1 -1
- package/dist/index.es.js +43 -7
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +43 -7
- package/dist/index.js.map +1 -1
- package/dist/store/ChatState.d.ts +1 -0
- package/dist/utils/checkSessionExpiration.d.ts +1 -0
- package/dist/utils/convertToSeconds.d.ts +4 -0
- package/package.json +10 -10
package/dist/index.js
CHANGED
|
@@ -7645,6 +7645,35 @@ var ChatMessage = function (props) {
|
|
|
7645
7645
|
React__default$1["default"].createElement("div", { className: "chat-msg-container ".concat(getClassName(props.message)) }, renderByType())));
|
|
7646
7646
|
};
|
|
7647
7647
|
|
|
7648
|
+
/**
|
|
7649
|
+
* value must be like "60m", "2h" etc.
|
|
7650
|
+
*/
|
|
7651
|
+
function convertToSeconds(value) {
|
|
7652
|
+
var unit = value === null || value === void 0 ? void 0 : value.slice(-1);
|
|
7653
|
+
var number = parseFloat(value === null || value === void 0 ? void 0 : value.slice(0, -1));
|
|
7654
|
+
switch (unit) {
|
|
7655
|
+
case "d": {
|
|
7656
|
+
return number * 24 * 60 * 60;
|
|
7657
|
+
}
|
|
7658
|
+
case "h": {
|
|
7659
|
+
return number * 60 * 60;
|
|
7660
|
+
}
|
|
7661
|
+
case "m": {
|
|
7662
|
+
return number * 60;
|
|
7663
|
+
}
|
|
7664
|
+
case "s": {
|
|
7665
|
+
return number;
|
|
7666
|
+
}
|
|
7667
|
+
default: {
|
|
7668
|
+
return number;
|
|
7669
|
+
}
|
|
7670
|
+
}
|
|
7671
|
+
}
|
|
7672
|
+
|
|
7673
|
+
function checkSessionExpiration(duration, lastMessageTimestamp, lastTimestamp) {
|
|
7674
|
+
return lastTimestamp - lastMessageTimestamp > convertToSeconds(duration);
|
|
7675
|
+
}
|
|
7676
|
+
|
|
7648
7677
|
function useExternalScript(url) {
|
|
7649
7678
|
React$1.useEffect(function () {
|
|
7650
7679
|
if (!url) {
|
|
@@ -30824,7 +30853,13 @@ var ChatWidget = function (props) {
|
|
|
30824
30853
|
set$1("visible", newVisible);
|
|
30825
30854
|
}, [staticMode]);
|
|
30826
30855
|
React$1.useEffect(function () {
|
|
30827
|
-
|
|
30856
|
+
var _a;
|
|
30857
|
+
if (checkSessionExpiration(chatState === null || chatState === void 0 ? void 0 : chatState.sessionExpiration, (_a = chatState === null || chatState === void 0 ? void 0 : chatState.chats[chatState.chats.length - 1]) === null || _a === void 0 ? void 0 : _a.timestamp, chatState === null || chatState === void 0 ? void 0 : chatState.lastTimestamp)) {
|
|
30858
|
+
innerDispatch(reset());
|
|
30859
|
+
}
|
|
30860
|
+
}, []);
|
|
30861
|
+
React$1.useEffect(function () {
|
|
30862
|
+
// For reopen widget after move on same windowyar
|
|
30828
30863
|
if (get("opened")) {
|
|
30829
30864
|
setVisible(true);
|
|
30830
30865
|
}
|
|
@@ -30994,7 +31029,7 @@ function createDefaultState(state) {
|
|
|
30994
31029
|
connectionStatus: "offline",
|
|
30995
31030
|
token: null,
|
|
30996
31031
|
greetingRequested: false
|
|
30997
|
-
}, accountStatus: "offline", departments: {}, visitor: DEFAULT_VISITOR, agents: {}, chats: [], lastTimestamp: 0, lastRatingRequestTimestamp: 0, hasRating: false, isChatting: false, queuePosition: 0, failureMsg: null, visitorId: visitorFingerprint(), chips: [] }, state);
|
|
31032
|
+
}, accountStatus: "offline", departments: {}, visitor: DEFAULT_VISITOR, agents: {}, chats: [], lastTimestamp: 0, lastRatingRequestTimestamp: 0, hasRating: false, isChatting: false, queuePosition: 0, failureMsg: null, visitorId: visitorFingerprint(), chips: [], sessionExpiration: "24h" }, state);
|
|
30998
31033
|
}
|
|
30999
31034
|
var DEFAULT_STATE = createDefaultState();
|
|
31000
31035
|
|
|
@@ -31191,7 +31226,7 @@ function createChatStore(config, dataStorage) {
|
|
|
31191
31226
|
if (dataStorage === void 0) { dataStorage = localStorage; }
|
|
31192
31227
|
var connection = config.connection;
|
|
31193
31228
|
var storage = new BrowserStateStorage(dataStorage, "xappchat.".concat(connection.serverUrl, ".").concat(connection.accountKey));
|
|
31194
|
-
var defaultState = createDefaultState({ accessToken: config.accessToken, userId: config.userId, attributes: config.attributes });
|
|
31229
|
+
var defaultState = createDefaultState({ accessToken: config.accessToken, userId: config.userId, attributes: config.attributes, sessionExpiration: config.sessionExpiration });
|
|
31195
31230
|
var chatReducer = persistStateReducer(storage, defaultState, storeHandler);
|
|
31196
31231
|
var middlewares = [
|
|
31197
31232
|
thunk__default["default"]
|
|
@@ -31201,19 +31236,20 @@ function createChatStore(config, dataStorage) {
|
|
|
31201
31236
|
}
|
|
31202
31237
|
|
|
31203
31238
|
var ChatWidgetContainer = function (props) {
|
|
31204
|
-
var _a, _b, _c, _d;
|
|
31239
|
+
var _a, _b, _c, _d, _e;
|
|
31205
31240
|
var messageMiddleware = useStandardMiddleware();
|
|
31206
31241
|
var connection = useServerConfig(props.config);
|
|
31207
31242
|
var chatStore = React$1.useMemo(function () {
|
|
31208
|
-
var _a, _b, _c;
|
|
31243
|
+
var _a, _b, _c, _d;
|
|
31209
31244
|
return createChatStore({
|
|
31210
31245
|
connection: connection,
|
|
31211
31246
|
userId: (_a = props.config) === null || _a === void 0 ? void 0 : _a.userId,
|
|
31212
31247
|
accessToken: (_b = props.config) === null || _b === void 0 ? void 0 : _b.accessToken,
|
|
31213
31248
|
attributes: (_c = props.config) === null || _c === void 0 ? void 0 : _c.attributes,
|
|
31249
|
+
sessionExpiration: (_d = props.config) === null || _d === void 0 ? void 0 : _d.sessionExpiration
|
|
31214
31250
|
});
|
|
31215
|
-
}, [connection, (_a = props.config) === null || _a === void 0 ? void 0 : _a.userId, (_b = props.config) === null || _b === void 0 ? void 0 : _b.accessToken, (_c = props.config) === null || _c === void 0 ? void 0 : _c.attributes]);
|
|
31216
|
-
if ((
|
|
31251
|
+
}, [connection, (_a = props.config) === null || _a === void 0 ? void 0 : _a.userId, (_b = props.config) === null || _b === void 0 ? void 0 : _b.accessToken, (_c = props.config) === null || _c === void 0 ? void 0 : _c.attributes, (_d = props.config) === null || _d === void 0 ? void 0 : _d.sessionExpiration]);
|
|
31252
|
+
if ((_e = props.config) === null || _e === void 0 ? void 0 : _e.disabled) {
|
|
31217
31253
|
return React__default$1["default"].createElement(React__default$1["default"].Fragment, null);
|
|
31218
31254
|
}
|
|
31219
31255
|
var widgetProps = __assign(__assign({}, props), { messageMiddleware: messageMiddleware });
|