react-jssip-kit 0.3.1 → 0.4.1

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.0
4
+ - Breaking: public client control methods now require an explicit `sessionId` as the first argument (`answer`, `hangup`, mute/hold toggles, DTMF/transfer helpers).
5
+ - Added exports for client-facing types (events, options, RTCSession/UA maps) from the package entrypoint for easier consumption.
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 (stubbed safely when disabled).
8
+
3
9
  ## 0.1.1
4
10
  - Exported `SipSessionState` from the public entrypoint and aligned demo/imports to the new package name.
5
11
 
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/userAgent.ts
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;
@@ -717,10 +828,6 @@ var SessionManager = class {
717
828
  const rtc = this.getRtc(sessionId);
718
829
  return rtc ? rtc.attendedTransfer(otherSession) : false;
719
830
  }
720
- startScreenShare(sessionId, getDisplayMedia) {
721
- const rtc = this.getRtc(sessionId);
722
- return rtc ? rtc.startScreenShare(getDisplayMedia) : false;
723
- }
724
831
  };
725
832
 
726
833
  // src/jssip-lib/sip/sessionLifecycle.ts
@@ -778,6 +885,7 @@ var SessionLifecycle = class {
778
885
  };
779
886
 
780
887
  // src/jssip-lib/sip/client.ts
888
+ var SESSION_DEBUG_KEY = "sip-debug-enabled";
781
889
  var SipClient = class extends EventTargetEmitter {
782
890
  constructor(options = {}) {
783
891
  super();
@@ -807,6 +915,9 @@ var SipClient = class extends EventTargetEmitter {
807
915
  attachSessionHandlers: (sessionId, session) => this.attachSessionHandlers(sessionId, session),
808
916
  getMaxSessionCount: () => this.maxSessionCount
809
917
  });
918
+ if (typeof window !== "undefined") {
919
+ window.sipDebugBridge = (debug) => this.setDebug(debug ?? true);
920
+ }
810
921
  }
811
922
  get state() {
812
923
  return this.stateStore.getState();
@@ -814,13 +925,19 @@ var SipClient = class extends EventTargetEmitter {
814
925
  connect(uri, password, config) {
815
926
  this.disconnect();
816
927
  this.stateStore.setState({ sipStatus: SipStatus.Connecting });
817
- const { debug: cfgDebug, maxSessionCount, pendingMediaTtlMs, ...uaCfg } = config;
928
+ const {
929
+ debug: cfgDebug,
930
+ maxSessionCount,
931
+ pendingMediaTtlMs,
932
+ ...uaCfg
933
+ } = config;
818
934
  this.maxSessionCount = typeof maxSessionCount === "number" ? maxSessionCount : Infinity;
819
935
  this.sessionManager.setPendingMediaTtl(pendingMediaTtlMs);
820
- const debug = this.debugPattern ?? cfgDebug;
936
+ const debug = cfgDebug ?? this.getPersistedDebug() ?? this.debugPattern;
821
937
  this.userAgent.start(uri, password, uaCfg, { debug });
822
938
  this.attachUAHandlers();
823
939
  this.attachBeforeUnload();
940
+ this.syncDebugInspector(debug);
824
941
  }
825
942
  registerUA() {
826
943
  this.userAgent.register();
@@ -847,11 +964,11 @@ var SipClient = class extends EventTargetEmitter {
847
964
  });
848
965
  }
849
966
  }
