Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use gorilla/websocket
  • Loading branch information
jackc committed Sep 6, 2016
1 parent ad93028 commit cf9b8b3
Show file tree
Hide file tree
Showing 22 changed files with 2,322 additions and 1,282 deletions.
9 changes: 5 additions & 4 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions connection.go
Expand Up @@ -2,11 +2,11 @@ package main

import (
"fmt"
"io"
"net/http"

"github.com/chzyer/readline"
"github.com/fatih/color"
"golang.org/x/net/websocket"
"github.com/gorilla/websocket"
)

type session struct {
Expand All @@ -16,7 +16,10 @@ type session struct {
}

func connect(url, origin string, rlConf *readline.Config) error {
ws, err := websocket.Dial(url, "", origin)
headers := make(http.Header)
headers.Add("Origin", origin)

ws, _, err := websocket.DefaultDialer.Dial(url, headers)
if err != nil {
return err
}
Expand Down Expand Up @@ -47,7 +50,7 @@ func (s *session) readConsole() {
return
}

_, err = io.WriteString(s.ws, line)
err = s.ws.WriteMessage(websocket.TextMessage, []byte(line))
if err != nil {
s.errChan <- err
return
Expand All @@ -56,17 +59,14 @@ func (s *session) readConsole() {
}

func (s *session) readWebsocket() {
buf := make([]byte, 4096)
rxSprintf := color.New(color.FgGreen).SprintfFunc()

for {
n, err := s.ws.Read(buf)
if n > 0 {
fmt.Fprint(s.rl.Stdout(), rxSprintf("< %s\n", string(buf[:n])))
}
_, buf, err := s.ws.ReadMessage()
if err != nil {
s.errChan <- err
return
}
fmt.Fprint(s.rl.Stdout(), rxSprintf("< %s\n", string(buf)))
}
}
25 changes: 25 additions & 0 deletions vendor/github.com/gorilla/websocket/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions vendor/github.com/gorilla/websocket/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions vendor/github.com/gorilla/websocket/AUTHORS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions vendor/github.com/gorilla/websocket/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 61 additions & 0 deletions vendor/github.com/gorilla/websocket/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cf9b8b3

Please sign in to comment.