Skip to content

Latest commit

 

History

History
626 lines (472 loc) · 11.9 KB

README.md

File metadata and controls

626 lines (472 loc) · 11.9 KB

@dlenroc/wdp · NPM Version

Installation

npm install @dlenroc/wdp --save

Usage

In this Windows Device Portal (WDP) binding, all functions are available in 2 styles:

  • Via Wdp class

    Allows you to initialize a class by passing the configuration once through the constructor.

    import { Wdp } from '@dlenroc/wdp';         // ESM
    // const { WDP } = require('@dlenroc/wdp'); // CJS
    
    const wdp = new Wdp({ address: ... });
    const packages = await wdp.getInstalledAppPackages()
    console.log(packages);
  • Via named import

    Allows you to import/use individual methods, but requires passing the configuration as the first parameter.

    import * as wdp from '@dlenroc/wdp';        // ESM
    // const wdp = require('@dlenroc/wdp');     // CJS
    
    const ctx = { address: ... };
    const packages = await wdp.getInstalledAppPackages(ctx);
    console.log(packages);

Regardless of which method you choose, the configuration will look the same.

type WdpCtx = {
  // Target
  address: string;
  username?: string;
  password?: string;

  // Abort signal
  signal?: AbortSignal;

  // W3C compliant implementations
  implementations?: {
    fetch?: any;
    FormData?: any;
    WebSocket?: any;
  };
}

📝 The ability to provide implementations allows you to provide only features that are missing in the engine, as well as customize those that may not meet your needs.

Example

Below you can see a simple example for Node.js 16 LTS using node-fetch and ws.

import { Wdp } from '@dlenroc/wdp';
import nodeFetch, { Blob, FormData } from 'node-fetch';
import { readFile } from 'node:fs/promises';
import https from 'node:https';
import { setTimeout as sleep } from 'node:timers/promises';
import { WebSocket as NodeWebSocket } from 'ws';

// Custom implementations without SSL verification
const agent = new https.Agent({ rejectUnauthorized: false });
const fetch = (url, init) => nodeFetch(url, { ...init, agent });
const WebSocket = function (url, protocols, options) {
  return new NodeWebSocket(url, protocols, { ...options, agent });
};

const wdp = new Wdp({
  address: 'https://192.168.18.5:11443',
  username: 'auto-xbox',
  password: 'secret',
  implementations: { fetch, FormData, WebSocket },
});

// Install application
// const appContent = new Blob([await readFile('app.msix')]);
// await wdp.installApp('app.msix', appContent);
// while (true) {
//   const state = await wdp.getInstallationState();
//   if (!state.InstallRunning) break;
//   await sleep(500);
// }

// Open "Microsoft Edge"
const app = await wdp.getInstalledAppPackages();
const edge = app.InstalledPackages.find((app) => app.Name === 'Microsoft Edge');
if (!edge) throw new Error('Microsoft Edge is not installed');
await wdp.startApp(edge.PackageRelativeId);
await sleep(5000);

// Scroll page
const input = await wdp.getRemoteInput();
input.move(50, 50);
for (let i = 0; i < 500; i++) {
  input.verticalWheelMove(50, 80, -20);
  await sleep(50);
}
input.disconnect();

APIs

