Skip to content

Commit

Permalink
Actually share and view shared input
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmcd committed Nov 5, 2018
1 parent 59b6d43 commit 3b8f883
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 13 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"encoding/json"
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"os"
Expand Down Expand Up @@ -86,6 +87,7 @@ func runHost() (err error) {
d.OnOpen = func() {
// fmt.Printf("Data channel '%s'-'%d'-'%d' open. This is the host\n", d.Label, d.ID, d.MaxPacketLifeTime)
fmt.Println("Data channel connected")
fmt.Print("\033[2J\033[H")
var err error
ptmx, err = pty.Start(cmd)

Expand All @@ -101,15 +103,23 @@ func runHost() (err error) {
os.Exit(0)
}
}()
oldState, err := terminal.MakeRaw(int(os.Stdin.Fd()))
if err != nil {
panic(err)
}
defer func() { _ = terminal.Restore(int(os.Stdin.Fd()), oldState) }()
go func() { _, _ = io.Copy(ptmx, os.Stdin) }()

buf := make([]byte, 1024)
for {
nr, err := ptmx.Read(buf)
if err != nil {
er := d.Send(datachannel.PayloadString{Data: []byte("quit")})
terminal.Restore(int(os.Stdin.Fd()), oldState)
glog.Error(er)
glog.Fatal(err)
os.Exit(0)
}
os.Stdout.Write(buf[0:nr])
err = d.Send(datachannel.PayloadBinary{Data: buf[0:nr]})
if err != nil {
glog.Fatal(err)
Expand All @@ -122,7 +132,7 @@ func runHost() (err error) {
d.Onmessage = func(payload datachannel.Payload) {
switch p := payload.(type) {
case *datachannel.PayloadString:
fmt.Printf("Message '%s' from DataChannel '%s' payload '%s'\n", p.PayloadType().String(), d.Label, string(p.Data))
// fmt.Printf("Message '%s' from DataChannel '%s' payload '%s'\n", p.PayloadType().String(), d.Label, string(p.Data))
data := string(p.Data)
if len(data) > 4 && data[:4] == "size" {
coords := strings.Split(data[5:], ",")
Expand Down Expand Up @@ -248,7 +258,7 @@ func runClient(offerString string) (err error) {
}
}()
ch <- syscall.SIGWINCH // Initial resize.

fmt.Print("\033[2J\033[H")
buf := make([]byte, 1024)
for {
nr, err := os.Stdin.Read(buf)
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# WebRTTY

WebRTTY allows you to share a terminal session from your machine. It uses a WebRTC DataChannel to share the session directly without the use of a proxy server.

```bash
go get github.com/maxmcd/webrtty
```
Expand Down

0 comments on commit 3b8f883

Please sign in to comment.