UNPKG

microsoft-speech-browser-sdk

Version:
77 lines (75 loc) 2.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var Error_1 = require("./Error"); var Guid_1 = require("./Guid"); var MessageType; (function (MessageType) { MessageType[MessageType["Text"] = 0] = "Text"; MessageType[MessageType["Binary"] = 1] = "Binary"; })(MessageType = exports.MessageType || (exports.MessageType = {})); var ConnectionMessage = /** @class */ (function () { function ConnectionMessage(messageType, body, headers, id) { this.body = null; if (messageType === MessageType.Text && body && !(typeof (body) === "string")) { throw new Error_1.InvalidOperationError("Payload must be a string"); } if (messageType === MessageType.Binary && body && !(body instanceof ArrayBuffer)) { throw new Error_1.InvalidOperationError("Payload must be ArrayBuffer"); } this.messageType = messageType; this.body = body; this.headers = headers ? headers : {}; this.id = id ? id : Guid_1.CreateNoDashGuid(); } Object.defineProperty(ConnectionMessage.prototype, "MessageType", { get: function () { return this.messageType; }, enumerable: true, configurable: true }); Object.defineProperty(ConnectionMessage.prototype, "Headers", { get: function () { return this.headers; }, enumerable: true, configurable: true }); Object.defineProperty(ConnectionMessage.prototype, "Body", { get: function () { return this.body; }, enumerable: true, configurable: true }); Object.defineProperty(ConnectionMessage.prototype, "TextBody", { get: function () { if (this.messageType === MessageType.Binary) { throw new Error_1.InvalidOperationError("Not supported for binary message"); } return this.body; }, enumerable: true, configurable: true }); Object.defineProperty(ConnectionMessage.prototype, "BinaryBody", { get: function () { if (this.messageType === MessageType.Text) { throw new Error_1.InvalidOperationError("Not supported for text message"); } return this.body; }, enumerable: true, configurable: true }); Object.defineProperty(ConnectionMessage.prototype, "Id", { get: function () { return this.id; }, enumerable: true, configurable: true }); return ConnectionMessage; }()); exports.ConnectionMessage = ConnectionMessage; //# sourceMappingURL=ConnectionMessage.js.map