From 1d478552bc184512f0a1145c375b27efed683121 Mon Sep 17 00:00:00 2001 From: Ralph Caraveo Date: Tue, 16 Jun 2015 13:17:13 -0700 Subject: [PATCH] Saving for WIP --- html5/Caddyfile | 9 ++-- html5/karaoke-konqueror.go | 35 ++++++++++++++++ html5/socket.html | 85 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+), 3 deletions(-) create mode 100644 html5/karaoke-konqueror.go create mode 100644 html5/socket.html diff --git a/html5/Caddyfile b/html5/Caddyfile index 79a12ea..e044ef9 100644 --- a/html5/Caddyfile +++ b/html5/Caddyfile @@ -1,7 +1,10 @@ # Run caddy in this directory and it will pick up Caddyfile automatically # Don't add caddy to the repo, just invoke it from where the binary is -localhost:2020 -gzip -log caddy.log +localhost +#gzip +#log has a bug where websocket feature doesn't work +#log caddy.log +#errors error.log # The root of the site root . +websocket /echo cat diff --git a/html5/karaoke-konqueror.go b/html5/karaoke-konqueror.go new file mode 100644 index 0000000..e845a59 --- /dev/null +++ b/html5/karaoke-konqueror.go @@ -0,0 +1,35 @@ +package main + +import ( + "bufio" + "fmt" + "os" +) + +func main() { + // Idea: this design will block if a single function takes long + // Solution: Have a protocol where each command is issued with a GUID + // Fire off command in goroutine such that other commands can be executed + // and return immediatley GUID with a queued flag + // When result commands back read result from channel and send to STDOUT + // along with the matching GUID, this way clients can match up calls + // Interesting solution. + scanner := bufio.NewScanner(os.Stdin) + for scanner.Scan() { + inCommand := scanner.Text() + + if inCommand == `{"command":"go"}` { + fmt.Println("Going...") + } else if inCommand == `{"command":"bark"}` { + fmt.Println("Barking...") + } else if inCommand == `{"command":"quit"}` { + fmt.Println("Quiting...") + break + } else { + fmt.Println("No command...") + } + } + if err := scanner.Err(); err != nil { + fmt.Fprintln(os.Stderr, "reading standard input:", err) + } +} diff --git a/html5/socket.html b/html5/socket.html new file mode 100644 index 0000000..5acd2dd --- /dev/null +++ b/html5/socket.html @@ -0,0 +1,85 @@ + + + + + Echo Chamber + + + + + +
+ +
+
+ + + +
+ +
+ + + + + +