forked from mirror/gin
Updates realtime-advanced
This commit is contained in:
parent
58ceb244e5
commit
286d775de6
|
@ -84,18 +84,11 @@
|
||||||
</div>
|
</div>
|
||||||
<input type="submit" class="btn btn-primary" value="Send" />
|
<input type="submit" class="btn btn-primary" value="Send" />
|
||||||
</form>
|
</form>
|
||||||
{{end}}
|
|
||||||
</div>
|
|
||||||
<div class="col-md-4">
|
|
||||||
{{if .nick}}
|
|
||||||
<h3>Inbound/Outbound</h3>
|
|
||||||
<div id="messagesChart" class="epoch category20c"></div>
|
|
||||||
{{else}}
|
{{else}}
|
||||||
<form action="" method="get">
|
<form action="" method="get" class="form-inline">
|
||||||
<legend>Join the SSE real-time chat</legend>
|
<legend>Join the SSE real-time chat</legend>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="nick">Your Name</label>
|
<input value='' name="nick" id="nick" placeholder="Your Name" type="text" class="form-control" />
|
||||||
<input value='' name="nick" id="nick" placeholder="John" type="text" class="form-control" />
|
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group text-center">
|
<div class="form-group text-center">
|
||||||
<input type="submit" class="btn btn-success btn-login-submit" value="Join" />
|
<input type="submit" class="btn btn-success btn-login-submit" value="Join" />
|
||||||
|
@ -103,6 +96,10 @@
|
||||||
</form>
|
</form>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
<h3>Inbound/Outbound</h3>
|
||||||
|
<div id="messagesChart" class="epoch category20c"></div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -47,7 +47,6 @@ function StartEpoch(timestamp) {
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
if($('#messagesChart').length ) {
|
|
||||||
window.messagesChart = $('#messagesChart').epoch({
|
window.messagesChart = $('#messagesChart').epoch({
|
||||||
type: 'time.area',
|
type: 'time.area',
|
||||||
axes: ['bottom', 'left'],
|
axes: ['bottom', 'left'],
|
||||||
|
@ -58,7 +57,6 @@ function StartEpoch(timestamp) {
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function StartSSE(roomid) {
|
function StartSSE(roomid) {
|
||||||
if (!window.EventSource) {
|
if (!window.EventSource) {
|
||||||
|
@ -75,10 +73,8 @@ function stats(e) {
|
||||||
heapChart.push(data.heap)
|
heapChart.push(data.heap)
|
||||||
mallocsChart.push(data.mallocs)
|
mallocsChart.push(data.mallocs)
|
||||||
goroutinesChart.push(data.goroutines)
|
goroutinesChart.push(data.goroutines)
|
||||||
if (typeof messagesChart !== 'undefined') {
|
|
||||||
messagesChart.push(data.messages)
|
messagesChart.push(data.messages)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function parseJSONStats(e) {
|
function parseJSONStats(e) {
|
||||||
var data = jQuery.parseJSON(e);
|
var data = jQuery.parseJSON(e);
|
||||||
|
|
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"html"
|
"html"
|
||||||
"io"
|
"io"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
@ -33,6 +34,7 @@ func roomPOST(c *gin.Context) {
|
||||||
roomid := c.ParamValue("roomid")
|
roomid := c.ParamValue("roomid")
|
||||||
nick := c.FormValue("nick")
|
nick := c.FormValue("nick")
|
||||||
message := c.PostFormValue("message")
|
message := c.PostFormValue("message")
|
||||||
|
message = strings.TrimSpace(message)
|
||||||
|
|
||||||
validMessage := len(message) > 1 && len(message) < 200
|
validMessage := len(message) > 1 && len(message) < 200
|
||||||
validNick := len(nick) > 1 && len(nick) < 14
|
validNick := len(nick) > 1 && len(nick) < 14
|
||||||
|
|
|
@ -26,6 +26,7 @@ func statsWorker() {
|
||||||
"Inbound": uint64(messages.Get("inbound")),
|
"Inbound": uint64(messages.Get("inbound")),
|
||||||
"Outbound": uint64(messages.Get("outbound")),
|
"Outbound": uint64(messages.Get("outbound")),
|
||||||
}
|
}
|
||||||
|
messages.Reset()
|
||||||
mutexStats.Unlock()
|
mutexStats.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue