@seamly/web-ui 22.3.4 → 22.3.5-beta.1

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 (34) hide show
  1. package/build/dist/lib/components.js +1484 -14
  2. package/build/dist/lib/components.js.map +1 -1
  3. package/build/dist/lib/components.min.js +1 -1
  4. package/build/dist/lib/components.min.js.map +1 -1
  5. package/build/dist/lib/hooks.js +1519 -9
  6. package/build/dist/lib/hooks.js.map +1 -1
  7. package/build/dist/lib/hooks.min.js +1 -1
  8. package/build/dist/lib/hooks.min.js.map +1 -1
  9. package/build/dist/lib/index.debug.js +15 -4
  10. package/build/dist/lib/index.debug.js.map +1 -1
  11. package/build/dist/lib/index.debug.min.js +1 -1
  12. package/build/dist/lib/index.debug.min.js.LICENSE.txt +4 -0
  13. package/build/dist/lib/index.debug.min.js.map +1 -1
  14. package/build/dist/lib/index.js +258 -244
  15. package/build/dist/lib/index.js.map +1 -1
  16. package/build/dist/lib/index.min.js +1 -1
  17. package/build/dist/lib/index.min.js.map +1 -1
  18. package/build/dist/lib/standalone.js +536 -245
  19. package/build/dist/lib/standalone.js.map +1 -1
  20. package/build/dist/lib/standalone.min.js +1 -1
  21. package/build/dist/lib/standalone.min.js.map +1 -1
  22. package/build/dist/lib/style-guide.js +265 -251
  23. package/build/dist/lib/style-guide.js.map +1 -1
  24. package/build/dist/lib/style-guide.min.js +1 -1
  25. package/build/dist/lib/style-guide.min.js.map +1 -1
  26. package/build/dist/lib/utils.js +8497 -8427
  27. package/build/dist/lib/utils.js.map +1 -1
  28. package/build/dist/lib/utils.min.js +1 -1
  29. package/build/dist/lib/utils.min.js.map +1 -1
  30. package/package.json +1 -1
  31. package/src/javascripts/api/conversation-connector.ts +48 -32
  32. package/src/javascripts/ui/components/core/seamly-event-subscriber.ts +197 -218
  33. package/src/javascripts/ui/hooks/seamly-hooks.js +5 -5
  34. package/src/javascripts/ui/hooks/use-seamly-conversation.ts +13 -0
@@ -1983,6 +1983,14 @@ var _ConversationConnector_instances, _ConversationConnector_connectionListeners
1983
1983
 
1984
1984
 
1985
1985
  const log = debug_default()('seamly');
