Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
James Criscuolo committed Jun 18, 2019
2 parents c3f995d + 263892a commit ad24f3c
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 262 deletions.
349 changes: 132 additions & 217 deletions package-lock.json

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "sip.js",
"title": "SIP.js",
"description": "A simple, intuitive, and powerful JavaScript signaling library",
"version": "0.14.4",
"version": "0.14.5",
"license": "MIT",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
Expand All @@ -26,12 +26,13 @@
"typescript"
],
"dependencies": {
"crypto-js": "^3.1.9-1"
"@types/node": "^12.0.8",
"crypto-js": "^3.1.9-1",
"tslib": "^1.10.0"
},
"devDependencies": {
"@types/crypto-js": "^3.1.43",
"@types/jasmine": "^3.3.13",
"@types/node": "^12.0.7",
"circular-dependency-plugin": "^5.0.2",
"jasmine-core": "^3.4.0",
"karma": "^4.1.0",
Expand All @@ -41,14 +42,14 @@
"karma-jasmine-html-reporter": "^1.4.2",
"karma-mocha-reporter": "^2.2.5",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^3.0.5",
"karma-webpack": "^4.0.2",
"pegjs": "^0.10.0",
"ts-loader": "^6.0.2",
"ts-loader": "^6.0.3",
"ts-pegjs": "0.2.5",
"tslint": "^5.17.0",
"typescript": "^3.5.1",
"webpack": "^4.33.0",
"webpack-cli": "^3.3.3"
"typescript": "^3.5.2",
"webpack": "^4.34.0",
"webpack-cli": "^3.3.4"
},
"engines": {
"node": ">=8.0"
Expand Down
4 changes: 0 additions & 4 deletions src/PublishContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ export class PublishContext extends ClientContext {
this.logger = ua.getLogger("sip.publish");

this.pubRequestExpires = this.options.expires;

ua.on("transportCreated", (transport: Transport) => {
transport.on("transportError", () => this.onTransportError());
});
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/RegisterContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,7 @@ export class RegisterContext extends ClientContext {
// Set status
this.registered = false;

ua.on("transportCreated", (transport: Transport): void => {
transport.on("disconnected", () => this.onTransportDisconnected());
});
ua.transport.on("disconnected", () => this.onTransportDisconnected());
}

public register(options: any = {}): void {
Expand Down
27 changes: 14 additions & 13 deletions src/UA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import {
} from "./Web/SessionDescriptionHandler";
import { Transport as WebTransport } from "./Web/Transport";

const environment = (global as any).window || global;
declare var chrome: any;

export namespace UA {
export interface Options {
Expand Down Expand Up @@ -161,7 +161,9 @@ export class UA extends EventEmitter {
private log: LoggerFactory;
private error: number | undefined;
private registerContext: RegisterContext;
private environListener: any;

/** Unload listener. */
private unloadListener = (() => { this.stop(); });

constructor(configuration?: UA.Options) {
super();
Expand Down Expand Up @@ -550,11 +552,11 @@ export class UA extends EventEmitter {
this.transport.disconnect();
this.userAgentCore.reset();

if (typeof environment.removeEventListener === "function") {
// Google Chrome Packaged Apps don't allow 'unload' listeners:
// unload is not available in packaged apps
if (!((global as any).chrome && (global as any).chrome.app && (global as any).chrome.app.runtime)) {
environment.removeEventListener("unload", this.environListener);
if (this.configuration.autostop) {
// Google Chrome Packaged Apps don't allow 'unload' listeners: unload is not available in packaged apps
const googleChromePackagedApp = typeof chrome !== "undefined" && chrome.app && chrome.app.runtime ? true : false;
if (window && !googleChromePackagedApp) {
window.removeEventListener("unload", this.unloadListener);
}
}

Expand Down Expand Up @@ -585,12 +587,11 @@ export class UA extends EventEmitter {
this.logger.error("Connection is down. Auto-Recovery system is trying to connect");
}

if (this.configuration.autostop && typeof environment.addEventListener === "function") {
// Google Chrome Packaged Apps don't allow 'unload' listeners:
// unload is not available in packaged apps
if (!((global as any).chrome && (global as any).chrome.app && (global as any).chrome.app.runtime)) {
this.environListener = this.stop;
environment.addEventListener("unload", () => this.environListener());
if (this.configuration.autostop) {
// Google Chrome Packaged Apps don't allow 'unload' listeners: unload is not available in packaged apps
const googleChromePackagedApp = typeof chrome !== "undefined" && chrome.app && chrome.app.runtime ? true : false;
if (window && !googleChromePackagedApp) {
window.addEventListener("unload", this.unloadListener);
}
}

Expand Down
12 changes: 2 additions & 10 deletions src/Web/SessionDescriptionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export class SessionDescriptionHandler extends EventEmitter implements SessionDe
private direction: string;
private C: any;
private modifiers: SessionDescriptionHandlerModifiers;
private WebRTC: any;
private iceGatheringDeferred: Utils.Deferred<any> | undefined;
private iceGatheringTimeout: boolean;
private iceGatheringTimer: any | undefined;
Expand Down Expand Up @@ -98,13 +97,6 @@ export class SessionDescriptionHandler extends EventEmitter implements SessionDe
this.modifiers = [this.modifiers];
}

const environment = (global as any).window || global;
this.WebRTC = {
MediaStream : environment.MediaStream,
getUserMedia : environment.navigator.mediaDevices.getUserMedia.bind(environment.navigator.mediaDevices),
RTCPeerConnection : environment.RTCPeerConnection
};

this.iceGatheringTimeout = false;

this.initPeerConnection(this.options.peerConnectionOptions);
Expand Down Expand Up @@ -513,7 +505,7 @@ export class SessionDescriptionHandler extends EventEmitter implements SessionDe
this.peerConnection.close();
}

this.peerConnection = new this.WebRTC.RTCPeerConnection(options.rtcConfiguration);
this.peerConnection = new RTCPeerConnection(options.rtcConfiguration);

this.logger.log("New peer connection created");

Expand Down Expand Up @@ -610,7 +602,7 @@ export class SessionDescriptionHandler extends EventEmitter implements SessionDe
this.emit("userMediaRequest", constraints);

if (constraints.audio || constraints.video) {
this.WebRTC.getUserMedia(constraints).then((streams: any) => {
navigator.mediaDevices.getUserMedia(constraints).then((streams) => {
this.observer.trackAdded();
this.emit("userMedia", streams);
resolve(streams);
Expand Down
6 changes: 3 additions & 3 deletions src/Web/Simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class Simple extends EventEmitter {
this.options = options;

// https://stackoverflow.com/questions/7944460/detect-safari-browser
const browserUa: string = (global as any).navigator.userAgent.toLowerCase();
const browserUa = navigator.userAgent.toLowerCase();
let isSafari: boolean = false;
let isFirefox: boolean = false;
if (browserUa.indexOf("safari") > -1 && browserUa.indexOf("chrome") < 0) {
Expand Down Expand Up @@ -300,7 +300,7 @@ export class Simple extends EventEmitter {
let remoteStream: any;

if (pc.getReceivers) {
remoteStream = new (global as any).window.MediaStream();
remoteStream = new MediaStream();
pc.getReceivers().forEach((receiver: any) => {
const track = receiver.track;
if (track) {
Expand Down Expand Up @@ -332,7 +332,7 @@ export class Simple extends EventEmitter {
const pc = (this.session.sessionDescriptionHandler as SessionDescriptionHandler).peerConnection;
let localStream: any;
if (pc.getSenders) {
localStream = new (global as any).window.MediaStream();
localStream = new MediaStream();
pc.getSenders().forEach((sender: any) => {
const track = sender.track;
if (track && track.kind === "video") {
Expand Down
16 changes: 14 additions & 2 deletions src/Web/Transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,9 @@ export class Transport extends TransportBase {
public server: WsServer;
public ws: any;

private WebSocket = ((global as any).window || global).WebSocket;

private connectionPromise: Promise<any> | undefined;
private connectDeferredResolve: ((obj: any) => void) | undefined;
private connectDeferredReject: ((obj: any) => void) | undefined;
private connectionTimeout: any | undefined;

private disconnectionPromise: Promise<any> | undefined;
Expand Down Expand Up @@ -182,6 +181,7 @@ export class Transport extends TransportBase {
}

this.connectDeferredResolve = resolve;
this.connectDeferredReject = reject;

this.status = TransportStatus.STATUS_CONNECTING;
this.emit("connecting");
Expand All @@ -194,11 +194,15 @@ export class Transport extends TransportBase {
this.statusTransition(TransportStatus.STATUS_CLOSED, true);
this.onError("error connecting to WebSocket " + this.server.wsUri + ":" + e);
reject("Failed to create a websocket");
this.connectDeferredResolve = undefined;
this.connectDeferredReject = undefined;
return;
}

if (!this.ws) {
reject("Unexpected instance websocket not set");
this.connectDeferredResolve = undefined;
this.connectDeferredReject = undefined;
return;
}

Expand All @@ -209,6 +213,8 @@ export class Transport extends TransportBase {
this.emit("disconnected", {code: 1000});
this.connectionPromise = undefined;
reject("Connection timeout");
this.connectDeferredResolve = undefined;
this.connectDeferredReject = undefined;
}, this.configuration.connectionTimeout * 1000);

this.boundOnOpen = this.onOpen.bind(this);
Expand Down Expand Up @@ -304,6 +310,8 @@ export class Transport extends TransportBase {

if (this.connectDeferredResolve) {
this.connectDeferredResolve({overrideEvent: true});
this.connectDeferredResolve = undefined;
this.connectDeferredReject = undefined;
} else {
this.logger.warn("Unexpected websocket.onOpen with no connectDeferredResolve");
}
Expand All @@ -327,9 +335,13 @@ export class Transport extends TransportBase {
if (this.connectionTimeout) {
clearTimeout(this.connectionTimeout);
}
if (this.connectDeferredReject) {
this.connectDeferredReject("Websocket Closed");
}
this.connectionTimeout = undefined;
this.connectionPromise = undefined;
this.connectDeferredResolve = undefined;
this.connectDeferredReject = undefined;

// Check whether the user requested to close.
if (this.disconnectDeferredResolve) {
Expand Down
1 change: 1 addition & 0 deletions src/core/dialogs/session-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ export class SessionDialog extends Dialog implements Session {
// https://tools.ietf.org/html/rfc3261#section-14.2
{
const uas = new ReInviteUserAgentServer(this, message);
this.signalingStateTransition(message);
this.delegate && this.delegate.onInvite ?
this.delegate.onInvite(uas) :
uas.reject({ statusCode: 488 }); // TODO: Warning header field.
Expand Down
8 changes: 6 additions & 2 deletions test/spec/SpecRegisterContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ describe('RegisterContext', function() {
getLoggerFactory: () => loggerFactory,
getSupportedResponseOptions: () => ["outbound"],
normalizeTarget: function (target) { return target; },
listeners: function () { return [1]; }
};
listeners: function () { return [1]; },
transport: {
on: function () {},
send: function () {}
}
};
ua.userAgentCore = new SIP.Core.UserAgentCore(SIP.makeUserAgentCoreConfigurationFromUA(ua));
RegisterContext = new SIP.RegisterContext(ua, ua.configuration.registerOptions);

Expand Down

0 comments on commit ad24f3c

Please sign in to comment.