UNPKG

@euirim/microsoft-cognitiveservices-speech-sdk

Version:
51 lines (49 loc) 1.72 kB
// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. import { InvalidOperationError } from "./Error"; import { createNoDashGuid } from "./Guid"; export var MessageType; (function (MessageType) { MessageType[MessageType["Text"] = 0] = "Text"; MessageType[MessageType["Binary"] = 1] = "Binary"; })(MessageType || (MessageType = {})); export class ConnectionMessage { constructor(messageType, body, headers, id) { this.privBody = null; if (messageType === MessageType.Text && body && !(typeof (body) === "string")) { throw new InvalidOperationError("Payload must be a string"); } if (messageType === MessageType.Binary && body && !(body instanceof ArrayBuffer)) { throw new InvalidOperationError("Payload must be ArrayBuffer"); } this.privMessageType = messageType; this.privBody = body; this.privHeaders = headers ? headers : {}; this.privId = id ? id : createNoDashGuid(); } get messageType() { return this.privMessageType; } get headers() { return this.privHeaders; } get body() { return this.privBody; } get textBody() { if (this.privMessageType === MessageType.Binary) { throw new InvalidOperationError("Not supported for binary message"); } return this.privBody; } get binaryBody() { if (this.privMessageType === MessageType.Text) { throw new InvalidOperationError("Not supported for text message"); } return this.privBody; } get id() { return this.privId; } } //# sourceMappingURL=ConnectionMessage.js.map