Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to compiler generated type declarations #668

Merged
merged 1 commit into from
Mar 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ module.exports = function (env) {
loader: "ts-loader",
options: {
compilerOptions: {
"declaration": false,
"outDir": mainDir + "/dist"
}
}
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "A simple, intuitive, and powerful JavaScript signaling library",
"version": "0.13.7",
"license": "MIT",
"main": "lib/index.js",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"homepage": "https://sipjs.com",
"author": "OnSIP <developer@onsip.com> (https://sipjs.com/aboutus/)",
"contributors": [
Expand Down Expand Up @@ -65,6 +66,5 @@
"commandLineTest": "npm run build-test && karma start --reporters mocha --browsers ChromeHeadless --single-run",
"buildAndTest": "npm run build && npm run commandLineTest",
"buildAndBrowserTest": "npm run build && npm run browserTest"
},
"types": "./types"
}
}
17 changes: 7 additions & 10 deletions src/ClientContext.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import { EventEmitter } from "events";

import { ClientContext as ClientContextDefinition } from "../types/client-context";
import { Logger } from "../types/logger-factory";
import { NameAddrHeader } from "../types/name-addr-header";
import { IncomingResponse, OutgoingRequest as OutgoingRequestType } from "../types/sip-message";
import { UA } from "../types/ua";
import { URI } from "../types/uri";

import { C } from "./Constants";
import { TypeStrings } from "./Enums";
import { Logger } from "./LoggerFactory";
import { NameAddrHeader } from "./NameAddrHeader";
import { RequestSender } from "./RequestSender";
import { OutgoingRequest } from "./SIPMessage";
import { IncomingResponse, OutgoingRequest } from "./SIPMessage";
import { UA } from "./UA";
import { URI } from "./URI";
import { Utils } from "./Utils";

export class ClientContext extends EventEmitter implements ClientContextDefinition {
export class ClientContext extends EventEmitter {
public static initializer(
objToConstruct: ClientContext,
ua: UA,
Expand Down Expand Up @@ -77,7 +74,7 @@ export class ClientContext extends EventEmitter implements ClientContextDefiniti
// inheritance issue with InviteClientContext
public ua!: UA;
public logger!: Logger;
public request!: OutgoingRequestType;
public request!: OutgoingRequest;
public method!: string;
public body: any;
public localIdentity!: NameAddrHeader;
Expand Down
31 changes: 14 additions & 17 deletions src/Dialogs.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import { Dialog as DialogDefinition } from "../types/dialogs";
import { Logger } from "../types/logger-factory";
import { InviteClientContext, InviteServerContext } from "../types/session";
import { SessionDescriptionHandler } from "../types/session-description-handler";
import { DTMF } from "../types/Session/dtmf";
import {
IncomingRequest,
IncomingResponse,
OutgoingRequest as OutgoingRequestType
} from "../types/sip-message";
import { Subscription } from "../types/subscription";
import { NonInviteClientTransaction } from "../types/transactions";
import { URI } from "../types/uri";

import { C } from "./Constants";
import { DialogStatus, SessionStatus, TypeStrings } from "./Enums";
import { Logger } from "./LoggerFactory";
import { RequestSender } from "./RequestSender";
import { OutgoingRequest } from "./SIPMessage";
import { InviteClientContext, InviteServerContext } from "./Session";
import { SessionDescriptionHandler } from "./session-description-handler";
import { DTMF } from "./Session/DTMF";
import {
IncomingRequest,
IncomingResponse,
OutgoingRequest
} from "./SIPMessage";
import { Subscription } from "./Subscription";
import {
InviteClientTransaction,
NonInviteClientTransaction,
TransactionState
} from "./Transactions";
import { URI } from "./URI";

/*
* @augments SIP
Expand All @@ -30,7 +27,7 @@ import {
* @param {Enum} state SIP.Dialog.C.STATUS_EARLY / SIP.Dialog.C.STATUS_CONFIRMED
*/

export class Dialog implements DialogDefinition {
export class Dialog {
public static readonly C = DialogStatus;

public type: TypeStrings;
Expand Down Expand Up @@ -260,7 +257,7 @@ export class Dialog implements DialogDefinition {
applicant: InviteClientContext | Subscription | DTMF,
method: string,
options: any = {}
): OutgoingRequestType {
): OutgoingRequest {
const extraHeaders: Array<string> = (options.extraHeaders || []).slice();

let body: any;
Expand Down
12 changes: 5 additions & 7 deletions src/DigestAuthentication.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import * as MD5 from "crypto-js/md5";

import { DigestAuthentication as DigestAuthenticationDefinition } from "../types/digest-authentication";
import { Logger } from "../types/logger-factory";
import { OutgoingRequest } from "../types/sip-message";
import { UA } from "../types/ua";
import { URI } from "../types/uri";

import { TypeStrings } from "./Enums";
import { Logger } from "./LoggerFactory";
import { OutgoingRequest } from "./SIPMessage";
import { UA } from "./UA";
import { URI } from "./URI";
import { Utils } from "./Utils";

/**
Expand All @@ -15,7 +13,7 @@ import { Utils } from "./Utils";
* @param {SIP.UA} ua
*/

export class DigestAuthentication implements DigestAuthenticationDefinition {
export class DigestAuthentication {
public type: TypeStrings;
public stale: boolean | undefined;

Expand Down
33 changes: 16 additions & 17 deletions src/Exceptions.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import {
Exception as ExceptionDefinition,
Exceptions as ExceptionsDefinition,
LegacyException as LegacyExceptionDefinition
} from "../types/exceptions";

import { SessionStatus, TypeStrings } from "./Enums";

// tslint:disable:max-classes-per-file

export abstract class Exception extends Error implements ExceptionDefinition {
/**
* An Exception is considered a condition that a reasonable application may wish to catch.
* An Error indicates serious problems that a reasonable application should not try to catch.
*/
export abstract class Exception extends Error {
protected constructor(message?: string) {
super(message); // 'Error' breaks prototype chain here
Object.setPrototypeOf(this, new.target.prototype); // restore prototype chain
}
}

export namespace Exceptions {
export class TransportError extends Exception
implements ExceptionsDefinition.TransportError {
/**
* Transport error.
*/
export class TransportError extends Exception {
constructor(message?: string) {
super(message ? message : "Unspecified transport error.");
}
Expand All @@ -31,7 +31,7 @@ export namespace Exceptions {
* "code" numbers and constant "name" strings. All of that is unnecessary when using
* TypeScript, inheriting from Error and properly setting up the prototype chain...
*/
abstract class LegacyException extends Exception implements LegacyExceptionDefinition {
abstract class LegacyException extends Exception {
public type!: TypeStrings;
public name: string;
public message: string;
Expand All @@ -46,7 +46,7 @@ abstract class LegacyException extends Exception implements LegacyExceptionDefin
}

export namespace Exceptions {
export class ConfigurationError extends LegacyException implements ExceptionsDefinition.ConfigurationError {
export class ConfigurationError extends LegacyException {
public parameter: string;
public value: any;

Expand All @@ -59,7 +59,7 @@ export namespace Exceptions {
}
}

export class InvalidStateError extends LegacyException implements ExceptionsDefinition.InvalidStateError {
export class InvalidStateError extends LegacyException {
public status: SessionStatus;

constructor(status: SessionStatus) {
Expand All @@ -69,7 +69,7 @@ export namespace Exceptions {
}
}

export class NotSupportedError extends LegacyException implements ExceptionsDefinition.NotSupportedError {
export class NotSupportedError extends LegacyException {
constructor(message: string) {
super(3, "NOT_SUPPORTED_ERROR", message);
this.type = TypeStrings.NotSupportedError;
Expand All @@ -78,14 +78,14 @@ export namespace Exceptions {

// 4 was GetDescriptionError, which was deprecated and now removed

export class RenegotiationError extends LegacyException implements ExceptionsDefinition.RenegotiationError {
export class RenegotiationError extends LegacyException {
constructor(message: string) {
super(5, "RENEGOTIATION_ERROR", message);
this.type = TypeStrings.RenegotiationError;
}
}

export class MethodParameterError extends LegacyException implements ExceptionsDefinition.MethodParameterError {
export class MethodParameterError extends LegacyException {
public method: string;
public parameter: string;
public value: any;
Expand All @@ -103,8 +103,7 @@ export namespace Exceptions {

// 7 was TransportError, which was replaced

export class SessionDescriptionHandlerError extends LegacyException
implements ExceptionsDefinition.SessionDescriptionHandlerError {
export class SessionDescriptionHandlerError extends LegacyException {
public error: string | undefined;
public method: string;

Expand Down
4 changes: 2 additions & 2 deletions src/Grammar.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as pegGrammar from "./Grammar/dist/Grammar";

import { NameAddrHeader } from "../types/name-addr-header";
import { URI } from "../types/uri";
import { NameAddrHeader } from "./NameAddrHeader";
import { URI } from "./URI";

export namespace Grammar {
export function parse(input: string, startRule: string): any {
Expand Down
9 changes: 2 additions & 7 deletions src/LoggerFactory.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import {
Logger as LoggerDefinition,
LoggerFactory as LoggerFactoryDefinition
} from "../types/logger-factory";

import { TypeStrings } from "./Enums";

export enum Levels {
Expand All @@ -12,7 +7,7 @@ export enum Levels {
debug
}

export class LoggerFactory implements LoggerFactoryDefinition {
export class LoggerFactory {
public type: TypeStrings;
public builtinEnabled: boolean = true;

Expand Down Expand Up @@ -94,7 +89,7 @@ export class LoggerFactory implements LoggerFactoryDefinition {
}

// tslint:disable-next-line:max-classes-per-file
export class Logger implements LoggerDefinition {
export class Logger {
public type: TypeStrings;

private logger: LoggerFactory;
Expand Down
7 changes: 2 additions & 5 deletions src/NameAddrHeader.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { NameAddrHeader as NameAddrHeaderDefinition } from "../types/name-addr-header";
import { URI } from "../types/uri";

import { TypeStrings } from "./Enums";
import { Parameters } from "./URI";
import { Parameters, URI } from "./URI";

/**
* @class Class creating a Name Address SIP header.
Expand All @@ -12,7 +9,7 @@ import { Parameters } from "./URI";
* @param {Object} [parameters]
*
*/
export class NameAddrHeader extends Parameters implements NameAddrHeaderDefinition {
export class NameAddrHeader extends Parameters {
public type: TypeStrings;
public uri: URI;
// tslint:disable-next-line:variable-name
Expand Down
5 changes: 2 additions & 3 deletions src/Parser.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Logger } from "../types/logger-factory";
import { UA } from "../types/ua";

import { TypeStrings } from "./Enums";
import { Grammar } from "./Grammar";
import { Logger } from "./LoggerFactory";
import { IncomingRequest, IncomingResponse } from "./SIPMessage";
import { UA } from "./UA";
// SIP.Parser = Parser;

/**
Expand Down
13 changes: 5 additions & 8 deletions src/PublishContext.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import { PublishContext as PublishContextDefinition } from "../types/publish-context";
import { IncomingResponse } from "../types/sip-message";
import { Transport } from "../types/transport";
import { UA } from "../types/ua";
import { URI } from "../types/uri";

import { ClientContext } from "./ClientContext";
import { C } from "./Constants";
import { TypeStrings } from "./Enums";
import { Exceptions } from "./Exceptions";
import { OutgoingRequest } from "./SIPMessage";
import { IncomingResponse, OutgoingRequest } from "./SIPMessage";
import { Transport } from "./Transport";
import { UA } from "./UA";
import { URI } from "./URI";
import { Utils } from "./Utils";

/**
* SIP Publish (SIP Extension for Event State Publication RFC3903)
* @class Class creating a SIP PublishContext.
*/
export class PublishContext extends ClientContext implements PublishContextDefinition {
export class PublishContext extends ClientContext {
public type: TypeStrings;

private options: any;
Expand Down
15 changes: 7 additions & 8 deletions src/React/SessionDescriptionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ import {
RTCPeerConnection,
} from "react-native-webrtc";

import { Logger } from "../../types/logger-factory";
import { InviteClientContext, InviteServerContext } from "../../types/session";
import { TypeStrings } from "../Enums";
import { Exceptions } from "../Exceptions";
import { Logger } from "../LoggerFactory";
import { InviteClientContext, InviteServerContext } from "../Session";
import {
BodyObj,
SessionDescriptionHandler as SessionDescriptionHandlerDefinition,
SessionDescriptionHandlerModifiers
} from "../../types/session-description-handler";
import { Utils as UtilsTypes } from "../../types/utils";

import { TypeStrings } from "../Enums";
import { Exceptions } from "../Exceptions";
} from "../session-description-handler";
import { Utils } from "../Utils";

import * as Modifiers from "../Web/Modifiers";
import { SessionDescriptionHandlerObserver } from "./SessionDescriptionHandlerObserver";

Expand All @@ -38,7 +37,7 @@ export class SessionDescriptionHandler extends EventEmitter implements SessionDe
private C: any;
private modifiers: SessionDescriptionHandlerModifiers;
private WebRTC: any;
private iceGatheringDeferred: UtilsTypes.Deferred<any> | undefined;
private iceGatheringDeferred: Utils.Deferred<any> | undefined;
private iceGatheringTimeout: boolean;
private iceGatheringTimer: any | undefined;
private constraints: any;
Expand Down
8 changes: 5 additions & 3 deletions src/React/SessionDescriptionHandlerObserver.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { InviteClientContext, InviteServerContext } from "../../types/session";

import { TypeStrings } from "../Enums";
import { InviteClientContext, InviteServerContext } from "../Session";
import {
SessionDescriptionHandlerObserver as SessionDescriptionHandlerObserverDefinition
} from "../session-description-handler-observer";

/* SessionDescriptionHandlerObserver
* @class SessionDescriptionHandler Observer Class.
* @param {SIP.Session} session
* @param {Object} [options]
*/

export class SessionDescriptionHandlerObserver {
export class SessionDescriptionHandlerObserver implements SessionDescriptionHandlerObserverDefinition {
public type: TypeStrings;
private session: InviteClientContext | InviteServerContext;
private options: any;
Expand Down
Loading