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/CHANGELOG.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
- Breaking: public client control methods now require an explicit `sessionId` as the first argument (`answer`, `hangup`, mute/hold toggles, DTMF/transfer helpers).
|
|
5
5
|
- Added exports for client-facing types (events, options, RTCSession/UA maps) from the package entrypoint for easier consumption.
|
|
6
6
|
- Allow setting media on a session id before the session object is attached to retain pending streams.
|
|
7
|
-
- When debug is enabled, expose `window.sipState()` and `window.sipSessions()` helpers for quick inspection.
|
|
7
|
+
- When debug is enabled, expose `window.sipState()` and `window.sipSessions()` helpers for quick inspection (stubbed safely when disabled).
|
|
8
8
|
|
|
9
9
|
## 0.1.1
|
|
10
10
|
- Exported `SipSessionState` from the public entrypoint and aligned demo/imports to the new package name.
|
package/dist/index.cjs
CHANGED
|
@@ -8,7 +8,118 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
8
8
|
|
|
9
9
|
var JsSIP__default = /*#__PURE__*/_interopDefault(JsSIP);
|
|
10
10
|
|
|
11
|
-
// src/jssip-lib/sip/
|
|
11
|
+
// src/jssip-lib/sip/debugger.ts
|
|
12
|
+
var SipDebugger = class {
|
|
13
|
+
constructor(storageKey = "sip-debug-enabled", defaultPattern = "JsSIP:*") {
|
|
14
|
+
this.enabled = false;
|
|
15
|
+
this.storageKey = storageKey;
|
|
16
|
+
this.defaultPattern = defaultPattern;
|
|
17
|
+
}
|
|
18
|
+
initFromSession(storage = safeSessionStorage()) {
|
|
19
|
+
try {
|
|
20
|
+
const saved = storage?.getItem(this.storageKey);
|
|
21
|
+
if (saved) {
|
|
22
|
+
this.enable(saved === "true" ? this.defaultPattern : saved, storage);
|
|
23
|
+
}
|
|
24
|
+
} catch {
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
enable(pattern = this.defaultPattern, storage = safeSessionStorage()) {
|
|
28
|
+
try {
|
|
29
|
+
if (typeof JsSIP__default.default?.debug?.enable === "function") {
|
|
30
|
+
JsSIP__default.default.debug.enable(pattern);
|
|
31
|
+
this.logger = console;
|
|
32
|
+
}
|
|
33
|
+
storage?.setItem?.(this.storageKey, pattern || "true");
|
|
34
|
+
try {
|
|
35
|
+
window.sipDebugBridge?.(pattern);
|
|
36
|
+
} catch {
|
|
37
|
+
}
|
|
38
|
+
this.enabled = true;
|
|
39
|
+
} catch {
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
disable(storage = safeSessionStorage()) {
|
|
43
|
+
try {
|
|
44
|
+
if (typeof JsSIP__default.default?.debug?.disable === "function") {
|
|
45
|
+
JsSIP__default.default.debug.disable();
|
|
46
|
+
} else if (typeof JsSIP__default.default?.debug?.enable === "function") {
|
|
47
|
+
JsSIP__default.default.debug.enable("");
|
|
48
|
+
}
|
|
49
|
+
storage?.removeItem?.(this.storageKey);
|
|
50
|
+
try {
|
|
51
|
+
window.sipDebugBridge?.(false);
|
|
52
|
+
} catch {
|
|
53
|
+
}
|
|
54
|
+
this.enabled = false;
|
|
55
|
+
} catch {
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
toggle(pattern = this.defaultPattern, storage = safeSessionStorage()) {
|
|
59
|
+
if (this.isEnabled()) {
|
|
60
|
+
this.disable(storage);
|
|
61
|
+
} else {
|
|
62
|
+
this.enable(pattern, storage);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
isEnabled() {
|
|
66
|
+
return this.enabled;
|
|
67
|
+
}
|
|
68
|
+
attachToWindow(win = window) {
|
|
69
|
+
const api = {
|
|
70
|
+
enableDebug: () => {
|
|
71
|
+
this.enable();
|
|
72
|
+
return { debug: this.isEnabled(), text: "press F5" };
|
|
73
|
+
},
|
|
74
|
+
disableDebug: () => {
|
|
75
|
+
this.disable();
|
|
76
|
+
return { debug: this.isEnabled(), text: "press F5" };
|
|
77
|
+
},
|
|
78
|
+
toggleDebug: () => {
|
|
79
|
+
this.toggle();
|
|
80
|
+
return { debug: this.isEnabled(), text: "press F5" };
|
|
81
|
+
},
|
|
82
|
+
debugState: () => ({
|
|
83
|
+
debug: this.isEnabled(),
|
|
84
|
+
text: this.isEnabled() ? "enabled" : "disabled"
|
|
85
|
+
}),
|
|
86
|
+
sipState: () => {
|
|
87
|
+
try {
|
|
88
|
+
const getter = win.sipState;
|
|
89
|
+
return typeof getter === "function" ? getter() : "sipState helper not available; ensure client debug is enabled";
|
|
90
|
+
} catch {
|
|
91
|
+
return "sipState helper not available";
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
sipSessions: () => {
|
|
95
|
+
try {
|
|
96
|
+
const getter = win.sipSessions;
|
|
97
|
+
return typeof getter === "function" ? getter() : "sipSessions helper not available; ensure client debug is enabled";
|
|
98
|
+
} catch {
|
|
99
|
+
return "sipSessions helper not available";
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
try {
|
|
104
|
+
win.sipSupport = api;
|
|
105
|
+
} catch {
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
function safeSessionStorage() {
|
|
110
|
+
if (typeof window === "undefined")
|
|
111
|
+
return null;
|
|
112
|
+
try {
|
|
113
|
+
return window.sessionStorage;
|
|
114
|
+
} catch {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
var sipDebugger = new SipDebugger();
|
|
119
|
+
if (typeof window !== "undefined") {
|
|
120
|
+
sipDebugger.attachToWindow();
|
|
121
|
+
sipDebugger.initFromSession();
|
|
122
|
+
}
|
|
12
123
|
var SipUserAgent = class {
|
|
13
124
|
constructor() {
|
|
14
125
|
this._ua = null;
|
|
@@ -774,6 +885,7 @@ var SessionLifecycle = class {
|
|
|
774
885
|
};
|
|
775
886
|
|
|
776
887
|
// src/jssip-lib/sip/client.ts
|
|
888
|
+
var SESSION_DEBUG_KEY = "sip-debug-enabled";
|
|
777
889
|
var SipClient = class extends EventTargetEmitter {
|
|
778
890
|
constructor(options = {}) {
|
|
779
891
|
super();
|
|
@@ -803,6 +915,9 @@ var SipClient = class extends EventTargetEmitter {
|
|
|
803
915
|
attachSessionHandlers: (sessionId, session) => this.attachSessionHandlers(sessionId, session),
|
|
804
916
|
getMaxSessionCount: () => this.maxSessionCount
|
|
805
917
|
});
|
|
918
|
+
if (typeof window !== "undefined") {
|
|
919
|
+
window.sipDebugBridge = (debug) => this.setDebug(debug ?? true);
|
|
920
|
+
}
|
|
806
921
|
}
|
|
807
922
|
get state() {
|
|
808
923
|
return this.stateStore.getState();
|
|
@@ -818,7 +933,7 @@ var SipClient = class extends EventTargetEmitter {
|
|
|
818
933
|
} = config;
|
|
819
934
|
this.maxSessionCount = typeof maxSessionCount === "number" ? maxSessionCount : Infinity;
|
|
820
935
|
this.sessionManager.setPendingMediaTtl(pendingMediaTtlMs);
|
|
821
|
-
const debug = this.
|
|
936
|
+
const debug = cfgDebug ?? this.getPersistedDebug() ?? this.debugPattern;
|
|
822
937
|
this.userAgent.start(uri, password, uaCfg, { debug });
|
|
823
938
|
this.attachUAHandlers();
|
|
824
939
|
this.attachBeforeUnload();
|
|
@@ -1120,18 +1235,55 @@ var SipClient = class extends EventTargetEmitter {
|
|
|
1120
1235
|
syncDebugInspector(debug) {
|
|
1121
1236
|
if (typeof window === "undefined")
|
|
1122
1237
|
return;
|
|
1123
|
-
|
|
1238
|
+
this.toggleStateLogger(Boolean(debug));
|
|
1124
1239
|
const win = window;
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
}
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1240
|
+
const disabledInspector = () => {
|
|
1241
|
+
console.warn("SIP debug inspector disabled; enable debug to inspect.");
|
|
1242
|
+
return null;
|
|
1243
|
+
};
|
|
1244
|
+
win.sipState = () => debug ? this.stateStore.getState() : disabledInspector();
|
|
1245
|
+
win.sipSessions = () => debug ? this.getSessions() : disabledInspector();
|
|
1246
|
+
}
|
|
1247
|
+
toggleStateLogger(enabled) {
|
|
1248
|
+
if (!enabled) {
|
|
1249
|
+
this.stateLogOff?.();
|
|
1250
|
+
this.stateLogOff = void 0;
|
|
1251
|
+
return;
|
|
1252
|
+
}
|
|
1253
|
+
if (this.stateLogOff)
|
|
1254
|
+
return;
|
|
1255
|
+
let prev = this.stateStore.getState();
|
|
1256
|
+
console.info("[sip][state]", { initial: true }, prev);
|
|
1257
|
+
this.stateLogOff = this.stateStore.onChange((next) => {
|
|
1258
|
+
const changes = this.diffState(prev, next);
|
|
1259
|
+
if (changes) {
|
|
1260
|
+
console.info("[sip][state]", changes, next);
|
|
1261
|
+
}
|
|
1262
|
+
prev = next;
|
|
1263
|
+
});
|
|
1264
|
+
}
|
|
1265
|
+
diffState(prev, next) {
|
|
1266
|
+
const changed = {};
|
|
1267
|
+
for (const key of Object.keys(next)) {
|
|
1268
|
+
if (prev[key] !== next[key]) {
|
|
1269
|
+
changed[key] = { from: prev[key], to: next[key] };
|
|
1133
1270
|
}
|
|
1134
1271
|
}
|
|
1272
|
+
return Object.keys(changed).length ? changed : null;
|
|
1273
|
+
}
|
|
1274
|
+
getPersistedDebug() {
|
|
1275
|
+
if (typeof window === "undefined")
|
|
1276
|
+
return void 0;
|
|
1277
|
+
try {
|
|
1278
|
+
const persisted = window.sessionStorage.getItem(SESSION_DEBUG_KEY);
|
|
1279
|
+
if (!persisted)
|
|
1280
|
+
return void 0;
|
|
1281
|
+
if (persisted === "true")
|
|
1282
|
+
return true;
|
|
1283
|
+
return persisted;
|
|
1284
|
+
} catch {
|
|
1285
|
+
return void 0;
|
|
1286
|
+
}
|
|
1135
1287
|
}
|
|
1136
1288
|
};
|
|
1137
1289
|
function createSipClientInstance(options) {
|