Skip to content

Commit

Permalink
Hikvision: fix delayed events
Browse files Browse the repository at this point in the history
  • Loading branch information
toxuin committed Sep 20, 2022
1 parent f485aca commit a486ef5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion servers/dahua/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ func (camera *DhCamera) readEvents(channel chan<- DhEvent, callback func()) {
multipartReader := multipart.NewReader(response.Body, multipartBoundary)
for {
part, err := multipartReader.NextPart()
contentLength, _ := strconv.Atoi(part.Header.Get("Content-Length"))
if err == io.EOF {
break
}
if err != nil {
fmt.Println(err)
continue
}
contentLength, _ := strconv.Atoi(part.Header.Get("Content-Length"))
body := make([]byte, contentLength)
_, err = part.Read(body)
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion servers/hikvision/httpEventReader.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"mime"
"mime/multipart"
"net/http"
"strconv"
)

type HttpEventReader struct {
Expand Down Expand Up @@ -73,7 +74,9 @@ func (eventReader *HttpEventReader) ReadEvents(camera *HikCamera, channel chan<-
fmt.Println(err)
continue
}
body, err := io.ReadAll(part)
contentLength, _ := strconv.Atoi(part.Header.Get("Content-Length"))
body := make([]byte, contentLength)
_, err = part.Read(body)
if err != nil {
fmt.Println(err)
continue
Expand Down

0 comments on commit a486ef5

Please sign in to comment.