diff --git a/handlers.go b/handlers.go index b046793..93b1337 100644 --- a/handlers.go +++ b/handlers.go @@ -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, "/"), "/") diff --git a/settings.go b/settings.go index 8320341..8ef017a 100644 --- a/settings.go +++ b/settings.go @@ -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) diff --git a/static/index.html b/static/index.html index 7fd8a9a..69fb7a8 100644 --- a/static/index.html +++ b/static/index.html @@ -12,6 +12,7 @@ {{ if .Chat }} diff --git a/static/js/client.js b/static/js/client.js index e937ba7..468ff63 100644 --- a/static/js/client.js +++ b/static/js/client.js @@ -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); }