Twitch login, TTS Login, and basic policies ui.
This commit is contained in:
52
src/app/hermes-socket.service.ts
Normal file
52
src/app/hermes-socket.service.ts
Normal file
@ -0,0 +1,52 @@
|
||||
import { Component, OnInit, Injectable } from '@angular/core';
|
||||
import { webSocket, WebSocketSubject } from 'rxjs/webSocket';
|
||||
import { catchError, tap, switchAll } from 'rxjs/operators';
|
||||
import { EMPTY, Observer, Subject } from 'rxjs';
|
||||
import { environment } from '../environments/environment';
|
||||
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class HermesSocketService implements OnInit {
|
||||
private WS_ENDPOINT = environment.WSS_ENDPOINT;
|
||||
private socket: WebSocketSubject<any> | undefined = undefined
|
||||
|
||||
constructor() { }
|
||||
|
||||
ngOnInit(): void {
|
||||
}
|
||||
|
||||
public connect(): void {
|
||||
if (!this.socket || this.socket.closed) {
|
||||
this.socket = this.getNewWebSocket();
|
||||
}
|
||||
}
|
||||
|
||||
private getNewWebSocket() {
|
||||
return webSocket({
|
||||
url: WS_ENDPOINT
|
||||
});
|
||||
}
|
||||
|
||||
public sendMessage(msg: any) {
|
||||
if (!this.socket || this.socket.closed)
|
||||
return
|
||||
|
||||
this.socket.next(msg);
|
||||
}
|
||||
|
||||
public subscribe(subscriptions: any) {
|
||||
if (!this.socket || this.socket.closed)
|
||||
return
|
||||
|
||||
return this.socket.subscribe(subscriptions);
|
||||
}
|
||||
|
||||
public close() {
|
||||
if (!this.socket || this.socket.closed)
|
||||
return
|
||||
|
||||
this.socket.complete();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user