{"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 */\n// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT license.\n\nimport { InvalidOperationError } from \"./Error.js\";\nimport { createNoDashGuid } from \"./Guid.js\";\nimport { IStringDictionary } from \"./IDictionary.js\";\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        // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\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"]}