Piik now has one public presentation and a coordinated App/Server release path. This phase unifies the room UI, rewrites the bilingual README and guides, adds a static website with an inline product film, and prepares matching GitHub/Gitee packages and update links. The film uses the current homepage and shared product controls on one seekable timeline. Runtime fixes preserve presentation when the App opens a room, normalize Site origins, and keep capture and media-recovery status in the television indicator. New visits use Chinese for a Chinese system language and English otherwise; explicit language and visual-mode choices remain available. An optional site passphrase controls site entry, while room authorization remains enforced. GitHub is the release authority. Gitee mirrors verified packages and provides update metadata when GitHub is unavailable. Reviewed PR release notes become the GitHub Release description. The separate public demo uses P2P only, with HTTPS and STUN verified. Validation: 756 Web tests, TypeScript and production build; Go core tests, formatting, vet and available target builds; bounded Windows capture and App/Site interoperability; browser film checks, audible playback and narrow layouts; anonymous Gitee Windows-package download, checksum and launcher/update-link checks. Public demo acceptance covers authenticated WebSocket signaling, synthetic P2P video and room cleanup on one network. macOS/Linux physical capture and the wider device/network/endurance matrix remain explicitly deferred. Publication builds every package from the merged source SHA. The repository is public, main protection is active, and Pages is configured for piik.tv. CI/publisher and Pages deployment records own publication results. ## Release notes ### 中文 Piik 是免费开源的屏幕共享工具。开个房间,发出邀请,最多 20 位朋友就能用浏览器加入观看。 - 使用浏览器或 Piik App 分享游戏、窗口和整个屏幕。 - 优先建立直连;自托管站点可开启媒体转发作为备用线路。 - Piik App 支持本地房间、临时公网邀请和已有站点。 - Piik Server 内置网页界面、房间管理和连接服务,方便自行部署。 - 提供中英文界面与使用指南,以及 GitHub、Gitee 两条下载线路。 [官网](https://piik.tv) · [在线体验](https://demo.piik.tv) · [使用指南](https://github.com/TNTcraftHIM/Piik/blob/main/docs/guide/getting-started.zh-CN.md) · [自行部署](https://github.com/TNTcraftHIM/Piik/blob/main/docs/operations/self-hosting.zh-CN.md) · [Gitee 下载](https://gitee.com/TNTcraftHIM/Piik/releases) Windows App 和桌面浏览器是本次主要验证的平台。macOS 和 Linux 尚未经过实机测试,欢迎有设备的朋友测试并反馈。演示站和 App 公网邀请使用 P2P,受限网络下可能无法连接;自托管站点可开启媒体转发。 ### English Piik is free, open-source screen sharing for you and up to 20 viewers. Start a room, send an invitation, and your friends can join in a browser. - Share games, windows or a whole screen from your browser or Piik App. - Direct connections come first, with optional media forwarding on self-hosted sites. - Piik App supports local rooms, temporary public invitations and existing sites. - Piik Server includes the web interface, rooms and connection services for self-hosting. - English and Chinese interfaces and guides are available, with GitHub and Gitee downloads. [Website](https://piik.tv) · [Online demo](https://demo.piik.tv) · [User guide](https://github.com/TNTcraftHIM/Piik/blob/main/docs/guide/getting-started.md) · [Self-hosting](https://github.com/TNTcraftHIM/Piik/blob/main/docs/operations/self-hosting.md) · [Gitee downloads](https://gitee.com/TNTcraftHIM/Piik/releases) Windows App and desktop browsers are the primary validated paths. macOS and Linux have not yet been tested on physical devices; testing and feedback are welcome. The demo and App public invitations rely on P2P and may not connect on restrictive networks. Self-hosted sites can enable media forwarding.
302 lines
10 KiB
JavaScript
302 lines
10 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
import { spawnSync } from "node:child_process";
|
|
import { createHash } from "node:crypto";
|
|
import {
|
|
chmodSync,
|
|
closeSync,
|
|
copyFileSync,
|
|
cpSync,
|
|
existsSync,
|
|
lstatSync,
|
|
mkdirSync,
|
|
openSync,
|
|
readSync,
|
|
readFileSync,
|
|
realpathSync,
|
|
rmSync,
|
|
writeFileSync,
|
|
} from "node:fs";
|
|
import { dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
import { clientPackageTarget, clientGoEnvironment, CLOUDFLARED_VERSION } from "./client-package-targets.mjs";
|
|
import { writeClientPlatformAssets } from "./client-icons.mjs";
|
|
import { writeClientLicenseNotices } from "./package-licenses.mjs";
|
|
import { tarExecutable } from "./archive-tool.mjs";
|
|
import { resetBuildWorkspace } from "./build-workspace.mjs";
|
|
import { isReleaseVersion } from "./release-version.mjs";
|
|
|
|
function fail(message) {
|
|
throw new Error(message);
|
|
}
|
|
|
|
function run(command, args, cwd, environment = process.env) {
|
|
const result = spawnSync(command, args, {
|
|
cwd,
|
|
env: environment,
|
|
encoding: "utf8",
|
|
stdio: ["ignore", "pipe", "pipe"],
|
|
});
|
|
if (result.error) throw result.error;
|
|
if (result.status !== 0) {
|
|
fail(`${command} failed: ${(result.stderr || result.stdout).trim()}`);
|
|
}
|
|
return result.stdout.trim();
|
|
}
|
|
|
|
function runNpm(args, cwd) {
|
|
if (process.platform === "win32") {
|
|
run(process.env.ComSpec || "cmd.exe", [
|
|
"/d", "/s", "/c", `npm ${args.join(" ")}`,
|
|
], cwd);
|
|
return;
|
|
}
|
|
run("npm", args, cwd);
|
|
}
|
|
|
|
function sha256(path) {
|
|
return createHash("sha256").update(readFileSync(path)).digest("hex");
|
|
}
|
|
|
|
function bytesAt(path, length, position = 0) {
|
|
const descriptor = openSync(path, "r");
|
|
try {
|
|
const bytes = Buffer.alloc(length);
|
|
return bytes.subarray(0, readSync(descriptor, bytes, 0, length, position));
|
|
} finally {
|
|
closeSync(descriptor);
|
|
}
|
|
}
|
|
|
|
function executableMatchesTarget(path, target) {
|
|
const header = bytesAt(path, 64);
|
|
if (target.goos === "windows") {
|
|
if (header.length < 64 || header[0] !== 0x4d || header[1] !== 0x5a) {
|
|
return false;
|
|
}
|
|
const pe = bytesAt(path, 6, header.readUInt32LE(0x3c));
|
|
return pe.length === 6 && pe.subarray(0, 4).equals(Buffer.from("PE\0\0")) &&
|
|
pe.readUInt16LE(4) === 0x8664;
|
|
}
|
|
if (target.goos === "linux") {
|
|
return header.length >= 20 && header.subarray(0, 4).equals(
|
|
Buffer.from([0x7f, 0x45, 0x4c, 0x46]),
|
|
) && header[4] === 2 && header[5] === 1 && header.readUInt16LE(18) === 0x3e;
|
|
}
|
|
return header.length >= 8 && header.subarray(0, 4).equals(
|
|
Buffer.from([0xcf, 0xfa, 0xed, 0xfe]),
|
|
) && header.readUInt32LE(4) === 0x0100000c;
|
|
}
|
|
|
|
function assertTargetExecutable(path, target, label) {
|
|
if (!lstatSync(path).isFile() || !executableMatchesTarget(path, target)) {
|
|
fail(`${label} does not match Client package target ${target.id}`);
|
|
}
|
|
}
|
|
|
|
function plainName(value, label) {
|
|
if (
|
|
typeof value !== "string" ||
|
|
!/^[A-Za-z0-9._-]+$/.test(value) ||
|
|
value === "." ||
|
|
value === ".."
|
|
) {
|
|
fail(`Release ${label} is invalid`);
|
|
}
|
|
return value;
|
|
}
|
|
|
|
function readDescriptor(path) {
|
|
let value;
|
|
try {
|
|
value = JSON.parse(readFileSync(path, "utf8"));
|
|
} catch {
|
|
fail("Application release descriptor is invalid");
|
|
}
|
|
if (
|
|
value?.schema !== 2 ||
|
|
(value.version !== "development" && !isReleaseVersion(value.version)) ||
|
|
typeof value.revision !== "string" ||
|
|
!/^[0-9a-f]{40}$/.test(value.revision) ||
|
|
typeof value.artifactSha256 !== "string" ||
|
|
!/^[0-9a-f]{64}$/.test(value.artifactSha256)
|
|
) {
|
|
fail("Application release descriptor is invalid");
|
|
}
|
|
return {
|
|
version: value.version,
|
|
revision: value.revision,
|
|
artifact: plainName(value.artifact, "artifact"),
|
|
artifactSha256: value.artifactSha256,
|
|
};
|
|
}
|
|
|
|
function assertOutputDirectory(repositoryRoot, outputRoot, target) {
|
|
const path = relative(repositoryRoot, outputRoot);
|
|
const candidateOutput = join(repositoryRoot, "build", "client-package", target.id,
|
|
"candidate", `piik-app-${target.id}`);
|
|
if (outputRoot !== candidateOutput &&
|
|
(path === "" || (path.split(/[\\/]/)[0] !== ".." && !isAbsolute(path)))) {
|
|
fail("Client output must be outside the repository or its exact candidate workspace");
|
|
}
|
|
if (outputRoot === candidateOutput) {
|
|
for (let parent = dirname(outputRoot); parent !== repositoryRoot; parent = dirname(parent)) {
|
|
const metadata = lstatSync(parent, { throwIfNoEntry: false });
|
|
if (metadata && (!metadata.isDirectory() || metadata.isSymbolicLink() ||
|
|
realpathSync(parent) !== parent)) fail("Client candidate output must not contain links");
|
|
}
|
|
}
|
|
if (existsSync(outputRoot)) {
|
|
fail("Client output directory must not already exist");
|
|
}
|
|
}
|
|
|
|
const positional = process.argv.slice(2, 4);
|
|
const options = process.argv.slice(4);
|
|
if (positional.length !== 2 || options.length % 2 !== 0) {
|
|
fail(
|
|
"Usage: node scripts/assemble-client.mjs <app-release.json> <new-output-directory> --target <windows-amd64|linux-amd64|darwin-arm64> [--capture <executable>] [--tunnel <executable>]",
|
|
);
|
|
}
|
|
|
|
let targetArgument = null;
|
|
let captureArgument = null;
|
|
let tunnelArgument = null;
|
|
for (let index = 0; index < options.length; index += 2) {
|
|
const name = options[index];
|
|
const value = options[index + 1];
|
|
if (
|
|
!value ||
|
|
(name !== "--target" && name !== "--capture" && name !== "--tunnel")
|
|
) {
|
|
fail("Client package option is invalid");
|
|
}
|
|
if (name === "--target" && targetArgument === null) {
|
|
targetArgument = value;
|
|
} else if (name === "--capture" && captureArgument === null) {
|
|
captureArgument = value;
|
|
} else if (name === "--tunnel" && tunnelArgument === null) {
|
|
tunnelArgument = value;
|
|
} else {
|
|
fail("Client package option is duplicated");
|
|
}
|
|
}
|
|
const target = clientPackageTarget(targetArgument);
|
|
if (!target) fail("Client package target is invalid");
|
|
if (target.cgo && process.platform !== target.nodePlatform) {
|
|
fail(`Client target ${target.id} requires a native macOS runner with its SDK and cgo`);
|
|
}
|
|
|
|
const repositoryRoot = realpathSync(resolve(dirname(fileURLToPath(import.meta.url)), ".."));
|
|
const descriptorPath = realpathSync(resolve(positional[0]));
|
|
const outputRoot = resolve(process.cwd(), positional[1]);
|
|
const capturePath = captureArgument ? realpathSync(resolve(captureArgument)) : null;
|
|
const tunnelPath = tunnelArgument ? realpathSync(resolve(tunnelArgument)) : null;
|
|
assertOutputDirectory(repositoryRoot, outputRoot, target);
|
|
if (capturePath && !target.captureName) {
|
|
fail("Capture runtime is invalid for the Client package target");
|
|
}
|
|
if (capturePath) assertTargetExecutable(capturePath, target, "Capture runtime");
|
|
if (tunnelPath) assertTargetExecutable(tunnelPath, target, "Public tunnel runtime");
|
|
|
|
const descriptor = readDescriptor(descriptorPath);
|
|
const version = descriptor.version;
|
|
process.env.VITE_PIIK_VERSION = version;
|
|
process.env.VITE_PIIK_REVISION = descriptor.revision;
|
|
const revision = run("git", ["rev-parse", "HEAD"], repositoryRoot).toLowerCase();
|
|
if (revision !== descriptor.revision) {
|
|
fail("Client source and application release revisions do not match");
|
|
}
|
|
if (run("git", ["status", "--porcelain"], repositoryRoot) !== "") {
|
|
fail("Client assembly requires a clean Git checkout");
|
|
}
|
|
const artifactPath = join(dirname(descriptorPath), descriptor.artifact);
|
|
if (!existsSync(artifactPath) || sha256(artifactPath) !== descriptor.artifactSha256) {
|
|
fail("Application release artifact does not match its descriptor");
|
|
}
|
|
|
|
const temporaryRoot = resetBuildWorkspace(repositoryRoot, "client-package", target.id, "assembly");
|
|
const packageRoot = join(temporaryRoot, "package");
|
|
const releaseRoot = join(temporaryRoot, "release");
|
|
try {
|
|
// The application release is consumed for its provenance only: the Client
|
|
// embeds the Web assets, so the revision, clean-tree and digest assertions
|
|
// above plus this REVISION check tie the binary to that immutable release.
|
|
mkdirSync(releaseRoot, { recursive: true });
|
|
run(tarExecutable(), ["-xzf", artifactPath, "-C", releaseRoot], repositoryRoot);
|
|
if (readFileSync(join(releaseRoot, "REVISION"), "ascii") !== `${revision}\n`) {
|
|
fail("Extracted application revision does not match the Client");
|
|
}
|
|
// Build the Web assets the Go binary embeds. The checkout is clean and at the
|
|
// release revision, so this reproduces that release's client.
|
|
runNpm(["run", "build:client"], repositoryRoot);
|
|
mkdirSync(packageRoot, { recursive: true });
|
|
|
|
let packagedCapture = null;
|
|
if (capturePath) {
|
|
const nativeRoot = join(packageRoot, "runtime", "native");
|
|
mkdirSync(nativeRoot, { recursive: true });
|
|
packagedCapture = join(nativeRoot, target.captureName);
|
|
copyFileSync(capturePath, packagedCapture);
|
|
chmodSync(packagedCapture, 0o755);
|
|
}
|
|
|
|
let packagedTunnel = null;
|
|
if (tunnelPath) {
|
|
const tunnelRoot = join(packageRoot, "runtime", "tunnel");
|
|
mkdirSync(tunnelRoot, { recursive: true });
|
|
const tunnelName = target.tunnelName;
|
|
packagedTunnel = join(tunnelRoot, tunnelName);
|
|
copyFileSync(tunnelPath, packagedTunnel);
|
|
chmodSync(packagedTunnel, 0o755);
|
|
}
|
|
|
|
const clientName = target.clientName;
|
|
const clientPath = join(packageRoot, clientName);
|
|
const goCommand = process.env.PIIK_GO?.trim() || "go";
|
|
run(goCommand, [
|
|
"build",
|
|
"-trimpath",
|
|
"-ldflags",
|
|
`-s -w -X github.com/TNTcraftHIM/Piik/internal/app.BuildRevision=${revision} -X github.com/TNTcraftHIM/Piik/internal/app.BuildVersion=${version}`,
|
|
"-o",
|
|
clientPath,
|
|
"./cmd/piik-app",
|
|
], repositoryRoot, clientGoEnvironment(target));
|
|
chmodSync(clientPath, 0o755);
|
|
assertTargetExecutable(clientPath, target, "Client executable");
|
|
writeClientLicenseNotices(repositoryRoot, packageRoot, goCommand, target,
|
|
packagedTunnel ? CLOUDFLARED_VERSION : null);
|
|
const platformAssets = writeClientPlatformAssets({
|
|
packageRoot,
|
|
target,
|
|
version,
|
|
revision,
|
|
iconPath: join(repositoryRoot, "cmd", "piik-app", "piik.ico"),
|
|
});
|
|
writeFileSync(join(packageRoot, "REVISION"), `${revision}\n`, "ascii");
|
|
|
|
cpSync(packageRoot, outputRoot, {
|
|
recursive: true,
|
|
errorOnExist: true,
|
|
force: false,
|
|
});
|
|
process.stdout.write(`${JSON.stringify({
|
|
root: outputRoot,
|
|
version,
|
|
revision,
|
|
target: target.id,
|
|
platform: target.goos,
|
|
arch: target.goarch,
|
|
client: clientName,
|
|
nativeCapture: packagedCapture ? `runtime/native/${target.captureName}` : null,
|
|
publicTunnel: packagedTunnel
|
|
? `runtime/tunnel/${target.tunnelName}`
|
|
: null,
|
|
platformAssets,
|
|
})}\n`);
|
|
} finally {
|
|
rmSync(temporaryRoot, { recursive: true, force: true });
|
|
}
|