hypeframe 0.1.0 → 0.2.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/bin/hypeframe.js CHANGED
@@ -1,135 +1,9 @@
1
1
  #!/usr/bin/env node
2
- // hypeframe: mesin di perangkat untuk HypeFrame Web. Render video dan agen AI berjalan di perangkat ini;
3
- // tampilannya di web. Pakai:
4
- // npx hypeframe [--gateway URL] [--web URL] [--nama NAMA] [--tanpa-browser] [--gpu]
5
- // --gpu: render memakai GPU perangkat (lebih cepat); bawaan SwiftShader seperti server render, hasilnya sama
6
- // npx hypeframe logout lepaskan perangkat ini dari akun (token lokal dihapus)
7
- import { spawn } from 'node:child_process';
8
- import crypto from 'node:crypto';
9
- import os from 'node:os';
10
- import path from 'node:path';
11
- import ffmpeg from 'ffmpeg-static';
12
- import { bacaAkun, folderData, hapusAkun, kunciTunggal, namaOs, simpanAkun, VERSI } from '../src/konfig.js';
13
- import { periksaChrome, siapkanChrome } from '../src/render/chrome.js';
14
- import { buatHalaman } from '../src/render/halaman.js';
15
- import { buatKerja } from '../src/render/kerja.js';
16
- import { buatLayananRender } from '../src/render/layanan.js';
17
- import { pasangkan, samarkanEmail } from '../src/pasang.js';
18
- import { buatPenangan } from '../src/penangan.js';
19
- import { Sambungan } from '../src/sambungan.js';
20
-
21
- const arg = process.argv.slice(2);
22
- const opsi = (nama, bawaan) => {
23
- const i = arg.indexOf(`--${nama}`);
24
- return i >= 0 && arg[i + 1] ? arg[i + 1] : bawaan;
25
- };
26
- const GATEWAY = opsi('gateway', process.env.HYPEFRAME_GATEWAY_URL || 'https://api.sairipedia.com').replace(/\/+$/, '');
27
- const NAMA = opsi('nama', os.hostname()).slice(0, 40);
28
- // alamat HypeFrame Web: halaman render diambil dari sini, dan hanya origin ini yang boleh memakai layanan render lokal
29
- const WEB = opsi('web', process.env.HYPEFRAME_WEB_URL || 'https://hype-frame.com').replace(/\/+$/, '');
30
- const cetak = (s) => console.log(s);
31
-
32
- function bukaBrowser(url) {
33
- // --tanpa-browser: untuk server tanpa layar dan uji otomatis (tautan tetap dicetak). Hanya tautan persetujuan yang
34
- // disusun sendiri (origin web + kode sah) yang dibuka, dan tanpa shell: Windows memakai explorer.exe, bukan cmd.
35
- if (arg.includes('--tanpa-browser') || !/^https?:\/\/[A-Za-z0-9.-]+(:\d+)?\/sambung\?kode=[A-HJ-NP-Z2-9]{4}-[A-HJ-NP-Z2-9]{4}$/.test(url)) return;
36
- const [cmd, args] = process.platform === 'win32' ? ['explorer.exe', [url]] : [process.platform === 'darwin' ? 'open' : 'xdg-open', [url]];
37
- const p = spawn(cmd, args, { stdio: 'ignore', detached: true });
38
- p.on('error', () => undefined);
39
- p.unref();
40
- }
41
-
42
- async function utama() {
43
- if (arg[0] === 'logout' || arg[0] === 'keluar') {
44
- hapusAkun();
45
- return cetak('Perangkat ini sudah dilepas dari akun. Jalankan lagi npx hypeframe untuk menyambungkan ulang.');
46
- }
47
- try {
48
- kunciTunggal();
49
- } catch (e) {
50
- if (e.code === 'SUDAH_JALAN') {
51
- console.error(e.message);
52
- process.exit(1);
53
- }
54
- throw e;
55
- }
56
- cetak(`HypeFrame mesin ${VERSI} (${namaOs()}, ${NAMA})`);
57
- let akun = bacaAkun();
58
- if (!akun || akun.gateway !== GATEWAY) {
59
- const a = await pasangkan({ gateway: GATEWAY, web: WEB, nama: NAMA, os: namaOs(), versi: VERSI, cetak, bukaBrowser });
60
- akun = { ...a, gateway: GATEWAY };
61
- simpanAkun(akun);
62
- }
63
- cetak(`Tersambung ke akun ${samarkanEmail(akun.email)}`);
64
-
65
- // layanan render lokal (127.0.0.1) dinyalakan dulu supaya portnya ikut di halo; Chrome disiapkan di latar
66
- const kemampuan = { render: false, chrome: null, transparan: false };
67
- const kunci = crypto.randomBytes(32).toString('base64url');
68
- const cache = path.join(folderData(), 'cache');
69
- const halaman = buatHalaman({ web: WEB, folderCache: cache });
70
- let kerja = null;
71
- const layanan = await buatLayananRender({
72
- folder: path.join(folderData(), 'kerja', 'render'),
73
- kunci,
74
- asal: new URL(WEB).origin,
75
- renderer: (t, o) => (kerja ? kerja.renderer(t, o) : Promise.reject(new Error('Render di mesin ini belum siap.'))),
76
- tambahanRute: (req, res, url) => (kerja ? kerja.rute(req, res, url) : halaman.rute(req, res, url)),
77
- });
78
- const penangan = buatPenangan({
79
- status: () => ({ versi: VERSI, os: namaOs(), kemampuan }),
80
- kunci: () => {
81
- if (!kemampuan.render) throw new Error('Render di mesin ini belum siap.');
82
- return { port: layanan.port, kunci, versi: VERSI };
83
- },
84
- });
85
- const s = new Sambungan({ gateway: GATEWAY, token: akun.token, info: { versi: VERSI, os: namaOs(), nama: NAMA, kemampuan, portLokal: layanan.port }, penangan });
86
- let pernah = false;
87
- s.on('tersambung', () => {
88
- cetak(pernah ? 'Tersambung lagi.' : 'Mesin siap. Biarkan jendela ini terbuka selama memakai HypeFrame Web.');
89
- pernah = true;
90
- });
91
- s.on('terputus', () => cetak('Sambungan ke HypeFrame putus, mencoba lagi...'));
92
- s.on('dicabut', () => {
93
- cetak('Perangkat ini sudah diputus dari akun. Jalankan lagi untuk menyambungkan ulang.');
94
- process.exit(0);
95
- });
96
- s.on('berhenti', (alasan) => {
97
- console.error(alasan === 'protokol' ? 'Versi mesin ini terlalu lama. Jalankan: npx hypeframe@latest' : 'Mesin ini sudah tersambung dari jendela atau komputer lain dengan akun yang sama, jadi yang ini berhenti.');
98
- process.exit(1);
99
- });
100
- s.mulai();
101
-
102
- // siapkan render: Chrome (yang terpasang, atau unduh sekali), halaman render dari web, ffmpeg dari paket npm
103
- let persenTerakhir = -10;
104
- const laporChrome = (persen, teks) => {
105
- if (persen - persenTerakhir >= 10 || persen === 0) (persenTerakhir = persen), cetak(`${teks} ${persen}%`);
106
- };
107
- async function siapkanRender() {
108
- try {
109
- if (!ffmpeg) throw new Error('ffmpeg tidak tersedia untuk sistem ini');
110
- const gpu = arg.includes('--gpu');
111
- const chrome = await siapkanChrome(cache, laporChrome);
112
- const info = await periksaChrome(chrome, { gpu });
113
- if (!info.avc) throw new Error(`Chrome ${info.versi} tidak bisa membuat video H.264`);
114
- await halaman.siapkan();
115
- kerja = buatKerja({ chrome, ffmpeg, halaman, gpu, transparan: info.transparan });
116
- kerja.aturPort(layanan.port);
117
- Object.assign(kemampuan, { render: true, chrome: info.versi, transparan: info.transparan });
118
- s.aturInfo({ kemampuan });
119
- s.kabar('status', { kemampuan });
120
- cetak(`Render siap (Chrome ${info.versi}${info.transparan ? '' : '; klip transparan dibuat di tempat lain'}).`);
121
- } catch (e) {
122
- cetak(`Render di mesin ini belum bisa: ${e.message}. Mesin tetap tersambung; dicoba lagi 10 menit lagi.`);
123
- setTimeout(siapkanRender, 10 * 60_000).unref();
124
- }
125
- }
126
- void siapkanRender();
127
- // halaman render versi baru di web diambil tiap 6 jam
128
- setInterval(() => kerja && void halaman.siapkan().catch(() => undefined), 6 * 3600_000).unref();
129
- }
130
-
131
- process.on('SIGINT', () => process.exit(0));
132
- utama().catch((e) => {
133
- console.error(e.message || String(e));
2
+ // Entry point installed as `hypeframe`. Checks the Node version before loading the bundle so old Node gets a clear
3
+ // message instead of a syntax error.
4
+ const [major, minor] = process.versions.node.split('.').map(Number);
5
+ if (major < 20 || (major === 20 && minor < 3)) {
6
+ console.error(`hypeframe needs Node.js 20.3 or newer (this is ${process.versions.node}). https://nodejs.org`);
134
7
  process.exit(1);
135
- });
8
+ }
9
+ await import('../dist/index.js');