divs in #messages are removed after set count maxes out. Default is 300
closes #20
This commit is contained in:
parent
7f2c17f041
commit
d77078edc3
13
handlers.go
13
handlers.go
|
@ -12,7 +12,6 @@ import (
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/nareix/joy4/av/avutil"
|
"github.com/nareix/joy4/av/avutil"
|
||||||
"github.com/nareix/joy4/av/pubsub"
|
"github.com/nareix/joy4/av/pubsub"
|
||||||
//"github.com/nareix/joy4/format"
|
|
||||||
"github.com/nareix/joy4/format/flv"
|
"github.com/nareix/joy4/format/flv"
|
||||||
"github.com/nareix/joy4/format/rtmp"
|
"github.com/nareix/joy4/format/rtmp"
|
||||||
)
|
)
|
||||||
|
@ -143,14 +142,16 @@ func handleIndexTemplate(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Data struct {
|
type Data struct {
|
||||||
Title string
|
Video, Chat bool
|
||||||
Video, Chat bool
|
MessageHistoryCount int
|
||||||
|
Title string
|
||||||
}
|
}
|
||||||
|
|
||||||
data := Data{
|
data := Data{
|
||||||
Title: "Movie Night!",
|
Video: true,
|
||||||
Video: true,
|
Chat: true,
|
||||||
Chat: true,
|
MessageHistoryCount: settings.MaxMessageCount,
|
||||||
|
Title: "Movie Night!",
|
||||||
}
|
}
|
||||||
|
|
||||||
path := strings.Split(strings.TrimLeft(r.URL.Path, "/"), "/")
|
path := strings.Split(strings.TrimLeft(r.URL.Path, "/"), "/")
|
||||||
|
|
20
settings.go
20
settings.go
|
@ -14,12 +14,13 @@ var settings *Settings
|
||||||
var settingsMtx sync.Mutex
|
var settingsMtx sync.Mutex
|
||||||
|
|
||||||
type Settings struct {
|
type Settings struct {
|
||||||
filename string
|
filename string
|
||||||
AdminPassword string
|
cmdLineKey string // stream key from the command line
|
||||||
Bans []BanInfo
|
MaxMessageCount int
|
||||||
StreamKey string
|
AdminPassword string
|
||||||
ListenAddress string
|
Bans []BanInfo
|
||||||
cmdLineKey string // stream key from the command line
|
StreamKey string
|
||||||
|
ListenAddress string
|
||||||
}
|
}
|
||||||
|
|
||||||
type BanInfo struct {
|
type BanInfo struct {
|
||||||
|
@ -57,6 +58,13 @@ func LoadSettings(filename string) (*Settings, error) {
|
||||||
}
|
}
|
||||||
s.filename = filename
|
s.filename = filename
|
||||||
|
|
||||||
|
// have a default of 200
|
||||||
|
if s.MaxMessageCount == 0 {
|
||||||
|
s.MaxMessageCount = 300
|
||||||
|
} else if s.MaxMessageCount < 0 {
|
||||||
|
return s, fmt.Errorf("the MaxMessageCount value must be greater than 0, given %d", s.MaxMessageCount)
|
||||||
|
}
|
||||||
|
|
||||||
s.AdminPassword = generateAdminPass(time.Now().Unix())
|
s.AdminPassword = generateAdminPass(time.Now().Unix())
|
||||||
fmt.Printf("Settings reloaded. New admin password: %s\n", s.AdminPassword)
|
fmt.Printf("Settings reloaded. New admin password: %s\n", s.AdminPassword)
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
{{ if .Chat }}
|
{{ if .Chat }}
|
||||||
<script>
|
<script>
|
||||||
|
maxMessageCount = {{ .MessageHistoryCount }}
|
||||||
window.onload = chatOnload;
|
window.onload = chatOnload;
|
||||||
</script>
|
</script>
|
||||||
<!-- If it is only the chat window, the the chat needs to be fullscreen -->
|
<!-- If it is only the chat window, the the chat needs to be fullscreen -->
|
||||||
|
|
|
@ -32,7 +32,6 @@ function setPlaying(title, link) {
|
||||||
$('#playinglink').attr('href', link);
|
$('#playinglink').attr('href', link);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function startGo() {
|
function startGo() {
|
||||||
if (!WebAssembly.instantiateStreaming) { // polyfill
|
if (!WebAssembly.instantiateStreaming) { // polyfill
|
||||||
WebAssembly.instantiateStreaming = async (resp, importObject) => {
|
WebAssembly.instantiateStreaming = async (resp, importObject) => {
|
||||||
|
@ -57,7 +56,16 @@ function getWsUri() {
|
||||||
return "ws://" + window.location.hostname + ":" + port + "/ws"
|
return "ws://" + window.location.hostname + ":" + port + "/ws"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let maxMessageCount = 0
|
||||||
function appendMessages(msg) {
|
function appendMessages(msg) {
|
||||||
|
let msgs = $("#messages").find('div')
|
||||||
|
|
||||||
|
// let's just say that if the max count is less than 1, then the count is infinite
|
||||||
|
// the server side should take care of chaking max count ranges
|
||||||
|
if (msgs.length > maxMessageCount) {
|
||||||
|
msgs.first().remove()
|
||||||
|
}
|
||||||
|
|
||||||
$("#messages").append(msg).scrollTop(9e6);
|
$("#messages").append(msg).scrollTop(9e6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue