@nonstrict/recordkit 0.2.0 → 0.3.0-alpha.1
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/bin/.gitkeep +0 -0
- package/bin/recordkit-rpc +0 -0
- package/build.sh +32 -0
- package/jest.config.js +16 -0
- package/{dist → out}/IpcRecordKit.d.ts +0 -1
- package/{dist → out}/IpcRecordKit.js +4 -1
- package/out/IpcRecordKit.js.map +1 -0
- package/{dist → out}/NonstrictRPC.d.ts +0 -1
- package/{dist → out}/NonstrictRPC.js +4 -2
- package/out/NonstrictRPC.js.map +1 -0
- package/out/RecordKit.d.ts +50 -0
- package/out/RecordKit.js +48 -0
- package/out/RecordKit.js.map +1 -0
- package/out/Recorder.d.ts +59 -0
- package/{dist/RecordingSession.js → out/Recorder.js} +23 -5
- package/out/Recorder.js.map +1 -0
- package/{dist → out}/finalizationRegistry.d.ts +0 -1
- package/{dist → out}/finalizationRegistry.js +1 -0
- package/out/finalizationRegistry.js.map +1 -0
- package/out/index.cjs +322 -0
- package/out/index.cjs.map +1 -0
- package/out/index.d.ts +3 -0
- package/{dist → out}/index.js +1 -0
- package/out/index.js.map +1 -0
- package/package.json +13 -11
- package/rollup.config.js +11 -0
- package/src/IpcRecordKit.ts +46 -0
- package/src/NonstrictRPC.test.ts +98 -0
- package/src/NonstrictRPC.ts +308 -0
- package/src/RecordKit.ts +99 -0
- package/src/Recorder.ts +113 -0
- package/src/__snapshots__/NonstrictRPC.test.ts.snap +24 -0
- package/src/finalizationRegistry.ts +2 -0
- package/src/index.ts +3 -0
- package/tsconfig.json +109 -0
- package/typedoc.json +6 -0
- package/dist/IpcRecordKit.d.ts.map +0 -1
- package/dist/NonstrictRPC.d.ts.map +0 -1
- package/dist/RecordKit.d.ts +0 -35
- package/dist/RecordKit.d.ts.map +0 -1
- package/dist/RecordKit.js +0 -24
- package/dist/RecordingSession.d.ts +0 -71
- package/dist/RecordingSession.d.ts.map +0 -1
- package/dist/finalizationRegistry.d.ts.map +0 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +0 -1
package/bin/.gitkeep
ADDED
|
File without changes
|
|
Binary file
|
package/build.sh
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/bin/bash -e
|
|
2
|
+
|
|
3
|
+
# Check arguments
|
|
4
|
+
VERSION_NUMBER="$1"
|
|
5
|
+
|
|
6
|
+
if [ -z "$VERSION_NUMBER" ]; then
|
|
7
|
+
echo "Missing version argument: ./build.sh 0.3.4"
|
|
8
|
+
exit 1
|
|
9
|
+
fi
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
# Clean up previous artifact directory
|
|
13
|
+
rm -r ./dist || echo "No old build to remove"
|
|
14
|
+
|
|
15
|
+
# Set version in package.json
|
|
16
|
+
function restore_package_json {
|
|
17
|
+
npm version 0.0.0
|
|
18
|
+
echo "Restored version"
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
# register the cleanup function to be called on the EXIT signal
|
|
22
|
+
trap restore_package_json EXIT
|
|
23
|
+
|
|
24
|
+
echo "Updating version number"
|
|
25
|
+
npm version $VERSION_NUMBER
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# Build recordkit-electron
|
|
29
|
+
npm run build
|
|
30
|
+
contents=(*)
|
|
31
|
+
mkdir dist
|
|
32
|
+
cp -r ${contents[*]} dist
|
package/jest.config.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
|
2
|
+
export default {
|
|
3
|
+
preset: "ts-jest/presets/default-esm",
|
|
4
|
+
testEnvironment: "node",
|
|
5
|
+
moduleNameMapper: {
|
|
6
|
+
"^(\\.{1,2}/.*)\\.js$": "$1",
|
|
7
|
+
},
|
|
8
|
+
transform: {
|
|
9
|
+
"^.+\\.tsx?$": [
|
|
10
|
+
"ts-jest",
|
|
11
|
+
{
|
|
12
|
+
useESM: true,
|
|
13
|
+
},
|
|
14
|
+
],
|
|
15
|
+
},
|
|
16
|
+
};
|
|
@@ -2,8 +2,10 @@ import { spawn } from 'node:child_process';
|
|
|
2
2
|
import * as readline from 'readline';
|
|
3
3
|
import { NSRPC } from "./NonstrictRPC.js";
|
|
4
4
|
export class IpcRecordKit {
|
|
5
|
+
logMessages = false;
|
|
6
|
+
childProcess;
|
|
7
|
+
nsrpc;
|
|
5
8
|
constructor() {
|
|
6
|
-
this.logMessages = false;
|
|
7
9
|
this.nsrpc = new NSRPC((message) => this.write(message));
|
|
8
10
|
}
|
|
9
11
|
async initialize(recordKitRpcPath, logMessages = false) {
|
|
@@ -38,3 +40,4 @@ export class IpcRecordKit {
|
|
|
38
40
|
stdin.write(message + "\n");
|
|
39
41
|
}
|
|
40
42
|
}
|
|
43
|
+
//# sourceMappingURL=IpcRecordKit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IpcRecordKit.js","sourceRoot":"","sources":["../src/IpcRecordKit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE1C,MAAM,OAAO,YAAY;IACb,WAAW,GAAY,KAAK,CAAC;IAC7B,YAAY,CAAgB;IAC3B,KAAK,CAAQ;IAEtB;QACI,IAAI,CAAC,KAAK,GAAG,IAAI,KAAK,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;IAC7D,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,gBAAwB,EAAE,cAAuB,KAAK;QACnE,IAAI,IAAI,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;YAAC,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;QAAC,CAAC;QAE/F,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IA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AAO,GAAG,IAAI,CAAC,CAAA;IAC/B,CAAC;CACJ"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { randomUUID } from "crypto";
|
|
2
2
|
import { finalizationRegistry } from "./finalizationRegistry.js";
|
|
3
3
|
export class NSRPC {
|
|
4
|
+
send;
|
|
5
|
+
responseHandlers = new Map();
|
|
6
|
+
closureTargets = new Map();
|
|
4
7
|
constructor(send) {
|
|
5
|
-
this.responseHandlers = new Map();
|
|
6
|
-
this.closureTargets = new Map();
|
|
7
8
|
this.send = send;
|
|
8
9
|
}
|
|
9
10
|
receive(data) {
|
|
@@ -153,3 +154,4 @@ export class NSRPC {
|
|
|
153
154
|
return target;
|
|
154
155
|
}
|
|
155
156
|
}
|
|
157
|
+
//# sourceMappingURL=NonstrictRPC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NonstrictRPC.js","sourceRoot":"","sources":["../src/NonstrictRPC.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AA+GjE,MAAM,OAAO,KAAK;IACC,IAAI,CAAyB;IAEtC,gBAAgB,GAA+B,IAAI,GAAG,EAAE,CAAC;IACzD,cAAc,GAA+B,IAAI,GAAG,EAAE,CAAC;IAE/D,YAAY,IAA4B;QACtC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,OAAO,CAAC,IAAY;QAClB,oFAAoF;QACpF,mCAAmC;QACnC,yEAAyE;QACzE,8DAA8D;QAC9D,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAiB,CAAC;QACjD,IAAI,QAAQ,IAAI,OAAO,EAAE,CAAC;YACxB,uDAAuD;YACvD,MAAM,eAAe,GAAG,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YAC9D,IAAI,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U,OAAO,CAAC,MAAM,IAAI,UAAU,EAAE,EAAE,CAAC;QAC1D,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QAEjD,oBAAoB,CAAC,QAAQ,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,EAAE;YACpD,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Recorder, RecorderSchema } from "./Recorder.js";
|
|
2
|
+
type AuthorizationStatus = 'notDetermined' | 'restricted' | 'denied' | 'authorized';
|
|
3
|
+
export interface Window {
|
|
4
|
+
id: number;
|
|
5
|
+
title?: string;
|
|
6
|
+
frame: Bounds;
|
|
7
|
+
level: number;
|
|
8
|
+
application_process_id?: number;
|
|
9
|
+
application_name?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface Camera {
|
|
12
|
+
id: string;
|
|
13
|
+
name: string;
|
|
14
|
+
model_id: string;
|
|
15
|
+
manufacturer: string;
|
|
16
|
+
availability: 'available' | 'lidClosed' | 'unknownSuspended';
|
|
17
|
+
}
|
|
18
|
+
export interface Microphone {
|
|
19
|
+
id: string;
|
|
20
|
+
name: string;
|
|
21
|
+
model_id: string;
|
|
22
|
+
manufacturer: string;
|
|
23
|
+
availability: 'available' | 'lidClosed' | 'unknownSuspended';
|
|
24
|
+
}
|
|
25
|
+
export interface Bounds {
|
|
26
|
+
x: number;
|
|
27
|
+
y: number;
|
|
28
|
+
width: number;
|
|
29
|
+
height: number;
|
|
30
|
+
}
|
|
31
|
+
export declare class RecordKit {
|
|
32
|
+
private ipcRecordKit;
|
|
33
|
+
initialize(args: {
|
|
34
|
+
rpcBinaryPath: string;
|
|
35
|
+
fallbackToNodeModules: boolean;
|
|
36
|
+
logRpcMessages?: boolean;
|
|
37
|
+
}): Promise<void>;
|
|
38
|
+
getWindows(): Promise<Window[]>;
|
|
39
|
+
getCameras(): Promise<Camera[]>;
|
|
40
|
+
getMicrophones(): Promise<Microphone[]>;
|
|
41
|
+
getCameraAuthorizationStatus(): Promise<AuthorizationStatus>;
|
|
42
|
+
getMicrophoneAuthorizationStatus(): Promise<AuthorizationStatus>;
|
|
43
|
+
getScreenRecordingAccess(): Promise<boolean>;
|
|
44
|
+
requestCameraAccess(): Promise<boolean>;
|
|
45
|
+
requestMicrophoneAccess(): Promise<boolean>;
|
|
46
|
+
requestScreenRecordingAccess(): Promise<void>;
|
|
47
|
+
createRecorder(schema: RecorderSchema): Promise<Recorder>;
|
|
48
|
+
}
|
|
49
|
+
export declare let recordkit: RecordKit;
|
|
50
|
+
export {};
|
package/out/RecordKit.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { IpcRecordKit } from "./IpcRecordKit.js";
|
|
2
|
+
import { Recorder } from "./Recorder.js";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
export class RecordKit {
|
|
5
|
+
ipcRecordKit = new IpcRecordKit();
|
|
6
|
+
async initialize(args) {
|
|
7
|
+
let rpcBinaryPath = args.rpcBinaryPath;
|
|
8
|
+
if (!args.fallbackToNodeModules) {
|
|
9
|
+
if (!existsSync(rpcBinaryPath)) {
|
|
10
|
+
console.log('Falling back to RPC binary from node_modules, no file at given RPC binary path.');
|
|
11
|
+
rpcBinaryPath = rpcBinaryPath.replace('node_modules/electron/dist/Electron.app/Contents/Resources', 'node_modules/@nonstrict/recordkit/bin');
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return this.ipcRecordKit.initialize(rpcBinaryPath, args.logRpcMessages);
|
|
15
|
+
}
|
|
16
|
+
async getWindows() {
|
|
17
|
+
return await this.ipcRecordKit.nsrpc.perform({ type: 'Recorder', action: 'getWindows' });
|
|
18
|
+
}
|
|
19
|
+
async getCameras() {
|
|
20
|
+
return await this.ipcRecordKit.nsrpc.perform({ type: 'Recorder', action: 'getCameras' });
|
|
21
|
+
}
|
|
22
|
+
async getMicrophones() {
|
|
23
|
+
return await this.ipcRecordKit.nsrpc.perform({ type: 'Recorder', action: 'getMicrophones' });
|
|
24
|
+
}
|
|
25
|
+
async getCameraAuthorizationStatus() {
|
|
26
|
+
return await this.ipcRecordKit.nsrpc.perform({ type: 'AuthorizationStatus', action: 'getCameraAuthorizationStatus' });
|
|
27
|
+
}
|
|
28
|
+
async getMicrophoneAuthorizationStatus() {
|
|
29
|
+
return await this.ipcRecordKit.nsrpc.perform({ type: 'AuthorizationStatus', action: 'getMicrophoneAuthorizationStatus' });
|
|
30
|
+
}
|
|
31
|
+
async getScreenRecordingAccess() {
|
|
32
|
+
return await this.ipcRecordKit.nsrpc.perform({ type: 'AuthorizationStatus', action: 'getScreenRecordingAccess' });
|
|
33
|
+
}
|
|
34
|
+
async requestCameraAccess() {
|
|
35
|
+
return await this.ipcRecordKit.nsrpc.perform({ type: 'AuthorizationStatus', action: 'requestCameraAccess' });
|
|
36
|
+
}
|
|
37
|
+
async requestMicrophoneAccess() {
|
|
38
|
+
return await this.ipcRecordKit.nsrpc.perform({ type: 'AuthorizationStatus', action: 'requestMicrophoneAccess' });
|
|
39
|
+
}
|
|
40
|
+
async requestScreenRecordingAccess() {
|
|
41
|
+
return await this.ipcRecordKit.nsrpc.perform({ type: 'AuthorizationStatus', action: 'requestScreenRecordingAccess' });
|
|
42
|
+
}
|
|
43
|
+
async createRecorder(schema) {
|
|
44
|
+
return Recorder.newInstance(this.ipcRecordKit.nsrpc, schema);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export let recordkit = new RecordKit();
|
|
48
|
+
//# sourceMappingURL=RecordKit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RecordKit.js","sourceRoot":"","sources":["../src/RecordKit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,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mode="require"/>
|
|
3
|
+
import { NSRPC } from "./NonstrictRPC.js";
|
|
4
|
+
import { EventEmitter } from "stream";
|
|
5
|
+
import { Camera, Microphone, Window } from "./RecordKit.js";
|
|
6
|
+
export interface RecorderSchema {
|
|
7
|
+
output_directory?: string;
|
|
8
|
+
items: RecorderSchemaItem[];
|
|
9
|
+
}
|
|
10
|
+
export type RecorderSchemaItem = WebcamSchema | WindowBasedCropSchema;
|
|
11
|
+
export interface WebcamSchema {
|
|
12
|
+
type: 'webcam';
|
|
13
|
+
filename?: string;
|
|
14
|
+
camera: Camera | string;
|
|
15
|
+
microphone: Microphone | string;
|
|
16
|
+
}
|
|
17
|
+
export interface WindowBasedCropSchema {
|
|
18
|
+
type: 'windowBasedCrop';
|
|
19
|
+
filename?: string;
|
|
20
|
+
window: Window | number;
|
|
21
|
+
shows_cursor?: boolean;
|
|
22
|
+
mouse_events?: boolean;
|
|
23
|
+
}
|
|
24
|
+
export type AbortReason = {
|
|
25
|
+
reason: 'userStopped';
|
|
26
|
+
result: RecordingResult;
|
|
27
|
+
} | {
|
|
28
|
+
reason: 'interrupted';
|
|
29
|
+
result: RecordingResult;
|
|
30
|
+
error: RecordKitError;
|
|
31
|
+
} | {
|
|
32
|
+
reason: 'failed';
|
|
33
|
+
error: RecordKitError;
|
|
34
|
+
};
|
|
35
|
+
export interface RecordingResult {
|
|
36
|
+
url: string;
|
|
37
|
+
info: BundleInfo;
|
|
38
|
+
}
|
|
39
|
+
export interface RecordKitError {
|
|
40
|
+
message?: string;
|
|
41
|
+
error_group: string;
|
|
42
|
+
debug_description: string;
|
|
43
|
+
}
|
|
44
|
+
export interface BundleInfo {
|
|
45
|
+
version: 1;
|
|
46
|
+
files: {
|
|
47
|
+
type: 'screen' | 'webcam' | 'mouse';
|
|
48
|
+
filename: string;
|
|
49
|
+
}[];
|
|
50
|
+
}
|
|
51
|
+
export declare class Recorder extends EventEmitter {
|
|
52
|
+
private readonly rpc;
|
|
53
|
+
private readonly target;
|
|
54
|
+
static newInstance(rpc: NSRPC, schema: RecorderSchema): Promise<Recorder>;
|
|
55
|
+
constructor(rpc: NSRPC, target: string);
|
|
56
|
+
prepare(): Promise<void>;
|
|
57
|
+
start(): Promise<void>;
|
|
58
|
+
stop(): Promise<RecordingResult>;
|
|
59
|
+
}
|
|
@@ -1,18 +1,35 @@
|
|
|
1
1
|
import { randomUUID } from "crypto";
|
|
2
2
|
import { EventEmitter } from "stream";
|
|
3
|
-
export class
|
|
3
|
+
export class Recorder extends EventEmitter {
|
|
4
|
+
rpc;
|
|
5
|
+
target;
|
|
4
6
|
static async newInstance(rpc, schema) {
|
|
5
|
-
const target = '
|
|
6
|
-
const object = new
|
|
7
|
+
const target = 'Recorder_' + randomUUID();
|
|
8
|
+
const object = new Recorder(rpc, target);
|
|
9
|
+
schema.items.forEach(item => {
|
|
10
|
+
if (item.type == 'webcam') {
|
|
11
|
+
if (typeof item.camera != 'string') {
|
|
12
|
+
item.camera = item.camera.id;
|
|
13
|
+
}
|
|
14
|
+
if (typeof item.microphone != 'string') {
|
|
15
|
+
item.microphone = item.microphone.id;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
if (item.type == 'windowBasedCrop') {
|
|
19
|
+
if (typeof item.window != 'number') {
|
|
20
|
+
item.window = item.window.id;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
});
|
|
7
24
|
const weakRefObject = new WeakRef(object);
|
|
8
25
|
const onAbortInstance = rpc.registerClosure({
|
|
9
26
|
handler: (params) => { weakRefObject.deref()?.emit('abort', params.reason); },
|
|
10
|
-
prefix: '
|
|
27
|
+
prefix: 'Recorder.onAbort',
|
|
11
28
|
lifecycle: object
|
|
12
29
|
});
|
|
13
30
|
await rpc.initialize({
|
|
14
31
|
target,
|
|
15
|
-
type: '
|
|
32
|
+
type: 'Recorder',
|
|
16
33
|
params: { schema, onAbortInstance },
|
|
17
34
|
lifecycle: object
|
|
18
35
|
});
|
|
@@ -33,3 +50,4 @@ export class RecordingSession extends EventEmitter {
|
|
|
33
50
|
return await this.rpc.perform({ target: this.target, action: 'stop' });
|
|
34
51
|
}
|
|
35
52
|
}
|
|
53
|
+
//# sourceMappingURL=Recorder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Recorder.js","sourceRoot":"","sources":["../src/Recorder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAGpC,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAmDtC,MAAM,OAAO,QAAS,SAAQ,YAAY;IACvB,GAAG,CAAQ;IACX,MAAM,CAAS;IAEhC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,GAAU,EAAE,MAAsB;QACzD,MAAM,MAAM,GAAG,WAAW,GAAG,UAAU,EAAE,CAAC;QAC1C,MAAM,MAAM,GAAG,IAAI,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QAEzC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YAC1B,IAAI,IAAI,CAAC,IAAI,IAAI,QAAQ,EAAE,CAAC;gBAC1B,IAAI,OAAO,IAAI,CAAC,MAAM,IAAI,QAAQ,EAAE,CAAC;oBACnC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,CAAA;gBAC9B,CAAC;gBACD,IAAI,OAAO,IAAI,CAAC,UAAU,IAAI,QAAQ,EAAE,CAAC;oBACvC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,EAAE,CAAA;gBACtC,CAAC;YACH,CAAC;YACD,IAAI,IAAI,CAAC,IAAI,IAAI,iBAAiB,EAAE,CAAC;gBACnC,IAAI,OAAO,IAAI,CAAC,MAAM,IAAI,QAAQ,EAAE,CAAC;oBACnC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,CAAA;gBAC9B,CAAC;YACH,CAAC;QACH,CAAC,CA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ry.js","sourceRoot":"","sources":["../src/finalizationRegistry.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,oBAAoB,CAAa,KAAK,EAAE,UAAU,EAAE,EAAE,GAAG,MAAM,UAAU,EAAE,CAAA,CAAC,CAAC,CAAC,CAAA"}
|
package/out/index.cjs
ADDED
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var node_child_process = require('node:child_process');
|
|
4
|
+
var readline = require('readline');
|
|
5
|
+
var crypto = require('crypto');
|
|
6
|
+
var stream = require('stream');
|
|
7
|
+
var node_fs = require('node:fs');
|
|
8
|
+
|
|
9
|
+
function _interopNamespaceDefault(e) {
|
|
10
|
+
var n = Object.create(null);
|
|
11
|
+
if (e) {
|
|
12
|
+
Object.keys(e).forEach(function (k) {
|
|
13
|
+
if (k !== 'default') {
|
|
14
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
15
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return e[k]; }
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
n.default = e;
|
|
23
|
+
return Object.freeze(n);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
var readline__namespace = /*#__PURE__*/_interopNamespaceDefault(readline);
|
|
27
|
+
|
|
28
|
+
const finalizationRegistry = new FinalizationRegistry(async (destructor) => { await destructor(); });
|
|
29
|
+
|
|
30
|
+
class NSRPC {
|
|
31
|
+
send;
|
|
32
|
+
responseHandlers = new Map();
|
|
33
|
+
closureTargets = new Map();
|
|
34
|
+
constructor(send) {
|
|
35
|
+
this.send = send;
|
|
36
|
+
}
|
|
37
|
+
receive(data) {
|
|
38
|
+
// TODO: For now we just assume the message is a valid NSRPC message, but we should:
|
|
39
|
+
// - Handle invalid JSON comming in
|
|
40
|
+
// - Check if the nsrpc property is set to a number in the range of 1..<2
|
|
41
|
+
// - Validate the message against the defined interfaces above
|
|
42
|
+
const message = JSON.parse(data);
|
|
43
|
+
if ("status" in message) {
|
|
44
|
+
// This is a response, dispatch it so it can be handled
|
|
45
|
+
const responseHandler = this.responseHandlers.get(message.id);
|
|
46
|
+
this.responseHandlers.delete(message.id);
|
|
47
|
+
if (responseHandler === undefined) {
|
|
48
|
+
// TODO: Got a response for a request we don't know about, log this
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if ("error" in message) {
|
|
52
|
+
responseHandler.reject(message.error);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
responseHandler.resolve(message.result);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
// This is a request
|
|
60
|
+
const responseBody = this.handleRequest(message);
|
|
61
|
+
if (responseBody !== undefined) {
|
|
62
|
+
this.sendResponse(message.id, responseBody);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/* Sending helpers */
|
|
67
|
+
sendMessage(message) {
|
|
68
|
+
this.send(JSON.stringify(message));
|
|
69
|
+
}
|
|
70
|
+
sendResponse(id, response) {
|
|
71
|
+
if (id === undefined) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
this.sendMessage({ ...response, nsrpc: 1, id });
|
|
75
|
+
}
|
|
76
|
+
async sendRequest(request) {
|
|
77
|
+
const id = "req_" + crypto.randomUUID();
|
|
78
|
+
const response = new Promise((resolve, reject) => {
|
|
79
|
+
this.responseHandlers.set(id, { resolve, reject });
|
|
80
|
+
});
|
|
81
|
+
this.sendMessage({ ...request, nsrpc: 1, id });
|
|
82
|
+
return response;
|
|
83
|
+
}
|
|
84
|
+
/* Request handling */
|
|
85
|
+
handleRequest(request) {
|
|
86
|
+
switch (request.procedure) {
|
|
87
|
+
case "init":
|
|
88
|
+
return {
|
|
89
|
+
status: 501,
|
|
90
|
+
error: {
|
|
91
|
+
debugDescription: "Init procedure not implemented.",
|
|
92
|
+
userMessage: "Failed to communicate with external process. (Procedure not implemented)",
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
case "perform":
|
|
96
|
+
if ("action" in request) {
|
|
97
|
+
return {
|
|
98
|
+
status: 501,
|
|
99
|
+
error: {
|
|
100
|
+
debugDescription: "Perform procedure for (static) methods not implemented.",
|
|
101
|
+
userMessage: "Failed to communicate with external process. (Procedure not implemented)",
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
return this.handleClosureRequest(request);
|
|
107
|
+
}
|
|
108
|
+
case "release":
|
|
109
|
+
return {
|
|
110
|
+
status: 501,
|
|
111
|
+
error: {
|
|
112
|
+
debugDescription: "Release procedure not implemented.",
|
|
113
|
+
userMessage: "Failed to communicate with external process. (Procedure not implemented)",
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
handleClosureRequest(request) {
|
|
119
|
+
const handler = this.closureTargets.get(request.target);
|
|
120
|
+
if (handler === undefined) {
|
|
121
|
+
return {
|
|
122
|
+
status: 404,
|
|
123
|
+
error: {
|
|
124
|
+
debugDescription: `Perform target '${request.target}' not found.`,
|
|
125
|
+
userMessage: "Failed to communicate with external process. (Target not found)",
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
try {
|
|
130
|
+
const rawresult = handler(request.params ?? {});
|
|
131
|
+
const result = rawresult === undefined ? undefined : rawresult;
|
|
132
|
+
return {
|
|
133
|
+
status: 200,
|
|
134
|
+
result,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
return {
|
|
139
|
+
status: 202,
|
|
140
|
+
// TODO: Would be good to have an error type that we can throw that fills these fields more specifically. (But for now it doesn't matter since this is just communicated back the the CLI and not to the user.)
|
|
141
|
+
error: {
|
|
142
|
+
debugDescription: `${error}`,
|
|
143
|
+
userMessage: "Handler failed to perform request.",
|
|
144
|
+
underlyingError: error,
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/* Perform remote procedures */
|
|
150
|
+
async initialize(args) {
|
|
151
|
+
const target = args.target;
|
|
152
|
+
finalizationRegistry.register(args.lifecycle, async () => {
|
|
153
|
+
await this.release(target);
|
|
154
|
+
});
|
|
155
|
+
await this.sendRequest({
|
|
156
|
+
target: args.target,
|
|
157
|
+
type: args.type,
|
|
158
|
+
params: args.params,
|
|
159
|
+
procedure: "init",
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
async perform(body) {
|
|
163
|
+
return await this.sendRequest({
|
|
164
|
+
...body,
|
|
165
|
+
procedure: "perform",
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
async release(target) {
|
|
169
|
+
await this.sendRequest({
|
|
170
|
+
procedure: "release",
|
|
171
|
+
target,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
/* Register locally available targets/actions */
|
|
175
|
+
registerClosure(options) {
|
|
176
|
+
const target = `target_${options.prefix}_${crypto.randomUUID()}`;
|
|
177
|
+
this.closureTargets.set(target, options.handler);
|
|
178
|
+
finalizationRegistry.register(options.lifecycle, () => {
|
|
179
|
+
this.closureTargets.delete(target);
|
|
180
|
+
});
|
|
181
|
+
return target;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
class IpcRecordKit {
|
|
186
|
+
logMessages = false;
|
|
187
|
+
childProcess;
|
|
188
|
+
nsrpc;
|
|
189
|
+
constructor() {
|
|
190
|
+
this.nsrpc = new NSRPC((message) => this.write(message));
|
|
191
|
+
}
|
|
192
|
+
async initialize(recordKitRpcPath, logMessages = false) {
|
|
193
|
+
if (this.childProcess !== undefined) {
|
|
194
|
+
throw new Error('RecordKit RPC: Already initialized.');
|
|
195
|
+
}
|
|
196
|
+
this.logMessages = logMessages;
|
|
197
|
+
this.childProcess = await new Promise((resolve, reject) => {
|
|
198
|
+
const childProcess = node_child_process.spawn(recordKitRpcPath);
|
|
199
|
+
childProcess.on('spawn', () => { resolve(childProcess); });
|
|
200
|
+
childProcess.on('error', (error) => { reject(error); });
|
|
201
|
+
});
|
|
202
|
+
const { stdout } = this.childProcess;
|
|
203
|
+
if (!stdout) {
|
|
204
|
+
throw new Error('RecordKit RPC: No stdout stream on child process.');
|
|
205
|
+
}
|
|
206
|
+
readline__namespace.createInterface({ input: stdout }).on('line', (line) => {
|
|
207
|
+
if (logMessages) {
|
|
208
|
+
console.log("< ", line.trimEnd());
|
|
209
|
+
}
|
|
210
|
+
this.nsrpc.receive(line);
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
write(message) {
|
|
214
|
+
const stdin = this.childProcess?.stdin;
|
|
215
|
+
if (!stdin) {
|
|
216
|
+
throw new Error('RecordKit RPC: Missing stdin stream.');
|
|
217
|
+
}
|
|
218
|
+
if (this.logMessages) {
|
|
219
|
+
console.log("> ", message);
|
|
220
|
+
}
|
|
221
|
+
stdin.write(message + "\n");
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
class Recorder extends stream.EventEmitter {
|
|
226
|
+
rpc;
|
|
227
|
+
target;
|
|
228
|
+
static async newInstance(rpc, schema) {
|
|
229
|
+
const target = 'Recorder_' + crypto.randomUUID();
|
|
230
|
+
const object = new Recorder(rpc, target);
|
|
231
|
+
schema.items.forEach(item => {
|
|
232
|
+
if (item.type == 'webcam') {
|
|
233
|
+
if (typeof item.camera != 'string') {
|
|
234
|
+
item.camera = item.camera.id;
|
|
235
|
+
}
|
|
236
|
+
if (typeof item.microphone != 'string') {
|
|
237
|
+
item.microphone = item.microphone.id;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (item.type == 'windowBasedCrop') {
|
|
241
|
+
if (typeof item.window != 'number') {
|
|
242
|
+
item.window = item.window.id;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
const weakRefObject = new WeakRef(object);
|
|
247
|
+
const onAbortInstance = rpc.registerClosure({
|
|
248
|
+
handler: (params) => { weakRefObject.deref()?.emit('abort', params.reason); },
|
|
249
|
+
prefix: 'Recorder.onAbort',
|
|
250
|
+
lifecycle: object
|
|
251
|
+
});
|
|
252
|
+
await rpc.initialize({
|
|
253
|
+
target,
|
|
254
|
+
type: 'Recorder',
|
|
255
|
+
params: { schema, onAbortInstance },
|
|
256
|
+
lifecycle: object
|
|
257
|
+
});
|
|
258
|
+
return object;
|
|
259
|
+
}
|
|
260
|
+
constructor(rpc, target) {
|
|
261
|
+
super();
|
|
262
|
+
this.rpc = rpc;
|
|
263
|
+
this.target = target;
|
|
264
|
+
}
|
|
265
|
+
async prepare() {
|
|
266
|
+
await this.rpc.perform({ target: this.target, action: 'prepare' });
|
|
267
|
+
}
|
|
268
|
+
async start() {
|
|
269
|
+
await this.rpc.perform({ target: this.target, action: 'start' });
|
|
270
|
+
}
|
|
271
|
+
async stop() {
|
|
272
|
+
return await this.rpc.perform({ target: this.target, action: 'stop' });
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
class RecordKit {
|
|
277
|
+
ipcRecordKit = new IpcRecordKit();
|
|
278
|
+
async initialize(args) {
|
|
279
|
+
let rpcBinaryPath = args.rpcBinaryPath;
|
|
280
|
+
if (!args.fallbackToNodeModules) {
|
|
281
|
+
if (!node_fs.existsSync(rpcBinaryPath)) {
|
|
282
|
+
console.log('Falling back to RPC binary from node_modules, no file at given RPC binary path.');
|
|
283
|
+
rpcBinaryPath = rpcBinaryPath.replace('node_modules/electron/dist/Electron.app/Contents/Resources', 'node_modules/@nonstrict/recordkit/bin');
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return this.ipcRecordKit.initialize(rpcBinaryPath, args.logRpcMessages);
|
|
287
|
+
}
|
|
288
|
+
async getWindows() {
|
|
289
|
+
return await this.ipcRecordKit.nsrpc.perform({ type: 'Recorder', action: 'getWindows' });
|
|
290
|
+
}
|
|
291
|
+
async getCameras() {
|
|
292
|
+
return await this.ipcRecordKit.nsrpc.perform({ type: 'Recorder', action: 'getCameras' });
|
|
293
|
+
}
|
|
294
|
+
async getMicrophones() {
|
|
295
|
+
return await this.ipcRecordKit.nsrpc.perform({ type: 'Recorder', action: 'getMicrophones' });
|
|
296
|
+
}
|
|
297
|
+
async getCameraAuthorizationStatus() {
|
|
298
|
+
return await this.ipcRecordKit.nsrpc.perform({ type: 'AuthorizationStatus', action: 'getCameraAuthorizationStatus' });
|
|
299
|
+
}
|
|
300
|
+
async getMicrophoneAuthorizationStatus() {
|
|
301
|
+
return await this.ipcRecordKit.nsrpc.perform({ type: 'AuthorizationStatus', action: 'getMicrophoneAuthorizationStatus' });
|
|
302
|
+
}
|
|
303
|
+
async getScreenRecordingAccess() {
|
|
304
|
+
return await this.ipcRecordKit.nsrpc.perform({ type: 'AuthorizationStatus', action: 'getScreenRecordingAccess' });
|
|
305
|
+
}
|
|
306
|
+
async requestCameraAccess() {
|
|
307
|
+
return await this.ipcRecordKit.nsrpc.perform({ type: 'AuthorizationStatus', action: 'requestCameraAccess' });
|
|
308
|
+
}
|
|
309
|
+
async requestMicrophoneAccess() {
|
|
310
|
+
return await this.ipcRecordKit.nsrpc.perform({ type: 'AuthorizationStatus', action: 'requestMicrophoneAccess' });
|
|
311
|
+
}
|
|
312
|
+
async requestScreenRecordingAccess() {
|
|
313
|
+
return await this.ipcRecordKit.nsrpc.perform({ type: 'AuthorizationStatus', action: 'requestScreenRecordingAccess' });
|
|
314
|
+
}
|
|
315
|
+
async createRecorder(schema) {
|
|
316
|
+
return Recorder.newInstance(this.ipcRecordKit.nsrpc, schema);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
let recordkit = new RecordKit();
|
|
320
|
+
|
|
321
|
+
exports.recordkit = recordkit;
|
|
322
|
+
//# sourceMappingURL=index.cjs.map
|