react-jssip-kit 0.3.0 → 0.4.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 +6 -0
- package/dist/index.cjs +90 -38
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -20
- package/dist/index.d.ts +20 -20
- package/dist/index.js +90 -38
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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.
|
|
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
|
@@ -717,10 +717,6 @@ var SessionManager = class {
|
|
|
717
717
|
const rtc = this.getRtc(sessionId);
|
|
718
718
|
return rtc ? rtc.attendedTransfer(otherSession) : false;
|
|
719
719
|
}
|
|
720
|
-
startScreenShare(sessionId, getDisplayMedia) {
|
|
721
|
-
const rtc = this.getRtc(sessionId);
|
|
722
|
-
return rtc ? rtc.startScreenShare(getDisplayMedia) : false;
|
|
723
|
-
}
|
|
724
720
|
};
|
|
725
721
|
|
|
726
722
|
// src/jssip-lib/sip/sessionLifecycle.ts
|
|
@@ -814,17 +810,25 @@ var SipClient = class extends EventTargetEmitter {
|
|
|
814
810
|
connect(uri, password, config) {
|
|
815
811
|
this.disconnect();
|
|
816
812
|
this.stateStore.setState({ sipStatus: SipStatus.Connecting });
|
|
817
|
-
const {
|
|
813
|
+
const {
|
|
814
|
+
debug: cfgDebug,
|
|
815
|
+
maxSessionCount,
|
|
816
|
+
pendingMediaTtlMs,
|
|
817
|
+
...uaCfg
|
|
818
|
+
} = config;
|
|
818
819
|
this.maxSessionCount = typeof maxSessionCount === "number" ? maxSessionCount : Infinity;
|
|
819
820
|
this.sessionManager.setPendingMediaTtl(pendingMediaTtlMs);
|
|
820
821
|
const debug = this.debugPattern ?? cfgDebug;
|
|
821
822
|
this.userAgent.start(uri, password, uaCfg, { debug });
|
|
822
823
|
this.attachUAHandlers();
|
|
824
|
+
this.attachBeforeUnload();
|
|
825
|
+
this.syncDebugInspector(debug);
|
|
823
826
|
}
|
|
824
827
|
registerUA() {
|
|
825
828
|
this.userAgent.register();
|
|
826
829
|
}
|
|
827
830
|
disconnect() {
|
|
831
|
+
this.detachBeforeUnload();
|
|
828
832
|
this.detachUAHandlers();
|
|
829
833
|
this.userAgent.stop();
|
|
830
834
|
this.cleanupAllSessions();
|
|
@@ -845,33 +849,37 @@ var SipClient = class extends EventTargetEmitter {
|
|
|
845
849
|
});
|
|
846
850
|
}
|
|
847
851
|
}
|
|
848
|
-
answer(options = {}) {
|
|
849
|
-
const
|
|
850
|
-
if (!
|
|
852
|
+
answer(sessionId, options = {}) {
|
|
853
|
+
const resolved = this.resolveExistingSessionId(sessionId);
|
|
854
|
+
if (!resolved)
|
|
851
855
|
return false;
|
|
852
|
-
return this.answerSession(
|
|
856
|
+
return this.answerSession(resolved, options);
|
|
853
857
|
}
|
|
854
|
-
hangup(options) {
|
|
855
|
-
const
|
|
856
|
-
if (!
|
|
858
|
+
hangup(sessionId, options) {
|
|
859
|
+
const resolved = this.resolveExistingSessionId(sessionId);
|
|
860
|
+
if (!resolved)
|
|
857
861
|
return false;
|
|
858
|
-
return this.hangupSession(
|
|
862
|
+
return this.hangupSession(resolved, options);
|
|
859
863
|
}
|
|
860
|
-
|
|
861
|
-
|
|
864
|
+
hangupAll(options) {
|
|
865
|
+
const ids = this.getSessionIds();
|
|
866
|
+
ids.forEach((id) => this.hangupSession(id, options));
|
|
867
|
+
return ids.length > 0;
|
|
862
868
|
}
|
|
863
|
-
|
|
864
|
-
return this.
|
|
869
|
+
toggleMute(sessionId) {
|
|
870
|
+
return this.toggleMuteSession(sessionId);
|
|
865
871
|
}
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
return this.sendDTMFSession(tones, options, sessionId ?? void 0);
|
|
872
|
+
toggleHold(sessionId) {
|
|
873
|
+
return this.toggleHoldSession(sessionId);
|
|
869
874
|
}
|
|
870
|
-
|
|
871
|
-
return this.
|
|
875
|
+
sendDTMF(sessionId, tones, options) {
|
|
876
|
+
return this.sendDTMFSession(sessionId, tones, options);
|
|
872
877
|
}
|
|
873
|
-
|
|
874
|
-
return this.
|
|
878
|
+
transfer(sessionId, target, options) {
|
|
879
|
+
return this.transferSession(sessionId, target, options);
|
|
880
|
+
}
|
|
881
|
+
attendedTransfer(sessionId, otherSession) {
|
|
882
|
+
return this.attendedTransferSession(sessionId, otherSession);
|
|
875
883
|
}
|
|
876
884
|
onChange(fn) {
|
|
877
885
|
return this.stateStore.onChange(fn);
|
|
@@ -890,6 +898,7 @@ var SipClient = class extends EventTargetEmitter {
|
|
|
890
898
|
setDebug(debug) {
|
|
891
899
|
this.debugPattern = debug;
|
|
892
900
|
this.userAgent.setDebug(debug);
|
|
901
|
+
this.syncDebugInspector(debug);
|
|
893
902
|
}
|
|
894
903
|
attachSessionHandlers(sessionId, session) {
|
|
895
904
|
const handlers = this.createSessionHandlersFor(sessionId, session);
|
|
@@ -979,24 +988,33 @@ var SipClient = class extends EventTargetEmitter {
|
|
|
979
988
|
const active = sessions.find((s) => s.status === CallStatus.Active);
|
|
980
989
|
return active?.id ?? sessions[0]?.id ?? null;
|
|
981
990
|
}
|
|
991
|
+
sessionExists(sessionId) {
|
|
992
|
+
return !!this.sessionManager.getSession(sessionId) || !!this.sessionManager.getRtc(sessionId);
|
|
993
|
+
}
|
|
994
|
+
resolveExistingSessionId(sessionId) {
|
|
995
|
+
const id = this.resolveSessionId(sessionId);
|
|
996
|
+
if (!id)
|
|
997
|
+
return null;
|
|
998
|
+
return this.sessionExists(id) ? id : null;
|
|
999
|
+
}
|
|
982
1000
|
ensureMediaConstraints(opts) {
|
|
983
1001
|
if (opts.mediaStream || opts.mediaConstraints)
|
|
984
1002
|
return opts;
|
|
985
1003
|
return { ...opts, mediaConstraints: { audio: true, video: false } };
|
|
986
1004
|
}
|
|
987
1005
|
answerSession(sessionId, options = {}) {
|
|
988
|
-
if (!sessionId)
|
|
1006
|
+
if (!sessionId || !this.sessionExists(sessionId))
|
|
989
1007
|
return false;
|
|
990
1008
|
const opts = this.ensureMediaConstraints(options);
|
|
991
1009
|
return this.sessionManager.answer(sessionId, opts);
|
|
992
1010
|
}
|
|
993
1011
|
hangupSession(sessionId, options) {
|
|
994
|
-
if (!sessionId)
|
|
1012
|
+
if (!sessionId || !this.sessionExists(sessionId))
|
|
995
1013
|
return false;
|
|
996
1014
|
return this.sessionManager.hangup(sessionId, options);
|
|
997
1015
|
}
|
|
998
1016
|
toggleMuteSession(sessionId) {
|
|
999
|
-
const resolved = this.
|
|
1017
|
+
const resolved = this.resolveExistingSessionId(sessionId);
|
|
1000
1018
|
if (!resolved)
|
|
1001
1019
|
return false;
|
|
1002
1020
|
const sessionState = this.stateStore.getState().sessions.find((s) => s.id === resolved);
|
|
@@ -1009,7 +1027,7 @@ var SipClient = class extends EventTargetEmitter {
|
|
|
1009
1027
|
return true;
|
|
1010
1028
|
}
|
|
1011
1029
|
toggleHoldSession(sessionId) {
|
|
1012
|
-
const resolved = this.
|
|
1030
|
+
const resolved = this.resolveExistingSessionId(sessionId);
|
|
1013
1031
|
if (!resolved)
|
|
1014
1032
|
return false;
|
|
1015
1033
|
const sessionState = this.stateStore.getState().sessions.find((s) => s.id === resolved);
|
|
@@ -1024,8 +1042,8 @@ var SipClient = class extends EventTargetEmitter {
|
|
|
1024
1042
|
}
|
|
1025
1043
|
return true;
|
|
1026
1044
|
}
|
|
1027
|
-
sendDTMFSession(tones, options
|
|
1028
|
-
const resolved = this.
|
|
1045
|
+
sendDTMFSession(sessionId, tones, options) {
|
|
1046
|
+
const resolved = this.resolveExistingSessionId(sessionId);
|
|
1029
1047
|
if (!resolved)
|
|
1030
1048
|
return false;
|
|
1031
1049
|
const sessionState = this.stateStore.getState().sessions.find((s) => s.id === resolved);
|
|
@@ -1033,8 +1051,8 @@ var SipClient = class extends EventTargetEmitter {
|
|
|
1033
1051
|
this.sessionManager.sendDTMF(resolved, tones, options);
|
|
1034
1052
|
return true;
|
|
1035
1053
|
}
|
|
1036
|
-
transferSession(target, options
|
|
1037
|
-
const resolved = this.
|
|
1054
|
+
transferSession(sessionId, target, options) {
|
|
1055
|
+
const resolved = this.resolveExistingSessionId(sessionId);
|
|
1038
1056
|
if (!resolved)
|
|
1039
1057
|
return false;
|
|
1040
1058
|
const sessionState = this.stateStore.getState().sessions.find((s) => s.id === resolved);
|
|
@@ -1042,8 +1060,8 @@ var SipClient = class extends EventTargetEmitter {
|
|
|
1042
1060
|
this.sessionManager.transfer(resolved, target, options);
|
|
1043
1061
|
return true;
|
|
1044
1062
|
}
|
|
1045
|
-
attendedTransferSession(
|
|
1046
|
-
const resolved = this.
|
|
1063
|
+
attendedTransferSession(sessionId, otherSession) {
|
|
1064
|
+
const resolved = this.resolveExistingSessionId(sessionId);
|
|
1047
1065
|
if (!resolved)
|
|
1048
1066
|
return false;
|
|
1049
1067
|
const sessionState = this.stateStore.getState().sessions.find((s) => s.id === resolved);
|
|
@@ -1055,18 +1073,21 @@ var SipClient = class extends EventTargetEmitter {
|
|
|
1055
1073
|
this.sessionManager.setSessionMedia(sessionId, stream);
|
|
1056
1074
|
}
|
|
1057
1075
|
switchCameraSession(sessionId, track) {
|
|
1076
|
+
if (!this.sessionExists(sessionId))
|
|
1077
|
+
return false;
|
|
1058
1078
|
const rtc = this.sessionManager.getRtc(sessionId);
|
|
1059
1079
|
return rtc ? rtc.switchCamera(track) : false;
|
|
1060
1080
|
}
|
|
1061
|
-
startScreenShareSession(sessionId, getDisplayMedia) {
|
|
1062
|
-
return this.sessionManager.startScreenShare(sessionId, getDisplayMedia);
|
|
1063
|
-
}
|
|
1064
1081
|
enableVideoSession(sessionId) {
|
|
1082
|
+
if (!this.sessionExists(sessionId))
|
|
1083
|
+
return false;
|
|
1065
1084
|
const rtc = this.sessionManager.getRtc(sessionId);
|
|
1066
1085
|
rtc?.enableVideo();
|
|
1067
1086
|
return !!rtc;
|
|
1068
1087
|
}
|
|
1069
1088
|
disableVideoSession(sessionId) {
|
|
1089
|
+
if (!this.sessionExists(sessionId))
|
|
1090
|
+
return false;
|
|
1070
1091
|
const rtc = this.sessionManager.getRtc(sessionId);
|
|
1071
1092
|
rtc?.disableVideo();
|
|
1072
1093
|
return !!rtc;
|
|
@@ -1080,6 +1101,38 @@ var SipClient = class extends EventTargetEmitter {
|
|
|
1080
1101
|
getSessions() {
|
|
1081
1102
|
return this.sessionManager.getSessions();
|
|
1082
1103
|
}
|
|
1104
|
+
attachBeforeUnload() {
|
|
1105
|
+
if (typeof window === "undefined" || this.unloadHandler)
|
|
1106
|
+
return;
|
|
1107
|
+
const handler = () => {
|
|
1108
|
+
this.hangupAll();
|
|
1109
|
+
this.disconnect();
|
|
1110
|
+
};
|
|
1111
|
+
window.addEventListener("beforeunload", handler);
|
|
1112
|
+
this.unloadHandler = handler;
|
|
1113
|
+
}
|
|
1114
|
+
detachBeforeUnload() {
|
|
1115
|
+
if (typeof window === "undefined" || !this.unloadHandler)
|
|
1116
|
+
return;
|
|
1117
|
+
window.removeEventListener("beforeunload", this.unloadHandler);
|
|
1118
|
+
this.unloadHandler = void 0;
|
|
1119
|
+
}
|
|
1120
|
+
syncDebugInspector(debug) {
|
|
1121
|
+
if (typeof window === "undefined")
|
|
1122
|
+
return;
|
|
1123
|
+
const enabled = Boolean(debug);
|
|
1124
|
+
const win = window;
|
|
1125
|
+
if (enabled) {
|
|
1126
|
+
win.sipState = () => this.stateStore.getState();
|
|
1127
|
+
win.sipSessions = () => this.getSessions();
|
|
1128
|
+
} else {
|
|
1129
|
+
try {
|
|
1130
|
+
delete win.sipState;
|
|
1131
|
+
delete win.sipSessions;
|
|
1132
|
+
} catch {
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1083
1136
|
};
|
|
1084
1137
|
function createSipClientInstance(options) {
|
|
1085
1138
|
return new SipClient(options);
|
|
@@ -1159,7 +1212,6 @@ function useSipActions() {
|
|
|
1159
1212
|
getSessions: () => client.getSessions(),
|
|
1160
1213
|
setSessionMedia: (...args) => client.setSessionMedia(...args),
|
|
1161
1214
|
switchCamera: (...args) => client.switchCameraSession(...args),
|
|
1162
|
-
startScreenShare: (...args) => client.startScreenShareSession(...args),
|
|
1163
1215
|
enableVideo: (...args) => client.enableVideoSession(...args),
|
|
1164
1216
|
disableVideo: (...args) => client.disableVideoSession(...args)
|
|
1165
1217
|
}),
|