850
- answer(options = {}) {
851
- const sessionId = this.resolveExistingSessionId();
852
- if (!sessionId)
967
+ answer(sessionId, options = {}) {
968
+ const resolved = this.resolveExistingSessionId(sessionId);
969
+ if (!resolved)
853
970
  return false;
854
- return this.answerSession(sessionId, options);
971
+ return this.answerSession(resolved, options);
855
972
  }
856
973
  hangup(sessionId, options) {
857
974
  const resolved = this.resolveExistingSessionId(sessionId);
@@ -864,21 +981,20 @@ var SipClient = class extends EventTargetEmitter {
864
981
  ids.forEach((id) => this.hangupSession(id, options));
865
982
  return ids.length > 0;
866
983
  }
867
- toggleMute() {
868
- return this.toggleMuteSession();
984
+ toggleMute(sessionId) {
985
+ return this.toggleMuteSession(sessionId);
869
986
  }
870
- toggleHold() {
871
- return this.toggleHoldSession();
987
+ toggleHold(sessionId) {
988
+ return this.toggleHoldSession(sessionId);
872
989
  }
873
- sendDTMF(tones, options) {
874
- const sessionId = this.resolveExistingSessionId();
875
- return this.sendDTMFSession(tones, options, sessionId ?? void 0);
990
+ sendDTMF(sessionId, tones, options) {
991
+ return this.sendDTMFSession(sessionId, tones, options);
876
992
  }
877
- transfer(target, options) {
878
- return this.transferSession(target, options);
993
+ transfer(sessionId, target, options) {
994
+ return this.transferSession(sessionId, target, options);
879
995
  }
880
- attendedTransfer(otherSession) {
881
- return this.attendedTransferSession(otherSession);
996
+ attendedTransfer(sessionId, otherSession) {
997
+ return this.attendedTransferSession(sessionId, otherSession);
882
998
  }
883
999
  onChange(fn) {
884
1000
  return this.stateStore.onChange(fn);
@@ -897,6 +1013,7 @@ var SipClient = class extends EventTargetEmitter {
897
1013
  setDebug(debug) {
898
1014
  this.debugPattern = debug;
899
1015
  this.userAgent.setDebug(debug);
1016
+ this.syncDebugInspector(debug);
900
1017
  }
901
1018
  attachSessionHandlers(sessionId, session) {
902
1019
  const handlers = this.createSessionHandlersFor(sessionId, session);
@@ -1040,7 +1157,7 @@ var SipClient = class extends EventTargetEmitter {
1040
1157
  }
1041
1158
  return true;
1042
1159
  }
1043
- sendDTMFSession(tones, options, sessionId) {
1160
+ sendDTMFSession(sessionId, tones, options) {
1044
1161
  const resolved = this.resolveExistingSessionId(sessionId);
1045
1162
  if (!resolved)
1046
1163
  return false;
@@ -1049,7 +1166,7 @@ var SipClient = class extends EventTargetEmitter {
1049
1166
  this.sessionManager.sendDTMF(resolved, tones, options);
1050
1167
  return true;
1051
1168
  }
1052
- transferSession(target, options, sessionId) {
1169
+ transferSession(sessionId, target, options) {
1053
1170
  const resolved = this.resolveExistingSessionId(sessionId);
1054
1171
  if (!resolved)
1055
1172
  return false;
@@ -1058,7 +1175,7 @@ var SipClient = class extends EventTargetEmitter {
1058
1175
  this.sessionManager.transfer(resolved, target, options);
1059
1176
  return true;
1060
1177
  }
1061
- attendedTransferSession(otherSession, sessionId) {
1178
+ attendedTransferSession(sessionId, otherSession) {
1062
1179
  const resolved = this.resolveExistingSessionId(sessionId);
1063
1180
  if (!resolved)
1064
1181
  return false;
@@ -1068,8 +1185,6 @@ var SipClient = class extends EventTargetEmitter {
1068
1185
  return true;
1069
1186
  }
1070
1187
  setSessionMedia(sessionId, stream) {
1071
- if (!this.sessionExists(sessionId))
1072
- return;
1073
1188
  this.sessionManager.setSessionMedia(sessionId, stream);
1074
1189
  }
1075
1190
  switchCameraSession(sessionId, track) {
@@ -1078,11 +1193,6 @@ var SipClient = class extends EventTargetEmitter {
1078
1193
  const rtc = this.sessionManager.getRtc(sessionId);
1079
1194
  return rtc ? rtc.switchCamera(track) : false;
1080
1195
  }
1081
- startScreenShareSession(sessionId, getDisplayMedia) {
1082
- if (!this.sessionExists(sessionId))
1083
- return false;
1084
- return this.sessionManager.startScreenShare(sessionId, getDisplayMedia);
1085
- }
1086
1196
  enableVideoSession(sessionId) {
1087
1197
  if (!this.sessionExists(sessionId))
1088
1198
  return false;
@@ -1122,6 +1232,59 @@ var SipClient = class extends EventTargetEmitter {
1122
1232
  window.removeEventListener("beforeunload", this.unloadHandler);
1123
1233
  this.unloadHandler = void 0;
1124
1234
  }
1235
+ syncDebugInspector(debug) {
1236
+ if (typeof window === "undefined")
1237
+ return;
1238
+ this.toggleStateLogger(Boolean(debug));
1239
+ const win = window;
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] };
1270
+ }
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
+ }
1287
+ }
1125
1288
  };
1126
1289
  function createSipClientInstance(options) {
1127
1290
  return new SipClient(options);
@@ -1201,7 +1364,6 @@ function useSipActions() {
1201
1364
  getSessions: () => client.getSessions(),
1202
1365
  setSessionMedia: (...args) => client.setSessionMedia(...args),
1203
1366
  switchCamera: (...args) => client.switchCameraSession(...args),
1204
- startScreenShare: (...args) => client.startScreenShareSession(...args),
1205
1367
  enableVideo: (...args) => client.enableVideoSession(...args),
1206
1368
  disableVideo: (...args) => client.disableVideoSession(...args)
1207
1369
  }),