Skip to content

Commit

Permalink
Updates realtime-advanced
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed May 14, 2015
1 parent 0076556 commit 3b2d56a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 23 deletions.
15 changes: 6 additions & 9 deletions realtime-advanced/resources/room_login.templ.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,22 @@ <h1>Server-Sent Events in Go</h1>
</div>
<input type="submit" class="btn btn-primary" value="Send" />
</form>
{{end}}
</div>
<div class="col-md-4">
{{if .nick}}
<h3>Inbound/Outbound</h3>
<div id="messagesChart" class="epoch category20c"></div>
{{else}}
<form action="" method="get">
<form action="" method="get" class="form-inline">
<legend>Join the SSE real-time chat</legend>
<div class="form-group">
<label for="nick">Your Name</label>
<input value='' name="nick" id="nick" placeholder="John" type="text" class="form-control" />
<input value='' name="nick" id="nick" placeholder="Your Name" type="text" class="form-control" />
</div>
<div class="form-group text-center">
<input type="submit" class="btn btn-success btn-login-submit" value="Join" />
</div>
</form>
{{end}}
</div>
<div class="col-md-4">
<h3>Inbound/Outbound</h3>
<div id="messagesChart" class="epoch category20c"></div>
</div>
</div>
</div>
</div>
Expand Down
24 changes: 10 additions & 14 deletions realtime-advanced/resources/static/realtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,15 @@ function StartEpoch(timestamp) {
]
});

if($('#messagesChart').length ) {
window.messagesChart = $('#messagesChart').epoch({
type: 'time.area',
axes: ['bottom', 'left'],
height: 250,
data: [
{values: defaultData},
{values: defaultData}
]
});
}
window.messagesChart = $('#messagesChart').epoch({
type: 'time.area',
axes: ['bottom', 'left'],
height: 250,
data: [
{values: defaultData},
{values: defaultData}
]
});
}

function StartSSE(roomid) {
Expand All @@ -75,9 +73,7 @@ function stats(e) {
heapChart.push(data.heap)
mallocsChart.push(data.mallocs)
goroutinesChart.push(data.goroutines)
if (typeof messagesChart !== 'undefined') {
messagesChart.push(data.messages)
}
messagesChart.push(data.messages)
}

function parseJSONStats(e) {
Expand Down
2 changes: 2 additions & 0 deletions realtime-advanced/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"html"
"io"
"strings"
"time"

"github.com/gin-gonic/gin"
Expand Down Expand Up @@ -33,6 +34,7 @@ func roomPOST(c *gin.Context) {
roomid := c.ParamValue("roomid")
nick := c.FormValue("nick")
message := c.PostFormValue("message")
message = strings.TrimSpace(message)

validMessage := len(message) > 1 && len(message) < 200
validNick := len(nick) > 1 && len(nick) < 14
Expand Down
1 change: 1 addition & 0 deletions realtime-advanced/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func statsWorker() {
"Inbound": uint64(messages.Get("inbound")),
"Outbound": uint64(messages.Get("outbound")),
}
messages.Reset()
mutexStats.Unlock()
}
}
Expand Down

0 comments on commit 3b2d56a

Please sign in to comment.