]> Untitled Git - lemmy.git/commitdiff
Merge branch 'dev' into websocket_scopes
authorDessalines <tyhou13@gmx.com>
Sun, 2 Feb 2020 14:15:02 +0000 (09:15 -0500)
committerDessalines <tyhou13@gmx.com>
Sun, 2 Feb 2020 14:15:02 +0000 (09:15 -0500)
1  2 
ui/src/services/WebSocketService.ts
ui/yarn.lock

index f1a6d1561c1b399feb6dde9b86a142bc94254b97,8fae384db842227dfad4e6f1bb5bfd21a0cf05c9..0b4def1c0946f7c42d032fa6a0906b8b8d336a08
@@@ -38,12 -38,8 +38,9 @@@ import 
    PrivateMessageForm,
    EditPrivateMessageForm,
    GetPrivateMessagesForm,
 +  UserJoinForm,
    MessageType,
  } from '../interfaces';
- import { webSocket } from 'rxjs/webSocket';
- import { Subject } from 'rxjs';
- import { retryWhen, delay } from 'rxjs/operators';
  import { UserService } from './';
  import { i18n } from '../i18next';
  import { toast } from '../utils';
@@@ -57,38 -57,24 +58,33 @@@ export class WebSocketService 
    public banned: Array<UserView>;
  
    private constructor() {
-     this.subject = webSocket(wsUri);
-     // Necessary to not keep reconnecting
-     this.subject
-       .pipe(
-         retryWhen(errors =>
-           errors.pipe(
-             delay(1000)
-             // take(999)
-           )
-         )
-       )
-       .subscribe();
-     console.log(`Connected to ${wsUri}`);
+     this.ws = new ReconnectingWebSocket(wsUri);
+     this.ws.onopen = () => {
+       console.log(`Connected to ${wsUri}`);
+     };
+     this.subject = Observable.create((obs: any) => {
+       this.ws.onmessage = e => {
+         obs.next(JSON.parse(e.data));
+       };
+     }).pipe(share());
 +
 +    if (UserService.Instance.user) {
 +      this.userJoin();
 +    }
    }
  
    public static get Instance() {
      return this._instance || (this._instance = new this());
    }
  
-     this.subject.next(this.wsSendWrapper(UserOperation.UserJoin, form));
 +  public userJoin() {
 +    let form: UserJoinForm = { auth: UserService.Instance.auth };
++    this.ws.send(this.wsSendWrapper(UserOperation.UserJoin, form));
 +  }
 +
    public login(loginForm: LoginForm) {
-     this.subject.next(this.wsSendWrapper(UserOperation.Login, loginForm));
+     this.ws.send(this.wsSendWrapper(UserOperation.Login, loginForm));
    }
  
    public register(registerForm: RegisterForm) {
diff --cc ui/yarn.lock
Simple merge