-
Notifications
You must be signed in to change notification settings - Fork 702
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
James Criscuolo
committed
Jun 7, 2019
1 parent
9c37c3f
commit be5d66a
Showing
244 changed files
with
63,113 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/// <reference types="node" /> | ||
import { EventEmitter } from "events"; | ||
import { IncomingResponseMessage, Logger, NameAddrHeader, OutgoingRequestMessage, URI } from "./core"; | ||
import { TypeStrings } from "./Enums"; | ||
import { BodyObj } from "./session-description-handler"; | ||
import { UA } from "./UA"; | ||
export declare namespace ClientContext { | ||
interface Options { | ||
body?: string; | ||
contentType?: string; | ||
extraHeaders?: Array<string>; | ||
params?: { | ||
fromUri?: string | URI; | ||
toUri?: string | URI; | ||
toDisplayName?: string; | ||
}; | ||
} | ||
} | ||
export declare class ClientContext extends EventEmitter { | ||
static initializer(objToConstruct: ClientContext, ua: UA, method: string, originalTarget: string | URI, options?: ClientContext.Options): void; | ||
type: TypeStrings; | ||
data: any; | ||
ua: UA; | ||
logger: Logger; | ||
request: OutgoingRequestMessage; | ||
method: string; | ||
body: BodyObj | undefined; | ||
localIdentity: NameAddrHeader; | ||
remoteIdentity: NameAddrHeader; | ||
constructor(ua: UA, method: string, target: string | URI, options?: ClientContext.Options); | ||
send(): this; | ||
receiveResponse(response: IncomingResponseMessage): void; | ||
onRequestTimeout(): void; | ||
onTransportError(): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var events_1 = require("events"); | ||
var Constants_1 = require("./Constants"); | ||
var core_1 = require("./core"); | ||
var Enums_1 = require("./Enums"); | ||
var Utils_1 = require("./Utils"); | ||
var ClientContext = /** @class */ (function (_super) { | ||
tslib_1.__extends(ClientContext, _super); | ||
function ClientContext(ua, method, target, options) { | ||
var _this = _super.call(this) || this; | ||
_this.data = {}; | ||
ClientContext.initializer(_this, ua, method, target, options); | ||
return _this; | ||
} | ||
ClientContext.initializer = function (objToConstruct, ua, method, originalTarget, options) { | ||
objToConstruct.type = Enums_1.TypeStrings.ClientContext; | ||
// Validate arguments | ||
if (originalTarget === undefined) { | ||
throw new TypeError("Not enough arguments"); | ||
} | ||
objToConstruct.ua = ua; | ||
objToConstruct.logger = ua.getLogger("sip.clientcontext"); | ||
objToConstruct.method = method; | ||
var target = ua.normalizeTarget(originalTarget); | ||
if (!target) { | ||
throw new TypeError("Invalid target: " + originalTarget); | ||
} | ||
var fromURI = ua.userAgentCore.configuration.aor; | ||
if (options && options.params && options.params.fromUri) { | ||
fromURI = | ||
(typeof options.params.fromUri === "string") ? | ||
core_1.Grammar.URIParse(options.params.fromUri) : | ||
options.params.fromUri; | ||
if (!fromURI) { | ||
throw new TypeError("Invalid from URI: " + options.params.fromUri); | ||
} | ||
} | ||
var toURI = target; | ||
if (options && options.params && options.params.toUri) { | ||
toURI = | ||
(typeof options.params.toUri === "string") ? | ||
core_1.Grammar.URIParse(options.params.toUri) : | ||
options.params.toUri; | ||
if (!toURI) { | ||
throw new TypeError("Invalid to URI: " + options.params.toUri); | ||
} | ||
} | ||
/* Options | ||
* - extraHeaders | ||
* - params | ||
* - contentType | ||
* - body | ||
*/ | ||
options = Object.create(options || Object.prototype); | ||
options = options || {}; | ||
var extraHeaders = (options.extraHeaders || []).slice(); | ||
var params = options.params || {}; | ||
var bodyObj; | ||
if (options.body) { | ||
bodyObj = { | ||
body: options.body, | ||
contentType: options.contentType ? options.contentType : "application/sdp" | ||
}; | ||
objToConstruct.body = bodyObj; | ||
} | ||
var body; | ||
if (bodyObj) { | ||
body = Utils_1.Utils.fromBodyObj(bodyObj); | ||
} | ||
// Build the request | ||
objToConstruct.request = ua.userAgentCore.makeOutgoingRequestMessage(method, target, fromURI, toURI, params, extraHeaders, body); | ||
/* Set other properties from the request */ | ||
if (objToConstruct.request.from) { | ||
objToConstruct.localIdentity = objToConstruct.request.from; | ||
} | ||
if (objToConstruct.request.to) { | ||
objToConstruct.remoteIdentity = objToConstruct.request.to; | ||
} | ||
}; | ||
ClientContext.prototype.send = function () { | ||
var _this = this; | ||
this.ua.userAgentCore.request(this.request, { | ||
onAccept: function (response) { return _this.receiveResponse(response.message); }, | ||
onProgress: function (response) { return _this.receiveResponse(response.message); }, | ||
onRedirect: function (response) { return _this.receiveResponse(response.message); }, | ||
onReject: function (response) { return _this.receiveResponse(response.message); }, | ||
onTrying: function (response) { return _this.receiveResponse(response.message); } | ||
}); | ||
return this; | ||
}; | ||
ClientContext.prototype.receiveResponse = function (response) { | ||
var statusCode = response.statusCode || 0; | ||
var cause = Utils_1.Utils.getReasonPhrase(statusCode); | ||
switch (true) { | ||
case /^1[0-9]{2}$/.test(statusCode.toString()): | ||
this.emit("progress", response, cause); | ||
break; | ||
case /^2[0-9]{2}$/.test(statusCode.toString()): | ||
if (this.ua.applicants[this.toString()]) { | ||
delete this.ua.applicants[this.toString()]; | ||
} | ||
this.emit("accepted", response, cause); | ||
break; | ||
default: | ||
if (this.ua.applicants[this.toString()]) { | ||
delete this.ua.applicants[this.toString()]; | ||
} | ||
this.emit("rejected", response, cause); | ||
this.emit("failed", response, cause); | ||
break; | ||
} | ||
}; | ||
ClientContext.prototype.onRequestTimeout = function () { | ||
this.emit("failed", undefined, Constants_1.C.causes.REQUEST_TIMEOUT); | ||
}; | ||
ClientContext.prototype.onTransportError = function () { | ||
this.emit("failed", undefined, Constants_1.C.causes.CONNECTION_ERROR); | ||
}; | ||
return ClientContext; | ||
}(events_1.EventEmitter)); | ||
exports.ClientContext = ClientContext; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
export declare namespace C { | ||
const USER_AGENT: string; | ||
const SIP = "sip"; | ||
const SIPS = "sips"; | ||
enum causes { | ||
CONNECTION_ERROR = "Connection Error", | ||
INTERNAL_ERROR = "Internal Error", | ||
REQUEST_TIMEOUT = "Request Timeout", | ||
SIP_FAILURE_CODE = "SIP Failure Code", | ||
ADDRESS_INCOMPLETE = "Address Incomplete", | ||
AUTHENTICATION_ERROR = "Authentication Error", | ||
BUSY = "Busy", | ||
DIALOG_ERROR = "Dialog Error", | ||
INCOMPATIBLE_SDP = "Incompatible SDP", | ||
NOT_FOUND = "Not Found", | ||
REDIRECTED = "Redirected", | ||
REJECTED = "Rejected", | ||
UNAVAILABLE = "Unavailable", | ||
BAD_MEDIA_DESCRIPTION = "Bad Media Description", | ||
CANCELED = "Canceled", | ||
EXPIRES = "Expires", | ||
NO_ACK = "No ACK", | ||
NO_ANSWER = "No Answer", | ||
NO_PRACK = "No PRACK", | ||
RTP_TIMEOUT = "RTP Timeout", | ||
USER_DENIED_MEDIA_ACCESS = "User Denied Media Access", | ||
WEBRTC_ERROR = "WebRTC Error", | ||
WEBRTC_NOT_SUPPORTED = "WebRTC Not Supported" | ||
} | ||
enum supported { | ||
REQUIRED = "required", | ||
SUPPORTED = "supported", | ||
UNSUPPORTED = "none" | ||
} | ||
const SIP_ERROR_CAUSES: { | ||
[name: string]: Array<number>; | ||
}; | ||
const ACK = "ACK"; | ||
const BYE = "BYE"; | ||
const CANCEL = "CANCEL"; | ||
const INFO = "INFO"; | ||
const INVITE = "INVITE"; | ||
const MESSAGE = "MESSAGE"; | ||
const NOTIFY = "NOTIFY"; | ||
const OPTIONS = "OPTIONS"; | ||
const REGISTER = "REGISTER"; | ||
const UPDATE = "UPDATE"; | ||
const SUBSCRIBE = "SUBSCRIBE"; | ||
const PUBLISH = "PUBLISH"; | ||
const REFER = "REFER"; | ||
const PRACK = "PRACK"; | ||
const REASON_PHRASE: { | ||
[code: number]: string; | ||
}; | ||
const OPTION_TAGS: { | ||
[option: string]: boolean; | ||
}; | ||
enum dtmfType { | ||
INFO = "info", | ||
RTP = "rtp" | ||
} | ||
} |
Oops, something went wrong.