JsSIP icon indicating copy to clipboard operation
JsSIP copied to clipboard

TypeScript types issues with DTFMOptions, Originator, SessionDirection

Open gavrya opened this issue 2 weeks ago • 5 comments

Typo in DTFMOptions TS type name. I belive it should be DTMFOptions instead of DTFMOptions:

export interface DTFMOptions extends ExtraHeaders {
  duration?: number;
  interToneGap?: number;
  transportType?: DTMF_TRANSPORT;
}

https://github.com/versatica/JsSIP/blob/master/lib/RTCSession.d.ts#L63


When I importOriginator enum type:

import { Originator } from 'jssip/lib/RTCSession';

And doing a comparison check:

session.on('progress', (event: IncomingEvent | OutgoingEvent) => {
  if (event.originator !== Originator.REMOTE) {
    return;
  }
  // some logic
});

I got a runtime error:

Uncaught TypeError: Cannot read properties of undefined (reading 'REMOTE')

https://github.com/versatica/JsSIP/blob/master/lib/RTCSession.d.ts#L22


The same is with the SessionDirection enum type.

When I importSessionDirection enum type:

import { SessionDirection } from 'jssip/lib/RTCSession';

And doing a comparison check:

const isIncomingSession = session.direction === SessionDirection.INCOMING;

I got a runtime error:

Uncaught TypeError: Cannot read properties of undefined (reading 'INCOMING')

https://github.com/versatica/JsSIP/blob/master/lib/RTCSession.d.ts#L17

gavrya avatar Dec 06 '25 10:12 gavrya

DTMFOptions typo has been fixed, thanks.

Regarding the other issue, it clearly seems that the typescript types (Originator, SessionDirection) are not being transpiled to JS, or at least not properly. Check the resulting .js file. It's definitely a matter of Typescript.

jmillan avatar Dec 09 '25 09:12 jmillan

Those types are probably TS enums so they are only available in the parent app is the parent app is a TS app rather than a JS app. TS converts enums to constants holding a real JS object, but if your app is directly written in pure JS then such a conversion is not done so you cannot import an enum from the JsSIP .d.ts file.

ibc avatar Dec 09 '25 10:12 ibc

I think that the Originator and SessionDirection are not exported from the lib at all as an enum (objects). package.json points to the "main": "lib-es5/JsSIP.js" and JsSIP.js is not exporting Originator and SessionDirection enum objects. They just defined inside a *.d.ts files. Ideally, if your lib wants to export them, they should be exported some how in JsSIP.js.

gavrya avatar Dec 09 '25 13:12 gavrya

Probably those constants should be created and exported in jssip/lib/RTCSession.js file:

https://github.com/versatica/JsSIP/blob/3.10.2/lib/RTCSession.js

according to the declaration file:

https://github.com/versatica/JsSIP/blob/3.10.2/lib/RTCSession.d.ts

gavrya avatar Dec 09 '25 15:12 gavrya

VSCode shows me that import from 'jssip/lib/RTCSession' should return an object with four keys according to the lib/RTCSession.d.ts declaration.

However, in reality, import jssip/lib/RTCSession resolves to a lib/RTCSession.js, which exports only one single class using a default export:

https://github.com/versatica/JsSIP/blob/3.10.2/lib/RTCSession.js#L41

I think that lib/RTCSession.js should return an object with four keys according to the lib/RTCSession.d.ts declaration file.

Image

gavrya avatar Dec 10 '25 07:12 gavrya

JsSIP is written in JS. TS declarations are defined separately, these are not compiled and hence they do not generate any JS code.

I'll suggest comparing with the real values instead: 'local', 'remote', 'system'.

jmillan avatar Dec 19 '25 15:12 jmillan