Commit 2139e5e for jssip.net
commit 2139e5e2063d509257c3392eca7323b9eea77399
Author: José Luis Millán <jmillan@aliax.net>
Date: Tue Dec 1 17:38:32 2026 +0100
comments (#1003)
diff --git a/src/Configuration.ts b/src/Configuration.ts
index 8dbccbb..8516ea1 100644
--- a/src/Configuration.ts
+++ b/src/Configuration.ts
@@ -30,7 +30,8 @@ export type Configuration = {
authorization_jwt: string | null;
// SIP account.
- /* NOTE: A number because `UA` allows a `0` to be given, which it then turns
+ /**
+ * NOTE: A number because `UA` allows a `0` to be given, which it then turns
* into '0'.
*/
display_name: string | number | null;
@@ -63,13 +64,14 @@ export type Configuration = {
// Global extra headers, to be added to every request and response
extra_headers: string[] | null;
- /*
- * Host address.
- * Value to be set in Via sent_by and host part of Contact FQDN.
+ /**
+ * Host address. Value to be set in Via sent_by and host part of Contact
+ * FQDN.
*/
via_host: string;
- /* NOTE: Optional because, unlike every other parameter, it has no default
+ /**
+ * NOTE: Optional because, unlike every other parameter, it has no default
* below. It only exists once the application configures it.
*/
user_agent?: string;
@@ -115,10 +117,8 @@ export const DEFAULT_CONFIGURATION: Configuration = {
// Global extra headers, to be added to every request and response
extra_headers: null,
- /*
- * Host address.
- * Value to be set in Via sent_by and host part of Contact FQDN.
- */
+ // Host address. Value to be set in Via sent_by and host part of
+ // Contact FQDN.
via_host: `${createRandomToken(12)}.invalid`,
};
@@ -134,7 +134,8 @@ type MandatoryParam = 'uri' | 'sockets';
*/
type OptionalParam = Exclude<keyof Configuration, MandatoryParam | 'via_host'>;
-/* NOTE: A check receives whatever the application passed, hence `unknown`.
+/**
+ * NOTE: A check receives whatever the application passed, hence `unknown`.
* Its return type is tied to the configuration parameter it populates, so a
* check can neither skip validating its input nor produce a value that
* parameter would not accept.
@@ -150,12 +151,12 @@ const checks: {
} = {
mandatory: {
sockets(sockets) {
- /* Allow defining sockets parameter as:
- * Socket: socket
- * Array of Socket: [socket1, socket2]
- * Array of Objects: [{socket: socket1, weight:1}, {socket: Socket2, weight:0}]
- * Array of Objects and Socket: [{socket: socket1}, socket2]
- */
+ // Allow defining sockets parameter as:
+ // - Socket: socket
+ // - Array of Socket: [socket1, socket2]
+ // - Array of Objects:
+ // [{socket: socket1, weight:1}, {socket: Socket2, weight:0}]
+ // - Array of Objects and Socket: [{socket: socket1}, socket2]
const _sockets: WeightedSocket[] = [];
if (isSocket(sockets)) {
@@ -179,9 +180,8 @@ const checks: {
},
uri(value) {
- /* NOTE: Coerced rather than rejected, since the regular expression and
- * the template below used to coerce it anyway.
- */
+ // NOTE: Coerced rather than rejected, since the regular expression
+ // and the template below coerce it anyway.
let uri = String(value);
if (!/^sip:/i.test(uri)) {
@@ -260,10 +260,8 @@ const checks: {
return undefined;
},
- /* NOTE: A number is accepted because `UA` turns a `0` into '0'. Anything
- * else used to be accepted too, only to fail later on when building a
- * `NameAddrHeader`.
- */
+ // NOTE: A number is accepted because `UA` turns a `0` into '0'. Anything
+ // else would fail later on when building a `NameAddrHeader`.
display_name(value) {
if (typeof value === 'string' || typeof value === 'number') {
return value;
@@ -360,9 +358,8 @@ const checks: {
register_from_tag_trail(value) {
if (typeof value === 'function') {
- /* NOTE: Whether it really takes no argument and returns a string
- * cannot be verified at runtime.
- */
+ // NOTE: Whether it really takes no argument and returns a string
+ // cannot be verified at runtime.
return value as () => string;
}
@@ -413,7 +410,8 @@ const checks: {
},
};
-/* NOTE: `dst[key] = value` cannot be expressed when `key` is a union, as
+/**
+ * NOTE: `dst[key] = value` cannot be expressed when `key` is a union, as
* TypeScript then requires the value to satisfy every member at once. The
* check that matters, that a check returns what its setting accepts, is
* already enforced by `ConfigCheck`.
@@ -451,9 +449,8 @@ export const load = (
if (Object.prototype.hasOwnProperty.call(src, parameter)) {
const value = src[parameter];
- /* If the parameter value is null, empty string, undefined, empty array
- * or it's a number with NaN value, then apply its default value.
- */
+ // If the parameter value is null, empty string, undefined, empty array
+ // or it's a number with NaN value, then apply its default value.
if (isEmpty(value)) {
continue;
}
diff --git a/src/Constants.ts b/src/Constants.ts
index df84da3..93ac385 100644
--- a/src/Constants.ts
+++ b/src/Constants.ts
@@ -74,7 +74,8 @@ export enum DTMF_TRANSPORT {
RFC2833 = 'RFC2833',
}
-/* SIP Response Reasons
+/**
+ * SIP Response Reasons
* DOC: https://www.iana.org/assignments/sip-parameters
* Copied from https://github.com/versatica/OverSIP/blob/master/lib/oversip/sip/constants.rb#L7
*/
diff --git a/src/Dialog.ts b/src/Dialog.ts
index 60c7d2b..62c362e 100644
--- a/src/Dialog.ts
+++ b/src/Dialog.ts
@@ -156,7 +156,8 @@ export class Dialog {
#incoming_ack_seqnum: number | null = null;
#outgoing_ack_seqnum: number | null = null;
- /* NOTE: Only set while there is a sequence number to remember.
+ /**
+ * NOTE: Only set while there is a sequence number to remember.
* `#local_seqnum` is lazily initialized by `#createRequest()` on dialogs
* created by an incoming request.
*/
@@ -190,9 +191,8 @@ export class Dialog {
state = message.status_code < 200 ? Status.EARLY : Status.CONFIRMED;
}
- /* NOTE: The non-null assertions below mirror the original implementation,
- * which throws if a mandatory header field is missing or unparseable.
- */
+ // NOTE: The non-null assertions below throw if a mandatory header field
+ // is missing or unparseable.
const contact = message.parseHeader<NameAddrHeader>('contact')!;
// RFC 3261 12.1.1.
@@ -295,9 +295,8 @@ export class Dialog {
// Increase the local CSeq on authentication.
eventHandlers.onAuthenticated = _request => {
- /* NOTE: `#createRequest()` above made sure there is a local sequence
- * number.
- */
+ // NOTE: `#createRequest()` above made sure there is a local sequence
+ // number.
this.#local_seqnum = (this.#local_seqnum ?? 0) + 1;
// In case of re-INVITE store outgoing ack_seqnum for its CANCEL or ACK.
@@ -383,9 +382,8 @@ export class Dialog {
// RFC 3261 12.2.2.
#checkInDialogRequest(request: IncomingRequest): boolean {
- /* NOTE: CSeq is a mandatory header field, so `sanityCheck` already dropped
- * the request if it had none.
- */
+ // NOTE: CSeq is a mandatory header field, so `sanityCheck` already
+ // dropped the request if it had none.
const cseq = request.cseq!;
if (!this.#remote_seqnum) {
@@ -409,9 +407,8 @@ export class Dialog {
this.#remote_seqnum = cseq;
}
- /* NOTE: An in-dialog request always reaches the dialog through its server
- * transaction, which the `UA` creates before routing it.
- */
+ // NOTE: An in-dialog request always reaches the dialog through its server
+ // transaction, which the `UA` creates before routing it.
const server_transaction = request.server_transaction!;
// RFC3261 14.2 Modifying an Existing Session -UAS BEHAVIOR-.
diff --git a/src/Dialog/RequestSender.ts b/src/Dialog/RequestSender.ts
index 4728d60..d7e3d59 100644
--- a/src/Dialog/RequestSender.ts
+++ b/src/Dialog/RequestSender.ts
@@ -90,12 +90,11 @@ export class DialogRequestSender {
const clientTransaction = request_sender.clientTransaction;
- /* RFC3261 14.2 Modifying an Existing Session -UAC BEHAVIOR-.
- *
- * NOTE: `send()` always creates the client transaction, and the `'state'
- * in` check just narrows out `AckClientTransaction` (the only one with no
- * state), which the method check already makes impossible here.
- */
+ // RFC3261 14.2 Modifying an Existing Session -UAC BEHAVIOR-.
+ //
+ // NOTE: `send()` always creates the client transaction, and the `'state'
+ // in` check just narrows out `AckClientTransaction` (the only one with no
+ // state), which the method check already makes impossible here.
if (
(this.#request.method === JsSIP_C.INVITE ||
(this.#request.method === JsSIP_C.UPDATE && this.#request.body)) &&
@@ -131,9 +130,8 @@ export class DialogRequestSender {
if (this.#reattempt) {
this.#eventHandlers.onErrorResponse(response);
} else {
- /* NOTE: The dialog always has a local sequence number here, since
- * `Dialog.sendRequest()` created the request being retried.
- */
+ // NOTE: The dialog always has a local sequence number here, since
+ // `Dialog.sendRequest()` created the request being retried.
const local_seqnum = (this.#dialog.local_seqnum ?? 0) + 1;
this.#dialog.local_seqnum = local_seqnum;
diff --git a/src/DigestAuthentication.ts b/src/DigestAuthentication.ts
index 35dbbb2..bc062db 100644
--- a/src/DigestAuthentication.ts
+++ b/src/DigestAuthentication.ts
@@ -3,7 +3,8 @@ import { calculateMD5, createRandomToken } from './Utils';
const logger = new Logger('DigestAuthentication');
-/* NOTE: All of them are nullable because they come straight from the UA
+/**
+ * NOTE: All of them are nullable because they come straight from the UA
* configuration, whose defaults are `null`.
*/
export type DigestCredentials = {
diff --git a/src/IncomingMessageBuilder.ts b/src/IncomingMessageBuilder.ts
index a75280f..272be57 100644
--- a/src/IncomingMessageBuilder.ts
+++ b/src/IncomingMessageBuilder.ts
@@ -28,13 +28,15 @@ export class IncomingMessageBuilder {
#via_branch?: string;
#call_id?: string;
#cseq?: number;
- /* NOTE: The method as given by the CSeq header field. A response takes its
+ /**
+ * NOTE: The method as given by the CSeq header field. A response takes its
* `method` from here, a request takes it from the request line.
*/
#cseq_method?: string;
#from?: NameAddrHeader;
#to?: NameAddrHeader;
- /* NOTE: `null` when the tag parameter is present but valueless (`;tag`),
+ /**
+ * NOTE: `null` when the tag parameter is present but valueless (`;tag`),
* `undefined` when it is absent altogether.
*/
#from_tag?: string | null;
@@ -185,10 +187,9 @@ export class IncomingMessageBuilder {
if (parsed) {
this.#cseq = parsed.value;
- /* NOTE: Only a response uses it, but it is recorded
- * unconditionally so that the builder does not need to know
- * which kind of message is being built.
- */
+ // NOTE: Only a response uses it, but it is recorded
+ // unconditionally so that the builder does not need to know
+ // which kind of message is being built.
this.#cseq_method = parsed.method;
}
break;
diff --git a/src/Parser.ts b/src/Parser.ts
index 1ac477d..ce848ca 100644
--- a/src/Parser.ts
+++ b/src/Parser.ts
@@ -40,9 +40,8 @@ export const parseMessage = (
let headerStart = headerEnd + 2;
- /* Loop over every line in data. Detect the end of each header and parse
- * it or simply add to the headers collection.
- */
+ // Loop over every line in data. Detect the end of each header and parse
+ // it or simply add to the headers collection.
while (true) {
headerEnd = getHeader(data, headerStart);
@@ -70,10 +69,8 @@ export const parseMessage = (
headerStart = headerEnd + 2;
}
- /* RFC3261 18.3.
- * If there are additional bytes in the transport packet
- * beyond the end of the body, they MUST be discarded.
- */
+ // RFC3261 18.3. If there are additional bytes in the transport packet
+ // beyond the end of the body, they MUST be discarded.
let body;
if (builder.hasHeader('content-length')) {
@@ -93,9 +90,8 @@ export const parseMessage = (
);
}
- /* RFC 3261 8.2.2.1. The grammar accepts any absoluteURI as Request-URI but
- * only turns a SIP one into a `URI`, so anything else cannot be handled.
- */
+ // RFC 3261 8.2.2.1. The grammar accepts any absoluteURI as Request-URI but
+ // only turns a SIP one into a `URI`, so anything else cannot be handled.
if (!parsed.uri) {
logger.warn(
`parseMessage() | unsupported Request-URI scheme in "${firstLine}"`
diff --git a/src/RTCSession.js b/src/RTCSession.js
index 4dc6b9d..051f382 100644
--- a/src/RTCSession.js
+++ b/src/RTCSession.js
@@ -409,14 +409,18 @@ module.exports = class RTCSession extends EventEmitter {
expires = request.getHeader('expires') * 1000;
}
- /* Set the to_tag before
- * replying a response code that will create a dialog.
- */
+ // Set the to_tag before
+ // replying a response code that will create a dialog.
request.to_tag = Utils.newTag();
- // An error on dialog creation will fire 'failed' event.
+ /**
+ * A dialog creation error can only be caused by the received request,
+ * since the To tag is set above.
+ *
+ * NOTE: `_createDialog()` reports it through the 'failed' event.
+ */
if (!this._createDialog(request, 'UAS', true)) {
- request.reply(500, 'Error creating dialog');
+ request.reply(400, 'Error creating dialog');
return;
}
@@ -435,9 +439,8 @@ module.exports = class RTCSession extends EventEmitter {
this._failed('local', null, JsSIP_C.causes.NO_ANSWER);
}, this._ua.configuration.no_answer_timeout);
- /* Set expiresTimer
- * RFC3261 13.3.1
- */
+ // Set expiresTimer
+ // RFC3261 13.3.1
if (expires) {
this._timers.expiresTimer = setTimeout(() => {
if (this._status === C.STATUS_WAITING_FOR_ANSWER) {
@@ -524,9 +527,14 @@ module.exports = class RTCSession extends EventEmitter {
this._status = C.STATUS_ANSWERED;
- // An error on dialog creation will fire 'failed' event.
+ /**
+ * A dialog creation error can only be caused by the received request,
+ * since the To tag is set above.
+ *
+ * NOTE: `_createDialog()` reports it through the 'failed' event.
+ */
if (!this._createDialog(request, 'UAS')) {
- request.reply(500, 'Error creating dialog');
+ request.reply(400, 'Error creating dialog');
return;
}
@@ -833,12 +841,11 @@ module.exports = class RTCSession extends EventEmitter {
);
}
- /* RFC 3261 section 15 (Terminating a session):
- *
- * "...the callee's UA MUST NOT send a BYE on a confirmed dialog
- * until it has received an ACK for its 2xx response or until the server
- * transaction times out."
- */
+ // RFC 3261 section 15 (Terminating a session):
+ //
+ // "...the callee's UA MUST NOT send a BYE on a confirmed dialog
+ // until it has received an ACK for its 2xx response or until the server
+ // transaction times out."
if (
this._status === C.STATUS_WAITING_FOR_ACK &&
this._direction === 'incoming' &&
@@ -1350,17 +1357,14 @@ module.exports = class RTCSession extends EventEmitter {
logger.debug('receiveRequest()');
if (request.method === JsSIP_C.CANCEL) {
- /* RFC3261 15 States that a UAS may have accepted an invitation while a CANCEL
- * was in progress and that the UAC MAY continue with the session established by
- * any 2xx response, or MAY terminate with BYE. JsSIP does continue with the
- * established session. So the CANCEL is processed only if the session is not yet
- * established.
- */
-
- /*
- * Terminate the whole session in case the user didn't accept (or yet send the answer)
- * nor reject the request opening the session.
- */
+ // RFC3261 15 States that a UAS may have accepted an invitation while a CANCEL
+ // was in progress and that the UAC MAY continue with the session established by
+ // any 2xx response, or MAY terminate with BYE. JsSIP does continue with the
+ // established session. So the CANCEL is processed only if the session is not yet
+ // established.
+
+ // Terminate the whole session in case the user didn't accept (or yet send the answer)
+ // nor reject the request opening the session.
if (
this._status === C.STATUS_WAITING_FOR_ANSWER ||
this._status === C.STATUS_ANSWERED
@@ -2544,10 +2548,8 @@ module.exports = class RTCSession extends EventEmitter {
response.status_code >= 200 &&
response.status_code <= 299
) {
- /*
- * If it is a retransmission from the endpoint that established
- * the dialog, send an ACK
- */
+ // If it is a retransmission from the endpoint that established
+ // the dialog, send an ACK
if (
this._dialog.id.call_id === response.call_id &&
this._dialog.id.local_tag === response.from_tag &&
diff --git a/src/RequestSender.ts b/src/RequestSender.ts
index 8d267b7..9f128b2 100644
--- a/src/RequestSender.ts
+++ b/src/RequestSender.ts
@@ -57,7 +57,8 @@ const DEFAULT_EVENT_HANDLERS: RequestSenderEventHandlers = {
};
export class RequestSender {
- /* NOTE: Not set by the constructor. Set by `send()`, which every applicant
+ /**
+ * NOTE: Not set by the constructor. Set by `send()`, which every applicant
* calls right after construction.
*/
clientTransaction?: ClientTransaction;
@@ -79,9 +80,8 @@ export class RequestSender {
this.#method = request.method;
this.#request = request;
- /* NOTE: Fills the given object in place, as the original implementation
- * does, so the applicant sees the defaults too.
- */
+ // NOTE: Fills the given object in place, so the applicant sees the
+ // defaults too.
this.#eventHandlers = Object.assign(eventHandlers, {
onRequestTimeout:
eventHandlers.onRequestTimeout ||
@@ -171,10 +171,8 @@ export class RequestSender {
let authorization_header_name: string;
const status_code = response.status_code;
- /*
- * Authentication
- * Authenticate once. _challenged_ flag used to avoid infinite authentications.
- */
+ // Authentication. Authenticate once, the _challenged_ flag is used to
+ // avoid infinite authentications.
if (
(status_code === 401 || status_code === 407) &&
(this.#ua.configuration.password !== null ||
diff --git a/src/SIPMessage.ts b/src/SIPMessage.ts
index 6bbb12f..3aa0a2a 100644
--- a/src/SIPMessage.ts
+++ b/src/SIPMessage.ts
@@ -76,15 +76,13 @@ export type OutgoingRequestParams = {
route_set?: OutgoingHeaderValue[];
};
-/*
- * TODO: The `*Like` types below are structural views of modules that are still
- * JavaScript. They are declared here so that this module stays a leaf of the
- * TypeScript migration. The real classes satisfy them structurally, so each one
- * must be replaced with a plain type import once its module is ported.
- *
- * Note that importing those modules only for their types does not create a
- * runtime require cycle, since type imports are erased.
- */
+// TODO: The `*Like` types below are structural views of modules that are still
+// JavaScript. They are declared here so that this module stays a leaf of the
+// TypeScript migration. The real classes satisfy them structurally, so each one
+// must be replaced with a plain type import once its module is ported.
+//
+// Note that importing those modules only for their types does not create a
+// runtime require cycle, since type imports are erased.
/**
* The client transaction an outgoing INVITE is bound to.
@@ -166,10 +164,12 @@ export class OutgoingRequest {
call_id: string;
cseq: number;
- /* NOTE: `declare`d (and so not emitted) because the original implementation
- * does not create these own properties in the constructor. `sdp` is created
- * by `parseSDP()` and `transaction` is assigned by `Transactions.js` when
- * the request is sent.
+ /**
+ * NOTE: `declare` makes TypeScript generate no field declaration for
+ * these, so they do not become own properties set to `undefined` on every
+ * instance, which is what `useDefineForClassFields` would otherwise do.
+ * `sdp` is created by `parseSDP()` and `transaction` is assigned by
+ * `Transactions` when the request is sent.
*/
declare sdp?: SDP;
declare transaction?: ClientTransactionLike | null;
@@ -213,8 +213,7 @@ export class OutgoingRequest {
this.setHeader('route', `<${ua.transport.sip_uri};lr>`);
}
- // Via.
- // Empty Via header. Will be filled by the client transaction.
+ // Via. Empty header, will be filled by the client transaction.
this.setHeader('via', '');
// Max-Forwards.
@@ -223,8 +222,8 @@ export class OutgoingRequest {
// To
const to_uri = params.to_uri || ruri;
const to_params = params.to_tag ? { tag: params.to_tag } : null;
- // NOTE: `NameAddrHeader` tolerates a `null` display name (its setter
- // stores it as is), so the cast keeps the original behaviour.
+ // NOTE: `NameAddrHeader` tolerates a `null` display name, its setter
+ // stores it as is, hence the cast.
const to_display_name = (
typeof params.to_display_name !== 'undefined'
? params.to_display_name
@@ -446,9 +445,6 @@ export class OutgoingRequest {
clone(): OutgoingRequest {
const request = new OutgoingRequest(this.method, this.ruri, this.ua);
- // NOTE: An arrow function is used instead of the original `function` plus
- // `thisArg` so that `this` is properly typed. Iteration and assignment
- // order are unchanged.
Object.keys(this.headers).forEach(name => {
request.headers[name] = this.headers[name]!.slice();
});
@@ -465,8 +461,9 @@ export class OutgoingRequest {
}
export class InitialOutgoingInviteRequest extends OutgoingRequest {
- /* NOTE: Unlike in `OutgoingRequest`, this is a real (emitted) field because
- * the original implementation does assign it in the constructor.
+ /**
+ * NOTE: Unlike in `OutgoingRequest`, declared normally, so every instance
+ * gets it as an own property initialized to `null`.
*/
override transaction: ClientTransactionLike | null = null;
@@ -519,7 +516,8 @@ export type IncomingMessageParams = {
call_id?: string;
cseq?: number;
from: NameAddrHeader;
- /* NOTE: `null` when the tag parameter is present but valueless (`;tag`),
+ /**
+ * NOTE: `null` when the tag parameter is present but valueless (`;tag`),
* `undefined` when it is absent altogether.
*/
from_tag?: string | null;
@@ -544,12 +542,11 @@ export type IncomingResponseParams = IncomingMessageParams & {
};
export class IncomingMessage {
- /* Header store operations.
- *
- * They are static so that `IncomingMessageBuilder` can collect and parse
- * header fields before any `IncomingMessage` exists. The instance methods
- * of the same name delegate to them.
- */
+ // Header store operations.
+ //
+ // They are static so that `IncomingMessageBuilder` can collect and parse
+ // header fields before any `IncomingMessage` exists. The instance methods
+ // of the same name delegate to them.
/**
* Insert a header of the given name and value into the last position of the
@@ -851,15 +848,13 @@ export class IncomingRequest extends IncomingMessage {
onFailure?: () => void
): void {
const supported: string[] = [];
- /* NOTE: `getHeader()` may return undefined, but a To header field is
- * guaranteed here: `IncomingMessageBuilder` refuses to build a message
- * whose To header field is missing or unparseable.
- */
+ // NOTE: `getHeader()` may return undefined, but a To header field is
+ // guaranteed here: `IncomingMessageBuilder` refuses to build a message
+ // whose To header field is missing or unparseable.
let to = this.getHeader('To');
- // NOTE: `code` is normalized into a local (instead of onto the parameter
- // itself) so that the `TypeError` message below is identical to the one
- // of the original implementation.
+ // NOTE: `code` is normalized into a local rather than onto the parameter
+ // itself, so that the `TypeError` below reports the value as it was given.
const status_code: number | null = code || null;
reason = reason || null;
@@ -1003,10 +998,9 @@ export class IncomingRequest extends IncomingMessage {
response += `Via: ${via}\r\n`;
}
- /* NOTE: `getHeader()` may return undefined, but a To header field is
- * guaranteed here: `IncomingMessageBuilder` refuses to build a message
- * whose To header field is missing or unparseable.
- */
+ // NOTE: `getHeader()` may return undefined, but a To header field is
+ // guaranteed here: `IncomingMessageBuilder` refuses to build a message
+ // whose To header field is missing or unparseable.
let to = this.getHeader('To');
if (!this.to_tag && code > 100) {
diff --git a/src/Subscriber.js b/src/Subscriber.js
index aa197c4..2166db1 100644
--- a/src/Subscriber.js
+++ b/src/Subscriber.js
@@ -250,10 +250,9 @@ module.exports = class Subscriber extends EventEmitter {
return;
}
- /* The dialog is created by an incoming request, so it has no local
- * sequence number yet. Continue the sequence of the initial SUBSCRIBE,
- * otherwise the refresh would use a random (possibly lower) CSeq.
- */
+ // The dialog is created by an incoming request, so it has no local
+ // sequence number yet. Continue the sequence of the initial SUBSCRIBE,
+ // otherwise the refresh would use a random (possibly lower) CSeq.
dialog.local_seqnum = this._initial_cseq;
this._dialog = dialog;
@@ -643,19 +642,17 @@ module.exports = class Subscriber extends EventEmitter {
}
_scheduleSubscribe(expires) {
- /*
- If the expires time is less than 140 seconds we do not support Chrome intensive timer throttling mode.
- In this case, the re-subcribe is sent 5 seconds before the subscription expiration.
-
- When Chrome is in intensive timer throttling mode, in the worst case,
- the timer will be 60 seconds late.
- We give the server 10 seconds to make sure it will execute the command even if it is heavily loaded.
- As a result, we order the time no later than 70 seconds before the subscription expiration.
- Resulting time calculated as half time interval + (half interval - 70) * random.
-
- E.g. expires is 140, re-subscribe will be ordered to send in 70 seconds.
- expires is 600, re-subscribe will be ordered to send in 300 + (0 .. 230) seconds.
- */
+ // If the expires time is less than 140 seconds we do not support Chrome intensive timer throttling mode.
+ // In this case, the re-subcribe is sent 5 seconds before the subscription expiration.
+ //
+ // When Chrome is in intensive timer throttling mode, in the worst case,
+ // the timer will be 60 seconds late.
+ // We give the server 10 seconds to make sure it will execute the command even if it is heavily loaded.
+ // As a result, we order the time no later than 70 seconds before the subscription expiration.
+ // Resulting time calculated as half time interval + (half interval - 70) * random.
+ //
+ // E.g. expires is 140, re-subscribe will be ordered to send in 70 seconds.
+ // expires is 600, re-subscribe will be ordered to send in 300 + (0 .. 230) seconds.
const timeout =
expires >= 140
diff --git a/src/Transactions.ts b/src/Transactions.ts
index b3c3bf0..d62b038 100644
--- a/src/Transactions.ts
+++ b/src/Transactions.ts
@@ -89,7 +89,8 @@ export class NonInviteClientTransaction extends EventEmitter {
request: SIPMessage.OutgoingRequest;
eventHandlers: ClientTransactionEventHandlers;
- /* NOTE: Not set by the constructor. `state` is set by `stateChanged()` and
+ /**
+ * NOTE: Not set by the constructor. `state` is set by `stateChanged()` and
* the timer handles when their timers are armed.
*/
state?: Status;
@@ -205,7 +206,8 @@ export class InviteClientTransaction extends EventEmitter {
request: SIPMessage.OutgoingRequest;
eventHandlers: ClientTransactionEventHandlers;
- /* NOTE: Not set by the constructor. `state` is set by `stateChanged()` and
+ /**
+ * NOTE: Not set by the constructor. `state` is set by `stateChanged()` and
* the timer handles when their timers are armed.
*/
state?: Status;
@@ -299,10 +301,8 @@ export class InviteClientTransaction extends EventEmitter {
}
sendACK(response: SIPMessage.IncomingResponse): void {
- /* NOTE: The non-null assertions below just reproduce the original
- * behaviour: the header getters are typed as possibly `undefined` but
- * their value is forwarded unconditionally.
- */
+ // NOTE: The header getters are typed as possibly `undefined`, but their
+ // value is forwarded unconditionally.
const ack = new SIPMessage.OutgoingRequest(
JsSIP_C.ACK,
this.request.ruri,
@@ -449,7 +449,8 @@ export class NonInviteServerTransaction extends EventEmitter {
last_response: string;
state: Status;
- /* NOTE: Not set by the constructor. `transportError` is set by
+ /**
+ * NOTE: Not set by the constructor. `transportError` is set by
* `onTransportError()` and `J` when its timer is armed.
*/
transportError?: boolean;
@@ -507,11 +508,8 @@ export class NonInviteServerTransaction extends EventEmitter {
onFailure?: () => void
): void {
if (status_code === 100) {
- /* RFC 4320 4.1
- * 'A SIP element MUST NOT
- * send any provisional response with a
- * Status-Code other than 100 to a non-INVITE request.'
- */
+ // RFC 4320 4.1 'A SIP element MUST NOT send any provisional response
+ // with a Status-Code other than 100 to a non-INVITE request.'
switch (this.state) {
case Status.TRYING: {
this.stateChanged(Status.PROCEEDING);
@@ -570,7 +568,8 @@ export class InviteServerTransaction extends EventEmitter {
state: Status;
resendProvisionalTimer: ReturnType<typeof setInterval> | null;
- /* NOTE: Not set by the constructor. `transportError` is set by
+ /**
+ * NOTE: Not set by the constructor. `transportError` is set by
* `onTransportError()` and the timer handles when their timers are armed.
*/
transportError?: boolean;
@@ -692,12 +691,10 @@ export class InviteServerTransaction extends EventEmitter {
}, Timers.PROVISIONAL_RESPONSE_INTERVAL);
}
} else if (status_code >= 200 && status_code <= 299) {
- /* NOTE: The original implementation lets the `Status.PROCEEDING`
- * case fall through into the `Status.ACCEPTED` one. TypeScript's
- * `noFallthroughCasesInSwitch` forbids that, so the proceeding part
- * is guarded by the state read before entering the switch, which is
- * exactly when the original evaluates the switch discriminant.
- */
+ // NOTE: `noFallthroughCasesInSwitch` forbids falling from the
+ // `Status.PROCEEDING` case into the `Status.ACCEPTED` one, so the
+ // proceeding part is guarded by the state read before entering the
+ // switch.
const was_proceeding = this.state === Status.PROCEEDING;
switch (this.state) {
@@ -779,10 +776,8 @@ export function checkTransaction(
{ _transactions }: { _transactions: TransactionRegistry },
request: SIPMessage.IncomingRequest
): boolean | undefined {
- /* NOTE: The original implementation uses a single `let tr` declared before
- * the switch. It is declared per case here so that each one gets the
- * matching transaction type; the variable was never read across cases.
- */
+ // NOTE: `tr` is declared per case so that each one gets the matching
+ // transaction type.
switch (request.method) {
case JsSIP_C.INVITE: {
const tr = _transactions.ist[request.via_branch!];
diff --git a/src/Transport.ts b/src/Transport.ts
index 87f7d88..9930da7 100644
--- a/src/Transport.ts
+++ b/src/Transport.ts
@@ -68,7 +68,7 @@ export type TransportDataEvent = {
message: string;
};
-/*
+/**
* Manages one or multiple JsSIP.Socket instances.
* Is reponsible for transport recovery logic among all socket instances.
*
diff --git a/src/UA.js b/src/UA.js
index 31dc25f..3afaf7a 100644
--- a/src/UA.js
+++ b/src/UA.js
@@ -21,7 +21,8 @@ const config = require('./Configuration');
const logger = new Logger('UA');
-/* How long stop() waits for the transactions pending at that moment, so that
+/**
+ * How long stop() waits for the transactions pending at that moment, so that
* the requests it sends (un-REGISTER, BYE, un-SUBSCRIBE) get a chance to be
* answered before the transport goes away.
*/
@@ -354,9 +355,8 @@ module.exports = class UA extends EventEmitter {
this._status = C.STATUS_USER_CLOSED;
- /* Give some time for the requests sent above to be answered. _mayClose()
- * closes as soon as they are.
- */
+ // Give some time for the requests sent above to be answered. _mayClose()
+ // closes as soon as they are.
this._closeTimer = setTimeout(() => this._close(), CLOSE_TIMEOUT);
this._mayClose();
@@ -622,11 +622,10 @@ module.exports = class UA extends EventEmitter {
/* eslint-enable no-new */
}
- /* RFC3261 12.2.2
- * Requests that do not change in any way the state of a dialog may be
- * received within a dialog (for example, an OPTIONS request).
- * They are processed as if they had been received outside the dialog.
- */
+ // RFC3261 12.2.2
+ // Requests that do not change in any way the state of a dialog may be
+ // received within a dialog (for example, an OPTIONS request).
+ // They are processed as if they had been received outside the dialog.
if (method === JsSIP_C.OPTIONS) {
if (this.listeners('newOptions').length === 0) {
request.reply(200);
@@ -714,10 +713,9 @@ module.exports = class UA extends EventEmitter {
break;
}
case JsSIP_C.ACK: {
- /* Absorb it.
- * ACK request without a corresponding Invite Transaction
- * and without To tag.
- */
+ // Absorb it.
+ // ACK request without a corresponding Invite Transaction
+ // and without To tag.
break;
}
case JsSIP_C.NOTIFY: {
@@ -772,11 +770,10 @@ module.exports = class UA extends EventEmitter {
}
}
} else if (method !== JsSIP_C.ACK) {
- /* RFC3261 12.2.2
- * Request with to tag, but no matching dialog found.
- * Exception: ACK for an Invite request for which a dialog has not
- * been created.
- */
+ // RFC3261 12.2.2
+ // Request with to tag, but no matching dialog found.
+ // Exception: ACK for an Invite request for which a dialog has not
+ // been created.
request.reply(481);
}
}
@@ -837,17 +834,15 @@ module.exports = class UA extends EventEmitter {
return true;
}
- /* The registrar is free to choose how the GRUUs it grants look (RFC
- * 5627, Appendix A), and this UA advertises them in the Contact header
- * of its outgoing requests, so requests targeted at them point to us.
- */
+ // The registrar is free to choose how the GRUUs it grants look (RFC
+ // 5627, Appendix A), and this UA advertises them in the Contact header
+ // of its outgoing requests, so requests targeted at them point to us.
for (const gruu of [this._contact.pub_gruu, this._contact.temp_gruu]) {
const uri = gruu ? URI.parse(gruu) : undefined;
- /* Compare AORs plus the 'gr' parameter, which is what identifies the
- * instance (RFC 5627, Section 3.1). Any other parameter a proxy may
- * have added on the way takes no part in the match.
- */
+ // Compare AORs plus the 'gr' parameter, which is what identifies the
+ // instance (RFC 5627, Section 3.1). Any other parameter a proxy may
+ // have added on the way takes no part in the match.
if (
uri &&
uri.toAor() === ruri.toAor() &&
@@ -1170,10 +1165,9 @@ function onTransportData(data) {
message.transport = transport;
this.receiveRequest(message);
} else if (message instanceof SIPMessage.IncomingResponse) {
- /* Unike stated in 18.1.2, if a response does not match
- * any transaction, it is discarded here and no passed to the core
- * in order to be discarded there.
- */
+ // Unike stated in 18.1.2, if a response does not match
+ // any transaction, it is discarded here and no passed to the core
+ // in order to be discarded there.
let transaction;
diff --git a/src/URI.ts b/src/URI.ts
index e3ebb2f..730c0cc 100644
--- a/src/URI.ts
+++ b/src/URI.ts
@@ -256,8 +256,8 @@ class URI {
// NOTE: `URI` is exported with `export =` because the pegjs generated
// `Grammar.js` does `var URI = require('./URI')` and then `new URI(...)`.
-// Types that used to be named exports of this module are merged into the
-// `URI` namespace so that they remain reachable.
+// The types below are merged into the `URI` namespace so that they remain
+// reachable.
// eslint-disable-next-line @typescript-eslint/no-namespace
declare namespace URI {
type URIScheme = 'sip' | string;
diff --git a/src/sanityCheck.ts b/src/sanityCheck.ts
index 2e5a9b8..bbdf0c3 100644
--- a/src/sanityCheck.ts
+++ b/src/sanityCheck.ts
@@ -74,24 +74,22 @@ export const sanityCheck = (
return true;
};
-/*
- * Sanity Check for incoming Messages
- *
- * Requests:
- * - _rfc3261_8_2_2_1_ Receive a Request with a non supported URI scheme
- * - _rfc3261_16_3_4_ Receive a Request already sent by us
- * Does not look at via sent-by but at jssip_id, which is inserted as
- * a prefix in all initial requests generated by the ua
- * - _rfc3261_18_3_request_ Body Content-Length
- * - _rfc3261_8_2_2_2_ Merged Requests
- *
- * Responses:
- * - _rfc3261_8_1_3_3_ Multiple Via headers
- * - _rfc3261_18_3_response_ Body Content-Length
- *
- * All:
- * - Minimum headers in a SIP message
- */
+// Sanity Check for incoming Messages
+//
+// Requests:
+// - _rfc3261_8_2_2_1_ Receive a Request with a non supported URI scheme
+// - _rfc3261_16_3_4_ Receive a Request already sent by us
+// Does not look at via sent-by but at jssip_id, which is inserted as
+// a prefix in all initial requests generated by the ua
+// - _rfc3261_18_3_request_ Body Content-Length
+// - _rfc3261_8_2_2_2_ Merged Requests
+//
+// Responses:
+// - _rfc3261_8_1_3_3_ Multiple Via headers
+// - _rfc3261_18_3_response_ Body Content-Length
+//
+// All:
+// - Minimum headers in a SIP message
// Sanity Check functions for requests.
function rfc3261_8_2_2_1(
diff --git a/src/test/include/sipMessage.ts b/src/test/include/sipMessage.ts
index 89f2105..f64fe93 100644
--- a/src/test/include/sipMessage.ts
+++ b/src/test/include/sipMessage.ts
@@ -180,9 +180,8 @@ function assemble(
fields.push(`Content-Type: ${options.contentType}`);
}
- /* JsSIP's parser reads the body as data.substr(start, Content-Length), so
- * this counts characters rather than bytes.
- */
+ // JsSIP's parser reads the body as data.substr(start, Content-Length), so
+ // this counts characters rather than bytes.
fields.push(`Content-Length: ${payload.length}`);
return [firstLine, ...fields, '', payload].join(CRLF);
diff --git a/src/test/test-Dialog.ts b/src/test/test-Dialog.ts
index c406929..5e8feee 100644
--- a/src/test/test-Dialog.ts
+++ b/src/test/test-Dialog.ts
@@ -18,9 +18,8 @@ const REMOTE = '<sip:bob@example.com>';
const CONTACT = 'Contact: <sip:bob@abcdefabcdef.invalid;transport=ws>';
describe('Dialog.Create()', () => {
- /* The dialogs below are never used, so the owner only has to carry the `ua`
- * that `Create()` registers them with.
- */
+ // The dialogs below are never used, so the owner only has to carry the `ua`
+ // that `Create()` registers them with.
const dialogs: Dialog[] = [];
const owner = {
@@ -53,9 +52,8 @@ describe('Dialog.Create()', () => {
extraHeaders: ['Event: weather', 'Expires: 3600', ...fields],
});
- /* A started UA does satisfy UALike, but no exported type says so: see
- * the TODO on 'Configuration', which UA mutates after loading it.
- */
+ // A started UA does satisfy UALike, but no exported type says so: see
+ // the TODO on 'Configuration', which UA mutates after loading it.
const message = Parser.parseMessage(data, ua as unknown as UALike);
if (!message) {
@@ -140,10 +138,9 @@ async function subscribeStatus(fields: string[]): Promise<number | undefined> {
await delay(50);
- /* A notifier that got its dialog arms an expires timer, and `UA.stop()`
- * does not terminate notifiers the way it does sessions and subscribers,
- * so the timer would outlive the test.
- */
+ // A notifier that got its dialog arms an expires timer, and `UA.stop()`
+ // does not terminate notifiers the way it does sessions and subscribers,
+ // so the timer would outlive the test.
if (notifier?.id) {
notifier.terminate();
}
@@ -154,10 +151,9 @@ async function subscribeStatus(fields: string[]): Promise<number | undefined> {
}
describe('notifier receiving a SUBSCRIBE that cannot establish a dialog', () => {
- /* Not 400: `Notifier.checkSubscribe()` rejects a SUBSCRIBE with no Contact
- * before the UA even emits 'newSubscribe', so `Dialog.Create()` never sees
- * it. Asserted so that the earlier gate is not removed unnoticed.
- */
+ // Not 400: `Notifier.checkSubscribe()` rejects a SUBSCRIBE with no Contact
+ // before the UA even emits 'newSubscribe', so `Dialog.Create()` never sees
+ // it. Asserted so that the earlier gate is not removed unnoticed.
test('answers a SUBSCRIBE with no Contact', async () => {
await expect(
subscribeStatus([`From: ${REMOTE};tag=remotetag`])
diff --git a/src/test/test-RTCSession.ts b/src/test/test-RTCSession.ts
index 8b5497d..c0e88d9 100644
--- a/src/test/test-RTCSession.ts
+++ b/src/test/test-RTCSession.ts
@@ -14,7 +14,8 @@ const PEER_URI = 'sip:bob@example.com';
const PEER_CONTACT = 'sip:bob@192.0.2.1:5060';
const PEER_TAG = 'peertag';
-/* The session events worth logging. 'failed' is among them so that a call
+/**
+ * The session events worth logging. 'failed' is among them so that a call
* that goes wrong shows up in the log instead of as a timeout.
*/
enum EVENT {
@@ -139,10 +140,9 @@ describe('RTCSession', () => {
await ended;
- /* This costs the whole UA close timeout: the INVITE client transaction
- * stays in 'accepted' for Timer M (RFC 6026, Section 7.2), so the UA
- * never looks idle.
- */
+ // This costs the whole UA close timeout: the INVITE client transaction
+ // stays in 'accepted' for Timer M (RFC 6026, Section 7.2), so the UA
+ // never looks idle.
await stopUA(ua);
expect(events).toEqual([
diff --git a/src/test/test-SubscriberNotifier.ts b/src/test/test-SubscriberNotifier.ts
index 043ac46..87bcdf4 100644
--- a/src/test/test-SubscriberNotifier.ts
+++ b/src/test/test-SubscriberNotifier.ts
@@ -76,7 +76,8 @@ describe('subscriber/notifier communication', () => {
};
type Result = {
- /* The subscriber, which is where the termination codes live: they are
+ /**
+ * The subscriber, which is where the termination codes live: they are
* a plain object in the implementation, not reachable statically.
*/
subscriber: Subscriber;
diff --git a/src/test/test-parser.ts b/src/test/test-parser.ts
index dcd7fe3..5af6fb4 100644
--- a/src/test/test-parser.ts
+++ b/src/test/test-parser.ts
@@ -434,9 +434,8 @@ P-Preferred-Identity: "Cullen Jennings" <sip:fluffy@cisco.com>\r\n\r\n';
})
);
- /* A started UA does satisfy UALike, but no exported type says so: see the
- * TODO on 'Configuration', which UA mutates after loading it.
- */
+ // A started UA does satisfy UALike, but no exported type says so: see the
+ // TODO on 'Configuration', which UA mutates after loading it.
const message = Parser.parseMessage(data, ua as unknown as UALike);
if (!message) {