@xapp/chat-widget 1.65.0 → 1.65.2

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/index.js CHANGED
@@ -716,7 +716,6 @@ var CtaBubbleContainer = function (props) {
716
716
  isMounted.current = false;
717
717
  };
718
718
  }, [startTime, timeout, delay]);
719
- console.log("visible ".concat(visible, " showBubble ").concat(showBubble));
720
719
  return (React__default$1["default"].createElement(React__default$1["default"].Fragment, null, visible && showBubble && React__default$1["default"].createElement(CtaBubble, { onClick: onClick, animate: animate, buttonAnimation: buttonAnimation }, children)));
721
720
  };
722
721
 
@@ -2439,7 +2438,6 @@ var StentorDirectChat = /** @class */ (function () {
2439
2438
  case 1:
2440
2439
  if (!(i < configurableMessages.length)) return [3 /*break*/, 4];
2441
2440
  timeout = this.config.timeout || 15000;
2442
- console.log("using timeout of ".concat(timeout));
2443
2441
  this.typing();
2444
2442
  // We don't start typing IF we have a failure message displayed and we are waiting on the timeout
2445
2443
  return [4 /*yield*/, new RetryRequest({ retries: 1, timeout: timeout })
@@ -2958,24 +2956,34 @@ var StentorRouterChat = /** @class */ (function () {
2958
2956
  _this.setConnectionStatus("online");
2959
2957
  };
2960
2958
  };
2961
- StentorRouterChat.prototype.wsCreate = function () {
2959
+ StentorRouterChat.prototype.wsClose = function () {
2960
+ if (this.ws) {
2961
+ this.ws.onclose = null;
2962
+ this.ws.onerror = null;
2963
+ this.ws.onopen = null;
2964
+ this.ws.onmessage = null;
2965
+ this.ws.close();
2966
+ }
2967
+ };
2968
+ StentorRouterChat.prototype.wsCreate = function (createWsReason) {
2962
2969
  var _this = this;
2963
- var _a, _b;
2964
2970
  if (this.isDisposed) {
2965
2971
  log("Stopping reconnect for disposed router connector");
2966
2972
  return undefined;
2967
2973
  }
2968
2974
  else {
2969
- log("Trying to re-connect...");
2975
+ log("Trying to re-connect. Reason: \"".concat(createWsReason, "\""));
2970
2976
  }
2971
2977
  var url = new URL(this.serverUrl);
2972
2978
  url.searchParams.set("userId", this._userId);
2973
2979
  url.searchParams.set("isAdmin", "".concat(this.isAdmin));
2980
+ url.searchParams.set("createWsReason", createWsReason); // tell the server the reconnect reason
2974
2981
  // Force close - just in case - when you create new
2975
- if (this.ws && ((_a = this.ws) === null || _a === void 0 ? void 0 : _a.readyState) !== WebSocket.CLOSED) {
2976
- var wsState = (_b = this.ws) === null || _b === void 0 ? void 0 : _b.readyState;
2982
+ if (this.ws && !(this.ws.readyState === WebSocket.CLOSED || this.ws.readyState === WebSocket.CLOSING)) {
2983
+ var wsState = this.ws.readyState;
2984
+ log("Forced WS close. State: ".concat(wsState));
2977
2985
  try {
2978
- this.ws.close();
2986
+ this.wsClose();
2979
2987
  }
2980
2988
  catch (err) {
2981
2989
  err("Failed to close WS (ready state: ".concat(wsState, "): ").concat(err));
@@ -3020,7 +3028,7 @@ var StentorRouterChat = /** @class */ (function () {
3020
3028
  log("Widget says: ".concat(payloadData));
3021
3029
  if (!this.ws) {
3022
3030
  // Fire up the WebSocket
3023
- this.autoReconnect(this.wsCreate.bind(this));
3031
+ this.autoReconnect(this.wsCreate.bind(this, "emitNoWs"));
3024
3032
  }
3025
3033
  return [4 /*yield*/, waitFor(this.checkConnection.bind(this), 1000, 10000, "connection")
3026
3034
  .then(function (t) {
@@ -3175,14 +3183,14 @@ var StentorRouterChat = /** @class */ (function () {
3175
3183
  StentorRouterChat.prototype.dispose = function () {
3176
3184
  this.isDisposed = true;
3177
3185
  if (this.ws) {
3178
- this.ws.close();
3186
+ this.wsClose();
3179
3187
  }
3180
3188
  log("Closed web socket (dispose)");
3181
3189
  };
3182
3190
  StentorRouterChat.prototype.sleep = function () {
3183
3191
  this.isDisposed = true;
3184
3192
  if (this.ws) {
3185
- this.ws.close();
3193
+ this.wsClose();
3186
3194
  }
3187
3195
  log("Closed web socket (sleep)");
3188
3196
  };
@@ -3193,7 +3201,7 @@ var StentorRouterChat = /** @class */ (function () {
3193
3201
  return;
3194
3202
  }
3195
3203
  // Fire up the WebSocket
3196
- this.autoReconnect(this.wsCreate.bind(this));
3204
+ this.autoReconnect(this.wsCreate.bind(this, "wakeup"));
3197
3205
  log("Waking up");
3198
3206
  };
3199
3207
  StentorRouterChat.prototype.bargeOut = function (_cb) {
@@ -8245,11 +8253,11 @@ var Suggestions = function (props) {
8245
8253
  };
8246
8254
 
8247
8255
  var ChatFooter = function (props) {
8248
- var _a, _b;
8256
+ var _a, _b, _c;
8257
+ var isAdmin = props.isAdmin, isChatting = props.isChatting, visible = props.visible, placeholder = props.placeholder, sendButtonIcon = props.sendButtonIcon, footerConfig = props.footerConfig, menuConfig = props.menuConfig, inputConfig = props.inputConfig, onSubmit = props.onSubmit;
8249
8258
  var innerDispatch = useChatDispatch();
8250
- var placeholder = props.placeholder, sendButtonIcon = props.sendButtonIcon, footerConfig = props.footerConfig, menuConfig = props.menuConfig, inputConfig = props.inputConfig, onSubmit = props.onSubmit;
8251
- var _c = React$1.useState(false), drawerOpen = _c[0], setDrawerState = _c[1]; // false initially
8252
- var _d = React$1.useState(), suggestionSearch = _d[0], setSuggestionSearch = _d[1];
8259
+ var _d = React$1.useState(false), drawerOpen = _d[0], setDrawerState = _d[1]; // false initially
8260
+ var _e = React$1.useState(), suggestionSearch = _e[0], setSuggestionSearch = _e[1];
8253
8261
  var contexts = reactRedux.useSelector(function (state) { return state.activeContexts; });
8254
8262
  var suggestions = useSuggestions(suggestionSearch, contexts);
8255
8263
  var menuPosition = (menuConfig === null || menuConfig === void 0 ? void 0 : menuConfig.menuButtonLocation) || "FOOTER";
@@ -8259,11 +8267,13 @@ var ChatFooter = function (props) {
8259
8267
  var menuButtonTabIndex = (_a = menuConfig === null || menuConfig === void 0 ? void 0 : menuConfig.button) === null || _a === void 0 ? void 0 : _a.tabIndex;
8260
8268
  var menuItems = React$1.useMemo(function () { return menuItemsRaw ? menuItemsRaw : []; }, [menuItemsRaw]);
8261
8269
  var brandingEnabled = (_b = footerConfig === null || footerConfig === void 0 ? void 0 : footerConfig.branding) === null || _b === void 0 ? void 0 : _b.enabled;
8262
- var _e = React$1.useState(false), isAdminJoined = _e[0], setAdminJoined = _e[1];
8263
- var _f = React$1.useState({
8270
+ var brandingText = (_c = footerConfig === null || footerConfig === void 0 ? void 0 : footerConfig.branding) === null || _c === void 0 ? void 0 : _c.text;
8271
+ // If they are NOT an admin, automatically enabled the input
8272
+ var _f = React$1.useState(!isAdmin), enableInput = _f[0], setEnableInput = _f[1];
8273
+ var _g = React$1.useState({
8264
8274
  text: "",
8265
8275
  formats: []
8266
- }), input = _f[0], setInput = _f[1];
8276
+ }), input = _g[0], setInput = _g[1];
8267
8277
  function toggleDrawer() {
8268
8278
  var newDrawer = !drawerOpen;
8269
8279
  setDrawerState(newDrawer);
@@ -8295,12 +8305,11 @@ var ChatFooter = function (props) {
8295
8305
  handleSubmit(data);
8296
8306
  }, [handleSubmit]);
8297
8307
  var handleItemUse = React$1.useCallback(function (data) {
8298
- console.log(data);
8299
8308
  setInput(data);
8300
8309
  setSuggestionSearch(data.text);
8301
8310
  }, []);
8302
8311
  var handleAdminJoin = function (status) {
8303
- setAdminJoined(status);
8312
+ setEnableInput(status);
8304
8313
  };
8305
8314
  return (React__default$1["default"].createElement("div", { className: "chat-footer background-footer", "aria-label": menuItems.length ? "to open menu click a button above the rounded rectangle at the bottom of widget" : "", "aria-hidden": false },
8306
8315
  showMenu && menuItems.length ?
@@ -8309,12 +8318,12 @@ var ChatFooter = function (props) {
8309
8318
  React__default$1["default"].createElement("div", { className: "chat-footer__menu-icon" },
8310
8319
  React__default$1["default"].createElement(DrawerBars, { tabIndex: menuButtonTabIndex, onToggle: toggleDrawer }))) : React__default$1["default"].createElement(React__default$1["default"].Fragment, null),
8311
8320
  React__default$1["default"].createElement(Suggestions, { className: "xappw-chat-footer__suggestions", data: suggestions.suggestions, index: suggestions.index, searchTerms: suggestionSearch, onItemClick: handleItemClick, onItemUse: handleItemUse }),
8312
- props.isAdmin && props.isChatting && props.visible && React__default$1["default"].createElement(AdminBar, { onAdminJoin: handleAdminJoin }),
8313
- React__default$1["default"].createElement("div", { style: { pointerEvents: isAdminJoined ? "auto" : "none", opacity: isAdminJoined ? 1 : 0.5 } },
8314
- React__default$1["default"].createElement(Input, { addClass: "chat-footer__input " + (props.isChatting && props.visible ? "visible" : ""), suggestion: suggestions.item, value: input, placeholder: placeholder, sendButtonIcon: sendButtonIcon, footerConfig: footerConfig, inputConfig: inputConfig, onSubmit: handleSubmit, onChange: handleChange, onSuggestionCommand: suggestions.execute,
8321
+ isAdmin && isChatting && visible && React__default$1["default"].createElement(AdminBar, { onAdminJoin: handleAdminJoin }),
8322
+ React__default$1["default"].createElement("div", { style: { pointerEvents: enableInput ? "auto" : "none", opacity: enableInput ? 1 : 0.5 } },
8323
+ React__default$1["default"].createElement(Input, { addClass: "chat-footer__input " + (isChatting && visible ? "visible" : ""), suggestion: suggestions.item, value: input, placeholder: placeholder, sendButtonIcon: sendButtonIcon, footerConfig: footerConfig, inputConfig: inputConfig, onSubmit: handleSubmit, onChange: handleChange, onSuggestionCommand: suggestions.execute,
8315
8324
  // onFocus={this.inputOnFocus}
8316
8325
  onFileUpload: props.onFileUpload })),
8317
- brandingEnabled && React__default$1["default"].createElement(ChatBranding, { text: 'Powered by [XAPP AI](https://xapp.ai)' })));
8326
+ brandingEnabled && brandingText && React__default$1["default"].createElement(ChatBranding, { text: brandingText })));
8318
8327
  };
8319
8328
 
8320
8329
  var noop = function () { };