@microsoft/windows-admin-center-sdk
Version:
Microsoft - Windows Admin Center Shell
271 lines (269 loc) • 7.61 kB
JavaScript
/**
* History:
* Version: 0.1.0
* Date: 09/20/2018
* - New RP Public API model.
*
* Version: 0.0.12
* Date: 07/17/2018
* [Update] AzureRequest.
* - AzureManager and AzureService need to communicate.
*
* Version: 0.0.11
* Date: 07/10/2018
*
* [Update] RpcCredSSPOperation
* - Restored disableTaskDelay parameter.
* - Added alertTitle parameter.
* - added alertId? parameter.
*
* Version: 0.0.10
* Date: 07/10/2018
*
* [Update] RpcCredSSPOperationType
* - Updated operation types for four operations.
*
* [Update] RpcCredSSPOperation
* - Removed taskDelay parameter.
*
* Version: 0.0.9
* Date: 05/18/2018
*
* [Update] RpcInitData.
* - Added Development settings (consoleDebug, sideLoad, and experiments) to RpcInitData.
*
* Version: 0.0.8
* Date: 05/18/2018
*
* [Update] CredSSPRequest.
* - CredSSPManager and CredSSPManagerShellService need to communicate.
*
* Version: 0.0.7
* Date: 04/27/2018
* [Update] RpcActivate for re-opening URL as an option.
* - moduleActivate has 'url' parameter to point re-activating inner URL.
*
* Version: 0.0.6
* Date: 01/29/2018
*
* [Add] OverlayOpen and OverlayClose
*
* Version: 0.0.5
* Date: 12/11/2017
*
* [Update] RpcInitData: accessibilityMode: boolean;
*
* Version: 0.0.4
* Date: 10/25/2017
*
* [Add] Added new RPC call.
*
* Version: 0.0.3
* Date: 9/11/2017
*
* [Updated] added assets and theme to RpcInitData
*
* Version: 0.0.2
* Date: 9/11/2017
*
* [Update] Add "reload" property to RpcShellNavigate
*
* Version: 0.0.1
* Date: 8/23/2017
*
* [Deleted] Deactivate
* [Updated] Open for RpcOpenResult
*
* Version: 0.0.0
* Date: 8/14/2017
*
* [Deleted] CanDeactivate
* [Deprecated] Deactivate
* [New Added] Deactivate2
*
*/
/**
* Version number of this RPC.
*/
export const rpcVersion = '0.1.0';
export const rpcCommandVersion = '0.1.0';
/**
* Rpc message packet type.
*/
export var RpcMessagePacketType;
(function (RpcMessagePacketType) {
// Rpc request call.
RpcMessagePacketType[RpcMessagePacketType["Request"] = 0] = "Request";
// Rpc response call with success.
RpcMessagePacketType[RpcMessagePacketType["Response"] = 1] = "Response";
// Rpc response call with error.
RpcMessagePacketType[RpcMessagePacketType["Error"] = 2] = "Error";
})(RpcMessagePacketType || (RpcMessagePacketType = {}));
/**
* Rpc open state.
*/
export var RpcOpenState;
(function (RpcOpenState) {
/**
* Opened.
*/
RpcOpenState[RpcOpenState["Opened"] = 0] = "Opened";
/**
* Failed.
*/
RpcOpenState[RpcOpenState["Failed"] = 1] = "Failed";
/**
* In progress.
*/
RpcOpenState[RpcOpenState["InProgress"] = 2] = "InProgress";
})(RpcOpenState || (RpcOpenState = {}));
/**
* Rpc deactivate state.
*/
export var RpcDeactivateState;
(function (RpcDeactivateState) {
/**
* Deactivated.
*/
RpcDeactivateState[RpcDeactivateState["Deactivated"] = 0] = "Deactivated";
/**
* Cancelled.
*/
RpcDeactivateState[RpcDeactivateState["Cancelled"] = 1] = "Cancelled";
/**
* In progress.
*/
RpcDeactivateState[RpcDeactivateState["InProgress"] = 2] = "InProgress";
})(RpcDeactivateState || (RpcDeactivateState = {}));
/**
* Rpc commands that Shell initiates to communicate a module (tool).
*/
export var RpcOutboundCommands;
(function (RpcOutboundCommands) {
RpcOutboundCommands[RpcOutboundCommands["Init"] = 100] = "Init";
RpcOutboundCommands[RpcOutboundCommands["Open"] = 101] = "Open";
RpcOutboundCommands[RpcOutboundCommands["Activate"] = 102] = "Activate";
RpcOutboundCommands[RpcOutboundCommands["Deactivate2"] = 103] = "Deactivate2";
RpcOutboundCommands[RpcOutboundCommands["Shutdown"] = 104] = "Shutdown";
RpcOutboundCommands[RpcOutboundCommands["Ping"] = 105] = "Ping";
})(RpcOutboundCommands || (RpcOutboundCommands = {}));
/**************************************************************************************************************************
* Inbound commands set.
**************************************************************************************************************************/
/**
* Rpc commands that a Module (tool) initiates to communicate Shell.
*/
export var RpcInboundCommands;
(function (RpcInboundCommands) {
RpcInboundCommands[RpcInboundCommands["Failed"] = 201] = "Failed";
})(RpcInboundCommands || (RpcInboundCommands = {}));
/**
* The type of RpcBase object.
*/
export var RpcType;
(function (RpcType) {
RpcType[RpcType["Channel"] = 0] = "Channel";
RpcType[RpcType["Inbound"] = 1] = "Inbound";
RpcType[RpcType["Outbound"] = 2] = "Outbound";
})(RpcType || (RpcType = {}));
/**
* Rpc base class.
*/
export class RpcBase {
rpcChannel;
name;
origin;
type;
/**
* Suffix of command to handler mapping.
*/
static handlerSuffix = 'Handler';
/**
* the window/iFrame object.
*/
window;
/**
* command collection to handle.
*/
commandCollection = new Map();
/**
* The sub name created dynamically when Outbound/Inbound communication is established.
*/
subName;
/**
* The depth of frame.
*/
depth;
/**
* The version of remote module.
*/
version;
/**
* Convert from handler name to command name.
*
* @param handlerName the handler name.
* @return the command name.
*/
static handlerToCommandName(handlerName) {
const suffix = handlerName.indexOf(RpcBase.handlerSuffix);
if (suffix > 0) {
return handlerName.substring(0, suffix);
}
return handlerName;
}
/**
* Convert from command name to handler name.
*
* @param commandName the command name.
* @return the handler name.
*/
static commandToHandlerName(commandName) {
return commandName + RpcBase.handlerSuffix;
}
/**
* Initializes a new instance of the RpcBase class.
*
* @param rpcChannel the rpc channel object..
* @param name the public name of Shell or Module (tool).
* @param origin the origin url to start Shell or Module (tool).
*/
constructor(rpcChannel, name, origin, type) {
this.rpcChannel = rpcChannel;
this.name = name;
this.origin = origin;
this.type = type;
}
/**
* Handle the command with data object.
*
* @param command the command name.
* @param sourceVersion the version string.
* @param sourceName the name of the remote rpc that sent the request.
* @param sourceSubName the sub name of the remote rpc that sent the request.
* @param data the data object.
* @return Promise<any> the promise object.
*/
handle(command, sourceVersion, sourceName, sourceSubName, data) {
const handler = this.commandCollection[command];
if (!handler) {
const message = MsftSme.getStrings().MsftSmeShell.Core.Error.RpcNotRegisteredHandler.message;
throw new Error(message.format(command));
}
Object.assign(data, {
sourceName,
sourceSubName,
sourceVersion
});
return handler(data);
}
/**
* Register the handler to the command.
*
* @param command the command name.
* @param handler the handler function.
*/
register(command, handler) {
this.commandCollection[command] = handler;
}
}
//# sourceMappingURL=rpc-base.js.map