cringe sfx
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import type { types } from 'mediasoup'
|
||||
import type { RemoteSocket, Server, Socket } from 'socket.io'
|
||||
import type { ChannelPublicDTO } from '../dto/channel.dto.ts'
|
||||
import type { ChannelModel, UserModel } from '../prisma/generated/client/models.ts'
|
||||
|
||||
export interface ServerInfo {
|
||||
owner_id: UserModel['id']
|
||||
channels: ChannelModel[]
|
||||
channels: ChannelPublicDTO[]
|
||||
rtpCapabilities: types.RtpCapabilities
|
||||
}
|
||||
|
||||
@@ -15,6 +16,7 @@ export interface ChadClient {
|
||||
displayName: UserModel['displayName']
|
||||
inputMuted: boolean
|
||||
outputMuted: boolean
|
||||
currentChannelId: ChannelModel['id']
|
||||
}
|
||||
|
||||
export interface ProducerShort {
|
||||
@@ -31,32 +33,41 @@ export interface SuccessCallbackResult {
|
||||
}
|
||||
|
||||
export type EventCallback<T = SuccessCallbackResult> = (result: T | ErrorCallbackResult) => void
|
||||
export type EventCallbackResult<T = SuccessCallbackResult> = Parameters<EventCallback<T>>[0]
|
||||
|
||||
type LastArg<T extends any[]> = T extends [...any[], infer Last] ? Last : T extends [infer Only] ? Only : never
|
||||
|
||||
export type ExtractCallbackPayload<
|
||||
T,
|
||||
Fallback = EventCallbackResult,
|
||||
>
|
||||
= T extends (...args: infer Args) => any
|
||||
? LastArg<Args> extends (...inner: infer CallbackArgs) => any
|
||||
? CallbackArgs extends [infer First, ...any[]]
|
||||
? First
|
||||
: Fallback
|
||||
: Fallback
|
||||
: Fallback
|
||||
|
||||
export interface ClientToServerEvents {
|
||||
join: (
|
||||
options: {
|
||||
rtpCapabilities: types.RtpCapabilities
|
||||
},
|
||||
cb: EventCallback<ChadClient[]>
|
||||
) => void
|
||||
getRtpCapabilities: (
|
||||
'webrtc:get-rtp-capabilities': (
|
||||
cb: EventCallback<types.RtpCapabilities>
|
||||
) => void
|
||||
createTransport: (
|
||||
'webrtc:create-transport': (
|
||||
options: {
|
||||
producing: boolean
|
||||
consuming: boolean
|
||||
},
|
||||
cb: EventCallback<Pick<types.WebRtcTransport, 'id' | 'iceParameters' | 'iceCandidates' | 'dtlsParameters'>>
|
||||
) => void
|
||||
connectTransport: (
|
||||
'webrtc:connect-transport': (
|
||||
options: {
|
||||
transportId: types.WebRtcTransport['id']
|
||||
dtlsParameters: types.WebRtcTransport['dtlsParameters']
|
||||
},
|
||||
cb: EventCallback
|
||||
) => void
|
||||
produce: (
|
||||
'webrtc:produce': (
|
||||
options: {
|
||||
transportId: types.WebRtcTransport['id']
|
||||
kind: types.MediaKind
|
||||
@@ -65,47 +76,51 @@ export interface ClientToServerEvents {
|
||||
},
|
||||
cb: EventCallback<{ id: types.Producer['id'] }>
|
||||
) => void
|
||||
closeProducer: (
|
||||
'webrtc:close-producer': (
|
||||
options: {
|
||||
producerId: types.Producer['id']
|
||||
},
|
||||
cb: EventCallback
|
||||
) => void
|
||||
pauseProducer: (
|
||||
'webrtc:pause-producer': (
|
||||
options: {
|
||||
producerId: types.Producer['id']
|
||||
},
|
||||
cb: EventCallback
|
||||
) => void
|
||||
resumeProducer: (
|
||||
'webrtc:resume-producer': (
|
||||
options: {
|
||||
producerId: types.Producer['id']
|
||||
},
|
||||
cb: EventCallback
|
||||
) => void
|
||||
pauseConsumer: (
|
||||
'webrtc:pause-consumer': (
|
||||
options: {
|
||||
consumerId: types.Consumer['id']
|
||||
},
|
||||
cb: EventCallback
|
||||
) => void
|
||||
resumeConsumer: (
|
||||
'webrtc:resume-consumer': (
|
||||
options: {
|
||||
consumerId: types.Consumer['id']
|
||||
},
|
||||
cb: EventCallback
|
||||
) => void
|
||||
updateClient: (
|
||||
'webrtc:update-client': (
|
||||
options: Partial<Pick<ChadClient, 'inputMuted' | 'outputMuted'>>,
|
||||
cb: EventCallback<ChadClient>
|
||||
) => void
|
||||
|
||||
'channel:join': (
|
||||
options: { channelId: ChannelModel['id'] },
|
||||
cb: EventCallback<{ channel: ChannelPublicDTO, clients: ChadClient[] }>
|
||||
) => void
|
||||
}
|
||||
|
||||
export interface ServerToClientEvents {
|
||||
authenticated: (arg: ServerInfo) => void
|
||||
newPeer: (arg: ChadClient) => void
|
||||
producers: (arg: ProducerShort[]) => void
|
||||
newConsumer: (
|
||||
'webrtc:authenticated': (arg: ServerInfo) => void
|
||||
'webrtc:producers': (arg: ProducerShort[]) => void
|
||||
'webrtc:new-consumer': (
|
||||
arg: {
|
||||
socketId: string
|
||||
producerId: types.Producer['id']
|
||||
@@ -118,14 +133,21 @@ export interface ServerToClientEvents {
|
||||
},
|
||||
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
|
||||
speakingPeers: (arg: { clientId: ChadClient['socketId'], volume: types.AudioLevelObserverVolume['volume'] }[]) => void
|
||||
activeSpeaker: (clientId?: ChadClient['socketId']) => void
|
||||
'webrtc:peer-closed': (arg: string) => void
|
||||
'webrtc:consumer-closed': (arg: { consumerId: string }) => void
|
||||
'webrtc:consumer-paused': (arg: { consumerId: string }) => void
|
||||
'webrtc:consumer-resumed': (arg: { consumerId: string }) => void
|
||||
'webrtc:consumer-score': (arg: { consumerId: string, score: types.ConsumerScore }) => void
|
||||
'webrtc:client-changed': (clientId: ChadClient['socketId'], client: ChadClient) => void
|
||||
'webrtc:speaking-peers': (arg: { clientId: ChadClient['socketId'], volume: types.AudioLevelObserverVolume['volume'] }[]) => void
|
||||
'webrtc:active-speaker': (clientId?: ChadClient['socketId']) => void
|
||||
|
||||
'channel:user-joined': (arg: { channelId: string, client: ChadClient }) => void
|
||||
'channel:user-left': (arg: { channelId: string, clientId: string }) => void
|
||||
'channel:deleted': (arg: { channelId: string }) => void
|
||||
'channel:created': (arg: ChannelPublicDTO) => void
|
||||
'channel:updated': (arg: ChannelPublicDTO) => void
|
||||
'channel:force-switch': (arg: { channelId: string }) => void
|
||||
}
|
||||
|
||||
export interface InterServerEvent {}
|
||||
@@ -143,7 +165,9 @@ export interface SocketData {
|
||||
consumers: Map<types.Consumer['id'], types.Consumer>
|
||||
}
|
||||
|
||||
export type SomeSocket = Socket<ClientToServerEvents, ServerToClientEvents, InterServerEvent, SocketData>
|
||||
| RemoteSocket<ServerToClientEvents, SocketData>
|
||||
export type ChadSocket = Socket<ClientToServerEvents, ServerToClientEvents, InterServerEvent, SocketData>
|
||||
export type ChadRemoteSocket = RemoteSocket<ServerToClientEvents, SocketData>
|
||||
|
||||
export type SomeSocket = ChadSocket | ChadRemoteSocket
|
||||
|
||||
export type SocketServer = Server<ClientToServerEvents, ServerToClientEvents, InterServerEvent, SocketData>
|
||||
|
||||
Reference in New Issue
Block a user