UNPKG

@microsoft/windows-admin-center-sdk

Version:

Microsoft - Windows Admin Center Shell

101 lines (99 loc) 3.53 kB
import { NativeQ } from '../data/native-q'; import { RpcBase, rpcCommandVersion, RpcInboundCommands, RpcOutboundCommands, RpcType } from './rpc-base'; /** * RpcToModule class. * - Shell uses the instance to communicate to the Module (tool). */ export class RpcOutbound extends RpcBase { /** * Initiates a new instance of the RpcToModule class. * * @param rpcChannel the rpc channel. * @param name the public name of the module. * @param origin the origin url. */ constructor(rpcChannel, name, origin) { super(rpcChannel, name, origin, RpcType.Outbound); const commands = Object.keys(RpcInboundCommands); commands.forEach((command) => { this.register(command, this.emptyHandler); }); } /** * Registers all handlers at once. * * @param handlers the module handlers. */ registerAll(handlers) { const handlerNames = Object.keys(handlers); handlerNames.forEach((handlerName) => { const command = RpcBase.handlerToCommandName(handlerName); this.register(command, handlers[handlerName]); }); } /** * The init command. * * @param data the RpcInitData data. * @return Promise<void> the promise object. */ init(data) { return this.rpcChannel.post(this, { command: RpcOutboundCommands[RpcOutboundCommands.Init], version: rpcCommandVersion, data: data }); } /** * The open command. (30 seconds waiting time) * * @param data the RpcOpenData object. * @return Promise<RpcOpenResult> the promise object of RpcOpenResult. */ open(data) { return this.rpcChannel.post(this, { command: RpcOutboundCommands[RpcOutboundCommands.Open], version: rpcCommandVersion, data: data }, 30 * 1000); } /** * The activate command. * * @param data the void object. * @return Promise<void> the promise object. */ activate(data) { return this.rpcChannel.post(this, { command: RpcOutboundCommands[RpcOutboundCommands.Activate], version: rpcCommandVersion, data: data }); } /** * The deactivate 2 command used with polling deactivation. * * @param data the void object. * @return Promise<RpcDeactivateResult> the promise object. */ deactivate2(data) { // ignore if it gets timed out because the frame could be gone already. return this.rpcChannel.post(this, { command: RpcOutboundCommands[RpcOutboundCommands.Deactivate2], version: rpcCommandVersion, data: data }, -1); } /** * The shutdown command. * * @param data the RpcShutdownData object. * @return Promise<RpcShutdownResult> the promise object. */ shutdown(data) { return this.rpcChannel.post(this, { command: RpcOutboundCommands[RpcOutboundCommands.Shutdown], version: rpcCommandVersion, data: data }); } /** * The ping command. * * @param data the RpcPingData object. * @return Promise<RpcPingResult> the promise object. */ ping(data) { return this.rpcChannel.retryPost(this, { command: RpcOutboundCommands[RpcOutboundCommands.Ping], version: rpcCommandVersion, data: data }, 40, 250); } /** * The empty handler to response always resolved. * * @param data the node context. * @return Promise<any> the promise. */ emptyHandler() { return NativeQ.resolved('emptyHandler'); } } //# sourceMappingURL=rpc-outbound.js.map