feat(vessels): key vessels by their source's stable id, and share a selected vessel

AIS Vessels are keyed by the id their live source gives, with the MMSI as an
attribute: an MMSI can be shared, spoofed or reused, so two vessels with one
MMSI are now two vessels. Looking a vessel up or selecting it by MMSI still
finds it.

A share link made while a vessel is selected opens that vessel. A UUID vessel
id travels as 16 bytes in a new thing field (13). A shared thing that is not
reporting now says so in a sentence per kind, with its id (ICAO, NORAD, MMSI
or vessel UUID) on a second line.
This commit is contained in:
Sameh Khamis committed 2026-11-10 18:12:53 -08:00
1 parent 57ff81f723
commit cbbf55cacd
74 files changed
+2481 -586

No files matched your search

+6 -1
View File
@@ -472,7 +472,12 @@ export class StyleManager extends ShellFacade {
initialShareCode,
});
this.shareLinkManager.setFollowSubjectProvider(({ nowMs }) =>
readShareFollowSubject({ viewer: this.viewer, nowMs }),
readShareFollowSubject({
viewer: this.viewer,
nowMs,
readSelectedVessel: () =>
this.services.aisLiveVesselsLayer?.getSelectedFix?.() ?? null,
}),
);
this.shareLinkManager.setPanelStateProvider(() =>
this._buildSharePanelState(),
+15 -9
View File
@@ -15,6 +15,7 @@ import { vesselCockpitInfo } from '../layers/vessels/cockpitSubject.js';
import { VesselRecords } from '../layers/vessels/records.js';
const RECORD = Object.freeze({
id: '211000000',
mmsi: '211000000',
name: 'NORDIC STAR',
type: '70',
@@ -65,9 +66,9 @@ function vesselLayer(record) {
enabled && selected
? { ...vesselCockpitInfo(selected), seaSurfaceHeightM: 0 }
: null,
setCockpitSubject(mmsi) {
calls.push(['subject', mmsi]);
subject = mmsi;
setCockpitSubject(id) {
calls.push(['subject', id]);
subject = id;
return true;
},
// Like the layer, leaves out the ship whose bridge the Cockpit rides.
@@ -75,7 +76,7 @@ function vesselLayer(record) {
radarQueries.push({ lat, lon, rangeM, maxCount });
const own = {
...NEIGHBOUR,
id: record.mmsi,
id: record.id,
latitude: record.lat,
longitude: record.lon,
};
@@ -257,7 +258,7 @@ test('entering the bridge hides the vessel and shows bridge readouts', async (t)
await settle();
assert.equal(cockpit.active, true);
assert.equal(cockpit.subjectKind, 'vessel');
assert.deepEqual(vessels.calls, [['subject', RECORD.mmsi]]);
assert.deepEqual(vessels.calls, [['subject', RECORD.id]]);
assert.equal(document.body.classList.contains('cockpit-mode'), true);
assert.equal(
@@ -303,7 +304,7 @@ test('exiting the bridge releases the vessel and returns to its map view', async
assert.equal(cockpit.active, false);
assert.equal(cockpit.subjectKind, null);
assert.deepEqual(vessels.calls, [
['subject', RECORD.mmsi],
['subject', RECORD.id],
['subject', null],
['focus'],
]);
@@ -374,7 +375,7 @@ test('tracking an aircraft from the bridge ends it without refocusing the vessel
assert.equal(viewer.trackedEntity, aircraft, 'the aircraft keeps tracking');
assert.equal(aircraft.show, true, 'the aircraft was never adopted');
assert.deepEqual(vessels.calls, [
['subject', RECORD.mmsi],
['subject', RECORD.id],
['subject', null],
]);
});
@@ -1474,7 +1475,7 @@ test('a fix the feed keeps re-serving goes on ageing into a stale feed', async (
effects,
);
poll();
const record = records.byMmsi.get(RECORD.mmsi);
const record = records.byId.get(RECORD.id);
const { $, cockpit, shots } = fixture(t, { record });
cockpit.enter();
await settle();
@@ -1540,7 +1541,12 @@ test("a ship's double-click memory does not carry over to another ship", async (
heightSensitiveProjection(viewer);
cockpit.onScenePointerDown(1000);
// Within the memory another ship is selected, drawn elsewhere.
vessels.select({ ...RECORD, mmsi: '211000009', name: 'OTHER' });
vessels.select({
...RECORD,
id: '211000009',
mmsi: '211000009',
name: 'OTHER',
});
heightSensitiveProjection(viewer, { x: 900 });
assert.equal(cockpit.onSceneDoubleClick({ x: 400, y: 300 }, 1250), false);
assert.equal(cockpit.active, false);
+1 -1
View File
@@ -164,7 +164,7 @@ export function maybeRefreshRegionalBrief(info) {
!Number.isFinite(info.longitude)
)
return;
const subjectId = `${info.layerId || 'aircraft'}:${info.icao24 || info.mmsi || info.noradId || info.registration || info.callsign || 'unknown'}`;
const subjectId = `${info.layerId || 'aircraft'}:${info.icao24 || (info.kind === 'vessel' ? info.id : '') || info.noradId || info.registration || info.callsign || 'unknown'}`;
if (subjectId !== this.regionalBriefSubjectId) {
this.regionalBriefAbort?.abort();
this.regionalBriefAbort = null;
+3 -3
View File
@@ -128,7 +128,7 @@ function vesselSurfaceM(info, nowMs, at = info) {
: 0;
const scene = this.viewer.scene;
let read =
this.vesselWaterline?.mmsi === info.mmsi ? this.vesselWaterline : null;
this.vesselWaterline?.vesselId === info.id ? this.vesselWaterline : null;
if (
typeof scene?.sampleHeightMostDetailed === 'function' &&
(!read || nowMs - read.sampledMs >= VESSEL_WATERLINE_REFRESH_MS)
@@ -138,7 +138,7 @@ function vesselSurfaceM(info, nowMs, at = info) {
);
if (!read) {
read = {
mmsi: info.mmsi,
vesselId: info.id,
heightM: loadedWaterlineM(scene, probes, seaM),
sampledMs: nowMs,
// Whether a full-detail read has answered for this ship.
@@ -219,7 +219,7 @@ function updateVessel(nowMs) {
return;
}
const info = this.readVesselInfo();
if (!info || info.mmsi !== this.subjectId) {
if (!info || info.id !== this.subjectId) {
this.exit({ restoreTracking: false });
return;
}
+1 -1
View File
@@ -139,7 +139,7 @@ export class CockpitViewController {
*/
this.subjectKind = null;
/**
* The vessel subject's MMSI or the satellite's NORAD id; aircraft are
* The vessel subject's id or the satellite's NORAD id; aircraft are
* identified by trackedEntity.
*/
this.subjectId = null;
+1 -1
View File
@@ -255,7 +255,7 @@ export class CockpitCoordinator {
: vessel
? {
kind: 'vessel',
id: vessel.mmsi,
id: vessel.id,
layerId: vessel.layerId,
callsign: null,
name: vessel.name,
+5 -3
View File
@@ -83,8 +83,10 @@ export function onScenePointerDown(nowMs = performance.now()) {
return;
}
const at = subjectCanvasPosition.call(this);
const mmsi = this.readVesselInfo()?.mmsi ?? null;
this.doubleClickStart = at ? { x: at.x, y: at.y, atMs: nowMs, mmsi } : null;
const vesselId = this.readVesselInfo()?.id ?? null;
this.doubleClickStart = at
? { x: at.x, y: at.y, atMs: nowMs, vesselId }
: null;
}
/**
@@ -111,7 +113,7 @@ export function onSceneDoubleClick(position, nowMs = performance.now()) {
// The memory is the ship's it was taken for: one followed since (an
// aircraft, another ship) is hit only where it is drawn.
this.resolveEntryKind() === 'vessel' &&
start.mmsi === (this.readVesselInfo()?.mmsi ?? null) &&
start.vesselId === (this.readVesselInfo()?.id ?? null) &&
doubleClickHitsSubject(position, start));
if (!hit) return false;
this.enter();
+8 -3
View File
@@ -65,7 +65,12 @@ export function resolveEntryKind() {
export function dispatchCockpitModeChanged(active, info = null) {
const subjectId = active
? String(info?.icao24 || info?.mmsi || info?.noradId || '')
? String(
info?.icao24 ||
(info?.kind === 'vessel' ? info.id : '') ||
info?.noradId ||
'',
)
.trim()
.toLowerCase() || null
: null;
@@ -245,7 +250,7 @@ export function enter({ kind = null } = {}) {
// Each session reads its own water: never a height left from the last.
this.vesselWaterline = null;
this.vesselFix = null;
this.subjectId = vessel ? info.mmsi : satellite ? info.noradId : null;
this.subjectId = vessel ? info.id : satellite ? info.noradId : null;
this.trackedEntity = entity;
if (entity) {
this.trackedEntityWasShown = entity.show;
@@ -255,7 +260,7 @@ export function enter({ kind = null } = {}) {
this.services.satellitesLayer?.setCockpitSubject?.(info.noradId);
this.beginOrbital();
} else {
this.services.aisLiveVesselsLayer?.setCockpitSubject?.(info.mmsi);
this.services.aisLiveVesselsLayer?.setCockpitSubject?.(info.id);
}
// A ship reporting neither heading nor course keeps the camera's own
// heading: no direction is made up for it.
+59 -6
View File
@@ -2,6 +2,8 @@ import * as Cesium from 'cesium';
import { trackedDisplayPositionForCamera } from '../data/trackedCamera.js';
import {
SHARE_VIEW_ENTITY_KINDS,
SHARE_VIEW_FOLLOW_RANGE_MAX_M,
followOffsetFor,
followOffsetFromEnu,
followOffsetToEnu,
} from '../share/follow.js';
@@ -28,17 +30,68 @@ function enuOffset(origin, position) {
return { east: local.x, north: local.y, up: local.z };
}
/** Degrees to the share format's 10⁻⁴-degree coordinate precision. */
const toCoordinate = (radians) =>
Math.round(Cesium.Math.toDegrees(radians) * 1e4) / 1e4;
/**
* The entity the camera follows as `{ kind, id, offset, lastKnown }`, with
* the camera's offset from it and its displayed position as of `nowMs`; null
* when the camera follows nothing a share link can name. A selected vessel is
* not followed (the camera stays where the user puts it), so a link made then
* keeps its own camera.
* The selected vessel as a thing view's subject: its drawn position as the
* last-known fix, and the follow offset that puts the derived camera
* (followCameraFor) where the camera is now. The offset is computed from the
* fix at the format's precision, so the opened link's camera matches this
* one to within the offset's whole metres and degrees. Null when the offset
* cannot carry the camera (it is not above the vessel's horizon, or its range
* is outside 1 m to SHARE_VIEW_FOLLOW_RANGE_MAX_M): the link is then a place
* view.
*/
export function readShareFollowSubject({ viewer, nowMs = Date.now() }) {
function selectedVesselSubject(cameraPosition, vessel, nowMs) {
const id = String(vessel?.id || '');
if (!id || !vessel.position) return null;
const fixAt = Cesium.Cartographic.fromCartesian(vessel.position);
const cameraAt = Cesium.Cartographic.fromCartesian(cameraPosition);
if (!fixAt || !cameraAt) return null;
const lastKnown = {
lat: toCoordinate(fixAt.latitude),
lon: toCoordinate(fixAt.longitude),
alt: Math.round(fixAt.height),
observedAtMs: Number.isFinite(vessel.observedAtMs)
? vessel.observedAtMs
: nowMs,
};
const offset = followOffsetFor(lastKnown, {
lat: Cesium.Math.toDegrees(cameraAt.latitude),
lon: Cesium.Math.toDegrees(cameraAt.longitude),
alt: cameraAt.height,
});
if (
!offset ||
!(offset.range >= 1 && offset.range <= SHARE_VIEW_FOLLOW_RANGE_MAX_M)
)
return null;
return { kind: 'vessel', id, offset, lastKnown };
}
/**
* The entity a share link made now names, as `{ kind, id, offset, lastKnown }`:
* the entity the camera follows, with the camera's offset from it and its
* displayed position as of `nowMs`; else, while the camera follows nothing,
* the selected vessel (`readSelectedVessel()`, the vessel layer's
* `getSelectedFix()`). A selected vessel is not followed (the camera stays
* where the user puts it), so its offset is the one that derives the camera
* where it is now. Null when there is nothing a share link can name.
*/
export function readShareFollowSubject({
viewer,
nowMs = Date.now(),
readSelectedVessel = null,
}) {
const cameraPosition = viewer?.camera?.positionWC;
if (!cameraPosition) return null;
const tracked = viewer.trackedEntity;
if (!tracked) {
const vessel = readSelectedVessel?.() ?? null;
return vessel ? selectedVesselSubject(cameraPosition, vessel, nowMs) : null;
}
const trackedId = String(tracked?.gevTrackedId || '');
const separator = trackedId.indexOf(':');
if (separator <= 0) return null;
+218 -10
View File
@@ -12,6 +12,7 @@ import {
} from './shareFollow.js';
import { createDefaultLayerState } from '../data/layerState.js';
import { parseSharePath, shareLinkUrl } from '../share/shareLinkPath.js';
import { worldClock } from '../time/worldClock.js';
import {
decodeShareView,
encodeShareView,
@@ -234,7 +235,9 @@ test('a code that fails its check restores nothing and says so', async (t) => {
(await page.owner.initialRestorePromise).status,
'not-requested',
);
assert.deepEqual(page.notices, ["This share link can't be opened"]);
assert.deepEqual(page.notices, [
{ message: "This share link can't be opened" },
]);
// The default start's first address write leaves the bad link behind.
page.manager._updateHash();
assert.equal(page.location.pathname, '/');
@@ -334,9 +337,10 @@ test('a thing that is not reporting leaves the view at its last-known fix, with
await flush();
assert.equal(page.notices.length, 1);
assert.match(
page.notices[0],
/^A1B2C3 isn't reporting now — showing where it was at .+/,
page.notices[0].message,
/^The shared flight isn't reporting now — showing where it was at .+/,
);
assert.equal(page.notices[0].detail, 'ICAO: A1B2C3');
// A long link names no fix and keeps the existing notice.
page.owner._initialShareState = { shareView: null };
page.owner._handleShareTrackingRestoreStatus({
@@ -345,19 +349,48 @@ test('a thing that is not reporting leaves the view at its last-known fix, with
label: 'flight',
classification: 'expired',
});
assert.equal(page.notices[1], 'Shared flight follow expired');
assert.deepEqual(page.notices[1], {
message: 'Shared flight follow expired',
});
});
test('the not-reporting notice names the id and the time of the fix', () => {
test('the not-reporting notice is a sentence per kind with the id on a second line', () => {
const at = new Date(2026, 9, 26, 14, 5).getTime();
const flight = sharedFixNotice(
{ kind: 'aircraft', id: 'a1b2c3' },
at,
at + 60_000,
);
assert.match(
sharedFixNotice({ kind: 'aircraft', id: 'a1b2c3' }, at, at + 60_000),
/^A1B2C3 isn't reporting now — showing where it was at .*05/,
flight.message,
/^The shared flight isn't reporting now — showing where it was at .*05/,
);
assert.equal(flight.detail, 'ICAO: A1B2C3');
assert.deepEqual(
sharedFixNotice({ kind: 'military_aircraft', id: 'ae01ce' }, null),
{
message:
"The shared military flight isn't reporting now — showing where it was last seen",
detail: 'ICAO: AE01CE',
},
);
assert.deepEqual(sharedFixNotice({ kind: 'vessel', id: '366999712' }, null), {
message:
"The shared vessel isn't reporting now — showing where it was last seen",
detail: 'MMSI: 366999712',
});
assert.equal(
sharedFixNotice({ kind: 'vessel', id: '366999712' }, null),
"366999712 isn't reporting now — showing where it was last seen",
sharedFixNotice(
{ kind: 'vessel', id: '3F2504E0-4F89-11D3-9A0C-0305E82C3301' },
null,
).detail,
'Vessel UUID: 3f2504e0-4f89-11d3-9a0c-0305e82c3301',
);
assert.deepEqual(sharedFixNotice({ kind: 'satellite', id: '25544' }, null), {
message:
"The shared satellite isn't reporting now — showing where it was last seen",
detail: 'NORAD: 25544',
});
});
test('a shared vessel is selected once the vessel feed has it', async (t) => {
@@ -398,7 +431,11 @@ test('a shared vessel is selected once the vessel feed has it', async (t) => {
page.runAll();
}
assert.equal(await missing, false);
assert.match(page.notices.at(-1), /^366999712 isn't reporting now/);
assert.match(
page.notices.at(-1).message,
/^The shared vessel isn't reporting now/,
);
assert.equal(page.notices.at(-1).detail, 'MMSI: 366999712');
});
test('the share button links to /share/<code>, following the followed entity', (t) => {
@@ -552,3 +589,174 @@ test('long links and hash navigation are unaffected by a share code start', asyn
assert.equal(page.restores.length, 2);
assert.equal(page.restores[1].style, 'normal');
});
const VESSEL_UUID = '0770e3ca-b896-c307-f499-4f9df2b8f86b';
const VESSEL_AT = { lat: 51.93012, lon: 4.05118, alt: 46.6 };
/** A camera `offset` from the vessel, as Cesium places it (WGS84). */
function cameraAround(offset) {
const vessel = Cesium.Cartesian3.fromDegrees(
VESSEL_AT.lon,
VESSEL_AT.lat,
VESSEL_AT.alt,
);
const local = followOffsetToEnu(offset);
return {
vessel,
camera: Cesium.Matrix4.multiplyByPoint(
Cesium.Transforms.eastNorthUpToFixedFrame(vessel),
new Cesium.Cartesian3(local.east, local.north, local.up),
new Cesium.Cartesian3(),
),
};
}
test('a selected vessel is the subject when the camera follows nothing', (t) => {
installPage(t, 'https://gev.example/');
const offset = { range: 6400, heading: 250, pitch: -28 };
const { vessel, camera } = cameraAround(offset);
const viewer = fakeViewer();
viewer.camera.positionWC = camera;
const fixAtMs = Math.floor(NOW_MS / 1000) * 1000 - 90_000;
let selected = { id: VESSEL_UUID, position: vessel, observedAtMs: fixAtMs };
const readSelectedVessel = () => selected;
const subject = readShareFollowSubject({
viewer,
nowMs: NOW_MS,
readSelectedVessel,
});
assert.equal(subject.kind, 'vessel');
assert.equal(subject.id, VESSEL_UUID);
// The fix is the vessel's drawn position at the format's precision.
assert.deepEqual(subject.lastKnown, {
lat: 51.9301,
lon: 4.0512,
alt: 47,
observedAtMs: fixAtMs,
});
// The inverse of the derived camera, from the user's camera: within the
// offset's whole degrees of the camera that placed it.
// (The fix is rounded to 10⁻⁴°, about 11 m, before the offset is taken.)
assert.ok(Math.abs(subject.offset.range - offset.range) <= 20);
assert.ok(Math.abs(subject.offset.heading - offset.heading) <= 1);
assert.ok(Math.abs(subject.offset.pitch - offset.pitch) <= 1);
// The share button's link opens with its camera where this one is.
const manager = new ShareLinkManager(viewer);
manager.setFollowSubjectProvider(({ nowMs }) =>
readShareFollowSubject({ viewer, nowMs, readSelectedVessel }),
);
const href = manager.buildLink({ nowMs: NOW_MS });
const code = parseSharePath(new URL(href).pathname).code;
const { state } = decodeShareView(code, { nowMs: NOW_MS });
assert.deepEqual(state.view.entity, { kind: 'vessel', id: VESSEL_UUID });
assert.equal(state.view.lastKnown.observedAtMs, fixAtMs);
const opened = Cesium.Cartesian3.fromDegrees(state.lon, state.lat, state.alt);
const missM = Cesium.Cartesian3.distance(opened, camera);
// Whole degrees at 6.4 km are at most about 80 m; 10⁻⁴° is about 11 m.
assert.ok(missM < 100, `${missM.toFixed(1)} m from the camera`);
// The UUID costs 13 bytes more than an ICAO address: 16 against 3.
manager.setFollowSubjectProvider(() => ({
...subject,
kind: 'aircraft',
id: 'a1b2c3',
}));
const aircraft = parseSharePath(
new URL(manager.buildLink({ nowMs: NOW_MS })).pathname,
).code;
assert.ok(
code.length - aircraft.length <= 18,
`${code.length} against ${aircraft.length} characters`,
);
manager.destroy();
// A camera below the vessel's horizon cannot be carried: a place view.
viewer.camera.positionWC = Cesium.Cartesian3.fromDegrees(4.0512, 54, 900);
assert.equal(
readShareFollowSubject({ viewer, nowMs: NOW_MS, readSelectedVessel }),
null,
);
// Nor can one at the vessel.
viewer.camera.positionWC = vessel;
assert.equal(
readShareFollowSubject({ viewer, nowMs: NOW_MS, readSelectedVessel }),
null,
);
// With nothing selected there is no subject.
viewer.camera.positionWC = camera;
selected = null;
assert.equal(
readShareFollowSubject({ viewer, nowMs: NOW_MS, readSelectedVessel }),
null,
);
});
test('a followed aircraft or satellite keeps priority over a selected vessel', () => {
const { vessel, camera } = cameraAround({
range: 2400,
heading: 30,
pitch: -20,
});
const readSelectedVessel = () => ({
id: VESSEL_UUID,
position: vessel,
observedAtMs: NOW_MS,
});
const viewer = {
camera: { positionWC: camera },
clock: { currentTime: Cesium.JulianDate.now() },
trackedEntity: {
gevTrackedId: 'satellites:25544',
gevDisplayPosition: () => vessel,
},
};
const subject = readShareFollowSubject({ viewer, readSelectedVessel });
assert.equal(subject.kind, 'satellite');
// A followed entity the share format cannot name is still followed: the
// link is a place view, not the selected vessel.
viewer.trackedEntity.gevTrackedId = 'local-adsb:abc';
assert.equal(readShareFollowSubject({ viewer, readSelectedVessel }), null);
});
test('a link to a UUID vessel at a world time selects it once its snapshot has it', async (t) => {
t.after(() => worldClock.goLive());
const worldTime = Math.floor((NOW_MS - 3_600_000) / 1000) * 1000;
const code = encodeShareView({
view: {
kind: 'thing',
entity: { kind: 'vessel', id: VESSEL_UUID },
offset: { range: 3200, heading: 20, pitch: -30 },
lastKnown: { ...VESSEL_AT, alt: 47, observedAtMs: worldTime },
},
sharedAtMs: Math.floor(NOW_MS / 1000) * 1000,
worldTime,
});
const page = openPage(t, `http://localhost/share/${code}`);
// The link opens paused at its world time.
assert.equal(worldClock.isLive(), false);
assert.equal(worldClock.now(), worldTime);
// The vessel layer: its records are the snapshot at the clock's time, which
// arrives a moment after the layer turns on.
const records = new Set();
const selected = [];
page.owner._dataManager = {
layers: new Map([
[
'ais-live-vessels',
{
module: {
hasContact: (id) => (records.size ? records.has(id) : null),
selectById: (id) => records.has(id) && selected.push(id) > 0,
},
},
],
]),
};
await restore(page);
assert.deepEqual(selected, []);
if (worldClock.now() === worldTime) records.add(VESSEL_UUID);
page.runAll();
await flush();
assert.deepEqual(selected, [VESSEL_UUID]);
assert.deepEqual(page.notices, []);
});
+88 -24
View File
@@ -70,34 +70,88 @@ export function shareTrackingRestoreNotice(result) {
: t('Shared {subject} is unavailable', { subject });
}
// The not-reporting notice, one ready-made sentence per shared entity kind
// (SHARE_VIEW_ENTITY_KINDS) for the same reason as SHARE_RESTORE_NOTICES.
const SHARED_FIX_NOTICES = Object.freeze({
aircraft: Object.freeze({
lastSeen: msg(
"The shared flight isn't reporting now — showing where it was last seen",
),
at: msg(
"The shared flight isn't reporting now — showing where it was at {time}",
),
}),
military_aircraft: Object.freeze({
lastSeen: msg(
"The shared military flight isn't reporting now — showing where it was last seen",
),
at: msg(
"The shared military flight isn't reporting now — showing where it was at {time}",
),
}),
vessel: Object.freeze({
lastSeen: msg(
"The shared vessel isn't reporting now — showing where it was last seen",
),
at: msg(
"The shared vessel isn't reporting now — showing where it was at {time}",
),
}),
satellite: Object.freeze({
lastSeen: msg(
"The shared satellite isn't reporting now — showing where it was last seen",
),
at: msg(
"The shared satellite isn't reporting now — showing where it was at {time}",
),
}),
});
// The second line names the entity by the id the link carries.
function sharedFixDetail(entity) {
const id = String(entity.id);
switch (entity.kind) {
case 'aircraft':
case 'military_aircraft':
// ICAO addresses read as they are written on the aircraft: upper case.
return t('ICAO: {id}', { id: id.toUpperCase() });
case 'satellite':
return t('NORAD: {id}', { id });
case 'vessel':
return /^\d+$/.test(id)
? t('MMSI: {id}', { id })
: t('Vessel UUID: {id}', { id: id.toLowerCase() });
default:
return id;
}
}
/**
* The notice for a shared entity that is not reporting: the view shows where
* it was when the link was made.
* it was when the link was made. The sentence is the notice; the entity's id
* goes on a second line under it.
* @param {{kind: string, id: string}} entity
* @param {number|null} observedAtMs
* @param {number} [nowMs]
* @returns {string}
* @returns {{message: string, detail: string}}
*/
export function sharedFixNotice(entity, observedAtMs, nowMs = Date.now()) {
// ICAO addresses read as they are written on the aircraft: upper case.
const id =
ENTITY_BY_KIND.get(entity.kind)?.idForm === 'hex24'
? String(entity.id).toUpperCase()
: String(entity.id);
const detail = sharedFixDetail(entity);
const notices = SHARED_FIX_NOTICES[entity.kind];
if (!notices)
return {
message: t('Shared {subject} is unavailable', { subject: t('entity') }),
detail,
};
if (!Number.isFinite(observedAtMs))
return t("{id} isn't reporting now — showing where it was last seen", {
id,
});
return { message: t(notices.lastSeen), detail };
const time = formatDate(
observedAtMs,
nowMs - observedAtMs < DAY_MS
? { hour: '2-digit', minute: '2-digit' }
: { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' },
);
return t("{id} isn't reporting now — showing where it was at {time}", {
id,
time,
});
return { message: t(notices.at, { time }), detail };
}
/** Own initial share restoration, durable layer state and restoration notices. */
@@ -181,7 +235,7 @@ export class ShareRestoration {
this.syncShareState();
if (this.shareLinkManager?.rejectedShareCode)
this._presentAfterStartupCover(
t("This share link can't be opened"),
{ message: t("This share link can't be opened") },
++this._shareTrackingNoticeGeneration,
);
}
@@ -411,7 +465,7 @@ export class ShareRestoration {
this._presentAfterStartupCover(
view.lastKnown
? sharedFixNotice(view.entity, view.lastKnown.observedAtMs)
: t('Shared vessel is unavailable'),
: { message: t('Shared vessel is unavailable') },
++this._shareTrackingNoticeGeneration,
);
return false;
@@ -505,26 +559,36 @@ export class ShareRestoration {
// A share link that knows where the entity was says so; the view is
// already there.
const fix = this._sharedThingFor(result)?.lastKnown;
const message = fix
const notice = fix
? sharedFixNotice(
this._initialShareState.shareView.entity,
fix.observedAtMs,
)
: shareTrackingRestoreNotice(result);
: { message: shareTrackingRestoreNotice(result) };
if (this._resolveInitialShareRestore) {
void this.initialRestorePromise.then(() =>
this._presentAfterStartupCover(message, noticeGeneration),
this._presentAfterStartupCover(notice, noticeGeneration),
);
return;
}
this._presentAfterStartupCover(message, noticeGeneration);
this._presentAfterStartupCover(notice, noticeGeneration);
}
/**
* Show a status notice once the start-up cover is gone, unless a newer
* notice (generation) has taken its place.
* notice (generation) has taken its place. A notice with a detail line is
* a last-known one: the sentence over the entity's id.
* @param {{message: string, detail?: string}} notice
* @param {number} noticeGeneration
*/
_presentAfterStartupCover(message, noticeGeneration) {
_presentAfterStartupCover(notice, noticeGeneration) {
const show = () =>
notice.detail
? this.showStatus(notice.message, {
state: 'last-known',
detail: notice.detail,
})
: this.showStatus(notice.message);
const showAfterStartupCover = () => {
this._lifetime.frame(() => {
if (
@@ -540,7 +604,7 @@ export class ShareRestoration {
!startupCover ||
getComputedStyle(startupCover).visibility === 'hidden'
) {
this.showStatus(message);
show();
return;
}
let fallbackTimer = null;
@@ -555,7 +619,7 @@ export class ShareRestoration {
this._disposed,
)
)
this.showStatus(message);
show();
};
removeStartupListener = this._lifetime.listen(
startupCover,
+18
View File
@@ -166,6 +166,24 @@ html:not([lang='en']) #global-loading-detail {
#global-loading-status[data-state='cancelled'] #global-loading-detail {
color: #ffd488;
}
/* A last-known notice is a sentence with the entity's id on a second line;
the id is shown whole (a vessel UUID is 36 characters). */
#global-loading-status[data-state='last-known'] {
flex-direction: column;
gap: 3px;
border-color: rgba(255, 212, 136, 0.55);
text-align: center;
}
#global-loading-status[data-state='last-known'] #global-loading-label {
color: #ffd488;
}
#global-loading-status[data-state='last-known'] #global-loading-detail {
max-width: none;
color: rgba(255, 228, 176, 0.82);
letter-spacing: 1.2px;
text-align: center;
text-transform: none;
}
#global-loading-status[data-state='acquiring'] {
border-color: rgba(0, 212, 255, 0.42);
box-shadow: