Your phone is the terminal. Stream a Linux/Mac desktop to an iPhone over WebRTC through NAT, with audio and input. Open source, single binaries.

0 downloads

Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/network-computer.git
HTTPS
https://gitstable.com/git/askrobots/network-computer.git
SSH
ssh://git@gitstable.com:2222/askrobots/network-computer.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

Dan Quellhorst Firefox policy: no WebRTC mDNS (a page using WebRTC made Firefox listen on UDP 5353) a1d92f3 1 month, 3 weeks ago History
hub_test.go · 2.4 KB · 90 lines
1package main
2
3import (
4 "context"
5 "sync"
6 "testing"
7 "time"
8
9 "github.com/pion/webrtc/v4/pkg/media"
10)
11
12type countWriter struct {
13 mu sync.Mutex
14 n int
15}
16
17func (c *countWriter) WriteSample(media.Sample) error { c.mu.Lock(); c.n++; c.mu.Unlock(); return nil }
18func (c *countWriter) count() int { c.mu.Lock(); defer c.mu.Unlock(); return c.n }
19
20// A fake encoder: a keyframe every 10th sample, until cancelled.
21func fakeEncoder(starts *int, mu *sync.Mutex) func(context.Context, captureOpts, sampleWriter, func()) {
22 return func(ctx context.Context, _ captureOpts, w sampleWriter, key func()) {
23 mu.Lock()
24 *starts++
25 mu.Unlock()
26 for i := 0; ctx.Err() == nil; i++ {
27 if i%10 == 0 {
28 key()
29 }
30 w.WriteSample(media.Sample{Data: []byte{byte(i)}})
31 time.Sleep(time.Millisecond)
32 }
33 }
34}
35
36func TestHubSharesOneEncoder(t *testing.T) {
37 var starts int
38 var mu sync.Mutex
39 h := newHub("video", true, fakeEncoder(&starts, &mu))
40 n := func() int { mu.Lock(); defer mu.Unlock(); return starts }
41 a, b := &countWriter{}, &countWriter{}
42 leaveA := h.join(a, captureOpts{})
43 time.Sleep(30 * time.Millisecond)
44 leaveB := h.join(b, captureOpts{})
45 time.Sleep(60 * time.Millisecond)
46 if n() != 1 {
47 t.Fatalf("two devices started %d encoders, want 1", n())
48 }
49 if a.count() == 0 || b.count() == 0 {
50 t.Fatalf("both devices get samples: a=%d b=%d", a.count(), b.count())
51 }
52 h.restart(captureOpts{Width: 800})
53 time.Sleep(30 * time.Millisecond)
54 if n() != 2 {
55 t.Fatalf("restart: %d starts, want 2", n())
56 }
57 leaveA()
58 leaveB()
59 h.mu.Lock()
60 running := h.cancel != nil
61 h.mu.Unlock()
62 if running {
63 t.Fatal("the encoder keeps running with nobody left")
64 }
65}
66
67func TestHubLateJoinerStartsAtKeyframe(t *testing.T) {
68 var starts int
69 var mu sync.Mutex
70 got := []byte{}
71 var gmu sync.Mutex
72 h := newHub("video", true, fakeEncoder(&starts, &mu))
73 first := &countWriter{}
74 leave := h.join(first, captureOpts{})
75 defer leave()
76 time.Sleep(15 * time.Millisecond) // mid-GOP
77 late := sampleFunc(func(s media.Sample) { gmu.Lock(); got = append(got, s.Data[0]); gmu.Unlock() })
78 leaveLate := h.join(late, captureOpts{})
79 time.Sleep(40 * time.Millisecond)
80 leaveLate()
81 gmu.Lock()
82 defer gmu.Unlock()
83 if len(got) == 0 || got[0]%10 != 0 {
84 t.Fatalf("a late device's first sample is %v, want a keyframe (multiple of 10)", got)
85 }
86}
87
88type sampleFunc func(media.Sample)
89
90func (f sampleFunc) WriteSample(s media.Sample) error { f(s); return nil }