'use strict'; // Enrollment listener has concurrency zero and discards upstream logs. const fs = require('node:fs'), path = require('node:path'), {spawn} = require('node:child_process'); const root=process.env.PT_ROOT || 'C:\\pt-worker'; const cfg=JSON.parse(fs.readFileSync(path.join(root,'state','worker.json'),'utf8').replace(/^\uFEFF/,'')); const env={...process.env, PT_ROOT:root, APPDATA:path.join(root,'profile','Roaming'), LOCALAPPDATA:path.join(root,'profile','Local'), FFMPEG_PATH:path.join(root,'bin','ffmpeg-nvenc.exe'),FFPROBE_PATH:path.join(root,'bin','ffprobe.exe'), PT_STATE_DIR:path.join(root,'state'),PT_WORKER_CONFIG:path.join(root,'state','worker.json')}; const toml=fs.readFileSync(path.join(env.APPDATA,'peertube-runner-nodejs','Config','default','config.toml'),'utf8'); if(!/^concurrency\s*=\s*0\s*$/m.test(toml)) throw Error('Enrollment requires concurrency zero'); const child=spawn(cfg.node_binary,[path.join(root,'runner','node_modules','@peertube','peertube-runner','dist','peertube-runner.js'),'server','--enable-job','vod-web-video-transcoding','--enable-job','vod-hls-transcoding','--enable-job','vod-audio-merge-transcoding'],{env,detached:true,windowsHide:true,stdio:'ignore'}); fs.writeFileSync(path.join(root,'state','enroll-process.json'),JSON.stringify({pid:child.pid})); child.unref(); console.log(JSON.stringify({enrollment_listener_started:true,concurrency:0}));