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AC,CAAC;wBAC9C,OAAO,EAAE,CAAC;qBACX;gBACH,CAAC,CAAC,CAAC;aACJ;YAED,OAAO,IAAI,CAAC,YAAY,CAAC;QAC3B,CAAC;QACH,cAAC;IAAD,CAAC,AA5CD,IA4CC","sourcesContent":["import { RemoteEvents } from './RemoteSuite';\nimport WebSocketChannel from './channels/WebSocket';\nimport HttpChannel from './channels/Http';\nimport BaseChannel, { ChannelOptions } from './channels/Base';\n\nexport { ChannelOptions };\n\nexport default class Channel {\n readonly options: ChannelOptions;\n\n private _channel!: BaseChannel;\n private _initialized!: Promise<void>;\n\n constructor(options: ChannelOptions) {\n this.options = options;\n }\n\n sendMessage(name: keyof RemoteEvents, data: any) {\n return this._initialize().then(() => {\n return this._channel.sendMessage(name, data);\n });\n }\n\n protected _initialize() {\n if (!this._initialized) {\n this._initialized = new Promise<void>(resolve => {\n if (this.options.port) {\n try {\n this._channel = new WebSocketChannel(this.options);\n this._channel.sendMessage('remoteStatus', 'ping').then(\n () => {\n resolve();\n },\n _error => {\n this._channel = new HttpChannel(this.options);\n resolve();\n }\n );\n } catch (error) {\n this._channel = new HttpChannel(this.options);\n resolve();\n }\n } else {\n this._channel = new HttpChannel(this.options);\n resolve();\n }\n });\n }\n\n return this._initialized;\n }\n}\n"]}
\No newline at end of file