conformtools 0.6.4 → 0.6.5
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/package.json +1 -1
- package/dist/arriraw-3GKCR6K2.js +0 -525
- package/dist/browser/timeline_core_bg.wasm +0 -0
- package/dist/chunk-42QQI3WX.js +0 -3
- package/dist/chunk-6FVGUJ6L.js +0 -3
- package/dist/chunk-6TM32YIJ.js +0 -7
- package/dist/chunk-7D7H6VFW.js +0 -3
- package/dist/chunk-AACY2V3L.js +0 -3
- package/dist/chunk-BUEIRRNY.js +0 -3
- package/dist/chunk-BW2NQ54J.js +0 -3
- package/dist/chunk-C2ESM27Z.js +0 -3
- package/dist/chunk-CL26XMDO.js +0 -3
- package/dist/chunk-DKGGJM6Z.js +0 -3
- package/dist/chunk-DRHOPOC7.js +0 -3
- package/dist/chunk-EO5NIBOV.js +0 -3
- package/dist/chunk-EPZ6NWE4.js +0 -3
- package/dist/chunk-GXEVALBL.js +0 -3
- package/dist/chunk-HKP4P6JN.js +0 -3
- package/dist/chunk-JB7PR2TQ.js +0 -3
- package/dist/chunk-P7OVDUA5.js +0 -3
- package/dist/chunk-PSANHDZM.js +0 -3
- package/dist/chunk-QDWB7QU7.js +0 -3
- package/dist/chunk-QTKRMXL5.js +0 -363
- package/dist/chunk-QTPCU2TF.js +0 -3
- package/dist/chunk-SP5RGDAM.js +0 -3
- package/dist/chunk-TEZP6VEQ.js +0 -3
- package/dist/chunk-TK55FA56.js +0 -3
- package/dist/chunk-UCMNH6Q6.js +0 -3
- package/dist/chunk-WHY3DVXS.js +0 -3
- package/dist/chunk-WT6NIJCB.js +0 -3
- package/dist/chunk-Y2BEEOPB.js +0 -3
- package/dist/claude-setup-BM3AAUKR.js +0 -5
- package/dist/cli.js +0 -17
- package/dist/clip-state-B6JOX3JE.js +0 -3
- package/dist/conformtools-decode +0 -0
- package/dist/cr3-wasm-WKWMEK3V.js +0 -3
- package/dist/dng-wasm-Z5OVO4UI.js +0 -3
- package/dist/dpx-wasm-QNYXAOAJ.js +0 -3
- package/dist/esm-SFFBP7PS.js +0 -3
- package/dist/exr-wasm-BHSBJLQH.js +0 -3
- package/dist/h264-LIZVHN2W.js +0 -3
- package/dist/h264-mxf-MWS7DDV7.js +0 -3
- package/dist/http.js +0 -4
- package/dist/i2o-transfer +0 -0
- package/dist/inspect-DZF537QL.js +0 -46
- package/dist/isobmff-HM3UPWPZ.js +0 -3
- package/dist/mcp.js +0 -14
- package/dist/media_core-R5PPN3AY.js +0 -9
- package/dist/media_core_bg-FGAR5KA5.js +0 -3
- package/dist/media_core_bg-YK63OUDM.js +0 -3
- package/dist/mxf-K465SWBN.js +0 -3
- package/dist/onnxruntime-web-stub-PKJ2NZBF.js +0 -3
- package/dist/ops-73NR3X6R.js +0 -3
- package/dist/premiere-uxp/icons/panel.png +0 -0
- package/dist/premiere-uxp/icons/panel@2x.png +0 -0
- package/dist/premiere-uxp/icons/plugin.png +0 -0
- package/dist/premiere-uxp/icons/plugin@2x.png +0 -0
- package/dist/premiere-uxp/index.html +0 -38
- package/dist/premiere-uxp/index.js +0 -93
- package/dist/premiere-uxp/lib/clipmeta.js +0 -170
- package/dist/premiere-uxp/lib/ctx.js +0 -62
- package/dist/premiere-uxp/lib/handles.js +0 -57
- package/dist/premiere-uxp/lib/markers.js +0 -198
- package/dist/premiere-uxp/lib/pairing.js +0 -58
- package/dist/premiere-uxp/lib/premiere.js +0 -82
- package/dist/premiere-uxp/lib/probe.js +0 -139
- package/dist/premiere-uxp/lib/protocol.js +0 -165
- package/dist/premiere-uxp/lib/render.js +0 -38
- package/dist/premiere-uxp/lib/session.js +0 -85
- package/dist/premiere-uxp/lib/sizing.js +0 -312
- package/dist/premiere-uxp/lib/time.js +0 -82
- package/dist/premiere-uxp/lib/timeline.js +0 -336
- package/dist/premiere-uxp/lib/verbs.js +0 -20
- package/dist/premiere-uxp/lib/write.js +0 -97
- package/dist/premiere-uxp/manifest.json +0 -102
- package/dist/prores-L4JZZWGH.js +0 -526
- package/dist/r3d-RR3FUM6H.js +0 -3
- package/dist/r3d-VUOYU2KQ.js +0 -1025
- package/dist/resolve-bridge.py +0 -1037
- package/dist/resolve-presets/conform.tools.xml +0 -127
- package/dist/source-BDJAUQVR.js +0 -3
- package/dist/sscd-embed-DHFTEIOC.js +0 -3
- package/dist/sscd-sweep-OYS4XAID.js +0 -3
- package/dist/statusline-GMMCFMOA.js +0 -4
- package/dist/statusline.js +0 -3
- package/dist/still-4G25EYN5.js +0 -3
- package/dist/tiff-wasm-QJPCR7JT.js +0 -3
- package/dist/timeline_core-VK2ZWPCO.js +0 -3
- package/dist/timeline_core_bg-2TYWZ35G.js +0 -3
- package/dist/udf_bg-A4WEMSAX.js +0 -3
- package/dist/wasm/media_core_bg.wasm +0 -0
- package/dist/wasm/udf_bg.wasm +0 -0
- package/dist/wasm-threads/media_core_bg.wasm +0 -0
- package/dist/wav-63QF6SCT.js +0 -3
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
// `markers`: sequence markers, and clip markers (which Premiere keeps on the
|
|
2
|
-
// PROJECT ITEM, not the track item - a track-item handle maps to its project
|
|
3
|
-
// item's markers, in source frames). Colours are Premiere's eight indexed
|
|
4
|
-
// marker colours; the neutral names below are what the app's Marker Utility
|
|
5
|
-
// shows, mapped both ways.
|
|
6
|
-
"use strict";
|
|
7
|
-
|
|
8
|
-
const { handles, h, g, transact, activeProject, PeerError, P } = require("./ctx");
|
|
9
|
-
const T = require("./time");
|
|
10
|
-
const TL = require("./timeline");
|
|
11
|
-
|
|
12
|
-
// Premiere marker colour index -> the app's colour name (Resolve's palette
|
|
13
|
-
// is the neutral vocabulary; the nearest name is used).
|
|
14
|
-
const COLOR_NAMES = ["Green", "Red", "Purple", "Yellow", "Blue", "Cyan", "Sky", "Fuchsia"];
|
|
15
|
-
const COLOR_INDEX = new Map(COLOR_NAMES.map((n, i) => [n.toLowerCase(), i]));
|
|
16
|
-
const COLOR_ALIASES = { orange: 1, pink: 7, lavender: 2, mint: 0, lemon: 3, sand: 3, cocoa: 1, cream: 3, rose: 7, teal: 5, sky: 6, cyan: 5 };
|
|
17
|
-
|
|
18
|
-
function colorName(index) { const i = Number(index); return COLOR_NAMES[i] || (Number.isFinite(i) ? String(i) : ""); }
|
|
19
|
-
function colorIndex(name) {
|
|
20
|
-
const k = String(name || "").trim().toLowerCase();
|
|
21
|
-
if (COLOR_INDEX.has(k)) return COLOR_INDEX.get(k);
|
|
22
|
-
if (k in COLOR_ALIASES) return COLOR_ALIASES[k];
|
|
23
|
-
const n = Number(k);
|
|
24
|
-
return Number.isFinite(n) && n >= 0 && n < 8 ? n : 0;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** The Markers object of a project item. `Markers.getMarkers` wants the
|
|
28
|
-
* ClipProjectItem cast (a bare ProjectItem hands back nothing, measured 26.2). */
|
|
29
|
-
async function clipMarkersHolder(ppro, projectItem) {
|
|
30
|
-
let clip = projectItem;
|
|
31
|
-
try { if (ppro.ClipProjectItem && P.has(ppro.ClipProjectItem, "cast")) clip = ppro.ClipProjectItem.cast(projectItem) || projectItem; } catch (_) { /* not a clip */ }
|
|
32
|
-
let holder = null;
|
|
33
|
-
try { holder = await P.callAny(ppro.Markers, ["getMarkers"], clip); } catch (_) { holder = null; }
|
|
34
|
-
if (!holder && clip !== projectItem) { try { holder = await P.callAny(ppro.Markers, ["getMarkers"], projectItem); } catch (_) { holder = null; } }
|
|
35
|
-
if (!holder) throw new PeerError("no_markers", "Premiere has no marker list for this clip");
|
|
36
|
-
return holder;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async function markersObjectFor(target) {
|
|
40
|
-
const ppro = P.api();
|
|
41
|
-
const kind = handles.kindOf(target);
|
|
42
|
-
const obj = g(target);
|
|
43
|
-
if (kind === "seq") {
|
|
44
|
-
const seq = obj;
|
|
45
|
-
const timebase = await TL.timebaseOf(seq);
|
|
46
|
-
return { holder: await P.callAny(ppro.Markers, ["getMarkers"], seq), timebase, scope: "timeline", seq };
|
|
47
|
-
}
|
|
48
|
-
if (kind === "item") {
|
|
49
|
-
let pi = null;
|
|
50
|
-
try { pi = await P.callAny(obj, ["getProjectItem"]); } catch (_) { /* none */ }
|
|
51
|
-
if (!pi) throw new PeerError("no_media", "this clip has no project item to carry markers");
|
|
52
|
-
const seq = await currentSeqOrNull();
|
|
53
|
-
const seqFps = seq ? T.fpsFromTimebase(await TL.timebaseOf(seq)) : 25;
|
|
54
|
-
const fps = await sourceFpsOf(pi, seqFps);
|
|
55
|
-
return { holder: await clipMarkersHolder(ppro, pi), timebase: T.timebaseFromFps(fps), scope: "clip", projectItem: pi };
|
|
56
|
-
}
|
|
57
|
-
if (kind === "clip") {
|
|
58
|
-
const seq = await currentSeqOrNull();
|
|
59
|
-
const seqFps = seq ? T.fpsFromTimebase(await TL.timebaseOf(seq)) : 25;
|
|
60
|
-
const fps = await sourceFpsOf(obj, seqFps);
|
|
61
|
-
return { holder: await clipMarkersHolder(ppro, obj), timebase: T.timebaseFromFps(fps), scope: "clip", projectItem: obj };
|
|
62
|
-
}
|
|
63
|
-
throw new PeerError("bad_handle", `markers live on a sequence or a clip, not a ${kind}`);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async function currentSeqOrNull() {
|
|
67
|
-
const p = await activeProject();
|
|
68
|
-
if (!p) return null;
|
|
69
|
-
try { return await P.callAny(p, ["getActiveSequence"]); } catch (_) { return null; }
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async function sourceFpsOf(pi, fallback) {
|
|
73
|
-
try {
|
|
74
|
-
if (P.has(pi, "getFootageInterpretation")) {
|
|
75
|
-
const fi = await pi.getFootageInterpretation();
|
|
76
|
-
const fr = fi && (P.has(fi, "getFrameRate") ? await fi.getFrameRate() : fi.frameRate);
|
|
77
|
-
if (fr && Number(fr) > 0) return Number(fr);
|
|
78
|
-
}
|
|
79
|
-
} catch (_) { /* fall back */ }
|
|
80
|
-
return fallback;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
async function markerList(holder) {
|
|
84
|
-
const list = await P.callAny(holder, ["getMarkers"]);
|
|
85
|
-
return Array.isArray(list) ? list : [];
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
async function markerFields(m, timebase) {
|
|
89
|
-
const start = T.toTicks(m.start !== undefined ? m.start : (P.has(m, "getStart") ? await m.getStart() : 0));
|
|
90
|
-
const durT = T.toTicks(m.duration !== undefined ? m.duration : (P.has(m, "getDuration") ? await m.getDuration() : 0));
|
|
91
|
-
let color = "";
|
|
92
|
-
try { color = colorName(P.has(m, "getColorIndex") ? await m.getColorIndex() : (P.has(m, "getColor") ? await m.getColor() : m.colorIndex)); } catch (_) { color = ""; }
|
|
93
|
-
const name = m.name !== undefined ? m.name : (P.has(m, "getName") ? await m.getName() : "");
|
|
94
|
-
const comments = m.comments !== undefined ? m.comments : (P.has(m, "getComments") ? await m.getComments() : "");
|
|
95
|
-
const guid = m.guid !== undefined ? String(m.guid) : "";
|
|
96
|
-
return {
|
|
97
|
-
frame: T.ticksToFrames(start, timebase), color, name: String(name || ""), note: String(comments || ""),
|
|
98
|
-
duration: Math.max(1, T.ticksToFrames(durT, timebase) || 1), custom_data: guid, guid, type: m.type !== undefined ? m.type : (P.has(m, "getType") ? await m.getType() : ""),
|
|
99
|
-
_obj: m,
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
async function findMarker(holder, timebase, frame) {
|
|
104
|
-
for (const m of await markerList(holder)) {
|
|
105
|
-
const f = await markerFields(m, timebase);
|
|
106
|
-
if (f.frame === Number(frame)) return f;
|
|
107
|
-
}
|
|
108
|
-
return null;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function tick(ppro, ticks) {
|
|
112
|
-
if (ppro.TickTime && P.has(ppro.TickTime, "createWithTicks")) return ppro.TickTime.createWithTicks(String(ticks));
|
|
113
|
-
if (ppro.TickTime && P.has(ppro.TickTime, "createWithSeconds")) return ppro.TickTime.createWithSeconds(ticks / T.TICKS_PER_SECOND);
|
|
114
|
-
return ticks;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const verbs = {
|
|
118
|
-
"markers.list": async ({ target }) => {
|
|
119
|
-
const { holder, timebase, scope } = await markersObjectFor(target);
|
|
120
|
-
const out = [];
|
|
121
|
-
for (const m of await markerList(holder)) {
|
|
122
|
-
const f = await markerFields(m, timebase);
|
|
123
|
-
out.push({ frame: f.frame, color: f.color, name: f.name, note: f.note, duration: f.duration, custom_data: f.custom_data, scope, keywords: "" });
|
|
124
|
-
}
|
|
125
|
-
out.sort((a, b) => a.frame - b.frame);
|
|
126
|
-
return out;
|
|
127
|
-
},
|
|
128
|
-
"markers.add": async ({ target, frame, color, name, note, duration, custom_data }) => {
|
|
129
|
-
const ppro = P.api();
|
|
130
|
-
const project = await activeProject();
|
|
131
|
-
if (!project) throw new PeerError("no_project", "No project open");
|
|
132
|
-
const { holder, timebase } = await markersObjectFor(target);
|
|
133
|
-
const startTicks = T.framesToTicks(Number(frame), timebase);
|
|
134
|
-
const durTicks = T.framesToTicks(Math.max(1, Number(duration) || 1), timebase);
|
|
135
|
-
// MEASURED 26.2: the marker types are statics on `Marker`
|
|
136
|
-
// (MARKER_TYPE_COMMENT = "Comment"); `Constants.MarkerType` does not exist.
|
|
137
|
-
const type = (ppro.Marker && ppro.Marker.MARKER_TYPE_COMMENT) || (ppro.Constants && ppro.Constants.MarkerType && (ppro.Constants.MarkerType.COMMENT || ppro.Constants.MarkerType.MARKER)) || "Comment";
|
|
138
|
-
const n = await transact(project, `Add marker "${name || ""}"`, async (add) => {
|
|
139
|
-
add(await P.callAny(holder, ["createAddMarkerAction"], String(name || ""), type, tick(ppro, startTicks), tick(ppro, durTicks), String(note || "")));
|
|
140
|
-
});
|
|
141
|
-
if (!n) return false;
|
|
142
|
-
// Colour is a second action on the created marker (there is no colour
|
|
143
|
-
// argument on add); the marker is the one now at that frame.
|
|
144
|
-
if (color) {
|
|
145
|
-
const created = await findMarker(holder, timebase, Number(frame));
|
|
146
|
-
if (created && (P.has(created._obj, "createSetColorByIndexAction") || P.has(created._obj, "createSetColorAction"))) {
|
|
147
|
-
await transact(project, "Marker colour", async (add) => { add(await P.callAny(created._obj, ["createSetColorByIndexAction", "createSetColorAction"], colorIndex(color))); });
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
return true;
|
|
151
|
-
},
|
|
152
|
-
"markers.delete_at": async ({ target, frame }) => {
|
|
153
|
-
const project = await activeProject();
|
|
154
|
-
if (!project) throw new PeerError("no_project", "No project open");
|
|
155
|
-
const { holder, timebase } = await markersObjectFor(target);
|
|
156
|
-
const found = await findMarker(holder, timebase, Number(frame));
|
|
157
|
-
if (!found) return false;
|
|
158
|
-
const n = await transact(project, "Delete marker", async (add) => { add(await P.callAny(holder, ["createRemoveMarkerAction"], found._obj)); });
|
|
159
|
-
return n > 0;
|
|
160
|
-
},
|
|
161
|
-
"markers.move": async ({ target, frame, to_frame }) => {
|
|
162
|
-
const ppro = P.api();
|
|
163
|
-
const project = await activeProject();
|
|
164
|
-
const { holder, timebase } = await markersObjectFor(target);
|
|
165
|
-
const found = await findMarker(holder, timebase, Number(frame));
|
|
166
|
-
if (!found) return false;
|
|
167
|
-
const n = await transact(project, "Move marker", async (add) => {
|
|
168
|
-
add(await P.callAny(holder, ["createMoveMarkerAction"], found._obj, tick(ppro, T.framesToTicks(Number(to_frame), timebase))));
|
|
169
|
-
});
|
|
170
|
-
return n > 0;
|
|
171
|
-
},
|
|
172
|
-
"markers.set_color": async ({ target, frame, color }) => {
|
|
173
|
-
const project = await activeProject();
|
|
174
|
-
const { holder, timebase } = await markersObjectFor(target);
|
|
175
|
-
const found = await findMarker(holder, timebase, Number(frame));
|
|
176
|
-
if (!found) return false;
|
|
177
|
-
const n = await transact(project, "Marker colour", async (add) => { add(await P.callAny(found._obj, ["createSetColorByIndexAction", "createSetColorAction"], colorIndex(color))); });
|
|
178
|
-
return n > 0;
|
|
179
|
-
},
|
|
180
|
-
"markers.set_text": async ({ target, frame, name, note }) => {
|
|
181
|
-
const project = await activeProject();
|
|
182
|
-
const { holder, timebase } = await markersObjectFor(target);
|
|
183
|
-
const found = await findMarker(holder, timebase, Number(frame));
|
|
184
|
-
if (!found) return false;
|
|
185
|
-
// MEASURED 26.2: the name and the comment must be SEPARATE transactions -
|
|
186
|
-
// both in one compound fails with "Script action failed to execute".
|
|
187
|
-
let n = 0;
|
|
188
|
-
if (name !== undefined && P.has(found._obj, "createSetNameAction")) {
|
|
189
|
-
n += await transact(project, "Marker name", async (add) => { add(await found._obj.createSetNameAction(String(name))); });
|
|
190
|
-
}
|
|
191
|
-
if (note !== undefined && P.has(found._obj, "createSetCommentsAction")) {
|
|
192
|
-
n += await transact(project, "Marker note", async (add) => { add(await found._obj.createSetCommentsAction(String(note))); });
|
|
193
|
-
}
|
|
194
|
-
return n > 0;
|
|
195
|
-
},
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
module.exports = { verbs, COLOR_NAMES, colorName, colorIndex, markerFields, h };
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
// Pairing: where the bridge is and the token to reach it. The conform.tools
|
|
2
|
-
// engine (~/.conform-mcp) and the desktop app each write `<app data>/host-bridge/pairing.json` (0600, new port and token on
|
|
3
|
-
// every start, deleted on stop). This panel READS it; the token never leaves
|
|
4
|
-
// the machine and is never shown in full.
|
|
5
|
-
//
|
|
6
|
-
// Three ways, in order: the file in the app's data folder (needs the
|
|
7
|
-
// manifest's localFileSystem "fullAccess"); a folder the user picked once
|
|
8
|
-
// (persistent token); a pasted JSON (local only, kept in localStorage).
|
|
9
|
-
"use strict";
|
|
10
|
-
|
|
11
|
-
function dataDirs(home, platform) {
|
|
12
|
-
// The conform.tools engine (the conformtools MCP / CLI) first, then the desktop app.
|
|
13
|
-
if (platform === "win32") {
|
|
14
|
-
const appdata = (typeof process !== "undefined" && process.env && process.env.APPDATA) || `${home}\\AppData\\Roaming`;
|
|
15
|
-
return [`${home}\\.conform-mcp\\host-bridge\\pairing.json`, `${appdata}\\app.conform.tools\\host-bridge\\pairing.json`];
|
|
16
|
-
}
|
|
17
|
-
return [`${home}/.conform-mcp/host-bridge/pairing.json`, `${home}/Library/Application Support/app.conform.tools/host-bridge/pairing.json`];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function parsePairing(text) {
|
|
21
|
-
const p = JSON.parse(String(text));
|
|
22
|
-
if (!p || typeof p !== "object") throw new Error("pairing is not an object");
|
|
23
|
-
if (p.protocol !== 1) throw new Error(`pairing protocol ${p.protocol}, this plugin speaks 1`);
|
|
24
|
-
if (typeof p.url !== "string" || !/^ws:\/\/(127\.0\.0\.1|localhost):\d+\/host-bridge$/.test(p.url)) throw new Error("pairing url is not the loopback bridge");
|
|
25
|
-
if (typeof p.token !== "string" || !/^[0-9a-f]{64}$/.test(p.token)) throw new Error("pairing token is malformed");
|
|
26
|
-
return { url: p.url, token: p.token, port: Number(p.port) || Number(p.url.split(":")[2]) };
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function maskToken(token) { return token ? `${token.slice(0, 6)}…${token.slice(-4)}` : ""; }
|
|
30
|
-
|
|
31
|
-
/** Build the reader for UXP; `deps` are injected so node tests run it. */
|
|
32
|
-
function makeReader(deps) {
|
|
33
|
-
const { readFileAt, pickedFolderRead, storage } = deps;
|
|
34
|
-
return async function readPairing() {
|
|
35
|
-
const errors = [];
|
|
36
|
-
for (const path of deps.candidates()) {
|
|
37
|
-
try {
|
|
38
|
-
const text = await readFileAt(path);
|
|
39
|
-
if (text) return { ...parsePairing(text), source: path };
|
|
40
|
-
} catch (e) { errors.push(`${path}: ${e.message || e}`); }
|
|
41
|
-
}
|
|
42
|
-
if (pickedFolderRead) {
|
|
43
|
-
try {
|
|
44
|
-
const text = await pickedFolderRead();
|
|
45
|
-
if (text) return { ...parsePairing(text), source: "picked folder" };
|
|
46
|
-
} catch (e) { errors.push(`picked folder: ${e.message || e}`); }
|
|
47
|
-
}
|
|
48
|
-
const pasted = storage && storage.getItem("conformtools.pairing");
|
|
49
|
-
if (pasted) {
|
|
50
|
-
try { return { ...parsePairing(pasted), source: "pasted" }; } catch (e) { errors.push(`pasted: ${e.message || e}`); }
|
|
51
|
-
}
|
|
52
|
-
const err = new Error(errors.length ? errors.join(" | ") : "no pairing found");
|
|
53
|
-
err.code = "unpaired";
|
|
54
|
-
throw err;
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
module.exports = { dataDirs, parsePairing, maskToken, makeReader };
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
// The one place the plugin touches the Premiere API module. Everything else
|
|
2
|
-
// goes through `api()` so the node tests can substitute a recorded fake.
|
|
3
|
-
//
|
|
4
|
-
// Premiere's UXP DOM is young (GA in 25.6) and parts of it are undocumented,
|
|
5
|
-
// so every call here is defensive: a missing method is a clear PeerError, not
|
|
6
|
-
// a TypeError deep inside a tool. `probe()` reports what THIS Premiere
|
|
7
|
-
// actually exposes; the live pass uses it to learn the real shapes.
|
|
8
|
-
"use strict";
|
|
9
|
-
|
|
10
|
-
const { PeerError } = require("./handles");
|
|
11
|
-
|
|
12
|
-
let _api = null;
|
|
13
|
-
let _uxp = null;
|
|
14
|
-
|
|
15
|
-
function api() {
|
|
16
|
-
if (_api) return _api;
|
|
17
|
-
try {
|
|
18
|
-
_api = require("premierepro");
|
|
19
|
-
} catch (e) {
|
|
20
|
-
throw new PeerError("no_premiere", "the premierepro module is not available (not running inside Premiere Pro?)");
|
|
21
|
-
}
|
|
22
|
-
return _api;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function uxp() {
|
|
26
|
-
if (_uxp) return _uxp;
|
|
27
|
-
try { _uxp = require("uxp"); } catch (_) { _uxp = null; }
|
|
28
|
-
return _uxp;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** Tests inject a fake DOM. */
|
|
32
|
-
function setApi(fake) { _api = fake; }
|
|
33
|
-
|
|
34
|
-
function hostVersion() {
|
|
35
|
-
try {
|
|
36
|
-
const u = uxp();
|
|
37
|
-
const v = u && u.host && u.host.version;
|
|
38
|
-
return v ? String(v) : "";
|
|
39
|
-
} catch (_) { return ""; }
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function platform() {
|
|
43
|
-
try {
|
|
44
|
-
const os = require("os");
|
|
45
|
-
const p = os.platform ? os.platform() : "";
|
|
46
|
-
return p === "darwin" || p === "win32" ? p : (p || "uxp");
|
|
47
|
-
} catch (_) { return "uxp"; }
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/** Call `obj.name(...)` when it exists, else throw a PeerError naming it. */
|
|
51
|
-
async function call(obj, name, ...args) {
|
|
52
|
-
if (!obj || typeof obj[name] !== "function") {
|
|
53
|
-
throw new PeerError("api_missing", `Premiere API has no ${name} here`);
|
|
54
|
-
}
|
|
55
|
-
return await obj[name](...args);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/** Try several method names in order (the DOM has renamed things between
|
|
59
|
-
* 25.x and 26.x); returns the first that exists. */
|
|
60
|
-
async function callAny(obj, names, ...args) {
|
|
61
|
-
for (const n of names) {
|
|
62
|
-
if (obj && typeof obj[n] === "function") return await obj[n](...args);
|
|
63
|
-
}
|
|
64
|
-
throw new PeerError("api_missing", `Premiere API has none of ${names.join("/")} here`);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function has(obj, name) { return !!obj && typeof obj[name] === "function"; }
|
|
68
|
-
|
|
69
|
-
/** Own + prototype member names of an object, for the probe. */
|
|
70
|
-
function members(obj) {
|
|
71
|
-
const out = new Set();
|
|
72
|
-
let o = obj;
|
|
73
|
-
let depth = 0;
|
|
74
|
-
while (o && depth < 4) {
|
|
75
|
-
for (const n of Object.getOwnPropertyNames(o)) if (n !== "constructor") out.add(n);
|
|
76
|
-
o = Object.getPrototypeOf(o);
|
|
77
|
-
depth += 1;
|
|
78
|
-
}
|
|
79
|
-
return Array.from(out).sort();
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
module.exports = { api, uxp, setApi, hostVersion, platform, call, callAny, has, members, PeerError };
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
// `debug.probe`: what THIS Premiere exposes. Data only (member names and
|
|
2
|
-
// constant values); nothing is evaluated. The live pass reads this first.
|
|
3
|
-
"use strict";
|
|
4
|
-
|
|
5
|
-
const { P, g, activeProject } = require("./ctx");
|
|
6
|
-
|
|
7
|
-
const verbs = {
|
|
8
|
-
// Try every plausible createKeyframe / createSetValueAction shape on ONE
|
|
9
|
-
// Motion param of `item` (Scale), inside a real transaction, and report
|
|
10
|
-
// which builds and which raises - so the write path uses the form Premiere
|
|
11
|
-
// actually wants. Data only; it writes Scale to itself (no net change).
|
|
12
|
-
"debug.sizing_probe": async ({ item }) => {
|
|
13
|
-
const PP = P;
|
|
14
|
-
const ppro = PP.api();
|
|
15
|
-
const it = g(item, "item");
|
|
16
|
-
const chain = await it.getComponentChain();
|
|
17
|
-
let motion = null;
|
|
18
|
-
for (let i = 0, n = await chain.getComponentCount(); i < n; i += 1) {
|
|
19
|
-
const c = await chain.getComponentAtIndex(i);
|
|
20
|
-
if (String(await c.getMatchName()).indexOf("Motion") >= 0) { motion = c; break; }
|
|
21
|
-
}
|
|
22
|
-
if (!motion) return { error: "no motion" };
|
|
23
|
-
let scale = null; let pos = null;
|
|
24
|
-
for (let j = 0, pn = await motion.getParamCount(); j < pn; j += 1) {
|
|
25
|
-
const prm = await motion.getParam(j);
|
|
26
|
-
if (String(prm.displayName) === "Scale") scale = prm;
|
|
27
|
-
if (String(prm.displayName) === "Position") pos = prm;
|
|
28
|
-
}
|
|
29
|
-
const out = { keyframe_forms: {}, setvalue_forms: {} };
|
|
30
|
-
const val = 130;
|
|
31
|
-
// createKeyframe variants
|
|
32
|
-
const tick0 = ppro.TickTime && ppro.TickTime.TIME_ZERO;
|
|
33
|
-
const kfTries = {
|
|
34
|
-
"num": () => scale.createKeyframe(val),
|
|
35
|
-
"num,tick": () => scale.createKeyframe(val, tick0),
|
|
36
|
-
"noarg": () => scale.createKeyframe(),
|
|
37
|
-
"obj_value": () => scale.createKeyframe({ value: val }),
|
|
38
|
-
};
|
|
39
|
-
let goodKf = null; let goodKfName = null;
|
|
40
|
-
for (const [name, fn] of Object.entries(kfTries)) {
|
|
41
|
-
try { const k = await fn(); out.keyframe_forms[name] = k === undefined ? "undefined" : (k && typeof k === "object" ? Object.keys(k).slice(0, 8) : String(k)); if (goodKf === null && k) { goodKf = k; goodKfName = name; } }
|
|
42
|
-
catch (e) { out.keyframe_forms[name] = "ERR " + (e.message || e); }
|
|
43
|
-
}
|
|
44
|
-
out.good_keyframe = goodKfName;
|
|
45
|
-
// createSetValueAction variants, each committed in its own transaction
|
|
46
|
-
const svTries = {
|
|
47
|
-
"value,ui": () => scale.createSetValueAction(val, true),
|
|
48
|
-
"value": () => scale.createSetValueAction(val),
|
|
49
|
-
"keyframe,ui": () => goodKf && scale.createSetValueAction(goodKf, true),
|
|
50
|
-
"keyframe": () => goodKf && scale.createSetValueAction(goodKf),
|
|
51
|
-
};
|
|
52
|
-
for (const [name, fn] of Object.entries(svTries)) {
|
|
53
|
-
try {
|
|
54
|
-
const action = await fn();
|
|
55
|
-
if (!action) { out.setvalue_forms[name] = "no-keyframe"; continue; }
|
|
56
|
-
await it.getProjectItem(); // touch, no-op
|
|
57
|
-
const proj = await PP.callAny(ppro.Project, ["getActiveProject"]);
|
|
58
|
-
let committed = false;
|
|
59
|
-
const run = () => { proj.executeTransaction((c) => c.addAction(action), "probe"); committed = true; };
|
|
60
|
-
if (PP.has(proj, "lockedAccess")) proj.lockedAccess(run); else run();
|
|
61
|
-
out.setvalue_forms[name] = committed ? "OK" : "built-not-committed";
|
|
62
|
-
} catch (e) { out.setvalue_forms[name] = "ERR " + (e.message || e); }
|
|
63
|
-
}
|
|
64
|
-
// Also whether the param itself has a direct setter
|
|
65
|
-
out.scale_members = PP.members(scale).filter((m) => /[Ss]et|[Kk]ey|[Vv]alue/.test(m));
|
|
66
|
-
return out;
|
|
67
|
-
},
|
|
68
|
-
"debug.probe": async () => {
|
|
69
|
-
const ppro = P.api();
|
|
70
|
-
const out = { host_version: P.hostVersion(), platform: P.platform(), top: Object.keys(ppro).sort(), classes: {}, constants: {} };
|
|
71
|
-
for (const k of ["Project", "Sequence", "VideoTrack", "VideoClipTrackItem", "TrackItem", "Markers", "Marker", "Metadata", "ClipProjectItem", "FolderItem", "ProjectItem", "ComponentChain", "Component", "ComponentParam", "Keyframe", "TickTime", "SequenceEditor", "EncoderManager", "ProjectConverter", "VideoFilterFactory", "PointF", "Media"]) {
|
|
72
|
-
if (ppro[k]) out.classes[k] = { static: P.members(ppro[k]).filter((n) => !["length", "name", "prototype"].includes(n)), proto: ppro[k].prototype ? P.members(ppro[k].prototype) : [] };
|
|
73
|
-
}
|
|
74
|
-
if (ppro.Constants) for (const k of Object.keys(ppro.Constants)) { try { out.constants[k] = ppro.Constants[k]; } catch (_) { /* skip */ } }
|
|
75
|
-
try {
|
|
76
|
-
const p = await activeProject();
|
|
77
|
-
if (p) {
|
|
78
|
-
out.project = { members: P.members(p), name: p.name, path: p.path };
|
|
79
|
-
const seq = P.has(p, "getActiveSequence") ? await p.getActiveSequence() : null;
|
|
80
|
-
if (seq) {
|
|
81
|
-
out.sequence = { members: P.members(seq), name: seq.name, timebase: String(await seq.getTimebase()) };
|
|
82
|
-
const track = P.has(seq, "getVideoTrack") ? await seq.getVideoTrack(0) : null;
|
|
83
|
-
if (track) {
|
|
84
|
-
out.track = { members: P.members(track) };
|
|
85
|
-
const items = await track.getTrackItems(ppro.Constants && ppro.Constants.TrackItemType ? ppro.Constants.TrackItemType.CLIP : 1, false);
|
|
86
|
-
// Every clip's raw numbers, as Premiere hands them out (ticks and
|
|
87
|
-
// seconds): what the model's frame maths is built on.
|
|
88
|
-
const tickOf = (v) => (v && typeof v === "object" ? { ticks: String(v.ticks !== undefined ? v.ticks : ""), seconds: Number(v.seconds !== undefined ? v.seconds : NaN) } : v);
|
|
89
|
-
out.items_raw = [];
|
|
90
|
-
for (const it of items || []) {
|
|
91
|
-
const row = {};
|
|
92
|
-
for (const m of ["getStartTime", "getEndTime", "getInPoint", "getOutPoint", "getDuration", "getSpeed", "isSpeedReversed", "isDisabled", "getName"]) {
|
|
93
|
-
try { row[m] = P.has(it, m) ? tickOf(await it[m]()) : "n/a"; } catch (e) { row[m] = `error: ${e.message || e}`; }
|
|
94
|
-
}
|
|
95
|
-
try {
|
|
96
|
-
const chain = P.has(it, "getComponentChain") ? await it.getComponentChain() : null;
|
|
97
|
-
const n = chain ? await chain.getComponentCount() : 0;
|
|
98
|
-
row.params = [];
|
|
99
|
-
for (let i = 0; i < n; i += 1) {
|
|
100
|
-
const c = await chain.getComponentAtIndex(i);
|
|
101
|
-
const pn = P.has(c, "getParamCount") ? await c.getParamCount() : 0;
|
|
102
|
-
for (let j = 0; j < pn; j += 1) {
|
|
103
|
-
const prm = await c.getParam(j);
|
|
104
|
-
let v = null;
|
|
105
|
-
try { v = P.has(prm, "getStartValue") ? await prm.getStartValue() : null; } catch (e) { v = `error: ${e.message || e}`; }
|
|
106
|
-
const val = v && typeof v === "object" ? { keys: Object.keys(v), value: v.value !== undefined ? (v.value && typeof v.value === "object" ? { x: v.value.x, y: v.value.y, keys: Object.keys(v.value) } : v.value) : undefined, x: v.x, y: v.y } : v;
|
|
107
|
-
let varying = null;
|
|
108
|
-
try { varying = P.has(prm, "isTimeVarying") ? await prm.isTimeVarying() : null; } catch (_) { varying = null; }
|
|
109
|
-
row.params.push({ component: P.has(c, "getDisplayName") ? await c.getDisplayName() : "", index: j, name: prm.displayName, start_value: val, time_varying: varying });
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
} catch (e) { row.params_error = String(e.message || e); }
|
|
113
|
-
out.items_raw.push(row);
|
|
114
|
-
}
|
|
115
|
-
if (items && items[0]) {
|
|
116
|
-
const it = items[0];
|
|
117
|
-
out.item = { members: P.members(it) };
|
|
118
|
-
const chain = P.has(it, "getComponentChain") ? await it.getComponentChain() : null;
|
|
119
|
-
if (chain) {
|
|
120
|
-
const n = await chain.getComponentCount();
|
|
121
|
-
out.components = [];
|
|
122
|
-
for (let i = 0; i < n; i += 1) {
|
|
123
|
-
const c = await chain.getComponentAtIndex(i);
|
|
124
|
-
const pn = P.has(c, "getParamCount") ? await c.getParamCount() : 0;
|
|
125
|
-
const params = [];
|
|
126
|
-
for (let j = 0; j < pn; j += 1) { const prm = await c.getParam(j); params.push({ index: j, displayName: prm.displayName, members: P.members(prm).slice(0, 40) }); }
|
|
127
|
-
out.components.push({ match: P.has(c, "getMatchName") ? await c.getMatchName() : "", display: P.has(c, "getDisplayName") ? await c.getDisplayName() : "", params });
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
} catch (e) { out.probe_error = String(e && e.message || e); }
|
|
135
|
-
return out;
|
|
136
|
-
},
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
module.exports = { verbs };
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
// The wire protocol, plugin side (docs/INTERNAL_HOST_BRIDGE.md, protocol 1).
|
|
2
|
-
//
|
|
3
|
-
// The app hosts a loopback WebSocket; this panel is the CLIENT (a UXP panel
|
|
4
|
-
// cannot listen). First frame out is `hello` with the pairing token; the app
|
|
5
|
-
// answers `welcome`. After that the app sends `request`s and we answer
|
|
6
|
-
// `response`s. We never send a request: there is no message that makes the
|
|
7
|
-
// app run anything.
|
|
8
|
-
//
|
|
9
|
-
// Pure: the WebSocket constructor and the verb table are injected, so the
|
|
10
|
-
// node tests drive this file without Premiere or a socket.
|
|
11
|
-
"use strict";
|
|
12
|
-
|
|
13
|
-
const { PeerError } = require("./handles");
|
|
14
|
-
|
|
15
|
-
const PROTOCOL_VERSION = 1;
|
|
16
|
-
const RECONNECT_MS = [500, 1000, 2000, 4000, 8000, 15000];
|
|
17
|
-
|
|
18
|
-
class BridgeClient {
|
|
19
|
-
/**
|
|
20
|
-
* @param {object} opts
|
|
21
|
-
* @param {(url:string)=>WebSocket} opts.makeSocket
|
|
22
|
-
* @param {()=>Promise<{url:string,token:string}|null>} opts.readPairing
|
|
23
|
-
* @param {{id:string,name:string,version:string,platform:string}} opts.host
|
|
24
|
-
* @param {string[]} opts.capabilities
|
|
25
|
-
* @param {string[]} [opts.optionalVerbs]
|
|
26
|
-
* @param {Record<string,(params:object)=>Promise<any>|any>} opts.verbs "cap.verb" -> fn
|
|
27
|
-
* @param {(line:string)=>void} [opts.log]
|
|
28
|
-
* @param {(state:string, detail?:string)=>void} [opts.onState]
|
|
29
|
-
* @param {(fn:Function, ms:number)=>any} [opts.setTimeout]
|
|
30
|
-
*/
|
|
31
|
-
constructor(opts) {
|
|
32
|
-
this.o = opts;
|
|
33
|
-
this.ws = null;
|
|
34
|
-
this.state = "idle";
|
|
35
|
-
this.attempt = 0;
|
|
36
|
-
this._stopped = false;
|
|
37
|
-
this._timer = null;
|
|
38
|
-
this._setTimeout = opts.setTimeout || ((fn, ms) => setTimeout(fn, ms));
|
|
39
|
-
this._clearTimeout = opts.clearTimeout || ((t) => clearTimeout(t));
|
|
40
|
-
this.inflight = 0;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
log(line) { if (this.o.log) this.o.log(line); }
|
|
44
|
-
setState(s, detail) { this.state = s; if (this.o.onState) this.o.onState(s, detail || ""); }
|
|
45
|
-
|
|
46
|
-
start() {
|
|
47
|
-
this._stopped = false;
|
|
48
|
-
this.attempt = 0;
|
|
49
|
-
return this.connect();
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
stop() {
|
|
53
|
-
this._stopped = true;
|
|
54
|
-
if (this._timer) { this._clearTimeout(this._timer); this._timer = null; }
|
|
55
|
-
if (this.ws) { try { this.ws.close(); } catch (_) { /* closing */ } this.ws = null; }
|
|
56
|
-
this.setState("stopped");
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async connect() {
|
|
60
|
-
if (this._stopped) return;
|
|
61
|
-
let pairing = null;
|
|
62
|
-
try { pairing = await this.o.readPairing(); } catch (e) { this.log(`pairing: ${e.message || e}`); }
|
|
63
|
-
if (!pairing || !pairing.url || !pairing.token) {
|
|
64
|
-
this.setState("unpaired", "no pairing file - enable the host bridge in conform.tools");
|
|
65
|
-
return this.scheduleReconnect();
|
|
66
|
-
}
|
|
67
|
-
// The pairing names 127.0.0.1; UXP matches the manifest's network
|
|
68
|
-
// domains by string, so the same loopback is also tried as `localhost`
|
|
69
|
-
// (both are listed) - alternating per attempt.
|
|
70
|
-
const url = this.attempt % 2 === 1 ? pairing.url.replace("ws://127.0.0.1:", "ws://localhost:") : pairing.url;
|
|
71
|
-
this.setState("connecting", url);
|
|
72
|
-
let ws;
|
|
73
|
-
try {
|
|
74
|
-
ws = this.o.makeSocket(url);
|
|
75
|
-
} catch (e) {
|
|
76
|
-
// UXP raises here when the manifest permission has not been granted yet
|
|
77
|
-
// (seen on cold start of an installed .ccx); a reconnect fixes it.
|
|
78
|
-
this.log(`socket: ${e.message || e}`);
|
|
79
|
-
return this.scheduleReconnect();
|
|
80
|
-
}
|
|
81
|
-
this.ws = ws;
|
|
82
|
-
ws.onopen = () => {
|
|
83
|
-
this.attempt = 0;
|
|
84
|
-
const hello = {
|
|
85
|
-
type: "hello", protocol: PROTOCOL_VERSION, token: pairing.token,
|
|
86
|
-
host: this.o.host, capabilities: this.o.capabilities, optional_verbs: this.o.optionalVerbs || [],
|
|
87
|
-
};
|
|
88
|
-
this.send(hello);
|
|
89
|
-
this.setState("hello");
|
|
90
|
-
};
|
|
91
|
-
ws.onmessage = (ev) => { this.onFrame(typeof ev === "string" ? ev : ev.data); };
|
|
92
|
-
ws.onerror = (ev) => { this.log(`socket error${ev && ev.message ? ": " + ev.message : ""}`); };
|
|
93
|
-
ws.onclose = (ev) => {
|
|
94
|
-
const wasConnected = this.state === "connected";
|
|
95
|
-
this.ws = null;
|
|
96
|
-
this.setState("closed", ev && ev.code ? `code ${ev.code}` : "");
|
|
97
|
-
if (!this._stopped) this.scheduleReconnect(wasConnected);
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
scheduleReconnect(fast) {
|
|
102
|
-
if (this._stopped || this._timer) return;
|
|
103
|
-
const ms = fast ? RECONNECT_MS[0] : RECONNECT_MS[Math.min(this.attempt, RECONNECT_MS.length - 1)];
|
|
104
|
-
this.attempt += 1;
|
|
105
|
-
this._timer = this._setTimeout(() => { this._timer = null; this.connect(); }, ms);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
send(obj) {
|
|
109
|
-
if (!this.ws) return false;
|
|
110
|
-
try { this.ws.send(JSON.stringify(obj)); return true; } catch (e) { this.log(`send: ${e.message || e}`); return false; }
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/** One text frame from the app. Never throws; a bad frame is logged. */
|
|
114
|
-
async onFrame(text) {
|
|
115
|
-
let msg;
|
|
116
|
-
try { msg = JSON.parse(text); } catch (_) { this.log("bad frame (not JSON)"); return; }
|
|
117
|
-
if (!msg || typeof msg !== "object") return;
|
|
118
|
-
switch (msg.type) {
|
|
119
|
-
case "welcome":
|
|
120
|
-
this.app = msg.app || {};
|
|
121
|
-
this.setState("connected", `${this.app.name || "app"} ${this.app.version || ""}`.trim());
|
|
122
|
-
return;
|
|
123
|
-
case "error":
|
|
124
|
-
this.log(`app refused: ${msg.code || "error"}${msg.message ? " - " + msg.message : ""}`);
|
|
125
|
-
this.setState("refused", msg.code || "error");
|
|
126
|
-
if (msg.code === "bad_token" || msg.code === "protocol_mismatch") {
|
|
127
|
-
// A stale pairing file: re-read it next time rather than hammering.
|
|
128
|
-
this.attempt = Math.max(this.attempt, 3);
|
|
129
|
-
}
|
|
130
|
-
return;
|
|
131
|
-
case "request":
|
|
132
|
-
return this.onRequest(msg);
|
|
133
|
-
default:
|
|
134
|
-
this.log(`unexpected frame type ${msg.type}`);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
async onRequest(msg) {
|
|
139
|
-
const id = msg.id;
|
|
140
|
-
const method = String(msg.method || "");
|
|
141
|
-
const fn = this.o.verbs[method];
|
|
142
|
-
if (!fn) {
|
|
143
|
-
const cap = method.split(".")[0];
|
|
144
|
-
const code = this.o.capabilities.includes(cap) ? "unknown_method" : "capability_missing";
|
|
145
|
-
return this.send({ type: "response", id, ok: false, error: { code, message: method } });
|
|
146
|
-
}
|
|
147
|
-
this.inflight += 1;
|
|
148
|
-
try {
|
|
149
|
-
const result = await fn(msg.params || {});
|
|
150
|
-
this.send({ type: "response", id, ok: true, result: result === undefined ? null : result });
|
|
151
|
-
} catch (e) {
|
|
152
|
-
const code = (e && e.code) || "peer_error";
|
|
153
|
-
const message = (e && e.message) || String(e);
|
|
154
|
-
this.log(`${method}: ${message}`);
|
|
155
|
-
this.send({ type: "response", id, ok: false, error: { code, message } });
|
|
156
|
-
} finally {
|
|
157
|
-
this.inflight -= 1;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/** A peer may push an event; it is inert JSON on the app side. */
|
|
162
|
-
event(name, data) { this.send({ type: "event", name, data: data || {} }); }
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
module.exports = { BridgeClient, PROTOCOL_VERSION, RECONNECT_MS, PeerError };
|