From 286d775de665a5c39bf00205b09a57c68a540ccd Mon Sep 17 00:00:00 2001 From: Manu Mtz-Almeida Date: Thu, 14 May 2015 17:01:02 +0200 Subject: [PATCH] Updates realtime-advanced --- .../resources/room_login.templ.html | 15 +++++------- .../resources/static/realtime.js | 24 ++++++++----------- examples/realtime-advanced/routes.go | 2 ++ examples/realtime-advanced/stats.go | 1 + 4 files changed, 19 insertions(+), 23 deletions(-) diff --git a/examples/realtime-advanced/resources/room_login.templ.html b/examples/realtime-advanced/resources/room_login.templ.html index 9db0fbe8..0e55aaea 100644 --- a/examples/realtime-advanced/resources/room_login.templ.html +++ b/examples/realtime-advanced/resources/room_login.templ.html @@ -84,18 +84,11 @@ - {{end}} - -
- {{if .nick}} -

Inbound/Outbound

-
{{else}} -
+ Join the SSE real-time chat
- - +
@@ -103,6 +96,10 @@ {{end}}
+
+

Inbound/Outbound

+
+
diff --git a/examples/realtime-advanced/resources/static/realtime.js b/examples/realtime-advanced/resources/static/realtime.js index c5fb8b19..da4ae88c 100644 --- a/examples/realtime-advanced/resources/static/realtime.js +++ b/examples/realtime-advanced/resources/static/realtime.js @@ -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) { @@ -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) { diff --git a/examples/realtime-advanced/routes.go b/examples/realtime-advanced/routes.go index a869079e..9762f52c 100644 --- a/examples/realtime-advanced/routes.go +++ b/examples/realtime-advanced/routes.go @@ -3,6 +3,7 @@ package main import ( "html" "io" + "strings" "time" "github.com/gin-gonic/gin" @@ -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 diff --git a/examples/realtime-advanced/stats.go b/examples/realtime-advanced/stats.go index 29371a48..f3ccab38 100644 --- a/examples/realtime-advanced/stats.go +++ b/examples/realtime-advanced/stats.go @@ -26,6 +26,7 @@ func statsWorker() { "Inbound": uint64(messages.Get("inbound")), "Outbound": uint64(messages.Get("outbound")), } + messages.Reset() mutexStats.Unlock() } }