## Problem and outcome Connection recovery and packet repair could leave stale pictures, missing sound or unreliable remote input. This maintenance release repairs media/route ownership, H.264 negotiation, voice forwarding and Windows input recovery, and makes shared mobile controls and popovers easier to use. ## Release notes **Piik, now in your pocket.** Piik App supports Android screen sharing, with touch controls for a friend's computer. **手机,也能开播。** Piik App 支持 Android 屏幕分享,也能用手机控制朋友的电脑。 ### English Piik v2.5.1 improves sharing recovery, voice playback and remote control, with clearer mobile controls. It keeps the existing 2.x compatibility baseline. - Improve H.264 selection and picture recovery after reconnecting, changing sources or recovering lost packets; keep a working share when a replacement source fails. - Keep audio and room voice continuous, and prevent duplicate sound when switching playback windows. - Improve Windows input recovery and release remote-control permissions when their connection ends. - Keep mobile controls together and popovers usable after layout changes or in short viewports. - Open the appropriate Android update download, including the Gitee ZIP containing the APK. Self-hosted SFU servers refresh public addresses for new connections without a restart. - Add macOS source-thumbnail support. Update the App and self-hosted site together to receive all fixes. Browser settings and existing room data are retained. ### 中文 Piik v2.5.1 改善分享恢复、语音播放与远程控制的稳定性,让手机操作更顺手,沿用现有 2.x 兼容基线。 - 改善 H.264 编码选择,以及重连、切换分享源和丢包后的画面恢复;新分享源切换失败时保留正常分享。 - 保持声音与房间语音连续,避免切换播放窗口时出现双重声音。 - 改善 Windows 输入恢复,并在连接结束时释放远程控制授权。 - 手机控件保持成组,浮层在布局变化或可见高度较小时仍可操作。 - Android 更新打开对应下载入口,Gitee 提供内含 APK 的 ZIP;自部署 SFU 为新连接刷新公网地址,无需重启服务。 - 补齐 macOS 选源缩略图支持。 请一起更新 App 与自部署站点,以获得全部修复。浏览器设置与已有房间数据保留。 ## Validation - Full frontend typecheck, test and production-build acceptance; current Windows App/Server packaging, extracted-file checks and exact served JavaScript verified locally. - Existing Go, vulnerability, native media and controlled-network results retained at their tested revisions. The final production delta from the fully checked candidate is the shared short-viewport popover correction. - The diagnostic report supplied for #502 informed the Windows input fixes. #500 sharing is confirmed working; its missing source previews are implemented. Original-device follow-up remains separate from this release's verified local fixes. ## Compatibility and scope Preserves the published 2.x Browser/server, Native control, capture and SQLite contracts. No 3.0 or iOS implementation or external contributor patch is included. Related: #500, #502, #510, #512.
240 lines
7.3 KiB
Go
240 lines
7.3 KiB
Go
package nativeviewer
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
"strings"
|
|
"sync"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/TNTcraftHIM/Piik/internal/app/nativecapture"
|
|
"github.com/TNTcraftHIM/Piik/internal/app/remoteinput"
|
|
"github.com/pion/webrtc/v4"
|
|
)
|
|
|
|
// Delay the real Native callback while Pion and SCTP recover independently.
|
|
type delayedInputStateHandler struct {
|
|
entered chan struct{}
|
|
release chan struct{}
|
|
once sync.Once
|
|
}
|
|
|
|
func (h *delayedInputStateHandler) Enabled(context.Context, slog.Level) bool { return true }
|
|
func (h *delayedInputStateHandler) Handle(_ context.Context, record slog.Record) error {
|
|
var event, direction, state string
|
|
record.Attrs(func(a slog.Attr) bool {
|
|
switch a.Key {
|
|
case "event":
|
|
event = a.Value.String()
|
|
case "direction":
|
|
direction = a.Value.String()
|
|
case "state":
|
|
state = a.Value.String()
|
|
}
|
|
return true
|
|
})
|
|
if event == "media-connection-state" && direction == "inbound" && state == "connecting" {
|
|
h.once.Do(func() { close(h.entered); <-h.release })
|
|
}
|
|
return nil
|
|
}
|
|
func (h *delayedInputStateHandler) WithAttrs([]slog.Attr) slog.Handler { return h }
|
|
func (h *delayedInputStateHandler) WithGroup(string) slog.Handler { return h }
|
|
|
|
// Exercise the actual native receiver and local playback edge, not a second
|
|
// Browser-only path. Both local playback and relay children use the media tree.
|
|
func TestInputChannelUsesPlaybackAndRelay(t *testing.T) {
|
|
previous := slog.Default()
|
|
delayed := &delayedInputStateHandler{entered: make(chan struct{}), release: make(chan struct{})}
|
|
slog.SetDefault(slog.New(delayed))
|
|
var releaseOnce sync.Once
|
|
resume := func() { releaseOnce.Do(func() { close(delayed.release) }) }
|
|
t.Cleanup(func() { resume(); slog.SetDefault(previous) })
|
|
peer := func() *webrtc.PeerConnection {
|
|
t.Helper()
|
|
p, err := webrtc.NewPeerConnection(webrtc.Configuration{})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Cleanup(func() { _ = p.Close() })
|
|
return p
|
|
}
|
|
localDescription := func(p *webrtc.PeerConnection, description webrtc.SessionDescription) webrtc.SessionDescription {
|
|
t.Helper()
|
|
gathered := webrtc.GatheringCompletePromise(p)
|
|
if err := p.SetLocalDescription(description); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
select {
|
|
case <-gathered:
|
|
case <-time.After(5 * time.Second):
|
|
t.Fatal("ICE gathering timed out")
|
|
}
|
|
return *p.LocalDescription()
|
|
}
|
|
upstream, playback := peer(), peer()
|
|
if _, err := upstream.AddTransceiverFromKind(webrtc.RTPCodecTypeVideo); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
remote, err := upstream.CreateDataChannel(remoteinput.ChannelLabel, nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
requests := make(chan string, 10)
|
|
remote.OnMessage(func(message webrtc.DataChannelMessage) { requests <- string(message.Data) })
|
|
offer, err := upstream.CreateOffer(nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
offer = localDescription(upstream, offer)
|
|
events := make(chan Event, 32)
|
|
observed := make(chan Event, 32)
|
|
session, err := Start(t.Context(), Options{ShareID: "input-viewer", EdgeCapacity: 2, Events: events})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Cleanup(func() { _ = session.Close() })
|
|
result, err := session.AcceptOffer("upstream", offer, nil, false, false)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err = upstream.SetRemoteDescription(result.Answer); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
go func() {
|
|
for {
|
|
select {
|
|
case event := <-events:
|
|
if event.Type == "edge-candidate" && event.ConnectionID == "upstream" && event.Candidate != nil {
|
|
_ = upstream.AddICECandidate(*event.Candidate)
|
|
} else {
|
|
observed <- event
|
|
}
|
|
case <-t.Context().Done():
|
|
return
|
|
}
|
|
}
|
|
}()
|
|
opened := make(chan *webrtc.DataChannel, 1)
|
|
states := make(chan string, 10)
|
|
playback.OnDataChannel(func(channel *webrtc.DataChannel) {
|
|
channel.OnMessage(func(message webrtc.DataChannelMessage) { states <- string(message.Data) })
|
|
channel.OnOpen(func() { opened <- channel })
|
|
})
|
|
localOffer, err := session.PrepareLocalEdge("upstream", "playback", "local-offer", false)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err = playback.SetRemoteDescription(localOffer); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
answer, err := playback.CreateAnswer(nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err = session.SetAnswer("playback", localDescription(playback, answer), "local-offer"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var local *webrtc.DataChannel
|
|
select {
|
|
case local = <-opened:
|
|
case <-time.After(5 * time.Second):
|
|
t.Fatal("local input channel did not open")
|
|
}
|
|
waitMessage := func(messages <-chan string, want string) {
|
|
t.Helper()
|
|
timer := time.NewTimer(5 * time.Second)
|
|
defer timer.Stop()
|
|
for {
|
|
select {
|
|
case message := <-messages:
|
|
if message == want {
|
|
return
|
|
}
|
|
case <-timer.C:
|
|
t.Fatalf("missing forwarded message %s", want)
|
|
}
|
|
}
|
|
}
|
|
waitMessage(requests, `{"ready":true}`)
|
|
if err = remote.SendText(`{"ready":true}`); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
waitMessage(states, `{"ready":true}`)
|
|
const packet = `{"id":"0123456789abcdef0123456789abcdef","epoch":"0123456789abcdef0123456789abcdef","data":"encrypted"}`
|
|
const closed = `{"id":"0123456789abcdef0123456789abcdef","epoch":"0123456789abcdef0123456789abcdef","closed":true}`
|
|
if err = local.SendText(packet); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
waitMessage(requests, packet)
|
|
// Restart the same Native PC, but delay its transient loss callback until
|
|
// the current connection and input handshake have recovered.
|
|
offer, err = upstream.CreateOffer(&webrtc.OfferOptions{ICERestart: true})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
offer = localDescription(upstream, offer)
|
|
result, err = session.AcceptOffer("upstream", offer, nil, true, false)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !result.Reused {
|
|
t.Fatal("restart replaced the Native receiver")
|
|
}
|
|
if err = upstream.SetRemoteDescription(result.Answer); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
select {
|
|
case <-delayed.entered:
|
|
case <-time.After(5 * time.Second):
|
|
t.Fatal("Native connecting callback was not delayed")
|
|
}
|
|
// ICE restart retires the selected pair and enters Checking directly. Input
|
|
// must release on that ordered event, before this queued media projection.
|
|
waitMessage(states, `{"ready":false}`)
|
|
waitMessage(requests, `{"ready":true}`)
|
|
if err = remote.SendText(`{"ready":true}`); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
waitMessage(states, `{"ready":true}`)
|
|
if err = local.SendText(packet); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
waitMessage(requests, packet)
|
|
resume()
|
|
// Wait until the delayed real callback has delivered its projection. Input
|
|
// already recovered on the ordered transport observer; this older callback
|
|
// must not demand another handshake or retire the fresh return path.
|
|
completed := time.NewTimer(5 * time.Second)
|
|
defer completed.Stop()
|
|
for {
|
|
select {
|
|
case event := <-observed:
|
|
if event.ConnectionID == "upstream" && event.State == "connecting" {
|
|
goto resumed
|
|
}
|
|
case <-completed.C:
|
|
t.Fatal("delayed Native projection did not finish")
|
|
}
|
|
}
|
|
resumed:
|
|
if err = local.SendText(packet); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
waitMessage(requests, packet)
|
|
|
|
if err = session.UpdateProfile(nativecapture.VideoProfile{Width: 1280, Height: 720, Framerate: 30, Bitrate: 2_000_000, Preference: "balanced"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
relay, err := session.PrepareEdge("upstream", "relay-child", nil, false)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.Contains(relay.SDP, "\nm=application ") {
|
|
t.Fatal("relay child has no input return path")
|
|
}
|
|
session.CloseEdge("playback")
|
|
waitMessage(requests, closed)
|
|
}
|