generated from allen-cell-animated/github-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathISimulator.ts
More file actions
99 lines (88 loc) · 3.32 KB
/
ISimulator.ts
File metadata and controls
99 lines (88 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import {
VisDataMessage,
TrajectoryFileInfo,
PlotConfig,
Plot,
Metrics,
} from "../simularium/types.js";
import { ClientSimulator } from "./ClientSimulator.js";
import { LocalFileSimulator } from "./LocalFileSimulator.js";
import { RemoteSimulator } from "./RemoteSimulator.js";
import {
SimulatorParams,
RemoteSimulatorParams,
ClientSimulatorParams,
LocalFileSimulatorParams,
} from "./types.js";
export const getSimulatorClassFromParams = (params?: SimulatorParams) => {
if (!params || !params.fileName) {
return { simulatorClass: null, typedParams: null };
}
if ("netConnectionSettings" in params) {
return {
simulatorClass: RemoteSimulator,
typedParams: params as RemoteSimulatorParams,
};
} else if ("clientSimulatorImpl" in params) {
return {
simulatorClass: ClientSimulator,
typedParams: params as ClientSimulatorParams,
};
} else if ("simulariumFile" in params) {
return {
simulatorClass: LocalFileSimulator,
typedParams: params as LocalFileSimulatorParams,
};
} else {
return { simulatorClass: null, typedParams: null };
}
};
/**
From the caller's perspective, this interface is a contract for a
simulator that can be used to control set up, tear down, and streaming,
and to subscribe to data events and error handling.
*/
export interface ISimulator {
/**
* Callbacks to subscribe front end implementations
* to data events and error handling from the simulator
*/
/** a callback to notify when TrajectoryFileInfo is ready */
setTrajectoryFileInfoHandler(
handler: (msg: TrajectoryFileInfo) => void
): void;
/** a callback to notify when VisDataMessage is ready (the agent data) */
setTrajectoryDataHandler(
handler: (msg: VisDataMessage | ArrayBuffer) => void
): void;
/** a callback to receive available metrics */
setMetricsHandler(handler: (msg: Metrics) => void): void;
/** a callback to receive plot data */
setPlotDataHandler(handler: (msg: Plot[]) => void): void;
/** a callback to propagate errors from a simulator to it's implementing context */
setErrorHandler(handler: (msg: Error) => void): void;
/** general update function for client simulators
* todo: could also be implemented for control of live
* and pre-run remote simulations
* */
sendUpdate(data: Record<string, unknown>): Promise<void>;
// General simulation streaming control
/** prepare a simulation for streaming, async to accommodate connection steps */
initialize(fileName: string): Promise<void>;
/** stop sending frames, release resources, close connections */
abort(): void;
/** request a stream of frames to begin */
stream(): void;
/** request that streaming of frames stop */
pause(): void;
/** request a single frame of data by frame number */
requestFrame(frameNumber: number): void;
/** request a single frame of data by time stamp */
requestFrameByTime(time: number): void;
/** request trajectory metadata */
requestTrajectoryFileInfo(fileName: string): void;
/** request available metrics */
requestAvailableMetrics(): void;
/** request available plots */
requestPlotData(plots: PlotConfig[]): void;
}