@euirim/microsoft-cognitiveservices-speech-sdk
Version:
Microsoft Cognitive Services Speech SDK for JavaScript
121 lines (119 loc) • 4.8 kB
JavaScript
;
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var Exports_1 = require("../common/Exports");
var PathHeaderName = "path";
var ContentTypeHeaderName = "content-type";
var RequestIdHeaderName = "x-requestid";
var RequestTimestampHeaderName = "x-timestamp";
var SpeechConnectionMessage = /** @class */ (function (_super) {
__extends(SpeechConnectionMessage, _super);
function SpeechConnectionMessage(messageType, path, requestId, contentType, body, additionalHeaders, id) {
var _this = this;
if (!path) {
throw new Exports_1.ArgumentNullError("path");
}
if (!requestId) {
throw new Exports_1.ArgumentNullError("requestId");
}
var headers = {};
headers[PathHeaderName] = path;
headers[RequestIdHeaderName] = requestId;
headers[RequestTimestampHeaderName] = new Date().toISOString();
if (contentType) {
headers[ContentTypeHeaderName] = contentType;
}
if (additionalHeaders) {
for (var headerName in additionalHeaders) {
if (headerName) {
headers[headerName] = additionalHeaders[headerName];
}
}
}
if (id) {
_this = _super.call(this, messageType, body, headers, id) || this;
}
else {
_this = _super.call(this, messageType, body, headers) || this;
}
_this.privPath = path;
_this.privRequestId = requestId;
_this.privContentType = contentType;
_this.privAdditionalHeaders = additionalHeaders;
return _this;
}
Object.defineProperty(SpeechConnectionMessage.prototype, "path", {
get: function () {
return this.privPath;
},
enumerable: true,
configurable: true
});
Object.defineProperty(SpeechConnectionMessage.prototype, "requestId", {
get: function () {
return this.privRequestId;
},
enumerable: true,
configurable: true
});
Object.defineProperty(SpeechConnectionMessage.prototype, "contentType", {
get: function () {
return this.privContentType;
},
enumerable: true,
configurable: true
});
Object.defineProperty(SpeechConnectionMessage.prototype, "additionalHeaders", {
get: function () {
return this.privAdditionalHeaders;
},
enumerable: true,
configurable: true
});
SpeechConnectionMessage.fromConnectionMessage = function (message) {
var path = null;
var requestId = null;
var contentType = null;
var requestTimestamp = null;
var additionalHeaders = {};
if (message.headers) {
for (var headerName in message.headers) {
if (headerName) {
if (headerName.toLowerCase() === PathHeaderName.toLowerCase()) {
path = message.headers[headerName];
}
else if (headerName.toLowerCase() === RequestIdHeaderName.toLowerCase()) {
requestId = message.headers[headerName];
}
else if (headerName.toLowerCase() === RequestTimestampHeaderName.toLowerCase()) {
requestTimestamp = message.headers[headerName];
}
else if (headerName.toLowerCase() === ContentTypeHeaderName.toLowerCase()) {
contentType = message.headers[headerName];
}
else {
additionalHeaders[headerName] = message.headers[headerName];
}
}
}
}
return new SpeechConnectionMessage(message.messageType, path, requestId, contentType, message.body, additionalHeaders, message.id);
};
return SpeechConnectionMessage;
}(Exports_1.ConnectionMessage));
exports.SpeechConnectionMessage = SpeechConnectionMessage;
//# sourceMappingURL=SpeechConnectionMessage.Internal.js.map