From edfe41816a3e9ea205107a5287d53fa4fbd59a6f Mon Sep 17 00:00:00 2001 From: Sean DuBois Date: Fri, 14 Jun 2019 07:05:39 -0700 Subject: [PATCH] Port to pion/webrtc@v2.0.0 (#19) --- client.go | 45 ++++++++++---------- client_test.go | 56 +++++++++++-------------- go.mod | 14 +++---- go.sum | 110 ++++++++++++++++++++++++++++++++++++++----------- host.go | 37 +++++++++-------- host_test.go | 20 ++++----- readme.md | 10 ++--- session.go | 18 ++++---- 8 files changed, 182 insertions(+), 128 deletions(-) diff --git a/client.go b/client.go index d2b0b1f..c5b13fd 100644 --- a/client.go +++ b/client.go @@ -11,18 +11,17 @@ import ( "github.com/kr/pty" "github.com/maxmcd/webtty/pkg/sd" "github.com/mitchellh/colorstring" - "github.com/pions/webrtc" - "github.com/pions/webrtc/pkg/datachannel" + "github.com/pion/webrtc/v2" "golang.org/x/crypto/ssh/terminal" ) type clientSession struct { session - dc *webrtc.RTCDataChannel + dc *webrtc.DataChannel offerString string } -func sendTermSize(term *os.File, dcSend func(p datachannel.Payload) error) error { +func sendTermSize(term *os.File, dcSend func(s string) error) error { winSize, err := pty.GetsizeFull(term) if err != nil { log.Fatal(err) @@ -30,12 +29,12 @@ func sendTermSize(term *os.File, dcSend func(p datachannel.Payload) error) error size := fmt.Sprintf(`["set_size",%d,%d,%d,%d]`, winSize.Rows, winSize.Cols, winSize.X, winSize.Y) - return dcSend(datachannel.PayloadString{Data: []byte(size)}) + return dcSend(size) } func (cs *clientSession) dataChannelOnOpen() func() { return func() { - log.Printf("Data channel '%s'-'%d'='%d' open.\n", cs.dc.Label, cs.dc.ID, *cs.dc.MaxPacketLifeTime) + log.Printf("Data channel '%s'-'%d'='%d' open.\n", cs.dc.Label(), cs.dc.ID(), cs.dc.MaxPacketLifeTime()) colorstring.Println("[bold]Terminal session started:") if err := cs.makeRawTerminal(); err != nil { @@ -47,7 +46,7 @@ func (cs *clientSession) dataChannelOnOpen() func() { signal.Notify(ch, syscall.SIGWINCH) go func() { for range ch { - err := sendTermSize(os.Stdin, cs.dc.Send) + err := sendTermSize(os.Stdin, cs.dc.SendText) if err != nil { log.Println(err) cs.errChan <- err @@ -62,7 +61,7 @@ func (cs *clientSession) dataChannelOnOpen() func() { log.Println(err) cs.errChan <- err } - err = cs.dc.Send(datachannel.PayloadBinary{Data: buf[0:nr]}) + err = cs.dc.Send(buf[0:nr]) if err != nil { log.Println(err) cs.errChan <- err @@ -71,10 +70,9 @@ func (cs *clientSession) dataChannelOnOpen() func() { } } -func (cs *clientSession) dataChannelOnMessage() func(payload datachannel.Payload) { - return func(payload datachannel.Payload) { - switch p := payload.(type) { - case *datachannel.PayloadString: +func (cs *clientSession) dataChannelOnMessage() func(payload webrtc.DataChannelMessage) { + return func(p webrtc.DataChannelMessage) { + if p.IsString { if string(p.Data) == "quit" { if cs.isTerminal { terminal.Restore(int(os.Stdin.Fd()), cs.oldTerminalState) @@ -83,14 +81,10 @@ func (cs *clientSession) dataChannelOnMessage() func(payload datachannel.Payload return } cs.errChan <- fmt.Errorf(`Unmatched string message: "%s"`, string(p.Data)) - case *datachannel.PayloadBinary: + } else { f := bufio.NewWriter(os.Stdout) f.Write(p.Data) f.Flush() - default: - cs.errChan <- fmt.Errorf( - "Message with type %s from DataChannel has no payload", - p.PayloadType().String()) } } } @@ -102,7 +96,7 @@ func (cs *clientSession) run() (err error) { maxPacketLifeTime := uint16(1000) // Arbitrary ordered := true - if cs.dc, err = cs.pc.CreateDataChannel("data", &webrtc.RTCDataChannelInit{ + if cs.dc, err = cs.pc.CreateDataChannel("data", &webrtc.DataChannelInit{ Ordered: &ordered, MaxPacketLifeTime: &maxPacketLifeTime, }); err != nil { @@ -123,9 +117,9 @@ func (cs *clientSession) run() (err error) { return } } - offer := webrtc.RTCSessionDescription{ - Type: webrtc.RTCSdpTypeOffer, - Sdp: cs.offer.Sdp, + offer := webrtc.SessionDescription{ + Type: webrtc.SDPTypeOffer, + SDP: cs.offer.Sdp, } if err = cs.pc.SetRemoteDescription(offer); err != nil { @@ -138,8 +132,15 @@ func (cs *clientSession) run() (err error) { log.Println(err) return } + + err = cs.pc.SetLocalDescription(answer) + if err != nil { + log.Println(err) + return + } + answerSd := sd.SessionDescription{ - Sdp: answer.Sdp, + Sdp: answer.SDP, Key: cs.offer.Key, Nonce: cs.offer.Nonce, } diff --git a/client_test.go b/client_test.go index e2adb65..22e6e22 100644 --- a/client_test.go +++ b/client_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/kr/pty" - "github.com/pions/webrtc/pkg/datachannel" + "github.com/pion/webrtc/v2" "golang.org/x/crypto/ssh/terminal" ) @@ -18,8 +18,8 @@ func TestClientDataChannelOnMessage(t *testing.T) { cs.errChan = make(chan error, 1) cs.oldTerminalState = &terminal.State{} onMessage := cs.dataChannelOnMessage() - quitPayload := datachannel.PayloadString{Data: []byte("quit")} - onMessage(&quitPayload) + quitPayload := webrtc.DataChannelMessage{IsString: true, Data: []byte("quit")} + onMessage(quitPayload) select { case err := <-cs.errChan: @@ -33,8 +33,8 @@ func TestClientDataChannelOnMessage(t *testing.T) { stdoutMock := tmpFile() stdout := os.Stdout os.Stdout = stdoutMock - binaryPayload := datachannel.PayloadBinary{Data: []byte("s")} - onMessage(&binaryPayload) + binaryPayload := webrtc.DataChannelMessage{IsString: false, Data: []byte("s")} + onMessage(binaryPayload) os.Stdout = stdout stdoutMock.Seek(0, 0) msg, _ := ioutil.ReadAll(stdoutMock) @@ -61,36 +61,30 @@ func TestSendTermSize(t *testing.T) { t.Error(err) } - dcSend := func(payload datachannel.Payload) error { - switch p := payload.(type) { - case datachannel.PayloadString: - onMessage, hs := makeShPty(t) - size, err := pty.GetsizeFull(hs.ptmx) - if err != nil { - t.Error(err) - } - if fmt.Sprintf("%v", size) != "&{0 0 0 0}" { - t.Error("wrong size", size) - } - onMessage(&datachannel.PayloadString{Data: p.Data}) - select { - case err := <-hs.errChan: - if err != nil { - t.Error(err) - } - default: - - } - size, err = pty.GetsizeFull(hs.ptmx) + dcSend := func(msg string) error { + onMessage, hs := makeShPty(t) + size, err := pty.GetsizeFull(hs.ptmx) + if err != nil { + t.Error(err) + } + if fmt.Sprintf("%v", size) != "&{0 0 0 0}" { + t.Error("wrong size", size) + } + onMessage(webrtc.DataChannelMessage{IsString: true, Data: []byte(msg)}) + select { + case err := <-hs.errChan: if err != nil { t.Error(err) } - if fmt.Sprintf("%v", size) != "&{19 29 9 8}" { - t.Error("wrong size", size) - } default: - fmt.Println(p.PayloadType().String()) - t.Error("Should have matched") + + } + size, err = pty.GetsizeFull(hs.ptmx) + if err != nil { + t.Error(err) + } + if fmt.Sprintf("%v", size) != "&{19 29 9 8}" { + t.Error("wrong size", size) } return nil } diff --git a/go.mod b/go.mod index 531a9d3..0074578 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,11 @@ module github.com/maxmcd/webtty +go 1.12 + require ( - github.com/btcsuite/btcutil v0.0.0-20180706230648-ab6388e0c60a - github.com/kr/pty v1.1.3 - github.com/mitchellh/colorstring v0.0.0-20150917214807-8631ce90f286 - github.com/pions/webrtc v1.1.2-0.20181205040827-70592e40f97d - golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9 - golang.org/x/net v0.0.0-20181213202711-891ebc4b82d6 // indirect - golang.org/x/sys v0.0.0-20181213200352-4d1cda033e06 // indirect + github.com/btcsuite/btcutil v0.0.0-20190316010144-3ac1210f4b38 + github.com/kr/pty v1.1.4 + github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db + github.com/pion/webrtc/v2 v2.0.15 + golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a ) diff --git a/go.sum b/go.sum index e37a3fd..0c11c23 100644 --- a/go.sum +++ b/go.sum @@ -1,28 +1,88 @@ -github.com/btcsuite/btcutil v0.0.0-20180706230648-ab6388e0c60a h1:RQMUrEILyYJEoAT34XS/kLu40vC0+po/UfxrBBA4qZE= -github.com/btcsuite/btcutil v0.0.0-20180706230648-ab6388e0c60a/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= +github.com/btcsuite/btcutil v0.0.0-20190316010144-3ac1210f4b38 h1:GbQHMJ2u/geMPV1tbN7i7zARSoPAPuXWa44V0KYvJXU= +github.com/btcsuite/btcutil v0.0.0-20190316010144-3ac1210f4b38/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= +github.com/cheekybits/genny v1.0.0 h1:uGGa4nei+j20rOSeDeP5Of12XVm7TGUd4dJA9RDitfE= +github.com/cheekybits/genny v1.0.0/go.mod h1:+tQajlRqAUrPI7DOSpB0XAqZYtQakVtB7wXkRAgjxjQ= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/kr/pty v1.1.3 h1:/Um6a/ZmD5tF7peoOJ5oN5KMQ0DrGVQSXLNwyckutPk= -github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/mitchellh/colorstring v0.0.0-20150917214807-8631ce90f286 h1:KHyL+3mQOF9sPfs26lsefckcFNDcIZtiACQiECzIUkw= -github.com/mitchellh/colorstring v0.0.0-20150917214807-8631ce90f286/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw= -github.com/pions/dtls v1.0.1 h1:HAOaQCXL62butEul8Hc4pOMcx/pUC9htdcWEzxG73UU= -github.com/pions/dtls v1.0.1/go.mod h1:T22vu8VCOxNmIrbe3nnM1UdIo3m1Bx5CJNkHyehahLg= -github.com/pions/pkg v0.0.0-20181115215726-b60cd756f712 h1:ciXO7F7PusyAzW/EZJt01bETgfTxP/BIGoWQ15pBP54= -github.com/pions/pkg v0.0.0-20181115215726-b60cd756f712/go.mod h1:r9wKZs+Xxv2acLspex4CHQiIhFjGK1zGP+nUm/8klXA= -github.com/pions/webrtc v1.1.1 h1:yVDoXk2sbaJJXIkW79IME2MRg0y/lT4zjOFI+EV0pQI= -github.com/pions/webrtc v1.1.1/go.mod h1:sQhy8101lrrfMDzn8H/9YoCJDLzAgpT05HKVeyupaak= -github.com/pions/webrtc v1.1.2-0.20181205040827-70592e40f97d h1:QJZMe/T+T/uq5LrwjLstpihM1p7Nw/3jwMXaN3CUV4A= -github.com/pions/webrtc v1.1.2-0.20181205040827-70592e40f97d/go.mod h1:6N2qMMzi6f4OyNlMR51fkIm9O57eg9HzRBesjOidP84= -github.com/pions/webrtc v1.1.2-0.20181212142319-7cc44ba79bba h1:2TmSfn1ghKFSDCpcUuNTpZq7Jd7dEO8R5TkRbcSctME= -github.com/pions/webrtc v1.1.2-0.20181212142319-7cc44ba79bba/go.mod h1:6N2qMMzi6f4OyNlMR51fkIm9O57eg9HzRBesjOidP84= -github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw= +github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/golang/mock v1.2.0 h1:28o5sBqPkBsMGnC6b4MvE2TzSr5/AT4c/1fLqVGIwlk= +github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/kr/pty v1.1.4 h1:5Myjjh3JY/NaAi4IsUbHADytDyl1VE1Y9PXDlL+P/VQ= +github.com/kr/pty v1.1.4/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/lucas-clemente/quic-go v0.7.1-0.20190401152353-907071221cf9 h1:tbuodUh2vuhOVZAdW3NEUvosFHUMJwUNl7jk/VSEiwc= +github.com/lucas-clemente/quic-go v0.7.1-0.20190401152353-907071221cf9/go.mod h1:PpMmPfPKO9nKJ/psF49ESTAGQSdfXxlg1otPbEB2nOw= +github.com/marten-seemann/qtls v0.2.3 h1:0yWJ43C62LsZt08vuQJDK1uC1czUc3FJeCLPoNAI4vA= +github.com/marten-seemann/qtls v0.2.3/go.mod h1:xzjG7avBwGGbdZ8dTGxlBnLArsVKLvwmjgmPuiQEcYk= +github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ= +github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs= +github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU= +github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/pion/datachannel v1.4.3 h1:tqS6YiqqAiFCxGGhvn1K7fHEzemK9Aov025dE/isGFo= +github.com/pion/datachannel v1.4.3/go.mod h1:SpMJbuu8v+qbA94m6lWQwSdCf8JKQvgmdSHDNtcbe+w= +github.com/pion/dtls v1.3.4 h1:MdOMsCfd44m2iTrxtkzA6UndvYVjLWWjua7hxU8EXEA= +github.com/pion/dtls v1.3.4/go.mod h1:CjlPLfQdsTg3G4AEXjJp8FY5bRweBlxHrgoFrN+fQsk= +github.com/pion/ice v0.2.8 h1:DCFMO8yJRB6XGaRjjdHupsHvjcM72LJ9YwL/2Io2EXk= +github.com/pion/ice v0.2.8/go.mod h1:HyIp0mppSrUdw7DFLQfPgJWnPRRV96pnTV8irdrBGrA= +github.com/pion/logging v0.2.1 h1:LwASkBKZ+2ysGJ+jLv1E/9H1ge0k1nTfi1X+5zirkDk= +github.com/pion/logging v0.2.1/go.mod h1:k0/tDVsRCX2Mb2ZEmTqNa7CWsQPc+YYCB7Q+5pahoms= +github.com/pion/quic v0.1.1 h1:D951FV+TOqI9A0rTF7tHx0Loooqz+nyzjEyj8o3PuMA= +github.com/pion/quic v0.1.1/go.mod h1:zEU51v7ru8Mp4AUBJvj6psrSth5eEFNnVQK5K48oV3k= +github.com/pion/rtcp v1.2.0 h1:rT2FptW5YHIern+4XlbGYnnsT26XGxurnkNLnzhtDXg= +github.com/pion/rtcp v1.2.0/go.mod h1:a5dj2d6BKIKHl43EnAOIrCczcjESrtPuMgfmL6/K6QM= +github.com/pion/rtp v1.1.2 h1:ERNugzYHW9F2ldpwoARbeFGKRoq1REe5Jxdjvm/rOx8= +github.com/pion/rtp v1.1.2/go.mod h1:/l4cvcKd0D3u9JLs2xSVI95YkfXW87a3br3nqmVtSlE= +github.com/pion/sctp v1.6.3 h1:SC4vKOjcddK8tXiTNj05a+0/GyPpCmuNfeBA/rzNFqs= +github.com/pion/sctp v1.6.3/go.mod h1:cCqpLdYvgEUdl715+qbWtgT439CuQrAgy8BZTp0aEfA= +github.com/pion/sdp/v2 v2.1.1 h1:i3fAyjiLuQseYNo0BtCOPfzp91Ppb7vasRGmUUTog28= +github.com/pion/sdp/v2 v2.1.1/go.mod h1:idSlWxhfWQDtTy9J05cgxpHBu/POwXN2VDRGYxT/EjU= +github.com/pion/srtp v1.2.4 h1:wwGKC5ewuBukkZ+i+pZ8aO33+t6z2y/XRiYtyP0Xpv0= +github.com/pion/srtp v1.2.4/go.mod h1:52qiP0g3FVMG/5NL6Ko8Vr2qirevKH+ukYbNS/4EX40= +github.com/pion/stun v0.2.2 h1:0IJCwJFOdEmHzz4oxl9SBGLlJbnNbF+0h6XSOmuE034= +github.com/pion/stun v0.2.2/go.mod h1:TChCNKgwnFiFG/c9K+zqEdd6pO6tlODb9yN1W/zVfsE= +github.com/pion/transport v0.6.0 h1:WAoyJg/6OI8dhCVFl/0JHTMd1iu2iHgGUXevptMtJ3U= +github.com/pion/transport v0.6.0/go.mod h1:iWZ07doqOosSLMhZ+FXUTq+TamDoXSllxpbGcfkCmbE= +github.com/pion/transport v0.7.0 h1:EsXN8TglHMlKZMo4ZGqwK6QgXBu0WYg7wfGMWIXsS+w= +github.com/pion/transport v0.7.0/go.mod h1:iWZ07doqOosSLMhZ+FXUTq+TamDoXSllxpbGcfkCmbE= +github.com/pion/webrtc/v2 v2.0.15 h1:0n8P+sYfGN515RnkdRyc4SD1r+0BZ5ts7SDSUxxlkmY= +github.com/pion/webrtc/v2 v2.0.15/go.mod h1:e1xwQPR2XVoDWTj5uGSKfHB9Xk4oWRt7mk4bVfXHi8E= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9 h1:mKdxBk7AujPs8kU4m80U72y/zjbZ3UcXC7dClwKbUI0= -golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181213202711-891ebc4b82d6 h1:gT0Y6H7hbVPUtvtk0YGxMXPgN+p8fYlqWkgJeUCZcaQ= -golang.org/x/net v0.0.0-20181213202711-891ebc4b82d6/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/sys v0.0.0-20181213200352-4d1cda033e06 h1:0oC8rFnE+74kEmuHZ46F6KHsMr5Gx2gUQPuNz28iQZM= -golang.org/x/sys v0.0.0-20181213200352-4d1cda033e06/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190404164418-38d8ce5564a5 h1:bselrhR0Or1vomJZC8ZIjWtbDmn9OYFLX5Ik9alpJpE= +golang.org/x/crypto v0.0.0-20190404164418-38d8ce5564a5/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= +golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a h1:Igim7XhdOpBnWPuYJ70XcNpq8q3BCACtVgNfoJxOV7g= +golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190228124157-a34e9553db1e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e h1:nFYrTHrdrAOpShe27kaFHjsqYSEQ0KWqdWLu3xuZJts= +golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/host.go b/host.go index 0c2df6f..5bfec4d 100644 --- a/host.go +++ b/host.go @@ -14,8 +14,7 @@ import ( "github.com/kr/pty" "github.com/maxmcd/webtty/pkg/sd" "github.com/mitchellh/colorstring" - "github.com/pions/webrtc" - "github.com/pions/webrtc/pkg/datachannel" + "github.com/pion/webrtc/v2" ) type hostSession struct { @@ -83,7 +82,7 @@ func (hs *hostSession) dataChannelOnOpen() func() { return } } - if err = hs.dc.Send(datachannel.PayloadBinary{Data: buf[0:nr]}); err != nil { + if err = hs.dc.Send(buf[0:nr]); err != nil { log.Println(err) hs.errChan <- err return @@ -92,8 +91,8 @@ func (hs *hostSession) dataChannelOnOpen() func() { } } -func (hs *hostSession) dataChannelOnMessage() func(payload datachannel.Payload) { - return func(payload datachannel.Payload) { +func (hs *hostSession) dataChannelOnMessage() func(payload webrtc.DataChannelMessage) { + return func(p webrtc.DataChannelMessage) { // OnMessage can fire before onOpen // Let's wait for the pty session to be ready @@ -101,8 +100,7 @@ func (hs *hostSession) dataChannelOnMessage() func(payload datachannel.Payload) time.Sleep(1 * time.Millisecond) } - switch p := payload.(type) { - case *datachannel.PayloadString: + if p.IsString { if len(p.Data) > 2 && p.Data[0] == '[' && p.Data[1] == '"' { var msg []string err := json.Unmarshal(p.Data, &msg) @@ -154,22 +152,18 @@ func (hs *hostSession) dataChannelOnMessage() func(payload datachannel.Payload) `Unmatched string message: "%s"`, string(p.Data), ) - case *datachannel.PayloadBinary: + } else { _, err := hs.ptmx.Write(p.Data) if err != nil { log.Println(err) hs.errChan <- err } - default: - hs.errChan <- fmt.Errorf( - "Message with type %s from DataChannel has no payload", - p.PayloadType().String()) } } } -func (hs *hostSession) onDataChannel() func(dc *webrtc.RTCDataChannel) { - return func(dc *webrtc.RTCDataChannel) { +func (hs *hostSession) onDataChannel() func(dc *webrtc.DataChannel) { + return func(dc *webrtc.DataChannel) { hs.dc = dc dc.OnOpen(hs.dataChannelOnOpen()) dc.OnMessage(hs.dataChannelOnMessage()) @@ -192,8 +186,15 @@ func (hs *hostSession) createOffer() (err error) { log.Println(err) return } + + err = hs.pc.SetLocalDescription(offer) + if err != nil { + log.Println(err) + return + } + hs.offer = sd.SessionDescription{ - Sdp: offer.Sdp, + Sdp: offer.SDP, } if hs.oneWay { hs.offer.GenKeys() @@ -255,9 +256,9 @@ func (hs *hostSession) run() (err error) { func (hs *hostSession) setHostRemoteDescriptionAndWait() (err error) { // Set the remote SessionDescription - answer := webrtc.RTCSessionDescription{ - Type: webrtc.RTCSdpTypeAnswer, - Sdp: hs.answer.Sdp, + answer := webrtc.SessionDescription{ + Type: webrtc.SDPTypeAnswer, + SDP: hs.answer.Sdp, } // Apply the answer as the remote description diff --git a/host_test.go b/host_test.go index 6d649e2..ded6b1a 100644 --- a/host_test.go +++ b/host_test.go @@ -8,15 +8,15 @@ import ( "testing" "github.com/kr/pty" - "github.com/pions/webrtc/pkg/datachannel" + "github.com/pion/webrtc/v2" ) func TestHosttDataChannelOnMessage(t *testing.T) { hs := hostSession{ptmxReady: true} hs.errChan = make(chan error, 1) onMessage := hs.dataChannelOnMessage() - quitPayload := datachannel.PayloadString{Data: []byte("quit")} - onMessage(&quitPayload) + quitPayload := webrtc.DataChannelMessage{IsString: true, Data: []byte("quit")} + onMessage(quitPayload) select { case err := <-hs.errChan: @@ -30,8 +30,8 @@ func TestHosttDataChannelOnMessage(t *testing.T) { stdoutMock := tmpFile() hs.ptmx = stdoutMock - binaryPayload := datachannel.PayloadBinary{Data: []byte("s")} - onMessage(&binaryPayload) + binaryPayload := webrtc.DataChannelMessage{IsString: false, Data: []byte("s")} + onMessage(binaryPayload) stdoutMock.Seek(0, 0) msg, _ := ioutil.ReadAll(stdoutMock) if string(msg) != "s" { @@ -40,7 +40,7 @@ func TestHosttDataChannelOnMessage(t *testing.T) { } -func makeShPty(t *testing.T) (func(p datachannel.Payload), hostSession) { +func makeShPty(t *testing.T) (func(p webrtc.DataChannelMessage), hostSession) { hs := hostSession{ptmxReady: true} hs.errChan = make(chan error, 1) onMessage := hs.dataChannelOnMessage() @@ -57,8 +57,8 @@ func makeShPty(t *testing.T) (func(p datachannel.Payload), hostSession) { func TestClientSetSizeOnMessage(t *testing.T) { onMessage, hs := makeShPty(t) - sizeOnlyPayload := datachannel.PayloadString{Data: []byte(`["set_size", 20, 30]`)} - onMessage(&sizeOnlyPayload) + sizeOnlyPayload := webrtc.DataChannelMessage{IsString: true, Data: []byte(`["set_size", 20, 30]`)} + onMessage(sizeOnlyPayload) size, err := pty.GetsizeFull(hs.ptmx) if err != nil { @@ -68,8 +68,8 @@ func TestClientSetSizeOnMessage(t *testing.T) { t.Error("wrong size", size) } - sizeAndCursorPayload := datachannel.PayloadString{Data: []byte(`["set_size", 20, 30, 10, 11]`)} - onMessage(&sizeAndCursorPayload) + sizeAndCursorPayload := webrtc.DataChannelMessage{IsString: true, Data: []byte(`["set_size", 20, 30, 10, 11]`)} + onMessage(sizeAndCursorPayload) size, err = pty.GetsizeFull(hs.ptmx) if err != nil { diff --git a/readme.md b/readme.md index 9bc62a0..c578e67 100644 --- a/readme.md +++ b/readme.md @@ -6,7 +6,7 @@ WebTTY allows you to share a terminal session from your machine using WebRTC. Yo ### Status -There are a handful of bugs to fix, but everything works pretty well at the moment. Please open an issue if you find a bug. +There are a handful of bugs to fix, but everything works pretty well at the moment. Please open an issue if you find a bug. ### Installation @@ -18,12 +18,12 @@ Or, install directly with Go. WebTTY requires go version 1.9 or higher. go get -u github.com/maxmcd/webtty ``` -There were recent breaking api changes in the pions/webrtc library. Make sure to run `go get -u github.com/pions/webrtc` if you're running into any installation errors. +There were recent breaking api changes in the pion/webrtc library. Make sure to run `go get -u github.com/pion/webrtc` if you're running into any installation errors. ### Running ```shell -> webtty -h +> webtty -h Usage of webtty: -cmd The command to run. Default is "bash -l" @@ -67,7 +67,7 @@ When you have the answer, paste it below and hit enter. By default WebTTY forces the size of the client terminal. This means the host size can frequently render incorrectly. One way you can fix this is by using tmux: -```bash +```bash tmux new-session -s shared # in another terminal webtty -ni -cmd tmux attach-session -t shared @@ -82,4 +82,4 @@ I think this somewhat violates the spirit of this tool because it relies on a th SDP descriptions are encrypted when uploaded and encryption keys are shared with the connection data to decrypt. So presumably the service being compromised is not problematic. -Very open to any ideas on how to enable trusted one-way connections. Please open an issue or reach out if you have thoughts. For now, the `-o` flag will print a warning and link to this explanation. +Very open to any ideas on how to enable trusted one-way connections. Please open an issue or reach out if you have thoughts. For now, the `-o` flag will print a warning and link to this explanation. diff --git a/session.go b/session.go index b77df4c..e2b24bd 100644 --- a/session.go +++ b/session.go @@ -5,9 +5,7 @@ import ( "os" "github.com/maxmcd/webtty/pkg/sd" - "github.com/pions/webrtc" - "github.com/pions/webrtc/pkg/datachannel" - "github.com/pions/webrtc/pkg/ice" + "github.com/pion/webrtc/v2" "golang.org/x/crypto/ssh/terminal" ) @@ -17,10 +15,10 @@ type session struct { stunServers []string errChan chan error isTerminal bool - pc *webrtc.RTCPeerConnection + pc *webrtc.PeerConnection offer sd.SessionDescription answer sd.SessionDescription - dc *webrtc.RTCDataChannel + dc *webrtc.DataChannel } func (s *session) init() (err error) { @@ -36,7 +34,7 @@ func (s *session) init() (err error) { func (s *session) cleanup() { if s.dc != nil { // TODO: check dc state? - if err := s.dc.Send(datachannel.PayloadString{Data: []byte("quit")}); err != nil { + if err := s.dc.SendText("quit"); err != nil { log.Println(err) } } @@ -62,14 +60,14 @@ func (s *session) makeRawTerminal() error { } func (s *session) createPeerConnection() (err error) { - config := webrtc.RTCConfiguration{ - IceServers: []webrtc.RTCIceServer{ + config := webrtc.Configuration{ + ICEServers: []webrtc.ICEServer{ { URLs: s.stunServers, }, }, } - s.pc, err = webrtc.New(config) + s.pc, err = webrtc.NewPeerConnection(config) if err != nil { return } @@ -80,7 +78,7 @@ func (s *session) createPeerConnection() (err error) { // if s.pc.OnDataChannel == nil { // return errors.New("Couldn't create a peerConnection") // } - s.pc.OnICEConnectionStateChange(func(connectionState ice.ConnectionState) { + s.pc.OnICEConnectionStateChange(func(connectionState webrtc.ICEConnectionState) { log.Printf("ICE Connection State has changed: %s\n", connectionState.String()) }) return