{"version":3,"sources":["../../../packages/core/data/electron.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,UAAU,EAAW,MAAM,MAAM,CAAC;AAMjD,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAEjC;;GAEG;AACH,qBAAa,QAAQ;IAUL,OAAO,CAAC,GAAG;IATvB;;OAEG;IACH,OAAO,CAAC,OAAO,CAAsC;IAErD;;;OAGG;gBACiB,GAAG,EAAE,GAAG;IAI5B;;;;;OAKG;IACI,OAAO,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,UAAU,CAAC,CAAC,CAAC;IA4BjE;;;OAGG;IACI,UAAU;IAIjB;;;OAGG;IACH,OAAO,CAAC,aAAa;CAIxB","file":"electron.d.ts","sourcesContent":["import { from, Observable, Subject } from 'rxjs';\r\nimport { filter, map, mergeMap, take } from 'rxjs/operators';\r\nimport { LogLevel } from '../diagnostics/log-level';\r\nimport { Logging } from '../diagnostics/logging';\r\nimport { RpcElectronOperation, RpcElectronOperationResult, RpcElectronResponseKey } from '../rpc/electron/rpc-electron-model';\r\nimport { RpcElectronRequestClient } from '../rpc/electron/rpc-electron-request-client';\r\nimport { Rpc } from '../rpc/rpc';\r\n\r\n/**\r\n * Electron Module Side Service.\r\n */\r\nexport class Electron {\r\n    /**\r\n     * Subject for tracking RPC responses from the electron host\r\n     */\r\n    private watcher: Subject<RpcElectronOperationResult>;\r\n\r\n    /**\r\n     * Initializes a new instance of the Electron Manager class\r\n     * @param rpc The rpc to forward auth requests to a parent window\r\n     */\r\n    constructor(private rpc: Rpc) {\r\n        this.watcher = new Subject<RpcElectronOperationResult>();\r\n    }\r\n\r\n    /**\r\n     * Send Electron Host Request\r\n     * @param eventName The electron host event\r\n     * @param payload The the event payload\r\n     * @returns An observable for te response message from the electron host\r\n     */\r\n    public request<T>(eventName: string, payload: any): Observable<T> {\r\n        const request: RpcElectronOperation = {\r\n            eventName: eventName,\r\n            requestId: MsftSme.newGuid(),\r\n            payload: payload\r\n        };\r\n        Logging.log({\r\n            level: LogLevel.Debug,\r\n            message: 'Sending request to Electron Shell Service. Request:{0}',\r\n            source: 'Electron',\r\n            params: request\r\n        });\r\n\r\n        return from(RpcElectronRequestClient.electronRequest(this.rpc, request))\r\n            .pipe(\r\n                mergeMap(() => this.watcher),\r\n                filter((result) => result.requestId === request.requestId),\r\n                take(1),\r\n                map((result) => {\r\n                    if (result.response) {\r\n                        return result.response;\r\n                    } else if (result.error) {\r\n                        throw result.error;\r\n                    }\r\n                    throw new Error('Unexpected Response from Electron RPC Request');\r\n                }));\r\n    }\r\n\r\n    /**\r\n     * Initializes the electron rpc response listener\r\n     * This is a module side only class. It should not be called from the shell\r\n     */\r\n    public initialize() {\r\n        this.rpc.register(RpcElectronResponseKey.command, this.onRpcResponse.bind(this));\r\n    }\r\n\r\n    /**\r\n     * Handles rpc response messages from the electron host.\r\n     * @param data the result of the electron host request\r\n     */\r\n    private onRpcResponse(data: RpcElectronOperationResult): Promise<any> {\r\n        this.watcher.next(data);\r\n        return Promise.resolve();\r\n    }\r\n}\r\n"]}