diff --git a/packages/appium/lib/appium.js b/packages/appium/lib/appium.js index f16187c0d..d08847a49 100644 --- a/packages/appium/lib/appium.js +++ b/packages/appium/lib/appium.js @@ -24,7 +24,7 @@ import { import {util} from '@appium/support'; import {getDefaultsForExtension} from './schema'; import {DRIVER_TYPE, BIDI_BASE_PATH} from './constants'; -import * as bidiHelpers from './bidi'; +import * as bidiCommands from './bidi-commands'; import * as inspectorCommands from './inspector-commands'; const desiredCapabilityConstraints = /** @type {const} */ ({ @@ -429,7 +429,7 @@ class AppiumDriver extends DriverCore { if (dCaps.webSocketUrl) { const {address, port, basePath} = this.args; const scheme = `ws${this.server.isSecure() ? 's' : ''}`; - const host = bidiHelpers.determineBiDiHost(address); + const host = bidiCommands.determineBiDiHost(address); const bidiUrl = `${scheme}://${host}:${port}${basePath}${BIDI_BASE_PATH}/${innerSessionId}`; this.log.info( `Upstream driver responded with webSocketUrl ${dCaps.webSocketUrl}, will rewrite to ` + @@ -568,32 +568,6 @@ class AppiumDriver extends DriverCore { } } - /** - * @param {string} sessionId - */ - cleanupBidiSockets(sessionId) { - // clean up any bidi sockets associated with session - if (this.bidiSockets[sessionId]) { - try { - this.log.debug(`Closing bidi socket(s) associated with session ${sessionId}`); - for (const ws of this.bidiSockets[sessionId]) { - // 1001 means server is going away - ws.close(1001, 'Appium session is closing'); - } - } catch {} - delete this.bidiSockets[sessionId]; - const proxyClient = this.bidiProxyClients[sessionId]; - if (proxyClient) { - this.log.debug(`Also closing proxy connection to upstream bidi server`); - try { - // 1000 means normal closure, which seems correct when Appium is acting as the client - proxyClient.close(1000); - } catch {} - delete this.bidiProxyClients[sessionId]; - } - } - } - async deleteAllSessions(opts = {}) { const sessionsCount = _.size(this.sessions); if (0 === sessionsCount) { @@ -938,9 +912,11 @@ class AppiumDriver extends DriverCore { return dstSession && dstSession.canProxy(sessionId); } - onBidiConnection = bidiHelpers.onBidiConnection; - onBidiMessage = bidiHelpers.onBidiMessage; - onBidiServerError = bidiHelpers.onBidiServerError; + onBidiConnection = bidiCommands.onBidiConnection; + onBidiMessage = bidiCommands.onBidiMessage; + onBidiServerError = bidiCommands.onBidiServerError; + cleanupBidiSockets = bidiCommands.cleanupBidiSockets; + listCommands = inspectorCommands.listCommands; listExtensions = inspectorCommands.listExtensions; } diff --git a/packages/appium/lib/bidi.ts b/packages/appium/lib/bidi-commands.ts similarity index 95% rename from packages/appium/lib/bidi.ts rename to packages/appium/lib/bidi-commands.ts index 617f2230d..e8ef2f2cb 100644 --- a/packages/appium/lib/bidi.ts +++ b/packages/appium/lib/bidi-commands.ts @@ -176,6 +176,38 @@ export function onBidiServerError(this: AppiumDriver, err: Error): void { this.log.warn(`Error from bidi websocket server: ${err}`); } +/** + * Clean up any bidi sockets associated with session + * + * @param sessionId + */ +export function cleanupBidiSockets(this: AppiumDriver, sessionId: string): void { + if (!this.bidiSockets[sessionId]) { + return; + } + try { + this.log.debug(`Closing bidi socket(s) associated with session ${sessionId}`); + for (const ws of this.bidiSockets[sessionId]) { + // 1001 means server is going away + ws.close(1001, 'Appium session is closing'); + } + } catch {} + delete this.bidiSockets[sessionId]; + + const proxyClient = this.bidiProxyClients[sessionId]; + if (!proxyClient) { + return; + } + this.log.debug(`Also closing proxy connection to upstream bidi server`); + try { + // 1000 means normal closure, which seems correct when Appium is acting as the client + proxyClient.close(1000); + } catch {} + delete this.bidiProxyClients[sessionId]; +} + +// #region Private functions + /** * Initialize a new bidi connection * @param ws The websocket connection object @@ -468,3 +500,5 @@ function initBidiEventListeners( plugin.eventEmitter?.on(BIDI_EVENT_NAME, eventListenerFactory('plugin', plugin)); } } + +// #endregion diff --git a/packages/base-driver/lib/basedriver/commands/inspector.ts b/packages/base-driver/lib/basedriver/commands/inspector.ts deleted file mode 100644 index b3a9388fe..000000000 --- a/packages/base-driver/lib/basedriver/commands/inspector.ts +++ /dev/null @@ -1,39 +0,0 @@ -import type { - Constraints, - IInspectorCommands, - ListCommandsResponse, - ListExtensionsResponse, -} from '@appium/types'; -import {mixin} from './mixin'; - -declare module '../driver' { - // eslint-disable-next-line @typescript-eslint/no-unused-vars - interface BaseDriver extends IInspectorCommands {} -} - -const InspectorCommands: IInspectorCommands = { - - /** - * This command is supposed to be handled by the umbrella driver. - * - * @param sessionId - * @returns - */ - // eslint-disable-next-line @typescript-eslint/no-unused-vars - async listCommands(sessionId?: string | null): Promise { - return {}; - }, - - /** - * This command is supposed to be handled by the umbrella driver. - * - * @param sessionId - * @returns - */ - // eslint-disable-next-line @typescript-eslint/no-unused-vars - async listExtensions(sessionId?: string | null): Promise { - return {}; - }, -}; - -mixin(InspectorCommands); diff --git a/packages/types/lib/driver.ts b/packages/types/lib/driver.ts index 740931d8b..0885d01e4 100644 --- a/packages/types/lib/driver.ts +++ b/packages/types/lib/driver.ts @@ -7,8 +7,6 @@ import type { BiDiResultData, ExecuteMethodMap, MethodMap, - ListCommandsResponse, - ListExtensionsResponse, } from './command'; import type {ServerArgs} from './config'; import type {HTTPHeaders, HTTPMethod} from './http'; @@ -24,6 +22,7 @@ export interface IDeviceSettings { update(newSettings: T): Promise; getSettings(): T; } + export interface ITimeoutCommands { /** * Set the various timeouts associated with a session @@ -360,11 +359,6 @@ export interface IBidiCommands { bidiStatus(): Promise; } -export interface IInspectorCommands { - listCommands(): Promise; - listExtensions(): Promise; -} - /** * A record of {@linkcode LogDef} objects, keyed by the log type name. * Used in {@linkcode ILogCommands.supportedLogTypes}