diff --git a/lib/commands/bidi/constants.ts b/lib/commands/bidi/constants.ts index cc35fc15..8ef0347e 100644 --- a/lib/commands/bidi/constants.ts +++ b/lib/commands/bidi/constants.ts @@ -1,3 +1,5 @@ export const BIDI_EVENT_NAME = 'bidiEvent'; -export const CONTEXT_UPDATED_EVENT = 'appium.contextUpdated'; +export const CONTEXT_UPDATED_EVENT = (domain: string) => `appium:${domain}.contextUpdated`; +/** @deprecated Use {@link CONTEXT_UPDATED_EVENT} instead */ +export const CONTEXT_UPDATED_EVENT_OBSOLETE = 'appium.contextUpdated'; export const LOG_ENTRY_ADDED_EVENT = 'log.entryAdded'; diff --git a/lib/commands/bidi/models.ts b/lib/commands/bidi/models.ts index e8c69d5f..18cf2b7a 100644 --- a/lib/commands/bidi/models.ts +++ b/lib/commands/bidi/models.ts @@ -1,11 +1,15 @@ import type { LogEntryAddedEvent, ContextUpdatedEvent } from './types'; import { NATIVE_WIN } from '../context/helpers'; -import { CONTEXT_UPDATED_EVENT, LOG_ENTRY_ADDED_EVENT } from './constants'; +import { + CONTEXT_UPDATED_EVENT, + LOG_ENTRY_ADDED_EVENT, + CONTEXT_UPDATED_EVENT_OBSOLETE, +} from './constants'; import type { LogcatRecord as LogEntry } from 'appium-adb'; -export function makeContextUpdatedEvent(contextName: string): ContextUpdatedEvent { +function toContextUpdatedEvent(method: string, contextName: string): ContextUpdatedEvent { return { - method: CONTEXT_UPDATED_EVENT, + method, params: { name: contextName, type: contextName === NATIVE_WIN ? 'NATIVE' : 'WEB', @@ -13,6 +17,17 @@ export function makeContextUpdatedEvent(contextName: string): ContextUpdatedEven }; } +export const makeContextUpdatedEvent = (contextName: string, domain: string) => toContextUpdatedEvent( + CONTEXT_UPDATED_EVENT(domain), contextName +); + +/** + * @deprecated Use {@link makeContextUpdatedEvent} instead + */ +export const makeObsoleteContextUpdatedEvent = (contextName: string) => toContextUpdatedEvent( + CONTEXT_UPDATED_EVENT_OBSOLETE, contextName +); + export function makeLogEntryAddedEvent(entry: LogEntry, context: string, type: string): LogEntryAddedEvent { return { context, diff --git a/lib/commands/context/exports.js b/lib/commands/context/exports.js index 8a978d92..2ee9682a 100644 --- a/lib/commands/context/exports.js +++ b/lib/commands/context/exports.js @@ -18,7 +18,7 @@ import { } from './helpers'; import {APP_STATE} from '../app-management'; import { BIDI_EVENT_NAME } from '../bidi/constants'; -import { makeContextUpdatedEvent } from '../bidi/models'; +import { makeContextUpdatedEvent, makeObsoleteContextUpdatedEvent } from '../bidi/models'; // https://github.com/appium/appium/issues/20710 const DEFAULT_NATIVE_WINDOW_HANDLE = '1'; @@ -382,7 +382,8 @@ export function isChromedriverContext(viewName) { */ export async function notifyBiDiContextChange() { const name = await this.getCurrentContext(); - this.eventEmitter.emit(BIDI_EVENT_NAME, makeContextUpdatedEvent(name)); + this.eventEmitter.emit(BIDI_EVENT_NAME, makeContextUpdatedEvent(_.toLower(String(this.opts.automationName)), name)); + this.eventEmitter.emit(BIDI_EVENT_NAME, makeObsoleteContextUpdatedEvent(name)); } /**