react-jssip-kit 0.4.0 → 0.4.2
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 +1 -1
- package/dist/index.cjs +163 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +163 -11
- package/dist/index.js.map +1 -1
- package/package.json +5 -2
package/dist/index.js
CHANGED
|
@@ -3,7 +3,118 @@ export { WebSocketInterface } from 'jssip';
|
|
|
3
3
|
import { createContext, useContext, useCallback, useSyncExternalStore, useMemo, useEffect, useRef } from 'react';
|
|
4
4
|
import { jsx } from 'react/jsx-runtime';
|
|
5
5
|
|
|
6
|
-
// src/jssip-lib/sip/
|
|
6
|
+
// src/jssip-lib/sip/debugger.ts
|
|
7
|
+
var SipDebugger = class {
|
|
8
|
+
constructor(storageKey = "sip-debug-enabled", defaultPattern = "JsSIP:*") {
|
|
9
|
+
this.enabled = false;
|
|
10
|
+
this.storageKey = storageKey;
|
|
11
|
+
this.defaultPattern = defaultPattern;
|
|
12
|
+
}
|
|
13
|
+
initFromSession(storage = safeSessionStorage()) {
|
|
14
|
+
try {
|
|
15
|
+
const saved = storage?.getItem(this.storageKey);
|
|
16
|
+
if (saved) {
|
|
17
|
+
this.enable(saved === "true" ? this.defaultPattern : saved, storage);
|
|
18
|
+
}
|
|
19
|
+
} catch {
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
enable(pattern = this.defaultPattern, storage = safeSessionStorage()) {
|
|
23
|
+
try {
|
|
24
|
+
if (typeof JsSIP?.debug?.enable === "function") {
|
|
25
|
+
JsSIP.debug.enable(pattern);
|
|
26
|
+
this.logger = console;
|
|
27
|
+
}
|
|
28
|
+
storage?.setItem?.(this.storageKey, pattern || "true");
|
|
29
|
+
try {
|
|
30
|
+
window.sipDebugBridge?.(pattern);
|
|
31
|
+
} catch {
|
|
32
|
+
}
|
|
33
|
+
this.enabled = true;
|
|
34
|
+
} catch {
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
disable(storage = safeSessionStorage()) {
|
|
38
|
+
try {
|
|
39
|
+
if (typeof JsSIP?.debug?.disable === "function") {
|
|
40
|
+
JsSIP.debug.disable();
|
|
41
|
+
} else if (typeof JsSIP?.debug?.enable === "function") {
|
|
42
|
+
JsSIP.debug.enable("");
|
|
43
|
+
}
|
|
44
|
+
storage?.removeItem?.(this.storageKey);
|
|
45
|
+
try {
|
|
46
|
+
window.sipDebugBridge?.(false);
|
|
47
|
+
} catch {
|
|
48
|
+
}
|
|
49
|
+
this.enabled = false;
|
|
50
|
+
} catch {
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
toggle(pattern = this.defaultPattern, storage = safeSessionStorage()) {
|
|
54
|
+
if (this.isEnabled()) {
|
|
55
|
+
this.disable(storage);
|
|
56
|
+
} else {
|
|
57
|
+
this.enable(pattern, storage);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
isEnabled() {
|
|
61
|
+
return this.enabled;
|
|
62
|
+
}
|
|
63
|
+
attachToWindow(win = window) {
|
|
64
|
+
const api = {
|
|
65
|
+
enableDebug: () => {
|
|
66
|
+
this.enable();
|
|
67
|
+
return { debug: this.isEnabled(), text: "press F5" };
|
|
68
|
+
},
|
|
69
|
+
disableDebug: () => {
|
|
70
|
+
this.disable();
|
|
71
|
+
return { debug: this.isEnabled(), text: "press F5" };
|
|
72
|
+
},
|
|
73
|
+
toggleDebug: () => {
|
|
74
|
+
this.toggle();
|
|
75
|
+
return { debug: this.isEnabled(), text: "press F5" };
|
|
76
|
+
},
|
|
77
|
+
debugState: () => ({
|
|
78
|
+
debug: this.isEnabled(),
|
|
79
|
+
text: this.isEnabled() ? "enabled" : "disabled"
|
|
80
|
+
}),
|
|
81
|
+
sipState: () => {
|
|
82
|
+
try {
|
|
83
|
+
const getter = win.sipState;
|
|
84
|
+
return typeof getter === "function" ? getter() : "sipState helper not available; ensure client debug is enabled";
|
|
85
|
+
} catch {
|
|
86
|
+
return "sipState helper not available";
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
sipSessions: () => {
|
|
90
|
+
try {
|
|
91
|
+
const getter = win.sipSessions;
|
|
92
|
+
return typeof getter === "function" ? getter() : "sipSessions helper not available; ensure client debug is enabled";
|
|
93
|
+
} catch {
|
|
94
|
+
return "sipSessions helper not available";
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
try {
|
|
99
|
+
win.sipSupport = api;
|
|
100
|
+
} catch {
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
function safeSessionStorage() {
|
|
105
|
+
if (typeof window === "undefined")
|
|
106
|
+
return null;
|
|
107
|
+
try {
|
|
108
|
+
return window.sessionStorage;
|
|
109
|
+
} catch {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
var sipDebugger = new SipDebugger();
|
|
114
|
+
if (typeof window !== "undefined") {
|
|
115
|
+
sipDebugger.attachToWindow();
|
|
116
|
+
sipDebugger.initFromSession();
|
|
117
|
+
}
|
|
7
118
|
var SipUserAgent = class {
|
|
8
119
|
constructor() {
|
|
9
120
|
this._ua = null;
|
|
@@ -769,6 +880,7 @@ var SessionLifecycle = class {
|
|
|
769
880
|
};
|
|
770
881
|
|
|
771
882
|
// src/jssip-lib/sip/client.ts
|
|
883
|
+
var SESSION_DEBUG_KEY = "sip-debug-enabled";
|
|
772
884
|
var SipClient = class extends EventTargetEmitter {
|
|
773
885
|
constructor(options = {}) {
|
|
774
886
|
super();
|
|
@@ -798,6 +910,9 @@ var SipClient = class extends EventTargetEmitter {
|
|
|
798
910
|
attachSessionHandlers: (sessionId, session) => this.attachSessionHandlers(sessionId, session),
|
|
799
911
|
getMaxSessionCount: () => this.maxSessionCount
|
|
800
912
|
});
|
|
913
|
+
if (typeof window !== "undefined") {
|
|
914
|
+
window.sipDebugBridge = (debug) => this.setDebug(debug ?? true);
|
|
915
|
+
}
|
|
801
916
|
}
|
|
802
917
|
get state() {
|
|
803
918
|
return this.stateStore.getState();
|
|
@@ -813,7 +928,7 @@ var SipClient = class extends EventTargetEmitter {
|
|
|
813
928
|
} = config;
|
|
814
929
|
this.maxSessionCount = typeof maxSessionCount === "number" ? maxSessionCount : Infinity;
|
|
815
930
|
this.sessionManager.setPendingMediaTtl(pendingMediaTtlMs);
|
|
816
|
-
const debug = this.
|
|
931
|
+
const debug = cfgDebug ?? this.getPersistedDebug() ?? this.debugPattern;
|
|
817
932
|
this.userAgent.start(uri, password, uaCfg, { debug });
|
|
818
933
|
this.attachUAHandlers();
|
|
819
934
|
this.attachBeforeUnload();
|
|
@@ -1115,18 +1230,55 @@ var SipClient = class extends EventTargetEmitter {
|
|
|
1115
1230
|
syncDebugInspector(debug) {
|
|
1116
1231
|
if (typeof window === "undefined")
|
|
1117
1232
|
return;
|
|
1118
|
-
|
|
1233
|
+
this.toggleStateLogger(Boolean(debug));
|
|
1119
1234
|
const win = window;
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
}
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1235
|
+
const disabledInspector = () => {
|
|
1236
|
+
console.warn("SIP debug inspector disabled; enable debug to inspect.");
|
|
1237
|
+
return null;
|
|
1238
|
+
};
|
|
1239
|
+
win.sipState = () => debug ? this.stateStore.getState() : disabledInspector();
|
|
1240
|
+
win.sipSessions = () => debug ? this.getSessions() : disabledInspector();
|
|
1241
|
+
}
|
|
1242
|
+
toggleStateLogger(enabled) {
|
|
1243
|
+
if (!enabled) {
|
|
1244
|
+
this.stateLogOff?.();
|
|
1245
|
+
this.stateLogOff = void 0;
|
|
1246
|
+
return;
|
|
1247
|
+
}
|
|
1248
|
+
if (this.stateLogOff)
|
|
1249
|
+
return;
|
|
1250
|
+
let prev = this.stateStore.getState();
|
|
1251
|
+
console.info("[sip][state]", { initial: true }, prev);
|
|
1252
|
+
this.stateLogOff = this.stateStore.onChange((next) => {
|
|
1253
|
+
const changes = this.diffState(prev, next);
|
|
1254
|
+
if (changes) {
|
|
1255
|
+
console.info("[sip][state]", changes, next);
|
|
1256
|
+
}
|
|
1257
|
+
prev = next;
|
|
1258
|
+
});
|
|
1259
|
+
}
|
|
1260
|
+
diffState(prev, next) {
|
|
1261
|
+
const changed = {};
|
|
1262
|
+
for (const key of Object.keys(next)) {
|
|
1263
|
+
if (prev[key] !== next[key]) {
|
|
1264
|
+
changed[key] = { from: prev[key], to: next[key] };
|
|
1128
1265
|
}
|
|
1129
1266
|
}
|
|
1267
|
+
return Object.keys(changed).length ? changed : null;
|
|
1268
|
+
}
|
|
1269
|
+
getPersistedDebug() {
|
|
1270
|
+
if (typeof window === "undefined")
|
|
1271
|
+
return void 0;
|
|
1272
|
+
try {
|
|
1273
|
+
const persisted = window.sessionStorage.getItem(SESSION_DEBUG_KEY);
|
|
1274
|
+
if (!persisted)
|
|
1275
|
+
return void 0;
|
|
1276
|
+
if (persisted === "true")
|
|
1277
|
+
return true;
|
|
1278
|
+
return persisted;
|
|
1279
|
+
} catch {
|
|
1280
|
+
return void 0;
|
|
1281
|
+
}
|
|
1130
1282
|
}
|
|
1131
1283
|
};
|
|
1132
1284
|
function createSipClientInstance(options) {
|