mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
The radio lifecycle no longer makes, shows, hides or removes the stations' Cesium data source or the selected station's entity itself: the rendering part does, through installDataSource, setStationsShown, removeSelectionEntity and removeDataSource, in the same order as before. The camera factory import moves to the rendering part too, which stays on the list. The lifecycle no longer imports Cesium or drives the viewer, so it leaves the allow-list.
113 lines
4.3 KiB
JavaScript
113 lines
4.3 KiB
JavaScript
import {
|
|
RADIO_OVERLAY_SOURCE_ID,
|
|
DEFAULT_RADIO_VOLUME,
|
|
EMPTY_ACCEPTED_CATALOG_SNAPSHOT,
|
|
DEFAULT_RADIO_FILTER,
|
|
} from './policy.js';
|
|
|
|
export function createLifecycle({
|
|
state: layerState,
|
|
services,
|
|
parts,
|
|
source,
|
|
}) {
|
|
const { clearOverlaySource, setOverlaySourceVisible } = services.overlays;
|
|
|
|
const methods = {
|
|
/** Initialize the stations' rendering and the single audio element. */
|
|
init(viewer) {
|
|
layerState._sessionGeneration += 1;
|
|
layerState._viewer = viewer;
|
|
parts.clustering.resetRadioClusterOverlayIdentities();
|
|
parts.playback.installAudio();
|
|
parts.rendering.installDataSource(viewer);
|
|
parts.rendering.setStationsShown(false);
|
|
clearOverlaySource(RADIO_OVERLAY_SOURCE_ID);
|
|
setOverlaySourceVisible(RADIO_OVERLAY_SOURCE_ID, false);
|
|
},
|
|
|
|
/** Show stations. Enabling or preset restoration never starts audio. */
|
|
enable() {
|
|
layerState._enabled = true;
|
|
parts.interaction.syncRadioLifecyclePresentation();
|
|
parts.presentation.emitState();
|
|
},
|
|
|
|
/** Hide the layer and stop playback without forgetting the selected station. */
|
|
disable() {
|
|
layerState._sessionGeneration += 1;
|
|
layerState._enabled = false;
|
|
parts.navigation.invalidateRadioCameraNavigation();
|
|
layerState._requestGeneration += 1;
|
|
layerState._abortController?.abort();
|
|
layerState._abortController = null;
|
|
layerState._loading = false;
|
|
layerState._selectionGeneration += 1;
|
|
if (layerState._selectionTimer) clearTimeout(layerState._selectionTimer);
|
|
layerState._selectionTimer = null;
|
|
parts.interaction.removeInteraction();
|
|
parts.tuning.endRadioTuning();
|
|
layerState._cancelledTuningPresentationStation = null;
|
|
layerState._tuningUnavailableStationId = null;
|
|
parts.playback.stopRadioPlayback({ origin: 'layer-disable' });
|
|
parts.rendering.setStationsShown(false);
|
|
parts.rendering.removeSelectionEntity();
|
|
if (layerState._overlayPublishTimer)
|
|
clearTimeout(layerState._overlayPublishTimer);
|
|
layerState._overlayPublishTimer = null;
|
|
parts.clustering.resetRadioClusterOverlayIdentities();
|
|
layerState._overlayDiagnostics =
|
|
parts.clustering.emptyRadioOverlayDiagnostics();
|
|
clearOverlaySource(RADIO_OVERLAY_SOURCE_ID);
|
|
setOverlaySourceVisible(RADIO_OVERLAY_SOURCE_ID, false);
|
|
parts.presentation.emitState();
|
|
},
|
|
|
|
/** Release rendering, event, request, and playback resources. */
|
|
destroy() {
|
|
this.disable();
|
|
parts.volume.cancelRadioVolumeTransition();
|
|
layerState._voiceDucked = false;
|
|
layerState._voiceRestoring = false;
|
|
parts.tuning.endRadioTuning();
|
|
const closedTuningNoise = layerState._tuningNoiseContext?.close?.();
|
|
if (closedTuningNoise?.catch) void closedTuningNoise.catch(() => {});
|
|
layerState._tuningNoiseContext = null;
|
|
if (layerState._audio) layerState._audio.volume = DEFAULT_RADIO_VOLUME;
|
|
layerState._audio = null;
|
|
layerState._userVolume = DEFAULT_RADIO_VOLUME;
|
|
parts.rendering.removeDataSource();
|
|
clearOverlaySource(RADIO_OVERLAY_SOURCE_ID);
|
|
layerState._stations = [];
|
|
layerState._acceptedCatalogSnapshot = EMPTY_ACCEPTED_CATALOG_SNAPSHOT;
|
|
layerState._stationById.clear();
|
|
layerState._categories = Object.freeze([]);
|
|
layerState._filter = DEFAULT_RADIO_FILTER;
|
|
layerState._renderById.clear();
|
|
parts.clustering.resetRadioClusterOverlayIdentities();
|
|
layerState._lastHorizonCameraPosition = null;
|
|
layerState._horizonScanCount = 0;
|
|
layerState._selectedId = null;
|
|
layerState._tuningPreviewId = null;
|
|
layerState._tuningStartStationId = null;
|
|
layerState._tuningResolutionSnapshot = EMPTY_ACCEPTED_CATALOG_SNAPSHOT;
|
|
layerState._tuningStationById = new Map();
|
|
layerState._tuningUnavailableStationId = null;
|
|
layerState._cancelledTuningPresentationStation = null;
|
|
layerState._loading = false;
|
|
layerState._stale = false;
|
|
layerState._degraded = false;
|
|
layerState._rejectedStationCount = 0;
|
|
layerState._error = null;
|
|
layerState._updatedAt = null;
|
|
layerState._managerLifecyclePresentation = null;
|
|
layerState._viewer = null;
|
|
parts.presentation.emitState();
|
|
layerState._listeners.clear();
|
|
layerState._playbackControlListeners.clear();
|
|
},
|
|
};
|
|
|
|
return { methods };
|
|
}
|