@nice2dev/ui-communication 1.0.4 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,341 @@
1
+ /**
2
+ * @file pstnGatewayService.ts
3
+ * @module @nice2dev/ui-communication
4
+ * @description PRO-20.2 — PSTN Dial-in Gateway Service
5
+ *
6
+ * Enables phone dial-in for video conferences:
7
+ * - Generate dial-in numbers
8
+ * - PIN/access code management
9
+ * - Participant bridging
10
+ * - Audio mixing with WebRTC
11
+ */
12
+ /** Phone number region/country code */
13
+ export type PhoneRegion = 'US' | 'CA' | 'UK' | 'DE' | 'FR' | 'PL' | 'ES' | 'IT' | 'AU' | 'JP' | 'IN' | 'BR' | 'MX';
14
+ /** Dial-in phone number details */
15
+ export interface DialInNumber {
16
+ /** Full E.164 phone number */
17
+ number: string;
18
+ /** Country/region code */
19
+ region: PhoneRegion;
20
+ /** Display number (formatted) */
21
+ displayNumber: string;
22
+ /** Is toll-free */
23
+ tollFree: boolean;
24
+ /** Number type */
25
+ type: 'local' | 'toll-free' | 'premium';
26
+ /** SIP URI for direct VoIP */
27
+ sipUri?: string;
28
+ }
29
+ /** Meeting dial-in info */
30
+ export interface MeetingDialInInfo {
31
+ /** Unique meeting ID */
32
+ meetingId: string;
33
+ /** Available dial-in numbers */
34
+ dialInNumbers: DialInNumber[];
35
+ /** Access pin code */
36
+ accessPin: string;
37
+ /** Meeting passcode (optional extra security) */
38
+ passcode?: string;
39
+ /** Meeting title for IVR */
40
+ meetingTitle: string;
41
+ /** Host pin for host controls */
42
+ hostPin?: string;
43
+ /** Expires at timestamp */
44
+ expiresAt: number;
45
+ }
46
+ /** PSTN participant state */
47
+ export type PstnParticipantState = 'connecting' | 'waiting-pin' | 'joined' | 'on-hold' | 'muted' | 'speaking' | 'disconnected';
48
+ /** PSTN participant info */
49
+ export interface PstnParticipant {
50
+ /** Unique call ID */
51
+ callId: string;
52
+ /** Caller phone number (if available) */
53
+ callerNumber?: string;
54
+ /** Caller ID name */
55
+ callerName?: string;
56
+ /** Current state */
57
+ state: PstnParticipantState;
58
+ /** Join timestamp */
59
+ joinedAt: number;
60
+ /** Audio stats */
61
+ audioStats: {
62
+ /** Current volume level (0-100) */
63
+ volume: number;
64
+ /** Is currently muted */
65
+ isMuted: boolean;
66
+ /** Packet loss percentage */
67
+ packetLoss: number;
68
+ /** Audio quality score (1-5) */
69
+ quality: number;
70
+ };
71
+ /** Is host caller */
72
+ isHost: boolean;
73
+ /** Is moderator */
74
+ isModerator: boolean;
75
+ }
76
+ /** Gateway configuration */
77
+ export interface PstnGatewayConfig {
78
+ /** SIP trunk provider */
79
+ provider: 'twilio' | 'vonage' | 'plivo' | 'telnyx' | 'custom';
80
+ /** Account SID */
81
+ accountSid: string;
82
+ /** Auth token */
83
+ authToken: string;
84
+ /** SIP domain */
85
+ sipDomain: string;
86
+ /** Default region */
87
+ defaultRegion: PhoneRegion;
88
+ /** Enabled regions */
89
+ enabledRegions: PhoneRegion[];
90
+ /** Max participants per meeting */
91
+ maxParticipants: number;
92
+ /** Recording mode */
93
+ recordingMode: 'none' | 'audio-only' | 'full';
94
+ /** Custom IVR text */
95
+ ivrText?: {
96
+ welcome: string;
97
+ enterPin: string;
98
+ invalidPin: string;
99
+ joined: string;
100
+ muted: string;
101
+ unmuted: string;
102
+ onHold: string;
103
+ goodbye: string;
104
+ };
105
+ }
106
+ /** DTMF command mapping */
107
+ export interface DtmfCommands {
108
+ /** Mute/unmute self */
109
+ toggleMute: string;
110
+ /** Raise/lower hand */
111
+ raiseHand: string;
112
+ /** Leave meeting */
113
+ leave: string;
114
+ /** Request help */
115
+ help: string;
116
+ /** Host: mute all */
117
+ hostMuteAll: string;
118
+ /** Host: unmute all */
119
+ hostUnmuteAll: string;
120
+ /** Host: end meeting */
121
+ hostEndMeeting: string;
122
+ }
123
+ /** Gateway events */
124
+ export interface PstnGatewayEvents {
125
+ /** Participant joined */
126
+ onParticipantJoined: (participant: PstnParticipant) => void;
127
+ /** Participant left */
128
+ onParticipantLeft: (participant: PstnParticipant) => void;
129
+ /** Participant state changed */
130
+ onParticipantStateChanged: (participant: PstnParticipant, oldState: PstnParticipantState) => void;
131
+ /** DTMF received */
132
+ onDtmfReceived: (participant: PstnParticipant, digit: string) => void;
133
+ /** Error occurred */
134
+ onError: (error: PstnGatewayError) => void;
135
+ /** Connection status changed */
136
+ onStatusChanged: (status: 'connected' | 'disconnected' | 'reconnecting') => void;
137
+ }
138
+ /** Gateway error */
139
+ export interface PstnGatewayError {
140
+ code: string;
141
+ message: string;
142
+ participant?: PstnParticipant;
143
+ timestamp: number;
144
+ }
145
+ /** Default DTMF commands */
146
+ export declare const DEFAULT_DTMF_COMMANDS: DtmfCommands;
147
+ /** Default IVR messages */
148
+ export declare const DEFAULT_IVR_TEXT: {
149
+ welcome: string;
150
+ enterPin: string;
151
+ invalidPin: string;
152
+ joined: string;
153
+ muted: string;
154
+ unmuted: string;
155
+ onHold: string;
156
+ goodbye: string;
157
+ };
158
+ /** Region phone codes */
159
+ export declare const REGION_CODES: Record<PhoneRegion, string>;
160
+ /**
161
+ * PSTN Dial-in Gateway Service for video conferences.
162
+ *
163
+ * Manages phone dial-in participants, audio bridging, and IVR interactions.
164
+ */
165
+ export declare class PstnGatewayService {
166
+ private config;
167
+ private eventHandlers;
168
+ private participants;
169
+ private meetingDialIns;
170
+ private dtmfCommands;
171
+ private connectionStatus;
172
+ private ivrText;
173
+ constructor(config?: Partial<PstnGatewayConfig>);
174
+ /**
175
+ * Set event handler.
176
+ */
177
+ on<K extends keyof PstnGatewayEvents>(event: K, handler: PstnGatewayEvents[K]): void;
178
+ /**
179
+ * Remove event handler.
180
+ */
181
+ off<K extends keyof PstnGatewayEvents>(event: K): void;
182
+ private emit;
183
+ /**
184
+ * Generate dial-in info for a meeting.
185
+ */
186
+ generateDialInInfo(meetingId: string, meetingTitle: string): MeetingDialInInfo;
187
+ /**
188
+ * Get dial-in info for a meeting.
189
+ */
190
+ getDialInInfo(meetingId: string): MeetingDialInInfo | undefined;
191
+ /**
192
+ * Get available dial-in numbers for enabled regions.
193
+ */
194
+ getAvailableNumbers(): DialInNumber[];
195
+ private generatePhoneNumber;
196
+ private formatPhoneNumber;
197
+ private generateAccessPin;
198
+ /**
199
+ * Handle incoming call.
200
+ */
201
+ handleIncomingCall(callId: string, callerNumber?: string, callerName?: string): Promise<PstnParticipant>;
202
+ /**
203
+ * Validate PIN and join meeting.
204
+ */
205
+ validatePinAndJoin(callId: string, meetingId: string, pin: string): Promise<{
206
+ success: boolean;
207
+ isHost: boolean;
208
+ }>;
209
+ /**
210
+ * Get participant by call ID.
211
+ */
212
+ getParticipant(callId: string): PstnParticipant | undefined;
213
+ /**
214
+ * Get all participants for a meeting.
215
+ */
216
+ getParticipants(): PstnParticipant[];
217
+ /**
218
+ * Update participant state.
219
+ */
220
+ private updateParticipantState;
221
+ /**
222
+ * Mute a participant.
223
+ */
224
+ muteParticipant(callId: string): Promise<void>;
225
+ /**
226
+ * Unmute a participant.
227
+ */
228
+ unmuteParticipant(callId: string): Promise<void>;
229
+ /**
230
+ * Toggle mute for a participant.
231
+ */
232
+ toggleMute(callId: string): Promise<boolean>;
233
+ /**
234
+ * Put participant on hold.
235
+ */
236
+ putOnHold(callId: string): Promise<void>;
237
+ /**
238
+ * Remove participant from hold.
239
+ */
240
+ removeFromHold(callId: string): Promise<void>;
241
+ /**
242
+ * Mute all participants (host control).
243
+ */
244
+ muteAll(excludeHosts?: boolean): Promise<void>;
245
+ /**
246
+ * Unmute all participants (host control).
247
+ */
248
+ unmuteAll(): Promise<void>;
249
+ /**
250
+ * Handle DTMF input from participant.
251
+ */
252
+ handleDtmf(callId: string, digits: string): Promise<void>;
253
+ /**
254
+ * Configure DTMF commands.
255
+ */
256
+ setDtmfCommands(commands: Partial<DtmfCommands>): void;
257
+ /**
258
+ * Play IVR message to participant.
259
+ */
260
+ playIvr(callId: string, messageKey: keyof typeof DEFAULT_IVR_TEXT): Promise<void>;
261
+ /**
262
+ * Play custom TTS message.
263
+ */
264
+ playCustomMessage(callId: string, text: string): Promise<void>;
265
+ /**
266
+ * Play help instructions.
267
+ */
268
+ playHelp(callId: string): Promise<void>;
269
+ /**
270
+ * Disconnect a participant.
271
+ */
272
+ disconnectParticipant(callId: string): Promise<void>;
273
+ /**
274
+ * End meeting for all PSTN participants.
275
+ */
276
+ endMeeting(): Promise<void>;
277
+ /**
278
+ * Get connection status.
279
+ */
280
+ getStatus(): 'connected' | 'disconnected' | 'reconnecting';
281
+ /**
282
+ * Connect to PSTN gateway.
283
+ */
284
+ connect(): Promise<void>;
285
+ /**
286
+ * Disconnect from PSTN gateway.
287
+ */
288
+ disconnect(): Promise<void>;
289
+ /**
290
+ * Get audio mixer configuration for WebRTC bridge.
291
+ */
292
+ getAudioBridgeConfig(): {
293
+ sampleRate: number;
294
+ channels: number;
295
+ codec: string;
296
+ bitrate: number;
297
+ };
298
+ /**
299
+ * Get SDP offer for audio bridging.
300
+ */
301
+ getSdpOffer(): string;
302
+ /**
303
+ * Process SDP answer from WebRTC peer.
304
+ */
305
+ processSdpAnswer(sdp: string): void;
306
+ }
307
+ /**
308
+ * Get the default PSTN gateway instance.
309
+ */
310
+ export declare function getPstnGateway(config?: Partial<PstnGatewayConfig>): PstnGatewayService;
311
+ /**
312
+ * Create a new PSTN gateway instance.
313
+ */
314
+ export declare function createPstnGateway(config: Partial<PstnGatewayConfig>): PstnGatewayService;
315
+ export interface UsePstnGatewayReturn {
316
+ /** Gateway connection status */
317
+ status: 'connected' | 'disconnected' | 'reconnecting';
318
+ /** List of PSTN participants */
319
+ participants: PstnParticipant[];
320
+ /** Generate dial-in info for a meeting */
321
+ generateDialIn: (meetingId: string, title: string) => MeetingDialInInfo;
322
+ /** Get dial-in info */
323
+ getDialIn: (meetingId: string) => MeetingDialInInfo | undefined;
324
+ /** Mute a participant */
325
+ mute: (callId: string) => Promise<void>;
326
+ /** Unmute a participant */
327
+ unmute: (callId: string) => Promise<void>;
328
+ /** Disconnect a participant */
329
+ disconnect: (callId: string) => Promise<void>;
330
+ /** Mute all participants */
331
+ muteAll: () => Promise<void>;
332
+ /** End meeting for all PSTN participants */
333
+ endMeeting: () => Promise<void>;
334
+ /** Connect to gateway */
335
+ connect: () => Promise<void>;
336
+ }
337
+ /**
338
+ * React hook for PSTN gateway management.
339
+ */
340
+ export declare function usePstnGateway(config?: Partial<PstnGatewayConfig>): UsePstnGatewayReturn;
341
+ export default PstnGatewayService;