From e5f8016d2657da412c60baa9686448409f97ebf3 Mon Sep 17 00:00:00 2001 From: gferraro Date: Fri, 20 Sep 2024 17:10:08 +0200 Subject: [PATCH 01/10] add audio seed --- Makefile | 4 ++-- api/audiorecording.go | 21 ++++++++++++++++++ go.mod | 20 ++++++++--------- go.sum | 44 +++++++++++++++++-------------------- html/audiorecording.html | 9 ++++++++ static/js/audiorecording.ts | 14 +++++++++++- 6 files changed, 75 insertions(+), 37 deletions(-) diff --git a/Makefile b/Makefile index b5a9e5a..ccad0ea 100644 --- a/Makefile +++ b/Makefile @@ -13,8 +13,8 @@ build: install-packr install-typescript .PHONY: install-typescript install-typescript: - npm install -g typescript - npm install -g rollup + npm install typescript + npm install rollup npm i @types/jquery npx tsc diff --git a/api/audiorecording.go b/api/audiorecording.go index 83e61e5..3b6eb71 100644 --- a/api/audiorecording.go +++ b/api/audiorecording.go @@ -21,6 +21,7 @@ package api import ( "encoding/json" "net/http" + "strconv" goconfig "github.com/TheCacophonyProject/go-config" "github.com/godbus/dbus" @@ -34,6 +35,7 @@ func (api *ManagementAPI) GetAudioRecording(w http.ResponseWriter, r *http.Reque } type AudioRecording struct { AudioMode string `json:"audio-mode"` + AudioSeed string `json:"audio-seed"` } w.WriteHeader(http.StatusOK) @@ -46,9 +48,28 @@ func (api *ManagementAPI) GetAudioRecording(w http.ResponseWriter, r *http.Reque func (api *ManagementAPI) SetAudioRecording(w http.ResponseWriter, r *http.Request) { log.Println("update audio recording") audioMode := r.FormValue("audio-mode") + stringSeed := r.FormValue("audio-seed") + var audioSeed uint32 + log.Printf("Audio seeds is %v", stringSeed) + if stringSeed == "" { + audioSeed = 0 + log.Printf("Set empty") + + } else { + log.Printf("try parse") + + seed, err := strconv.ParseUint(r.FormValue("audio-seed"), 10, 32) + if err != nil { + badRequest(&w, err) + return + } + audioSeed = uint32(seed) + + } audioRecording := goconfig.AudioRecording{ AudioMode: audioMode, + AudioSeed: audioSeed, } if err := api.config.Set(goconfig.AudioRecordingKey, &audioRecording); err != nil { diff --git a/go.mod b/go.mod index cc54b73..2526549 100644 --- a/go.mod +++ b/go.mod @@ -5,8 +5,8 @@ go 1.22.3 require ( github.com/TheCacophonyProject/audiobait/v3 v3.0.1 github.com/TheCacophonyProject/event-reporter v1.3.2-0.20200210010421-ca3fcb76a231 - github.com/TheCacophonyProject/go-api v1.2.0 - github.com/TheCacophonyProject/go-config v1.18.0 + github.com/TheCacophonyProject/go-api v1.2.1 + github.com/TheCacophonyProject/go-config v1.21.0 github.com/TheCacophonyProject/go-cptv v0.0.0-20211109233846-8c32a5d161f7 github.com/TheCacophonyProject/lepton3 v0.0.0-20211005194419-22311c15d6ee github.com/TheCacophonyProject/rtc-utils v1.2.0 @@ -25,12 +25,12 @@ require ( github.com/TheCacophonyProject/trap-controller v0.0.0-20230227002937-262a1adfaa47 github.com/alexflint/go-arg v1.4.3 github.com/sirupsen/logrus v1.9.3 - golang.org/x/text v0.16.0 + golang.org/x/text v0.18.0 ) require ( - github.com/TheCacophonyProject/event-reporter/v3 v3.7.0 // indirect + github.com/TheCacophonyProject/event-reporter/v3 v3.8.1 // indirect github.com/TheCacophonyProject/window v0.0.0-20200312071457-7fc8799fdce7 // indirect github.com/alexflint/go-scalar v1.1.0 // indirect github.com/boltdb/bolt v1.3.1 // indirect @@ -38,26 +38,26 @@ require ( github.com/gobuffalo/envy v1.10.2 // indirect github.com/gobuffalo/packd v1.0.2 // indirect github.com/godbus/dbus/v5 v5.1.0 // indirect - github.com/gofrs/flock v0.8.1 // indirect + github.com/gofrs/flock v0.12.1 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/joho/godotenv v1.5.1 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/pelletier/go-toml v1.9.5 // indirect - github.com/pelletier/go-toml/v2 v2.2.2 // indirect + github.com/pelletier/go-toml/v2 v2.2.3 // indirect github.com/rogpeppe/go-internal v1.11.0 // indirect github.com/sagikazarmark/locafero v0.6.0 // indirect github.com/sagikazarmark/slog-shim v0.1.0 // indirect github.com/sourcegraph/conc v0.3.0 // indirect github.com/spf13/afero v1.11.0 // indirect - github.com/spf13/cast v1.6.0 // indirect + github.com/spf13/cast v1.7.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/viper v1.19.0 // indirect github.com/subosito/gotenv v1.6.0 // indirect go.uber.org/multierr v1.11.0 // indirect - golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 // indirect - golang.org/x/mod v0.18.0 // indirect - golang.org/x/sys v0.21.0 // indirect + golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect + golang.org/x/mod v0.21.0 // indirect + golang.org/x/sys v0.25.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637 // indirect gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0 // indirect diff --git a/go.sum b/go.sum index ea4327c..24caf58 100644 --- a/go.sum +++ b/go.sum @@ -53,19 +53,18 @@ github.com/TheCacophonyProject/audiobait/v3 v3.0.1/go.mod h1:EDM0fyF6oHPUmtOfY4Q github.com/TheCacophonyProject/event-reporter v1.3.2-0.20200210010421-ca3fcb76a231 h1:nLqfSx3zDBzghlP/S8X2j/WRtW0e3BZvSkMm1J/Fa8U= github.com/TheCacophonyProject/event-reporter v1.3.2-0.20200210010421-ca3fcb76a231/go.mod h1:kei6S/4x+VHp5yiwYPqvcNnhuRpZ8iLsh95Sue6kPvc= github.com/TheCacophonyProject/event-reporter/v3 v3.3.0/go.mod h1:dGIYfhABsJHKjcsxtftDwpdcfLOWTYKeIyCYxCOIMrc= -github.com/TheCacophonyProject/event-reporter/v3 v3.7.0 h1:B+a5PXqBh7Bkf2HDo+j94Ascqw6SCTlOhSN9TXZfjY8= -github.com/TheCacophonyProject/event-reporter/v3 v3.7.0/go.mod h1:WTppJtTBxduasM1Or5SAh4Mm0YrTDnprOChjnGYgyEI= +github.com/TheCacophonyProject/event-reporter/v3 v3.8.1 h1:iBiRlg+hHMNw2OCbsljoG7FSf6RIj0sNbsCG1ZEjDsc= +github.com/TheCacophonyProject/event-reporter/v3 v3.8.1/go.mod h1:yHG7Jw48+j65rJNVQmg9oRoqSpYYiq5QxAWdcuEUKEc= github.com/TheCacophonyProject/go-api v0.0.0-20190923033957-174cea2ac81c/go.mod h1:FfMpa4cFhNXQ9tuKG18HO6yLExezcJhzjUjBOFocrQw= -github.com/TheCacophonyProject/go-api v1.0.4/go.mod h1:F7UUNgsLhbw7hsiNBMRB9kQz9uXXosVmNToqImz7EA8= -github.com/TheCacophonyProject/go-api v1.2.0 h1:5cEUlv3Xe8T4SuLmIPK2ppkPt/Mi41OSvp/vCPPUxuY= -github.com/TheCacophonyProject/go-api v1.2.0/go.mod h1:F7UUNgsLhbw7hsiNBMRB9kQz9uXXosVmNToqImz7EA8= +github.com/TheCacophonyProject/go-api v1.2.1 h1:QS8mzStQHzb3oAqqwjoLqCvXsRM8fx7F9I7hpgKND5c= +github.com/TheCacophonyProject/go-api v1.2.1/go.mod h1:F7UUNgsLhbw7hsiNBMRB9kQz9uXXosVmNToqImz7EA8= github.com/TheCacophonyProject/go-config v0.0.0-20190922224052-7c2a21bc6b88/go.mod h1:gPUJLVu408NRz9/P3BrsxzOzLc+KJLrv+jVdDw3RI0Y= github.com/TheCacophonyProject/go-config v0.0.0-20190927054511-c93578ae648a/go.mod h1:QCgT+KCrz1CmLVpeeOMl5L8/X1QvWwpsLzR7afTmEJc= github.com/TheCacophonyProject/go-config v1.4.0/go.mod h1:oARW/N3eJbcewCqB+Jc7TBwuODawwYgpo56UO6yBdKU= github.com/TheCacophonyProject/go-config v1.6.4/go.mod h1:eDQfBjmTDh/l+2QLBgsotmJFd/1x/7w4SwwBUxMM86w= github.com/TheCacophonyProject/go-config v1.9.0/go.mod h1:+y80PSRZudMYuVrYTGOvzc66NxVJWKS4TuU442vmvhY= -github.com/TheCacophonyProject/go-config v1.18.0 h1:R3zOjfHBxsI8t5J7PSuv6Wb5xwj2LPMC8vqD+d5Azd8= -github.com/TheCacophonyProject/go-config v1.18.0/go.mod h1:XZwQmNl2wQXhYR18RQtwZ6LwFwgAx73yzJfymYLz68s= +github.com/TheCacophonyProject/go-config v1.21.0 h1:t0uMbLXaKydWJSFTrK76sTECqbwXYj9OIQK4OXUmr3I= +github.com/TheCacophonyProject/go-config v1.21.0/go.mod h1:Nf1iBI/gqYf7UCcUZezO7bj9hzY2jRPdzDW+kOI9/Fo= github.com/TheCacophonyProject/go-cptv v0.0.0-20200116020937-858bd8b71512/go.mod h1:8H6Aaft5549sIWxcsuCIL2o60/TQkoF93fVoSTpgZb8= github.com/TheCacophonyProject/go-cptv v0.0.0-20200616224711-fc633122087a/go.mod h1:Vg73Ezn4kr8qDNP9LNgjki9qgi+5T/0Uc9oDyflaYUY= github.com/TheCacophonyProject/go-cptv v0.0.0-20200818214604-bd5d4aa36043/go.mod h1:wG4/P/TsGtk33uBClYPjRlSbcdQrIASXutOUV8LMn2o= @@ -81,7 +80,6 @@ github.com/TheCacophonyProject/lepton3 v0.0.0-20211005194419-22311c15d6ee h1:whi github.com/TheCacophonyProject/lepton3 v0.0.0-20211005194419-22311c15d6ee/go.mod h1:+FTQKx63hdEbuTe/nxNv9TQ2EWqdlzMZx7UNLGCX9SE= github.com/TheCacophonyProject/modemd v0.0.0-20190605010435-ae5b0f2eb760/go.mod h1:bfwJ/WcvDY9XtHKC5tcRfVrU8RWaW8DLYAAUfsrJr/4= github.com/TheCacophonyProject/modemd v0.0.0-20190708011609-1940f5b6677b/go.mod h1:txGgnRinv6H0/jB4n71MpuS+2qtu8tAlntIjY5udXDU= -github.com/TheCacophonyProject/modemd v1.6.0/go.mod h1:0M7yJCdqhvoI5dVeDjOH6vsmbOBr1YhZ8DpAK4AkOA0= github.com/TheCacophonyProject/periph v2.1.1-0.20200615222341-6834cd5be8c1+incompatible h1:0pEn1FoMTgOZR3EkqOTiqd0++jOS/jWlGrbvOHK0/KM= github.com/TheCacophonyProject/periph v2.1.1-0.20200615222341-6834cd5be8c1+incompatible/go.mod h1:K1wa07sGXKzV0G9p+4R069mZk4GOpqKW8GU6/k+BrIo= github.com/TheCacophonyProject/rpi-net-manager v0.4.0-deb12 h1:0EowolSaXYxt8DOlVT+fCPNWf+HQoK5YoI3YLbUu8Dk= @@ -192,8 +190,9 @@ github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5x github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk= github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gofrs/flock v0.7.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU= -github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw= github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU= +github.com/gofrs/flock v0.12.1 h1:MTLVXXHf8ekldpJk3AKicLij9MdwOWkZ+a/jHHZby9E= +github.com/gofrs/flock v0.12.1/go.mod h1:9zxTsyu5xtJ9DK+1tFZyibEV7y3uwDxPPfbxeeHCoD0= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= @@ -372,8 +371,8 @@ github.com/pelletier/go-toml v1.6.0/go.mod h1:5N711Q9dKgbdkxHL+MEfF31hpT7l0S0s/t github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8= github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= -github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= -github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= +github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M= +github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -427,8 +426,8 @@ github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY= github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cast v1.4.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= -github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= -github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= +github.com/spf13/cast v1.7.0 h1:ntdiHjuueXFgm5nzDRdOS4yfT43P5Fnud6DH50rz/7w= +github.com/spf13/cast v1.7.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= @@ -444,8 +443,6 @@ github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= @@ -454,7 +451,6 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= @@ -514,8 +510,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0 golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= -golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 h1:yixxcjnhBmY0nkL253HFVIm0JsFHwrHdT3Yh6szTnfY= -golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8/go.mod h1:jj3sYF3dwk5D+ghuXyeI3r5MFf+NT2An6/9dOA95KSI= +golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 h1:e66Fs6Z+fZTbFBAxKfP3PALWBtpfqks2bwGcexMxgtk= +golang.org/x/exp v0.0.0-20240909161429-701f63a606c0/go.mod h1:2TbTHSBQa924w8M6Xs1QcRcFwyucIwBGpK1p2f1YFFY= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -541,8 +537,8 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0= -golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0= +golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -680,8 +676,8 @@ golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211117180635-dee7805ff2e1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= -golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= +golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -692,8 +688,8 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= -golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= +golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= diff --git a/html/audiorecording.html b/html/audiorecording.html index a562046..c936bc2 100644 --- a/html/audiorecording.html +++ b/html/audiorecording.html @@ -40,6 +40,15 @@

Audio Recording

+
+
+ + +
+ + +
+
diff --git a/static/js/audiorecording.ts b/static/js/audiorecording.ts index 4c19969..3acae58 100644 --- a/static/js/audiorecording.ts +++ b/static/js/audiorecording.ts @@ -164,7 +164,9 @@ function updateAudio() { data["audio-mode"] = ( document.getElementById("audio-mode-select") as HTMLSelectElement ).value; - + data["audio-seed"] = ( + document.getElementById("audio-seed") as HTMLInputElement + ).value; var xmlHttp = new XMLHttpRequest(); xmlHttp.open("POST", "/api/audiorecording", true); xmlHttp.setRequestHeader("Authorization", "Basic " + btoa("admin:feathers")); @@ -204,4 +206,14 @@ function updateAudioError(xmlHttp: XMLHttpRequest) { window.onload = async function () { getAudioStatus(); + document + .getElementById("updateBtn") + ?.addEventListener("click", updateAudio, false); + + const audioseed = (document.getElementById("audio-seed") as HTMLInputElement) + .value; + if (Number(audioseed) == 0) { + // @ts-ignore + (document.getElementById("audio-seed") as HTMLInputElement).value = null; + } }; From c1fc77cf2c739966a3f77727fac3219bdb5edbe2 Mon Sep 17 00:00:00 2001 From: gferraro Date: Fri, 20 Sep 2024 17:24:05 +0200 Subject: [PATCH 02/10] rmeove logs --- api/audiorecording.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/api/audiorecording.go b/api/audiorecording.go index 3b6eb71..dd989dd 100644 --- a/api/audiorecording.go +++ b/api/audiorecording.go @@ -50,28 +50,21 @@ func (api *ManagementAPI) SetAudioRecording(w http.ResponseWriter, r *http.Reque audioMode := r.FormValue("audio-mode") stringSeed := r.FormValue("audio-seed") var audioSeed uint32 - log.Printf("Audio seeds is %v", stringSeed) if stringSeed == "" { audioSeed = 0 - log.Printf("Set empty") - } else { - log.Printf("try parse") - seed, err := strconv.ParseUint(r.FormValue("audio-seed"), 10, 32) if err != nil { badRequest(&w, err) return } audioSeed = uint32(seed) - } audioRecording := goconfig.AudioRecording{ AudioMode: audioMode, AudioSeed: audioSeed, } - if err := api.config.Set(goconfig.AudioRecordingKey, &audioRecording); err != nil { serverError(&w, err) } From e492e9e82698e604585948c7d37c1a394aa677d9 Mon Sep 17 00:00:00 2001 From: gferraro Date: Sun, 22 Sep 2024 22:22:14 +0200 Subject: [PATCH 03/10] add audio seed stuff --- html/audiorecording.html | 12 ++++++------ static/js/audiorecording.ts | 3 +++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/html/audiorecording.html b/html/audiorecording.html index c936bc2..d477e26 100644 --- a/html/audiorecording.html +++ b/html/audiorecording.html @@ -31,7 +31,7 @@

Audio Recording

- @@ -42,24 +42,24 @@

Audio Recording

- + +
- +
- +
+

Test Recording

-
-
diff --git a/static/js/audiorecording.ts b/static/js/audiorecording.ts index 3acae58..4d07578 100644 --- a/static/js/audiorecording.ts +++ b/static/js/audiorecording.ts @@ -209,6 +209,9 @@ window.onload = async function () { document .getElementById("updateBtn") ?.addEventListener("click", updateAudio, false); + document + .getElementById("audio-mode-select") + ?.addEventListener("change", handleModeChange, false); const audioseed = (document.getElementById("audio-seed") as HTMLInputElement) .value; From 378ea4d7bb3bb217c60723bfa180d8836110f7d7 Mon Sep 17 00:00:00 2001 From: gferraro Date: Sun, 22 Sep 2024 22:22:35 +0200 Subject: [PATCH 04/10] ran prettier --- static/js/about.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/static/js/about.js b/static/js/about.js index 168ff80..40a4ff1 100644 --- a/static/js/about.js +++ b/static/js/about.js @@ -8,7 +8,6 @@ window.onload = async function () { }; async function setAutoUpdate(autoUpdate) { - var headers = new Headers(authHeaders); headers.append("Content-Type", "application/x-www-form-urlencoded"); console.log("set auto update", autoUpdate); @@ -230,7 +229,7 @@ async function setEnvironment() { const selectedEnvironment = document.getElementById("environment-select").value; if (selectedEnvironment == "") { - alert('Please select an environment'); + alert("Please select an environment"); return; } $("#set-environment-button").attr("disabled", true); From 60184355742f327ee6324370b5aa95095372ce9f Mon Sep 17 00:00:00 2001 From: gferraro Date: Sun, 22 Sep 2024 22:23:19 +0200 Subject: [PATCH 05/10] add global --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index ccad0ea..b5a9e5a 100644 --- a/Makefile +++ b/Makefile @@ -13,8 +13,8 @@ build: install-packr install-typescript .PHONY: install-typescript install-typescript: - npm install typescript - npm install rollup + npm install -g typescript + npm install -g rollup npm i @types/jquery npx tsc From 2034fe76c880465c5ad83ff194562b9a916526eb Mon Sep 17 00:00:00 2001 From: gferraro Date: Tue, 8 Oct 2024 14:01:17 +0200 Subject: [PATCH 06/10] add 5 minutes button --- Makefile | 4 +-- api/audiorecording.go | 25 ++++++++++++++ cmd/managementd/main.go | 1 + html/audiorecording.html | 9 +++++ static/js/audiorecording.ts | 68 +++++++++++++++++++++++++++++++++---- 5 files changed, 98 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index b5a9e5a..ccad0ea 100644 --- a/Makefile +++ b/Makefile @@ -13,8 +13,8 @@ build: install-packr install-typescript .PHONY: install-typescript install-typescript: - npm install -g typescript - npm install -g rollup + npm install typescript + npm install rollup npm i @types/jquery npx tsc diff --git a/api/audiorecording.go b/api/audiorecording.go index dd989dd..5c6ef0a 100644 --- a/api/audiorecording.go +++ b/api/audiorecording.go @@ -93,6 +93,31 @@ func (api *ManagementAPI) AudioRecordingStatus(w http.ResponseWriter, r *http.Re } +func (api *ManagementAPI) TakeLongAudioRecording(w http.ResponseWriter, r *http.Request) { + tc2AgentDbus, err := getTC2AgentDbus() + if err != nil { + log.Println(err) + http.Error(w, "Failed to connect to DBus", http.StatusInternalServerError) + return + } + seconds, err := strconv.ParseUint(r.URL.Query().Get("seconds"), 10, 32) + if err != nil { + badRequest(&w, err) + return + } + var result string + + err = tc2AgentDbus.Call("org.cacophony.TC2Agent.longaudiorecording", 0, seconds).Store(&result) + if err != nil { + log.Println(err) + http.Error(w, "Failed to request long audio recording", http.StatusInternalServerError) + return + } + w.WriteHeader(http.StatusOK) + + json.NewEncoder(w).Encode(result) +} + func (api *ManagementAPI) TakeTestAudioRecording(w http.ResponseWriter, r *http.Request) { tc2AgentDbus, err := getTC2AgentDbus() if err != nil { diff --git a/cmd/managementd/main.go b/cmd/managementd/main.go index b7ce561..e18a50e 100644 --- a/cmd/managementd/main.go +++ b/cmd/managementd/main.go @@ -209,6 +209,7 @@ func main() { apiRouter.HandleFunc("/audiorecording", apiObj.SetAudioRecording).Methods("POST") apiRouter.HandleFunc("/audiorecording", apiObj.GetAudioRecording).Methods("GET") + apiRouter.HandleFunc("/audio/long-recording", apiObj.TakeLongAudioRecording).Methods("PUT") apiRouter.HandleFunc("/audio/test-recording", apiObj.TakeTestAudioRecording).Methods("PUT") apiRouter.HandleFunc("/audio/audio-status", apiObj.AudioRecordingStatus).Methods("GET") apiRouter.HandleFunc("/audio/recordings", apiObj.GetAudioRecordings).Methods("GET") diff --git a/html/audiorecording.html b/html/audiorecording.html index d477e26..faae086 100644 --- a/html/audiorecording.html +++ b/html/audiorecording.html @@ -57,6 +57,15 @@

Test Recording

+ +
+

5 Recording

+
+
+ +
diff --git a/static/js/audiorecording.ts b/static/js/audiorecording.ts index 4d07578..25a1736 100644 --- a/static/js/audiorecording.ts +++ b/static/js/audiorecording.ts @@ -107,23 +107,74 @@ async function getAudioStatus() { await xmlHttp.send(); } -function enableRecButton() { +function enableRecButtons() { audioState.clearInterval(); + document + .getElementById("audio-recording-button") + ?.removeAttribute("disabled"); + (document.getElementById("audio-recording-button") as HTMLElement).innerText = + "Take Test Recording"; document.getElementById("audio-test-button")?.removeAttribute("disabled"); (document.getElementById("audio-test-button") as HTMLElement).innerText = "Take Test Recording"; } -async function takeTestRecording() { - (document.getElementById("audio-test-button") as HTMLElement).innerText = - "Making a test recording"; +function disableRecButtons() { document .getElementById("audio-test-button") ?.setAttribute("disabled", "true"); + document + .getElementById("audio-recording-button") + ?.setAttribute("disabled", "true"); +} + +async function takeLongRecording() { + (document.getElementById("audio-recording-button") as HTMLElement).innerText = + "Making a 5 minute recording"; + disableRecButtons(); + recordingAPICall(true); +} + +async function takeTestRecording() { + (document.getElementById("audio-test-button") as HTMLElement).innerText = + "Making a test recording"; + disableRecButtons(); testAPICall(true); } +async function recordingAPICall(checkResponse: boolean) { + var xmlHttp = new XMLHttpRequest(); + xmlHttp.open("PUT", "/api/audio/long-recording?seconds=300", true); + xmlHttp.setRequestHeader("Authorization", "Basic " + btoa("admin:feathers")); + + var success = false; + if (checkResponse) { + xmlHttp.onload = async function () { + if (xmlHttp.status == 200) { + success = xmlHttp.responseText == '"Asked for a test recording"\n'; + if (!success) { + enableRecButtons(); + updateAudioError(xmlHttp); + } else { + audioState.clearInterval(); + audioState.startPolling(); + } + } else { + enableRecButtons(); + updateAudioError(xmlHttp); + } + }; + } + + xmlHttp.onerror = async function () { + enableRecButtons(); + updateAudioError(xmlHttp); + }; + + xmlHttp.send(); +} + async function testAPICall(checkResponse: boolean) { var xmlHttp = new XMLHttpRequest(); xmlHttp.open("PUT", "/api/audio/test-recording", true); @@ -134,21 +185,21 @@ async function testAPICall(checkResponse: boolean) { if (xmlHttp.status == 200) { success = xmlHttp.responseText == '"Asked for a test recording"\n'; if (!success) { - enableRecButton(); + enableRecButtons(); updateAudioError(xmlHttp); } else { audioState.clearInterval(); audioState.startPolling(); } } else { - enableRecButton(); + enableRecButtons(); updateAudioError(xmlHttp); } }; } xmlHttp.onerror = async function () { - enableRecButton(); + enableRecButtons(); updateAudioError(xmlHttp); }; @@ -206,6 +257,9 @@ function updateAudioError(xmlHttp: XMLHttpRequest) { window.onload = async function () { getAudioStatus(); + document + .getElementById("audio-recording-button") + ?.addEventListener("click", takeLongRecording, false); document .getElementById("updateBtn") ?.addEventListener("click", updateAudio, false); From 714cc2d628e98e87959fb071c8c25ce34d0142f2 Mon Sep 17 00:00:00 2001 From: gferraro Date: Tue, 8 Oct 2024 14:19:11 +0200 Subject: [PATCH 07/10] add 5 minute audio recording --- api/audiorecording.go | 2 +- html/audiorecording.html | 2 +- static/js/audiorecording.ts | 62 ++++++++++++++----------------------- 3 files changed, 26 insertions(+), 40 deletions(-) diff --git a/api/audiorecording.go b/api/audiorecording.go index 5c6ef0a..7d71025 100644 --- a/api/audiorecording.go +++ b/api/audiorecording.go @@ -110,7 +110,7 @@ func (api *ManagementAPI) TakeLongAudioRecording(w http.ResponseWriter, r *http. err = tc2AgentDbus.Call("org.cacophony.TC2Agent.longaudiorecording", 0, seconds).Store(&result) if err != nil { log.Println(err) - http.Error(w, "Failed to request long audio recording", http.StatusInternalServerError) + http.Error(w, "Failed to request 5 minute audio recording", http.StatusInternalServerError) return } w.WriteHeader(http.StatusOK) diff --git a/html/audiorecording.html b/html/audiorecording.html index faae086..cdc5fab 100644 --- a/html/audiorecording.html +++ b/html/audiorecording.html @@ -55,7 +55,7 @@

Audio Recording

Test Recording

- +
+
+ +

5 Recording

-
- -
-
- -
+
+ +
+
+ +