From: Dessalines Date: Sun, 2 Feb 2020 14:15:02 +0000 (-0500) Subject: Merge branch 'dev' into websocket_scopes X-Git-Url: http://these/git/%22https:/www.exeterceilidhs.net/%22%7B%7D/readmes/README.es.md?a=commitdiff_plain;h=4d95be06b5145abdcb4f360439623269468dee35;p=lemmy.git Merge branch 'dev' into websocket_scopes --- 4d95be06b5145abdcb4f360439623269468dee35 diff --cc ui/src/services/WebSocketService.ts index f1a6d156,8fae384d..0b4def1c --- a/ui/src/services/WebSocketService.ts +++ b/ui/src/services/WebSocketService.ts @@@ -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; 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()); } + public userJoin() { + let form: UserJoinForm = { auth: UserService.Instance.auth }; - this.subject.next(this.wsSendWrapper(UserOperation.UserJoin, form)); ++ 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) {