@seamly/web-ui 21.0.2 → 21.0.3-beta.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.
@@ -6717,21 +6717,37 @@ class ConversationConnector {
6717
6717
  this.channel.on('system', msg => {
6718
6718
  switch (msg.type) {
6719
6719
  case 'attach_channel_succeeded':
6720
- __classPrivateFieldGet(this, _ConversationConnector_instances, "m", _ConversationConnector_emitConnectionState).call(this, 'attach_channel_succeeded');
6720
+ __classPrivateFieldGet(this, _ConversationConnector_instances, "m", _ConversationConnector_emitConnectionState).call(this, {
6721
+ connected: true,
6722
+ ready: true,
6723
+ currentState: 'attach_channel_succeeded'
6724
+ });
6721
6725
  break;
6722
6726
  }
6723
6727
  });
6724
6728
  this.socket.onClose(() => {
6725
6729
  log('[SOCKET]CLOSE');
6726
- __classPrivateFieldGet(this, _ConversationConnector_instances, "m", _ConversationConnector_emitConnectionState).call(this, 'socket_closed');
6730
+ __classPrivateFieldGet(this, _ConversationConnector_instances, "m", _ConversationConnector_emitConnectionState).call(this, {
6731
+ connected: false,
6732
+ ready: false,
6733
+ currentState: 'socket_closed'
6734
+ });
6727
6735
  });
6728
6736
  this.channel.onClose(() => {
6729
6737
  log('[CHANNEL]CLOSE');
6730
- __classPrivateFieldGet(this, _ConversationConnector_instances, "m", _ConversationConnector_emitConnectionState).call(this, 'channel_closed');
6738
+ __classPrivateFieldGet(this, _ConversationConnector_instances, "m", _ConversationConnector_emitConnectionState).call(this, {
6739
+ connected: false,
6740
+ ready: false,
6741
+ currentState: 'channel_closed'
6742
+ });
6731
6743
  });
6732
6744
  this.channel.onError(msg => {
6733
6745
  log('[CHANNEL][ERROR]', msg);
6734
- __classPrivateFieldGet(this, _ConversationConnector_instances, "m", _ConversationConnector_emitConnectionState).call(this, 'channel_erred');
6746
+ __classPrivateFieldGet(this, _ConversationConnector_instances, "m", _ConversationConnector_emitConnectionState).call(this, {
6747
+ connected: false,
6748
+ ready: false,
6749
+ currentState: 'channel_erred'
6750
+ });
6735
6751
  });
6736
6752
  __classPrivateFieldGet(this, _ConversationConnector_instances, "m", _ConversationConnector_listenTo).call(this, 'ack', 'ui', 'error', 'participant', 'message', 'service_data', 'system', 'info', 'sync');
6737
6753
  });
@@ -6739,10 +6755,18 @@ class ConversationConnector {
6739
6755
  start() {
6740
6756
  this.channel.join().receive('ok', () => {
6741
6757
  log('[CHANNEL][JOIN] OK');
6742
- __classPrivateFieldGet(this, _ConversationConnector_instances, "m", _ConversationConnector_emitConnectionState).call(this, 'join_channel_succeeded');
6758
+ __classPrivateFieldGet(this, _ConversationConnector_instances, "m", _ConversationConnector_emitConnectionState).call(this, {
6759
+ connected: true,
6760
+ ready: false,
6761
+ currentState: 'join_channel_succeeded'
6762
+ });
6743
6763
  }).receive('error', err => {
6744
6764
  log('[CHANNEL][JOIN] ERROR', err);
6745
- __classPrivateFieldGet(this, _ConversationConnector_instances, "m", _ConversationConnector_emitConnectionState).call(this, 'join_channel_erred');
6765
+ __classPrivateFieldGet(this, _ConversationConnector_instances, "m", _ConversationConnector_emitConnectionState).call(this, {
6766
+ connected: false,
6767
+ ready: false,
6768
+ currentState: 'join_channel_erred'
6769
+ });
6746
6770
  // @ts-ignore
6747
6771
  this.channel.socket.disconnect();
6748
6772
  }).receive('timeout', () => {
@@ -6756,7 +6780,6 @@ class ConversationConnector {
6756
6780
  (_b = this.socket) === null || _b === void 0 ? void 0 : _b.remove(this.channel);
6757
6781
  (_c = this.socket) === null || _c === void 0 ? void 0 : _c.disconnect();
6758
6782
  }
6759
- // eslint-disable-next-line no-unused-vars
6760
6783
  onConnection(cb) {
6761
6784
  __classPrivateFieldGet(this, _ConversationConnector_connectionListeners, "f").push(cb);
6762
6785
  }
@@ -6771,7 +6794,15 @@ _ConversationConnector_connectionListeners = new WeakMap(), _ConversationConnect
6771
6794
  });
6772
6795
  });
