divs in #messages are removed after set count maxes out. Default is 300

closes #20
This commit is contained in:
joeyak 2019-03-13 00:02:36 -04:00
parent 7f2c17f041
commit d77078edc3
4 changed files with 31 additions and 13 deletions

View File

@ -12,7 +12,6 @@ import (
"github.com/gorilla/websocket"
"github.com/nareix/joy4/av/avutil"
"github.com/nareix/joy4/av/pubsub"
//"github.com/nareix/joy4/format"
"github.com/nareix/joy4/format/flv"
"github.com/nareix/joy4/format/rtmp"
)
@ -143,14 +142,16 @@ func handleIndexTemplate(w http.ResponseWriter, r *http.Request) {
}
type Data struct {
Title string
Video, Chat bool
Video, Chat bool
MessageHistoryCount int
Title string
}
data := Data{
Title: "Movie Night!",
Video: true,
Chat: true,
Video: true,
Chat: true,
MessageHistoryCount: settings.MaxMessageCount,
Title: "Movie Night!",
}
path := strings.Split(strings.TrimLeft(r.URL.Path, "/"), "/")

View File

@ -14,12 +14,13 @@ var settings *Settings
var settingsMtx sync.Mutex
type Settings struct {
filename string
AdminPassword string
Bans []BanInfo
StreamKey string
ListenAddress string
cmdLineKey string // stream key from the command line
filename string
cmdLineKey string // stream key from the command line
MaxMessageCount int
AdminPassword string
Bans []BanInfo
StreamKey string
ListenAddress string
}
type BanInfo struct {
@ -57,6 +58,13 @@ func LoadSettings(filename string) (*Settings, error) {
}
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())
fmt.Printf("Settings reloaded. New admin password: %s\n", s.AdminPassword)

View File

@ -12,6 +12,7 @@
{{ if .Chat }}
<script>
maxMessageCount = {{ .MessageHistoryCount }}
window.onload = chatOnload;
</script>
<!-- If it is only the chat window, the the chat needs to be fullscreen -->

View File

@ -32,7 +32,6 @@ function setPlaying(title, link) {
$('#playinglink').attr('href', link);
}
function startGo() {
if (!WebAssembly.instantiateStreaming) { // polyfill
WebAssembly.instantiateStreaming = async (resp, importObject) => {
@ -57,7 +56,16 @@ function getWsUri() {
return "ws://" + window.location.hostname + ":" + port + "/ws"
}
let maxMessageCount = 0
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);
}