1986
+ // Subscribers set which are used to subscribe to changes in the conversation.
1987
+ // Needs to be outside of the ConversationConnector class so its not recreated for each instance.
1988
+ const subscribers = new Set();
1989
+ // Syncs the lifecycle of the conversation with Preact. Each subscriber will fetch the latest value from the conversation if needed.
1990
+ const emitChange = () => {
1991
+ // Call the callback function for each subscriber
1992
+ subscribers.forEach(callback => callback());
1993
+ };
1986
1994
  class ConversationConnector {
1987
1995
  constructor() {
1988
1996
  _ConversationConnector_instances.add(this);
@@ -1998,35 +2006,37 @@ class ConversationConnector {
1998
2006
  url: splittedUrl,
1999
2007
  params
2000
2008
  } = split_url_params(this.url);
2001
- if (!this.socket) {
2002
- this.socket = new Socket(splittedUrl, {
2003
- params: Object.assign(Object.assign({}, params), {
2004
- v: apiVersion
2005
- }),
2006
- reconnectAfterMs: tries => {
2007
- // Calculate the backoff time based on the number of tries.
2008
- const backoff = Math.pow(2, tries) * 250;
2009
- // Limit the backoff time to 10 seconds.
2010
- return Math.min(backoff, 10000);
2011
- }
2012
- });
2013
- }
2014
- // Checks if the socket is not already connected before attempting a connection.
2015
- // This prevents multiple connection attempts during server reconnects, network switches or SPA route changes.
2016
- if (!this.socket.isConnected()) {
2017
- this.socket.connect();
2018
- }
2019
- this.channel = this.socket.channel(this.channelTopic, {
2020
- authorization: `Bearer ${this.accessToken}`,
2021
- channelName: this.channelName
2009
+ this.socket = new Socket(splittedUrl, {
2010
+ params: Object.assign(Object.assign({}, params), {
2011
+ v: apiVersion
2012
+ }),
2013
+ reconnectAfterMs: tries => {
2014
+ // Calculate the backoff time based on the number of tries.
2015
+ const backoff = Math.pow(2, tries) * 250;
2016
+ // Limit the backoff time to 10 seconds.
2017
+ return Math.min(backoff, 10000);
2018
+ }
2022
2019
  });
2023
- this.start();
2024
2020
  this.socket.onError(err => {
2025
2021
  log('[SOCKET][ERROR]', err);
2026
2022
  });
2027
2023
  this.socket.onOpen(() => {
2028
2024
  log('[SOCKET]OPEN');
2029
2025
  });
2026
+ this.socket.onClose(() => {
2027
+ log('[SOCKET]CLOSE');
2028
+ __classPrivateFieldGet(this, _ConversationConnector_instances, "m", _ConversationConnector_emitConnectionState).call(this, {
2029
+ connected: false,
2030
+ ready: false,
2031
+ currentState: 'socket_closed'
2032
+ });
2033
+ });
2034
+ this.socket.connect();
2035
+ this.channel = this.socket.channel(this.channelTopic, {
2036
+ authorization: `Bearer ${this.accessToken}`,
2037
+ channelName: this.channelName
2038
+ });
2039
+ this.start();
2030
2040
  this.channel.on('system', msg => {
2031
2041
  switch (msg.type) {
2032
2042
  case 'attach_channel_succeeded':
@@ -2038,14 +2048,6 @@ class ConversationConnector {
2038
2048
  break;
2039
2049
  }
2040
2050
  });
2041
- this.socket.onClose(() => {
2042
- log('[SOCKET]CLOSE');
2043
- __classPrivateFieldGet(this, _ConversationConnector_instances, "m", _ConversationConnector_emitConnectionState).call(this, {
2044
- connected: false,
2045
- ready: false,
2046
- currentState: 'socket_closed'
2047
- });
2048
- });
2049
2051
  this.channel.onClose(() => {
2050
2052
  log('[CHANNEL]CLOSE');
2051
2053
  __classPrivateFieldGet(this, _ConversationConnector_instances, "m", _ConversationConnector_emitConnectionState).call(this, {
@@ -2099,6 +2101,13 @@ class ConversationConnector {
2099
2101
  pushToChannel(command, payload, timeout = 10000) {
2100
2102
  this.channel.push(command, payload, timeout);
2101
2103
  }
2104
+ // Adds a callback function to the subscribers set and returns a method to unsubscribe from the store.
2105
+ // This method is used to sync the state with the lifecycle of Preact.
2106
+ static subscribe(callback) {
2107
+ subscribers.add(callback);
2108
+ // Returns a function that removes the callback from the subscribers set.
2109
+ return () => subscribers.delete(callback);
2110
+ }
2102
2111
  }
2103
2112
  _ConversationConnector_connectionListeners = new WeakMap(), _ConversationConnector_instances = new WeakSet(), _ConversationConnector_listenTo = function _ConversationConnector_listenTo(...types) {
2104
2113
  types.forEach(type => {
@@ -2112,6 +2121,7 @@ _ConversationConnector_connectionListeners = new WeakMap(), _ConversationConnect
2112
2121
  // If we only want to execute the callback once, remove it from the listener
2113
2122
  return !complete;
2114
2123
  }), "f");
2124
+ emitChange();
2115
2125
  };
2116
2126
  /* harmony default export */ const conversation_connector = (ConversationConnector);
2117
2127
  ;// CONCATENATED MODULE: ./src/javascripts/api/index.ts
@@ -2631,7 +2641,7 @@ _API_ready = new WeakMap(), _API_externalId = new WeakMap(), _API_conversationAu
2631
2641
  return {
2632
2642
  clientName: "@seamly/web-ui",
2633
2643
  clientVariant: api_classPrivateFieldGet(this, _API_layoutMode, "f"),
2634
- clientVersion: "22.3.4",
2644
+ clientVersion: "22.3.5-beta.1",
2635
2645
  currentUrl: window.location.toString(),
2636
2646
  screenResolution: `${window.screen.width}x${window.screen.height}`,
2637
2647
  timezone: getTimeZone(),
@@ -8771,9 +8781,9 @@ const useShowInlineView = () => {
8771
8781
  ;// CONCATENATED MODULE: ./src/javascripts/ui/hooks/seamly-api-hooks.ts
8772
8782
 
8773
8783
 
8774
- const seamly_api_hooks_useSeamlyApiContext = () => (0,hooks_.useContext)(SeamlyApiContext);
8784
+ const useSeamlyApiContext = () => (0,hooks_.useContext)(SeamlyApiContext);
8775
8785
  const useSeamlyObjectStore = () => {
8776
- const api = seamly_api_hooks_useSeamlyApiContext();
8786
+ const api = useSeamlyApiContext();
8777
8787
  return api.store;
8778
8788
  };
8779
8789
  const useSeamlyConversationUrl = () => {
@@ -8786,7 +8796,7 @@ const useSeamlyConversationUrl = () => {
8786
8796
  return null;
8787
8797
  };
8788
8798
  const useSeamlyHasConversation = () => {
8789
- const api = seamly_api_hooks_useSeamlyApiContext();
8799
+ const api = useSeamlyApiContext();
8790
8800
  const hasConversation = (0,hooks_.useCallback)(() => {
8791
8801
  return api.hasConversation();
8792
8802
  }, [api]);
@@ -8810,7 +8820,7 @@ const useSeamlyHasConversation = () => {
8810
8820
 
8811
8821
 
8812
8822
  const useSeamlyCommands = () => {
8813
- const api = seamly_api_hooks_useSeamlyApiContext();
8823
+ const api = useSeamlyApiContext();
8814
8824
  const appConfig = useConfig();
8815
8825
  const dispatch = useDispatch();
8816
8826
  const eventBus = (0,hooks_.useContext)(SeamlyEventBusContext);
@@ -9939,6 +9949,18 @@ const useSeamlyMessageContainerClassNames = event => {
9939
9949
  }
9940
9950
  return classNames;
9941
9951
  };
9952
+ ;// CONCATENATED MODULE: external "preact/compat"
9953
+ const compat_namespaceObject = require("preact/compat");
9954
+ ;// CONCATENATED MODULE: ./src/javascripts/ui/hooks/use-seamly-conversation.ts
9955
+
9956
+
9957
+
9958
+ const use_seamly_conversation_useSeamlyConversation = () => {
9959
+ const api = useSeamlyApiContext();
9960
+ const getSnapshot = () => api.conversation;
9961
+ return (0,compat_namespaceObject.useSyncExternalStore)(conversation_connector.subscribe, getSnapshot);
9962
+ };
9963
+ /* harmony default export */ const use_seamly_conversation = (use_seamly_conversation_useSeamlyConversation);
9942
9964
  ;// CONCATENATED MODULE: ./src/javascripts/ui/hooks/focus-helper-hooks.js
9943
9965
 
9944
9966
 
@@ -10379,12 +10401,12 @@ const useStableCallback = callback => {
10379
10401
  // and imported directly from this file
10380
10402
  // Please do not remove
10381
10403
  const useSeamlyEventStream = (nextFn, filterFn) => {
10382
- const api = useSeamlyApiContext();
10404
+ const conversation = useSeamlyConversation();
10383
10405
  useEffect(() => {
10384
- if (api.connectionInfo && api.conversation?.channel) {
10406
+ if (conversation.channel) {
10385
10407
  const {
10386
10408
  channel
10387
- } = api.conversation;
10409
+ } = conversation;
10388
10410
  channel.onMessage = (type, payload) => {
10389
10411
  if (!filterFn || filterFn({
10390
10412
  type,
@@ -10398,7 +10420,7 @@ const useSeamlyEventStream = (nextFn, filterFn) => {
10398
10420
  return payload;
10399
10421
  };
10400
10422
  }
10401
- }, [nextFn, filterFn, api.connectionInfo, api.conversation]);
10423
+ }, [nextFn, filterFn, conversation]);
10402
10424
  };
10403
10425
  ;// CONCATENATED MODULE: ./src/javascripts/domains/translations/selectors.ts
10404
10426
 
@@ -13979,9 +14001,10 @@ var seamly_event_subscriber_rest = undefined && undefined.__rest || function (s,
13979
14001
 
13980
14002
 
13981
14003
 
14004
+
13982
14005
  const EMITTABLE_MESSAGE_TYPES = ['text', 'choice_prompt', 'image', 'video'];
13983
14006
  const SeamlyEventSubscriber = () => {
13984
- const api = seamly_api_hooks_useSeamlyApiContext();
14007
+ const conversation = use_seamly_conversation();
13985
14008
  const syncChannelRef = (0,hooks_.useRef)();
13986
14009
  const messageChannelRef = (0,hooks_.useRef)();
13987
14010
  const dispatch = useAppDispatch();
@@ -13995,10 +14018,10 @@ const SeamlyEventSubscriber = () => {
13995
14018
  emitEvent
13996
14019
  } = use_seamly_commands();
13997
14020
  (0,hooks_.useEffect)(() => {
13998
- if (api.connectionInfo && api.conversation.socket) {
14021
+ if (conversation.socket) {
13999
14022
  const {
14000
14023
  socket
14001
- } = api.conversation;
14024
+ } = conversation;
14002
14025
  socket.onError(err => {
14003
14026
  const seamlyOfflineError = new SeamlyOfflineError(err);
14004
14027
  dispatch(setInterrupt({
@@ -14014,10 +14037,10 @@ const SeamlyEventSubscriber = () => {
14014
14037
  dispatch(clearInterrupt());
14015
14038
  });
14016
14039
  }
14017
- }, [api, api.connectionInfo, api.conversation.socket, dispatch]);
14040
+ }, [conversation, dispatch]);
14018
14041
  (0,hooks_.useEffect)(() => {
14019
- if (api.connectionInfo && api.conversation.socket) {
14020
- api.conversation.onConnection(({
14042
+ if (conversation.socket) {
14043
+ conversation.onConnection(({
14021
14044
  currentState
14022
14045
  }) => {
14023
14046
  if (currentState === 'join_channel_erred') {
@@ -14035,217 +14058,210 @@ const SeamlyEventSubscriber = () => {
14035
14058
  return false;
14036
14059
  });
14037
14060
  }
14038
- }, [api, api.connectionInfo, api.conversation.channel, dispatch]);
14061
+ }, [conversation, dispatch]);
14039
14062
  (0,hooks_.useEffect)(() => {
14040
- if (api.connectionInfo) {
14041
- const updateParticipant = event => {
14042
- if (event.type !== 'participant') {
14043
- return;
14044
- }
14045
- const {
14063
+ const updateParticipant = event => {
14064
+ if (event.type !== 'participant') {
14065
+ return;
14066
+ }
14067
+ const {
14068
+ payload
14069
+ } = event;
14070
+ if (!payload || !payload.participant) {
14071
+ return;
14072
+ }
14073
+ const {
14074
+ fromClient,
14075
+ participant
14076
+ } = payload;
14077
+ if (!fromClient && typeof participant !== 'string' && (participant === null || participant === void 0 ? void 0 : participant.name)) {
14078
+ dispatch(setHeaderSubTitle(participant.name));
14079
+ }
14080
+ dispatch(setParticipant({
14081
+ participant,
14082
+ fromClient
14083
+ }));
14084
+ if (typeof participant !== 'string' && participant.introduction) {
14085
+ dispatch(addEvent(event));
14086
+ }
14087
+ };
14088
+ conversation.onConnection(({
14089
+ connected
14090
+ }) => {
14091
+ if (!connected) return false;
14092
+ const {
14093
+ channel
14094
+ } = conversation;
14095
+ channel.onMessage = (type, payload) => {
14096
+ const event = {
14097
+ type,
14046
14098
  payload
14047
- } = event;
14048
- if (!payload || !payload.participant) {
14049
- return;
14050
- }
14051
- const {
14052
- fromClient,
14053
- participant
14054
- } = payload;
14055
- if (!fromClient && typeof participant !== 'string' && (participant === null || participant === void 0 ? void 0 : participant.name)) {
14056
- dispatch(setHeaderSubTitle(participant.name));
14057
- }
14058
- dispatch(setParticipant({
14059
- participant,
14060
- fromClient
14061
- }));
14062
- if (typeof participant !== 'string' && participant.introduction) {
14063
- dispatch(addEvent(event));
14064
- }
14065
- };
14066
- api.conversation.onConnection(({
14067
- connected
14068
- }) => {
14069
- if (!connected) return false;
14070
- const {
14071
- channel
14072
- } = api.conversation;
14073
- channel.onMessage = (type, payload) => {
14074
- const event = {
14075
- type,
14076
- payload
14077
- };
14078
- switch (type) {
14079
- case 'ui':
14080
- if (payload.state && payload.state.hasOwnProperty('loading')) {
14081
- dispatch(setIsLoading(payload.state.loading));
14082
- }
14083
- switch (payload.type) {
14084
- case 'idle_detach_countdown':
14085
- initCountdown(payload.body.duration);
14086
- break;
14087
- case 'idle_detach_countdown_elapsed':
14088
- endCountdown(undefined, true);
14089
- break;
14090
- case 'resume_conversation_prompt':
14091
- dispatch(initResumeConversationPrompt());
14092
- break;
14093
- case 'translation_proposal':
14094
- dispatch(setTranslationProposalPrompt(payload.body));
14095
- break;
14096
- case 'user_first_response':
14097
- dispatch(setHasResponded(true));
14098
- // @ts-ignore
14099
- eventBus.emit('system.userFirstResponse', payload.body);
14100
- break;
14101
- }
14102
- break;
14103
- case 'message':
14104
- updateParticipant(payload);
14105
- switch (payload.type) {
14106
- case 'text':
14107
- case 'choice_prompt':
14108
- case 'splash':
14109
- case 'image':
14110
- case 'upload':
14111
- case 'video':
14112
- case 'cta':
14113
- case 'custom':
14114
- case 'carousel':
14115
- case 'card':
14116
- if (payload.service && payload.service.serviceSessionId) {
14117
- dispatch(setActiveService(payload.service.serviceSessionId));
14118
- }
14119
- dispatch(addEvent(event));
14120
- break;
14121
- }
14122
- break;
14123
- case 'participant':
14124
- updateParticipant(event);
14125
- break;
14126
- case 'service_data':
14127
- if (payload.persist) {
14128
- dispatch(setServiceDataItem(payload));
14129
- }
14130
- break;
14131
- case 'ack':
14132
- dispatch(ackEvent(event));
14133
- break;
14134
- case 'system':
14135
- if (payload.type === 'service_changed') {
14136
- const {
14137
- serviceSettings
14138
- } = payload,
14139
- eventPayload = seamly_event_subscriber_rest(payload, ["serviceSettings"]);
14140
- const {
14141
- entry,
14142
- proactiveMessages
14143
- } = serviceSettings;
14144
- const {
14145
- upload
14146
- } = entry.options;
14147
- dispatch(setFeatureEnabledState({
14148
- key: featureKeys.uploads,
14149
- enabled: !!(upload && upload.enabled)
14150
- }));
14151
- dispatch(setProactiveMessages(proactiveMessages.enabled || false));
14152
- dispatch(setServiceEntryMetadata(entry));
14153
- if (payload.serviceSessionId) {
14154
- dispatch(setActiveService(payload.serviceSessionId));
14099
+ };
14100
+ switch (type) {
14101
+ case 'ui':
14102
+ if (payload.state && payload.state.hasOwnProperty('loading')) {
14103
+ dispatch(setIsLoading(payload.state.loading));
14104
+ }
14105
+ switch (payload.type) {
14106
+ case 'idle_detach_countdown':
14107
+ initCountdown(payload.body.duration);
14108
+ break;
14109
+ case 'idle_detach_countdown_elapsed':
14110
+ endCountdown(undefined, true);
14111
+ break;
14112
+ case 'resume_conversation_prompt':
14113
+ dispatch(initResumeConversationPrompt());
14114
+ break;
14115
+ case 'translation_proposal':
14116
+ dispatch(setTranslationProposalPrompt(payload.body));
14117
+ break;
14118
+ case 'user_first_response':
14119
+ dispatch(setHasResponded(true));
14120
+ // @ts-ignore
14121
+ eventBus.emit('system.userFirstResponse', payload.body);
14122
+ break;
14123
+ }
14124
+ break;
14125
+ case 'message':
14126
+ updateParticipant(payload);
14127
+ switch (payload.type) {
14128
+ case 'text':
14129
+ case 'choice_prompt':
14130
+ case 'splash':
14131
+ case 'image':
14132
+ case 'upload':
14133
+ case 'video':
14134
+ case 'cta':
14135
+ case 'custom':
14136
+ case 'carousel':
14137
+ case 'card':
14138
+ if (payload.service && payload.service.serviceSessionId) {
14139
+ dispatch(setActiveService(payload.service.serviceSessionId));
14155
14140
  }
14156
- emitEvent('system.serviceChanged', eventPayload);
14157
- }
14158
- break;
14159
- case 'info':
14160
- if (payload.type === 'divider' || payload.type === 'text' || payload.type === 'translation') {
14161
14141
  dispatch(addEvent(event));
14142
+ break;
14143
+ }
14144
+ break;
14145
+ case 'participant':
14146
+ updateParticipant(event);
14147
+ break;
14148
+ case 'service_data':
14149
+ if (payload.persist) {
14150
+ dispatch(setServiceDataItem(payload));
14151
+ }
14152
+ break;
14153
+ case 'ack':
14154
+ dispatch(ackEvent(event));
14155
+ break;
14156
+ case 'system':
14157
+ if (payload.type === 'service_changed') {
14158
+ const {
14159
+ serviceSettings
14160
+ } = payload,
14161
+ eventPayload = seamly_event_subscriber_rest(payload, ["serviceSettings"]);
14162
+ const {
14163
+ entry,
14164
+ proactiveMessages
14165
+ } = serviceSettings;
14166
+ const {
14167
+ upload
14168
+ } = entry.options;
14169
+ dispatch(setFeatureEnabledState({
14170
+ key: featureKeys.uploads,
14171
+ enabled: !!(upload && upload.enabled)
14172
+ }));
14173
+ dispatch(setProactiveMessages(proactiveMessages.enabled || false));
14174
+ dispatch(setServiceEntryMetadata(entry));
14175
+ if (payload.serviceSessionId) {
14176
+ dispatch(setActiveService(payload.serviceSessionId));
14162
14177
  }
14163
- break;
14164
- case 'error':
14165
- switch (payload.type) {
14166
- case 'find_conversation_erred':
14167
- const seamlySessionExpiredError = new SeamlySessionExpiredError(event);
14168
- dispatch(setInterrupt({
14169
- name: seamlySessionExpiredError.name,
14170
- action: seamlySessionExpiredError.action,
14171
- message: seamlySessionExpiredError.message,
14172
- originalEvent: seamlySessionExpiredError.originalEvent,
14173
- originalError: seamlySessionExpiredError.originalError
14174
- }));
14175
- break;
14176
- case 'conversation_erred':
14177
- case 'attach_channel_erred':
14178
- const seamlyGeneralError = new SeamlyGeneralError(event);
14179
- dispatch(setInterrupt({
14180
- name: seamlyGeneralError.name,
14181
- message: seamlyGeneralError.message,
14182
- langKey: seamlyGeneralError.langKey,
14183
- originalEvent: seamlyGeneralError.originalEvent,
14184
- originalError: seamlyGeneralError.originalError,
14185
- action: seamlyGeneralError.action
14186
- }));
14187
- break;
14188
- }
14189
- }
14190
- return payload;
14191
- };
14192
- return false;
14193
- });
14194
- }
14195
- }, [api, api.connectionInfo, api.conversation.channel, dispatch, emitEvent, endCountdown, eventBus, initCountdown]);
14196
- (0,hooks_.useEffect)(() => {
14197
- if (api.connectionInfo) {
14198
- api.conversation.onConnection(({
14199
- connected
14200
- }) => {
14201
- if (!connected) return false;
14202
- const {
14203
- channel
14204
- } = api.conversation;
14205
- if (messageChannelRef.current) {
14206
- channel === null || channel === void 0 ? void 0 : channel.off('message', messageChannelRef.current);
14178
+ emitEvent('system.serviceChanged', eventPayload);
14179
+ }
14180
+ break;
14181
+ case 'info':
14182
+ if (payload.type === 'divider' || payload.type === 'text' || payload.type === 'translation') {
14183
+ dispatch(addEvent(event));
14184
+ }
14185
+ break;
14186
+ case 'error':
14187
+ switch (payload.type) {
14188
+ case 'find_conversation_erred':
14189
+ const seamlySessionExpiredError = new SeamlySessionExpiredError(event);
14190
+ dispatch(setInterrupt({
14191
+ name: seamlySessionExpiredError.name,
14192
+ action: seamlySessionExpiredError.action,
14193
+ message: seamlySessionExpiredError.message,
14194
+ originalEvent: seamlySessionExpiredError.originalEvent,
14195
+ originalError: seamlySessionExpiredError.originalError
14196
+ }));
14197
+ break;
14198
+ case 'conversation_erred':
14199
+ case 'attach_channel_erred':
14200
+ const seamlyGeneralError = new SeamlyGeneralError(event);
14201
+ dispatch(setInterrupt({
14202
+ name: seamlyGeneralError.name,
14203
+ message: seamlyGeneralError.message,
14204
+ langKey: seamlyGeneralError.langKey,
14205
+ originalEvent: seamlyGeneralError.originalEvent,
14206
+ originalError: seamlyGeneralError.originalError,
14207
+ action: seamlyGeneralError.action
14208
+ }));
14209
+ break;
14210
+ }
14207
14211
  }
14208
- messageChannelRef.current = channel.on('message', payload => {
14209
- if (!EMITTABLE_MESSAGE_TYPES.includes(payload.type)) {
14210
- return payload;
14211
- }
14212
- // This check dedupes the sending of messages via
14213
- // the bus if a duplicate connection exists in an
14214
- // error situation.
14215
- if (payload.id !== prevEmittedEventId.current) {
14216
- // @ts-ignore
14217
- eventBus.emit('message', payload);
14218
- }
14219
- prevEmittedEventId.current = payload.id;
14212
+ return payload;
14213
+ };
14214
+ return false;
14215
+ });
14216
+ }, [conversation, dispatch, emitEvent, endCountdown, eventBus, initCountdown]);
14217
+ (0,hooks_.useEffect)(() => {
14218
+ conversation.onConnection(({
14219
+ connected
14220
+ }) => {
14221
+ if (!connected) return false;
14222
+ const {
14223
+ channel
14224
+ } = conversation;
14225
+ if (messageChannelRef.current) {
14226
+ channel.off('message', messageChannelRef.current);
14227
+ }
14228
+ messageChannelRef.current = channel.on('message', payload => {
14229
+ if (!EMITTABLE_MESSAGE_TYPES.includes(payload.type)) {
14220
14230
  return payload;
14221
- });
14222
- return true;
14231
+ }
14232
+ // This check dedupes the sending of messages via
14233
+ // the bus if a duplicate connection exists in an
14234
+ // error situation.
14235
+ if (payload.id !== prevEmittedEventId.current) {
14236
+ // @ts-ignore
14237
+ eventBus.emit('message', payload);
14238
+ }
14239
+ prevEmittedEventId.current = payload.id;
14240
+ return payload;
14223
14241
  });
14224
- }
14225
- }, [api, api.connectionInfo, api.conversation.channel, eventBus]);
14242
+ return true;
14243
+ });
14244
+ }, [conversation, eventBus]);
14226
14245
  (0,hooks_.useEffect)(() => {
14227
- if (api.connectionInfo) {
14228
- api.conversation.onConnection(({
14229
- connected
14230
- }) => {
14231
- var _a;
14232
- if (!connected) return false;
14233
- if (syncChannelRef.current) {
14234
- (_a = api.conversation.channel) === null || _a === void 0 ? void 0 : _a.off('sync', syncChannelRef.current);
14246
+ conversation.onConnection(({
14247
+ connected
14248
+ }) => {
14249
+ if (!connected) return false;
14250
+ if (syncChannelRef.current) {
14251
+ conversation.channel.off('sync', syncChannelRef.current);
14252
+ }
14253
+ syncChannelRef.current = conversation.channel.on('sync', payload => seamly_event_subscriber_awaiter(void 0, void 0, void 0, function* () {
14254
+ try {
14255
+ const history = yield dispatch(getConversation(payload)).unwrap();
14256
+ if (!history) return;
14257
+ dispatch(setHistory(history));
14258
+ } catch (_e) {
14259
+ // nothing to do, the error is handled in the thunk
14235
14260
  }
14236
- syncChannelRef.current = api.conversation.channel.on('sync', payload => seamly_event_subscriber_awaiter(void 0, void 0, void 0, function* () {
14237
- try {
14238
- const history = yield dispatch(getConversation(payload)).unwrap();
14239
- if (!history) return;
14240
- dispatch(setHistory(history));
14241
- } catch (_e) {
14242
- // nothing to do, the error is handled in the thunk
14243
- }
14244
- }));
14245
- return true;
14246
- });
14247
- }
14248
- }, [api, api.connectionInfo, api.conversation.channel, dispatch]);
14261
+ }));
14262
+ return true;
14263
+ });
14264
+ }, [conversation, dispatch]);
14249
14265
  return null;
14250
14266
  };
14251
14267
  /* harmony default export */ const seamly_event_subscriber = (SeamlyEventSubscriber);
@@ -14297,7 +14313,7 @@ const toBase64 = (file) => new Promise((resolve, reject) => {
14297
14313
  const SeamlyFileUpload = ({ children }) => {
14298
14314
  const { t } = useI18n();
14299
14315
  const dispatch = useDispatch();
14300
- const api = seamly_api_hooks_useSeamlyApiContext();
14316
+ const api = useSeamlyApiContext();
14301
14317
  const { addUploadBubble } = use_seamly_commands();
14302
14318
  const addImageToSessionStorage = (0,hooks_.useCallback)((file, fileId) => seamly_file_upload_awaiter(void 0, void 0, void 0, function* () {
14303
14319
  dispatch(startProcessingImage(fileId));
@@ -14452,7 +14468,7 @@ const SeamlyInstanceFunctionsLoader = () => {
14452
14468
  } = useVisibility();
14453
14469
  const currentVisibility = (0,hooks_.useRef)(visible);
14454
14470
  const eventBus = (0,hooks_.useContext)(SeamlyEventBusContext);
14455
- const api = seamly_api_hooks_useSeamlyApiContext();
14471
+ const api = useSeamlyApiContext();
14456
14472
  const unreadCount = useSeamlyUnreadCount();
14457
14473
  const previousUnreadCount = (0,hooks_.useRef)(null);
14458
14474
  const previousVisibilityState = (0,hooks_.useRef)(null);
@@ -15052,7 +15068,7 @@ const useEntryAbortTransaction = () => {
15052
15068
 
15053
15069
  function AbortTransactionButton() {
15054
15070
  const { abortTransaction, clearEntryAbortTransaction } = useEntryAbortTransaction();
15055
- const api = seamly_api_hooks_useSeamlyApiContext();
15071
+ const api = useSeamlyApiContext();
15056
15072
  if (!abortTransaction)
15057
15073
  return null;
15058
15074
  const handleAbortTransaction = () => {
@@ -15075,8 +15091,6 @@ function AbortTransactionButton() {
15075
15091
  ]), type: "button", onClick: handleAbortTransaction, children: abortTransaction.label }) }));
15076
15092
  }
15077
15093
 
15078
- ;// CONCATENATED MODULE: external "preact/compat"
15079
- const compat_namespaceObject = require("preact/compat");
15080
15094
  ;// CONCATENATED MODULE: ./src/javascripts/ui/components/conversation/event/chat-scroll/chat-scroll-context.ts
15081
15095
 
15082
15096
  const ChatScrollContext = (0,external_preact_.createContext)(null);