Added TTS chat filters.

This commit is contained in:
Tom
2024-12-28 01:37:44 +00:00
parent 0afa2138b4
commit 275069697f
30 changed files with 722 additions and 192 deletions
+13 -7
View File
@@ -1,15 +1,14 @@
import { Component, OnInit, Injectable } from '@angular/core';
import { 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 { catchError, filter, first, timeout } from 'rxjs/operators';
import { environment } from '../environments/environment';
import { Observable, throwError } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class HermesSocketService implements OnInit {
private WS_ENDPOINT = environment.WSS_ENDPOINT;
private socket: WebSocketSubject<any> | undefined = undefined
constructor() { }
@@ -23,6 +22,13 @@ export class HermesSocketService implements OnInit {
}
}
public first(predicate: (data: any) => boolean): Observable<any>|null {
if (!this.socket || this.socket.closed)
return null;
return this.socket.pipe(timeout(3000), catchError((e) => throwError(() => 'No response after 3 seconds.')), first(predicate));
}
private getNewWebSocket() {
return webSocket({
url: environment.WSS_ENDPOINT
@@ -31,21 +37,21 @@ export class HermesSocketService implements OnInit {
public sendMessage(msg: any) {
if (!this.socket || this.socket.closed)
return
return;
this.socket.next(msg);
}
public subscribe(subscriptions: any) {
if (!this.socket || this.socket.closed)
return
return;
return this.socket.subscribe(subscriptions);
}
public close() {
if (!this.socket || this.socket.closed)
return
return;
this.socket.complete();
}