6773
6796
  }, _ConversationConnector_emitConnectionState = function _ConversationConnector_emitConnectionState(payload) {
6774
- __classPrivateFieldGet(this, _ConversationConnector_connectionListeners, "f").forEach(cb => cb(payload));
6797
+ // Loop in reverse order to enable splicing the array while iterating
6798
+ for (let i = __classPrivateFieldGet(this, _ConversationConnector_connectionListeners, "f").length - 1; i >= 0; i--) {
6799
+ const callback = __classPrivateFieldGet(this, _ConversationConnector_connectionListeners, "f")[i];
6800
+ const complete = callback(payload);
6801
+ // If we only want to execute the callback once, remove it from the listener
6802
+ if (complete) {
6803
+ __classPrivateFieldGet(this, _ConversationConnector_connectionListeners, "f").splice(i, 1);
6804
+ }
6805
+ }
6775
6806
  };
6776
6807
  ;// CONCATENATED MODULE: ./src/javascripts/api/index.ts
6777
6808
  var api_awaiter = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
@@ -7025,9 +7056,12 @@ class API {
7025
7056
  conversationInitialState = yield api_classPrivateFieldGet(this, _API_instances, "m", _API_createConversation).call(this);
7026
7057
  }
7027
7058
  this.conversation.connect(`${api_classPrivateFieldGet(this, _API_instances, "m", _API_getUrlPrefix).call(this, 'ws')}${this.URLS.socket}`, api_classPrivateFieldGet(this, _API_config, "f").context.channelName, api_classPrivateFieldGet(this, _API_instances, "m", _API_getChannelTopic).call(this), api_classPrivateFieldGet(this, _API_instances, "m", _API_getAccessToken).call(this));
7028
- this.conversation.onConnection(connectionState => {
7029
- this.connected = ['attach_channel_succeeded', 'join_channel_succeeded'].includes(connectionState);
7030
- api_classPrivateFieldSet(this, _API_ready, connectionState === 'attach_channel_succeeded', "f");
7059
+ this.conversation.onConnection(({
7060
+ connected,
7061
+ ready
7062
+ }) => {
7063
+ this.connected = connected;
7064
+ api_classPrivateFieldSet(this, _API_ready, ready, "f");
7031
7065
  });
7032
7066
  // Send environment
7033
7067
  if (api_classPrivateFieldGet(this, _API_config, "f").sendEnvironment) {
@@ -7110,12 +7144,17 @@ class API {
7110
7144
  var _a;
7111
7145
  if (!this.connected || waitForReady && !api_classPrivateFieldGet(this, _API_ready, "f")) {
7112
7146
  // Wait for connection to be made
7113
- (_a = this.conversation) === null || _a === void 0 ? void 0 : _a.onConnection(connectionState => {
7114
- const connected = connectionState === 'join_channel_succeeded';
7115
- const ready = connectionState === 'attach_channel_succeeded';
7116
- if (connected || ready) {
7147
+ (_a = this.conversation) === null || _a === void 0 ? void 0 : _a.onConnection(({
7148
+ connected,
7149
+ ready
7150
+ }) => {
7151
+ this.connected = connected;
7152
+ api_classPrivateFieldSet(this, _API_ready, ready, "f");
7153
+ if (waitForReady ? ready : connected) {
7117
7154
  this.send(command, payload, waitForReady);
7155
+ return true;
7118
7156
  }
7157
+ return false;
7119
7158
  });
7120
7159
  return;
7121
7160
  }
@@ -17835,8 +17874,10 @@ const SeamlyEventSubscriber = () => {
17835
17874
  return () => {};
17836
17875
  }, [api, api.connectionInfo, api.conversation]);
17837
17876
  (0,hooks_.useEffect)(() => {
17838
- api.conversation.onConnection(connectionState => {
17839
- if (connectionState === 'join_channel_erred') {
17877
+ api.conversation.onConnection(({
17878
+ currentState
17879
+ }) => {
17880
+ if (currentState === 'join_channel_erred') {
17840
17881
  const seamlyGeneralError = new SeamlyGeneralError();
17841
17882
  dispatch(setInterrupt({
17842
17883
  name: seamlyGeneralError.name,