Files
AAA f92162b3bb feat: launch Piik with a unified interface and public website
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.
2026-09-12 22:09:12 +08:00

287 lines
9.6 KiB
Go

package main
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"log/slog"
"net/http"
"net/url"
"os"
"regexp"
"strings"
"time"
"golang.org/x/mod/semver"
)
// The Browser notice and operator checker read the same published release.
const defaultReleaseAPIURL = "https://api.github.com/repos/TNTcraftHIM/Piik/releases/latest"
const mirrorReleaseAPIURL = "https://gitee.com/api/v5/repos/TNTcraftHIM/Piik/releases"
// deploy/check-release.sh forwards these codes without installing anything.
const (
exitUpToDate = 0
exitUpdateAvailable = 10
exitUpdateUnavailable = 20
releaseTimeout = 5 * time.Second
releaseURLPrefix = "https://github.com/TNTcraftHIM/Piik/releases/tag/"
releaseAPIHost = "api.github.com"
mirrorReleasePrefix = "https://gitee.com/TNTcraftHIM/Piik/releases/tag/"
)
var fullRevisionPattern = regexp.MustCompile(`^[0-9a-f]{40}$`)
var mirrorSourcePattern = regexp.MustCompile(`(?m)^<!-- piik-source: ([0-9a-f]{40}) -->\r?$`)
const (
statusUpToDate = "up-to-date"
statusUpdateAvailable = "update-available"
statusDifferentBuild = "different-build"
statusOfficialRelease = "official-release"
statusUnavailable = "unavailable"
)
// Unknown identity fields are explicit nulls in the single printed JSON line.
type releaseResult struct {
Status string `json:"status"`
CurrentVersion *string `json:"currentVersion"`
LatestVersion *string `json:"latestVersion"`
CurrentRevision *string `json:"currentRevision"`
LatestRevision *string `json:"latestRevision"`
ReleaseURL *string `json:"releaseUrl"`
}
func checkDeployedRelease(ctx context.Context, apiURL string, out io.Writer) int {
mirrorURL := ""
if apiURL == defaultReleaseAPIURL {
mirrorURL = mirrorReleaseAPIURL
}
result := checkRelease(ctx, BuildVersion, BuildRevision, apiURL, os.Getenv("GITHUB_TOKEN"), mirrorURL)
encoder := json.NewEncoder(out)
encoder.SetEscapeHTML(false)
if err := encoder.Encode(result); err != nil {
return exitUpdateUnavailable
}
switch result.Status {
case statusUpdateAvailable, statusDifferentBuild, statusOfficialRelease:
return exitUpdateAvailable
case statusUpToDate:
return exitUpToDate
default:
return exitUpdateUnavailable
}
}
func checkRelease(ctx context.Context, currentVersion, currentRevision, apiURL, token, mirrorURL string) releaseResult {
result := unavailableResult(currentVersion, currentRevision)
comparableVersion := result.CurrentVersion != nil && semver.IsValid(*result.CurrentVersion)
if !comparableVersion && result.CurrentRevision == nil {
return result
}
version, revision, releaseURL, ok := fetchLatestRelease(ctx, apiURL, token, false)
if !ok && mirrorURL != "" {
version, revision, releaseURL, ok = fetchLatestRelease(ctx, mirrorURL, "", true)
}
if !ok {
return result
}
result.LatestVersion = &version
result.LatestRevision = revisionOrNull(revision)
result.ReleaseURL = &releaseURL
if comparableVersion {
result.Status = statusUpToDate
order := semver.Compare(version, *result.CurrentVersion)
if order > 0 {
result.Status = statusUpdateAvailable
} else if order == 0 && result.CurrentRevision != nil && result.LatestRevision != nil &&
*result.CurrentRevision != *result.LatestRevision {
result.Status = statusDifferentBuild
}
} else if result.CurrentRevision != nil && result.LatestRevision != nil {
result.Status = statusOfficialRelease
if *result.CurrentRevision == *result.LatestRevision {
result.Status = statusUpToDate
}
}
return result
}
// Routine startup only announces actionable release choices. An unavailable
// provider is not a server failure, and never changes the running installation.
func logReleaseNotice(logger *slog.Logger, result releaseResult) {
var message string
switch result.Status {
case statusUpdateAvailable:
message = "A newer Piik release is available"
case statusDifferentBuild:
message = "This Piik build differs from the official release"
case statusOfficialRelease:
message = "An official Piik release is available"
default:
return
}
current := "development"
if result.CurrentVersion != nil {
current = *result.CurrentVersion
}
logger.Info(message, "event", "release-check", "status", result.Status,
"currentVersion", current, "latestVersion", *result.LatestVersion, "releaseUrl", *result.ReleaseURL)
}
func fetchLatestRelease(ctx context.Context, apiURL, token string, mirror bool) (version, revision, releaseURL string, ok bool) {
endpoint, err := url.Parse(apiURL)
if err != nil || (endpoint.Scheme != "https" && endpoint.Scheme != "http") {
return "", "", "", false
}
ctx, cancel := context.WithTimeout(ctx, releaseTimeout)
defer cancel()
for page := 1; page <= 10; page++ {
if mirror {
query := endpoint.Query()
query.Set("per_page", "100")
query.Set("page", fmt.Sprint(page))
query.Set("direction", "desc")
endpoint.RawQuery = query.Encode()
}
body, err := readReleaseResponse(ctx, endpoint, token, mirror)
if err != nil {
return "", "", "", false
}
if !mirror {
return parseReleaseMetadata(body)
}
var releases []json.RawMessage
if err := json.Unmarshal(body, &releases); err != nil || releases == nil || len(releases) > 100 {
return "", "", "", false
}
for _, payload := range releases {
candidateVersion, candidateRevision, candidateURL, valid := parseMirrorReleaseMetadata(payload)
if valid && (!ok || semver.Compare(candidateVersion, version) > 0) {
version, revision, releaseURL, ok = candidateVersion, candidateRevision, candidateURL, true
}
}
if len(releases) < 100 {
return
}
}
// Incomplete pagination cannot establish the highest stable version.
return "", "", "", false
}
func readReleaseResponse(ctx context.Context, endpoint *url.URL, token string, mirror bool) ([]byte, error) {
request, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil {
return nil, err
}
request.Header.Set("Accept", "application/json")
request.Header.Set("User-Agent", "Piik-release-check")
if !mirror {
request.Header.Set("Accept", "application/vnd.github+json")
request.Header.Set("X-GitHub-Api-Version", "2022-11-28")
if authorizesGitHub(endpoint, token) {
request.Header.Set("Authorization", "Bearer "+strings.TrimSpace(token))
}
}
client := &http.Client{CheckRedirect: func(*http.Request, []*http.Request) error {
return errors.New("release endpoint redirected")
}}
response, err := client.Do(request)
if err != nil {
return nil, err
}
defer response.Body.Close()
if response.StatusCode < 200 || response.StatusCode > 299 {
return nil, errors.New("release endpoint unavailable")
}
const limit = 4 << 20
body, err := io.ReadAll(io.LimitReader(response.Body, limit+1))
if err != nil || len(body) > limit {
return nil, errors.New("release metadata unreadable or too large")
}
return body, nil
}
// Only the HTTPS GitHub API receives an operator token, and redirects are refused.
func authorizesGitHub(endpoint *url.URL, token string) bool {
return endpoint.Scheme == "https" &&
strings.ToLower(endpoint.Hostname()) == releaseAPIHost &&
strings.TrimSpace(token) != ""
}
func unavailableResult(currentVersion, currentRevision string) releaseResult {
currentVersion = strings.TrimSpace(currentVersion)
if canonical := semver.Canonical(currentVersion); canonical != "" {
currentVersion = canonical
}
result := releaseResult{Status: statusUnavailable, CurrentRevision: revisionOrNull(currentRevision)}
if currentVersion != "" {
result.CurrentVersion = &currentVersion
}
return result
}
func revisionOrNull(value string) *string {
revision := strings.ToLower(strings.TrimSpace(value))
if !fullRevisionPattern.MatchString(revision) {
return nil
}
return &revision
}
type releaseMetadata struct {
TagName string `json:"tag_name"`
HTMLURL string `json:"html_url"`
TargetCommitish string `json:"target_commitish"`
Draft bool `json:"draft"`
Prerelease bool `json:"prerelease"`
}
// A branch-valued target_commitish is unknown provenance, never a source SHA.
func parseReleaseMetadata(payload []byte) (version, revision, releaseURL string, ok bool) {
var metadata releaseMetadata
if err := json.Unmarshal(payload, &metadata); err != nil {
return "", "", "", false
}
return normalizeReleaseMetadata(metadata)
}
func normalizeReleaseMetadata(metadata releaseMetadata) (version, revision, releaseURL string, ok bool) {
if metadata.Draft || metadata.Prerelease {
return "", "", "", false
}
version = metadata.TagName
if version == "" || semver.Canonical(version) != version || semver.Prerelease(version) != "" ||
metadata.HTMLURL != releaseURLPrefix+version {
return "", "", "", false
}
if source := revisionOrNull(metadata.TargetCommitish); source != nil {
revision = *source
}
return version, revision, metadata.HTMLURL, true
}
func parseMirrorReleaseMetadata(payload []byte) (version, revision, releaseURL string, ok bool) {
var metadata struct {
TagName string `json:"tag_name"`
Body string `json:"body"`
Prerelease *bool `json:"prerelease"`
}
if err := json.Unmarshal(payload, &metadata); err != nil || metadata.Prerelease == nil || *metadata.Prerelease {
return "", "", "", false
}
sources := mirrorSourcePattern.FindAllStringSubmatch(metadata.Body, -1)
if len(sources) != 1 {
return "", "", "", false
}
// The mirror's target_commitish identifies its README, not the original source.
version, revision, _, ok = normalizeReleaseMetadata(releaseMetadata{
TagName: metadata.TagName, TargetCommitish: sources[0][1], HTMLURL: releaseURLPrefix + metadata.TagName,
})
if !ok {
return "", "", "", false
}
return version, revision, mirrorReleasePrefix + version, true
}