Commit 28dd4dd for jssip.net

commit 28dd4dd0bc16cb0998fdb01fd11c8a92fb6ada67
Author: José Luis Millán <jmillan@aliax.net>
Date:   Tue Feb 17 13:03:34 2026 +0100

    Fix ReferSubscriber: properly handle authentication

diff --git a/src/Dialog.js b/src/Dialog.js
index c8f68cc..85b9b90 100644
--- a/src/Dialog.js
+++ b/src/Dialog.js
@@ -141,14 +141,19 @@ module.exports = class Dialog {
 		const body = options.body || null;
 		const request = this._createRequest(method, extraHeaders, body);

+		// Some usages may need to know about authentication.
+		const onAuthenticated = eventHandlers.onAuthenticated || (() => {});
+
 		// Increase the local CSeq on authentication.
-		eventHandlers.onAuthenticated = () => {
+		eventHandlers.onAuthenticated = _request => {
 			this._local_seqnum += 1;

 			// In case of re-INVITE store outgoing ack_seqnum for its CANCEL or ACK.
 			if (request.method === JsSIP_C.INVITE) {
 				this._outgoing_ack_seqnum = this._local_seqnum;
 			}
+
+			onAuthenticated(_request);
 		};

 		const request_sender = new Dialog_RequestSender(
diff --git a/src/RTCSession.js b/src/RTCSession.js
index ed0f26a..47f8848 100644
--- a/src/RTCSession.js
+++ b/src/RTCSession.js
@@ -1296,7 +1296,7 @@ module.exports = class RTCSession extends EventEmitter {
 		referSubscriber.sendRefer(target, options);

 		// Store in the map.
-		const id = referSubscriber.id;
+		let id = referSubscriber.id;

 		this._referSubscribers[id] = referSubscriber;

@@ -1310,6 +1310,14 @@ module.exports = class RTCSession extends EventEmitter {
 		referSubscriber.on('failed', () => {
 			delete this._referSubscribers[id];
 		});
+		referSubscriber.on('authenticated', () => {
+			// Refer request authentication casues CSEQ and hence ID update.
+			delete this._referSubscribers[id];
+
+			id = referSubscriber.id;
+
+			this._referSubscribers[id] = referSubscriber;
+		});

 		return referSubscriber;
 	}
diff --git a/src/RTCSession/ReferSubscriber.js b/src/RTCSession/ReferSubscriber.js
index 26231ef..84d82e9 100644
--- a/src/RTCSession/ReferSubscriber.js
+++ b/src/RTCSession/ReferSubscriber.js
@@ -78,6 +78,10 @@ module.exports = class ReferSubscriber extends EventEmitter {
 				onDialogError: () => {
 					this._requestFailed(null, JsSIP_C.causes.DIALOG_ERROR);
 				},
+				onAuthenticated: _request => {
+					this._id = _request.cseq;
+					this.emit('authenticated');
+				},
 			},
 		});