getInstalledAppPackages(options?: { streamable?: boolean; includeframeworkpackages?: boolean }): Promise<AppPackages>
getContentGroups(packageFullName: string): Promise<ContentGroups>
installApp(name: string, content: Blob, extra?: Record<string, Blob>): Promise<void>
installCertificate(name: string, content: Blob): Promise<void>
registerNetworkShareApp(app: NetworkAppPackages): Promise<void>
getInstallationState(): Promise<InstallState>
uninstallAppPackage(packageFullName: string): Promise<void>
registerLooseApp(folder: string): Promise<void>
uploadLooseApp(folder: string, files: Record<string, Blob>): Promise<void>
pullInstallFromNetwork(install: Record<string, any>): Promise<void>
deleteSshPins(): Promise<void>
getDeployInfo(packageFullName: string, overlayFolder?: string): Promise<AppDeployInfo>
getPairedBluetoothDevices(): Promise<PairedBluetoothDevices>
getAvailableBluetoothDevices(): Promise<AvailableBluetoothDevices>
getBluetoothRadios(): Promise<BluetoothRadios>
setBluetoothRadioState(id: string, enable: boolean): Promise<void>
removeBluetoothDevice(deviceId: string): Promise<void>
disconnectBluetoothDevice(deviceId: string): Promise<void>
connectBluetoothDevice(deviceId: string): Promise<void>
getSSLCertificate(): Promise<Blob>
getContainers(): Promise<any>
getPluginTools(): Promise<PluginTools>
getPluginWorkspaces(): Promise<Workspaces>
getUniqueId(): Promise<UniqueId>
getDevices(): Promise<Devices>
getUsbDevices(): Promise<UsbDevices>
getServiceTags(): Promise<ServiceTags>
deleteAllServiceTags(): Promise<void>
addServiceTag(tag: string): Promise<void>
deleteServiceTag(tag: string): Promise<void>
getCrashDumps(): Promise<AppCrashDumps>
getCrashDumpControlSettings(packageFullName: string): Promise<AppCrashDumpSettings>
setCrashDumpControlSettings(packageFullName: string, enable: boolean): Promise<void>
getCrashDump(packageFullName: string, fileName: string): Promise<Blob>
deleteCrashDump(packageFullName: string, fileName: string): Promise<void>
getProcessDump(pid: number): Promise<Blob>
getKernelDump(): Promise<Blob>
getBugCheckDumps(): Promise<DumpFiles>
getBugCheckDump(filename: string): Promise<Blob>
getCrashControlSettings(): Promise<DumpSetting>
setCrashControlSettings(settings: DumpSetting): Promise<DumpSetting>
getWerReports(): Promise<WerReports>
getWerReportFiles(user: string, type: string, name: string): Promise<WerReportFiles>
getWerReportFile(user: string, type: string, name: string, file: string): Promise<Blob>
getEtwEvents(): Promise<EtwEvents>
getEtwProviders(): Promise<EtwProviders>
getCustomEtwProviders(): Promise<EtwProviders>
getFeatures(): Promise<FeatureCategories>
setFeatureState(id: string, state: boolean): Promise<void>
getFiddlerTracingState(): Promise<FiddlerTracingState>
enableFiddler(proxyAddress: string, proxyPort: number, cert?: Blob): Promise<void>
disableFiddler(): Promise<void>
getKnownFolders(): Promise<KnownFolders>
getFiles(knownFolderId: string, options?: { packageFullName?: string; path?: string }): Promise<KnownFolderFiles>
deleteFile(knownFolderId: string, filename: string, options: { packageFullName?: string; path?: string }): Promise<void>
renameFile(knownFolderId: string, filename: string, newFilename: string, options: { packageFullName?: string; path?: string }): Promise<void>
createFolder(knownFolderId: string, newFolderName: string, options: { packageFullName?: string; path?: string }): Promise<void>
getFile(knownFolderId: string, filename: string, options?: { packageFullName?: string; path?: string }): Promise<Blob>
uploadFiles(knownFolderId: string, files: Record<string, Blob>, options: { packageFullName?: string; path?: string; extract?: boolean }): Promise<void>
getHttpMonitorState(): Promise<HttpMonitorState>
getHttpMonitor(): Promise<HttpMonitor>
getLocationOverrideMode(): Promise<LocationOverride>
setLocationOverrideMode(override: boolean): Promise<LocationOverride>
getLocation(): Promise<Location>
setLocation(position: Location): Promise<Location>
getScreenshot(): Promise<Blob>
getNetworkCredentials(): Promise<NetworkCredentials>
addNetworkCredential(networkPath: string, username: string, password: string): Promise<void>
deleteNetworkCredential(networkPath: string): Promise<void>
getIpConfig(): Promise<NetworkAdapters>
setIpConfig(guid: string, options?: { ipAddress?: string; subnetMask?: string; defaultGateway?: string; primaryDNS?: string; secondaryDNS?: string }): Promise<void>
setComputerName(name: string): Promise<void>
getComputerName(): Promise<ComputerName>
getXboxInfo(): Promise<XboxInfo>
getOsInfo(): Promise<OSInfo>
getDeviceFamily(): Promise<DeviceFamily>
startCustomWprTrace(name: string, content: Blob): Promise<WprTraceState>
startCustomWprBootTrace(name: string, content: Blob): Promise<WprTraceState>
startWprTrace(profile: string): Promise<WprTraceState>
startWprBootTrace(profile: string): Promise<WprTraceState>
stopWprTrace(): Promise<void>
stopWprBootTrace(): Promise<void>
getWprTraceState(): Promise<WprTraceState>
getWprTraces(): Promise<WprTraces>
getWprTrace(filename: string): Promise<Blob>
deleteWprTrace(filename: string): Promise<void>
getPowerState(): Promise<PowerState>
getBatteryState(): Promise<BatteryState>
getPowerConfig(scheme: string): Promise<PowerConfig>
setPowerConfig(scheme: string, valueAC: number, valueDC: number): Promise<void>
setPowerActiveScheme(scheme: string): Promise<void>
getPowerActiveScheme(): Promise<ActivePowerScheme>
getSleepStudyReports(): Promise<SleepStudyReports>
getSleepStudyReport(fileName: string): Promise<Blob>
getSleepStudyTransform(): Promise<Blob>
getRootKeys(containerId?: string): Promise<RegistryRootKeys>
getSubKeys(rootKey: string, options?: { regKey?: string; containerId?: string }): Promise<RegistrySubKeys>
getRegValues(rootKey: string, options?: { regKey?: string; containerId?: string }): Promise<RegistryValues>
restart(): Promise<void>
shutdown(): Promise<void>
getPhysicalControllers(): Promise<PhysicalControllers>
disconnectPhysicalControllers(): Promise<void>
getRemoteInput(options?: { timeout?: number }): Promise<RemoteInput>
getProcesses(options?: { containerId?: string }): Promise<Processes>
getSystemPerformanceStatistics(): Promise<PerformanceStatistics>
getSmbCredentials(): Promise<SmbCredentials>
getSettings(): Promise<Settings>
getSetting(name: string): Promise<Setting>
setSetting(name: string, value: any): Promise<Setting>
startApp(appId: string, options?: { holographic?: boolean; packageFullName?: string }): Promise<void>
stopApp(packageFullName: string, force?: boolean): Promise<void>
suspendApp(packageFullName: string): Promise<void>
resumeApp(packageFullName: string): Promise<void>
stopProcess(pid: number, options?: { containerId?: string }): Promise<void>
getSignedInUser(): Promise<ActiveUser>
getUsers(): Promise<Users>
deleteUser(userId: number): Promise<void>
addUser(email: string, password: string, autoSignIn?: boolean): Promise<void>
setUserSignInState(userId: number, signIn: boolean): Promise<void>
getWindows(containerId?: string): Promise<any>
getWirelessInterfaces(): Promise<WifiInterfaces>
getAvailableWirelessNetworks(guid: string): Promise<WifiNetworks>
connectToNetwork(guid: string, ssid: string, key: string, createProfile?: boolean): Promise<void>
connectToNetworkUsingProfile(guid: string, profile: string): Promise<void>
disconnectFromNetwork(guid: string): Promise<void>
deleteWifiProfile(guid: string, profile: string): Promise<void>
getXboxLiveSandbox(): Promise<XboxLiveSandbox>
setXboxLiveSandbox(sandbox: string): Promise<XboxLiveSandbox>