@microsoft/windows-admin-center-sdk
Version:
Microsoft - Windows Admin Center Shell
54 lines (52 loc) • 1.7 kB
JavaScript
import { NativeQ } from '../data/native-q';
import { RpcBase, rpcCommandVersion, RpcInboundCommands, RpcOutboundCommands, RpcType } from './rpc-base';
/**
* RpcToShell class.
* - Module (tool) uses the instance to communicate to Shell.
*/
export class RpcInbound extends RpcBase {
/**
* Initiates a new instance of the RpcToShell 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.Inbound);
const commands = Object.keys(RpcOutboundCommands);
commands.forEach((command) => {
this.register(command, this.emptyHandler);
});
}
/**
* Registers all handlers at once.
*
* @param handlers the Shell handlers.
*/
registerAll(handlers) {
const handlerNames = Object.keys(handlers);
handlerNames.forEach((handlerName) => {
const command = RpcBase.handlerToCommandName(handlerName);
this.register(command, handlers[handlerName]);
});
}
/**
* The failed command.
*
* @param data the RpcBaseData object.
* @return Promise<void> the promise object.
*/
failed(data) {
return this.rpcChannel.post(this, { command: RpcInboundCommands[RpcInboundCommands.Failed], version: rpcCommandVersion, data: data });
}
/**
* The empty handler to response always resolved.
*
* @return Promise<string> the promise.
*/
emptyHandler(_) {
return NativeQ.resolved('emptyHandler');
}
}
//# sourceMappingURL=rpc-inbound.js.map