mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-30 14:55:28 +00:00
Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e7b43b6637 | ||
|
|
2221207036 | ||
|
|
dca1535f5a | ||
|
|
8b2eaf3ef4 | ||
|
|
c19837df1e | ||
|
|
783c333b46 | ||
|
|
2497c9c8e4 | ||
|
|
54a8164dd3 | ||
|
|
2c6a2f5a36 | ||
|
|
92f91cf260 | ||
|
|
5c94cddc74 | ||
|
|
7a0e945ecd | ||
|
|
1eaabf2e75 | ||
|
|
955dcca8c6 | ||
|
|
d312baeb6e | ||
|
|
00f78b5a50 | ||
|
|
b59da597ba | ||
|
|
8ca105a0b6 | ||
|
|
e027f22f8b |
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2025 Joel Wetzell
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
19
go.mod
19
go.mod
@@ -4,6 +4,8 @@ go 1.25.3
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/eclipse/paho.mqtt.golang v1.5.1
|
github.com/eclipse/paho.mqtt.golang v1.5.1
|
||||||
|
github.com/emiago/diago v0.23.1-0.20251211215055-e1d875617111
|
||||||
|
github.com/emiago/sipgo v1.0.1-alpha.0.20251212165843-9c9bcdf9126f
|
||||||
github.com/expr-lang/expr v1.17.6
|
github.com/expr-lang/expr v1.17.6
|
||||||
github.com/jwetzell/free-d-go v0.1.0
|
github.com/jwetzell/free-d-go v0.1.0
|
||||||
github.com/jwetzell/osc-go v0.1.0
|
github.com/jwetzell/osc-go v0.1.0
|
||||||
@@ -19,20 +21,33 @@ require (
|
|||||||
require (
|
require (
|
||||||
github.com/creack/goselect v0.1.2 // indirect
|
github.com/creack/goselect v0.1.2 // indirect
|
||||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||||
|
github.com/go-audio/riff v1.0.0 // indirect
|
||||||
|
github.com/gobwas/httphead v0.1.0 // indirect
|
||||||
|
github.com/gobwas/pool v0.2.1 // indirect
|
||||||
|
github.com/gobwas/ws v1.4.0 // indirect
|
||||||
github.com/google/uuid v1.6.0 // indirect
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
github.com/gorilla/websocket v1.5.3 // indirect
|
github.com/gorilla/websocket v1.5.3 // indirect
|
||||||
|
github.com/icholy/digest v1.1.0 // indirect
|
||||||
github.com/klauspost/compress v1.18.0 // indirect
|
github.com/klauspost/compress v1.18.0 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
github.com/nats-io/nkeys v0.4.11 // indirect
|
github.com/nats-io/nkeys v0.4.11 // indirect
|
||||||
github.com/nats-io/nuid v1.0.1 // indirect
|
github.com/nats-io/nuid v1.0.1 // indirect
|
||||||
github.com/ncruces/go-strftime v0.1.9 // indirect
|
github.com/ncruces/go-strftime v0.1.9 // indirect
|
||||||
|
github.com/pion/logging v0.2.4 // indirect
|
||||||
|
github.com/pion/randutil v0.1.0 // indirect
|
||||||
|
github.com/pion/rtcp v1.2.16 // indirect
|
||||||
|
github.com/pion/rtp v1.8.26 // indirect
|
||||||
|
github.com/pion/srtp/v3 v3.0.9 // indirect
|
||||||
|
github.com/pion/transport/v3 v3.1.1 // indirect
|
||||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||||
|
github.com/zaf/g711 v1.4.0 // indirect
|
||||||
go.yaml.in/yaml/v2 v2.4.2 // indirect
|
go.yaml.in/yaml/v2 v2.4.2 // indirect
|
||||||
golang.org/x/crypto v0.42.0 // indirect
|
golang.org/x/crypto v0.42.0 // indirect
|
||||||
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b // indirect
|
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b // indirect
|
||||||
golang.org/x/net v0.44.0 // indirect
|
golang.org/x/net v0.44.0 // indirect
|
||||||
golang.org/x/sync v0.17.0 // indirect
|
golang.org/x/sync v0.19.0 // indirect
|
||||||
golang.org/x/sys v0.36.0 // indirect
|
golang.org/x/sys v0.39.0 // indirect
|
||||||
|
gopkg.in/hraban/opus.v2 v2.0.0-20230925203106-0188a62cb302 // indirect
|
||||||
modernc.org/libc v1.66.10 // indirect
|
modernc.org/libc v1.66.10 // indirect
|
||||||
modernc.org/libquickjs v0.12.2 // indirect
|
modernc.org/libquickjs v0.12.2 // indirect
|
||||||
modernc.org/mathutil v1.7.1 // indirect
|
modernc.org/mathutil v1.7.1 // indirect
|
||||||
|
|||||||
63
go.sum
63
go.sum
@@ -6,16 +6,30 @@ github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkp
|
|||||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||||
github.com/eclipse/paho.mqtt.golang v1.5.1 h1:/VSOv3oDLlpqR2Epjn1Q7b2bSTplJIeV2ISgCl2W7nE=
|
github.com/eclipse/paho.mqtt.golang v1.5.1 h1:/VSOv3oDLlpqR2Epjn1Q7b2bSTplJIeV2ISgCl2W7nE=
|
||||||
github.com/eclipse/paho.mqtt.golang v1.5.1/go.mod h1:1/yJCneuyOoCOzKSsOTUc0AJfpsItBGWvYpBLimhArU=
|
github.com/eclipse/paho.mqtt.golang v1.5.1/go.mod h1:1/yJCneuyOoCOzKSsOTUc0AJfpsItBGWvYpBLimhArU=
|
||||||
|
github.com/emiago/diago v0.23.1-0.20251211215055-e1d875617111 h1:jqhOZbH40pf2jiUhGaBNk334wOtNYvAaXg/mHOXhy/Y=
|
||||||
|
github.com/emiago/diago v0.23.1-0.20251211215055-e1d875617111/go.mod h1:3vLCCq8/G/Ei5I64IHtrmBTag+nPLcgXcKeN1KkLtuc=
|
||||||
|
github.com/emiago/sipgo v1.0.1-alpha.0.20251212165843-9c9bcdf9126f h1:n3wpx7ZyJBr0popXyATnTUZp/AdLIHjKbnKzr4ruF7g=
|
||||||
|
github.com/emiago/sipgo v1.0.1-alpha.0.20251212165843-9c9bcdf9126f/go.mod h1:DuwAxBZhKMqIzQFPGZb1MVAGU6Wuxj64oTOhd5dx/FY=
|
||||||
github.com/expr-lang/expr v1.17.6 h1:1h6i8ONk9cexhDmowO/A64VPxHScu7qfSl2k8OlINec=
|
github.com/expr-lang/expr v1.17.6 h1:1h6i8ONk9cexhDmowO/A64VPxHScu7qfSl2k8OlINec=
|
||||||
github.com/expr-lang/expr v1.17.6/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4=
|
github.com/expr-lang/expr v1.17.6/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4=
|
||||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
github.com/go-audio/riff v1.0.0 h1:d8iCGbDvox9BfLagY94fBynxSPHO80LmZCaOsmKxokA=
|
||||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
github.com/go-audio/riff v1.0.0/go.mod h1:l3cQwc85y79NQFCRB7TiPoNiaijp6q8Z0Uv38rVG498=
|
||||||
|
github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU=
|
||||||
|
github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM=
|
||||||
|
github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og=
|
||||||
|
github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
|
||||||
|
github.com/gobwas/ws v1.4.0 h1:CTaoG1tojrh4ucGPcoJFiAQUAsEWekEWvLy7GsVNqGs=
|
||||||
|
github.com/gobwas/ws v1.4.0/go.mod h1:G3gNqMNtPppf5XUz7O4shetPpcZ1VJ7zt18dlUeakrc=
|
||||||
|
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||||
|
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
||||||
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
|
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
|
||||||
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
|
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
|
||||||
|
github.com/icholy/digest v1.1.0 h1:HfGg9Irj7i+IX1o1QAmPfIBNu/Q5A5Tu3n/MED9k9H4=
|
||||||
|
github.com/icholy/digest v1.1.0/go.mod h1:QNrsSGQ5v7v9cReDI0+eyjsXGUoRSUZQHeQ5C4XLa0Y=
|
||||||
github.com/jwetzell/free-d-go v0.1.0 h1:xHt6dvyit98X+OC3jVzV0aLidxbyzi3vI9QiYkteEtA=
|
github.com/jwetzell/free-d-go v0.1.0 h1:xHt6dvyit98X+OC3jVzV0aLidxbyzi3vI9QiYkteEtA=
|
||||||
github.com/jwetzell/free-d-go v0.1.0/go.mod h1:KmrkooRARRaxJTBSPvwt/6IMAIaHH1R8bSA8cwbbELw=
|
github.com/jwetzell/free-d-go v0.1.0/go.mod h1:KmrkooRARRaxJTBSPvwt/6IMAIaHH1R8bSA8cwbbELw=
|
||||||
github.com/jwetzell/osc-go v0.1.0 h1:EXxup5VWBErHot2Ri4MFToPf6KCzLDTbCt2x6GLfw8I=
|
github.com/jwetzell/osc-go v0.1.0 h1:EXxup5VWBErHot2Ri4MFToPf6KCzLDTbCt2x6GLfw8I=
|
||||||
@@ -24,6 +38,10 @@ github.com/jwetzell/psn-go v0.3.0 h1:WVpCEmExYE8a+I5hQak5jNJJp2x35VdGX/VuMUKPmhY
|
|||||||
github.com/jwetzell/psn-go v0.3.0/go.mod h1:bcEAeti4sQM375buujb3mIfmUstD4Aby18gq3ENb6+o=
|
github.com/jwetzell/psn-go v0.3.0/go.mod h1:bcEAeti4sQM375buujb3mIfmUstD4Aby18gq3ENb6+o=
|
||||||
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
|
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
|
||||||
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
|
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
|
||||||
|
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||||
|
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||||
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
|
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||||
github.com/nats-io/nats.go v1.47.0 h1:YQdADw6J/UfGUd2Oy6tn4Hq6YHxCaJrVKayxxFqYrgM=
|
github.com/nats-io/nats.go v1.47.0 h1:YQdADw6J/UfGUd2Oy6tn4Hq6YHxCaJrVKayxxFqYrgM=
|
||||||
@@ -34,14 +52,40 @@ github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
|
|||||||
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
|
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
|
||||||
github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4=
|
github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4=
|
||||||
github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
|
github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
|
||||||
|
github.com/pion/logging v0.2.3 h1:gHuf0zpoh1GW67Nr6Gj4cv5Z9ZscU7g/EaoC/Ke/igI=
|
||||||
|
github.com/pion/logging v0.2.3/go.mod h1:z8YfknkquMe1csOrxK5kc+5/ZPAzMxbKLX5aXpbpC90=
|
||||||
|
github.com/pion/logging v0.2.4 h1:tTew+7cmQ+Mc1pTBLKH2puKsOvhm32dROumOZ655zB8=
|
||||||
|
github.com/pion/logging v0.2.4/go.mod h1:DffhXTKYdNZU+KtJ5pyQDjvOAh/GsNSyv1lbkFbe3so=
|
||||||
|
github.com/pion/randutil v0.1.0 h1:CFG1UdESneORglEsnimhUjf33Rwjubwj6xfiOXBa3mA=
|
||||||
|
github.com/pion/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8=
|
||||||
|
github.com/pion/rtcp v1.2.15 h1:LZQi2JbdipLOj4eBjK4wlVoQWfrZbh3Q6eHtWtJBZBo=
|
||||||
|
github.com/pion/rtcp v1.2.15/go.mod h1:jlGuAjHMEXwMUHK78RgX0UmEJFV4zUKOFHR7OP+D3D0=
|
||||||
|
github.com/pion/rtcp v1.2.16 h1:fk1B1dNW4hsI78XUCljZJlC4kZOPk67mNRuQ0fcEkSo=
|
||||||
|
github.com/pion/rtcp v1.2.16/go.mod h1:/as7VKfYbs5NIb4h6muQ35kQF/J0ZVNz2Z3xKoCBYOo=
|
||||||
|
github.com/pion/rtp v1.8.18 h1:yEAb4+4a8nkPCecWzQB6V/uEU18X1lQCGAQCjP+pyvU=
|
||||||
|
github.com/pion/rtp v1.8.18/go.mod h1:bAu2UFKScgzyFqvUKmbvzSdPr+NGbZtv6UB2hesqXBk=
|
||||||
|
github.com/pion/rtp v1.8.26 h1:VB+ESQFQhBXFytD+Gk8cxB6dXeVf2WQzg4aORvAvAAc=
|
||||||
|
github.com/pion/rtp v1.8.26/go.mod h1:rF5nS1GqbR7H/TCpKwylzeq6yDM+MM6k+On5EgeThEM=
|
||||||
|
github.com/pion/srtp/v3 v3.0.6 h1:E2gyj1f5X10sB/qILUGIkL4C2CqK269Xq167PbGCc/4=
|
||||||
|
github.com/pion/srtp/v3 v3.0.6/go.mod h1:BxvziG3v/armJHAaJ87euvkhHqWe9I7iiOy50K2QkhY=
|
||||||
|
github.com/pion/srtp/v3 v3.0.9 h1:lRGF4G61xxj+m/YluB3ZnBpiALSri2lTzba0kGZMrQY=
|
||||||
|
github.com/pion/srtp/v3 v3.0.9/go.mod h1:E+AuWd7Ug2Fp5u38MKnhduvpVkveXJX6J4Lq4rxUYt8=
|
||||||
|
github.com/pion/transport/v3 v3.0.7 h1:iRbMH05BzSNwhILHoBoAPxoB9xQgOaJk+591KC9P1o0=
|
||||||
|
github.com/pion/transport/v3 v3.0.7/go.mod h1:YleKiTZ4vqNxVwh77Z0zytYi7rXHl7j6uPLGhhz9rwo=
|
||||||
|
github.com/pion/transport/v3 v3.1.1 h1:Tr684+fnnKlhPceU+ICdrw6KKkTms+5qHMgw6bIkYOM=
|
||||||
|
github.com/pion/transport/v3 v3.1.1/go.mod h1:+c2eewC5WJQHiAA46fkMMzoYZSuGzA/7E2FPrOYHctQ=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
||||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||||
|
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
|
||||||
|
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
|
||||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||||
github.com/urfave/cli/v3 v3.6.1 h1:j8Qq8NyUawj/7rTYdBGrxcH7A/j7/G8Q5LhWEW4G3Mo=
|
github.com/urfave/cli/v3 v3.6.1 h1:j8Qq8NyUawj/7rTYdBGrxcH7A/j7/G8Q5LhWEW4G3Mo=
|
||||||
github.com/urfave/cli/v3 v3.6.1/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso=
|
github.com/urfave/cli/v3 v3.6.1/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso=
|
||||||
|
github.com/zaf/g711 v1.4.0 h1:XZYkjjiAg9QTBnHqEg37m2I9q3IIDv5JRYXs2N8ma7c=
|
||||||
|
github.com/zaf/g711 v1.4.0/go.mod h1:eCDXt3dSp/kYYAoooba7ukD/Q75jvAaS4WOMr0l1Roo=
|
||||||
gitlab.com/gomidi/midi/v2 v2.3.16 h1:yufWSENyjnJ4LFQa9BerzUm4E4aLfTyzw5nmnCteO0c=
|
gitlab.com/gomidi/midi/v2 v2.3.16 h1:yufWSENyjnJ4LFQa9BerzUm4E4aLfTyzw5nmnCteO0c=
|
||||||
gitlab.com/gomidi/midi/v2 v2.3.16/go.mod h1:jDpP4O4skYi+7iVwt6Zyp18bd2M4hkjtMuw2cmgKgfw=
|
gitlab.com/gomidi/midi/v2 v2.3.16/go.mod h1:jDpP4O4skYi+7iVwt6Zyp18bd2M4hkjtMuw2cmgKgfw=
|
||||||
go.bug.st/serial v1.6.4 h1:7FmqNPgVp3pu2Jz5PoPtbZ9jJO5gnEnZIvnI1lzve8A=
|
go.bug.st/serial v1.6.4 h1:7FmqNPgVp3pu2Jz5PoPtbZ9jJO5gnEnZIvnI1lzve8A=
|
||||||
@@ -58,17 +102,22 @@ golang.org/x/mod v0.29.0 h1:HV8lRxZC4l2cr3Zq1LvtOsi/ThTgWnUk/y64QSs8GwA=
|
|||||||
golang.org/x/mod v0.29.0/go.mod h1:NyhrlYXJ2H4eJiRy/WDBO6HMqZQ6q9nk4JzS3NuCK+w=
|
golang.org/x/mod v0.29.0/go.mod h1:NyhrlYXJ2H4eJiRy/WDBO6HMqZQ6q9nk4JzS3NuCK+w=
|
||||||
golang.org/x/net v0.44.0 h1:evd8IRDyfNBMBTTY5XRF1vaZlD+EmWx6x8PkhR04H/I=
|
golang.org/x/net v0.44.0 h1:evd8IRDyfNBMBTTY5XRF1vaZlD+EmWx6x8PkhR04H/I=
|
||||||
golang.org/x/net v0.44.0/go.mod h1:ECOoLqd5U3Lhyeyo/QDCEVQ4sNgYsqvCZ722XogGieY=
|
golang.org/x/net v0.44.0/go.mod h1:ECOoLqd5U3Lhyeyo/QDCEVQ4sNgYsqvCZ722XogGieY=
|
||||||
golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
|
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
|
||||||
golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
|
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
|
||||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
|
golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk=
|
||||||
golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||||
golang.org/x/tools v0.37.0 h1:DVSRzp7FwePZW356yEAChSdNcQo6Nsp+fex1SUW09lE=
|
golang.org/x/tools v0.37.0 h1:DVSRzp7FwePZW356yEAChSdNcQo6Nsp+fex1SUW09lE=
|
||||||
golang.org/x/tools v0.37.0/go.mod h1:MBN5QPQtLMHVdvsbtarmTNukZDdgwdwlO5qGacAzF0w=
|
golang.org/x/tools v0.37.0/go.mod h1:MBN5QPQtLMHVdvsbtarmTNukZDdgwdwlO5qGacAzF0w=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||||
|
gopkg.in/hraban/opus.v2 v2.0.0-20230925203106-0188a62cb302 h1:xeVptzkP8BuJhoIjNizd2bRHfq9KB9HfOLZu90T04XM=
|
||||||
|
gopkg.in/hraban/opus.v2 v2.0.0-20230925203106-0188a62cb302/go.mod h1:/L5E7a21VWl8DeuCPKxQBdVG5cy+L0MRZ08B1wnqt7g=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
|
||||||
|
gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=
|
||||||
modernc.org/cc/v4 v4.27.1 h1:9W30zRlYrefrDV2JE2O8VDtJ1yPGownxciz5rrbQZis=
|
modernc.org/cc/v4 v4.27.1 h1:9W30zRlYrefrDV2JE2O8VDtJ1yPGownxciz5rrbQZis=
|
||||||
modernc.org/cc/v4 v4.27.1/go.mod h1:uVtb5OGqUKpoLWhqwNQo/8LwvoiEBLvZXIQ/SmO6mL0=
|
modernc.org/cc/v4 v4.27.1/go.mod h1:uVtb5OGqUKpoLWhqwNQo/8LwvoiEBLvZXIQ/SmO6mL0=
|
||||||
modernc.org/ccgo/v4 v4.30.1 h1:4r4U1J6Fhj98NKfSjnPUN7Ze2c6MnAdL0hWw6+LrJpc=
|
modernc.org/ccgo/v4 v4.30.1 h1:4r4U1J6Fhj98NKfSjnPUN7Ze2c6MnAdL0hWw6+LrJpc=
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ type HTTPClient struct {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "net.http.client",
|
Type: "http.client",
|
||||||
New: func(ctx context.Context, config config.ModuleConfig, router route.RouteIO) (Module, error) {
|
New: func(ctx context.Context, config config.ModuleConfig, router route.RouteIO) (Module, error) {
|
||||||
|
|
||||||
return &HTTPClient{config: config, ctx: ctx, router: router}, nil
|
return &HTTPClient{config: config, ctx: ctx, router: router}, nil
|
||||||
@@ -43,7 +43,7 @@ func (hc *HTTPClient) Run() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
<-hc.ctx.Done()
|
<-hc.ctx.Done()
|
||||||
slog.Debug("router context done in module", "id", hc.config.Id)
|
slog.Debug("router context done in module", "id", hc.Id())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,11 +52,11 @@ func (hc *HTTPClient) Output(payload any) error {
|
|||||||
payloadRequest, ok := payload.(*http.Request)
|
payloadRequest, ok := payload.(*http.Request)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("net.http.client is only able to output an http.Request")
|
return fmt.Errorf("http.client is only able to output an http.Request")
|
||||||
}
|
}
|
||||||
|
|
||||||
if hc.client == nil {
|
if hc.client == nil {
|
||||||
return fmt.Errorf("net.http.client client is nil")
|
return fmt.Errorf("http.client client is nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
response, err := hc.client.Do(payloadRequest)
|
response, err := hc.client.Do(payloadRequest)
|
||||||
@@ -66,7 +66,7 @@ func (hc *HTTPClient) Output(payload any) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if hc.router != nil {
|
if hc.router != nil {
|
||||||
hc.router.HandleInput(hc.config.Id, response)
|
hc.router.HandleInput(hc.Id(), response)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -25,18 +25,18 @@ type ResponseData struct {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "net.http.server",
|
Type: "http.server",
|
||||||
New: func(ctx context.Context, config config.ModuleConfig, router route.RouteIO) (Module, error) {
|
New: func(ctx context.Context, config config.ModuleConfig, router route.RouteIO) (Module, error) {
|
||||||
params := config.Params
|
params := config.Params
|
||||||
port, ok := params["port"]
|
port, ok := params["port"]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("net.http.server requires a port parameter")
|
return nil, fmt.Errorf("http.server requires a port parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
portNum, ok := port.(float64)
|
portNum, ok := port.(float64)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("net.http.server port must be uint16")
|
return nil, fmt.Errorf("http.server port must be uint16")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &HTTPServer{Port: uint16(portNum), config: config, ctx: ctx, router: router}, nil
|
return &HTTPServer{Port: uint16(portNum), config: config, ctx: ctx, router: router}, nil
|
||||||
@@ -61,7 +61,7 @@ func (hs *HTTPServer) HandleDefault(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if hs.router != nil {
|
if hs.router != nil {
|
||||||
routingErrors := hs.router.HandleInput(hs.config.Id, r)
|
routingErrors := hs.router.HandleInput(hs.Id(), r)
|
||||||
if routingErrors != nil {
|
if routingErrors != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
response.Status = "error"
|
response.Status = "error"
|
||||||
@@ -89,12 +89,12 @@ func (hs *HTTPServer) Run() error {
|
|||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
<-hs.ctx.Done()
|
<-hs.ctx.Done()
|
||||||
slog.Debug("router context done in module", "id", hs.config.Id)
|
slog.Debug("router context done in module", "id", hs.Id())
|
||||||
httpServer.Close()
|
httpServer.Close()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err := httpServer.ListenAndServe()
|
err := httpServer.ListenAndServe()
|
||||||
slog.Debug("net.http.server closed", "id", hs.config.Id)
|
slog.Debug("http.server closed", "id", hs.Id())
|
||||||
// TODO(jwetzell): handle server closed error differently
|
// TODO(jwetzell): handle server closed error differently
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -105,5 +105,5 @@ func (hs *HTTPServer) Run() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (hs *HTTPServer) Output(payload any) error {
|
func (hs *HTTPServer) Output(payload any) error {
|
||||||
return fmt.Errorf("net.http.server output is not implemented")
|
return fmt.Errorf("http.server output is not implemented")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,11 +56,11 @@ func (i *Interval) Run() error {
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-i.ctx.Done():
|
case <-i.ctx.Done():
|
||||||
slog.Debug("router context done in module", "id", i.config.Id)
|
slog.Debug("router context done in module", "id", i.Id())
|
||||||
return nil
|
return nil
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
if i.router != nil {
|
if i.router != nil {
|
||||||
i.router.HandleInput(i.config.Id, time.Now())
|
i.router.HandleInput(i.Id(), time.Now())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,31 +25,31 @@ type MIDIClient struct {
|
|||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
//TODO(jwetzell): find a better namespace than "misc"
|
//TODO(jwetzell): find a better namespace than "misc"
|
||||||
Type: "misc.midi.client",
|
Type: "midi.client",
|
||||||
New: func(ctx context.Context, config config.ModuleConfig, router route.RouteIO) (Module, error) {
|
New: func(ctx context.Context, config config.ModuleConfig, router route.RouteIO) (Module, error) {
|
||||||
params := config.Params
|
params := config.Params
|
||||||
input, ok := params["input"]
|
input, ok := params["input"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("misc.midi.client requires a input parameter")
|
return nil, fmt.Errorf("midi.client requires a input parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
inputString, ok := input.(string)
|
inputString, ok := input.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("misc.midi.client input must be a string")
|
return nil, fmt.Errorf("midi.client input must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
output, ok := params["output"]
|
output, ok := params["output"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("misc.midi.client requires a output parameter")
|
return nil, fmt.Errorf("midi.client requires a output parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
outputString, ok := output.(string)
|
outputString, ok := output.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("misc.midi.client output must be a string")
|
return nil, fmt.Errorf("midi.client output must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &MIDIClient{config: config, InputPort: inputString, OutputPort: outputString, ctx: ctx, router: router}, nil
|
return &MIDIClient{config: config, InputPort: inputString, OutputPort: outputString, ctx: ctx, router: router}, nil
|
||||||
@@ -70,11 +70,12 @@ func (mc *MIDIClient) Run() error {
|
|||||||
|
|
||||||
in, err := midi.FindInPort(mc.InputPort)
|
in, err := midi.FindInPort(mc.InputPort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("misc.midi.client can't find input port: %s", mc.InputPort)
|
return fmt.Errorf("midi.client can't find input port: %s", mc.InputPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
stop, err := midi.ListenTo(in, func(msg midi.Message, timestampms int32) {
|
stop, err := midi.ListenTo(in, func(msg midi.Message, timestampms int32) {
|
||||||
if mc.router != nil {
|
if mc.router != nil {
|
||||||
|
// TODO(jwetzell): unpack MIDI messsage into something more useful?
|
||||||
mc.router.HandleInput(mc.Id(), msg)
|
mc.router.HandleInput(mc.Id(), msg)
|
||||||
}
|
}
|
||||||
}, midi.UseSysEx())
|
}, midi.UseSysEx())
|
||||||
@@ -88,7 +89,7 @@ func (mc *MIDIClient) Run() error {
|
|||||||
out, err := midi.FindOutPort(mc.OutputPort)
|
out, err := midi.FindOutPort(mc.OutputPort)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("misc.midi.client can't find output port: %s", mc.OutputPort)
|
return fmt.Errorf("midi.client can't find output port: %s", mc.OutputPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
send, err := midi.SendTo(out)
|
send, err := midi.SendTo(out)
|
||||||
@@ -99,19 +100,19 @@ func (mc *MIDIClient) Run() error {
|
|||||||
mc.SendFunc = send
|
mc.SendFunc = send
|
||||||
|
|
||||||
<-mc.ctx.Done()
|
<-mc.ctx.Done()
|
||||||
slog.Debug("router context done in module", "id", mc.config.Id)
|
slog.Debug("router context done in module", "id", mc.Id())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mc *MIDIClient) Output(payload any) error {
|
func (mc *MIDIClient) Output(payload any) error {
|
||||||
if mc.SendFunc == nil {
|
if mc.SendFunc == nil {
|
||||||
return fmt.Errorf("misc.midi.client output is not setup")
|
return fmt.Errorf("midi.client output is not setup")
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadMessage, ok := payload.(midi.Message)
|
payloadMessage, ok := payload.(midi.Message)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("misc.midi.client can only ouptut midi.Message")
|
return fmt.Errorf("midi.client can only ouptut midi.Message")
|
||||||
}
|
}
|
||||||
|
|
||||||
return mc.SendFunc(payloadMessage)
|
return mc.SendFunc(payloadMessage)
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
|
|
||||||
mqtt "github.com/eclipse/paho.mqtt.golang"
|
mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/route"
|
"github.com/jwetzell/showbridge-go/internal/route"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -23,43 +22,43 @@ type MQTTClient struct {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "net.mqtt.client",
|
Type: "mqtt.client",
|
||||||
New: func(ctx context.Context, config config.ModuleConfig, router route.RouteIO) (Module, error) {
|
New: func(ctx context.Context, config config.ModuleConfig, router route.RouteIO) (Module, error) {
|
||||||
params := config.Params
|
params := config.Params
|
||||||
broker, ok := params["broker"]
|
broker, ok := params["broker"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("net.mqtt.client requires a broker parameter")
|
return nil, fmt.Errorf("mqtt.client requires a broker parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
brokerString, ok := broker.(string)
|
brokerString, ok := broker.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("net.mqtt.client broker must be string")
|
return nil, fmt.Errorf("mqtt.client broker must be string")
|
||||||
}
|
}
|
||||||
|
|
||||||
topic, ok := params["topic"]
|
topic, ok := params["topic"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("net.mqtt.client requires a topic parameter")
|
return nil, fmt.Errorf("mqtt.client requires a topic parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
topicString, ok := topic.(string)
|
topicString, ok := topic.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("net.mqtt.client topic must be string")
|
return nil, fmt.Errorf("mqtt.client topic must be string")
|
||||||
}
|
}
|
||||||
|
|
||||||
clientId, ok := params["clientId"]
|
clientId, ok := params["clientId"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("net.mqtt.client requires a clientId parameter")
|
return nil, fmt.Errorf("mqtt.client requires a clientId parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
clientIdString, ok := clientId.(string)
|
clientIdString, ok := clientId.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("net.mqtt.client clientId must be string")
|
return nil, fmt.Errorf("mqtt.client clientId must be string")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &MQTTClient{config: config, Broker: brokerString, Topic: topicString, ClientID: clientIdString, ctx: ctx, router: router}, nil
|
return &MQTTClient{config: config, Broker: brokerString, Topic: topicString, ClientID: clientIdString, ctx: ctx, router: router}, nil
|
||||||
@@ -84,7 +83,7 @@ func (mc *MQTTClient) Run() error {
|
|||||||
|
|
||||||
opts.OnConnect = func(c mqtt.Client) {
|
opts.OnConnect = func(c mqtt.Client) {
|
||||||
token := mc.client.Subscribe(mc.Topic, 1, func(c mqtt.Client, m mqtt.Message) {
|
token := mc.client.Subscribe(mc.Topic, 1, func(c mqtt.Client, m mqtt.Message) {
|
||||||
mc.router.HandleInput(mc.config.Id, m)
|
mc.router.HandleInput(mc.Id(), m)
|
||||||
})
|
})
|
||||||
token.Wait()
|
token.Wait()
|
||||||
}
|
}
|
||||||
@@ -100,26 +99,28 @@ func (mc *MQTTClient) Run() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
<-mc.ctx.Done()
|
<-mc.ctx.Done()
|
||||||
slog.Debug("router context done in module", "id", mc.config.Id)
|
slog.Debug("router context done in module", "id", mc.Id())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mc *MQTTClient) Output(payload any) error {
|
func (mc *MQTTClient) Output(payload any) error {
|
||||||
payloadMessage, ok := payload.(processor.MQTTMessage)
|
payloadMessage, ok := payload.(mqtt.Message)
|
||||||
|
|
||||||
|
fmt.Printf("payload type: %T\n", payload)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("net.mqtt.client is only able to output a MQTTMessage")
|
return fmt.Errorf("mqtt.client is only able to output a MQTTMessage")
|
||||||
}
|
}
|
||||||
|
|
||||||
if mc.client == nil {
|
if mc.client == nil {
|
||||||
return fmt.Errorf("net.mqtt.client client is not setup")
|
return fmt.Errorf("mqtt.client client is not setup")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !mc.client.IsConnected() {
|
if !mc.client.IsConnected() {
|
||||||
return fmt.Errorf("net.mqtt.client is not connected")
|
return fmt.Errorf("mqtt.client is not connected")
|
||||||
}
|
}
|
||||||
|
|
||||||
token := mc.client.Publish(payloadMessage.Topic, payloadMessage.QoS, payloadMessage.Retained, payloadMessage.Payload)
|
token := mc.client.Publish(payloadMessage.Topic(), payloadMessage.Qos(), payloadMessage.Retained(), payloadMessage.Payload())
|
||||||
|
|
||||||
token.Wait()
|
token.Wait()
|
||||||
|
|
||||||
|
|||||||
@@ -22,31 +22,31 @@ type NATSClient struct {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "net.nats.client",
|
Type: "nats.client",
|
||||||
New: func(ctx context.Context, config config.ModuleConfig, router route.RouteIO) (Module, error) {
|
New: func(ctx context.Context, config config.ModuleConfig, router route.RouteIO) (Module, error) {
|
||||||
params := config.Params
|
params := config.Params
|
||||||
url, ok := params["url"]
|
url, ok := params["url"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("net.nats.client requires a url parameter")
|
return nil, fmt.Errorf("nats.client requires a url parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
urlString, ok := url.(string)
|
urlString, ok := url.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("net.nats.client url must be string")
|
return nil, fmt.Errorf("nats.client url must be string")
|
||||||
}
|
}
|
||||||
|
|
||||||
subject, ok := params["subject"]
|
subject, ok := params["subject"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("net.nats.client requires a subject parameter")
|
return nil, fmt.Errorf("nats.client requires a subject parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
subjectString, ok := subject.(string)
|
subjectString, ok := subject.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("net.nats.client subject must be string")
|
return nil, fmt.Errorf("nats.client subject must be string")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &NATSClient{config: config, URL: urlString, Subject: subjectString, ctx: ctx, router: router}, nil
|
return &NATSClient{config: config, URL: urlString, Subject: subjectString, ctx: ctx, router: router}, nil
|
||||||
@@ -76,7 +76,7 @@ func (nc *NATSClient) Run() error {
|
|||||||
|
|
||||||
sub, err := nc.client.Subscribe(nc.Subject, func(msg *nats.Msg) {
|
sub, err := nc.client.Subscribe(nc.Subject, func(msg *nats.Msg) {
|
||||||
if nc.router != nil {
|
if nc.router != nil {
|
||||||
nc.router.HandleInput(nc.config.Id, msg)
|
nc.router.HandleInput(nc.Id(), msg)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ func (nc *NATSClient) Run() error {
|
|||||||
defer sub.Unsubscribe()
|
defer sub.Unsubscribe()
|
||||||
|
|
||||||
<-nc.ctx.Done()
|
<-nc.ctx.Done()
|
||||||
slog.Debug("router context done in module", "id", nc.config.Id)
|
slog.Debug("router context done in module", "id", nc.Id())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,15 +96,15 @@ func (nc *NATSClient) Output(payload any) error {
|
|||||||
payloadMessage, ok := payload.(processor.NATSMessage)
|
payloadMessage, ok := payload.(processor.NATSMessage)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("net.nats.client is only able to output NATSMessage")
|
return fmt.Errorf("nats.client is only able to output NATSMessage")
|
||||||
}
|
}
|
||||||
|
|
||||||
if nc.client == nil {
|
if nc.client == nil {
|
||||||
return fmt.Errorf("net.nats.client client is not setup")
|
return fmt.Errorf("nats.client client is not setup")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !nc.client.IsConnected() {
|
if !nc.client.IsConnected() {
|
||||||
return fmt.Errorf("net.nats.client is not connected")
|
return fmt.Errorf("nats.client is not connected")
|
||||||
}
|
}
|
||||||
|
|
||||||
err := nc.client.Publish(payloadMessage.Subject, payloadMessage.Payload)
|
err := nc.client.Publish(payloadMessage.Subject, payloadMessage.Payload)
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ type PSNClient struct {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
Type: "net.psn.client",
|
Type: "psn.client",
|
||||||
New: func(ctx context.Context, config config.ModuleConfig, router route.RouteIO) (Module, error) {
|
New: func(ctx context.Context, config config.ModuleConfig, router route.RouteIO) (Module, error) {
|
||||||
|
|
||||||
return &PSNClient{config: config, decoder: psn.NewDecoder(), ctx: ctx, router: router}, nil
|
return &PSNClient{config: config, decoder: psn.NewDecoder(), ctx: ctx, router: router}, nil
|
||||||
@@ -58,7 +58,7 @@ func (pc *PSNClient) Run() error {
|
|||||||
select {
|
select {
|
||||||
case <-pc.ctx.Done():
|
case <-pc.ctx.Done():
|
||||||
// TODO(jwetzell): cleanup?
|
// TODO(jwetzell): cleanup?
|
||||||
slog.Debug("router context done in module", "id", pc.config.Id)
|
slog.Debug("router context done in module", "id", pc.Id())
|
||||||
return nil
|
return nil
|
||||||
default:
|
default:
|
||||||
pc.conn.SetDeadline(time.Now().Add(time.Millisecond * 200))
|
pc.conn.SetDeadline(time.Now().Add(time.Millisecond * 200))
|
||||||
@@ -76,15 +76,15 @@ func (pc *PSNClient) Run() error {
|
|||||||
message := buffer[:numBytes]
|
message := buffer[:numBytes]
|
||||||
err := pc.decoder.Decode(message)
|
err := pc.decoder.Decode(message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("net.psn.client problem decoding psn traffic", "id", pc.config.Id, "error", err)
|
slog.Error("psn.client problem decoding psn traffic", "id", pc.Id(), "error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if pc.router != nil {
|
if pc.router != nil {
|
||||||
for _, tracker := range pc.decoder.Trackers {
|
for _, tracker := range pc.decoder.Trackers {
|
||||||
pc.router.HandleInput(pc.config.Id, tracker)
|
pc.router.HandleInput(pc.Id(), tracker)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
slog.Error("net.psn.client has no router", "id", pc.config.Id)
|
slog.Error("psn.client has no router", "id", pc.Id())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,5 +92,5 @@ func (pc *PSNClient) Run() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (pc *PSNClient) Output(payload any) error {
|
func (pc *PSNClient) Output(payload any) error {
|
||||||
return fmt.Errorf("net.psn.client output is not implemented")
|
return fmt.Errorf("psn.client output is not implemented")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,19 +27,19 @@ type SerialClient struct {
|
|||||||
func init() {
|
func init() {
|
||||||
RegisterModule(ModuleRegistration{
|
RegisterModule(ModuleRegistration{
|
||||||
//TODO(jwetzell): find a better namespace than "misc"
|
//TODO(jwetzell): find a better namespace than "misc"
|
||||||
Type: "misc.serial.client",
|
Type: "serial.client",
|
||||||
New: func(ctx context.Context, config config.ModuleConfig, router route.RouteIO) (Module, error) {
|
New: func(ctx context.Context, config config.ModuleConfig, router route.RouteIO) (Module, error) {
|
||||||
params := config.Params
|
params := config.Params
|
||||||
port, ok := params["port"]
|
port, ok := params["port"]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("misc.serial.client requires a port parameter")
|
return nil, fmt.Errorf("serial.client requires a port parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
portString, ok := port.(string)
|
portString, ok := port.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("misc.serial.client port must be a string")
|
return nil, fmt.Errorf("serial.client port must be a string")
|
||||||
}
|
}
|
||||||
|
|
||||||
framingMethod := "RAW"
|
framingMethod := "RAW"
|
||||||
@@ -50,7 +50,7 @@ func init() {
|
|||||||
framingMethodString, ok := framingMethodRaw.(string)
|
framingMethodString, ok := framingMethodRaw.(string)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("misc.serial.client framing method must be a string")
|
return nil, fmt.Errorf("serial.client framing method must be a string")
|
||||||
}
|
}
|
||||||
framingMethod = framingMethodString
|
framingMethod = framingMethodString
|
||||||
}
|
}
|
||||||
@@ -63,12 +63,12 @@ func init() {
|
|||||||
|
|
||||||
buadRate, ok := params["baudRate"]
|
buadRate, ok := params["baudRate"]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("misc.serial.client requires a baudRate parameter")
|
return nil, fmt.Errorf("serial.client requires a baudRate parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
baudRateNum, ok := buadRate.(float64)
|
baudRateNum, ok := buadRate.(float64)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("misc.serial.client baudRate must be a number")
|
return nil, fmt.Errorf("serial.client baudRate must be a number")
|
||||||
}
|
}
|
||||||
|
|
||||||
mode := serial.Mode{
|
mode := serial.Mode{
|
||||||
@@ -92,7 +92,7 @@ func (mc *SerialClient) SetupPort() error {
|
|||||||
|
|
||||||
port, err := serial.Open(mc.Port, mc.Mode)
|
port, err := serial.Open(mc.Port, mc.Mode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("misc.serial.client can't open input port: %s", mc.Port)
|
return fmt.Errorf("serial.client can't open input port: %s", mc.Port)
|
||||||
}
|
}
|
||||||
|
|
||||||
mc.port = port
|
mc.port = port
|
||||||
@@ -105,7 +105,7 @@ func (mc *SerialClient) Run() error {
|
|||||||
// TODO(jwetzell): shutdown with router.Context properly
|
// TODO(jwetzell): shutdown with router.Context properly
|
||||||
go func() {
|
go func() {
|
||||||
<-mc.ctx.Done()
|
<-mc.ctx.Done()
|
||||||
slog.Debug("router context done in module", "id", mc.config.Id)
|
slog.Debug("router context done in module", "id", mc.Id())
|
||||||
if mc.port != nil {
|
if mc.port != nil {
|
||||||
mc.port.Close()
|
mc.port.Close()
|
||||||
}
|
}
|
||||||
@@ -115,10 +115,10 @@ func (mc *SerialClient) Run() error {
|
|||||||
err := mc.SetupPort()
|
err := mc.SetupPort()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if mc.ctx.Err() != nil {
|
if mc.ctx.Err() != nil {
|
||||||
slog.Debug("router context done in module", "id", mc.config.Id)
|
slog.Debug("router context done in module", "id", mc.Id())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
slog.Error("misc.serial.client", "id", mc.config.Id, "error", err.Error())
|
slog.Error("serial.client", "id", mc.Id(), "error", err.Error())
|
||||||
time.Sleep(time.Second * 2)
|
time.Sleep(time.Second * 2)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -126,14 +126,14 @@ func (mc *SerialClient) Run() error {
|
|||||||
buffer := make([]byte, 1024)
|
buffer := make([]byte, 1024)
|
||||||
select {
|
select {
|
||||||
case <-mc.ctx.Done():
|
case <-mc.ctx.Done():
|
||||||
slog.Debug("router context done in module", "id", mc.config.Id)
|
slog.Debug("router context done in module", "id", mc.Id())
|
||||||
return nil
|
return nil
|
||||||
default:
|
default:
|
||||||
READ:
|
READ:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-mc.ctx.Done():
|
case <-mc.ctx.Done():
|
||||||
slog.Debug("router context done in module", "id", mc.config.Id)
|
slog.Debug("router context done in module", "id", mc.Id())
|
||||||
return nil
|
return nil
|
||||||
default:
|
default:
|
||||||
byteCount, err := mc.port.Read(buffer)
|
byteCount, err := mc.port.Read(buffer)
|
||||||
@@ -148,9 +148,9 @@ func (mc *SerialClient) Run() error {
|
|||||||
messages := mc.Framer.Decode(buffer[0:byteCount])
|
messages := mc.Framer.Decode(buffer[0:byteCount])
|
||||||
for _, message := range messages {
|
for _, message := range messages {
|
||||||
if mc.router != nil {
|
if mc.router != nil {
|
||||||
mc.router.HandleInput(mc.config.Id, message)
|
mc.router.HandleInput(mc.Id(), message)
|
||||||
} else {
|
} else {
|
||||||
slog.Error("misc.serial.client has no router", "id", mc.config.Id)
|
slog.Error("serial.client has no router", "id", mc.Id())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -166,7 +166,7 @@ func (mc *SerialClient) Output(payload any) error {
|
|||||||
payloadBytes, ok := payload.([]byte)
|
payloadBytes, ok := payload.([]byte)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("misc.serial.client can only ouptut bytes")
|
return fmt.Errorf("serial.client can only ouptut bytes")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := mc.port.Write(mc.Framer.Encode(payloadBytes))
|
_, err := mc.port.Write(mc.Framer.Encode(payloadBytes))
|
||||||
|
|||||||
185
internal/module/sip-call-server.go
Normal file
185
internal/module/sip-call-server.go
Normal file
@@ -0,0 +1,185 @@
|
|||||||
|
package module
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log/slog"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/emiago/diago"
|
||||||
|
"github.com/emiago/diago/media"
|
||||||
|
"github.com/emiago/sipgo"
|
||||||
|
"github.com/emiago/sipgo/sip"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/route"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SIPCallServer struct {
|
||||||
|
config config.ModuleConfig
|
||||||
|
ctx context.Context
|
||||||
|
router route.RouteIO
|
||||||
|
IP string
|
||||||
|
Port int
|
||||||
|
Transport string
|
||||||
|
UserAgent string
|
||||||
|
dg *diago.Diago
|
||||||
|
}
|
||||||
|
|
||||||
|
type SIPCallMessage struct {
|
||||||
|
To string
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
RegisterModule(ModuleRegistration{
|
||||||
|
Type: "sip.call.server",
|
||||||
|
New: func(ctx context.Context, config config.ModuleConfig, router route.RouteIO) (Module, error) {
|
||||||
|
params := config.Params
|
||||||
|
portNum := 5060
|
||||||
|
|
||||||
|
port, ok := params["port"]
|
||||||
|
if ok {
|
||||||
|
specificPortNum, ok := port.(float64)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("sip.call.server port must be a number")
|
||||||
|
}
|
||||||
|
portNum = int(specificPortNum)
|
||||||
|
}
|
||||||
|
|
||||||
|
ipString := "0.0.0.0"
|
||||||
|
|
||||||
|
ip, ok := params["ip"]
|
||||||
|
if ok {
|
||||||
|
|
||||||
|
specificIpString, ok := ip.(string)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("sip.call.server ip must be a string")
|
||||||
|
}
|
||||||
|
ipString = specificIpString
|
||||||
|
}
|
||||||
|
|
||||||
|
transportString := "udp"
|
||||||
|
|
||||||
|
transport, ok := params["transport"]
|
||||||
|
if ok {
|
||||||
|
|
||||||
|
specificTransportString, ok := transport.(string)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("sip.call.server transport must be a string")
|
||||||
|
}
|
||||||
|
transportString = specificTransportString
|
||||||
|
}
|
||||||
|
|
||||||
|
userAgentString := "showbridge"
|
||||||
|
|
||||||
|
userAgent, ok := params["userAgent"]
|
||||||
|
if ok {
|
||||||
|
|
||||||
|
specificTransportString, ok := userAgent.(string)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("sip.call.server userAgent must be a string")
|
||||||
|
}
|
||||||
|
userAgentString = specificTransportString
|
||||||
|
}
|
||||||
|
return &SIPCallServer{config: config, ctx: ctx, router: router, IP: ipString, Port: int(portNum), Transport: transportString, UserAgent: userAgentString}, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sds *SIPCallServer) Id() string {
|
||||||
|
return sds.config.Id
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sds *SIPCallServer) Type() string {
|
||||||
|
return sds.config.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sds *SIPCallServer) Run() error {
|
||||||
|
diagoLogger := slog.New(slog.NewJSONHandler(io.Discard, nil))
|
||||||
|
|
||||||
|
ua, _ := sipgo.NewUA(
|
||||||
|
sipgo.WithUserAgent(sds.UserAgent),
|
||||||
|
sipgo.WithUserAgentTransportLayerOptions(sip.WithTransportLayerLogger(diagoLogger)),
|
||||||
|
sipgo.WithUserAgentTransactionLayerOptions(sip.WithTransactionLayerLogger(diagoLogger)),
|
||||||
|
)
|
||||||
|
defer ua.Close()
|
||||||
|
|
||||||
|
sip.SetDefaultLogger(diagoLogger)
|
||||||
|
media.SetDefaultLogger(diagoLogger)
|
||||||
|
dg := diago.NewDiago(ua, diago.WithLogger(diagoLogger), diago.WithTransport(
|
||||||
|
diago.Transport{
|
||||||
|
Transport: sds.Transport,
|
||||||
|
BindHost: sds.IP,
|
||||||
|
BindPort: sds.Port,
|
||||||
|
},
|
||||||
|
))
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
dg.Serve(sds.ctx, func(inDialog *diago.DialogServerSession) {
|
||||||
|
sds.HandleCall(inDialog)
|
||||||
|
})
|
||||||
|
}()
|
||||||
|
|
||||||
|
sds.dg = dg
|
||||||
|
|
||||||
|
<-sds.ctx.Done()
|
||||||
|
slog.Debug("router context done in module", "id", sds.Id())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sds *SIPCallServer) HandleCall(inDialog *diago.DialogServerSession) {
|
||||||
|
inDialog.Trying()
|
||||||
|
inDialog.Ringing()
|
||||||
|
inDialog.Answer()
|
||||||
|
sds.router.HandleInput(sds.Id(), SIPCallMessage{
|
||||||
|
To: inDialog.ToUser(),
|
||||||
|
})
|
||||||
|
<-inDialog.Context().Done()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sds *SIPCallServer) Output(payload any) error {
|
||||||
|
|
||||||
|
payloadMsg, ok := payload.(string)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("sip.call.server output payload must be of type string")
|
||||||
|
}
|
||||||
|
|
||||||
|
if sds.dg == nil {
|
||||||
|
return fmt.Errorf("sip.call.server diago is not initialized")
|
||||||
|
}
|
||||||
|
|
||||||
|
var uri sip.Uri
|
||||||
|
err := sip.ParseUri(payloadMsg, &uri)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("sip.call.server output payload is not a valid SIP URI: %v", err)
|
||||||
|
}
|
||||||
|
outDialog, err := sds.dg.NewDialog(uri, diago.NewDialogOptions{
|
||||||
|
Transport: sds.Transport,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("sip.call.server failed to create new dialog: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = outDialog.Invite(sds.ctx, diago.InviteClientOptions{})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("sip.call.server failed to send invite: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = outDialog.Ack(sds.ctx)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("sip.call.server failed to send ack: %v", err)
|
||||||
|
}
|
||||||
|
// TODO(jwetzell): make this configurable
|
||||||
|
// NOTE(jwetzell): wait 5 seconds before hanging up the call
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
err = outDialog.Hangup(sds.ctx)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("sip.call.server failed to hangup call: %v", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
163
internal/module/sip-dtmf-server.go
Normal file
163
internal/module/sip-dtmf-server.go
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
package module
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log/slog"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/emiago/diago"
|
||||||
|
"github.com/emiago/diago/media"
|
||||||
|
"github.com/emiago/sipgo"
|
||||||
|
"github.com/emiago/sipgo/sip"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/route"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SIPDTMFServer struct {
|
||||||
|
config config.ModuleConfig
|
||||||
|
ctx context.Context
|
||||||
|
router route.RouteIO
|
||||||
|
IP string
|
||||||
|
Port int
|
||||||
|
Transport string
|
||||||
|
Separator string
|
||||||
|
}
|
||||||
|
|
||||||
|
type SIPDTMFMessage struct {
|
||||||
|
To string
|
||||||
|
Digits string
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
RegisterModule(ModuleRegistration{
|
||||||
|
Type: "sip.dtmf.server",
|
||||||
|
New: func(ctx context.Context, config config.ModuleConfig, router route.RouteIO) (Module, error) {
|
||||||
|
params := config.Params
|
||||||
|
portNum := 5060
|
||||||
|
|
||||||
|
port, ok := params["port"]
|
||||||
|
if ok {
|
||||||
|
specificPortNum, ok := port.(float64)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("sip.dtmf.server port must be a number")
|
||||||
|
}
|
||||||
|
portNum = int(specificPortNum)
|
||||||
|
}
|
||||||
|
|
||||||
|
ipString := "0.0.0.0"
|
||||||
|
|
||||||
|
ip, ok := params["ip"]
|
||||||
|
if ok {
|
||||||
|
|
||||||
|
specificIpString, ok := ip.(string)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("sip.dtmf.server ip must be a string")
|
||||||
|
}
|
||||||
|
ipString = specificIpString
|
||||||
|
}
|
||||||
|
|
||||||
|
transportString := "udp"
|
||||||
|
|
||||||
|
transport, ok := params["transport"]
|
||||||
|
if ok {
|
||||||
|
|
||||||
|
specificTransportString, ok := transport.(string)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("sip.dtmf.server transport must be a string")
|
||||||
|
}
|
||||||
|
transportString = specificTransportString
|
||||||
|
}
|
||||||
|
|
||||||
|
separator, ok := params["separator"]
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("sip.dtmf.server requires a separator parameter")
|
||||||
|
}
|
||||||
|
separatorString, ok := separator.(string)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("sip.dtmf.server separator must be a string")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(separatorString) != 1 {
|
||||||
|
return nil, fmt.Errorf("sip.dtmf.server separator must be a single character")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.ContainsRune("0123456789*#ABCD", rune(separatorString[0])) {
|
||||||
|
return nil, fmt.Errorf("sip.dtmf.server separator must be a valid DTMF character")
|
||||||
|
}
|
||||||
|
return &SIPDTMFServer{config: config, ctx: ctx, router: router, IP: ipString, Port: int(portNum), Transport: transportString, Separator: separatorString}, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sds *SIPDTMFServer) Id() string {
|
||||||
|
return sds.config.Id
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sds *SIPDTMFServer) Type() string {
|
||||||
|
return sds.config.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sds *SIPDTMFServer) Run() error {
|
||||||
|
diagoLogger := slog.New(slog.NewJSONHandler(io.Discard, nil))
|
||||||
|
|
||||||
|
ua, _ := sipgo.NewUA(
|
||||||
|
sipgo.WithUserAgentTransportLayerOptions(sip.WithTransportLayerLogger(diagoLogger)),
|
||||||
|
sipgo.WithUserAgentTransactionLayerOptions(sip.WithTransactionLayerLogger(diagoLogger)),
|
||||||
|
)
|
||||||
|
defer ua.Close()
|
||||||
|
|
||||||
|
sip.SetDefaultLogger(diagoLogger)
|
||||||
|
media.SetDefaultLogger(diagoLogger)
|
||||||
|
dg := diago.NewDiago(ua, diago.WithLogger(diagoLogger), diago.WithTransport(
|
||||||
|
diago.Transport{
|
||||||
|
Transport: sds.Transport,
|
||||||
|
BindHost: sds.IP,
|
||||||
|
BindPort: sds.Port,
|
||||||
|
},
|
||||||
|
))
|
||||||
|
|
||||||
|
err := dg.Serve(sds.ctx, func(inDialog *diago.DialogServerSession) {
|
||||||
|
sds.HandleCall(inDialog)
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
<-sds.ctx.Done()
|
||||||
|
slog.Debug("router context done in module", "id", sds.Id())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sds *SIPDTMFServer) HandleCall(inDialog *diago.DialogServerSession) error {
|
||||||
|
inDialog.Trying()
|
||||||
|
inDialog.Ringing()
|
||||||
|
inDialog.Answer()
|
||||||
|
|
||||||
|
reader := inDialog.AudioReaderDTMF()
|
||||||
|
userString := ""
|
||||||
|
return reader.Listen(func(dtmf rune) error {
|
||||||
|
if dtmf == rune(sds.Separator[0]) {
|
||||||
|
if sds.router != nil {
|
||||||
|
sds.router.HandleInput(sds.Id(), SIPDTMFMessage{
|
||||||
|
To: inDialog.ToUser(),
|
||||||
|
Digits: userString,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
userString = ""
|
||||||
|
} else {
|
||||||
|
userString += string(dtmf)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}, 5*time.Second)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sds *SIPDTMFServer) Output(payload any) error {
|
||||||
|
return fmt.Errorf("sip.dtmf.server output is not implemented")
|
||||||
|
}
|
||||||
@@ -91,7 +91,7 @@ func (tc *TCPClient) Run() error {
|
|||||||
// TODO(jwetzell): shutdown with router.Context properly
|
// TODO(jwetzell): shutdown with router.Context properly
|
||||||
go func() {
|
go func() {
|
||||||
<-tc.ctx.Done()
|
<-tc.ctx.Done()
|
||||||
slog.Debug("router context done in module", "id", tc.config.Id)
|
slog.Debug("router context done in module", "id", tc.Id())
|
||||||
if tc.conn != nil {
|
if tc.conn != nil {
|
||||||
tc.conn.Close()
|
tc.conn.Close()
|
||||||
}
|
}
|
||||||
@@ -101,10 +101,10 @@ func (tc *TCPClient) Run() error {
|
|||||||
err := tc.SetupConn()
|
err := tc.SetupConn()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if tc.ctx.Err() != nil {
|
if tc.ctx.Err() != nil {
|
||||||
slog.Debug("router context done in module", "id", tc.config.Id)
|
slog.Debug("router context done in module", "id", tc.Id())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
slog.Error("net.tcp.client", "id", tc.config.Id, "error", err.Error())
|
slog.Error("net.tcp.client", "id", tc.Id(), "error", err.Error())
|
||||||
time.Sleep(time.Second * 2)
|
time.Sleep(time.Second * 2)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -112,14 +112,14 @@ func (tc *TCPClient) Run() error {
|
|||||||
buffer := make([]byte, 1024)
|
buffer := make([]byte, 1024)
|
||||||
select {
|
select {
|
||||||
case <-tc.ctx.Done():
|
case <-tc.ctx.Done():
|
||||||
slog.Debug("router context done in module", "id", tc.config.Id)
|
slog.Debug("router context done in module", "id", tc.Id())
|
||||||
return nil
|
return nil
|
||||||
default:
|
default:
|
||||||
READ:
|
READ:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-tc.ctx.Done():
|
case <-tc.ctx.Done():
|
||||||
slog.Debug("router context done in module", "id", tc.config.Id)
|
slog.Debug("router context done in module", "id", tc.Id())
|
||||||
return nil
|
return nil
|
||||||
default:
|
default:
|
||||||
byteCount, err := tc.conn.Read(buffer)
|
byteCount, err := tc.conn.Read(buffer)
|
||||||
@@ -134,9 +134,9 @@ func (tc *TCPClient) Run() error {
|
|||||||
messages := tc.framer.Decode(buffer[0:byteCount])
|
messages := tc.framer.Decode(buffer[0:byteCount])
|
||||||
for _, message := range messages {
|
for _, message := range messages {
|
||||||
if tc.router != nil {
|
if tc.router != nil {
|
||||||
tc.router.HandleInput(tc.config.Id, message)
|
tc.router.HandleInput(tc.Id(), message)
|
||||||
} else {
|
} else {
|
||||||
slog.Error("net.tcp.client has no router", "id", tc.config.Id)
|
slog.Error("net.tcp.client has no router", "id", tc.Id())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ func (ts *TCPServer) handleClient(client *net.TCPConn) {
|
|||||||
ts.connectionsMu.Lock()
|
ts.connectionsMu.Lock()
|
||||||
ts.connections = append(ts.connections, client)
|
ts.connections = append(ts.connections, client)
|
||||||
ts.connectionsMu.Unlock()
|
ts.connectionsMu.Unlock()
|
||||||
slog.Debug("net.tcp.server connection accepted", "id", ts.config.Id, "remoteAddr", client.RemoteAddr().String())
|
slog.Debug("net.tcp.server connection accepted", "id", ts.Id(), "remoteAddr", client.RemoteAddr().String())
|
||||||
defer client.Close()
|
defer client.Close()
|
||||||
|
|
||||||
buffer := make([]byte, 1024)
|
buffer := make([]byte, 1024)
|
||||||
@@ -125,7 +125,7 @@ ClientRead:
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
slog.Debug("net.tcp.server connection reset", "id", ts.config.Id, "remoteAddr", client.RemoteAddr().String())
|
slog.Debug("net.tcp.server connection reset", "id", ts.Id(), "remoteAddr", client.RemoteAddr().String())
|
||||||
ts.connectionsMu.Unlock()
|
ts.connectionsMu.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -138,7 +138,7 @@ ClientRead:
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
slog.Debug("net.tcp.server stream ended", "id", ts.config.Id, "remoteAddr", client.RemoteAddr().String())
|
slog.Debug("net.tcp.server stream ended", "id", ts.Id(), "remoteAddr", client.RemoteAddr().String())
|
||||||
ts.connectionsMu.Unlock()
|
ts.connectionsMu.Unlock()
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@@ -148,9 +148,9 @@ ClientRead:
|
|||||||
messages := ts.Framer.Decode(buffer[0:byteCount])
|
messages := ts.Framer.Decode(buffer[0:byteCount])
|
||||||
for _, message := range messages {
|
for _, message := range messages {
|
||||||
if ts.router != nil {
|
if ts.router != nil {
|
||||||
ts.router.HandleInput(ts.config.Id, message)
|
ts.router.HandleInput(ts.Id(), message)
|
||||||
} else {
|
} else {
|
||||||
slog.Error("net.tcp.server has no router", "id", ts.config.Id)
|
slog.Error("net.tcp.server has no router", "id", ts.Id())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -170,7 +170,7 @@ func (ts *TCPServer) Run() error {
|
|||||||
<-ts.ctx.Done()
|
<-ts.ctx.Done()
|
||||||
close(ts.quit)
|
close(ts.quit)
|
||||||
listener.Close()
|
listener.Close()
|
||||||
slog.Debug("router context done in module", "id", ts.config.Id)
|
slog.Debug("router context done in module", "id", ts.Id())
|
||||||
}()
|
}()
|
||||||
|
|
||||||
AcceptLoop:
|
AcceptLoop:
|
||||||
|
|||||||
@@ -55,11 +55,11 @@ func (t *Timer) Run() error {
|
|||||||
select {
|
select {
|
||||||
case <-t.ctx.Done():
|
case <-t.ctx.Done():
|
||||||
t.timer.Stop()
|
t.timer.Stop()
|
||||||
slog.Debug("router context done in module", "id", t.config.Id)
|
slog.Debug("router context done in module", "id", t.Id())
|
||||||
return nil
|
return nil
|
||||||
case time := <-t.timer.C:
|
case time := <-t.timer.C:
|
||||||
if t.router != nil {
|
if t.router != nil {
|
||||||
t.router.HandleInput(t.config.Id, time)
|
t.router.HandleInput(t.Id(), time)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ func (uc *UDPClient) Run() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
<-uc.ctx.Done()
|
<-uc.ctx.Done()
|
||||||
slog.Debug("router context done in module", "id", uc.config.Id)
|
slog.Debug("router context done in module", "id", uc.Id())
|
||||||
if uc.conn != nil {
|
if uc.conn != nil {
|
||||||
uc.conn.Close()
|
uc.conn.Close()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ func (um *UDPMulticast) Run() error {
|
|||||||
select {
|
select {
|
||||||
case <-um.ctx.Done():
|
case <-um.ctx.Done():
|
||||||
// TODO(jwetzell): cleanup?
|
// TODO(jwetzell): cleanup?
|
||||||
slog.Debug("router context done in module", "id", um.config.Id)
|
slog.Debug("router context done in module", "id", um.Id())
|
||||||
return nil
|
return nil
|
||||||
default:
|
default:
|
||||||
um.conn.SetDeadline(time.Now().Add(time.Millisecond * 200))
|
um.conn.SetDeadline(time.Now().Add(time.Millisecond * 200))
|
||||||
@@ -97,9 +97,9 @@ func (um *UDPMulticast) Run() error {
|
|||||||
message := buffer[:numBytes]
|
message := buffer[:numBytes]
|
||||||
|
|
||||||
if um.router != nil {
|
if um.router != nil {
|
||||||
um.router.HandleInput(um.config.Id, message)
|
um.router.HandleInput(um.Id(), message)
|
||||||
} else {
|
} else {
|
||||||
slog.Error("net.udp.multicast has no router", "id", um.config.Id)
|
slog.Error("net.udp.multicast has no router", "id", um.Id())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ func (us *UDPServer) Run() error {
|
|||||||
select {
|
select {
|
||||||
case <-us.ctx.Done():
|
case <-us.ctx.Done():
|
||||||
// TODO(jwetzell): cleanup?
|
// TODO(jwetzell): cleanup?
|
||||||
slog.Debug("router context done in module", "id", us.config.Id)
|
slog.Debug("router context done in module", "id", us.Id())
|
||||||
return nil
|
return nil
|
||||||
default:
|
default:
|
||||||
listener.SetDeadline(time.Now().Add(time.Millisecond * 200))
|
listener.SetDeadline(time.Now().Add(time.Millisecond * 200))
|
||||||
@@ -96,9 +96,9 @@ func (us *UDPServer) Run() error {
|
|||||||
}
|
}
|
||||||
message := buffer[:numBytes]
|
message := buffer[:numBytes]
|
||||||
if us.router != nil {
|
if us.router != nil {
|
||||||
us.router.HandleInput(us.config.Id, message)
|
us.router.HandleInput(us.Id(), message)
|
||||||
} else {
|
} else {
|
||||||
slog.Error("net.udp.server has no router", "id", us.config.Id)
|
slog.Error("net.udp.server has no router", "id", us.Id())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
55
internal/processor/midi-message-filter.go
Normal file
55
internal/processor/midi-message-filter.go
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
//go:build cgo
|
||||||
|
|
||||||
|
package processor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
"gitlab.com/gomidi/midi/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MIDIMessageFilter struct {
|
||||||
|
config config.ProcessorConfig
|
||||||
|
MIDIType string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mmf *MIDIMessageFilter) Process(ctx context.Context, payload any) (any, error) {
|
||||||
|
payloadMessage, ok := payload.(midi.Message)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("midi.message.filter processor only accepts an midi.Message")
|
||||||
|
}
|
||||||
|
|
||||||
|
if payloadMessage.Type().String() != mmf.MIDIType {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return payloadMessage, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mmf *MIDIMessageFilter) Type() string {
|
||||||
|
return mmf.config.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
RegisterProcessor(ProcessorRegistration{
|
||||||
|
Type: "midi.message.filter",
|
||||||
|
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||||
|
params := config.Params
|
||||||
|
midiType, ok := params["type"]
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("midi.message.filter requires a type parameter")
|
||||||
|
}
|
||||||
|
midiTypeString, ok := midiType.(string)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("midi.message.filter type must be a string")
|
||||||
|
}
|
||||||
|
|
||||||
|
return &MIDIMessageFilter{config: config, MIDIType: midiTypeString}, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
90
internal/processor/midi-message-unpack.go
Normal file
90
internal/processor/midi-message-unpack.go
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
//go:build cgo
|
||||||
|
|
||||||
|
package processor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
"gitlab.com/gomidi/midi/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MIDIMessageUnpack struct {
|
||||||
|
config config.ProcessorConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
type MIDINoteOn struct {
|
||||||
|
Channel uint8
|
||||||
|
Note uint8
|
||||||
|
Velocity uint8
|
||||||
|
}
|
||||||
|
|
||||||
|
type MIDINoteOff struct {
|
||||||
|
Channel uint8
|
||||||
|
Note uint8
|
||||||
|
Velocity uint8
|
||||||
|
}
|
||||||
|
|
||||||
|
type MIDIControlChange struct {
|
||||||
|
Channel uint8
|
||||||
|
Control uint8
|
||||||
|
Value uint8
|
||||||
|
}
|
||||||
|
|
||||||
|
type MIDIProgramChange struct {
|
||||||
|
Channel uint8
|
||||||
|
Program uint8
|
||||||
|
}
|
||||||
|
|
||||||
|
type MIDIPitchBend struct {
|
||||||
|
Channel uint8
|
||||||
|
Relative int16
|
||||||
|
Absolute uint16
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mmu *MIDIMessageUnpack) Process(ctx context.Context, payload any) (any, error) {
|
||||||
|
payloadMidi, ok := payload.(midi.Message)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("midi.message.unpack processor only accepts a midi.Message")
|
||||||
|
}
|
||||||
|
|
||||||
|
switch payloadMidi.Type() {
|
||||||
|
case midi.NoteOnMsg:
|
||||||
|
noteOnMsg := MIDINoteOn{}
|
||||||
|
payloadMidi.GetNoteOn(¬eOnMsg.Channel, ¬eOnMsg.Note, ¬eOnMsg.Velocity)
|
||||||
|
return noteOnMsg, nil
|
||||||
|
case midi.NoteOffMsg:
|
||||||
|
noteOffMsg := MIDINoteOff{}
|
||||||
|
payloadMidi.GetNoteOff(¬eOffMsg.Channel, ¬eOffMsg.Note, ¬eOffMsg.Velocity)
|
||||||
|
return noteOffMsg, nil
|
||||||
|
case midi.ControlChangeMsg:
|
||||||
|
controlChangeMsg := MIDIControlChange{}
|
||||||
|
payloadMidi.GetControlChange(&controlChangeMsg.Channel, &controlChangeMsg.Control, &controlChangeMsg.Value)
|
||||||
|
return controlChangeMsg, nil
|
||||||
|
case midi.ProgramChangeMsg:
|
||||||
|
programChangeMsg := MIDIProgramChange{}
|
||||||
|
payloadMidi.GetProgramChange(&programChangeMsg.Channel, &programChangeMsg.Program)
|
||||||
|
return programChangeMsg, nil
|
||||||
|
case midi.PitchBendMsg:
|
||||||
|
pitchBendMsg := MIDIPitchBend{}
|
||||||
|
payloadMidi.GetPitchBend(&pitchBendMsg.Channel, &pitchBendMsg.Relative, &pitchBendMsg.Absolute)
|
||||||
|
return pitchBendMsg, nil
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("midi.message.unpack message type not supported %v", payloadMidi.Type())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mmu *MIDIMessageUnpack) Type() string {
|
||||||
|
return mmu.config.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
RegisterProcessor(ProcessorRegistration{
|
||||||
|
Type: "midi.message.unpack",
|
||||||
|
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||||
|
return &MIDIMessageUnpack{config: config}, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -8,10 +8,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type MQTTMessage struct {
|
type MQTTMessage struct {
|
||||||
Topic string
|
topic string
|
||||||
QoS byte
|
qos byte
|
||||||
Payload any
|
payload []byte
|
||||||
Retained bool
|
retained bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type MQTTMessageCreate struct {
|
type MQTTMessageCreate struct {
|
||||||
@@ -19,16 +19,44 @@ type MQTTMessageCreate struct {
|
|||||||
Topic string
|
Topic string
|
||||||
QoS byte
|
QoS byte
|
||||||
Retained bool
|
Retained bool
|
||||||
Payload any
|
Payload []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (mm MQTTMessage) Duplicate() bool {
|
||||||
|
// TODO(jwetzell): implement?
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mm MQTTMessage) Qos() byte {
|
||||||
|
return mm.qos
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mm MQTTMessage) Retained() bool {
|
||||||
|
return mm.retained
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mm MQTTMessage) Topic() string {
|
||||||
|
return mm.topic
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mm MQTTMessage) MessageID() uint16 {
|
||||||
|
// TODO(jwetzell): implement?
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mm MQTTMessage) Payload() []byte {
|
||||||
|
return mm.payload
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mm MQTTMessage) Ack() {}
|
||||||
|
|
||||||
func (mmc *MQTTMessageCreate) Process(ctx context.Context, payload any) (any, error) {
|
func (mmc *MQTTMessageCreate) Process(ctx context.Context, payload any) (any, error) {
|
||||||
|
|
||||||
message := MQTTMessage{
|
message := MQTTMessage{
|
||||||
Topic: mmc.Topic,
|
topic: mmc.Topic,
|
||||||
QoS: mmc.QoS,
|
qos: mmc.QoS,
|
||||||
Retained: mmc.Retained,
|
retained: mmc.Retained,
|
||||||
Payload: mmc.Payload,
|
payload: mmc.Payload,
|
||||||
}
|
}
|
||||||
|
|
||||||
return message, nil
|
return message, nil
|
||||||
@@ -86,7 +114,19 @@ func init() {
|
|||||||
return nil, fmt.Errorf("mqtt.message.create requires an payload parameter")
|
return nil, fmt.Errorf("mqtt.message.create requires an payload parameter")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &MQTTMessageCreate{config: config, Topic: topicString, QoS: byte(qosByte), Retained: retainedBool, Payload: payload}, nil
|
if payloadBytes, ok := payload.([]byte); ok {
|
||||||
|
return &MQTTMessageCreate{config: config, Topic: topicString, QoS: byte(qosByte), Retained: retainedBool, Payload: payloadBytes}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
payloadString, ok := payload.(string)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("mqtt.message.create payload must be a string or byte array")
|
||||||
|
}
|
||||||
|
|
||||||
|
payloadBytes := []byte(payloadString)
|
||||||
|
|
||||||
|
return &MQTTMessageCreate{config: config, Topic: topicString, QoS: byte(qosByte), Retained: retainedBool, Payload: payloadBytes}, nil
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user