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
34
main.go
34
main.go
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
"text/template"
|
"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) {
|
func (server Server) addStream(w http.ResponseWriter, r *http.Request) {
|
||||||
nameMessage := ""
|
nameMessage := ""
|
||||||
URLMessage := ""
|
URLMessage := ""
|
||||||
|
intervalMessage := ""
|
||||||
|
motionIntervalMessage := ""
|
||||||
if r.Method == "POST" {
|
if r.Method == "POST" {
|
||||||
name := r.FormValue("name")
|
name := r.FormValue("name")
|
||||||
URL := r.FormValue("URL")
|
URL := r.FormValue("URL")
|
||||||
|
interval := r.FormValue("interval")
|
||||||
|
motionInterval := r.FormValue("motion_interval")
|
||||||
if name == "" {
|
if name == "" {
|
||||||
nameMessage = "Name is required"
|
nameMessage = "Name is required"
|
||||||
}
|
}
|
||||||
if URL == "" {
|
if URL == "" {
|
||||||
URLMessage = "URL is required"
|
URLMessage = "URL is required"
|
||||||
}
|
}
|
||||||
|
if interval == "" {
|
||||||
|
intervalMessage = "Interval is required"
|
||||||
|
}
|
||||||
|
if motionInterval == "" {
|
||||||
|
motionIntervalMessage = "MotionInterval is required"
|
||||||
|
}
|
||||||
_, exists := server.Streams[name]
|
_, exists := server.Streams[name]
|
||||||
if exists {
|
if exists {
|
||||||
nameMessage = "Name already used"
|
nameMessage = "Name already used"
|
||||||
}
|
}
|
||||||
if !exists && name != "" && URL != "" {
|
if !exists && name != "" && URL != "" && interval != "" && motionInterval != "" {
|
||||||
server.Streams[name] = NewStream(name, URL)
|
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()
|
go server.Streams[name].UpdateInterval()
|
||||||
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
|
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
|
||||||
}
|
}
|
||||||
|
|
@ -75,9 +101,13 @@ func (server Server) addStream(w http.ResponseWriter, r *http.Request) {
|
||||||
addStreamTemplate.Execute(w, struct {
|
addStreamTemplate.Execute(w, struct {
|
||||||
NameMessage string
|
NameMessage string
|
||||||
URLMessage string
|
URLMessage string
|
||||||
|
IntervalMessage string
|
||||||
|
MotionIntervalMessage string
|
||||||
}{
|
}{
|
||||||
nameMessage,
|
nameMessage,
|
||||||
URLMessage,
|
URLMessage,
|
||||||
|
intervalMessage,
|
||||||
|
motionIntervalMessage,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,15 +30,15 @@ type Stream struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewStream creates a new Stream Object
|
// 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)
|
base64 := URLToBase64(URL)
|
||||||
|
|
||||||
stream := Stream{
|
stream := Stream{
|
||||||
Name: Name,
|
Name: Name,
|
||||||
URL: URL,
|
URL: URL,
|
||||||
Base64: base64,
|
Base64: base64,
|
||||||
Interval: 5000,
|
Interval: Interval,
|
||||||
MotionInterval: 500,
|
MotionInterval: MotionInterval,
|
||||||
WatchAreas: make([]WatchArea, 0),
|
WatchAreas: make([]WatchArea, 0),
|
||||||
Timeouts: 0,
|
Timeouts: 0,
|
||||||
MotionDetected: false,
|
MotionDetected: false,
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
{{template "base" .}}
|
{{template "base" .}}
|
||||||
{{define "head"}}
|
{{define "head"}}
|
||||||
|
<script src="/static/js/add_stream.js"></script>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{define "content"}}
|
{{define "content"}}
|
||||||
<h1>Add Stream</h1>
|
<h1>Add Stream</h1>
|
||||||
|
|
@ -7,9 +8,19 @@
|
||||||
<label for="name">Stream Name:</label>
|
<label for="name">Stream Name:</label>
|
||||||
<input type="text" id="name" name="name" placeholder="Stream Name" size="30">
|
<input type="text" id="name" name="name" placeholder="Stream Name" size="30">
|
||||||
<span class="pure-form-message">{{.NameMessage}}</span>
|
<span class="pure-form-message">{{.NameMessage}}</span>
|
||||||
|
|
||||||
<label for="URL">URL:</label>
|
<label for="URL">URL:</label>
|
||||||
<input type="text" id="URL" name="URL" placeholder="URL" size="100">
|
<input type="text" id="URL" name="URL" placeholder="URL" size="100">
|
||||||
<span class="pure-form-message">{{.URLMessage}}</span>
|
<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>
|
<button type="submit" class="pure-button pure-button-primary">Submit</button>
|
||||||
</form>
|
</form>
|
||||||
{{end}}
|
{{end}}
|
||||||
Loading…
Add table
Reference in a new issue