drone-path 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/README.md +3 -3
- package/THIRD-PARTY-NOTICES.md +7 -7
- package/app/ipc.mjs +178 -0
- package/app/main.mjs +4 -198
- package/dist/appsession.js +25 -59
- package/dist/appstate.js +22 -20
- package/dist/cammeta.js +4 -5
- package/dist/cli.js +3 -21
- package/dist/config.js +190 -129
- package/dist/ff.js +2 -19
- package/dist/frametime.js +32 -0
- package/dist/png.js +1 -18
- package/dist/render.js +35 -112
- package/dist/run.js +49 -112
- package/dist/telemetry-json.js +33 -27
- package/dist/telemetry-math.js +2 -1
- package/dist/telemetry.js +18 -14
- package/dist/tiles.js +30 -86
- package/package.json +7 -8
- package/dist/renderer/leaflet.js +0 -1
- package/dist/tracing.js +0 -184
package/dist/tiles.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import PQueue from 'p-queue';
|
|
3
4
|
import { errorMessage } from './errors.js';
|
|
4
5
|
import { solidPng } from './png.js';
|
|
5
6
|
import { tilePaths } from './tilecache.js';
|
|
@@ -12,24 +13,8 @@ const DOWNLOAD_WORKERS = 2;
|
|
|
12
13
|
const REQUEST_INTERVAL_MS = 500;
|
|
13
14
|
const RETRY_DELAY_MS = 500;
|
|
14
15
|
const FETCH_TIMEOUT_MS = 20000;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
let tail = Promise.resolve();
|
|
18
|
-
return () => {
|
|
19
|
-
const turn = tail.then(async () => {
|
|
20
|
-
for (;;) {
|
|
21
|
-
const now = Date.now();
|
|
22
|
-
if (now >= nextFreeAt) {
|
|
23
|
-
nextFreeAt = now + REQUEST_INTERVAL_MS;
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
await sleep(nextFreeAt - now);
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
tail = turn.catch(() => { });
|
|
30
|
-
return turn;
|
|
31
|
-
};
|
|
32
|
-
}
|
|
16
|
+
// p-queue starts higher priorities first, so 'now' jumps the queued pre-warm.
|
|
17
|
+
const TASK_PRIORITY = { now: 1, background: 0 };
|
|
33
18
|
function tileUrl(style, tile) {
|
|
34
19
|
const source = TILE_SOURCES[style];
|
|
35
20
|
const subdomain = source.subdomains.length
|
|
@@ -44,18 +29,24 @@ function tileUrl(style, tile) {
|
|
|
44
29
|
function canceledError(signal) {
|
|
45
30
|
return new Error('tile download canceled', { cause: signal.reason });
|
|
46
31
|
}
|
|
47
|
-
async function
|
|
32
|
+
async function fetchBody(url, signal) {
|
|
33
|
+
const res = await fetch(url, {
|
|
34
|
+
headers: { 'User-Agent': USER_AGENT },
|
|
35
|
+
signal: signal
|
|
36
|
+
? AbortSignal.any([AbortSignal.timeout(FETCH_TIMEOUT_MS), signal])
|
|
37
|
+
: AbortSignal.timeout(FETCH_TIMEOUT_MS),
|
|
38
|
+
});
|
|
39
|
+
return res.ok ? Buffer.from(await res.arrayBuffer()) : null;
|
|
40
|
+
}
|
|
41
|
+
async function downloadTile(queue, url, priority, signal) {
|
|
48
42
|
for (let attempt = 0; attempt < DOWNLOAD_ATTEMPTS; attempt++) {
|
|
49
|
-
await acquire();
|
|
50
43
|
try {
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
signal
|
|
54
|
-
? AbortSignal.any([AbortSignal.timeout(FETCH_TIMEOUT_MS), signal])
|
|
55
|
-
: AbortSignal.timeout(FETCH_TIMEOUT_MS),
|
|
44
|
+
const body = await queue.add(() => fetchBody(url, signal), {
|
|
45
|
+
priority: TASK_PRIORITY[priority],
|
|
46
|
+
signal,
|
|
56
47
|
});
|
|
57
|
-
if (
|
|
58
|
-
return
|
|
48
|
+
if (body)
|
|
49
|
+
return body;
|
|
59
50
|
}
|
|
60
51
|
catch {
|
|
61
52
|
if (signal?.aborted)
|
|
@@ -85,11 +76,11 @@ function createPlaceholderSource() {
|
|
|
85
76
|
return png;
|
|
86
77
|
};
|
|
87
78
|
}
|
|
88
|
-
async function fetchTileToCache(ctx, style, tile, signal) {
|
|
79
|
+
async function fetchTileToCache(ctx, style, tile, priority, signal) {
|
|
89
80
|
const paths = tilePaths(ctx.cacheDir, style, tile);
|
|
90
81
|
if (fs.existsSync(paths.file))
|
|
91
82
|
return { file: paths.file, status: 'cached' };
|
|
92
|
-
const body = await downloadTile(tileUrl(style, tile),
|
|
83
|
+
const body = await downloadTile(ctx.queue, tileUrl(style, tile), priority, signal);
|
|
93
84
|
if (body) {
|
|
94
85
|
writeCacheFile(paths.file, body);
|
|
95
86
|
return { file: paths.file, status: 'downloaded' };
|
|
@@ -98,36 +89,16 @@ async function fetchTileToCache(ctx, style, tile, signal) {
|
|
|
98
89
|
return { file: paths.placeholder, status: 'failed' };
|
|
99
90
|
}
|
|
100
91
|
function createDownloader(cacheDir, placeholderPng) {
|
|
101
|
-
const
|
|
92
|
+
const queue = new PQueue({
|
|
93
|
+
concurrency: DOWNLOAD_WORKERS,
|
|
94
|
+
intervalCap: 1,
|
|
95
|
+
interval: REQUEST_INTERVAL_MS,
|
|
96
|
+
// Sliding window: no more than intervalCap starts in any interval window,
|
|
97
|
+
// matching the old request gate's nextFreeAt semantics.
|
|
98
|
+
strict: true,
|
|
99
|
+
});
|
|
100
|
+
const ctx = { cacheDir, queue, placeholderPng };
|
|
102
101
|
const inFlight = new Map();
|
|
103
|
-
const queue = [];
|
|
104
|
-
let active = 0;
|
|
105
|
-
function pump() {
|
|
106
|
-
while (active < DOWNLOAD_WORKERS) {
|
|
107
|
-
const job = queue.shift();
|
|
108
|
-
if (!job)
|
|
109
|
-
break;
|
|
110
|
-
if (job.signal?.aborted) {
|
|
111
|
-
job.detach();
|
|
112
|
-
job.fail(canceledError(job.signal));
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
active++;
|
|
116
|
-
void (async () => {
|
|
117
|
-
try {
|
|
118
|
-
job.settle(await fetchTileToCache(ctx, job.style, job.tile, job.signal));
|
|
119
|
-
}
|
|
120
|
-
catch (e) {
|
|
121
|
-
job.fail(e);
|
|
122
|
-
}
|
|
123
|
-
finally {
|
|
124
|
-
job.detach();
|
|
125
|
-
active--;
|
|
126
|
-
pump();
|
|
127
|
-
}
|
|
128
|
-
})();
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
102
|
return {
|
|
132
103
|
enqueue(style, tile, options = {}) {
|
|
133
104
|
const priority = options.priority ?? 'background';
|
|
@@ -136,34 +107,7 @@ function createDownloader(cacheDir, placeholderPng) {
|
|
|
136
107
|
const shared = inFlight.get(key);
|
|
137
108
|
if (shared && shared.signal === options.signal)
|
|
138
109
|
return shared.promise;
|
|
139
|
-
const task =
|
|
140
|
-
const job = {
|
|
141
|
-
style,
|
|
142
|
-
tile,
|
|
143
|
-
signal: options.signal,
|
|
144
|
-
settle: resolve,
|
|
145
|
-
fail: reject,
|
|
146
|
-
detach: () => { },
|
|
147
|
-
};
|
|
148
|
-
const signal = options.signal;
|
|
149
|
-
if (signal) {
|
|
150
|
-
const onAbort = () => {
|
|
151
|
-
const at = queue.indexOf(job);
|
|
152
|
-
if (at < 0)
|
|
153
|
-
return;
|
|
154
|
-
queue.splice(at, 1);
|
|
155
|
-
job.detach();
|
|
156
|
-
reject(canceledError(signal));
|
|
157
|
-
};
|
|
158
|
-
signal.addEventListener('abort', onAbort, { once: true });
|
|
159
|
-
job.detach = () => signal.removeEventListener('abort', onAbort);
|
|
160
|
-
}
|
|
161
|
-
if (priority === 'now')
|
|
162
|
-
queue.unshift(job);
|
|
163
|
-
else
|
|
164
|
-
queue.push(job);
|
|
165
|
-
pump();
|
|
166
|
-
});
|
|
110
|
+
const task = fetchTileToCache(ctx, style, tile, priority, options.signal);
|
|
167
111
|
const entry = { promise: task, signal: options.signal };
|
|
168
112
|
const clear = () => {
|
|
169
113
|
if (inFlight.get(key) === entry)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drone-path",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Render flight-path map overlay videos (exactly the source frame rate and frame count) from DJI drone recordings - telemetry from the
|
|
3
|
+
"version": "0.10.0",
|
|
4
|
+
"description": "Render flight-path map overlay videos (exactly the source frame rate and frame count) from DJI drone recordings - telemetry from the embedded CAM-meta (DVTM) stream or the .SRT sidecar.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "app/main.mjs",
|
|
7
7
|
"bin": {
|
|
@@ -61,13 +61,10 @@
|
|
|
61
61
|
},
|
|
62
62
|
"homepage": "https://github.com/MrManny/drone-path#readme",
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"
|
|
65
|
-
"@opentelemetry/exporter-trace-otlp-proto": "~0.301.0",
|
|
66
|
-
"@opentelemetry/resources": "~3.1.0",
|
|
67
|
-
"@opentelemetry/sdk-trace": "~3.1.0",
|
|
68
|
-
"commander": "~15.0.0",
|
|
64
|
+
"commander": "~15.1.0",
|
|
69
65
|
"electron-updater": "~6.8.11",
|
|
70
66
|
"leaflet": "~1.9.4",
|
|
67
|
+
"p-queue": "~10.0.0",
|
|
71
68
|
"playwright-core": "~1.65.0",
|
|
72
69
|
"zod": "~4.6.7"
|
|
73
70
|
},
|
|
@@ -80,15 +77,17 @@
|
|
|
80
77
|
"@next/eslint-plugin-next": "~16.4.3",
|
|
81
78
|
"@testing-library/react": "~16.3.3",
|
|
82
79
|
"@testing-library/user-event": "~14.6.8",
|
|
80
|
+
"@types/leaflet": "~1.9.22",
|
|
83
81
|
"@types/node": "~24.19.2",
|
|
84
82
|
"@types/react": "~19.3.0",
|
|
85
83
|
"@types/react-dom": "~19.3.0",
|
|
86
|
-
"concurrently": "~10.0.
|
|
84
|
+
"concurrently": "~10.0.7",
|
|
87
85
|
"electron": "~45.2.1",
|
|
88
86
|
"electron-builder": "~26.18.0",
|
|
89
87
|
"eslint": "~10.14.0",
|
|
90
88
|
"eslint-plugin-react-hooks": "~7.1.1",
|
|
91
89
|
"jsdom": "~31.0.0",
|
|
90
|
+
"lucide-react": "~1.71.0",
|
|
92
91
|
"marked": "~18.1.3",
|
|
93
92
|
"next": "~16.4.3",
|
|
94
93
|
"react": "~19.3.1",
|
package/dist/renderer/leaflet.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/tracing.js
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import { errorMessage } from './errors.js';
|
|
2
|
-
import { VERSION } from './version.js';
|
|
3
|
-
const SERVICE_NAME = 'drone-path';
|
|
4
|
-
const OTLP_PROTOCOL = 'http/protobuf';
|
|
5
|
-
const noopSpan = {
|
|
6
|
-
setAttribute: () => { },
|
|
7
|
-
setAttributes: () => { },
|
|
8
|
-
fail: () => { },
|
|
9
|
-
end: () => { },
|
|
10
|
-
};
|
|
11
|
-
export const NOOP_TRACER = {
|
|
12
|
-
startSpan: () => noopSpan,
|
|
13
|
-
};
|
|
14
|
-
function envFlag(value) {
|
|
15
|
-
return value?.trim().toLowerCase() === 'true';
|
|
16
|
-
}
|
|
17
|
-
function envText(value) {
|
|
18
|
-
const trimmed = value?.trim();
|
|
19
|
-
return trimmed === '' ? undefined : trimmed;
|
|
20
|
-
}
|
|
21
|
-
export function isTracingEnabled(env = process.env) {
|
|
22
|
-
const endpoint = envText(env['OTEL_EXPORTER_OTLP_TRACES_ENDPOINT']) ??
|
|
23
|
-
envText(env['OTEL_EXPORTER_OTLP_ENDPOINT']);
|
|
24
|
-
return endpoint !== undefined && !envFlag(env['OTEL_SDK_DISABLED']);
|
|
25
|
-
}
|
|
26
|
-
// Per OTLP spec the specific endpoint is used as-is; the generic one is a base URL that gets /v1/traces.
|
|
27
|
-
export function otlpTracesUrl(env) {
|
|
28
|
-
const specific = envText(env['OTEL_EXPORTER_OTLP_TRACES_ENDPOINT']);
|
|
29
|
-
if (specific)
|
|
30
|
-
return specific;
|
|
31
|
-
const base = envText(env['OTEL_EXPORTER_OTLP_ENDPOINT']);
|
|
32
|
-
return base ? `${base.replace(/\/+$/, '')}/v1/traces` : undefined;
|
|
33
|
-
}
|
|
34
|
-
function parseKeyValueList(value) {
|
|
35
|
-
const out = {};
|
|
36
|
-
for (const pair of (value ?? '').split(',')) {
|
|
37
|
-
const eq = pair.indexOf('=');
|
|
38
|
-
if (eq <= 0)
|
|
39
|
-
continue;
|
|
40
|
-
const key = pair.slice(0, eq).trim();
|
|
41
|
-
const rawValue = pair.slice(eq + 1).trim();
|
|
42
|
-
if (!key)
|
|
43
|
-
continue;
|
|
44
|
-
try {
|
|
45
|
-
out[key] = decodeURIComponent(rawValue);
|
|
46
|
-
}
|
|
47
|
-
catch {
|
|
48
|
-
out[key] = rawValue;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return out;
|
|
52
|
-
}
|
|
53
|
-
export function otlpHeaders(env) {
|
|
54
|
-
return {
|
|
55
|
-
...parseKeyValueList(envText(env['OTEL_EXPORTER_OTLP_HEADERS'])),
|
|
56
|
-
...parseKeyValueList(envText(env['OTEL_EXPORTER_OTLP_TRACES_HEADERS'])),
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
export function resourceAttributesFromEnv(env) {
|
|
60
|
-
const attrs = parseKeyValueList(envText(env['OTEL_RESOURCE_ATTRIBUTES']));
|
|
61
|
-
const serviceName = envText(env['OTEL_SERVICE_NAME']);
|
|
62
|
-
if (serviceName !== undefined)
|
|
63
|
-
attrs['service.name'] = serviceName;
|
|
64
|
-
return attrs;
|
|
65
|
-
}
|
|
66
|
-
function assertSupportedProtocol(env) {
|
|
67
|
-
const specific = envText(env['OTEL_EXPORTER_OTLP_TRACES_PROTOCOL']);
|
|
68
|
-
const generic = envText(env['OTEL_EXPORTER_OTLP_PROTOCOL']);
|
|
69
|
-
const name = specific !== undefined
|
|
70
|
-
? 'OTEL_EXPORTER_OTLP_TRACES_PROTOCOL'
|
|
71
|
-
: 'OTEL_EXPORTER_OTLP_PROTOCOL';
|
|
72
|
-
const value = specific ?? generic;
|
|
73
|
-
if (value !== undefined && value.toLowerCase() !== OTLP_PROTOCOL) {
|
|
74
|
-
throw new Error(`unsupported ${name}: ${value} (only ${OTLP_PROTOCOL} is supported)`);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
export async function withSpan(tracer, name, options, body) {
|
|
78
|
-
const span = tracer.startSpan(name, options);
|
|
79
|
-
try {
|
|
80
|
-
const result = await body(span);
|
|
81
|
-
span.end();
|
|
82
|
-
return result;
|
|
83
|
-
}
|
|
84
|
-
catch (e) {
|
|
85
|
-
span.fail(e);
|
|
86
|
-
span.end();
|
|
87
|
-
throw e;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
export function stage(tracer, name, parent, attributes, body) {
|
|
91
|
-
return withSpan(tracer, name, { parent, attributes }, body);
|
|
92
|
-
}
|
|
93
|
-
class OtelSpan {
|
|
94
|
-
api;
|
|
95
|
-
raw;
|
|
96
|
-
ended = false;
|
|
97
|
-
constructor(api, raw) {
|
|
98
|
-
this.api = api;
|
|
99
|
-
this.raw = raw;
|
|
100
|
-
}
|
|
101
|
-
setAttribute(name, value) {
|
|
102
|
-
this.raw.setAttribute(name, value);
|
|
103
|
-
}
|
|
104
|
-
setAttributes(values) {
|
|
105
|
-
this.raw.setAttributes(values);
|
|
106
|
-
}
|
|
107
|
-
fail(error) {
|
|
108
|
-
if (this.ended)
|
|
109
|
-
return;
|
|
110
|
-
const exception = error instanceof Error ? error : new Error(errorMessage(error));
|
|
111
|
-
this.raw.recordException(exception);
|
|
112
|
-
this.raw.setStatus({
|
|
113
|
-
code: this.api.SpanStatusCode.ERROR,
|
|
114
|
-
message: exception.message,
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
end() {
|
|
118
|
-
if (this.ended)
|
|
119
|
-
return;
|
|
120
|
-
this.ended = true;
|
|
121
|
-
this.raw.end();
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
class OtelTracer {
|
|
125
|
-
api;
|
|
126
|
-
raw;
|
|
127
|
-
constructor(api, raw) {
|
|
128
|
-
this.api = api;
|
|
129
|
-
this.raw = raw;
|
|
130
|
-
}
|
|
131
|
-
startSpan(name, options) {
|
|
132
|
-
const parent = options?.parent;
|
|
133
|
-
// Unwrap through Span.raw, not instanceof: a parent without an OpenTelemetry handle would silently detach the new span.
|
|
134
|
-
const parentRaw = parent?.raw;
|
|
135
|
-
if (parent && !parentRaw) {
|
|
136
|
-
throw new Error('parent span carries no OpenTelemetry handle');
|
|
137
|
-
}
|
|
138
|
-
const context = parentRaw
|
|
139
|
-
? this.api.trace.setSpan(this.api.context.active(), parentRaw)
|
|
140
|
-
: undefined;
|
|
141
|
-
return new OtelSpan(this.api, this.raw.startSpan(name, { attributes: options?.attributes }, context));
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
export async function createTracing(options = {}) {
|
|
145
|
-
const env = options.env ?? process.env;
|
|
146
|
-
if (!isTracingEnabled(env)) {
|
|
147
|
-
return {
|
|
148
|
-
enabled: false,
|
|
149
|
-
tracer: NOOP_TRACER,
|
|
150
|
-
flush: async () => { },
|
|
151
|
-
shutdown: async () => { },
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
assertSupportedProtocol(env);
|
|
155
|
-
const api = await import('@opentelemetry/api');
|
|
156
|
-
const { TracerProvider, BatchSpanProcessor } = await import('@opentelemetry/sdk-trace');
|
|
157
|
-
const { resourceFromAttributes } = await import('@opentelemetry/resources');
|
|
158
|
-
const { OTLPTraceExporter } = await import('@opentelemetry/exporter-trace-otlp-proto');
|
|
159
|
-
const exporter = options.spanExporter ??
|
|
160
|
-
new OTLPTraceExporter({
|
|
161
|
-
url: otlpTracesUrl(env),
|
|
162
|
-
headers: otlpHeaders(env),
|
|
163
|
-
});
|
|
164
|
-
const resource = resourceFromAttributes({
|
|
165
|
-
'service.name': SERVICE_NAME,
|
|
166
|
-
'service.version': VERSION,
|
|
167
|
-
}).merge(resourceFromAttributes(resourceAttributesFromEnv(env)));
|
|
168
|
-
const provider = new TracerProvider({
|
|
169
|
-
resource,
|
|
170
|
-
spanProcessors: [
|
|
171
|
-
new BatchSpanProcessor({
|
|
172
|
-
exporter,
|
|
173
|
-
// The default queue (2048) drops spans silently; long batches need thousands to survive.
|
|
174
|
-
maxQueueSize: 8192,
|
|
175
|
-
}),
|
|
176
|
-
],
|
|
177
|
-
});
|
|
178
|
-
return {
|
|
179
|
-
enabled: true,
|
|
180
|
-
tracer: new OtelTracer(api, provider.getTracer(SERVICE_NAME, VERSION)),
|
|
181
|
-
flush: () => provider.forceFlush(),
|
|
182
|
-
shutdown: () => provider.shutdown(),
|
|
183
|
-
};
|
|
184
|
-
}
|