UNPKG

@voice-ping/cognitive-services-speech

Version:

VoicePing Cognitive Services Speech SDK for JavaScript forked from Microsoft

1 lines 3.05 kB
{"version":3,"sources":["src/common/ConnectionMessage.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAElD,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;IAuBf,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":["// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT license.\n\nimport { InvalidOperationError } from \"./Error\";\nimport { createNoDashGuid } from \"./Guid\";\nimport { IStringDictionary } from \"./IDictionary\";\n\nexport enum MessageType {\n Text,\n Binary,\n}\n\nexport class ConnectionMessage {\n\n private privMessageType: MessageType;\n private privHeaders: IStringDictionary<string>;\n private privBody: any = null;\n private privSize: number;\n\n private privId: string;\n\n public constructor(\n messageType: MessageType,\n body: any,\n headers?: IStringDictionary<string>,\n id?: string) {\n\n if (messageType === MessageType.Text && body && !(typeof (body) === \"string\")) {\n throw new InvalidOperationError(\"Payload must be a string\");\n }\n\n if (messageType === MessageType.Binary && body && !(body instanceof ArrayBuffer)) {\n throw new InvalidOperationError(\"Payload must be ArrayBuffer\");\n }\n\n this.privMessageType = messageType;\n this.privBody = body;\n this.privHeaders = headers ? headers : {};\n this.privId = id ? id : createNoDashGuid();\n switch (this.messageType) {\n case MessageType.Binary:\n this.privSize = this.binaryBody !== null ? this.binaryBody.byteLength : 0;\n break;\n case MessageType.Text:\n this.privSize = this.textBody.length;\n }\n }\n\n public get messageType(): MessageType {\n return this.privMessageType;\n }\n\n public get headers(): IStringDictionary<string> {\n return this.privHeaders;\n }\n\n public get body(): any {\n return this.privBody;\n }\n\n public get textBody(): string {\n if (this.privMessageType === MessageType.Binary) {\n throw new InvalidOperationError(\"Not supported for binary message\");\n }\n\n return this.privBody as string;\n }\n\n public get binaryBody(): ArrayBuffer {\n if (this.privMessageType === MessageType.Text) {\n throw new InvalidOperationError(\"Not supported for text message\");\n }\n\n return this.privBody;\n }\n\n public get id(): string {\n return this.privId;\n }\n}\n"]}