react-jssip-kit 0.7.8 → 1.0.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/dist/index.d.cts CHANGED
@@ -1,22 +1,50 @@
1
+ import { UA } from 'jssip';
2
+ export { WebSocketInterface } from 'jssip';
1
3
  import * as jssip_src_RTCSession from 'jssip/src/RTCSession';
2
- import { RTCSessionEventMap, Originator, AnswerOptions, TerminateOptions, DTMFOptions, ReferOptions, RTCSession } from 'jssip/src/RTCSession';
4
+ import { RTCSessionEventMap, TerminateOptions, AnswerOptions, DTMFOptions, ReferOptions, RTCSession } from 'jssip/src/RTCSession';
3
5
  export { AnswerOptions, DTMFOptions, RTCSession, RTCSessionEventMap, ReferOptions, TerminateOptions } from 'jssip/src/RTCSession';
4
6
  import * as jssip_src_UA from 'jssip/src/UA';
5
7
  import { UAEventMap, IncomingRTCSessionEvent, UAConfiguration, CallOptions, RTCSessionEvent } from 'jssip/src/UA';
6
8
  export { CallOptions } from 'jssip/src/UA';
7
- import { UA } from 'jssip';
8
- export { WebSocketInterface } from 'jssip';
9
- import * as react from 'react';
10
- import react__default from 'react';
11
9
  import * as react_jsx_runtime from 'react/jsx-runtime';
10
+ import React from 'react';
11
+
12
+ declare const SipStatus: {
13
+ readonly Disconnected: "disconnected";
14
+ readonly Connecting: "connecting";
15
+ readonly Connected: "connected";
16
+ readonly Registered: "registered";
17
+ readonly Unregistered: "unregistered";
18
+ readonly RegistrationFailed: "registrationFailed";
19
+ };
20
+ type SipStatus = (typeof SipStatus)[keyof typeof SipStatus];
21
+ declare const CallStatus: {
22
+ readonly Idle: "idle";
23
+ readonly Dialing: "dialing";
24
+ readonly Ringing: "ringing";
25
+ readonly Active: "active";
26
+ readonly Hold: "hold";
27
+ };
28
+ type CallStatus = (typeof CallStatus)[keyof typeof CallStatus];
29
+ type CallDirection = "local" | "remote";
30
+ type SipSessionState = {
31
+ id: string;
32
+ status: CallStatus;
33
+ direction: CallDirection | null;
34
+ from: string | null;
35
+ to: string | null;
36
+ muted: boolean;
37
+ acceptedAt: number | null;
38
+ };
39
+ interface SipState {
40
+ sipStatus: SipStatus;
41
+ error: string | null;
42
+ sessions: SipSessionState[];
43
+ sessionsById: Record<string, SipSessionState>;
44
+ sessionIds: string[];
45
+ }
12
46
 
13
47
  type UAExtraEvents = {
14
- error: {
15
- cause: string;
16
- code?: string;
17
- raw?: any;
18
- message?: string;
19
- };
20
48
  missed: IncomingRTCSessionEvent;
21
49
  };
22
50
  type UAEventName = keyof UAEventMap | keyof UAExtraEvents;
@@ -37,26 +65,12 @@ type JsSIPEventMap = {
37
65
  [K in JsSIPEventName]: JsSIPEventPayload<K>;
38
66
  };
39
67
  type SipConfiguration = Omit<UAConfiguration, "password" | "uri"> & {
40
- /**
41
- * Enable JsSIP debug logging. If string, treated as debug pattern.
42
- */
43
68
  debug?: boolean | string;
44
- /**
45
- * Enable automatic microphone recovery for sessions.
46
- */
47
69
  enableMicRecovery?: boolean;
48
- /**
49
- * Interval between recovery attempts in milliseconds.
50
- */
51
70
  micRecoveryIntervalMs?: number;
52
- /**
53
- * Maximum number of recovery attempts per session.
54
- */
55
71
  micRecoveryMaxRetries?: number;
56
- /**
57
- * Maximum allowed concurrent sessions. Additional sessions are rejected.
58
- */
59
72
  maxSessionCount?: number;
73
+ iceCandidateReadyDelayMs?: number;
60
74
  };
61
75
 
62
76
  type StartOpts = {
@@ -81,41 +95,6 @@ declare class SipUserAgent {
81
95
  private clearSessionFlag;
82
96
  }
83
97
 
84
- declare const SipStatus: {
85
- readonly Disconnected: "disconnected";
86
- readonly Connecting: "connecting";
87
- readonly Connected: "connected";
88
- readonly Registered: "registered";
89
- readonly Unregistered: "unregistered";
90
- readonly RegistrationFailed: "registrationFailed";
91
- };
92
- type SipStatus = (typeof SipStatus)[keyof typeof SipStatus];
93
- declare const CallStatus: {
94
- readonly Idle: "idle";
95
- readonly Dialing: "dialing";
96
- readonly Ringing: "ringing";
97
- readonly Active: "active";
98
- readonly Hold: "hold";
99
- };
100
- type CallStatus = (typeof CallStatus)[keyof typeof CallStatus];
101
- type CallDirection = Originator.LOCAL | Originator.REMOTE;
102
- type SipSessionState = {
103
- id: string;
104
- status: CallStatus;
105
- direction: CallDirection | null;
106
- from: string | null;
107
- to: string | null;
108
- muted: boolean;
109
- acceptedAt: number | null;
110
- mediaKind: "audio" | "video";
111
- remoteVideoEnabled: boolean;
112
- };
113
- interface SipState {
114
- sipStatus: SipStatus;
115
- error: string | null;
116
- sessions: SipSessionState[];
117
- }
118
-
119
98
  type Listener<T = any> = (payload: T) => void;
120
99
  declare class EventTargetEmitter<Events extends Record<string, any> = any> {
121
100
  private target;
@@ -123,30 +102,6 @@ declare class EventTargetEmitter<Events extends Record<string, any> = any> {
123
102
  emit<K extends keyof Events>(event: K, payload?: Events[K]): void;
124
103
  }
125
104
 
126
- interface SipErrorPayload {
127
- cause: string;
128
- code?: string;
129
- raw?: any;
130
- message?: string;
131
- }
132
- interface SipErrorFormatInput {
133
- raw: any;
134
- code?: string;
135
- fallback?: string;
136
- }
137
- type SipErrorFormatter = (input: SipErrorFormatInput) => SipErrorPayload | undefined;
138
- type SipErrorHandlerOptions = {
139
- formatter?: SipErrorFormatter;
140
- messages?: Record<string, string>;
141
- };
142
- declare class SipErrorHandler {
143
- private readonly formatter?;
144
- private readonly messages?;
145
- constructor(options?: SipErrorHandlerOptions);
146
- format(input: SipErrorFormatInput): SipErrorPayload;
147
- private readRawMessage;
148
- }
149
-
150
105
  type SipStateListener = (state: SipState) => void;
151
106
  declare class SipStateStore {
152
107
  private state;
@@ -163,55 +118,34 @@ declare class SipStateStore {
163
118
  private emit;
164
119
  }
165
120
 
121
+ declare function createSipEventManager(client: SipClient): SipEventManager;
122
+
166
123
  type SipClientOptions = {
167
- errorMessages?: Record<string, string>;
168
- formatError?: SipErrorFormatter;
169
- errorHandler?: SipErrorHandler;
170
124
  debug?: boolean | string;
171
125
  };
172
126
  declare class SipClient extends EventTargetEmitter<JsSIPEventMap> {
173
127
  readonly userAgent: SipUserAgent;
174
128
  readonly stateStore: SipStateStore;
175
- private readonly uaHandlers;
176
- private readonly uaHandlerKeys;
177
- private sessionHandlers;
178
- private readonly errorHandler;
129
+ private readonly uaModule;
179
130
  private debugPattern?;
180
131
  private maxSessionCount;
132
+ private iceCandidateReadyDelayMs?;
181
133
  private sessionManager;
182
- private lifecycle;
134
+ private sessionModule;
183
135
  private micRecovery;
184
- private unloadHandler?;
185
- private stateLogOff?;
136
+ private unloadRuntime;
137
+ private debugRuntime;
186
138
  get state(): SipState;
187
139
  constructor(options?: SipClientOptions);
188
140
  connect(uri: string, password: string, config: SipConfiguration): void;
189
141
  registerUA(): void;
190
142
  disconnect(): void;
191
143
  call(target: string, callOptions?: CallOptions): void;
192
- answer(sessionId: string, options?: AnswerOptions): boolean;
193
- hangup(sessionId: string, options?: TerminateOptions): boolean;
194
144
  hangupAll(options?: TerminateOptions): boolean;
195
- toggleMute(sessionId: string): boolean;
196
- toggleHold(sessionId: string): boolean;
197
- sendDTMF(sessionId: string, tones: string | number, options?: DTMFOptions): boolean;
198
- transfer(sessionId: string, target: string, options?: ReferOptions): boolean;
199
145
  onChange(fn: (s: SipState) => void): () => void;
200
- private attachUAHandlers;
201
146
  setDebug(debug?: boolean | string): void;
202
- private attachSessionHandlers;
203
- private detachSessionHandlers;
204
- private detachUAHandlers;
205
- private cleanupSession;
206
147
  private cleanupAllSessions;
207
- private createSessionHandlersFor;
208
148
  protected onNewRTCSession(e: RTCSessionEvent): void;
209
- protected onSessionFailed(error?: string, event?: RTCSessionEvent): void;
210
- private emitError;
211
- private resolveSessionId;
212
- private sessionExists;
213
- private resolveExistingSessionId;
214
- private ensureMediaConstraints;
215
149
  answerSession(sessionId: string, options?: AnswerOptions): boolean;
216
150
  hangupSession(sessionId: string, options?: TerminateOptions): boolean;
217
151
  toggleMuteSession(sessionId?: string): boolean;
@@ -219,41 +153,77 @@ declare class SipClient extends EventTargetEmitter<JsSIPEventMap> {
219
153
  sendDTMFSession(sessionId: string, tones: string | number, options?: DTMFOptions): boolean;
220
154
  transferSession(sessionId: string, target: string, options?: ReferOptions): boolean;
221
155
  setSessionMedia(sessionId: string, stream: MediaStream): void;
222
- switchCameraSession(sessionId: string, track: MediaStreamTrack): false | Promise<boolean>;
223
- enableVideoSession(sessionId: string): boolean;
224
- disableVideoSession(sessionId: string): boolean;
225
156
  getSession(sessionId: string): RTCSession | null;
226
157
  getSessionIds(): string[];
227
158
  getSessions(): {
228
159
  id: string;
229
160
  session: RTCSession;
230
161
  }[];
231
- private attachBeforeUnload;
232
- private detachBeforeUnload;
233
- private syncDebugInspector;
234
- private toggleStateLogger;
235
- private getPersistedDebug;
236
- private requestMicrophoneStreamInternal;
237
162
  }
238
163
  declare function createSipClientInstance(options?: SipClientOptions): SipClient;
239
- declare function createSipEventManager(client: SipClient): SipEventManager;
240
164
 
241
- type SipContextType = {
242
- client: SipClient;
243
- sipEventManager: SipEventManager;
165
+ type SessionMediaState = {
166
+ sessionId: string;
167
+ session: RTCSession | null;
168
+ peerConnection: RTCPeerConnection | null;
169
+ remoteStream: MediaStream | null;
170
+ audioTracks: MediaStreamTrack[];
244
171
  };
245
- declare const SipContext: react.Context<SipContextType | null>;
172
+ interface MediaModule {
173
+ getSession(sessionId: string): RTCSession | null;
174
+ observePeerConnection(sessionId: string, onPeerConnection: (peerConnection: RTCPeerConnection | null) => void): () => void;
175
+ buildRemoteStream(peerConnection: RTCPeerConnection | null): MediaStream | null;
176
+ }
177
+
178
+ interface SipKernel {
179
+ client: SipClient;
180
+ store: {
181
+ getState: () => SipState;
182
+ subscribe: (onStoreChange: () => void) => () => void;
183
+ };
184
+ commands: {
185
+ connect: (uri: string, password: string, config: SipConfiguration) => void;
186
+ disconnect: () => void;
187
+ register: () => void;
188
+ setDebug: (debug?: boolean | string) => void;
189
+ call: (target: string, options?: CallOptions) => void;
190
+ answer: (sessionId: string, options?: AnswerOptions) => boolean;
191
+ hangup: (sessionId: string, options?: TerminateOptions) => boolean;
192
+ hangupAll: (options?: TerminateOptions) => boolean;
193
+ toggleMute: (sessionId?: string) => boolean;
194
+ toggleHold: (sessionId?: string) => boolean;
195
+ sendDTMF: (sessionId: string, tones: string | number, options?: DTMFOptions) => boolean;
196
+ transfer: (sessionId: string, target: string, options?: ReferOptions) => boolean;
197
+ getSession: SipClient["getSession"];
198
+ getSessionIds: SipClient["getSessionIds"];
199
+ getSessions: SipClient["getSessions"];
200
+ setSessionMedia: SipClient["setSessionMedia"];
201
+ };
202
+ events: {
203
+ onUA: <K extends UAEventName>(event: K, handler: (payload?: UAEventPayload<K>) => void) => () => void;
204
+ onSession: <K extends SessionEventName>(sessionId: string, event: K, handler: (payload?: SessionEventPayload<K>) => void) => () => void;
205
+ };
206
+ eventManager: SipEventManager;
207
+ media: MediaModule;
208
+ }
209
+
210
+ declare function createSipKernel(): SipKernel;
246
211
 
247
212
  declare function useSipState(): SipState;
248
213
 
249
214
  declare function useSipActions(): {
250
- call: (target: string, callOptions?: jssip_src_UA.CallOptions | undefined) => void;
251
- answer: (sessionId: string, options?: jssip_src_RTCSession.AnswerOptions | undefined) => boolean;
252
- hangup: (sessionId: string, options?: jssip_src_RTCSession.TerminateOptions | undefined) => boolean;
253
- toggleMute: (sessionId?: string | undefined) => boolean;
254
- toggleHold: (sessionId?: string | undefined) => boolean;
255
- sendDTMF: (sessionId: string, tones: string | number, options?: jssip_src_RTCSession.DTMFOptions | undefined) => boolean;
256
- transfer: (sessionId: string, target: string, options?: jssip_src_RTCSession.ReferOptions | undefined) => boolean;
215
+ connect: (uri: string, password: string, config: SipConfiguration) => void;
216
+ disconnect: () => void;
217
+ register: () => void;
218
+ setDebug: (debug?: boolean | string) => void;
219
+ call: (target: string, options?: jssip_src_UA.CallOptions) => void;
220
+ answer: (sessionId: string, options?: jssip_src_RTCSession.AnswerOptions) => boolean;
221
+ hangup: (sessionId: string, options?: jssip_src_RTCSession.TerminateOptions) => boolean;
222
+ hangupAll: (options?: jssip_src_RTCSession.TerminateOptions) => boolean;
223
+ toggleMute: (sessionId?: string) => boolean;
224
+ toggleHold: (sessionId?: string) => boolean;
225
+ sendDTMF: (sessionId: string, tones: string | number, options?: jssip_src_RTCSession.DTMFOptions) => boolean;
226
+ transfer: (sessionId: string, target: string, options?: jssip_src_RTCSession.ReferOptions) => boolean;
257
227
  getSession: (sessionId: string) => jssip_src_RTCSession.RTCSession | null;
258
228
  getSessionIds: () => string[];
259
229
  getSessions: () => {
@@ -261,26 +231,33 @@ declare function useSipActions(): {
261
231
  session: jssip_src_RTCSession.RTCSession;
262
232
  }[];
263
233
  setSessionMedia: (sessionId: string, stream: MediaStream) => void;
264
- switchCamera: (sessionId: string, track: MediaStreamTrack) => false | Promise<boolean>;
265
- enableVideo: (sessionId: string) => boolean;
266
- disableVideo: (sessionId: string) => boolean;
267
234
  };
268
235
 
269
- declare function useSip(): SipContextType;
236
+ declare function useSipKernel(): SipKernel;
237
+
238
+ type SipSelector<TSelected> = (state: SipState) => TSelected;
239
+ type SipSelectorEqualityFn<TSelected> = (prev: TSelected, next: TSelected) => boolean;
240
+ declare function useSipSelector<TSelected>(selector: SipSelector<TSelected>, equalityFn?: SipSelectorEqualityFn<TSelected>): TSelected;
241
+
242
+ declare function useActiveSipSession(): SipSessionState | null;
243
+
244
+ declare function useSipSession(sessionId?: string): SipSessionState | null;
270
245
 
271
246
  declare function useSipSessions(): Pick<SipState, "sessions">;
272
247
 
273
248
  declare function useSipEvent<K extends UAEventName>(event: K, handler?: (payload?: UAEventPayload<K>) => void): void;
274
249
  declare function useSipSessionEvent<K extends SessionEventName>(sessionId: string, event: K, handler?: (payload?: SessionEventPayload<K>) => void): void;
275
250
 
251
+ declare function useSessionMedia(sessionId?: string): SessionMediaState;
252
+
276
253
  declare function CallPlayer({ sessionId }: {
277
254
  sessionId?: string;
278
255
  }): react_jsx_runtime.JSX.Element;
279
256
 
280
- declare function SipProvider({ client, children, sipEventManager, }: {
281
- sipEventManager?: SipEventManager;
282
- client: SipClient;
283
- children: react__default.ReactNode;
284
- }): react_jsx_runtime.JSX.Element;
257
+ type SipProviderProps = {
258
+ kernel: SipKernel;
259
+ children: React.ReactNode;
260
+ };
261
+ declare function SipProvider(props: SipProviderProps): react_jsx_runtime.JSX.Element;
285
262
 
286
- export { type CallDirection, type CallDirection as CallDirectionType, CallPlayer, CallStatus, CallStatus as CallStatusType, type JsSIPEventMap, type JsSIPEventName, type SessionEventName, type SessionEventPayload, type SipConfiguration, SipContext, type SipContextType, type SipEventHandlers, type SipEventManager, SipProvider, type SipSessionState, type SipState, SipStatus, SipStatus as SipStatusType, type UAEventName, type UAEventPayload, createSipClientInstance, createSipEventManager, useSip, useSipActions, useSipEvent, useSipSessionEvent, useSipSessions, useSipState };
263
+ export { type CallDirection, type CallDirection as CallDirectionType, CallPlayer, CallStatus, CallStatus as CallStatusType, type JsSIPEventMap, type JsSIPEventName, type SessionEventName, type SessionEventPayload, type SipConfiguration, type SipEventHandlers, type SipEventManager, type SipKernel, SipProvider, type SipProviderProps, type SipSessionState, type SipState, SipStatus, SipStatus as SipStatusType, type UAEventName, type UAEventPayload, createSipClientInstance, createSipEventManager, createSipKernel, useActiveSipSession, useSessionMedia, useSipActions, useSipEvent, useSipKernel, useSipSelector, useSipSession, useSipSessionEvent, useSipSessions, useSipState };