added inputs for interval/motion interval on the addStream page
This commit is contained in:
parent
f8b13dc3ef
commit
63aae590d5
3 changed files with 48 additions and 7 deletions
38
main.go
38
main.go
|
|
@ -7,6 +7,7 @@ import (
|
|||
"log"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
|
|
@ -47,21 +48,46 @@ func (server Server) index(w http.ResponseWriter, r *http.Request) {
|
|||
func (server Server) addStream(w http.ResponseWriter, r *http.Request) {
|
||||
nameMessage := ""
|
||||
URLMessage := ""
|
||||
intervalMessage := ""
|
||||
motionIntervalMessage := ""
|
||||
if r.Method == "POST" {
|
||||
name := r.FormValue("name")
|
||||
URL := r.FormValue("URL")
|
||||
interval := r.FormValue("interval")
|
||||
motionInterval := r.FormValue("motion_interval")
|
||||
if name == "" {
|
||||
nameMessage = "Name is required"
|
||||
}
|
||||
if URL == "" {
|
||||
URLMessage = "URL is required"
|
||||
}
|
||||
if interval == "" {
|
||||
intervalMessage = "Interval is required"
|
||||
}
|
||||
if motionInterval == "" {
|
||||
motionIntervalMessage = "MotionInterval is required"
|
||||
}
|
||||
_, exists := server.Streams[name]
|
||||
if exists {
|
||||
nameMessage = "Name already used"
|
||||
}
|
||||
if !exists && name != "" && URL != "" {
|
||||
server.Streams[name] = NewStream(name, URL)
|
||||
if !exists && name != "" && URL != "" && interval != "" && motionInterval != "" {
|
||||
intInterval, err := strconv.ParseInt(interval, 10, 64)
|
||||
if err != nil {
|
||||
log.Println("Illigal value for Interval: ", interval)
|
||||
intInterval = 5000
|
||||
}
|
||||
intMotionInterval, err := strconv.ParseInt(motionInterval, 10, 64)
|
||||
if err != nil {
|
||||
log.Println("Illigal value for MotionInterval: ", motionInterval)
|
||||
intMotionInterval = 1000
|
||||
}
|
||||
server.Streams[name] = NewStream(
|
||||
name,
|
||||
URL,
|
||||
(int)(intInterval),
|
||||
(int)(intMotionInterval),
|
||||
)
|
||||
go server.Streams[name].UpdateInterval()
|
||||
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
|
||||
}
|
||||
|
|
@ -73,11 +99,15 @@ func (server Server) addStream(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
addStreamTemplate.Execute(w, struct {
|
||||
NameMessage string
|
||||
URLMessage string
|
||||
NameMessage string
|
||||
URLMessage string
|
||||
IntervalMessage string
|
||||
MotionIntervalMessage string
|
||||
}{
|
||||
nameMessage,
|
||||
URLMessage,
|
||||
intervalMessage,
|
||||
motionIntervalMessage,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,15 +30,15 @@ type Stream struct {
|
|||
}
|
||||
|
||||
// NewStream creates a new Stream Object
|
||||
func NewStream(Name string, URL string) *Stream {
|
||||
func NewStream(Name string, URL string, Interval int, MotionInterval int) *Stream {
|
||||
base64 := URLToBase64(URL)
|
||||
|
||||
stream := Stream{
|
||||
Name: Name,
|
||||
URL: URL,
|
||||
Base64: base64,
|
||||
Interval: 5000,
|
||||
MotionInterval: 500,
|
||||
Interval: Interval,
|
||||
MotionInterval: MotionInterval,
|
||||
WatchAreas: make([]WatchArea, 0),
|
||||
Timeouts: 0,
|
||||
MotionDetected: false,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
{{template "base" .}}
|
||||
{{define "head"}}
|
||||
<script src="/static/js/add_stream.js"></script>
|
||||
{{end}}
|
||||
{{define "content"}}
|
||||
<h1>Add Stream</h1>
|
||||
|
|
@ -7,9 +8,19 @@
|
|||
<label for="name">Stream Name:</label>
|
||||
<input type="text" id="name" name="name" placeholder="Stream Name" size="30">
|
||||
<span class="pure-form-message">{{.NameMessage}}</span>
|
||||
|
||||
<label for="URL">URL:</label>
|
||||
<input type="text" id="URL" name="URL" placeholder="URL" size="100">
|
||||
<span class="pure-form-message">{{.URLMessage}}</span>
|
||||
|
||||
<label for="interval">Interval (MS):</label>
|
||||
<input type="number" id="interval" name="interval" onchange="intervalChange()" value="5000" min="100">
|
||||
<span class="pure-form-message">{{.IntervalMessage}}</span>
|
||||
|
||||
<label id="motion_interval_label" for="motion_interval">Motion Interval (MS): 1000</label>
|
||||
<input type="range" id="motion_interval" name="motion_interval" onchange="motionIntervalChange()" value="1000" min="50" max="5000">
|
||||
<span class="pure-form-message">{{.MotionIntervalMessage}}</span>
|
||||
|
||||
<button type="submit" class="pure-button pure-button-primary">Submit</button>
|
||||
</form>
|
||||
{{end}}
|
||||
Loading…
Add table
Reference in a new issue