Finally enable push notification

This commit is contained in:
Neale Pickett 2014-08-05 22:35:51 +00:00
parent b7f0d926fc
commit b450b67d67
2 changed files with 25 additions and 11 deletions

View File

@ -43,6 +43,9 @@ input[name~=target] {
} }
input[name~=text] { input[name~=text] {
width: 75%; width: 75%;
}
body {
height: 100%;
} }
</style> </style>
</head> </head>

View File

@ -35,18 +35,29 @@ func tail(w http.ResponseWriter, pos int) {
} }
defer f.Close() defer f.Close()
for {
_, err = f.Seek(int64(pos), 0) printid := false
if err != nil {
log.Fatal(err) _, 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) { func handleCommand(w http.ResponseWriter, text string, target string) {