msg91-webrtc-call
Version:
**msg91-webrtc-call** is a lightweight JavaScript SDK that enables you to easily add peer-to-peer WebRTC audio/video calling functionality to your web applications using the MSG91 infrastructure.
141 lines (140 loc) • 3.81 kB
TypeScript
import type { IncomingCall, OutgoingCall } from "..";
import { User } from "./user";
export type Message = {
type: "text";
content: string;
} | {
type: "image";
content: string;
} | {
type: "button";
options: {
title: string;
}[];
};
export type MessageArray = Message[];
export declare enum CALL_EVENT {
ENDED = "ended",
ANSWERED = "answered",
REJOINED = "rejoined",
UNAVAILABLE = "unavailable",
ERROR = "error",
CONNECTED = "connected",
MUTE = "mute",
UNMUTE = "unmute",
MESSAGE = "message",
SILENCE_STATE = "silence"
}
export interface CallEventMap {
[CALL_EVENT.ANSWERED]: (data: AnsweredPayload) => void;
[CALL_EVENT.UNAVAILABLE]: (data: UnavailablePayload) => void;
[CALL_EVENT.REJOINED]: (data: RejoinedPayload) => void;
[CALL_EVENT.ENDED]: (data: EndedPayload) => void;
[CALL_EVENT.ERROR]: (data: ErrorPayload) => void;
[CALL_EVENT.CONNECTED]: (data: ConnectedPayload) => void;
[CALL_EVENT.SILENCE_STATE]: (data: SilenceStatePayload) => void;
[CALL_EVENT.MESSAGE]: (data: MessagePayload) => void;
[CALL_EVENT.MUTE]: (data: MutePayload) => void;
[CALL_EVENT.UNMUTE]: (data: UnmutePayload) => void;
}
type CallPayload = Omit<CallData, 'status' | 'type' | 'summary' | 'producerTransport' | 'consumerTransport' | 'routerRtpCapabilities' | 'token'>;
export type AnsweredPayload = CallPayload & {
answeredBy: User;
answeredAt: Date;
message: 'Call answered';
type: 'call-answered';
};
export type UnavailablePayload = CallPayload & {
answeredBy: User;
answeredAt: Date;
message: 'Call already answered';
type: 'call-unavailable';
};
export type RejoinedPayload = CallPayload & Pick<CallData, 'summary' | 'type' | 'status'>;
export type ErrorPayload = {
message: string;
error: any;
};
export type ConnectedPayload = typeof MediaStream;
export type EndedPayload = CallPayload & {
endedAt: Date;
endedBy: User;
type: 'call-ended';
message: 'Call ended';
};
export type SilenceStatePayload = {
silent: boolean;
};
export type MessagePayload = {
message: {
type: "text";
content: string;
};
from: "bot" | "user";
};
export type MutePayload = {
uid: string;
};
export type UnmutePayload = {
uid: string;
};
export declare enum WebRTC_EVENT {
CALL = "call",
INCOMING_CALL = "incoming-call",
OUTGOING_CALL = "outgoing-call",
PLAY_RINGTONE = "play-ringtone",
STOP_RINGTONE = "stop-ringtone"
}
export interface WebRTCEventMap {
[WebRTC_EVENT.CALL]: (data: CallData) => void;
[WebRTC_EVENT.INCOMING_CALL]: (data: IncomingCall) => void;
[WebRTC_EVENT.OUTGOING_CALL]: (data: OutgoingCall) => void;
[WebRTC_EVENT.PLAY_RINGTONE]: () => void;
[WebRTC_EVENT.STOP_RINGTONE]: () => void;
}
export declare enum CALL_STATUS {
IDLE = "idle",
RINGING = "ringing",
CONNECTED = "connected",
ENDED = "ended"
}
export declare enum CALL_TYPE {
INCOMING = "incoming-call",
OUTGOING = "outgoing-call"
}
export declare enum USER_STATUS {
IDLE = "idle",// User is available to take new call
BUSY = "busy"
}
export declare enum RINGTONE {
STOP = "stop",
RING = "ring"
}
export declare enum CALL_MANAGER_EVENT {
RINGTONE_STATUS_CHANGED = "ringtone-status-changed"
}
export interface CallData {
id: string;
from: User;
to: User[];
bot?: User;
summary?: {
startedAt: Date;
answeredAt: Date;
answeredBy: User;
};
status?: CALL_STATUS;
producerTransport: any;
consumerTransport: any;
routerRtpCapabilities: any;
type: CALL_TYPE;
token?: string;
}
export type CallInfo = {
id: string;
from: User;
to: User[];
type: CALL_TYPE;
silent?: boolean;
};
export {};