appium-xcuitest-driver
Version:
Appium driver for iOS using XCUITest for backend
67 lines • 2.92 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConnectedDevicesClient = void 0;
const appium_ios_device_1 = require("appium-ios-device");
const node_devicectl_1 = require("node-devicectl");
const logger_1 = require("../logger");
const remote_xpc_1 = require("./remote-xpc");
class ConnectedDevicesClient {
services;
constructor(services) {
this.services = services;
}
/**
* Create a connected devices client instance.
* When opts indicate iOS/tvOS 18+, loads and stores the remotexpc Services
* instance for tunnel registry listing; otherwise uses legacy listing only.
*/
static async create(opts) {
const services = await remote_xpc_1.RemoteXPCFacade.tryGetServicesStatic(opts.platformVersion);
return new ConnectedDevicesClient(services);
}
/**
* Returns the list of connected real device UDIDs.
* Only considers tunnel registry UDIDs when remotexpc is loaded and tunnels are running;
* otherwise returns the legacy list only.
*/
async getConnectedDevices() {
const [tunnelSettled, legacySettled] = await Promise.allSettled([
this.listUdidsFromTunnelsRegistry(),
this.listLegacyUdids(),
]);
// Tunnels succeeded → short-circuit: return tunnel UDIDs only (legacy not used)
if (tunnelSettled.status === 'fulfilled') {
return tunnelSettled.value;
}
// Tunnels rejected (only other status after fulfilled) → use legacy; throw if legacy failed
const err = tunnelSettled.reason;
logger_1.log.warn((0, remote_xpc_1.formatRemoteXPCFallbackLog)('devices listing', err));
if (legacySettled.status === 'rejected') {
throw legacySettled.reason instanceof Error ? legacySettled.reason : new Error(String(legacySettled.reason));
}
return legacySettled.value;
}
isPreferDevicectlEnabled() {
return ['yes', 'true', '1'].includes(String(process.env.APPIUM_XCUITEST_PREFER_DEVICECTL ?? '').toLowerCase());
}
/**
* Fetches UDIDs from the tunnel registry.
* @throws When remotexpc is not loaded or when the tunnel registry is unreachable.
*/
async listUdidsFromTunnelsRegistry() {
if (!this.services) {
throw new Error('appium-ios-remotexpc module cannot be loaded');
}
return await this.services.getAvailableDevices();
}
async listLegacyUdids() {
if (this.isPreferDevicectlEnabled()) {
return (await new node_devicectl_1.Devicectl('').listDevices())
.map(({ hardwareProperties }) => hardwareProperties?.udid)
.filter(Boolean);
}
return await appium_ios_device_1.utilities.getConnectedDevices();
}
}
exports.ConnectedDevicesClient = ConnectedDevicesClient;
//# sourceMappingURL=connected-devices-client.js.map