diff --git a/client.go b/client.go index 6b8dff5..84c4e98 100644 --- a/client.go +++ b/client.go @@ -23,7 +23,7 @@ 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(datachannel.PayloadString{Data: []byte(size)}) } func clientDataChannelOnOpen(errChan chan error, dc *webrtc.RTCDataChannel) func() { @@ -40,7 +40,11 @@ func clientDataChannelOnOpen(errChan chan error, dc *webrtc.RTCDataChannel) func signal.Notify(ch, syscall.SIGWINCH) go func() { for range ch { - sendTermSize(os.Stdin, dc.Send) + err := sendTermSize(os.Stdin, dc.Send) + if err != nil { + log.Println(err) + errChan <- err + } } }() ch <- syscall.SIGWINCH // Initial resize. diff --git a/client_test.go b/client_test.go index 73c65f9..ea2f0bf 100644 --- a/client_test.go +++ b/client_test.go @@ -60,7 +60,7 @@ func TestSendTermSize(t *testing.T) { dcSend := func(payload datachannel.Payload) error { switch p := payload.(type) { - case *datachannel.PayloadString: + case datachannel.PayloadString: onMessage, errChan := makeShPty(t) size, err := pty.GetsizeFull(ptmx) if err != nil { diff --git a/host.go b/host.go index a3f61f8..750add1 100644 --- a/host.go +++ b/host.go @@ -9,6 +9,7 @@ import ( "os" "os/exec" "os/signal" + "time" "github.com/kr/pty" "github.com/mitchellh/colorstring" @@ -41,6 +42,8 @@ func hostDataChannelOnOpen(dc *webrtc.RTCDataChannel, errChan chan error) func() errChan <- err return } + // wait for pmtx to be readyd + time.Sleep(time.Millisecond * 10) if _, err = terminal.MakeRaw(int(os.Stdin.Fd())); err != nil { log.Println(err) @@ -119,6 +122,7 @@ func hostDataChannelOnMessage(errChan chan error) func(payload datachannel.Paylo if err != nil { log.Println(err) errChan <- err + return } ws.Rows = uint16(size[1]) ws.Cols = uint16(size[2]) @@ -128,7 +132,7 @@ func hostDataChannelOnMessage(errChan chan error) func(payload datachannel.Paylo ws.Y = uint16(size[4]) } - if err = pty.Setsize(ptmx, ws); err != nil { + if err := pty.Setsize(ptmx, ws); err != nil { log.Println(err) errChan <- err } diff --git a/main.go b/main.go index 65aa252..536031e 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "flag" + "fmt" "io/ioutil" "log" @@ -12,13 +13,13 @@ import ( func main() { oneWay := flag.Bool("o", false, "One-way connection with no response needed.") verbose := flag.Bool("v", false, "Verbose logging") + flag.Parse() if *verbose { log.SetFlags(log.LstdFlags | log.Lshortfile) } else { log.SetFlags(0) log.SetOutput(ioutil.Discard) } - flag.Parse() args := flag.Args() var offerString string if len(args) > 0 { @@ -28,12 +29,12 @@ func main() { if len(offerString) == 0 { err := runHost(*oneWay) if err != nil { - log.Println(err) + fmt.Println(err) } } else { err := runClient(offerString) if err != nil { - log.Println(err) + fmt.Println(err) } } resumeTerminal()