import { Observable } from 'rxjs'; import { NativeDeferred } from '../data/native-q'; import { EnvironmentModuleEntryPoint } from '../manifest/environment-modules'; import { CommandCallBackType, RpcDeactivateResult, RpcInboundCommands, RpcInitResult, RpcOpenResult, RpcOutboundCommands, RpcShutdownResult } from './rpc-base'; import { RpcManager } from './rpc-manager'; import { RpcSeekMode, RpcSeekResult } from './seek/rpc-seek-model'; /** * Deferred data object. */ export interface DeferredData { deferred: NativeDeferred; data: TData; } /** * The Rpc class. */ export declare class Rpc { private static rpcTimeout; /** * This subject is updated whenever there's new reported data */ private rpcSubjects; /** * Deferred response collection. */ private deferredCollection; /** * Active status of rpc by Observable. */ private stateChangedInternal; /** * Active status of rpc. */ private stateActiveInternal; /** * Inbound module handlers to process when rpc is called. * - called from Module to Shell. */ private rpcInboundHandlers; /** * Outbound shell handlers to process when rpc is called. * - called from Shell to Module. * - if code reached a handler, module is not ready yet. * set timeout for RPC call. */ private rpcOutboundHandlers; /** * Rpc manager object. */ rpcManager: RpcManager; /** * Initializes a new instance of the Rpc class. * * @param http the Http class instance injected. */ constructor(); /** * Gets observable to watch the state change. */ get stateChanged(): Observable; /** * Gets the state of rpc. */ get stateActive(): boolean; /** * Gets whether rpc is running on the shell. */ get isShell(): boolean; /** * Register inbound command handler. * * @param command The command name. * @param handler The command handler. */ registerInboundHandler(command: string, handler: CommandCallBackType): void; /** * Register outbound command handler. * * @param command The command name. * @param handler The command handler. */ registerOutboundHandler(command: string, handler: CommandCallBackType): void; /** * Initializes Rpc configuration */ init(): void; /*************************************************************** * Section for Shell usage. ***************************************************************/ /** * This updates its value every time there's a reported data from the rpc channel */ moduleSubjects(commandType: RpcInboundCommands): Observable>; /** * Connect a module with name and iframe. * - start pinging to iframe to wait for response. * * @param name the name of the module. * @param path the path to open the module the module name. * @param iframe the iframe window object. * @param primary the primary window to affect router url. * @return Promise the promise with subName created for the window. */ moduleConnect(name: string, path: string, iframe: Window, primary: boolean): Promise; /** * Init the module. * * @param name the name of module. * @param subName the sub name of rpc channel. * @param entryPointType the entry point type. * @return Promise the promise object of init result. */ moduleInit(name: string, subName: string, entryPoint: EnvironmentModuleEntryPoint): Promise; /** * Open the module by specifying the path and parameters. * * @param name the name of module. * @param subName the sub name of rpc channel. * @param path the open path. * @return Promise the promise object of RpcOpenResult. */ moduleOpen(name: string, subName: string, path: string): Promise; /** * Activate the module to start receiving data. * * @param name the module name. * @param subName the sub name of rpc channel. * @param primary the primary window to affect router url. * @param url the inner url to open. * @return Promise the promise of activation result. */ moduleActivate(name: string, subName: string, primary: boolean, url: string): Promise; /** * Deactivate 2 the module to stop receiving data. * * @param name the module name. * @param subName the sub name of rpc channel. * @return Promise the promise of deactivation result. */ moduleDeactivate2(name: string, subName: string): Promise; /** * Request to shutdown the module. * * @param name the module name. * @param subName the sub name of rpc channel. * @param primary the primary window to affect router url. * @param force the forcible state. * @return Promise the promise object of result. */ moduleShutdown(name: string, subName: string, primary: boolean, force: boolean): Promise; /** * Remove the module from the rpc channel. * * @param name the module name. * @param subName the sub name of rpc channel. */ moduleRemove(name: string, subName: string): void; /** * Get module version string. * * @param name the name of module. * @param subName the sub name of rpc channel. * @return string the RPC version of module. */ moduleVersion(name: string, subName: string): string; /*************************************************************** * Section for Module usage. ***************************************************************/ /** * Register outbound handler. It accepts delay register in case of loading/initialization took a time for module. * * @param command the name of RPC Shell command. * @param handler the handler to handle Shell request. */ register(command: string, handler: (data: any) => Promise): void; /** * Register outbound handler. It accepts delay register in case of loading/initialization took a time for module. * * @param command the enum ID of RPC Shell command. * @param handler the handler to handle Shell request. */ register(command: RpcOutboundCommands, handler: (data: any) => Promise): void; /** * Module report a failure. */ failed(data: any): Promise; /** * Seek shell frame. * * @param Promise the promise object. */ seekShell(mode: RpcSeekMode): Promise; /** * Validate existing outbound connection and remove if it doesn't live anymore. * * @return number the count of removed outbound. */ validate(): number; /** * Change the active status of rpc. */ changeActiveState(state: boolean): void; /** * Create auto-failed timer promise. * * @param command the outbound command type. * @param timeoutMs the timeout milliseconds. * @param data the data context. * @return Promise the promise. */ private createTimerPromise; /** * Create promise that does not timeout. * * @param command the outbound type. * @param data the data context. * @return Promise the promise. */ private createPromise; /** * Process data pushing into next call of subject with deferred data type. * * @param command the inbound command type. * @param data the rpc data came from a module/iframe. * @return Promise the promise which receiver must settle within fixed waiting time (10 seconds) */ private processNextForSubject; }