jeffbcross / aim

82 stars 27 forks source link

Socket sends all previous messages on retry #30

Open Flood opened 7 years ago

Flood commented 7 years ago

Hi!

We are using this web socket implementation. On page load everything is correct and we start sending messages etc. When we loose connection and it gets back again the websocket sends ALL previous messages directly (the messageQueue is empty).

I've commented out this section and now it just creates a new connection without sending anything.

.retryWhen(errors => errors.switchMap(err => {
      // update the connection state to let it know we're retrying
      this.connectionState.next(ConnectionStates.RETRYING);

      if(navigator.onLine) {
        // if we have a network connection, try again in 3 seconds
        return Observable.timer(3000);
      } else {
        // if we're offline, so wait for an online event.
        return Observable.fromEvent(window, 'online').take(1);
      }
    }));

How can we make this not send old messages? We still want the retryWhen code since we need to do stuff when we gets back online.

Thanks