react-jssip-kit 0.1.0
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.
- package/CHANGELOG.md +4 -0
- package/LICENSE +21 -0
- package/README.md +75 -0
- package/dist/index.cjs +1377 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +318 -0
- package/dist/index.d.ts +318 -0
- package/dist/index.js +1355 -0
- package/dist/index.js.map +1 -0
- package/package.json +49 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import { UA } from 'jssip';
|
|
2
|
+
export { WebSocketInterface } from 'jssip';
|
|
3
|
+
import * as jssip_lib_UA from 'jssip/lib/UA';
|
|
4
|
+
import { UAEventMap, IncomingRTCSessionEvent, UAConfiguration, CallOptions, RTCSessionEvent } from 'jssip/lib/UA';
|
|
5
|
+
import * as jssip_lib_RTCSession from 'jssip/lib/RTCSession';
|
|
6
|
+
import { RTCSessionEventMap, DTFMOptions as DTFMOptions$1, AnswerOptions, TerminateOptions, RTCSession, ReferOptions } from 'jssip/lib/RTCSession';
|
|
7
|
+
import * as react from 'react';
|
|
8
|
+
import react__default from 'react';
|
|
9
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
10
|
+
|
|
11
|
+
type ExtraEvents = {
|
|
12
|
+
error: {
|
|
13
|
+
cause: string;
|
|
14
|
+
code?: string;
|
|
15
|
+
raw?: any;
|
|
16
|
+
message?: string;
|
|
17
|
+
};
|
|
18
|
+
missed: IncomingRTCSessionEvent;
|
|
19
|
+
sessionCleanup: {
|
|
20
|
+
sessionId: string;
|
|
21
|
+
session?: jssip_lib_RTCSession.RTCSession | null;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
declare const JsSIPEventName: {
|
|
25
|
+
readonly connecting: "connecting";
|
|
26
|
+
readonly connected: "connected";
|
|
27
|
+
readonly disconnected: "disconnected";
|
|
28
|
+
readonly registered: "registered";
|
|
29
|
+
readonly unregistered: "unregistered";
|
|
30
|
+
readonly registrationFailed: "registrationFailed";
|
|
31
|
+
readonly registrationExpiring: "registrationExpiring";
|
|
32
|
+
readonly newRTCSession: "newRTCSession";
|
|
33
|
+
readonly newMessage: "newMessage";
|
|
34
|
+
readonly sipEvent: "sipEvent";
|
|
35
|
+
readonly newOptions: "newOptions";
|
|
36
|
+
readonly peerconnection: "peerconnection";
|
|
37
|
+
readonly sending: "sending";
|
|
38
|
+
readonly progress: "progress";
|
|
39
|
+
readonly accepted: "accepted";
|
|
40
|
+
readonly confirmed: "confirmed";
|
|
41
|
+
readonly ended: "ended";
|
|
42
|
+
readonly failed: "failed";
|
|
43
|
+
readonly newDTMF: "newDTMF";
|
|
44
|
+
readonly newInfo: "newInfo";
|
|
45
|
+
readonly hold: "hold";
|
|
46
|
+
readonly unhold: "unhold";
|
|
47
|
+
readonly muted: "muted";
|
|
48
|
+
readonly unmuted: "unmuted";
|
|
49
|
+
readonly reinvite: "reinvite";
|
|
50
|
+
readonly update: "update";
|
|
51
|
+
readonly refer: "refer";
|
|
52
|
+
readonly replaces: "replaces";
|
|
53
|
+
readonly sdp: "sdp";
|
|
54
|
+
readonly error: "error";
|
|
55
|
+
readonly icecandidate: "icecandidate";
|
|
56
|
+
readonly getusermediafailed: "getusermediafailed";
|
|
57
|
+
readonly "peerconnection:createofferfailed": "peerconnection:createofferfailed";
|
|
58
|
+
readonly "peerconnection:createanswerfailed": "peerconnection:createanswerfailed";
|
|
59
|
+
readonly "peerconnection:setlocaldescriptionfailed": "peerconnection:setlocaldescriptionfailed";
|
|
60
|
+
readonly "peerconnection:setremotedescriptionfailed": "peerconnection:setremotedescriptionfailed";
|
|
61
|
+
readonly missed: "missed";
|
|
62
|
+
readonly sessionCleanup: "sessionCleanup";
|
|
63
|
+
};
|
|
64
|
+
type JsSIPEventName = keyof UAEventMap | keyof RTCSessionEventMap | keyof ExtraEvents | "sessionCleanup";
|
|
65
|
+
type JsSIPEventPayload<K extends JsSIPEventName> = K extends keyof UAEventMap ? Parameters<UAEventMap[K]>[0] : K extends keyof RTCSessionEventMap ? Parameters<RTCSessionEventMap[K]>[0] : K extends keyof ExtraEvents ? ExtraEvents[K] : never;
|
|
66
|
+
type JsSIPEventHandler<K extends JsSIPEventName> = (payload?: JsSIPEventPayload<K>) => void;
|
|
67
|
+
type SipEventHandlers = {
|
|
68
|
+
[K in JsSIPEventName]?: JsSIPEventHandler<K>;
|
|
69
|
+
};
|
|
70
|
+
interface SipEventManager {
|
|
71
|
+
bind: (handlers: SipEventHandlers) => () => void;
|
|
72
|
+
}
|
|
73
|
+
type JsSIPEventMap = {
|
|
74
|
+
[K in JsSIPEventName]: JsSIPEventPayload<K>;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
type DTFMOptions = DTFMOptions$1;
|
|
78
|
+
|
|
79
|
+
type SipConfiguration = Omit<UAConfiguration, "password" | "uri"> & {
|
|
80
|
+
/**
|
|
81
|
+
* Enable JsSIP debug logging. If string, treated as debug pattern.
|
|
82
|
+
*/
|
|
83
|
+
debug?: boolean | string;
|
|
84
|
+
/**
|
|
85
|
+
* Maximum allowed concurrent sessions. Additional sessions are rejected.
|
|
86
|
+
*/
|
|
87
|
+
maxSessionCount?: number;
|
|
88
|
+
/**
|
|
89
|
+
* Milliseconds to keep enqueued outgoing media before dropping. Defaults to 30000.
|
|
90
|
+
*/
|
|
91
|
+
pendingMediaTtlMs?: number;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
type StartOpts = {
|
|
95
|
+
debug?: boolean | string;
|
|
96
|
+
};
|
|
97
|
+
declare class SipUserAgent {
|
|
98
|
+
private _ua;
|
|
99
|
+
get ua(): UA | null;
|
|
100
|
+
get isStarted(): boolean;
|
|
101
|
+
get isRegistered(): boolean;
|
|
102
|
+
start(uri: string, password: string, config: Omit<SipConfiguration, "debug">, opts?: StartOpts): UA;
|
|
103
|
+
register(): void;
|
|
104
|
+
stop(): void;
|
|
105
|
+
getUA(): UA | null;
|
|
106
|
+
setDebug(debug?: boolean | string): void;
|
|
107
|
+
protected buildUAConfig(config: Omit<SipConfiguration, "debug">, uri: string, password: string): UAConfiguration;
|
|
108
|
+
protected ensureValid(cfg: UAConfiguration): void;
|
|
109
|
+
protected applyDebug(debug?: boolean | string): void;
|
|
110
|
+
protected createUA(cfg: UAConfiguration): UA;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
declare const SipStatus: {
|
|
114
|
+
readonly Disconnected: "disconnected";
|
|
115
|
+
readonly Connecting: "connecting";
|
|
116
|
+
readonly Connected: "connected";
|
|
117
|
+
readonly Registered: "registered";
|
|
118
|
+
readonly Unregistered: "unregistered";
|
|
119
|
+
readonly RegistrationFailed: "registrationFailed";
|
|
120
|
+
};
|
|
121
|
+
type SipStatus = typeof SipStatus[keyof typeof SipStatus];
|
|
122
|
+
declare const CallStatus: {
|
|
123
|
+
readonly Idle: "idle";
|
|
124
|
+
readonly Dialing: "dialing";
|
|
125
|
+
readonly Ringing: "ringing";
|
|
126
|
+
readonly Active: "active";
|
|
127
|
+
readonly Hold: "hold";
|
|
128
|
+
};
|
|
129
|
+
type CallStatus = typeof CallStatus[keyof typeof CallStatus];
|
|
130
|
+
declare const CallDirection: {
|
|
131
|
+
readonly Incoming: "incoming";
|
|
132
|
+
readonly Outgoing: "outgoing";
|
|
133
|
+
readonly None: "none";
|
|
134
|
+
};
|
|
135
|
+
type CallDirection = typeof CallDirection[keyof typeof CallDirection];
|
|
136
|
+
type SipSessionState = {
|
|
137
|
+
id: string;
|
|
138
|
+
status: CallStatus;
|
|
139
|
+
direction: CallDirection;
|
|
140
|
+
from: string | null;
|
|
141
|
+
to: string | null;
|
|
142
|
+
muted: boolean;
|
|
143
|
+
acceptedAt: number | null;
|
|
144
|
+
mediaKind: "audio" | "video";
|
|
145
|
+
remoteVideoEnabled: boolean;
|
|
146
|
+
};
|
|
147
|
+
interface SipState {
|
|
148
|
+
sipStatus: SipStatus;
|
|
149
|
+
error: string | null;
|
|
150
|
+
sessions: SipSessionState[];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
type Listener<T = any> = (payload: T) => void;
|
|
154
|
+
declare class EventTargetEmitter<Events extends Record<string, any> = any> {
|
|
155
|
+
private target;
|
|
156
|
+
on<K extends keyof Events>(event: K, fn: Listener<Events[K]>): () => void;
|
|
157
|
+
emit<K extends keyof Events>(event: K, payload?: Events[K]): void;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
interface SipErrorPayload {
|
|
161
|
+
cause: string;
|
|
162
|
+
code?: string;
|
|
163
|
+
raw?: any;
|
|
164
|
+
message?: string;
|
|
165
|
+
}
|
|
166
|
+
interface SipErrorFormatInput {
|
|
167
|
+
raw: any;
|
|
168
|
+
code?: string;
|
|
169
|
+
fallback?: string;
|
|
170
|
+
}
|
|
171
|
+
type SipErrorFormatter = (input: SipErrorFormatInput) => SipErrorPayload | undefined;
|
|
172
|
+
type SipErrorHandlerOptions = {
|
|
173
|
+
formatter?: SipErrorFormatter;
|
|
174
|
+
messages?: Record<string, string>;
|
|
175
|
+
};
|
|
176
|
+
declare class SipErrorHandler {
|
|
177
|
+
private readonly formatter?;
|
|
178
|
+
private readonly messages?;
|
|
179
|
+
constructor(options?: SipErrorHandlerOptions);
|
|
180
|
+
format(input: SipErrorFormatInput): SipErrorPayload;
|
|
181
|
+
private readRawMessage;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
type SipStateListener = (state: SipState) => void;
|
|
185
|
+
declare class SipStateStore {
|
|
186
|
+
private state;
|
|
187
|
+
private lastState;
|
|
188
|
+
private listeners;
|
|
189
|
+
private pendingState;
|
|
190
|
+
private updateScheduled;
|
|
191
|
+
getState(): SipState;
|
|
192
|
+
onChange(fn: SipStateListener): () => void;
|
|
193
|
+
subscribe(fn: SipStateListener): () => void;
|
|
194
|
+
setState(partial: Partial<SipState>): void;
|
|
195
|
+
batchSet(partial: Partial<SipState>): void;
|
|
196
|
+
reset(overrides?: Partial<SipState>): void;
|
|
197
|
+
private emit;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
type SipClientOptions = {
|
|
201
|
+
errorMessages?: Record<string, string>;
|
|
202
|
+
formatError?: SipErrorFormatter;
|
|
203
|
+
errorHandler?: SipErrorHandler;
|
|
204
|
+
debug?: boolean | string;
|
|
205
|
+
};
|
|
206
|
+
declare class SipClient extends EventTargetEmitter<JsSIPEventMap> {
|
|
207
|
+
readonly userAgent: SipUserAgent;
|
|
208
|
+
readonly stateStore: SipStateStore;
|
|
209
|
+
private readonly uaHandlers;
|
|
210
|
+
private readonly uaHandlerKeys;
|
|
211
|
+
private sessionHandlers;
|
|
212
|
+
private readonly errorHandler;
|
|
213
|
+
private debugPattern?;
|
|
214
|
+
private sessionManager;
|
|
215
|
+
private lifecycle;
|
|
216
|
+
get state(): SipState;
|
|
217
|
+
constructor(options?: SipClientOptions);
|
|
218
|
+
connect(uri: string, password: string, config: SipConfiguration): void;
|
|
219
|
+
registerUA(): void;
|
|
220
|
+
disconnect(): void;
|
|
221
|
+
call(target: string, callOptions?: CallOptions): void;
|
|
222
|
+
answer(options?: AnswerOptions): void;
|
|
223
|
+
hangup(options?: TerminateOptions): void;
|
|
224
|
+
mute(): void;
|
|
225
|
+
unmute(): void;
|
|
226
|
+
hold(): void;
|
|
227
|
+
unhold(): void;
|
|
228
|
+
sendDTMF(tones: string | number, options?: DTFMOptions): void;
|
|
229
|
+
transfer(target: string | RTCSession, options?: ReferOptions): void;
|
|
230
|
+
attendedTransfer(otherSession: RTCSession): void;
|
|
231
|
+
onChange(fn: (s: SipState) => void): () => void;
|
|
232
|
+
private attachUAHandlers;
|
|
233
|
+
setDebug(debug?: boolean | string): void;
|
|
234
|
+
private attachSessionHandlers;
|
|
235
|
+
private detachSessionHandlers;
|
|
236
|
+
private detachUAHandlers;
|
|
237
|
+
private cleanupSession;
|
|
238
|
+
private cleanupAllSessions;
|
|
239
|
+
private createSessionHandlersFor;
|
|
240
|
+
protected onNewRTCSession(e: RTCSessionEvent): void;
|
|
241
|
+
protected onSessionFailed(error?: string, event?: RTCSessionEvent): void;
|
|
242
|
+
private emitError;
|
|
243
|
+
private resolveSessionId;
|
|
244
|
+
answerSession(sessionIdOrOptions?: string | AnswerOptions, options?: AnswerOptions): boolean;
|
|
245
|
+
hangupSession(sessionIdOrOptions?: string | TerminateOptions, options?: TerminateOptions): boolean;
|
|
246
|
+
muteSession(sessionId?: string): boolean;
|
|
247
|
+
unmuteSession(sessionId?: string): boolean;
|
|
248
|
+
holdSession(sessionId?: string): boolean;
|
|
249
|
+
unholdSession(sessionId?: string): boolean;
|
|
250
|
+
sendDTMFSession(tones: string | number, options?: DTFMOptions, sessionId?: string): boolean;
|
|
251
|
+
transferSession(target: string | RTCSession, options?: ReferOptions, sessionId?: string): boolean;
|
|
252
|
+
attendedTransferSession(otherSession: RTCSession, sessionId?: string): boolean;
|
|
253
|
+
setSessionMedia(sessionId: string, stream: MediaStream): void;
|
|
254
|
+
switchCameraSession(sessionId: string, track: MediaStreamTrack): boolean;
|
|
255
|
+
startScreenShareSession(sessionId: string, getDisplayMedia: () => Promise<MediaStream>): Promise<boolean>;
|
|
256
|
+
enableVideoSession(sessionId: string): boolean;
|
|
257
|
+
disableVideoSession(sessionId: string): boolean;
|
|
258
|
+
getSession(sessionId: string): RTCSession | null;
|
|
259
|
+
getSessionIds(): string[];
|
|
260
|
+
getSessions(): {
|
|
261
|
+
id: string;
|
|
262
|
+
session: RTCSession;
|
|
263
|
+
}[];
|
|
264
|
+
}
|
|
265
|
+
declare function createSipClientInstance(options?: SipClientOptions): SipClient;
|
|
266
|
+
declare function createSipEventManager(client: SipClient): SipEventManager;
|
|
267
|
+
|
|
268
|
+
type SipContextType = {
|
|
269
|
+
client: SipClient;
|
|
270
|
+
sipEventManager: SipEventManager;
|
|
271
|
+
};
|
|
272
|
+
declare const SipContext: react.Context<SipContextType | null>;
|
|
273
|
+
|
|
274
|
+
declare function useSipState(): SipState;
|
|
275
|
+
|
|
276
|
+
declare function useSipActions(): {
|
|
277
|
+
call: (target: string, callOptions?: jssip_lib_UA.CallOptions | undefined) => void;
|
|
278
|
+
answer: (sessionIdOrOptions?: string | jssip_lib_RTCSession.AnswerOptions | undefined, options?: jssip_lib_RTCSession.AnswerOptions | undefined) => boolean;
|
|
279
|
+
hangup: (sessionIdOrOptions?: string | jssip_lib_RTCSession.TerminateOptions | undefined, options?: jssip_lib_RTCSession.TerminateOptions | undefined) => boolean;
|
|
280
|
+
mute: (sessionId?: string | undefined) => boolean;
|
|
281
|
+
unmute: (sessionId?: string | undefined) => boolean;
|
|
282
|
+
hold: (sessionId?: string | undefined) => boolean;
|
|
283
|
+
unhold: (sessionId?: string | undefined) => boolean;
|
|
284
|
+
sendDTMF: (tones: string | number, options?: jssip_lib_RTCSession.DTFMOptions | undefined, sessionId?: string | undefined) => boolean;
|
|
285
|
+
transfer: (target: string | jssip_lib_RTCSession.RTCSession, options?: jssip_lib_RTCSession.ReferOptions | undefined, sessionId?: string | undefined) => boolean;
|
|
286
|
+
attendedTransfer: (otherSession: jssip_lib_RTCSession.RTCSession, sessionId?: string | undefined) => boolean;
|
|
287
|
+
getSession: (sessionId: string) => jssip_lib_RTCSession.RTCSession | null;
|
|
288
|
+
getSessionIds: () => string[];
|
|
289
|
+
getSessions: () => {
|
|
290
|
+
id: string;
|
|
291
|
+
session: jssip_lib_RTCSession.RTCSession;
|
|
292
|
+
}[];
|
|
293
|
+
setSessionMedia: (sessionId: string, stream: MediaStream) => void;
|
|
294
|
+
switchCamera: (sessionId: string, track: MediaStreamTrack) => false | Promise<boolean>;
|
|
295
|
+
startScreenShare: (sessionId: string, getDisplayMedia: () => Promise<MediaStream>) => false | Promise<boolean>;
|
|
296
|
+
enableVideo: (sessionId: string) => boolean;
|
|
297
|
+
disableVideo: (sessionId: string) => boolean;
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
declare function useSip(): SipContextType;
|
|
301
|
+
|
|
302
|
+
declare function useSipSessions(): Pick<SipState, "sessions">;
|
|
303
|
+
|
|
304
|
+
type EventName = JsSIPEventName | "sessionCleanup";
|
|
305
|
+
declare function useSipEvent<K extends EventName>(event: K, handler?: JsSIPEventHandler<K>): void;
|
|
306
|
+
declare function useSipSessionEvent<K extends EventName>(sessionId: string | null | undefined, event: K, handler?: JsSIPEventHandler<K>): void;
|
|
307
|
+
|
|
308
|
+
declare function CallPlayer({ sessionId }: {
|
|
309
|
+
sessionId?: string;
|
|
310
|
+
}): react_jsx_runtime.JSX.Element;
|
|
311
|
+
|
|
312
|
+
declare function SipProvider({ client, children, sipEventManager, }: {
|
|
313
|
+
sipEventManager?: SipEventManager;
|
|
314
|
+
client: SipClient;
|
|
315
|
+
children: react__default.ReactNode;
|
|
316
|
+
}): react_jsx_runtime.JSX.Element;
|
|
317
|
+
|
|
318
|
+
export { CallDirection, CallDirection as CallDirectionType, CallPlayer, CallStatus, CallStatus as CallStatusType, SipContext, type SipContextType, SipProvider, type SipState, SipStatus, SipStatus as SipStatusType, createSipClientInstance, createSipEventManager, useSip, useSipActions, useSipEvent, useSipSessionEvent, useSipSessions, useSipState };
|