@seamly/web-ui 21.0.2 → 21.0.3-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.
@@ -6761,21 +6761,37 @@ class ConversationConnector {
6761
6761
  this.channel.on('system', msg => {
6762
6762
  switch (msg.type) {
6763
6763
  case 'attach_channel_succeeded':
6764
- __classPrivateFieldGet(this, _ConversationConnector_instances, "m", _ConversationConnector_emitConnectionState).call(this, 'attach_channel_succeeded');
6764
+ __classPrivateFieldGet(this, _ConversationConnector_instances, "m", _ConversationConnector_emitConnectionState).call(this, {
6765
+ connected: true,
6766
+ ready: true,
6767
+ currentState: 'attach_channel_succeeded'
6768
+ });
6765
6769
  break;
6766
6770
  }
6767
6771
  });
6768
6772
  this.socket.onClose(() => {
6769
6773
  log('[SOCKET]CLOSE');
6770
- __classPrivateFieldGet(this, _ConversationConnector_instances, "m", _ConversationConnector_emitConnectionState).call(this, 'socket_closed');
6774
+ __classPrivateFieldGet(this, _ConversationConnector_instances, "m", _ConversationConnector_emitConnectionState).call(this, {
6775
+ connected: false,
6776
+ ready: false,
6777
+ currentState: 'socket_closed'
6778
+ });
6771
6779
  });
6772
6780
  this.channel.onClose(() => {
6773
6781
  log('[CHANNEL]CLOSE');
6774
- __classPrivateFieldGet(this, _ConversationConnector_instances, "m", _ConversationConnector_emitConnectionState).call(this, 'channel_closed');
6782
+ __classPrivateFieldGet(this, _ConversationConnector_instances, "m", _ConversationConnector_emitConnectionState).call(this, {
6783
+ connected: false,
6784
+ ready: false,
6785
+ currentState: 'channel_closed'
6786
+ });
6775
6787
  });
6776
6788
  this.channel.onError(msg => {
6777
6789
  log('[CHANNEL][ERROR]', msg);
6778
- __classPrivateFieldGet(this, _ConversationConnector_instances, "m", _ConversationConnector_emitConnectionState).call(this, 'channel_erred');
6790
+ __classPrivateFieldGet(this, _ConversationConnector_instances, "m", _ConversationConnector_emitConnectionState).call(this, {
6791
+ connected: false,
6792
+ ready: false,
6793
+ currentState: 'channel_erred'
6794
+ });
6779
6795
  });
6780
6796
  __classPrivateFieldGet(this, _ConversationConnector_instances, "m", _ConversationConnector_listenTo).call(this, 'ack', 'ui', 'error', 'participant', 'message', 'service_data', 'system', 'info', 'sync');
6781
6797
  });
@@ -6783,10 +6799,18 @@ class ConversationConnector {
6783
6799
  start() {
6784
6800
  this.channel.join().receive('ok', () => {
6785
6801
  log('[CHANNEL][JOIN] OK');
6786
- __classPrivateFieldGet(this, _ConversationConnector_instances, "m", _ConversationConnector_emitConnectionState).call(this, 'join_channel_succeeded');
6802
+ __classPrivateFieldGet(this, _ConversationConnector_instances, "m", _ConversationConnector_emitConnectionState).call(this, {
6803
+ connected: true,
6804
+ ready: false,
6805
+ currentState: 'join_channel_succeeded'
6806
+ });
6787
6807
  }).receive('error', err => {
6788
6808
  log('[CHANNEL][JOIN] ERROR', err);
6789
- __classPrivateFieldGet(this, _ConversationConnector_instances, "m", _ConversationConnector_emitConnectionState).call(this, 'join_channel_erred');
6809
+ __classPrivateFieldGet(this, _ConversationConnector_instances, "m", _ConversationConnector_emitConnectionState).call(this, {
6810
+ connected: false,
6811
+ ready: false,
6812
+ currentState: 'join_channel_erred'
6813
+ });
6790
6814
  // @ts-ignore
6791
6815
  this.channel.socket.disconnect();
6792
6816
  }).receive('timeout', () => {
@@ -6800,7 +6824,6 @@ class ConversationConnector {
6800
6824
  (_b = this.socket) === null || _b === void 0 ? void 0 : _b.remove(this.channel);
6801
6825
  (_c = this.socket) === null || _c === void 0 ? void 0 : _c.disconnect();
6802
6826
  }
6803
- // eslint-disable-next-line no-unused-vars
6804
6827
  onConnection(cb) {
6805
6828
  __classPrivateFieldGet(this, _ConversationConnector_connectionListeners, "f").push(cb);
6806
6829
  }
@@ -6815,7 +6838,15 @@ _ConversationConnector_connectionListeners = new WeakMap(), _ConversationConnect
6815
6838
  });
6816
6839
  });
