Voice Cockpit entry no longer switches Contacts on (#1889)

* fix(voice): voice Cockpit entry no longer turns Contacts on

Voice entry now changes no Context mode or detection setting, as the COCKPIT
button does not. An entry that names a layer or class searches that layer's
own aircraft, nearest first from the followed aircraft or the ground under
the camera, and follows the nearest match before entering; the followed
aircraft counts when it matches. A military request while Military Flights
is off switches that layer on as a plain layer. The class filter is shared
with Contacts navigation.

* fix(voice): a military Cockpit entry waits for the layer's first data and leaves no layer behind

A military entry that switched Military Flights on waits for that layer to
report its first data before searching it, bounded by that update, the
layer failing or going off, and the request's cancellation. If entry then
fails, the layer is switched off again; a layer that was already on stays
on. The search covers only the aircraft the person's filters show.

* Add the changelog entry
This commit is contained in:
Sameh Khamis authored and GitHub committed 2026-11-20 22:01:03 -08:00
1 parent 5608b12a25
commit fbbe6cd91f
9 files changed
+568 -384

No files matched your search

+57 -8
View File
@@ -9,7 +9,13 @@ import {
subjectEntryAllowed,
} from '../contextModePolicy.js';
import { cockpitSubjectProviders } from '../cockpitSubjectProviders.js';
import { formatAwarenessLabel } from '../data/militaryAwarenessEngine.js';
import {
AWARENESS_MAX_FLIGHT_SEARCH_RADIUS_M,
aircraftClassMatches,
formatAwarenessLabel,
} from '../data/militaryAwarenessEngine.js';
import { fromDegreesInto } from '../geo/ellipsoid.js';
import { findCamera } from '../render/rendererOf.js';
import { enterCockpitWithTracking } from '../cockpitTracking.js';
import { cockpitVisionModeForStyle } from '../cockpitVisionPolicy.js';
import { readEntityRecord } from '../data/entityRecords.js';
@@ -352,13 +358,41 @@ export class CockpitCoordinator {
};
}
/**
* Where a requested-layer entry searches from: the aircraft the camera
* follows, else the ground under the camera.
* @param {{layerId: string}|null} currentTarget The tracked aircraft.
* @returns {{x: number, y: number, z: number}|null}
*/
_cockpitEntrySearchOrigin(currentTarget) {
const { flightsLayer, militaryFlightsLayer } = this.services;
const layer =
currentTarget?.layerId === 'military'
? militaryFlightsLayer
: currentTarget?.layerId === 'flights'
? flightsLayer
: null;
const subject = layer?.getTrackedSubject?.();
if (subject?.position) return subject.position;
const pose = findCamera(this.viewer)?.pose?.();
if (!Number.isFinite(pose?.lat) || !Number.isFinite(pose?.lon)) return null;
return fromDegreesInto(pose.lon, pose.lat, 0, { x: 0, y: 0, z: 0 });
}
/**
* Retarget a voice entry to the requested layer and class before entering.
* It searches the aircraft that layer shows, under the person's own
* filters, nearest first, from the followed aircraft or the camera, and
* follows the nearest match; the aircraft already followed counts when it
* matches. It needs nothing from Contacts.
*/
_retargetCockpitEntryLayer({
targetLayer,
aircraftClass,
currentTarget,
selectedTarget,
}) {
const { militaryAwarenessLayer } = this.services;
const { flightsLayer, militaryFlightsLayer } = this.services;
if (!['flights', 'military'].includes(targetLayer)) {
return {
ok: false,
@@ -370,12 +404,27 @@ export class CockpitCoordinator {
const alreadyOnLayer = activeLayer === targetLayer;
if (alreadyOnLayer && !aircraftClass)
return { ok: true, retargeted: false };
const moved = militaryAwarenessLayer?.navigateNext
? !!militaryAwarenessLayer.navigateNext({
targetLayer,
aircraftClass,
origin: 'voice',
})
const layer =
targetLayer === 'military' ? militaryFlightsLayer : flightsLayer;
const origin = this._cockpitEntrySearchOrigin(currentTarget);
const nearby =
origin && typeof layer?.getNearby === 'function'
? layer.getNearby(
origin,
AWARENESS_MAX_FLIGHT_SEARCH_RADIUS_M,
targetLayer === 'military' ? 5000 : 25000,
)
: [];
const match = nearby.find(
(item) => item?.icao24 && aircraftClassMatches(item, aircraftClass),
);
const followed =
match &&
currentTarget?.layerId === targetLayer &&
String(currentTarget.id) === String(match.icao24);
if (followed) return { ok: true, retargeted: false };
const moved = match
? !!layer.trackById?.(match.icao24, { origin: 'voice' })
: false;
if (moved) return { ok: true, retargeted: true };
// A filter that matched nothing still enters, as long as the layer is
+76
View File
@@ -869,3 +869,79 @@ test('a malformed provider is left out and the built-in kinds are unchanged', as
assert.equal(cockpit.enter(), true);
assert.equal(cockpit.subjectKind, 'aircraft');
});
// A requested-layer entry finds its aircraft in that layer, from the
// aircraft the camera follows; it never asks Contacts.
function retargetFixture(t, nearby) {
const { coordinator } = fixture(t, {
enabled: ['flights', 'military'],
tracked: { layerId: 'flights', info: CIVIL },
});
const tracked = [];
const searches = [];
coordinator.services.militaryAwarenessLayer.navigateNext = () =>
assert.fail('entry must not navigate through Contacts');
coordinator.services.flightsLayer.getTrackedSubject = () => ({
layerId: 'flights',
id: CIVIL.icao24,
position: { x: 1, y: 2, z: 3 },
});
coordinator.services.militaryFlightsLayer.getNearby = (...args) => {
searches.push(args);
return nearby;
};
coordinator.services.militaryFlightsLayer.trackById = (id, options) => {
tracked.push([id, options.origin]);
return true;
};
return { coordinator, tracked, searches };
}
test('a voice entry asking for a military class follows the nearest match without Contacts', (t) => {
const { coordinator, tracked, searches } = retargetFixture(t, [
{ icao24: 'jet1', aircraftClass: 'fighter', distance: 10 },
{ icao24: 'helo1', aircraftClass: 'helicopter', distance: 20 },
{ icao24: 'helo2', aircraftClass: 'helicopter', distance: 30 },
]);
const result = coordinator._retargetCockpitEntryLayer({
targetLayer: 'military',
aircraftClass: 'helicopter',
currentTarget: { layerId: 'flights', id: CIVIL.icao24 },
selectedTarget: null,
});
assert.deepEqual(result, { ok: true, retargeted: true });
assert.deepEqual(tracked, [['helo1', 'voice']]);
// Searched from the followed aircraft, among the aircraft the person's
// filters show: never the hidden ones.
assert.deepEqual(searches[0][0], { x: 1, y: 2, z: 3 });
assert.equal(searches[0][3], undefined);
});
test('a voice entry whose followed aircraft already matches stays on it', (t) => {
const { coordinator, tracked } = retargetFixture(t, [
{ icao24: 'helo1', aircraftClass: 'helicopter', distance: 0 },
]);
const result = coordinator._retargetCockpitEntryLayer({
targetLayer: 'military',
aircraftClass: 'helicopter',
currentTarget: { layerId: 'military', id: 'helo1' },
selectedTarget: null,
});
assert.deepEqual(result, { ok: true, retargeted: false });
assert.deepEqual(tracked, []);
});
test('a voice entry with no matching aircraft says so and follows nothing', (t) => {
const { coordinator, tracked } = retargetFixture(t, [
{ icao24: 'jet1', aircraftClass: 'fighter', distance: 10 },
]);
const result = coordinator._retargetCockpitEntryLayer({
targetLayer: 'military',
aircraftClass: 'helicopter',
currentTarget: { layerId: 'flights', id: CIVIL.icao24 },
selectedTarget: null,
});
assert.equal(result.ok, false);
assert.match(result.error, /No helicopter military contact is available/);
assert.deepEqual(tracked, []);
});