microsoft-cognitiveservices-speech-sdk
Version:
Microsoft Cognitive Services Speech SDK for JavaScript
1 lines • 3.36 kB
Source Map (JSON)
{"version":3,"sources":["src/common/ConnectionMessage.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,oBAAY,WAAW;IACnB,IAAI,IAAA;IACJ,MAAM,IAAA;CACT;AAED,qBAAa,iBAAiB;IAE1B,OAAO,CAAC,eAAe,CAAc;IACrC,OAAO,CAAC,WAAW,CAA4B;IAC/C,OAAO,CAAC,QAAQ,CAAa;IAC7B,OAAO,CAAC,QAAQ,CAAS;IAEzB,OAAO,CAAC,MAAM,CAAS;gBAGnB,WAAW,EAAE,WAAW,EACxB,IAAI,EAAE,GAAG,EACT,OAAO,CAAC,EAAE,iBAAiB,CAAC,MAAM,CAAC,EACnC,EAAE,CAAC,EAAE,MAAM;IAwBf,IAAW,WAAW,IAAI,WAAW,CAEpC;IAED,IAAW,OAAO,IAAI,iBAAiB,CAAC,MAAM,CAAC,CAE9C;IAED,IAAW,IAAI,IAAI,GAAG,CAErB;IAED,IAAW,QAAQ,IAAI,MAAM,CAM5B;IAED,IAAW,UAAU,IAAI,WAAW,CAMnC;IAED,IAAW,EAAE,IAAI,MAAM,CAEtB;CACJ","file":"ConnectionMessage.d.ts","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-return */\r\n// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT license.\r\n\r\nimport { InvalidOperationError } from \"./Error.js\";\r\nimport { createNoDashGuid } from \"./Guid.js\";\r\nimport { IStringDictionary } from \"./IDictionary.js\";\r\n\r\nexport enum MessageType {\r\n Text,\r\n Binary,\r\n}\r\n\r\nexport class ConnectionMessage {\r\n\r\n private privMessageType: MessageType;\r\n private privHeaders: IStringDictionary<string>;\r\n private privBody: any = null;\r\n private privSize: number;\r\n\r\n private privId: string;\r\n\r\n public constructor(\r\n messageType: MessageType,\r\n body: any,\r\n headers?: IStringDictionary<string>,\r\n id?: string) {\r\n\r\n if (messageType === MessageType.Text && body && !(typeof (body) === \"string\")) {\r\n throw new InvalidOperationError(\"Payload must be a string\");\r\n }\r\n\r\n if (messageType === MessageType.Binary && body && !(body instanceof ArrayBuffer)) {\r\n throw new InvalidOperationError(\"Payload must be ArrayBuffer\");\r\n }\r\n\r\n this.privMessageType = messageType;\r\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\r\n this.privBody = body;\r\n this.privHeaders = headers ? headers : {};\r\n this.privId = id ? id : createNoDashGuid();\r\n switch (this.messageType) {\r\n case MessageType.Binary:\r\n this.privSize = this.binaryBody !== null ? this.binaryBody.byteLength : 0;\r\n break;\r\n case MessageType.Text:\r\n this.privSize = this.textBody.length;\r\n }\r\n }\r\n\r\n public get messageType(): MessageType {\r\n return this.privMessageType;\r\n }\r\n\r\n public get headers(): IStringDictionary<string> {\r\n return this.privHeaders;\r\n }\r\n\r\n public get body(): any {\r\n return this.privBody;\r\n }\r\n\r\n public get textBody(): string {\r\n if (this.privMessageType === MessageType.Binary) {\r\n throw new InvalidOperationError(\"Not supported for binary message\");\r\n }\r\n\r\n return this.privBody as string;\r\n }\r\n\r\n public get binaryBody(): ArrayBuffer {\r\n if (this.privMessageType === MessageType.Text) {\r\n throw new InvalidOperationError(\"Not supported for text message\");\r\n }\r\n\r\n return this.privBody;\r\n }\r\n\r\n public get id(): string {\r\n return this.privId;\r\n }\r\n}\r\n"]}