6817
6840
  }, _ConversationConnector_emitConnectionState = function _ConversationConnector_emitConnectionState(payload) {
6818
- __classPrivateFieldGet(this, _ConversationConnector_connectionListeners, "f").forEach(cb => cb(payload));
6841
+ // Loop in reverse order to enable splicing the array while iterating
6842
+ for (let i = __classPrivateFieldGet(this, _ConversationConnector_connectionListeners, "f").length - 1; i >= 0; i--) {
6843
+ const cb = __classPrivateFieldGet(this, _ConversationConnector_connectionListeners, "f")[i];
6844
+ const complete = cb(payload);
6845
+ // If we only want to execute the callback once, remove it from the listener
6846
+ if (complete) {
6847
+ __classPrivateFieldGet(this, _ConversationConnector_connectionListeners, "f").splice(i, 1);
6848
+ }
6849
+ }
6819
6850
  };
6820
6851
  ;// CONCATENATED MODULE: ./src/javascripts/api/index.ts
6821
6852
  var api_awaiter = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
@@ -7069,9 +7100,12 @@ class API {
7069
7100
  conversationInitialState = yield api_classPrivateFieldGet(this, _API_instances, "m", _API_createConversation).call(this);
7070
7101
  }
7071
7102
  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));
7072
- this.conversation.onConnection(connectionState => {
7073
- this.connected = ['attach_channel_succeeded', 'join_channel_succeeded'].includes(connectionState);
7074
- api_classPrivateFieldSet(this, _API_ready, connectionState === 'attach_channel_succeeded', "f");
7103
+ this.conversation.onConnection(({
7104
+ connected,
7105
+ ready
7106
+ }) => {
7107
+ this.connected = connected;
7108
+ api_classPrivateFieldSet(this, _API_ready, ready, "f");
7075
7109
  });
7076
7110
  // Send environment
7077
7111
  if (api_classPrivateFieldGet(this, _API_config, "f").sendEnvironment) {
@@ -7154,12 +7188,17 @@ class API {
7154
7188
  var _a;
7155
7189
  if (!this.connected || waitForReady && !api_classPrivateFieldGet(this, _API_ready, "f")) {
7156
7190
  // Wait for connection to be made
7157
- (_a = this.conversation) === null || _a === void 0 ? void 0 : _a.onConnection(connectionState => {
7158
- const connected = connectionState === 'join_channel_succeeded';
7159
- const ready = connectionState === 'attach_channel_succeeded';
7160
- if (connected || ready) {
7191
+ (_a = this.conversation) === null || _a === void 0 ? void 0 : _a.onConnection(({
7192
+ connected,
7193
+ ready
7194
+ }) => {
7195
+ this.connected = connected;
7196
+ api_classPrivateFieldSet(this, _API_ready, ready, "f");
7197
+ if (waitForReady ? ready : connected) {
7161
7198
  this.send(command, payload, waitForReady);
7199
+ return true;
7162
7200
  }
7201
+ return false;
7163
7202
  });
7164
7203
  return;
7165
7204
  }
@@ -17879,8 +17918,10 @@ const SeamlyEventSubscriber = () => {
17879
17918
  return () => {};
17880
17919
  }, [api, api.connectionInfo, api.conversation]);
17881
17920
  (0,hooks_.useEffect)(() => {
17882
- api.conversation.onConnection(connectionState => {
17883
- if (connectionState === 'join_channel_erred') {
17921
+ api.conversation.onConnection(({
17922
+ currentState
17923
+ }) => {
17924
+ if (currentState === 'join_channel_erred') {
17884
17925
  const seamlyGeneralError = new SeamlyGeneralError();
17885
17926
  dispatch(setInterrupt({
17886
17927
  name: seamlyGeneralError.name,