@sawport/peers-caller
Version:
WebRTC multi-peer video call library with mesh architecture supporting up to 4 participants
262 lines • 7.68 kB
TypeScript
/**
* Core type definitions for PeersCaller library
*/
import type { Socket } from "socket.io-client";
import type SimplePeer from "simple-peer";
export interface CallParticipant {
peer?: SimplePeer.Instance | null;
userId: string;
videoOn: boolean;
audioOn: boolean;
screenSharing: boolean;
stream?: MediaStream;
videoElement?: HTMLVideoElement;
}
export interface CallState {
conversationId: string;
participants: Record<string, CallParticipant>;
localParticipant: CallParticipant | null;
isCalling: boolean;
isRecording: boolean;
recordLoading: boolean;
callStatus: "idle" | "connecting" | "connected" | "disconnecting" | "failed";
error: string | null;
callStatusInfo: CallStatusResponse | null;
callStatusLoading: boolean;
callStatusError: string | null;
}
export interface MediaStreamConfig {
video: boolean | MediaTrackConstraints;
audio: boolean | MediaTrackConstraints;
}
export interface ScreenShareConfig {
video: boolean | MediaTrackConstraints;
audio: boolean;
}
export interface PeerConnectionConfig {
iceServers: RTCIceServer[];
maxBitrate?: number;
initiator?: boolean;
}
export interface RecordingConfig {
mimeType?: string;
videoBitsPerSecond?: number;
audioBitsPerSecond?: number;
interval?: number;
recordingData?: RecordingData;
}
export interface TranscriptionConfig {
language?: string;
continuous?: boolean;
interimResults?: boolean;
sendInterval?: number;
}
export interface CallStatusResponse {
conversationId: string;
hasActiveCall: boolean;
participantCount: number;
maxParticipants: number;
participants: string[];
startedAt: Date | null;
canJoin: boolean;
status: "no_call" | "active" | "full" | "ending";
}
export interface SignalingEvents {
"call.start": (data: {
conversationId: string;
userId: string;
}) => void;
"call.join": (data: {
conversationId: string;
userId: string;
}) => void;
"call.leave": (data: {
conversationId: string;
userId: string;
}) => void;
"call.offer": (data: {
to: string;
from: string;
offer: RTCSessionDescriptionInit;
conversationId: string;
}) => void;
"call.answer": (data: {
to: string;
from: string;
answer: RTCSessionDescriptionInit;
conversationId: string;
}) => void;
"call.candidate": (data: {
to: string;
from: string;
candidate: RTCIceCandidateInit;
conversationId: string;
}) => void;
"call.state": (data: {
to?: string;
from: string;
state: Partial<CallParticipant>;
conversationId: string;
}) => void;
"call.end": (data: {
conversationId: string;
targetUserId?: string;
}) => void;
"call.status": (data: {
conversationId: string;
userId: string;
}) => void;
"call.recording.start": (data: {
conversationId: string;
recordingId: string;
}) => void;
"call.recording.chunk": (data: {
conversationId: string;
recordingId: string;
chunk: Blob;
}) => void;
"call.recording.end": (data: {
conversationId: string;
recordingId: string;
}) => void;
"call.transcript": (data: {
conversationId: string;
userId: string;
transcript: string;
timestamp: number;
}) => void;
}
export interface SignalingIncomingEvents {
"call.started": (data: {
conversationId: string;
userId: string;
success: boolean;
participants: string[];
}) => void;
"call.participant.joined": (data: {
userId: string;
participants: string[];
conversationId: string;
}) => void;
"call.participant.left": (data: {
userId: string;
participants: string[];
conversationId: string;
}) => void;
"call.participants": (data: {
participants: string[];
conversationId: string;
}) => void;
"call.left": (data: {
conversationId: string;
success: boolean;
}) => void;
"call.error": (data: {
error: string;
message: string;
}) => void;
"call.offer": (data: {
from: string;
offer: RTCSessionDescriptionInit;
conversationId: string;
}) => void;
"call.answer": (data: {
from: string;
answer: RTCSessionDescriptionInit;
conversationId: string;
}) => void;
"call.candidate": (data: {
from: string;
candidate: RTCIceCandidateInit;
conversationId: string;
}) => void;
"call.state": (data: {
from: string;
state: Partial<CallParticipant>;
conversationId: string;
}) => void;
"call.ended": (data: {
conversationId: string;
endedBy: string;
reason: string;
}) => void;
"call.status.changed": (data: CallStatusResponse) => void;
"call.recording.start": (data: {
recordingId: string;
conversationId: string;
}) => void;
"call.recording.chunk.received": (data: {
recordingId: string;
conversationId: string;
chunkSize: number;
timestamp: number;
}) => void;
"call.recording.end": (data: {
recordingId: string;
conversationId: string;
}) => void;
"call.transcript": (data: {
userId: string;
transcript: string;
timestamp: number;
conversationId: string;
}) => void;
}
export type PeersCallerError = "MEDIA_ACCESS_DENIED" | "PEER_CONNECTION_FAILED" | "SIGNALING_ERROR" | "RECORDING_FAILED" | "TRANSCRIPTION_FAILED" | "CALL_LIMIT_EXCEEDED" | "INVALID_CONVERSATION_ID" | "NETWORK_ERROR" | "UNKNOWN_ERROR";
export interface PeersCallerConfig {
conversationId: string;
userId: string;
token: string;
socketUrl: string;
socketPath?: string;
iceServers?: RTCIceServer[];
mediaConfig?: MediaStreamConfig;
recordingConfig?: RecordingConfig;
transcriptionConfig?: TranscriptionConfig;
maxParticipants?: number;
debug?: boolean;
}
export interface PeersCallerCallbacks {
onCallStarted?: (data: {
conversationId: string;
userId: string;
success: boolean;
participants: string[];
}) => void;
onCallEnded?: (data: {
conversationId: string;
endedBy: string;
reason: string;
}) => void;
onParticipantJoined?: (participant: CallParticipant) => void;
onParticipantLeft?: (userId: string) => void;
onParticipantStateChanged?: (userId: string, state: Partial<CallParticipant>) => void;
onStreamReceived?: (userId: string, stream: MediaStream) => void;
onCallStateChanged?: (state: CallState["callStatus"]) => void;
onCallStatusChanged?: (statusInfo: CallStatusResponse) => void;
onRecordingStateChanged?: (isRecording: boolean) => void;
onError?: (error: PeersCallerError, message: string) => void;
}
export type PeerConnection = SimplePeer.Instance;
export type SocketClient = Socket;
export type AllSignalingEvents = SignalingEvents & SignalingIncomingEvents;
export interface RecordingData {
id: string;
filename: string;
conversationId: string;
startTime: number;
}
export interface TranscriptData {
userId: string;
text: string;
timestamp: number;
isFinal: boolean;
}
export interface CallMetrics {
connectionCount: number;
activeStreams: number;
recordingSize: number;
transcriptCount: number;
bandwidthUsage: number;
}
//# sourceMappingURL=index.d.ts.map