mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
add interface to socket
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
import { Observable, BehaviorSubject } from 'rxjs';
|
||||
import { Result } from 'neverthrow';
|
||||
import { HubConnection } from '@microsoft/signalr';
|
||||
import { ISignalRInput } from './type';
|
||||
|
||||
export abstract class ISignalRService {
|
||||
abstract establishConnection(): Promise<Result<HubConnection, false>>;
|
||||
abstract sendData<T>(input: ISignalRInput): Promise<void>;
|
||||
abstract join(): void;
|
||||
abstract getData<T>(): Observable<{ method: string; data: T }>;
|
||||
abstract getConnectionState(): Observable<boolean>;
|
||||
abstract newConnection(): void;
|
||||
}
|
||||
@@ -9,17 +9,10 @@ import { Result } from 'neverthrow';
|
||||
import { HubConnection } from '@microsoft/signalr';
|
||||
import { MessageOutPutDataDTO } from 'src/app/module/chat/data/dto/message/messageOutputDTO';
|
||||
import { UserTypingDTO } from 'src/app/module/chat/data/dto/typing/typingInputDTO';
|
||||
import { ISignalRInput } from '../type';
|
||||
|
||||
const { App } = Plugins;
|
||||
|
||||
const SignalRInputSchema = z.object({
|
||||
method: z.string(),
|
||||
data: z.object({
|
||||
requestId: z.string(),
|
||||
}).catchall(z.unknown()), // Allows any additional properties with unknown values
|
||||
})
|
||||
|
||||
export type ISignalRInput = z.infer<typeof SignalRInputSchema>;
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
|
||||
@@ -4,8 +4,8 @@ import { ok, Result, err } from 'neverthrow';
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
import { filter, first } from 'rxjs/operators';
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { ISignalRInput } from './signal-r.service';
|
||||
import { MessageOutPutDataDTO } from 'src/app/module/chat/data/dto/message/messageOutputDTO';
|
||||
import { ISignalRInput } from '../type';
|
||||
|
||||
export interface SocketMessage<T> {
|
||||
method: string,
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import { z } from "zod";
|
||||
|
||||
const SignalRInputSchema = z.object({
|
||||
method: z.string(),
|
||||
data: z.object({
|
||||
requestId: z.string(),
|
||||
}).catchall(z.unknown()), // Allows any additional properties with unknown values
|
||||
})
|
||||
|
||||
export type ISignalRInput = z.infer<typeof SignalRInputSchema>;
|
||||
Reference in New Issue
Block a user