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.cjs
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var JsSIP = require('jssip');
|
|
4
|
-
var
|
|
4
|
+
var react = require('react');
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
6
|
|
|
7
7
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
8
|
|
|
9
9
|
var JsSIP__default = /*#__PURE__*/_interopDefault(JsSIP);
|
|
10
|
-
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
11
10
|
|
|
12
11
|
// src/jssip-lib/sip/debugger.ts
|
|
13
12
|
var SipDebugger = class {
|
|
@@ -500,7 +499,10 @@ function createSessionHandlers(deps) {
|
|
|
500
499
|
)
|
|
501
500
|
});
|
|
502
501
|
},
|
|
503
|
-
confirmed: (e) =>
|
|
502
|
+
confirmed: (e) => {
|
|
503
|
+
emitter.emit("confirmed", e);
|
|
504
|
+
onSessionConfirmed?.(sessionId);
|
|
505
|
+
},
|
|
504
506
|
ended: (e) => {
|
|
505
507
|
emitter.emit("ended", e);
|
|
506
508
|
detachSessionHandlers();
|
|
@@ -965,14 +967,6 @@ var SipClient = class extends EventTargetEmitter {
|
|
|
965
967
|
this.attachBeforeUnload();
|
|
966
968
|
this.syncDebugInspector(debug);
|
|
967
969
|
}
|
|
968
|
-
setMicrophoneProvider(fn) {
|
|
969
|
-
this.requestMicrophoneStream = fn;
|
|
970
|
-
if (fn && this.micRecoveryEnabled) {
|
|
971
|
-
this.sessionManager.getSessions().forEach(({ id }) => {
|
|
972
|
-
this.enableMicrophoneRecovery(id);
|
|
973
|
-
});
|
|
974
|
-
}
|
|
975
|
-
}
|
|
976
970
|
registerUA() {
|
|
977
971
|
this.userAgent.register();
|
|
978
972
|
}
|
|
@@ -984,21 +978,6 @@ var SipClient = class extends EventTargetEmitter {
|
|
|
984
978
|
this.stateStore.reset();
|
|
985
979
|
}
|
|
986
980
|
call(target, callOptions = {}) {
|
|
987
|
-
if (!callOptions.mediaStream && this.requestMicrophoneStream) {
|
|
988
|
-
void this.requestMicrophoneStream().then((stream) => {
|
|
989
|
-
if (!stream)
|
|
990
|
-
throw new Error("microphone stream unavailable");
|
|
991
|
-
this.call(target, { ...callOptions, mediaStream: stream });
|
|
992
|
-
}).catch((e) => {
|
|
993
|
-
const err = this.emitError(
|
|
994
|
-
e,
|
|
995
|
-
"MICROPHONE_FAILED",
|
|
996
|
-
"microphone failed"
|
|
997
|
-
);
|
|
998
|
-
this.stateStore.batchSet({ error: err.cause });
|
|
999
|
-
});
|
|
1000
|
-
return;
|
|
1001
|
-
}
|
|
1002
981
|
try {
|
|
1003
982
|
const opts = this.ensureMediaConstraints(callOptions);
|
|
1004
983
|
if (opts.mediaStream)
|
|
@@ -1069,9 +1048,6 @@ var SipClient = class extends EventTargetEmitter {
|
|
|
1069
1048
|
if (h)
|
|
1070
1049
|
session.on(ev, h);
|
|
1071
1050
|
});
|
|
1072
|
-
if (this.requestMicrophoneStream && this.micRecoveryEnabled) {
|
|
1073
|
-
this.enableMicrophoneRecovery(sessionId);
|
|
1074
|
-
}
|
|
1075
1051
|
}
|
|
1076
1052
|
detachSessionHandlers(sessionId, session) {
|
|
1077
1053
|
const handlers = this.sessionHandlers.get(sessionId);
|
|
@@ -1165,22 +1141,10 @@ var SipClient = class extends EventTargetEmitter {
|
|
|
1165
1141
|
answerSession(sessionId, options = {}) {
|
|
1166
1142
|
if (!sessionId || !this.sessionExists(sessionId))
|
|
1167
1143
|
return false;
|
|
1168
|
-
if (!options.mediaStream && this.requestMicrophoneStream) {
|
|
1169
|
-
void this.requestMicrophoneStream().then((stream) => {
|
|
1170
|
-
if (!stream)
|
|
1171
|
-
throw new Error("microphone stream unavailable");
|
|
1172
|
-
this.answerSession(sessionId, { ...options, mediaStream: stream });
|
|
1173
|
-
}).catch((e) => {
|
|
1174
|
-
const err = this.emitError(
|
|
1175
|
-
e,
|
|
1176
|
-
"MICROPHONE_FAILED",
|
|
1177
|
-
"microphone failed"
|
|
1178
|
-
);
|
|
1179
|
-
this.stateStore.batchSet({ error: err.cause });
|
|
1180
|
-
});
|
|
1181
|
-
return true;
|
|
1182
|
-
}
|
|
1183
1144
|
const opts = this.ensureMediaConstraints(options);
|
|
1145
|
+
if (opts.mediaStream) {
|
|
1146
|
+
this.sessionManager.setSessionMedia(sessionId, opts.mediaStream);
|
|
1147
|
+
}
|
|
1184
1148
|
return this.sessionManager.answer(sessionId, opts);
|
|
1185
1149
|
}
|
|
1186
1150
|
hangupSession(sessionId, options) {
|
|
@@ -1243,9 +1207,6 @@ var SipClient = class extends EventTargetEmitter {
|
|
|
1243
1207
|
if (!resolved)
|
|
1244
1208
|
return () => {
|
|
1245
1209
|
};
|
|
1246
|
-
if (!this.requestMicrophoneStream)
|
|
1247
|
-
return () => {
|
|
1248
|
-
};
|
|
1249
1210
|
this.disableMicrophoneRecovery(resolved);
|
|
1250
1211
|
const intervalMs = options.intervalMs ?? this.micRecoveryDefaults.intervalMs;
|
|
1251
1212
|
const maxRetries = options.maxRetries ?? this.micRecoveryDefaults.maxRetries;
|
|
@@ -1268,12 +1229,24 @@ var SipClient = class extends EventTargetEmitter {
|
|
|
1268
1229
|
const senderLive = sender?.track?.readyState === "live";
|
|
1269
1230
|
if (trackLive && senderLive)
|
|
1270
1231
|
return;
|
|
1232
|
+
this.emitError(
|
|
1233
|
+
{
|
|
1234
|
+
cause: "microphone dropped",
|
|
1235
|
+
trackLive,
|
|
1236
|
+
senderLive
|
|
1237
|
+
},
|
|
1238
|
+
"MICROPHONE_DROPPED",
|
|
1239
|
+
"microphone dropped"
|
|
1240
|
+
);
|
|
1271
1241
|
retries += 1;
|
|
1242
|
+
if (trackLive && !senderLive && track) {
|
|
1243
|
+
await rtc.replaceAudioTrack(track);
|
|
1244
|
+
return;
|
|
1245
|
+
}
|
|
1272
1246
|
let nextStream;
|
|
1273
1247
|
try {
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
nextStream = await this.requestMicrophoneStream();
|
|
1248
|
+
const deviceId = track?.getSettings?.().deviceId ?? sender?.track?.getSettings?.().deviceId;
|
|
1249
|
+
nextStream = await this.requestMicrophoneStreamInternal(deviceId);
|
|
1277
1250
|
} catch (err) {
|
|
1278
1251
|
console.warn("[sip] mic recovery failed to get stream", err);
|
|
1279
1252
|
return;
|
|
@@ -1411,6 +1384,23 @@ var SipClient = class extends EventTargetEmitter {
|
|
|
1411
1384
|
return void 0;
|
|
1412
1385
|
}
|
|
1413
1386
|
}
|
|
1387
|
+
async requestMicrophoneStreamInternal(deviceId) {
|
|
1388
|
+
if (typeof navigator === "undefined" || !navigator.mediaDevices?.getUserMedia) {
|
|
1389
|
+
throw new Error("getUserMedia not available");
|
|
1390
|
+
}
|
|
1391
|
+
const audio = deviceId && deviceId !== "default" ? { deviceId: { exact: deviceId } } : true;
|
|
1392
|
+
try {
|
|
1393
|
+
return await navigator.mediaDevices.getUserMedia({ audio });
|
|
1394
|
+
} catch (err) {
|
|
1395
|
+
const cause = err?.name || "getUserMedia failed";
|
|
1396
|
+
this.emitError(
|
|
1397
|
+
{ raw: err, cause },
|
|
1398
|
+
"MICROPHONE_UNAVAILABLE",
|
|
1399
|
+
"microphone unavailable"
|
|
1400
|
+
);
|
|
1401
|
+
throw err;
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1414
1404
|
};
|
|
1415
1405
|
function createSipClientInstance(options) {
|
|
1416
1406
|
return new SipClient(options);
|
|
@@ -1430,9 +1420,9 @@ function createSipEventManager(client) {
|
|
|
1430
1420
|
}
|
|
1431
1421
|
};
|
|
1432
1422
|
}
|
|
1433
|
-
var SipContext =
|
|
1423
|
+
var SipContext = react.createContext(null);
|
|
1434
1424
|
function useSip() {
|
|
1435
|
-
const ctx =
|
|
1425
|
+
const ctx = react.useContext(SipContext);
|
|
1436
1426
|
if (!ctx)
|
|
1437
1427
|
throw new Error("Must be used within SipProvider");
|
|
1438
1428
|
return ctx;
|
|
@@ -1441,16 +1431,16 @@ function useSip() {
|
|
|
1441
1431
|
// src/hooks/useSipState.ts
|
|
1442
1432
|
function useSipState() {
|
|
1443
1433
|
const { client } = useSip();
|
|
1444
|
-
const subscribe =
|
|
1434
|
+
const subscribe = react.useCallback(
|
|
1445
1435
|
(onStoreChange) => client.onChange(onStoreChange),
|
|
1446
1436
|
[client]
|
|
1447
1437
|
);
|
|
1448
|
-
const getSnapshot =
|
|
1449
|
-
return
|
|
1438
|
+
const getSnapshot = react.useCallback(() => client.state, [client]);
|
|
1439
|
+
return react.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
1450
1440
|
}
|
|
1451
1441
|
function useSipActions() {
|
|
1452
1442
|
const { client } = useSip();
|
|
1453
|
-
return
|
|
1443
|
+
return react.useMemo(
|
|
1454
1444
|
() => ({
|
|
1455
1445
|
call: (...args) => client.call(...args),
|
|
1456
1446
|
answer: (...args) => client.answerSession(...args),
|
|
@@ -1480,7 +1470,7 @@ function useSipSessions() {
|
|
|
1480
1470
|
}
|
|
1481
1471
|
function useSipEvent(event, handler) {
|
|
1482
1472
|
const { sipEventManager } = useSip();
|
|
1483
|
-
|
|
1473
|
+
react.useEffect(() => {
|
|
1484
1474
|
if (!handler)
|
|
1485
1475
|
return;
|
|
1486
1476
|
return sipEventManager.onUA(event, handler);
|
|
@@ -1488,7 +1478,7 @@ function useSipEvent(event, handler) {
|
|
|
1488
1478
|
}
|
|
1489
1479
|
function useSipSessionEvent(sessionId, event, handler) {
|
|
1490
1480
|
const { sipEventManager } = useSip();
|
|
1491
|
-
|
|
1481
|
+
react.useEffect(() => {
|
|
1492
1482
|
if (!handler)
|
|
1493
1483
|
return;
|
|
1494
1484
|
return sipEventManager.onSession(sessionId, event, handler);
|
|
@@ -1586,8 +1576,8 @@ function createCallPlayer(audioEl) {
|
|
|
1586
1576
|
}
|
|
1587
1577
|
function CallPlayer({ sessionId }) {
|
|
1588
1578
|
const { client } = useSip();
|
|
1589
|
-
const audioRef =
|
|
1590
|
-
|
|
1579
|
+
const audioRef = react.useRef(null);
|
|
1580
|
+
react.useEffect(() => {
|
|
1591
1581
|
if (!audioRef.current)
|
|
1592
1582
|
return;
|
|
1593
1583
|
const player = createCallPlayer(audioRef.current);
|
|
@@ -1603,17 +1593,13 @@ function CallPlayer({ sessionId }) {
|
|
|
1603
1593
|
function SipProvider({
|
|
1604
1594
|
client,
|
|
1605
1595
|
children,
|
|
1606
|
-
sipEventManager
|
|
1607
|
-
requestMicrophoneStream
|
|
1596
|
+
sipEventManager
|
|
1608
1597
|
}) {
|
|
1609
|
-
const manager =
|
|
1598
|
+
const manager = react.useMemo(
|
|
1610
1599
|
() => sipEventManager ?? createSipEventManager(client),
|
|
1611
1600
|
[client, sipEventManager]
|
|
1612
1601
|
);
|
|
1613
|
-
|
|
1614
|
-
client.setMicrophoneProvider(requestMicrophoneStream);
|
|
1615
|
-
}, [client, requestMicrophoneStream]);
|
|
1616
|
-
const contextValue = React.useMemo(() => ({ client, sipEventManager: manager }), [client, manager]);
|
|
1602
|
+
const contextValue = react.useMemo(() => ({ client, sipEventManager: manager }), [client, manager]);
|
|
1617
1603
|
return /* @__PURE__ */ jsxRuntime.jsx(SipContext.Provider, { value: contextValue, children });
|
|
1618
1604
|
}
|
|
1619
1605
|
|