react-jssip-kit 0.7.0 → 0.7.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/dist/index.cjs +53 -67
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -4
- package/dist/index.d.ts +2 -4
- package/dist/index.js +41 -54
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import JsSIP from 'jssip';
|
|
2
2
|
export { WebSocketInterface } from 'jssip';
|
|
3
|
-
import
|
|
3
|
+
import { createContext, useContext, useCallback, useSyncExternalStore, useMemo, useEffect, useRef } from 'react';
|
|
4
4
|
import { jsx } from 'react/jsx-runtime';
|
|
5
5
|
|
|
6
6
|
// src/jssip-lib/sip/debugger.ts
|
|
@@ -494,7 +494,10 @@ function createSessionHandlers(deps) {
|
|
|
494
494
|
)
|
|
495
495
|
});
|
|
496
496
|
},
|
|
497
|
-
confirmed: (e) =>
|
|
497
|
+
confirmed: (e) => {
|
|
498
|
+
emitter.emit("confirmed", e);
|
|
499
|
+
onSessionConfirmed?.(sessionId);
|
|
500
|
+
},
|
|
498
501
|
ended: (e) => {
|
|
499
502
|
emitter.emit("ended", e);
|
|
500
503
|
detachSessionHandlers();
|
|
@@ -959,14 +962,6 @@ var SipClient = class extends EventTargetEmitter {
|
|
|
959
962
|
this.attachBeforeUnload();
|
|
960
963
|
this.syncDebugInspector(debug);
|
|
961
964
|
}
|
|
962
|
-
setMicrophoneProvider(fn) {
|
|
963
|
-
this.requestMicrophoneStream = fn;
|
|
964
|
-
if (fn && this.micRecoveryEnabled) {
|
|
965
|
-
this.sessionManager.getSessions().forEach(({ id }) => {
|
|
966
|
-
this.enableMicrophoneRecovery(id);
|
|
967
|
-
});
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
965
|
registerUA() {
|
|
971
966
|
this.userAgent.register();
|
|
972
967
|
}
|
|
@@ -978,21 +973,6 @@ var SipClient = class extends EventTargetEmitter {
|
|
|
978
973
|
this.stateStore.reset();
|
|
979
974
|
}
|
|
980
975
|
call(target, callOptions = {}) {
|
|
981
|
-
if (!callOptions.mediaStream && this.requestMicrophoneStream) {
|
|
982
|
-
void this.requestMicrophoneStream().then((stream) => {
|
|
983
|
-
if (!stream)
|
|
984
|
-
throw new Error("microphone stream unavailable");
|
|
985
|
-
this.call(target, { ...callOptions, mediaStream: stream });
|
|
986
|
-
}).catch((e) => {
|
|
987
|
-
const err = this.emitError(
|
|
988
|
-
e,
|
|
989
|
-
"MICROPHONE_FAILED",
|
|
990
|
-
"microphone failed"
|
|
991
|
-
);
|
|
992
|
-
this.stateStore.batchSet({ error: err.cause });
|
|
993
|
-
});
|
|
994
|
-
return;
|
|
995
|
-
}
|
|
996
976
|
try {
|
|
997
977
|
const opts = this.ensureMediaConstraints(callOptions);
|
|
998
978
|
if (opts.mediaStream)
|
|
@@ -1063,9 +1043,6 @@ var SipClient = class extends EventTargetEmitter {
|
|
|
1063
1043
|
if (h)
|
|
1064
1044
|
session.on(ev, h);
|
|
1065
1045
|
});
|
|
1066
|
-
if (this.requestMicrophoneStream && this.micRecoveryEnabled) {
|
|
1067
|
-
this.enableMicrophoneRecovery(sessionId);
|
|
1068
|
-
}
|
|
1069
1046
|
}
|
|
1070
1047
|
detachSessionHandlers(sessionId, session) {
|
|
1071
1048
|
const handlers = this.sessionHandlers.get(sessionId);
|
|
@@ -1159,22 +1136,10 @@ var SipClient = class extends EventTargetEmitter {
|
|
|
1159
1136
|
answerSession(sessionId, options = {}) {
|
|
1160
1137
|
if (!sessionId || !this.sessionExists(sessionId))
|
|
1161
1138
|
return false;
|
|
1162
|
-
if (!options.mediaStream && this.requestMicrophoneStream) {
|
|
1163
|
-
void this.requestMicrophoneStream().then((stream) => {
|
|
1164
|
-
if (!stream)
|
|
1165
|
-
throw new Error("microphone stream unavailable");
|
|
1166
|
-
this.answerSession(sessionId, { ...options, mediaStream: stream });
|
|
1167
|
-
}).catch((e) => {
|
|
1168
|
-
const err = this.emitError(
|
|
1169
|
-
e,
|
|
1170
|
-
"MICROPHONE_FAILED",
|
|
1171
|
-
"microphone failed"
|
|
1172
|
-
);
|
|
1173
|
-
this.stateStore.batchSet({ error: err.cause });
|
|
1174
|
-
});
|
|
1175
|
-
return true;
|
|
1176
|
-
}
|
|
1177
1139
|
const opts = this.ensureMediaConstraints(options);
|
|
1140
|
+
if (opts.mediaStream) {
|
|
1141
|
+
this.sessionManager.setSessionMedia(sessionId, opts.mediaStream);
|
|
1142
|
+
}
|
|
1178
1143
|
return this.sessionManager.answer(sessionId, opts);
|
|
1179
1144
|
}
|
|
1180
1145
|
hangupSession(sessionId, options) {
|
|
@@ -1237,9 +1202,6 @@ var SipClient = class extends EventTargetEmitter {
|
|
|
1237
1202
|
if (!resolved)
|
|
1238
1203
|
return () => {
|
|
1239
1204
|
};
|
|
1240
|
-
if (!this.requestMicrophoneStream)
|
|
1241
|
-
return () => {
|
|
1242
|
-
};
|
|
1243
1205
|
this.disableMicrophoneRecovery(resolved);
|
|
1244
1206
|
const intervalMs = options.intervalMs ?? this.micRecoveryDefaults.intervalMs;
|
|
1245
1207
|
const maxRetries = options.maxRetries ?? this.micRecoveryDefaults.maxRetries;
|
|
@@ -1262,12 +1224,24 @@ var SipClient = class extends EventTargetEmitter {
|
|
|
1262
1224
|
const senderLive = sender?.track?.readyState === "live";
|
|
1263
1225
|
if (trackLive && senderLive)
|
|
1264
1226
|
return;
|
|
1227
|
+
this.emitError(
|
|
1228
|
+
{
|
|
1229
|
+
cause: "microphone dropped",
|
|
1230
|
+
trackLive,
|
|
1231
|
+
senderLive
|
|
1232
|
+
},
|
|
1233
|
+
"MICROPHONE_DROPPED",
|
|
1234
|
+
"microphone dropped"
|
|
1235
|
+
);
|
|
1265
1236
|
retries += 1;
|
|
1237
|
+
if (trackLive && !senderLive && track) {
|
|
1238
|
+
await rtc.replaceAudioTrack(track);
|
|
1239
|
+
return;
|
|
1240
|
+
}
|
|
1266
1241
|
let nextStream;
|
|
1267
1242
|
try {
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
nextStream = await this.requestMicrophoneStream();
|
|
1243
|
+
const deviceId = track?.getSettings?.().deviceId ?? sender?.track?.getSettings?.().deviceId;
|
|
1244
|
+
nextStream = await this.requestMicrophoneStreamInternal(deviceId);
|
|
1271
1245
|
} catch (err) {
|
|
1272
1246
|
console.warn("[sip] mic recovery failed to get stream", err);
|
|
1273
1247
|
return;
|
|
@@ -1405,6 +1379,23 @@ var SipClient = class extends EventTargetEmitter {
|
|
|
1405
1379
|
return void 0;
|
|
1406
1380
|
}
|
|
1407
1381
|
}
|
|
1382
|
+
async requestMicrophoneStreamInternal(deviceId) {
|
|
1383
|
+
if (typeof navigator === "undefined" || !navigator.mediaDevices?.getUserMedia) {
|
|
1384
|
+
throw new Error("getUserMedia not available");
|
|
1385
|
+
}
|
|
1386
|
+
const audio = deviceId && deviceId !== "default" ? { deviceId: { exact: deviceId } } : true;
|
|
1387
|
+
try {
|
|
1388
|
+
return await navigator.mediaDevices.getUserMedia({ audio });
|
|
1389
|
+
} catch (err) {
|
|
1390
|
+
const cause = err?.name || "getUserMedia failed";
|
|
1391
|
+
this.emitError(
|
|
1392
|
+
{ raw: err, cause },
|
|
1393
|
+
"MICROPHONE_UNAVAILABLE",
|
|
1394
|
+
"microphone unavailable"
|
|
1395
|
+
);
|
|
1396
|
+
throw err;
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1408
1399
|
};
|
|
1409
1400
|
function createSipClientInstance(options) {
|
|
1410
1401
|
return new SipClient(options);
|
|
@@ -1597,16 +1588,12 @@ function CallPlayer({ sessionId }) {
|
|
|
1597
1588
|
function SipProvider({
|
|
1598
1589
|
client,
|
|
1599
1590
|
children,
|
|
1600
|
-
sipEventManager
|
|
1601
|
-
requestMicrophoneStream
|
|
1591
|
+
sipEventManager
|
|
1602
1592
|
}) {
|
|
1603
1593
|
const manager = useMemo(
|
|
1604
1594
|
() => sipEventManager ?? createSipEventManager(client),
|
|
1605
1595
|
[client, sipEventManager]
|
|
1606
1596
|
);
|
|
1607
|
-
React.useEffect(() => {
|
|
1608
|
-
client.setMicrophoneProvider(requestMicrophoneStream);
|
|
1609
|
-
}, [client, requestMicrophoneStream]);
|
|
1610
1597
|
const contextValue = useMemo(() => ({ client, sipEventManager: manager }), [client, manager]);
|
|
1611
1598
|
return /* @__PURE__ */ jsx(SipContext.Provider, { value: contextValue, children });
|
|
1612
1599
|
}
|