import type { types } from 'mediasoup' import type { RemoteSocket, Socket, Namespace as SocketNamespace } from 'socket.io' import type { User } from '../prisma/client' export interface ChadClient { socketId: string userId: User['id'] username: User['username'] displayName: User['displayName'] inputMuted: boolean outputMuted: boolean } export interface ProducerShort { producerId: types.Producer['id'] kind: types.MediaKind } export interface ErrorCallbackResult { error: string } export interface SuccessCallbackResult { ok: true } export type EventCallback = (result: T | ErrorCallbackResult) => void export interface ClientToServerEvents { join: ( options: { rtpCapabilities: types.RtpCapabilities }, cb: EventCallback ) => void getRtpCapabilities: ( cb: EventCallback ) => void createTransport: ( options: { producing: boolean consuming: boolean }, cb: EventCallback> ) => void connectTransport: ( options: { transportId: types.WebRtcTransport['id'] dtlsParameters: types.WebRtcTransport['dtlsParameters'] }, cb: EventCallback ) => void produce: ( options: { transportId: types.WebRtcTransport['id'] kind: types.MediaKind rtpParameters: types.RtpParameters appData: { source: 'share' | string } }, cb: EventCallback<{ id: types.Producer['id'] }> ) => void closeProducer: ( options: { producerId: types.Producer['id'] }, cb: EventCallback ) => void pauseProducer: ( options: { producerId: types.Producer['id'] }, cb: EventCallback ) => void resumeProducer: ( options: { producerId: types.Producer['id'] }, cb: EventCallback ) => void pauseConsumer: ( options: { consumerId: types.Consumer['id'] }, cb: EventCallback ) => void resumeConsumer: ( options: { consumerId: types.Consumer['id'] }, cb: EventCallback ) => void updateClient: ( options: Partial>, cb: EventCallback ) => void } export interface ServerToClientEvents { authenticated: () => void newPeer: (arg: ChadClient) => void producers: (arg: ProducerShort[]) => void newConsumer: ( arg: { socketId: string producerId: types.Producer['id'] id: types.Consumer['id'] kind: types.MediaKind rtpParameters: types.RtpParameters type: types.ConsumerType appData: types.Producer['appData'] producerPaused: types.Consumer['producerPaused'] }, cb: EventCallback ) => void peerClosed: (arg: string) => void consumerClosed: (arg: { consumerId: string }) => void consumerPaused: (arg: { consumerId: string }) => void consumerResumed: (arg: { consumerId: string }) => void consumerScore: (arg: { consumerId: string, score: types.ConsumerScore }) => void clientChanged: (clientId: ChadClient['socketId'], client: ChadClient) => void } export interface InterServerEvent {} export interface SocketData { joined: boolean userId: User['id'] username: User['username'] displayName: User['displayName'] inputMuted: boolean outputMuted: boolean rtpCapabilities: types.RtpCapabilities transports: Map producers: Map consumers: Map } export type SomeSocket = Socket | RemoteSocket export type Namespace = SocketNamespace