From b450b67d67927afe6b2ca4b2b8a37a28cafb8a5f Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Tue, 5 Aug 2014 22:35:51 +0000 Subject: [PATCH] Finally enable push notification --- index.html | 3 +++ irc.cgi.go | 33 ++++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/index.html b/index.html index e3efc9e..323399b 100644 --- a/index.html +++ b/index.html @@ -43,6 +43,9 @@ input[name~=target] { } input[name~=text] { width: 75%; +} +body { + height: 100%; } diff --git a/irc.cgi.go b/irc.cgi.go index 0e555ac..3dbafed 100644 --- a/irc.cgi.go +++ b/irc.cgi.go @@ -35,18 +35,29 @@ func tail(w http.ResponseWriter, pos int) { } defer f.Close() - - _, err = f.Seek(int64(pos), 0) - if err != nil { - log.Fatal(err) + for { + printid := false + + _, err = f.Seek(int64(pos), 0) + if err != nil { + log.Fatal(err) + } + bf := bufio.NewScanner(f) + for bf.Scan() { + t := bf.Text() + pos += len(t) + 1 // XXX: this breaks if we ever see \r\n + fmt.Fprintf(w, "data: %s\n", t) + printid = true + } + if printid { + _, err = fmt.Fprintf(w, "id: %d\n\n", pos) + } + if err != nil { + break + } + w.(http.Flusher).Flush() + time.Sleep(350 * time.Millisecond) } - bf := bufio.NewScanner(f) - for bf.Scan() { - t := bf.Text() - pos += len(t) + 1 // XXX: this breaks if we ever see \r\n - fmt.Fprintf(w, "data: %s\n", t) - } - fmt.Fprintf(w, "id: %d\n\n", pos) } func handleCommand(w http.ResponseWriter, text string, target string) {