UNPKG

@nonstrict/recordkit

Version:

Powerful screen recording for your Electron app on macOS.

256 lines 10.3 kB
import { IpcRecordKit } from "./IpcRecordKit.js"; import { Recorder } from "./Recorder.js"; import { EventEmitter } from "events"; import { existsSync } from "node:fs"; /** * Entry point for the RecordKit SDK, an instance is available as `recordkit` that can be imported from the module. Do not instantiate this class directly. * * @groupDescription Discovery * Discover the windows and devices that are available to record. * * @groupDescription Permissions * Check and request the apps permission to access the recording devices. * * @groupDescription Logging * Log what's going on to the console for easy debugging and troubleshooting. */ export class RecordKit extends EventEmitter { ipcRecordKit = new IpcRecordKit(); /** @ignore */ constructor() { super(); } /** * Initialize the RecordKit SDK. * * ⚠️ Must be called before calling any other RecordKit method. * * @param args */ async initialize(args) { let rpcBinaryPath = args.rpcBinaryPath; if (args.fallbackToNodeModules ?? true) { if (!existsSync(rpcBinaryPath)) { rpcBinaryPath = rpcBinaryPath.replace('node_modules/electron/dist/Electron.app/Contents/Resources', 'node_modules/@nonstrict/recordkit/bin'); console.error(`RecordKit: [RPC] !! Falling back to RPC binary from node_modules at ${rpcBinaryPath}`); } } await this.ipcRecordKit.initialize(rpcBinaryPath, args.logRpcMessages); const logHandlerInstance = this.ipcRecordKit.nsrpc.registerClosure({ handler: (params) => { console.log('RecordKit:', params.formattedMessage); this.emit('log', params); }, prefix: 'RecordKit.logHandler', lifecycle: this }); await this.ipcRecordKit.nsrpc.perform({ type: 'Logger', action: 'setLogHandler', params: { logHandlerInstance } }); if (args.logLevel) { await this.setLogLevel(args.logLevel); } } /** * Set the global log level. Defaults to `debug`. * * Messages with a lower level than this will be ignored and not passed to any log handlers. * * @group Logging */ async setLogLevel(logLevel) { await this.ipcRecordKit.nsrpc.perform({ type: 'Logger', action: 'setLogLevel', params: { logLevel } }); } /** * Overrides the global log level for a specific category. Defaults to the global log level. * * Messages in the given category with a lower level than this will be ignored and not passed to any log handlers. * * @group Logging */ async setCategoryLogLevel(params) { await this.ipcRecordKit.nsrpc.perform({ type: 'Logger', action: 'setLogLevel', params }); } /** * A list of Mac displays that can be used for screen recording. * * @group Discovery */ async getDisplays() { return await this.ipcRecordKit.nsrpc.perform({ type: 'Recorder', action: 'getDisplays' }); } /** * A list of macOS windows that can be used for screen recording. * * @group Discovery */ async getWindows() { return await this.ipcRecordKit.nsrpc.perform({ type: 'Recorder', action: 'getWindows' }); } /** * A list of cameras that are connected to the system. * * @param params.includeDeskView - Whether to include Desk View cameras in the results * @group Discovery */ async getCameras(params) { return await this.ipcRecordKit.nsrpc.perform({ type: 'Recorder', action: 'getCameras', params: { includeDeskView: params?.includeDeskView ?? false } }); } /** * A list of microphones that are connected to the system. * * @group Discovery */ async getMicrophones() { return await this.ipcRecordKit.nsrpc.perform({ type: 'Recorder', action: 'getMicrophones' }); } /** * A list of iOS devices that are connected to the system. * * @group Discovery */ async getAppleDevices() { return await this.ipcRecordKit.nsrpc.perform({ type: 'Recorder', action: 'getAppleDevices' }); } /** * A list of currently running applications that can be used for screen or audio recording. * * @group Discovery */ async getRunningApplications() { return await this.ipcRecordKit.nsrpc.perform({ type: 'Recorder', action: 'getRunningApplications' }); } /** * Indicates if camera can be used. * * Authorization status that indicates whether the user grants the app permission to capture video. * * @group Permissions */ async getCameraAuthorizationStatus() { return await this.ipcRecordKit.nsrpc.perform({ type: 'AuthorizationStatus', action: 'getCameraAuthorizationStatus' }); } /** * Indicates if microphone can be used. * * Authorization status that indicates whether the user grants the app permission to capture audio. * * @group Permissions */ async getMicrophoneAuthorizationStatus() { return await this.ipcRecordKit.nsrpc.perform({ type: 'AuthorizationStatus', action: 'getMicrophoneAuthorizationStatus' }); } /** * Indicates if screen can be recorded. * * @group Permissions */ async getScreenRecordingAccess() { return await this.ipcRecordKit.nsrpc.perform({ type: 'AuthorizationStatus', action: 'getScreenRecordingAccess' }); } /** * Indicates if system audio can be recorded. * * @group Permissions */ async getSystemAudioRecordingAccess() { return await this.ipcRecordKit.nsrpc.perform({ type: 'AuthorizationStatus', action: 'getSystemAudioRecordingAccess' }); } /** * Indicates if keystroke events of other apps can be recorded via Input Monitoring. * * @group Permissions */ async getInputMonitoringAccess() { return await this.ipcRecordKit.nsrpc.perform({ type: 'AuthorizationStatus', action: 'getInputMonitoringAccess' }); } /** * Indicates if other apps can be controlled via Accessibility. * * @group Permissions */ async getAccessibilityControlAccess() { return await this.ipcRecordKit.nsrpc.perform({ type: 'AuthorizationStatus', action: 'getAccessibilityControlAccess' }); } /** * Requests the user's permission to allow the app to capture the camera. * * Prompts the users if this is the first time requesting access, otherwise immediately returns. * * @returns Boolean value that indicates whether the user granted or denied access to your app. * @group Permissions */ async requestCameraAccess() { return await this.ipcRecordKit.nsrpc.perform({ type: 'AuthorizationStatus', action: 'requestCameraAccess' }); } /** * Requests the user's permission to allow the app to capture the microphone. * * Prompts the users if this is the first time requesting access, otherwise immediately returns. * * @returns Boolean value that indicates whether the user granted or denied access to your app. * @group Permissions */ async requestMicrophoneAccess() { return await this.ipcRecordKit.nsrpc.perform({ type: 'AuthorizationStatus', action: 'requestMicrophoneAccess' }); } /** * Requests the user's permission to allow the app to capture the screen. * * If this is the first time requesting access, this shows dialog that lets th users open System Settings. * In System Settings, the user can allow the app permission to do screen recording. * * Afterwards, the users needs to restart this app, for the permission to become active in the app. * * @group Permissions */ async requestScreenRecordingAccess() { return await this.ipcRecordKit.nsrpc.perform({ type: 'AuthorizationStatus', action: 'requestScreenRecordingAccess' }); } /** * Requests the user's permission to allow the app to capture system audio. * * If this is the first time requesting access, this shows dialog that lets th users open System Settings. * In System Settings, the user can allow the app permission to do screen recording. * * Afterwards, the users needs to restart this app, for the permission to become active in the app. * * @remarks Currently, system audio recording is currently implemented using ScreenCaptureKit, * which means the users needs to grant screen recording access. * * @group Permissions */ async requestSystemAudioRecordingAccess() { return await this.ipcRecordKit.nsrpc.perform({ type: 'AuthorizationStatus', action: 'requestSystemAudioRecordingAccess' }); } /** * Requests the users's permission to monitor keystrokes of other apps via Input Monitoring. * * If this is the first time requesting access, this shows dialog that lets th users open System Settings. * In System Settings, the user can allow the app permission to monitor other apps. * * Afterwards, the users needs to restart this app, for the permission to become active in the app. * * @group Permissions */ async requestInputMonitoringAccess() { return await this.ipcRecordKit.nsrpc.perform({ type: 'AuthorizationStatus', action: 'requestInputMonitoringAccess' }); } /** * Requests the users's permission to control other apps via Accessibility permissions. * * If this is the first time requesting access, this shows dialog that lets th users open System Settings. * In System Settings, the user can allow the app permission to control apps. * * Afterwards, the users needs to restart this app, for the permission to become active in the app. * * @group Permissions */ async requestAccessibilityControlAccess() { return await this.ipcRecordKit.nsrpc.perform({ type: 'AuthorizationStatus', action: 'requestAccessibilityControlAccess' }); } async createRecorder(schema) { return Recorder.newInstance(this.ipcRecordKit.nsrpc, schema); } } /** @ignore */ export let recordkit = new RecordKit(); //# sourceMappingURL=RecordKit.js.map