mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-08-31 10:48:59 +00:00
Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e30376ffb9 | |||
| ca78efa27a | |||
| 36dfda68ce | |||
| 7675eaa226 | |||
| 10ca10db0d | |||
| 31dc7e1027 | |||
| 34527d7fc2 | |||
| adf649fac8 | |||
| 54ada59f6e | |||
| f9287cc87e | |||
| 5574b73c78 | |||
| 2491353860 | |||
| 252662db9f | |||
| 6f71797ac8 | |||
| 11df8f8a4b | |||
| f0f074950e | |||
| 79ab05adb4 | |||
| 70e1251391 | |||
| 0b3d04d6db | |||
| 35ca05404e |
@@ -38,12 +38,9 @@ jobs:
|
||||
|
||||
- name: clean up coverage report
|
||||
run: cat coverage.out | grep -v "github.com/jwetzell/showbridge-go/cmd" > coverage.nocmd.out
|
||||
- name: Update coverage report
|
||||
uses: ncruces/go-coverage-report@v0.3.2
|
||||
|
||||
- name: Upload coverage reports to Codecov
|
||||
uses: codecov/codecov-action@v7
|
||||
with:
|
||||
coverage-file: coverage.nocmd.out
|
||||
report: true
|
||||
chart: true
|
||||
amend: true
|
||||
if: github.event_name == 'push'
|
||||
continue-on-error: true
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
files: coverage.nocmd.out
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
ARG GO_VERSION=1.26.3
|
||||
ARG GO_VERSION=1.27.0
|
||||
FROM golang:${GO_VERSION}-alpine AS build
|
||||
RUN apk --no-cache add ca-certificates tzdata git
|
||||
WORKDIR /build
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
# showbridge (go edition)
|
||||
|
||||
[](https://raw.githack.com/wiki/jwetzell/showbridge-go/coverage.html)
|
||||
[](https://codecov.io/gh/jwetzell/showbridge-go)
|
||||
|
||||
Simple protocol router _/s_
|
||||
|
||||
</div>
|
||||
@@ -24,7 +25,6 @@ Simple protocol router _/s_
|
||||
- Serial (not included in pre-built binaries yet)
|
||||
- [OSC](https://opensoundcontrol.stanford.edu/spec-1_0.html)
|
||||
- [FreeD](https://ptzoptics.com/freed/)
|
||||
- [SIP](https://en.wikipedia.org/wiki/Session_Initiation_Protocol)
|
||||
- [Redis](https://redis.io/)
|
||||
|
||||
### CLI Usage
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
module github.com/jwetzell/showbridge-go
|
||||
|
||||
go 1.26.3
|
||||
go 1.27.0
|
||||
|
||||
require (
|
||||
github.com/eclipse/paho.mqtt.golang v1.5.1
|
||||
github.com/emiago/diago v0.32.0
|
||||
github.com/emiago/sipgo v1.5.0
|
||||
github.com/expr-lang/expr v1.17.8
|
||||
github.com/extism/go-sdk v1.7.1
|
||||
github.com/google/jsonschema-go v0.4.3
|
||||
github.com/gorilla/websocket v1.5.3
|
||||
github.com/jwetzell/artnet-go v0.3.0
|
||||
github.com/jwetzell/free-d-go v0.2.0
|
||||
github.com/jwetzell/osc-go v0.3.0
|
||||
github.com/jwetzell/osc-go v0.3.1
|
||||
github.com/jwetzell/psn-go v0.3.0
|
||||
github.com/nats-io/nats-server/v2 v2.14.5
|
||||
github.com/nats-io/nats-server/v2 v2.14.6
|
||||
github.com/nats-io/nats.go v1.53.1
|
||||
github.com/redis/go-redis/v9 v9.22.0
|
||||
github.com/urfave/cli/v3 v3.11.0
|
||||
@@ -31,16 +29,10 @@ require (
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/dylibso/observe-sdk/go v0.0.0-20240828172851-9145d8ad07e1 // indirect
|
||||
github.com/emiago/dtls/v3 v3.0.0-20260122183559-8b8d23e359c0 // indirect
|
||||
github.com/go-audio/riff v1.0.0 // indirect
|
||||
github.com/gobwas/glob v0.2.3 // 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/go-tpm v0.9.8 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/ianlancetaylor/demangle v0.0.0-20260505044615-1ff4bf46051f // indirect
|
||||
github.com/icholy/digest v1.1.0 // indirect
|
||||
github.com/klauspost/compress v1.19.2 // indirect
|
||||
github.com/mattn/go-isatty v0.0.24 // indirect
|
||||
github.com/minio/highwayhash v1.0.4 // indirect
|
||||
@@ -48,17 +40,10 @@ require (
|
||||
github.com/nats-io/nkeys v0.4.16 // indirect
|
||||
github.com/nats-io/nuid v1.0.1 // indirect
|
||||
github.com/ncruces/go-strftime v1.0.0 // 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.10.2 // indirect
|
||||
github.com/pion/srtp/v3 v3.0.10 // indirect
|
||||
github.com/pion/transport/v4 v4.0.1 // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||
github.com/rogpeppe/go-internal v1.14.1 // indirect
|
||||
github.com/tetratelabs/wabin v0.0.0-20230304001439-f6f874872834 // indirect
|
||||
github.com/tetratelabs/wazero v1.11.0 // indirect
|
||||
github.com/zaf/g711 v1.4.0 // indirect
|
||||
go.opentelemetry.io/proto/otlp v1.10.0 // indirect
|
||||
go.uber.org/atomic v1.11.0 // indirect
|
||||
go.yaml.in/yaml/v2 v2.4.2 // indirect
|
||||
@@ -68,7 +53,7 @@ require (
|
||||
golang.org/x/sync v0.22.0 // indirect
|
||||
golang.org/x/sys v0.47.0 // indirect
|
||||
google.golang.org/protobuf v1.36.11 // indirect
|
||||
gopkg.in/hraban/opus.v2 v2.0.0-20230925203106-0188a62cb302 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
||||
modernc.org/libc v1.75.4 // indirect
|
||||
modernc.org/libquickjs v0.13.1 // indirect
|
||||
modernc.org/mathutil v1.7.1 // indirect
|
||||
|
||||
@@ -14,30 +14,12 @@ github.com/dylibso/observe-sdk/go v0.0.0-20240828172851-9145d8ad07e1 h1:idfl8M8r
|
||||
github.com/dylibso/observe-sdk/go v0.0.0-20240828172851-9145d8ad07e1/go.mod h1:C8DzXehI4zAbrdlbtOByKX6pfivJTBiV9Jjqv56Yd9Q=
|
||||
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/emiago/diago v0.31.0 h1:w/GZQnMS60EBANKXMnf/MjFDlUfcfHLPOlEKiZkaNe0=
|
||||
github.com/emiago/diago v0.31.0/go.mod h1:CP7p9/aBZG/fQEYdtGdQkCblr1jLr1zbxODcu8MryVU=
|
||||
github.com/emiago/diago v0.32.0 h1:U6urbJc/LD2HwrHVe1d/yT0lMgyDMRUFle7gMqJe0Jg=
|
||||
github.com/emiago/diago v0.32.0/go.mod h1:CP7p9/aBZG/fQEYdtGdQkCblr1jLr1zbxODcu8MryVU=
|
||||
github.com/emiago/dtls/v3 v3.0.0-20260122183559-8b8d23e359c0 h1:o4LxpUnZ1zxiQ+Qjc9kLwXcjz31NGAHmnZ7xoJto3VM=
|
||||
github.com/emiago/dtls/v3 v3.0.0-20260122183559-8b8d23e359c0/go.mod h1:ydcZ977eS1I6uOWodzMuw30BwvNAzT9su/xcNYSJqjA=
|
||||
github.com/emiago/sipgo v1.4.3 h1:Ju1Ilp0LhTcSHCyp2jBYAQDQ8TAwuxQHzT1IhO6jSIY=
|
||||
github.com/emiago/sipgo v1.4.3/go.mod h1:DuwAxBZhKMqIzQFPGZb1MVAGU6Wuxj64oTOhd5dx/FY=
|
||||
github.com/emiago/sipgo v1.5.0 h1:YVq5Rw5eVN4DRsB5MoBBiiurpHXXCjJstaH9cTvrlyI=
|
||||
github.com/emiago/sipgo v1.5.0/go.mod h1:DuwAxBZhKMqIzQFPGZb1MVAGU6Wuxj64oTOhd5dx/FY=
|
||||
github.com/expr-lang/expr v1.17.8 h1:W1loDTT+0PQf5YteHSTpju2qfUfNoBt4yw9+wOEU9VM=
|
||||
github.com/expr-lang/expr v1.17.8/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4=
|
||||
github.com/extism/go-sdk v1.7.1 h1:lWJos6uY+tRFdlIHR+SJjwFDApY7OypS/2nMhiVQ9Sw=
|
||||
github.com/extism/go-sdk v1.7.1/go.mod h1:IT+Xdg5AZM9hVtpFUA+uZCJMge/hbvshl8bwzLtFyKA=
|
||||
github.com/go-audio/riff v1.0.0 h1:d8iCGbDvox9BfLagY94fBynxSPHO80LmZCaOsmKxokA=
|
||||
github.com/go-audio/riff v1.0.0/go.mod h1:l3cQwc85y79NQFCRB7TiPoNiaijp6q8Z0Uv38rVG498=
|
||||
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
|
||||
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
|
||||
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/go-tpm v0.9.8 h1:slArAR9Ft+1ybZu0lBwpSmpwhRXaa85hWtMinMyRAWo=
|
||||
@@ -54,24 +36,23 @@ github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
|
||||
github.com/ianlancetaylor/demangle v0.0.0-20260505044615-1ff4bf46051f h1:NW3E2QSchEk63/fjeEvWOa2cE02FSv9ox//VE/N4c8g=
|
||||
github.com/ianlancetaylor/demangle v0.0.0-20260505044615-1ff4bf46051f/go.mod h1:gx7rwoVhcfuVKG5uya9Hs3Sxj7EIvldVofAWIUtGouw=
|
||||
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/artnet-go v0.3.0 h1:MDHElOSbpgmIbYGHO9SoxsT7ynrYtV5/UHGT82geHk0=
|
||||
github.com/jwetzell/artnet-go v0.3.0/go.mod h1:zqRsSsrd6rPwJacwscPteDqGIqevjZ3Z6dpp092VJ1w=
|
||||
github.com/jwetzell/free-d-go v0.2.0 h1:8WQW4du8Sf3d18aUzk9n5jZtHE6WdDQHDFjkFffvycc=
|
||||
github.com/jwetzell/free-d-go v0.2.0/go.mod h1:yHuRy51NeDfN26eJ6wzZgys8qyQiS7hkYILw8yF+UJ4=
|
||||
github.com/jwetzell/osc-go v0.3.0 h1:z75TxuQSEmdcmZ56OAepkDa3m88SdZh//3m4nBb/XZI=
|
||||
github.com/jwetzell/osc-go v0.3.0/go.mod h1:kCs329JxY6Qjga08tRQ/Gl0PqhgQzLIMpOhm6uszvIc=
|
||||
github.com/jwetzell/osc-go v0.3.1 h1:IyXCUxzMFjiUFOeqOpz57zNv5D3Zf9yEYs2tKmPQnxA=
|
||||
github.com/jwetzell/osc-go v0.3.1/go.mod h1:vdfsVQ0fvtaOVwnvaz7IJ0gqtx2bLcswsVU9k7h2UGo=
|
||||
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/klauspost/compress v1.19.0 h1:sXLILfc9jV2QYWkzFOPWStmcUVH2RHEB1JCdY2oVvCQ=
|
||||
github.com/klauspost/compress v1.19.0/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ=
|
||||
github.com/klauspost/compress v1.19.2 h1:hMRETovs/pu/dVWN7zIT1PGG8t509MwT6bO7XSi26R8=
|
||||
github.com/klauspost/compress v1.19.2/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ=
|
||||
github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE=
|
||||
github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
|
||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
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.24 h1:tGZZoVgT/KiqK1c8ocVLeDS8BSWMRd47J3Lbz7vsReI=
|
||||
@@ -80,12 +61,8 @@ github.com/minio/highwayhash v1.0.4 h1:asJizugGgchQod2ja9NJlGOWq4s7KsAWr5XUc9Clg
|
||||
github.com/minio/highwayhash v1.0.4/go.mod h1:GGYsuwP/fPD6Y9hMiXuapVvlIUEhFhMTh0rxU3ik1LQ=
|
||||
github.com/nats-io/jwt/v2 v2.8.2 h1:XXRgB60MSTnqsRwejQurVDs/hcv2dkt+86GjI+I/bMc=
|
||||
github.com/nats-io/jwt/v2 v2.8.2/go.mod h1:Ag/56sq9OblL4JgdYufDd16Egb17Kr/8WwwuO/forVc=
|
||||
github.com/nats-io/nats-server/v2 v2.14.4 h1:efgjZ8cdExAKRuqSg8UPJFprb+l7NlBtSDPhDlw3rO4=
|
||||
github.com/nats-io/nats-server/v2 v2.14.4/go.mod h1:BltdpOYestjbtQSnVO2zGHdg5SGBZjt+GYTgB9LZq/I=
|
||||
github.com/nats-io/nats-server/v2 v2.14.5 h1:M6yeo/Xb7khi97RSEVELof3DForDqmYza3P4tHCPFWw=
|
||||
github.com/nats-io/nats-server/v2 v2.14.5/go.mod h1:1D3iocrisKvWaD1B/imqarTqmaGrWMqALMLbEDo3v7Q=
|
||||
github.com/nats-io/nats.go v1.52.0 h1:n3avV4VBsCgsdwh71TppsTwtv+QdPs7ntSKM8qJLGsc=
|
||||
github.com/nats-io/nats.go v1.52.0/go.mod h1:26HypzazeOkyO3/mqd1zZd53STJN0EjCYF9Uy2ZOBno=
|
||||
github.com/nats-io/nats-server/v2 v2.14.6 h1:dHjEHa49lUTxIb5jrsk5kz/AmOyOQ4T9ti8djcBumDQ=
|
||||
github.com/nats-io/nats-server/v2 v2.14.6/go.mod h1:u/0bNBzN/m5orQGz7q2NNzxCQ6PWdwaOSwPNDADZn/A=
|
||||
github.com/nats-io/nats.go v1.53.1 h1:Otsq3uLc/kLdjmkNHkXH0jBqwUquwdKFoe3fq6/3/Xo=
|
||||
github.com/nats-io/nats.go v1.53.1/go.mod h1:26HypzazeOkyO3/mqd1zZd53STJN0EjCYF9Uy2ZOBno=
|
||||
github.com/nats-io/nkeys v0.4.16 h1:rd5oAuLOb8mnAycB0xleuEBNS1pVVnN0fv/FF34Eypg=
|
||||
@@ -94,18 +71,6 @@ 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/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w=
|
||||
github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
|
||||
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.16 h1:fk1B1dNW4hsI78XUCljZJlC4kZOPk67mNRuQ0fcEkSo=
|
||||
github.com/pion/rtcp v1.2.16/go.mod h1:/as7VKfYbs5NIb4h6muQ35kQF/J0ZVNz2Z3xKoCBYOo=
|
||||
github.com/pion/rtp v1.10.2 h1:l+f6tTDcAH6xwepaAoW791ddhuYsJlqRATOzirO04Mo=
|
||||
github.com/pion/rtp v1.10.2/go.mod h1:Au8fc6cEByy8RLTwKTQTEeQqDB/SJDxwL4mZuxYA5Pk=
|
||||
github.com/pion/srtp/v3 v3.0.10 h1:tFirkpBb3XccP5VEXLi50GqXhv5SKPxqrdlhDCJlZrQ=
|
||||
github.com/pion/srtp/v3 v3.0.10/go.mod h1:3mOTIB0cq9qlbn59V4ozvv9ClW/BSEbRp4cY0VtaR7M=
|
||||
github.com/pion/transport/v4 v4.0.1 h1:sdROELU6BZ63Ab7FrOLn13M6YdJLY20wldXW2Cu2k8o=
|
||||
github.com/pion/transport/v4 v4.0.1/go.mod h1:nEuEA4AD5lPdcIegQDpVLgNoDGreqM/YqmEx3ovP4jM=
|
||||
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/redis/go-redis/v9 v9.22.0 h1:laDvpYXTJtZLloinw1fA5Kqd6HAEH2XKxOkG/PDq2F0=
|
||||
@@ -120,12 +85,8 @@ github.com/tetratelabs/wabin v0.0.0-20230304001439-f6f874872834 h1:ZF+QBjOI+tILZ
|
||||
github.com/tetratelabs/wabin v0.0.0-20230304001439-f6f874872834/go.mod h1:m9ymHTgNSEjuxvw8E7WWe4Pl4hZQHXONY8wE6dMLaRk=
|
||||
github.com/tetratelabs/wazero v1.11.0 h1:+gKemEuKCTevU4d7ZTzlsvgd1uaToIDtlQlmNbwqYhA=
|
||||
github.com/tetratelabs/wazero v1.11.0/go.mod h1:eV28rsN8Q+xwjogd7f4/Pp4xFxO7uOGbLcD/LzB1wiU=
|
||||
github.com/urfave/cli/v3 v3.10.1 h1:7Kx9H50hrHbRbyxgO1KP6/BcbiGRz0uYh5YyQ30JEEY=
|
||||
github.com/urfave/cli/v3 v3.10.1/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso=
|
||||
github.com/urfave/cli/v3 v3.11.0 h1:P/euJp99kb9p0tlVY+iYTLYYTAQlfl0hR2gUO1Img1Q=
|
||||
github.com/urfave/cli/v3 v3.11.0/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=
|
||||
github.com/zeebo/xxh3 v1.1.0 h1:s7DLGDK45Dyfg7++yxI0khrfwq9661w9EN78eP/UZVs=
|
||||
github.com/zeebo/xxh3 v1.1.0/go.mod h1:IisAie1LELR4xhVinxWS5+zf1lA4p0MW4T+w+W07F5s=
|
||||
gitlab.com/gomidi/midi/v2 v2.3.24 h1:afkq5nhlzKvZaj9QK80YbK8tH3lIlKLnPPP9HxxD7Do=
|
||||
@@ -140,43 +101,32 @@ go.yaml.in/yaml/v2 v2.4.2 h1:DzmwEr2rDGHl7lsFgAHxmNz/1NlQ7xLIrlN2h5d1eGI=
|
||||
go.yaml.in/yaml/v2 v2.4.2/go.mod h1:081UH+NErpNdqlCXm3TtEran0rJZGxAYx9hb/ELlsPU=
|
||||
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
|
||||
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
|
||||
golang.org/x/crypto v0.54.0 h1:YLIA59K4fiNzHzjnZt2tUJQjQtUWfWbeHBqKtk3eScw=
|
||||
golang.org/x/crypto v0.54.0/go.mod h1:KWL8ny2AZdGR2cWmzeHrp2azQPGogOv+HeQaVEXC2dk=
|
||||
golang.org/x/crypto v0.55.0 h1:+KWHjbgOaAQ66dh/YlkZKHlz9ZUlq61AFirAR9ntP8M=
|
||||
golang.org/x/crypto v0.55.0/go.mod h1:uq0V9dE/fzQuJtbnL+2EhWOE63vo164FY8xqEnV9xis=
|
||||
golang.org/x/mod v0.37.0 h1:vF1DjpVEshcIqoEaauuHebaLk1O1forxjxBaVn884JQ=
|
||||
golang.org/x/mod v0.37.0/go.mod h1:m8S8VeM9r4dzDwjrKO0a1sZP3YjeMamRRlD+fmR2Q/0=
|
||||
golang.org/x/net v0.56.0 h1:Rw8j/hFzGvJUZwNBXnAtf5sVDVt+65SK2C7IxCxZt5o=
|
||||
golang.org/x/net v0.56.0/go.mod h1:D3Ku6r+V6JROoZK144D2XfMHFcMq/0zSfLelVTCFKec=
|
||||
golang.org/x/mod v0.38.0 h1:MECBjubtXD7yj4HrhIUcywNaGeNVUdfVnxmPajOk4yk=
|
||||
golang.org/x/mod v0.38.0/go.mod h1:V6Xz0pq8TQ3dGqVQ1FVHuelZpAL0uNhSkk9ogYP3c40=
|
||||
golang.org/x/net v0.57.0 h1:K5+3DljvIuDG9/Jv9rvyMywYNFCQ9RSUY6OOTTkT+tE=
|
||||
golang.org/x/net v0.57.0/go.mod h1:KpXc8iv+r3XplLAG/f7Jsf9RPszJzdR0f58q9vGOuEU=
|
||||
golang.org/x/sync v0.21.0 h1:HLII4xRRTtCRkxYp4HNFF0Js/Og6q2i++KXbg0gHCwM=
|
||||
golang.org/x/sync v0.21.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
||||
golang.org/x/sync v0.22.0 h1:SZjpbeLmrCk4xhRSZFNZW5gFUeCeFgjekvI/+gfScek=
|
||||
golang.org/x/sync v0.22.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs=
|
||||
golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
||||
golang.org/x/time v0.15.0 h1:bbrp8t3bGUeFOx08pvsMYRTCVSMk89u4tKbNOZbp88U=
|
||||
golang.org/x/time v0.15.0/go.mod h1:Y4YMaQmXwGQZoFaVFk4YpCt4FLQMYKZe9oeV/f4MSno=
|
||||
golang.org/x/tools v0.47.0 h1:7Kn5x/d1svx/PzryTsqeoZN4TZwqeH5pGWjefhLi/1Q=
|
||||
golang.org/x/tools v0.47.0/go.mod h1:dFHnyTvFWY212G+h7ZY4Vsp/K3U4/7W9TyVaAul8uCA=
|
||||
golang.org/x/tools v0.48.0 h1:3+hClM1aLL5mjMKm5ovokw9epgRXPuu2tILgismM6RE=
|
||||
golang.org/x/tools v0.48.0/go.mod h1:08xX0orndb/F7jJxGDicx061tyd5pcMto75YMAXr6lk=
|
||||
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
|
||||
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
|
||||
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/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.29.1 h1:MKgdCV3WykTSPqpVrnxdEDS0HEd2FHpKZDzxzU5LyeI=
|
||||
modernc.org/cc/v4 v4.29.1/go.mod h1:OnovgIhbbMXMu1aISnJ0wvVD1KnW+cAUJkIrAWh+kVI=
|
||||
modernc.org/ccgo/v4 v4.34.6 h1:sBgfIwyN0TQ9C5hwIeuqyeAKyMWnbvj2fvpF4L11uzU=
|
||||
modernc.org/ccgo/v4 v4.34.6/go.mod h1:SZ8YcN9NG7XVsQYdm6jYBvi8PQP1qi+kqB6OhjqI3Fk=
|
||||
modernc.org/cc/v4 v4.29.2 h1:h6+9ciCnPKutf4I03CvheAvDLX7+IHlqR6Iy6J+cgd8=
|
||||
modernc.org/cc/v4 v4.29.2/go.mod h1:OnovgIhbbMXMu1aISnJ0wvVD1KnW+cAUJkIrAWh+kVI=
|
||||
modernc.org/ccgo/v4 v4.35.0 h1:F+TUsmw09QxLzmi3aeYYGxjAXarmZaKgj3mKQHNaA8w=
|
||||
modernc.org/ccgo/v4 v4.35.0/go.mod h1:qrVGs9S3Sr2Ztcg9ve+kTAYMp5a3YvWjo+SoN06kJ5I=
|
||||
modernc.org/fileutil v1.4.0 h1:j6ZzNTftVS054gi281TyLjHPp6CPHr2KCxEXjEbD6SM=
|
||||
modernc.org/fileutil v1.4.0/go.mod h1:EqdKFDxiByqxLk8ozOxObDSfcVOv/54xDs/DUHdvCUU=
|
||||
modernc.org/gc/v2 v2.6.5 h1:nyqdV8q46KvTpZlsw66kWqwXRHdjIlJOhG6kxiV/9xI=
|
||||
@@ -185,34 +135,20 @@ modernc.org/gc/v3 v3.1.5 h1:21ldfPfRYE31Tb7B3mwAK8gy1AxP4+dKjrOQPfqakoc=
|
||||
modernc.org/gc/v3 v3.1.5/go.mod h1:HFK/6AGESC7Ex+EZJhJ2Gni6cTaYpSMmU/cT9RmlfYY=
|
||||
modernc.org/goabi0 v0.2.0 h1:HvEowk7LxcPd0eq6mVOAEMai46V+i7Jrj13t4AzuNks=
|
||||
modernc.org/goabi0 v0.2.0/go.mod h1:CEFRnnJhKvWT1c1JTI3Avm+tgOWbkOu5oPA8eH8LnMI=
|
||||
modernc.org/libc v1.74.4 h1:fX1Omw4o2/1C2iRkkIsrQTasJQldLhRmuPreXLoWs9k=
|
||||
modernc.org/libc v1.74.4/go.mod h1:eeQAS9W3sZeKYMFubydxJpII9ybHWshk+7or7bLG9co=
|
||||
modernc.org/libc v1.75.3 h1:vCqT5+R0jPXMnvMkGo0T2zXvFNth+lYXVCx5X7CCX/g=
|
||||
modernc.org/libc v1.75.3/go.mod h1:MjAX68G+0oufI+hNuh0QXcK+Ap+sL8bNPPcIC6EqOfo=
|
||||
modernc.org/libc v1.75.4 h1:EHQJNYDC6LiDIOqM76862xe4frbDc7IzEOZTtGxZV8Q=
|
||||
modernc.org/libc v1.75.4/go.mod h1:bO5o2ztHxBb2rjz0PgdHN0sSMw57CgxGFLZ3Qd/QpVQ=
|
||||
modernc.org/libquickjs v0.13.1 h1:uCb9AYyEyL1JS2dnKtLZKWH/vDb36cx1Mr1SIdbzb8A=
|
||||
modernc.org/libquickjs v0.13.1/go.mod h1:tCEsA1Zda1+C5JagFIJGqjYZOxDPFOUYjK3dGhEeq0g=
|
||||
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
|
||||
modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
|
||||
modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI=
|
||||
modernc.org/memory v1.11.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
|
||||
modernc.org/memory v1.12.0 h1:twkmYNkGXCvtYWzoux02jtK6eovjZbdI0uHFUYp6kuU=
|
||||
modernc.org/memory v1.12.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
|
||||
modernc.org/memory v1.12.1 h1:nFMiWrpStgZczNl6XI9GnIk/rWhYIyHGUaR04pGbp9g=
|
||||
modernc.org/memory v1.12.1/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
|
||||
modernc.org/opt v0.2.0 h1:tGyef5ApycA7FSEOMraay9SaTk5zmbx7Tu+cJs4QKZg=
|
||||
modernc.org/opt v0.2.0/go.mod h1:03fq9lsNfvkYSfxrfUhZCWPk1lm4cq4N+Bh//bEtgns=
|
||||
modernc.org/quickjs v0.23.0 h1:k+px+rFrMqHm2LPMvrd+vCR+8m6eogiTkROz+YJHkj8=
|
||||
modernc.org/quickjs v0.23.0/go.mod h1:bFvjVk4JGlbqLYXVFt72YvwdnHbwtNIE9nQ+eh4fdi0=
|
||||
modernc.org/quickjs v0.24.0 h1:Vo7bkccDIstEmNf7umJPPVBaEmwoAo/8RX1ymVPmZQM=
|
||||
modernc.org/quickjs v0.24.0/go.mod h1:KYT0ACuCE+4eFnNc3WEZBUWfsFeIfsdtyDSltZz21iE=
|
||||
modernc.org/quickjs v0.24.2 h1:wfVrO+6ailTzKHA7LAlknnOXH/rJyiIgw4+WNI0m6ew=
|
||||
modernc.org/quickjs v0.24.2/go.mod h1:4SZg8rXHeX2pO2VpBVmqSDrIOYD/UF5Cnh3ew4tzFng=
|
||||
modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w=
|
||||
modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE=
|
||||
modernc.org/sqlite v1.56.0 h1:/D8e2RfFqoy/Zc6PuC76U28zFwmI/sYx1Kjm4yEn9e0=
|
||||
modernc.org/sqlite v1.56.0/go.mod h1:yCJ2cmAaIkHQ25oXWrF8H4O1lIfPYPR26yCEDj2P3pQ=
|
||||
modernc.org/sqlite v1.57.0 h1:qNQP6xnx5M0ISNtlnxoOX0+cD5bJ0/gr9aMmndFczzg=
|
||||
modernc.org/sqlite v1.57.0/go.mod h1:yCJ2cmAaIkHQ25oXWrF8H4O1lIfPYPR26yCEDj2P3pQ=
|
||||
modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0=
|
||||
|
||||
@@ -1,269 +0,0 @@
|
||||
package module
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log/slog"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/emiago/diago"
|
||||
"github.com/emiago/diago/media"
|
||||
"github.com/emiago/sipgo"
|
||||
"github.com/emiago/sipgo/sip"
|
||||
"github.com/google/jsonschema-go/jsonschema"
|
||||
"github.com/jwetzell/showbridge-go/internal/common"
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
)
|
||||
|
||||
func init() {
|
||||
RegisterModule(ModuleRegistration{
|
||||
Type: "sip.call.server",
|
||||
Title: "SIP Call Server",
|
||||
ParamsSchema: &jsonschema.Schema{
|
||||
Type: "object",
|
||||
Properties: map[string]*jsonschema.Schema{
|
||||
"ip": {
|
||||
Title: "IP",
|
||||
Description: "the IP address to bind the SIP server to",
|
||||
Type: "string",
|
||||
Default: json.RawMessage(`"0.0.0.0"`),
|
||||
},
|
||||
"port": {
|
||||
Title: "Port",
|
||||
Description: "the port for the SIP server to listen on",
|
||||
Type: "integer",
|
||||
Minimum: jsonschema.Ptr[float64](1024),
|
||||
Maximum: jsonschema.Ptr[float64](65535),
|
||||
Default: json.RawMessage(`5060`),
|
||||
},
|
||||
"transport": {
|
||||
Title: "Transport",
|
||||
Description: "the transport protocol to use for the SIP server",
|
||||
Type: "string",
|
||||
Enum: []any{"udp", "tcp", "ws", "udp4", "tcp4"},
|
||||
Default: json.RawMessage(`"udp"`),
|
||||
},
|
||||
"userAgent": {
|
||||
Title: "User Agent",
|
||||
Description: "the user agent string to use",
|
||||
Type: "string",
|
||||
Default: json.RawMessage(`"showbridge"`),
|
||||
},
|
||||
},
|
||||
Required: []string{},
|
||||
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||
},
|
||||
New: func(moduleConfig config.ModuleConfig) (common.Module, error) {
|
||||
params := moduleConfig.Params
|
||||
portNum, err := params.GetInt("port")
|
||||
if err != nil {
|
||||
|
||||
if errors.Is(err, config.ErrParamNotFound) {
|
||||
portNum = 5060
|
||||
} else {
|
||||
return nil, fmt.Errorf("sip.call.server port error: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
ipString, err := params.GetString("ip")
|
||||
if err != nil {
|
||||
if errors.Is(err, config.ErrParamNotFound) {
|
||||
ipString = "0.0.0.0"
|
||||
} else {
|
||||
return nil, fmt.Errorf("sip.call.server ip error: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
transportString, err := params.GetString("transport")
|
||||
if err != nil {
|
||||
if errors.Is(err, config.ErrParamNotFound) {
|
||||
transportString = "udp"
|
||||
} else {
|
||||
return nil, fmt.Errorf("sip.call.server transport error: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
userAgentString, err := params.GetString("userAgent")
|
||||
if err != nil {
|
||||
if errors.Is(err, config.ErrParamNotFound) {
|
||||
userAgentString = "showbridge"
|
||||
} else {
|
||||
return nil, fmt.Errorf("sip.call.server userAgent error: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return &SIPCallServer{config: moduleConfig, IP: ipString, Port: int(portNum), Transport: transportString, UserAgent: userAgentString, logger: CreateLogger(moduleConfig)}, nil
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
type SIPCallServer struct {
|
||||
config config.ModuleConfig
|
||||
ctx context.Context
|
||||
inputHandler common.InputHandler
|
||||
IP string
|
||||
Port int
|
||||
Transport string
|
||||
UserAgent string
|
||||
logger *slog.Logger
|
||||
cancel context.CancelFunc
|
||||
ua *sipgo.UserAgent
|
||||
uaMu sync.Mutex
|
||||
}
|
||||
|
||||
type SIPCallMessage struct {
|
||||
To string
|
||||
}
|
||||
|
||||
type SIPCall struct {
|
||||
inDialog *diago.DialogServerSession
|
||||
lock sync.Mutex
|
||||
}
|
||||
|
||||
type sipCallContextKey string
|
||||
|
||||
func (scs *SIPCallServer) Id() string {
|
||||
return scs.config.Id
|
||||
}
|
||||
|
||||
func (scs *SIPCallServer) Type() string {
|
||||
return scs.config.Type
|
||||
}
|
||||
|
||||
func (scs *SIPCallServer) Start(ctx context.Context, inputHandler common.InputHandler) error {
|
||||
scs.logger.Debug("running")
|
||||
scs.inputHandler = inputHandler
|
||||
moduleContext, cancel := context.WithCancel(ctx)
|
||||
scs.ctx = moduleContext
|
||||
scs.cancel = cancel
|
||||
|
||||
diagoLogger := slog.New(slog.NewJSONHandler(io.Discard, nil))
|
||||
|
||||
ua, _ := sipgo.NewUA(
|
||||
sipgo.WithUserAgent(scs.UserAgent),
|
||||
sipgo.WithUserAgentTransportLayerOptions(sip.WithTransportLayerLogger(diagoLogger)),
|
||||
sipgo.WithUserAgentTransactionLayerOptions(sip.WithTransactionLayerLogger(diagoLogger)),
|
||||
)
|
||||
scs.uaMu.Lock()
|
||||
scs.ua = ua
|
||||
scs.uaMu.Unlock()
|
||||
|
||||
sip.SetDefaultLogger(diagoLogger)
|
||||
media.SetDefaultLogger(diagoLogger)
|
||||
dg := diago.NewDiago(ua, diago.WithLogger(diagoLogger), diago.WithTransport(
|
||||
diago.Transport{
|
||||
Transport: scs.Transport,
|
||||
BindHost: scs.IP,
|
||||
BindPort: scs.Port,
|
||||
},
|
||||
))
|
||||
|
||||
err := dg.Serve(scs.ctx, func(inDialog *diago.DialogServerSession) {
|
||||
scs.HandleCall(inDialog)
|
||||
})
|
||||
if err != nil {
|
||||
scs.logger.Error("diago serve error", "error", err)
|
||||
}
|
||||
|
||||
<-scs.ctx.Done()
|
||||
scs.logger.Debug("done")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (scs *SIPCallServer) HandleCall(inDialog *diago.DialogServerSession) {
|
||||
inDialog.Trying()
|
||||
inDialog.Ringing()
|
||||
inDialog.Answer()
|
||||
|
||||
dialogContext := context.WithValue(scs.ctx, sipCallContextKey("call"), &SIPCall{
|
||||
inDialog: inDialog,
|
||||
})
|
||||
if scs.inputHandler != nil {
|
||||
scs.inputHandler(dialogContext, scs.Id(), SIPCallMessage{
|
||||
To: inDialog.ToUser(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (scs *SIPCallServer) Output(ctx context.Context, payload any) error {
|
||||
|
||||
call, ok := ctx.Value(sipCallContextKey("call")).(*SIPCall)
|
||||
|
||||
if !ok {
|
||||
return errors.New("sip.call.server output must originate from sip.call.server input")
|
||||
}
|
||||
|
||||
gotLock := call.lock.TryLock()
|
||||
|
||||
if !gotLock {
|
||||
return errors.New("sip.call.server call is already locked")
|
||||
}
|
||||
|
||||
if call.inDialog.LoadState() == sip.DialogStateEnded {
|
||||
return errors.New("sip.call.server inDialog already ended")
|
||||
}
|
||||
|
||||
payloadDTMFResponse, ok := common.GetAnyAs[processor.SipDTMFResponse](payload)
|
||||
|
||||
if ok {
|
||||
dtmfWriter, err := call.inDialog.AudioWriterDTMF()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
time.Sleep(time.Millisecond * time.Duration(payloadDTMFResponse.PreWait))
|
||||
for i, dtmfRune := range payloadDTMFResponse.Digits {
|
||||
err := dtmfWriter.WriteDTMF(dtmfRune)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("sip.dtmf.server error output dtmf digit at index %d", i)
|
||||
}
|
||||
}
|
||||
time.Sleep(time.Millisecond * time.Duration(payloadDTMFResponse.PostWait))
|
||||
return nil
|
||||
}
|
||||
|
||||
payloadAudioFileResponse, ok := common.GetAnyAs[processor.SipAudioFileResponse](payload)
|
||||
|
||||
if ok {
|
||||
audioFile, err := os.Open(payloadAudioFileResponse.AudioFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer audioFile.Close()
|
||||
|
||||
playback, err := call.inDialog.PlaybackCreate()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
time.Sleep(time.Millisecond * time.Duration(payloadAudioFileResponse.PreWait))
|
||||
|
||||
_, err = playback.Play(audioFile, "audio/wav")
|
||||
|
||||
time.Sleep(time.Millisecond * time.Duration(payloadAudioFileResponse.PostWait))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return errors.New("sip.dtmf.server can only output SipDTMFResponse or SipAudioFileResponse")
|
||||
}
|
||||
|
||||
func (scs *SIPCallServer) Stop() {
|
||||
if scs.cancel != nil {
|
||||
defer scs.cancel()
|
||||
}
|
||||
scs.uaMu.Lock()
|
||||
defer scs.uaMu.Unlock()
|
||||
if scs.ua != nil {
|
||||
scs.ua.Close()
|
||||
}
|
||||
}
|
||||
@@ -1,308 +0,0 @@
|
||||
package module
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log/slog"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/emiago/diago"
|
||||
"github.com/emiago/diago/media"
|
||||
"github.com/emiago/sipgo"
|
||||
"github.com/emiago/sipgo/sip"
|
||||
"github.com/google/jsonschema-go/jsonschema"
|
||||
"github.com/jwetzell/showbridge-go/internal/common"
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
)
|
||||
|
||||
func init() {
|
||||
RegisterModule(ModuleRegistration{
|
||||
Type: "sip.dtmf.server",
|
||||
Title: "SIP DTMF Server",
|
||||
ParamsSchema: &jsonschema.Schema{
|
||||
Type: "object",
|
||||
Properties: map[string]*jsonschema.Schema{
|
||||
"ip": {
|
||||
Title: "IP",
|
||||
Description: "the IP address to bind the SIP server to",
|
||||
Type: "string",
|
||||
Default: json.RawMessage(`"0.0.0.0"`),
|
||||
},
|
||||
"port": {
|
||||
Title: "Port",
|
||||
Description: "the port for the SIP server to listen on",
|
||||
Type: "integer",
|
||||
Minimum: jsonschema.Ptr[float64](1024),
|
||||
Maximum: jsonschema.Ptr[float64](65535),
|
||||
Default: json.RawMessage(`5060`),
|
||||
},
|
||||
"transport": {
|
||||
Title: "Transport",
|
||||
Description: "the transport protocol to use for the SIP server",
|
||||
Type: "string",
|
||||
Enum: []any{"udp", "tcp", "ws", "udp4", "tcp4"},
|
||||
Default: json.RawMessage(`"udp"`),
|
||||
},
|
||||
"userAgent": {
|
||||
Title: "User Agent",
|
||||
Description: "the user agent string to use",
|
||||
Type: "string",
|
||||
Default: json.RawMessage(`"showbridge"`),
|
||||
},
|
||||
"separator": {
|
||||
Title: "DTMF Separator",
|
||||
Description: "the DTMF character to use as a separator between DTMF digit groups",
|
||||
Type: "string",
|
||||
MinLength: new(1),
|
||||
MaxLength: new(1),
|
||||
},
|
||||
},
|
||||
Required: []string{"separator"},
|
||||
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||
},
|
||||
New: func(moduleConfig config.ModuleConfig) (common.Module, error) {
|
||||
params := moduleConfig.Params
|
||||
|
||||
portNum, err := params.GetInt("port")
|
||||
if err != nil {
|
||||
|
||||
if errors.Is(err, config.ErrParamNotFound) {
|
||||
portNum = 5060
|
||||
} else {
|
||||
return nil, fmt.Errorf("sip.dtmf.server port error: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
ipString, err := params.GetString("ip")
|
||||
if err != nil {
|
||||
if errors.Is(err, config.ErrParamNotFound) {
|
||||
ipString = "0.0.0.0"
|
||||
} else {
|
||||
return nil, fmt.Errorf("sip.dtmf.server ip error: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
transportString, err := params.GetString("transport")
|
||||
if err != nil {
|
||||
if errors.Is(err, config.ErrParamNotFound) {
|
||||
transportString = "udp"
|
||||
} else {
|
||||
return nil, fmt.Errorf("sip.dtmf.server transport error: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
userAgentString, err := params.GetString("userAgent")
|
||||
if err != nil {
|
||||
if errors.Is(err, config.ErrParamNotFound) {
|
||||
userAgentString = "showbridge"
|
||||
} else {
|
||||
return nil, fmt.Errorf("sip.dtmf.server userAgent error: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
separatorString, err := params.GetString("separator")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("sip.dtmf.server separator error: %w", err)
|
||||
}
|
||||
|
||||
if len(separatorString) != 1 {
|
||||
return nil, errors.New("sip.dtmf.server separator must be a single character")
|
||||
}
|
||||
|
||||
if !strings.ContainsRune("0123456789*#ABCD", rune(separatorString[0])) {
|
||||
return nil, errors.New("sip.dtmf.server separator must be a valid DTMF character")
|
||||
}
|
||||
return &SIPDTMFServer{config: moduleConfig, IP: ipString, Port: int(portNum), Transport: transportString, UserAgent: userAgentString, Separator: separatorString, logger: CreateLogger(moduleConfig)}, nil
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
type SIPDTMFServer struct {
|
||||
config config.ModuleConfig
|
||||
ctx context.Context
|
||||
inputHandler common.InputHandler
|
||||
IP string
|
||||
Port int
|
||||
Transport string
|
||||
UserAgent string
|
||||
Separator string
|
||||
logger *slog.Logger
|
||||
cancel context.CancelFunc
|
||||
ua *sipgo.UserAgent
|
||||
uaMu sync.Mutex
|
||||
}
|
||||
|
||||
type SIPDTMFMessage struct {
|
||||
To string
|
||||
Digits string
|
||||
}
|
||||
|
||||
type SIPDTMFCall struct {
|
||||
inDialog *diago.DialogServerSession
|
||||
lock sync.Mutex
|
||||
}
|
||||
|
||||
func (sds *SIPDTMFServer) Id() string {
|
||||
return sds.config.Id
|
||||
}
|
||||
|
||||
func (sds *SIPDTMFServer) Type() string {
|
||||
return sds.config.Type
|
||||
}
|
||||
|
||||
func (sds *SIPDTMFServer) Start(ctx context.Context, inputHandler common.InputHandler) error {
|
||||
sds.logger.Debug("running")
|
||||
sds.inputHandler = inputHandler
|
||||
moduleContext, cancel := context.WithCancel(ctx)
|
||||
sds.ctx = moduleContext
|
||||
sds.cancel = cancel
|
||||
|
||||
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)),
|
||||
)
|
||||
|
||||
sds.uaMu.Lock()
|
||||
sds.ua = ua
|
||||
sds.uaMu.Unlock()
|
||||
|
||||
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()
|
||||
sds.logger.Debug("done")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sds *SIPDTMFServer) HandleCall(inDialog *diago.DialogServerSession) error {
|
||||
inDialog.Trying()
|
||||
inDialog.Ringing()
|
||||
inDialog.Answer()
|
||||
|
||||
reader, err := inDialog.AudioReaderDTMF()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
userString := ""
|
||||
|
||||
return reader.Listen(func(dtmf rune) error {
|
||||
if dtmf == rune(sds.Separator[0]) {
|
||||
if sds.inputHandler != nil {
|
||||
dialogContext := context.WithValue(sds.ctx, sipCallContextKey("call"), &SIPDTMFCall{
|
||||
inDialog: inDialog,
|
||||
})
|
||||
sds.inputHandler(dialogContext, sds.Id(), SIPDTMFMessage{
|
||||
To: inDialog.ToUser(),
|
||||
Digits: userString,
|
||||
})
|
||||
}
|
||||
userString = ""
|
||||
} else {
|
||||
userString += string(dtmf)
|
||||
}
|
||||
return nil
|
||||
}, 5*time.Second)
|
||||
}
|
||||
|
||||
func (sds *SIPDTMFServer) Output(ctx context.Context, payload any) error {
|
||||
call, ok := ctx.Value(sipCallContextKey("call")).(*SIPDTMFCall)
|
||||
|
||||
if !ok {
|
||||
return errors.New("sip.dtmf.server output must originate from sip.dtmf.server input")
|
||||
}
|
||||
|
||||
gotLock := call.lock.TryLock()
|
||||
|
||||
if !gotLock {
|
||||
return errors.New("sip.dtmf.server call is already locked")
|
||||
}
|
||||
|
||||
if call.inDialog.LoadState() == sip.DialogStateEnded {
|
||||
return errors.New("sip.dtmf.server inDialog already ended")
|
||||
}
|
||||
|
||||
payloadDTMFResponse, ok := common.GetAnyAs[processor.SipDTMFResponse](payload)
|
||||
|
||||
if ok {
|
||||
dtmfWriter, err := call.inDialog.AudioWriterDTMF()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
time.Sleep(time.Millisecond * time.Duration(payloadDTMFResponse.PreWait))
|
||||
for i, dtmfRune := range payloadDTMFResponse.Digits {
|
||||
err := dtmfWriter.WriteDTMF(dtmfRune)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("sip.dtmf.server error output dtmf digit at index %d", i)
|
||||
}
|
||||
}
|
||||
time.Sleep(time.Millisecond * time.Duration(payloadDTMFResponse.PostWait))
|
||||
return nil
|
||||
}
|
||||
|
||||
payloadAudioFileResponse, ok := common.GetAnyAs[processor.SipAudioFileResponse](payload)
|
||||
|
||||
if ok {
|
||||
audioFile, err := os.Open(payloadAudioFileResponse.AudioFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer audioFile.Close()
|
||||
|
||||
playback, err := call.inDialog.PlaybackCreate()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
time.Sleep(time.Millisecond * time.Duration(payloadAudioFileResponse.PreWait))
|
||||
|
||||
_, err = playback.Play(audioFile, "audio/wav")
|
||||
|
||||
time.Sleep(time.Millisecond * time.Duration(payloadAudioFileResponse.PostWait))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
return errors.New("sip.dtmf.server can only output SipDTMFResponse or SipAudioFileResponse")
|
||||
}
|
||||
|
||||
func (sds *SIPDTMFServer) Stop() {
|
||||
if sds.cancel != nil {
|
||||
defer sds.cancel()
|
||||
}
|
||||
sds.uaMu.Lock()
|
||||
defer sds.uaMu.Unlock()
|
||||
if sds.ua != nil {
|
||||
sds.ua.Close()
|
||||
}
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
package module_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/module"
|
||||
)
|
||||
|
||||
func TestSIPCallServerFromRegistry(t *testing.T) {
|
||||
registration, ok := module.GetModuleRegistration("sip.call.server")
|
||||
if !ok {
|
||||
t.Fatalf("sip.call.server module not registered")
|
||||
}
|
||||
|
||||
moduleInstance, err := registration.New(config.ModuleConfig{
|
||||
Id: "test",
|
||||
Type: "sip.call.server",
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create sip.call.server module: %s", err)
|
||||
}
|
||||
|
||||
if moduleInstance.Id() != "test" {
|
||||
t.Fatalf("sip.call.server module has wrong id: %s", moduleInstance.Id())
|
||||
}
|
||||
|
||||
if moduleInstance.Type() != "sip.call.server" {
|
||||
t.Fatalf("sip.call.server module has wrong type: %s", moduleInstance.Type())
|
||||
}
|
||||
}
|
||||
|
||||
func TestBadSIPCallServer(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
params map[string]any
|
||||
errorString string
|
||||
}{
|
||||
{
|
||||
name: "non-number port param",
|
||||
params: map[string]any{
|
||||
"port": "8000",
|
||||
},
|
||||
errorString: "sip.call.server port error: not a number",
|
||||
},
|
||||
{
|
||||
name: "non-string ip param",
|
||||
params: map[string]any{
|
||||
"ip": 123,
|
||||
},
|
||||
errorString: "sip.call.server ip error: not a string",
|
||||
},
|
||||
{
|
||||
name: "non-string transport param",
|
||||
params: map[string]any{
|
||||
"transport": 123,
|
||||
},
|
||||
errorString: "sip.call.server transport error: not a string",
|
||||
},
|
||||
{
|
||||
name: "non-string userAgent param",
|
||||
params: map[string]any{
|
||||
"userAgent": 123,
|
||||
},
|
||||
errorString: "sip.call.server userAgent error: not a string",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
|
||||
registration, ok := module.GetModuleRegistration("sip.call.server")
|
||||
if !ok {
|
||||
t.Fatalf("sip.call.server module not registered")
|
||||
}
|
||||
|
||||
moduleInstance, err := registration.New(config.ModuleConfig{
|
||||
Id: "test",
|
||||
Type: "sip.call.server",
|
||||
Params: test.params,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
if test.errorString != err.Error() {
|
||||
t.Fatalf("sip.call.server got error '%s', expected '%s'", err.Error(), test.errorString)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
err = moduleInstance.Start(t.Context(), nil)
|
||||
|
||||
if err == nil {
|
||||
t.Fatalf("sip.call.server expected to fail")
|
||||
}
|
||||
|
||||
if err.Error() != test.errorString {
|
||||
t.Fatalf("sip.call.server got error '%s', expected '%s'", err.Error(), test.errorString)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,121 +0,0 @@
|
||||
package module_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/module"
|
||||
)
|
||||
|
||||
func TestSIPDTMFServerFromRegistry(t *testing.T) {
|
||||
registration, ok := module.GetModuleRegistration("sip.dtmf.server")
|
||||
if !ok {
|
||||
t.Fatalf("sip.dtmf.server module not registered")
|
||||
}
|
||||
|
||||
moduleInstance, err := registration.New(config.ModuleConfig{
|
||||
Id: "test",
|
||||
Type: "sip.dtmf.server",
|
||||
Params: map[string]any{
|
||||
"separator": "#",
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create sip.dtmf.server module: %s", err)
|
||||
}
|
||||
|
||||
if moduleInstance.Id() != "test" {
|
||||
t.Fatalf("sip.dtmf.server module has wrong id: %s", moduleInstance.Id())
|
||||
}
|
||||
|
||||
if moduleInstance.Type() != "sip.dtmf.server" {
|
||||
t.Fatalf("sip.dtmf.server module has wrong type: %s", moduleInstance.Type())
|
||||
}
|
||||
}
|
||||
|
||||
func TestBadSIPDTMFServer(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
params map[string]any
|
||||
errorString string
|
||||
}{
|
||||
{
|
||||
name: "no separator param",
|
||||
params: map[string]any{},
|
||||
errorString: "sip.dtmf.server separator error: not found",
|
||||
},
|
||||
{
|
||||
name: "non-string separator param",
|
||||
params: map[string]any{
|
||||
"separator": 123,
|
||||
},
|
||||
errorString: "sip.dtmf.server separator error: not a string",
|
||||
},
|
||||
{
|
||||
name: "non-number port param",
|
||||
params: map[string]any{
|
||||
"separator": "#",
|
||||
"port": "8000",
|
||||
},
|
||||
errorString: "sip.dtmf.server port error: not a number",
|
||||
},
|
||||
{
|
||||
name: "non-string ip param",
|
||||
params: map[string]any{
|
||||
"separator": "#",
|
||||
"ip": 123,
|
||||
},
|
||||
errorString: "sip.dtmf.server ip error: not a string",
|
||||
},
|
||||
{
|
||||
name: "non-string transport param",
|
||||
params: map[string]any{
|
||||
"separator": "#",
|
||||
"transport": 123,
|
||||
},
|
||||
errorString: "sip.dtmf.server transport error: not a string",
|
||||
},
|
||||
{
|
||||
name: "non-string userAgent param",
|
||||
params: map[string]any{
|
||||
"separator": "#",
|
||||
"userAgent": 123,
|
||||
},
|
||||
errorString: "sip.dtmf.server userAgent error: not a string",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
|
||||
registration, ok := module.GetModuleRegistration("sip.dtmf.server")
|
||||
if !ok {
|
||||
t.Fatalf("sip.dtmf.server module not registered")
|
||||
}
|
||||
|
||||
moduleInstance, err := registration.New(config.ModuleConfig{
|
||||
Id: "test",
|
||||
Type: "sip.dtmf.server",
|
||||
Params: test.params,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
if test.errorString != err.Error() {
|
||||
t.Fatalf("sip.dtmf.server got error '%s', expected '%s'", err.Error(), test.errorString)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
err = moduleInstance.Start(t.Context(), nil)
|
||||
|
||||
if err == nil {
|
||||
t.Fatalf("sip.dtmf.server expected to fail")
|
||||
}
|
||||
|
||||
if err.Error() != test.errorString {
|
||||
t.Fatalf("sip.dtmf.server got error '%s', expected '%s'", err.Error(), test.errorString)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,10 @@ func (apd *ArtNetPacketDecode) Process(ctx context.Context, wrappedPayload commo
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (apd *ArtNetPacketDecode) Id() string {
|
||||
return apd.config.Id
|
||||
}
|
||||
|
||||
func (apd *ArtNetPacketDecode) Type() string {
|
||||
return apd.config.Type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,10 @@ func (ape *ArtNetPacketEncode) Process(ctx context.Context, wrappedPayload commo
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (ape *ArtNetPacketEncode) Id() string {
|
||||
return ape.config.Id
|
||||
}
|
||||
|
||||
func (ape *ArtNetPacketEncode) Type() string {
|
||||
return ape.config.Type
|
||||
}
|
||||
|
||||
@@ -143,6 +143,10 @@ func (dq *DbQuery) Process(ctx context.Context, wrappedPayload common.WrappedPay
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (dq *DbQuery) Id() string {
|
||||
return dq.config.Id
|
||||
}
|
||||
|
||||
func (dq *DbQuery) Type() string {
|
||||
return dq.config.Type
|
||||
}
|
||||
|
||||
@@ -33,7 +33,10 @@ func (dl *DebugLog) Process(ctx context.Context, wrappedPayload common.WrappedPa
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (dl *DebugLog) Id() string {
|
||||
return dl.config.Id
|
||||
}
|
||||
|
||||
func (dl *DebugLog) Type() string {
|
||||
return dl.config.Type
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,10 @@ func (fc *FilterChange) Process(ctx context.Context, wrappedPayload common.Wrapp
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (fc *FilterChange) Id() string {
|
||||
return fc.config.Id
|
||||
}
|
||||
|
||||
func (fc *FilterChange) Type() string {
|
||||
return fc.config.Type
|
||||
}
|
||||
|
||||
@@ -76,6 +76,10 @@ func (fe *FilterExpr) Process(ctx context.Context, wrappedPayload common.Wrapped
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (fe *FilterExpr) Id() string {
|
||||
return fe.config.Id
|
||||
}
|
||||
|
||||
func (fe *FilterExpr) Type() string {
|
||||
return fe.config.Type
|
||||
}
|
||||
|
||||
@@ -53,6 +53,10 @@ func (fc *FilterRate) Process(ctx context.Context, wrappedPayload common.Wrapped
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (fc *FilterRate) Id() string {
|
||||
return fc.config.Id
|
||||
}
|
||||
|
||||
func (fc *FilterRate) Type() string {
|
||||
return fc.config.Type
|
||||
}
|
||||
|
||||
@@ -69,6 +69,10 @@ func (fr *FilterRegex) Process(ctx context.Context, wrappedPayload common.Wrappe
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (fr *FilterRegex) Id() string {
|
||||
return fr.config.Id
|
||||
}
|
||||
|
||||
func (fr *FilterRegex) Type() string {
|
||||
return fr.config.Type
|
||||
}
|
||||
|
||||
@@ -68,6 +68,10 @@ func (fp *FloatParse) Process(ctx context.Context, wrappedPayload common.Wrapped
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (fp *FloatParse) Id() string {
|
||||
return fp.config.Id
|
||||
}
|
||||
|
||||
func (fp *FloatParse) Type() string {
|
||||
return fp.config.Type
|
||||
}
|
||||
|
||||
@@ -97,6 +97,10 @@ func (fr *FloatRandom) Process(ctx context.Context, wrappedPayload common.Wrappe
|
||||
return wrappedPayload, errors.New("float.random bitSize error: must be 32 or 64")
|
||||
}
|
||||
|
||||
func (fr *FloatRandom) Id() string {
|
||||
return fr.config.Id
|
||||
}
|
||||
|
||||
func (fr *FloatRandom) Type() string {
|
||||
return fr.config.Type
|
||||
}
|
||||
|
||||
@@ -182,32 +182,32 @@ func init() {
|
||||
}
|
||||
|
||||
return &FreeDCreate{
|
||||
config: config,
|
||||
Id: idTemplate,
|
||||
Pan: panTemplate,
|
||||
Tilt: tiltTemplate,
|
||||
Roll: rollTemplate,
|
||||
PosX: posXTemplate,
|
||||
PosY: posYTemplate,
|
||||
PosZ: posZTemplate,
|
||||
Zoom: zoomTemplate,
|
||||
Focus: focusTemplate,
|
||||
config: config,
|
||||
IdTemplate: idTemplate,
|
||||
PanTemplate: panTemplate,
|
||||
TiltTemplate: tiltTemplate,
|
||||
RollTemplate: rollTemplate,
|
||||
PosXTemplate: posXTemplate,
|
||||
PosYTemplate: posYTemplate,
|
||||
PosZTemplate: posZTemplate,
|
||||
ZoomTemplate: zoomTemplate,
|
||||
FocusTemplate: focusTemplate,
|
||||
}, nil
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
type FreeDCreate struct {
|
||||
config config.ProcessorConfig
|
||||
Id *template.Template
|
||||
Pan *template.Template
|
||||
Tilt *template.Template
|
||||
Roll *template.Template
|
||||
PosX *template.Template
|
||||
PosY *template.Template
|
||||
PosZ *template.Template
|
||||
Zoom *template.Template
|
||||
Focus *template.Template
|
||||
config config.ProcessorConfig
|
||||
IdTemplate *template.Template
|
||||
PanTemplate *template.Template
|
||||
TiltTemplate *template.Template
|
||||
RollTemplate *template.Template
|
||||
PosXTemplate *template.Template
|
||||
PosYTemplate *template.Template
|
||||
PosZTemplate *template.Template
|
||||
ZoomTemplate *template.Template
|
||||
FocusTemplate *template.Template
|
||||
}
|
||||
|
||||
func (fc *FreeDCreate) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||
@@ -215,7 +215,7 @@ func (fc *FreeDCreate) Process(ctx context.Context, wrappedPayload common.Wrappe
|
||||
templateData := wrappedPayload
|
||||
|
||||
var idBuffer bytes.Buffer
|
||||
err := fc.Id.Execute(&idBuffer, templateData)
|
||||
err := fc.IdTemplate.Execute(&idBuffer, templateData)
|
||||
|
||||
if err != nil {
|
||||
wrappedPayload.End = true
|
||||
@@ -232,7 +232,7 @@ func (fc *FreeDCreate) Process(ctx context.Context, wrappedPayload common.Wrappe
|
||||
}
|
||||
|
||||
var panBuffer bytes.Buffer
|
||||
err = fc.Pan.Execute(&panBuffer, templateData)
|
||||
err = fc.PanTemplate.Execute(&panBuffer, templateData)
|
||||
|
||||
if err != nil {
|
||||
wrappedPayload.End = true
|
||||
@@ -249,7 +249,7 @@ func (fc *FreeDCreate) Process(ctx context.Context, wrappedPayload common.Wrappe
|
||||
}
|
||||
|
||||
var tiltBuffer bytes.Buffer
|
||||
err = fc.Tilt.Execute(&tiltBuffer, templateData)
|
||||
err = fc.TiltTemplate.Execute(&tiltBuffer, templateData)
|
||||
|
||||
if err != nil {
|
||||
wrappedPayload.End = true
|
||||
@@ -266,7 +266,7 @@ func (fc *FreeDCreate) Process(ctx context.Context, wrappedPayload common.Wrappe
|
||||
}
|
||||
|
||||
var rollBuffer bytes.Buffer
|
||||
err = fc.Roll.Execute(&rollBuffer, templateData)
|
||||
err = fc.RollTemplate.Execute(&rollBuffer, templateData)
|
||||
|
||||
if err != nil {
|
||||
wrappedPayload.End = true
|
||||
@@ -283,7 +283,7 @@ func (fc *FreeDCreate) Process(ctx context.Context, wrappedPayload common.Wrappe
|
||||
}
|
||||
|
||||
var posXBuffer bytes.Buffer
|
||||
err = fc.PosX.Execute(&posXBuffer, templateData)
|
||||
err = fc.PosXTemplate.Execute(&posXBuffer, templateData)
|
||||
|
||||
if err != nil {
|
||||
wrappedPayload.End = true
|
||||
@@ -300,7 +300,7 @@ func (fc *FreeDCreate) Process(ctx context.Context, wrappedPayload common.Wrappe
|
||||
}
|
||||
|
||||
var posYBuffer bytes.Buffer
|
||||
err = fc.PosY.Execute(&posYBuffer, templateData)
|
||||
err = fc.PosYTemplate.Execute(&posYBuffer, templateData)
|
||||
|
||||
if err != nil {
|
||||
wrappedPayload.End = true
|
||||
@@ -317,7 +317,7 @@ func (fc *FreeDCreate) Process(ctx context.Context, wrappedPayload common.Wrappe
|
||||
}
|
||||
|
||||
var posZBuffer bytes.Buffer
|
||||
err = fc.PosZ.Execute(&posZBuffer, templateData)
|
||||
err = fc.PosZTemplate.Execute(&posZBuffer, templateData)
|
||||
|
||||
if err != nil {
|
||||
wrappedPayload.End = true
|
||||
@@ -334,7 +334,7 @@ func (fc *FreeDCreate) Process(ctx context.Context, wrappedPayload common.Wrappe
|
||||
}
|
||||
|
||||
var zoomBuffer bytes.Buffer
|
||||
err = fc.Zoom.Execute(&zoomBuffer, templateData)
|
||||
err = fc.ZoomTemplate.Execute(&zoomBuffer, templateData)
|
||||
|
||||
if err != nil {
|
||||
wrappedPayload.End = true
|
||||
@@ -351,7 +351,7 @@ func (fc *FreeDCreate) Process(ctx context.Context, wrappedPayload common.Wrappe
|
||||
}
|
||||
|
||||
var focusBuffer bytes.Buffer
|
||||
err = fc.Focus.Execute(&focusBuffer, templateData)
|
||||
err = fc.FocusTemplate.Execute(&focusBuffer, templateData)
|
||||
|
||||
if err != nil {
|
||||
wrappedPayload.End = true
|
||||
@@ -384,6 +384,10 @@ func (fc *FreeDCreate) Process(ctx context.Context, wrappedPayload common.Wrappe
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (fc *FreeDCreate) Id() string {
|
||||
return fc.config.Id
|
||||
}
|
||||
|
||||
func (fc *FreeDCreate) Type() string {
|
||||
return fc.config.Type
|
||||
}
|
||||
|
||||
@@ -21,9 +21,9 @@ func init() {
|
||||
|
||||
type FreeDDecode struct {
|
||||
config config.ProcessorConfig
|
||||
buf [29]byte
|
||||
buf [29]byte
|
||||
}
|
||||
|
||||
|
||||
func (fd *FreeDDecode) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||
payload := wrappedPayload.Payload
|
||||
payloadBytes, ok := common.GetAnyAsByteSlice(payload)
|
||||
@@ -49,6 +49,10 @@ func (fd *FreeDDecode) Process(ctx context.Context, wrappedPayload common.Wrappe
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (fd *FreeDDecode) Id() string {
|
||||
return fd.config.Id
|
||||
}
|
||||
|
||||
func (fd *FreeDDecode) Type() string {
|
||||
return fd.config.Type
|
||||
}
|
||||
|
||||
@@ -38,6 +38,10 @@ func (fe *FreeDEncode) Process(ctx context.Context, wrappedPayload common.Wrappe
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (fe *FreeDEncode) Id() string {
|
||||
return fe.config.Id
|
||||
}
|
||||
|
||||
func (fe *FreeDEncode) Type() string {
|
||||
return fe.config.Type
|
||||
}
|
||||
|
||||
@@ -114,6 +114,10 @@ func (hrd *HTTPRequestDo) Process(ctx context.Context, wrappedPayload common.Wra
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (hrd *HTTPRequestDo) Id() string {
|
||||
return hrd.config.Id
|
||||
}
|
||||
|
||||
func (hrd *HTTPRequestDo) Type() string {
|
||||
return hrd.config.Type
|
||||
}
|
||||
|
||||
@@ -85,6 +85,10 @@ func (hrc *HTTPResponseCreate) Process(ctx context.Context, wrappedPayload commo
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (hrc *HTTPResponseCreate) Id() string {
|
||||
return hrc.config.Id
|
||||
}
|
||||
|
||||
func (hrc *HTTPResponseCreate) Type() string {
|
||||
return hrc.config.Type
|
||||
}
|
||||
|
||||
@@ -85,6 +85,10 @@ func (ip *IntParse) Process(ctx context.Context, wrappedPayload common.WrappedPa
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (ip *IntParse) Id() string {
|
||||
return ip.config.Id
|
||||
}
|
||||
|
||||
func (ip *IntParse) Type() string {
|
||||
return ip.config.Type
|
||||
}
|
||||
|
||||
@@ -66,6 +66,10 @@ func (ir *IntRandom) Process(ctx context.Context, wrappedPayload common.WrappedP
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (ir *IntRandom) Id() string {
|
||||
return ir.config.Id
|
||||
}
|
||||
|
||||
func (ir *IntRandom) Type() string {
|
||||
return ir.config.Type
|
||||
}
|
||||
|
||||
@@ -98,6 +98,10 @@ func (is *IntScale) Process(ctx context.Context, wrappedPayload common.WrappedPa
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (is *IntScale) Id() string {
|
||||
return is.config.Id
|
||||
}
|
||||
|
||||
func (is *IntScale) Type() string {
|
||||
return is.config.Type
|
||||
}
|
||||
|
||||
@@ -50,6 +50,10 @@ func (jd *JsonDecode) Process(ctx context.Context, wrappedPayload common.Wrapped
|
||||
|
||||
}
|
||||
|
||||
func (jd *JsonDecode) Id() string {
|
||||
return jd.config.Id
|
||||
}
|
||||
|
||||
func (jd *JsonDecode) Type() string {
|
||||
return jd.config.Type
|
||||
}
|
||||
|
||||
@@ -42,6 +42,10 @@ func (je *JsonEncode) Process(ctx context.Context, wrappedPayload common.Wrapped
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (je *JsonEncode) Id() string {
|
||||
return je.config.Id
|
||||
}
|
||||
|
||||
func (je *JsonEncode) Type() string {
|
||||
return je.config.Type
|
||||
}
|
||||
|
||||
@@ -89,6 +89,10 @@ func (kvg *KVGet) Process(ctx context.Context, wrappedPayload common.WrappedPayl
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (kvg *KVGet) Id() string {
|
||||
return kvg.config.Id
|
||||
}
|
||||
|
||||
func (kvg *KVGet) Type() string {
|
||||
return kvg.config.Type
|
||||
}
|
||||
|
||||
@@ -89,6 +89,10 @@ func (kvs *KVSet) Process(ctx context.Context, wrappedPayload common.WrappedPayl
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (kvs *KVSet) Id() string {
|
||||
return kvs.config.Id
|
||||
}
|
||||
|
||||
func (kvs *KVSet) Type() string {
|
||||
return kvs.config.Type
|
||||
}
|
||||
|
||||
@@ -147,6 +147,10 @@ func (mccc *MIDIControlChangeCreate) Process(ctx context.Context, wrappedPayload
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (mccc *MIDIControlChangeCreate) Id() string {
|
||||
return mccc.config.Id
|
||||
}
|
||||
|
||||
func (mccc *MIDIControlChangeCreate) Type() string {
|
||||
return mccc.config.Type
|
||||
}
|
||||
|
||||
@@ -40,6 +40,10 @@ func (mmd *MIDIMessageDecode) Process(ctx context.Context, wrappedPayload common
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (mmd *MIDIMessageDecode) Id() string {
|
||||
return mmd.config.Id
|
||||
}
|
||||
|
||||
func (mmd *MIDIMessageDecode) Type() string {
|
||||
return mmd.config.Type
|
||||
}
|
||||
|
||||
@@ -38,6 +38,10 @@ func (mme *MIDIMessageEncode) Process(ctx context.Context, wrappedPayload common
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (mme *MIDIMessageEncode) Id() string {
|
||||
return mme.config.Id
|
||||
}
|
||||
|
||||
func (mme *MIDIMessageEncode) Type() string {
|
||||
return mme.config.Type
|
||||
}
|
||||
|
||||
@@ -96,6 +96,10 @@ func (mmu *MIDIMessageUnpack) Process(ctx context.Context, wrappedPayload common
|
||||
}
|
||||
}
|
||||
|
||||
func (mmu *MIDIMessageUnpack) Id() string {
|
||||
return mmu.config.Id
|
||||
}
|
||||
|
||||
func (mmu *MIDIMessageUnpack) Type() string {
|
||||
return mmu.config.Type
|
||||
}
|
||||
|
||||
@@ -146,6 +146,10 @@ func (mnoc *MIDINoteOffCreate) Process(ctx context.Context, wrappedPayload commo
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (mnoc *MIDINoteOffCreate) Id() string {
|
||||
return mnoc.config.Id
|
||||
}
|
||||
|
||||
func (mnoc *MIDINoteOffCreate) Type() string {
|
||||
return mnoc.config.Type
|
||||
}
|
||||
|
||||
@@ -145,6 +145,10 @@ func (mnoc *MIDINoteOnCreate) Process(ctx context.Context, wrappedPayload common
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (mnoc *MIDINoteOnCreate) Id() string {
|
||||
return mnoc.config.Id
|
||||
}
|
||||
|
||||
func (mnoc *MIDINoteOnCreate) Type() string {
|
||||
return mnoc.config.Type
|
||||
}
|
||||
|
||||
@@ -113,6 +113,10 @@ func (mpcc *MIDIProgramChangeCreate) Process(ctx context.Context, wrappedPayload
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (mpcc *MIDIProgramChangeCreate) Id() string {
|
||||
return mpcc.config.Id
|
||||
}
|
||||
|
||||
func (mpcc *MIDIProgramChangeCreate) Type() string {
|
||||
return mpcc.config.Type
|
||||
}
|
||||
|
||||
@@ -81,6 +81,10 @@ func (mo *ModuleOutput) Process(ctx context.Context, wrappedPayload common.Wrapp
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (mo *ModuleOutput) Id() string {
|
||||
return mo.config.Id
|
||||
}
|
||||
|
||||
func (mo *ModuleOutput) Type() string {
|
||||
return mo.config.Type
|
||||
}
|
||||
|
||||
@@ -157,6 +157,10 @@ func (omc *OSCMessageCreate) Process(ctx context.Context, wrappedPayload common.
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (omc *OSCMessageCreate) Id() string {
|
||||
return omc.config.Id
|
||||
}
|
||||
|
||||
func (omc *OSCMessageCreate) Type() string {
|
||||
return omc.config.Type
|
||||
}
|
||||
|
||||
@@ -52,6 +52,10 @@ func (omd *OSCMessageDecode) Process(ctx context.Context, wrappedPayload common.
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (omd *OSCMessageDecode) Id() string {
|
||||
return omd.config.Id
|
||||
}
|
||||
|
||||
func (omd *OSCMessageDecode) Type() string {
|
||||
return omd.config.Type
|
||||
}
|
||||
|
||||
@@ -42,6 +42,10 @@ func (ome *OSCMessageEncode) Process(ctx context.Context, wrappedPayload common.
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (ome *OSCMessageEncode) Id() string {
|
||||
return ome.config.Id
|
||||
}
|
||||
|
||||
func (ome *OSCMessageEncode) Type() string {
|
||||
return ome.config.Type
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
)
|
||||
|
||||
type Processor interface {
|
||||
Id() string
|
||||
Type() string
|
||||
Process(context.Context, common.WrappedPayload) (common.WrappedPayload, error)
|
||||
}
|
||||
|
||||
@@ -104,6 +104,10 @@ func (psp *PubSubPublish) Process(ctx context.Context, wrappedPayload common.Wra
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (psp *PubSubPublish) Id() string {
|
||||
return psp.config.Id
|
||||
}
|
||||
|
||||
func (psp *PubSubPublish) Type() string {
|
||||
return psp.config.Type
|
||||
}
|
||||
|
||||
@@ -68,6 +68,10 @@ func (ri *RouterInput) Process(ctx context.Context, wrappedPayload common.Wrappe
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (ri *RouterInput) Id() string {
|
||||
return ri.config.Id
|
||||
}
|
||||
|
||||
func (ri *RouterInput) Type() string {
|
||||
return ri.config.Type
|
||||
}
|
||||
|
||||
@@ -65,6 +65,10 @@ func (se *ScriptExpr) Process(ctx context.Context, wrappedPayload common.Wrapped
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (se *ScriptExpr) Id() string {
|
||||
return se.config.Id
|
||||
}
|
||||
|
||||
func (se *ScriptExpr) Type() string {
|
||||
return se.config.Type
|
||||
}
|
||||
|
||||
@@ -135,6 +135,10 @@ func (sj *ScriptJS) Process(ctx context.Context, wrappedPayload common.WrappedPa
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (sj *ScriptJS) Id() string {
|
||||
return sj.config.Id
|
||||
}
|
||||
|
||||
func (sj *ScriptJS) Type() string {
|
||||
return sj.config.Type
|
||||
}
|
||||
|
||||
@@ -120,6 +120,10 @@ func (sw *ScriptWASM) Process(ctx context.Context, wrappedPayload common.Wrapped
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (sw *ScriptWASM) Id() string {
|
||||
return sw.config.Id
|
||||
}
|
||||
|
||||
func (sw *ScriptWASM) Type() string {
|
||||
return sw.config.Type
|
||||
}
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
package processor
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"text/template"
|
||||
|
||||
"github.com/google/jsonschema-go/jsonschema"
|
||||
"github.com/jwetzell/showbridge-go/internal/common"
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
)
|
||||
|
||||
func init() {
|
||||
RegisterProcessor(ProcessorRegistration{
|
||||
Type: "sip.response.audio.create",
|
||||
Title: "Create SIP Audio Response",
|
||||
ParamsSchema: &jsonschema.Schema{
|
||||
Type: "object",
|
||||
Properties: map[string]*jsonschema.Schema{
|
||||
"preWait": {
|
||||
Title: "Pre Wait (ms)",
|
||||
Description: "number of milliseconds to wait before playing the audio",
|
||||
Type: "integer",
|
||||
},
|
||||
"audioFile": {
|
||||
Title: "Audio File",
|
||||
Description: "path to the audio file to play",
|
||||
Type: "string",
|
||||
},
|
||||
"postWait": {
|
||||
Title: "Post Wait (ms)",
|
||||
Description: "number of milliseconds to wait after playing the audio",
|
||||
Type: "integer",
|
||||
},
|
||||
},
|
||||
Required: []string{"preWait", "postWait", "audioFile"},
|
||||
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||
},
|
||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||
params := config.Params
|
||||
|
||||
preWaitNum, err := params.GetInt("preWait")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("sip.response.audio.create preWait error: %w", err)
|
||||
}
|
||||
|
||||
postWaitNum, err := params.GetInt("postWait")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("sip.response.audio.create postWait error: %w", err)
|
||||
}
|
||||
|
||||
audioFileString, err := params.GetString("audioFile")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("sip.response.audio.create audioFile error: %w", err)
|
||||
}
|
||||
|
||||
audioFileTemplate, err := template.New("audioFile").Parse(audioFileString)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &SipResponseAudioCreate{config: config, AudioFile: audioFileTemplate, PreWait: int(preWaitNum), PostWait: int(postWaitNum)}, nil
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
type SipResponseAudioCreate struct {
|
||||
config config.ProcessorConfig
|
||||
PreWait int
|
||||
PostWait int
|
||||
AudioFile *template.Template
|
||||
}
|
||||
|
||||
type SipAudioFileResponse struct {
|
||||
PreWait int
|
||||
PostWait int
|
||||
AudioFile string
|
||||
}
|
||||
|
||||
func (srac *SipResponseAudioCreate) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||
|
||||
templateData := wrappedPayload
|
||||
|
||||
var audioFileBuffer bytes.Buffer
|
||||
err := srac.AudioFile.Execute(&audioFileBuffer, templateData)
|
||||
|
||||
if err != nil {
|
||||
wrappedPayload.End = true
|
||||
return wrappedPayload, err
|
||||
}
|
||||
|
||||
audioFileString := audioFileBuffer.String()
|
||||
|
||||
wrappedPayload.Payload = SipAudioFileResponse{
|
||||
PreWait: srac.PreWait,
|
||||
PostWait: srac.PostWait,
|
||||
AudioFile: audioFileString,
|
||||
}
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (srac *SipResponseAudioCreate) Type() string {
|
||||
return srac.config.Type
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
package processor
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"text/template"
|
||||
|
||||
"github.com/google/jsonschema-go/jsonschema"
|
||||
"github.com/jwetzell/showbridge-go/internal/common"
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
)
|
||||
|
||||
func init() {
|
||||
RegisterProcessor(ProcessorRegistration{
|
||||
Type: "sip.response.dtmf.create",
|
||||
Title: "Create SIP DTMF Response",
|
||||
ParamsSchema: &jsonschema.Schema{
|
||||
Type: "object",
|
||||
Properties: map[string]*jsonschema.Schema{
|
||||
"preWait": {
|
||||
Title: "Pre Wait (ms)",
|
||||
Description: "number of milliseconds to wait before sending the DTMF tones",
|
||||
Type: "integer",
|
||||
},
|
||||
"digits": {
|
||||
Title: "Digits",
|
||||
Description: "DTMF digits to send",
|
||||
Type: "string",
|
||||
},
|
||||
"postWait": {
|
||||
Title: "Post Wait (ms)",
|
||||
Description: "number of milliseconds to wait after sending the DTMF tones",
|
||||
Type: "integer",
|
||||
},
|
||||
},
|
||||
Required: []string{"preWait", "postWait", "digits"},
|
||||
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||
},
|
||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||
params := config.Params
|
||||
|
||||
preWaitNum, err := params.GetInt("preWait")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("sip.response.dtmf.create preWait error: %w", err)
|
||||
}
|
||||
|
||||
postWaitNum, err := params.GetInt("postWait")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("sip.response.dtmf.create postWait error: %w", err)
|
||||
}
|
||||
|
||||
digitsString, err := params.GetString("digits")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("sip.response.dtmf.create digits error: %w", err)
|
||||
}
|
||||
|
||||
digitsTemplate, err := template.New("digits").Parse(digitsString)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &SipResponseDTMFCreate{config: config, Digits: digitsTemplate, PreWait: int(preWaitNum), PostWait: int(postWaitNum), validDTMF: validDTMFRegex}, nil
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
type SipResponseDTMFCreate struct {
|
||||
config config.ProcessorConfig
|
||||
PreWait int
|
||||
PostWait int
|
||||
Digits *template.Template
|
||||
validDTMF *regexp.Regexp
|
||||
}
|
||||
|
||||
type SipDTMFResponse struct {
|
||||
PreWait int
|
||||
PostWait int
|
||||
Digits string
|
||||
}
|
||||
|
||||
var validDTMFRegex = regexp.MustCompile(`^[0-9*#A-Da-d]+$`)
|
||||
|
||||
func (srdc *SipResponseDTMFCreate) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||
|
||||
templateData := wrappedPayload
|
||||
|
||||
var digitsBuffer bytes.Buffer
|
||||
err := srdc.Digits.Execute(&digitsBuffer, templateData)
|
||||
|
||||
if err != nil {
|
||||
wrappedPayload.End = true
|
||||
return wrappedPayload, err
|
||||
}
|
||||
|
||||
digitsString := digitsBuffer.String()
|
||||
|
||||
if !srdc.validDTMF.MatchString(digitsString) {
|
||||
wrappedPayload.End = true
|
||||
return wrappedPayload, errors.New("sip.response.dtmf.create result of digits template contains invalid characters")
|
||||
}
|
||||
|
||||
wrappedPayload.Payload = SipDTMFResponse{
|
||||
PreWait: srdc.PreWait,
|
||||
PostWait: srdc.PostWait,
|
||||
Digits: digitsString,
|
||||
}
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (srdc *SipResponseDTMFCreate) Type() string {
|
||||
return srdc.config.Type
|
||||
}
|
||||
@@ -65,6 +65,10 @@ func (sc *StringCreate) Process(ctx context.Context, wrappedPayload common.Wrapp
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (sc *StringCreate) Id() string {
|
||||
return sc.config.Id
|
||||
}
|
||||
|
||||
func (sc *StringCreate) Type() string {
|
||||
return sc.config.Type
|
||||
}
|
||||
|
||||
@@ -37,6 +37,10 @@ func (sd *StringDecode) Process(ctx context.Context, wrappedPayload common.Wrapp
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (sd *StringDecode) Id() string {
|
||||
return sd.config.Id
|
||||
}
|
||||
|
||||
func (sd *StringDecode) Type() string {
|
||||
return sd.config.Type
|
||||
}
|
||||
|
||||
@@ -36,6 +36,10 @@ func (se *StringEncode) Process(ctx context.Context, wrappedPayload common.Wrapp
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (se *StringEncode) Id() string {
|
||||
return se.config.Id
|
||||
}
|
||||
|
||||
func (se *StringEncode) Type() string {
|
||||
return se.config.Type
|
||||
}
|
||||
|
||||
@@ -59,6 +59,10 @@ func (ss *StringSplit) Process(ctx context.Context, wrappedPayload common.Wrappe
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (ss *StringSplit) Id() string {
|
||||
return ss.config.Id
|
||||
}
|
||||
|
||||
func (ss *StringSplit) Type() string {
|
||||
return ss.config.Type
|
||||
}
|
||||
|
||||
@@ -67,6 +67,10 @@ func (sfg *StructFieldGet) Process(ctx context.Context, wrappedPayload common.Wr
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (sfg *StructFieldGet) Id() string {
|
||||
return sfg.config.Id
|
||||
}
|
||||
|
||||
func (sfg *StructFieldGet) Type() string {
|
||||
return sfg.config.Type
|
||||
}
|
||||
|
||||
@@ -86,6 +86,10 @@ func (smg *StructMethodGet) Process(ctx context.Context, wrappedPayload common.W
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (smg *StructMethodGet) Id() string {
|
||||
return smg.config.Id
|
||||
}
|
||||
|
||||
func (smg *StructMethodGet) Type() string {
|
||||
return smg.config.Type
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ func TestArtnetPacketDecodeFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "artnet.packet.decode",
|
||||
})
|
||||
|
||||
@@ -24,6 +25,10 @@ func TestArtnetPacketDecodeFromRegistry(t *testing.T) {
|
||||
t.Fatalf("failed to create artnet.packet.decode processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("artnet.packet.decode processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "artnet.packet.decode" {
|
||||
t.Fatalf("artnet.packet.decode processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ func TestArtnetPacketEncodeFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "artnet.packet.encode",
|
||||
})
|
||||
|
||||
@@ -24,6 +25,10 @@ func TestArtnetPacketEncodeFromRegistry(t *testing.T) {
|
||||
t.Fatalf("failed to create artnet.packet.encode processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("artnet.packet.encode processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "artnet.packet.encode" {
|
||||
t.Fatalf("artnet.packet.encode processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ func TestDbQueryFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "db.query",
|
||||
Params: map[string]any{
|
||||
"module": "test",
|
||||
@@ -28,6 +29,10 @@ func TestDbQueryFromRegistry(t *testing.T) {
|
||||
t.Fatalf("failed to create db.query processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("db.query processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "db.query" {
|
||||
t.Fatalf("db.query processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ func TestDebugLogFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "debug.log",
|
||||
})
|
||||
|
||||
@@ -23,6 +24,10 @@ func TestDebugLogFromRegistry(t *testing.T) {
|
||||
t.Fatalf("failed to create debug.log processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("debug.log processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "debug.log" {
|
||||
t.Fatalf("debug.log processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -16,12 +16,17 @@ func TestFilterChangeFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "filter.change",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create filter.change processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("filter.change processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "filter.change" {
|
||||
t.Fatalf("filter.change processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ func TestFilterExprFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "filter.expr",
|
||||
Params: map[string]any{
|
||||
"expression": "foo + bar",
|
||||
@@ -25,6 +26,10 @@ func TestFilterExprFromRegistry(t *testing.T) {
|
||||
t.Fatalf("failed to create filter.expr processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("filter.expr processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "filter.expr" {
|
||||
t.Fatalf("filter.expr processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ func TestFilterRateFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "filter.rate",
|
||||
Params: map[string]any{
|
||||
"rate": 1,
|
||||
@@ -25,6 +26,10 @@ func TestFilterRateFromRegistry(t *testing.T) {
|
||||
t.Fatalf("failed to create filter.rate processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("filter.rate processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "filter.rate" {
|
||||
t.Fatalf("filter.rate processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ func TestFilterRegexFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "filter.regex",
|
||||
Params: map[string]any{
|
||||
"pattern": "hello",
|
||||
@@ -25,6 +26,10 @@ func TestFilterRegexFromRegistry(t *testing.T) {
|
||||
t.Fatalf("failed to create filter.regex processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("filter.regex processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "filter.regex" {
|
||||
t.Fatalf("filter.regex processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ func TestFloatParseFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "float.parse",
|
||||
})
|
||||
|
||||
@@ -23,6 +24,9 @@ func TestFloatParseFromRegistry(t *testing.T) {
|
||||
t.Fatalf("failed to create float.parse processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("float.parse processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
if processorInstance.Type() != "float.parse" {
|
||||
t.Fatalf("float.parse processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ func TestFloatRandomFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "float.random",
|
||||
Params: map[string]any{
|
||||
"min": 1.0,
|
||||
@@ -26,6 +27,10 @@ func TestFloatRandomFromRegistry(t *testing.T) {
|
||||
t.Fatalf("failed to create float.random processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("float.random processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "float.random" {
|
||||
t.Fatalf("float.random processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ func TestFreeDCreateFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "freed.create",
|
||||
Params: map[string]any{
|
||||
"id": "0",
|
||||
@@ -35,6 +36,10 @@ func TestFreeDCreateFromRegistry(t *testing.T) {
|
||||
t.Fatalf("failed to create freed.create processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("freed.create processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "freed.create" {
|
||||
t.Fatalf("freed.create processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ func TestFreeDDecodeFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "freed.decode",
|
||||
})
|
||||
|
||||
@@ -24,6 +25,10 @@ func TestFreeDDecodeFromRegistry(t *testing.T) {
|
||||
t.Fatalf("failed to create freed.decode processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("freed.decode processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "freed.decode" {
|
||||
t.Fatalf("freed.decode processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ func TestFreeDEncodeFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "freed.encode",
|
||||
})
|
||||
|
||||
@@ -24,6 +25,10 @@ func TestFreeDEncodeFromRegistry(t *testing.T) {
|
||||
t.Fatalf("failed to create freed.encode processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("freed.encode processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "freed.encode" {
|
||||
t.Fatalf("freed.encode processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ func TestHTTPRequestCreateFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "http.request.do",
|
||||
Params: map[string]any{
|
||||
"method": "GET",
|
||||
@@ -27,6 +28,10 @@ func TestHTTPRequestCreateFromRegistry(t *testing.T) {
|
||||
t.Fatalf("failed to create http.request.do processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("http.request.do processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "http.request.do" {
|
||||
t.Fatalf("http.request.do processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ func TestHTTPResponseCreateFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "http.response.create",
|
||||
Params: map[string]any{
|
||||
"status": 200,
|
||||
@@ -27,6 +28,10 @@ func TestHTTPResponseCreateFromRegistry(t *testing.T) {
|
||||
t.Fatalf("failed to create http.response.create processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("http.response.create processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "http.response.create" {
|
||||
t.Fatalf("http.response.create processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ func TestIntParseFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "int.parse",
|
||||
})
|
||||
|
||||
@@ -23,6 +24,10 @@ func TestIntParseFromRegistry(t *testing.T) {
|
||||
t.Fatalf("failed to create int.parse processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("int.parse processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "int.parse" {
|
||||
t.Fatalf("int.parse processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ func TestIntRandomFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "int.random",
|
||||
Params: map[string]any{
|
||||
"min": 1,
|
||||
@@ -26,6 +27,10 @@ func TestIntRandomFromRegistry(t *testing.T) {
|
||||
t.Fatalf("failed to create int.random processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("int.random processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "int.random" {
|
||||
t.Fatalf("int.random processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ func TestIntScaleFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "int.scale",
|
||||
Params: map[string]any{
|
||||
"inMin": 0,
|
||||
@@ -28,6 +29,10 @@ func TestIntScaleFromRegistry(t *testing.T) {
|
||||
t.Fatalf("failed to create int.scale processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("int.scale processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "int.scale" {
|
||||
t.Fatalf("int.scale processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -17,12 +17,17 @@ func TestJsonDecodeFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "json.decode",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create json.decode processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("json.decode processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "json.decode" {
|
||||
t.Fatalf("json.decode processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -18,12 +18,17 @@ func TestJsonEncodeFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "json.encode",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create json.encode processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("json.encode processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "json.encode" {
|
||||
t.Fatalf("json.encode processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ func TestKvGetFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "kv.get",
|
||||
Params: map[string]any{
|
||||
"module": "test",
|
||||
@@ -27,6 +28,10 @@ func TestKvGetFromRegistry(t *testing.T) {
|
||||
t.Fatalf("failed to create kv.get processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("kv.get processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "kv.get" {
|
||||
t.Fatalf("kv.get processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ func TestKvSetFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "kv.set",
|
||||
Params: map[string]any{
|
||||
"module": "test",
|
||||
@@ -27,6 +28,9 @@ func TestKvSetFromRegistry(t *testing.T) {
|
||||
t.Fatalf("failed to create kv.set processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("kv.set processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
if processorInstance.Type() != "kv.set" {
|
||||
t.Fatalf("kv.set processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ func TestMIDIControlChangeCreateFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "midi.control_change.create",
|
||||
Params: map[string]any{
|
||||
"channel": "1",
|
||||
@@ -29,6 +30,10 @@ func TestMIDIControlChangeCreateFromRegistry(t *testing.T) {
|
||||
t.Fatalf("failed to create midi.control_change.create processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("midi.control_change.create processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "midi.control_change.create" {
|
||||
t.Fatalf("midi.control_change.create processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ func TestMIDIMessageDecodeFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "midi.message.decode",
|
||||
})
|
||||
|
||||
@@ -24,6 +25,10 @@ func TestMIDIMessageDecodeFromRegistry(t *testing.T) {
|
||||
t.Fatalf("failed to create midi.message.decode processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("midi.message.decode processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "midi.message.decode" {
|
||||
t.Fatalf("midi.message.decode processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ func TestMIDIMessageEncodeFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "midi.message.encode",
|
||||
})
|
||||
|
||||
@@ -24,6 +25,10 @@ func TestMIDIMessageEncodeFromRegistry(t *testing.T) {
|
||||
t.Fatalf("failed to create midi.message.encode processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("midi.message.encode processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "midi.message.encode" {
|
||||
t.Fatalf("midi.message.encode processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ func TestMIDIMessageUnpackFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "midi.message.unpack",
|
||||
})
|
||||
|
||||
@@ -24,6 +25,9 @@ func TestMIDIMessageUnpackFromRegistry(t *testing.T) {
|
||||
t.Fatalf("failed to create midi.message.unpack processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("midi.message.unpack processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
if processorInstance.Type() != "midi.message.unpack" {
|
||||
t.Fatalf("midi.message.unpack processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ func TestMIDINoteOffCreteaFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "midi.note_off.create",
|
||||
Params: map[string]any{
|
||||
"channel": "1",
|
||||
@@ -28,6 +29,9 @@ func TestMIDINoteOffCreteaFromRegistry(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create midi.note_off.create processor: %s", err)
|
||||
}
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("midi.note_off.create processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "midi.note_off.create" {
|
||||
t.Fatalf("midi.note_off.create processor has wrong type: %s", processorInstance.Type())
|
||||
|
||||
@@ -17,6 +17,7 @@ func TestMIDINoteOnCreateFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "midi.note_on.create",
|
||||
Params: map[string]any{
|
||||
"channel": "1",
|
||||
@@ -29,6 +30,10 @@ func TestMIDINoteOnCreateFromRegistry(t *testing.T) {
|
||||
t.Fatalf("failed to create midi.note_on.create processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("midi.note_on.create processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "midi.note_on.create" {
|
||||
t.Fatalf("midi.note_on.create processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ func TestMIDIProgramChangeCreateFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "midi.program_change.create",
|
||||
Params: map[string]any{
|
||||
"channel": "1",
|
||||
@@ -28,6 +29,10 @@ func TestMIDIProgramChangeCreateFromRegistry(t *testing.T) {
|
||||
t.Fatalf("failed to create midi.program_change.create processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("midi.program_change.create processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "midi.program_change.create" {
|
||||
t.Fatalf("midi.program_change.create processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ func TestModuleOutputFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "module.output",
|
||||
Params: config.Params{
|
||||
"module": "test",
|
||||
@@ -27,6 +28,10 @@ func TestModuleOutputFromRegistry(t *testing.T) {
|
||||
t.Fatalf("failed to create module.output processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("module.output processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "module.output" {
|
||||
t.Fatalf("module.output processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ func TestOSCMessageCreateFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "osc.message.create",
|
||||
Params: map[string]any{
|
||||
"address": "/test",
|
||||
@@ -27,6 +28,10 @@ func TestOSCMessageCreateFromRegistry(t *testing.T) {
|
||||
t.Fatalf("failed to create osc.message.create processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("osc.message.create processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "osc.message.create" {
|
||||
t.Fatalf("osc.message.create processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ func TestOSCMessageDecodeFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "osc.message.decode",
|
||||
})
|
||||
|
||||
@@ -24,6 +25,10 @@ func TestOSCMessageDecodeFromRegistry(t *testing.T) {
|
||||
t.Fatalf("failed to create osc.message.decode processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("osc.message.decode processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "osc.message.decode" {
|
||||
t.Fatalf("osc.message.decode processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ func TestOSCMessageEncodeFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "osc.message.encode",
|
||||
})
|
||||
|
||||
@@ -24,6 +25,10 @@ func TestOSCMessageEncodeFromRegistry(t *testing.T) {
|
||||
t.Fatalf("failed to create osc.message.encode processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("osc.message.encode processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "osc.message.encode" {
|
||||
t.Fatalf("osc.message.encode processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -53,3 +53,20 @@ func TestProcessorBadRegistrationExistingType(t *testing.T) {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestTestProcessor(t *testing.T) {
|
||||
testProcessor := &test.TestProcessor{
|
||||
Config: config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "test",
|
||||
},
|
||||
}
|
||||
|
||||
if testProcessor.Id() != "test-id" {
|
||||
t.Fatalf("test processor has wrong id: %s", testProcessor.Id())
|
||||
}
|
||||
|
||||
if testProcessor.Type() != "test" {
|
||||
t.Fatalf("test processor has wrong type: %s", testProcessor.Type())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ func TestPubSubPublishFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "pubsub.publish",
|
||||
Params: map[string]any{
|
||||
"module": "test",
|
||||
@@ -28,6 +29,10 @@ func TestPubSubPublishFromRegistry(t *testing.T) {
|
||||
t.Fatalf("failed to create pubsub.publish processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("pubsub.publish processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "pubsub.publish" {
|
||||
t.Fatalf("pubsub.publish processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ func TestRouterInputFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "router.input",
|
||||
Params: config.Params{
|
||||
"source": "test",
|
||||
@@ -27,6 +28,10 @@ func TestRouterInputFromRegistry(t *testing.T) {
|
||||
t.Fatalf("failed to create router.input processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("router.input processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "router.input" {
|
||||
t.Fatalf("router.input processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ func TestScriptExprFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "script.expr",
|
||||
Params: map[string]any{
|
||||
"expression": "foo + bar",
|
||||
@@ -24,6 +25,10 @@ func TestScriptExprFromRegistry(t *testing.T) {
|
||||
t.Fatalf("failed to create script.expr processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("script.expr processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "script.expr" {
|
||||
t.Fatalf("script.expr processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ func TestScriptJSFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "script.js",
|
||||
Params: map[string]any{
|
||||
"program": `
|
||||
@@ -27,6 +28,10 @@ func TestScriptJSFromRegistry(t *testing.T) {
|
||||
t.Fatalf("failed to create script.js processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("script.js processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "script.js" {
|
||||
t.Fatalf("script.js processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ func TestScriptWASMFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "script.wasm",
|
||||
Params: map[string]any{
|
||||
"path": "good.wasm",
|
||||
@@ -26,6 +27,10 @@ func TestScriptWASMFromRegistry(t *testing.T) {
|
||||
t.Fatalf("failed to create script.wasm processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("script.wasm processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "script.wasm" {
|
||||
t.Fatalf("script.wasm processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -1,243 +0,0 @@
|
||||
package processor_test
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/common"
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
)
|
||||
|
||||
func TestSipResponseAudioCreateFromRegistry(t *testing.T) {
|
||||
registration, ok := processor.GetProcessorRegistration("sip.response.audio.create")
|
||||
if !ok {
|
||||
t.Fatalf("sip.response.audio.create processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "sip.response.audio.create",
|
||||
Params: map[string]any{
|
||||
"preWait": 0,
|
||||
"audioFile": "good.wav",
|
||||
"postWait": 0,
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to filter sip.response.audio.create processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "sip.response.audio.create" {
|
||||
t.Fatalf("sip.response.audio.create processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
}
|
||||
|
||||
func TestGoodSipResponseAudioCreate(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
params map[string]any
|
||||
payload any
|
||||
expected any
|
||||
}{
|
||||
{
|
||||
name: "basic",
|
||||
params: map[string]any{
|
||||
"preWait": 0,
|
||||
"audioFile": "good.wav",
|
||||
"postWait": 0,
|
||||
},
|
||||
payload: nil,
|
||||
expected: processor.SipAudioFileResponse{
|
||||
PreWait: 0,
|
||||
PostWait: 0,
|
||||
AudioFile: "good.wav",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "template audio file",
|
||||
params: map[string]any{
|
||||
"preWait": 1,
|
||||
"audioFile": "{{.Payload.SomeField}}.wav",
|
||||
"postWait": 2,
|
||||
},
|
||||
payload: map[string]any{
|
||||
"SomeField": "templated",
|
||||
},
|
||||
expected: processor.SipAudioFileResponse{
|
||||
PreWait: 1,
|
||||
PostWait: 2,
|
||||
AudioFile: "templated.wav",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
|
||||
registration, ok := processor.GetProcessorRegistration("sip.response.audio.create")
|
||||
if !ok {
|
||||
t.Fatalf("sip.response.audio.create processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "sip.response.audio.create",
|
||||
Params: test.params,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("sip.response.audio.create failed to create processor: %s", err)
|
||||
}
|
||||
|
||||
got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
|
||||
if err != nil {
|
||||
t.Fatalf("sip.response.audio.create processing failed: %s", err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(got.Payload, test.expected) {
|
||||
t.Fatalf("sip.response.audio.create got %+v (%T), expected %+v (%T)", got.Payload, got.Payload, test.expected, test.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestBadSipResponseAudioCreate(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
params map[string]any
|
||||
payload any
|
||||
errorString string
|
||||
}{
|
||||
{
|
||||
name: "missing preWait param",
|
||||
params: map[string]any{
|
||||
"audioFile": "good.wav",
|
||||
"postWait": 0,
|
||||
},
|
||||
errorString: "sip.response.audio.create preWait error: not found",
|
||||
},
|
||||
{
|
||||
name: "non-numeric preWait param",
|
||||
params: map[string]any{
|
||||
"preWait": "not a number",
|
||||
"audioFile": "good.wav",
|
||||
"postWait": 0,
|
||||
},
|
||||
errorString: "sip.response.audio.create preWait error: not a number",
|
||||
},
|
||||
{
|
||||
name: "missing audioFile param",
|
||||
params: map[string]any{
|
||||
"preWait": 0,
|
||||
"postWait": 0,
|
||||
},
|
||||
errorString: "sip.response.audio.create audioFile error: not found",
|
||||
},
|
||||
{
|
||||
name: "non-string audioFile param",
|
||||
params: map[string]any{
|
||||
"preWait": 0,
|
||||
"audioFile": 123,
|
||||
"postWait": 0,
|
||||
},
|
||||
errorString: "sip.response.audio.create audioFile error: not a string",
|
||||
},
|
||||
{
|
||||
name: "audioFile template syntax error",
|
||||
params: map[string]any{
|
||||
"preWait": 0,
|
||||
"audioFile": "{{.Unclosed",
|
||||
"postWait": 0,
|
||||
},
|
||||
errorString: "template: audioFile:1: unclosed action",
|
||||
},
|
||||
{
|
||||
name: "audioFile template error",
|
||||
params: map[string]any{
|
||||
"preWait": 0,
|
||||
"audioFile": "{{.NonExistentField}} ",
|
||||
"postWait": 0,
|
||||
},
|
||||
errorString: "template: audioFile:1:2: executing \"audioFile\" at <.NonExistentField>: can't evaluate field NonExistentField in type common.WrappedPayload",
|
||||
},
|
||||
{
|
||||
name: "missing postWait param",
|
||||
params: map[string]any{
|
||||
"preWait": 0,
|
||||
"audioFile": "good.wav",
|
||||
},
|
||||
errorString: "sip.response.audio.create postWait error: not found",
|
||||
},
|
||||
{
|
||||
name: "non-numeric postWait param",
|
||||
params: map[string]any{
|
||||
"preWait": 0,
|
||||
"audioFile": "good.wav",
|
||||
"postWait": "not a number",
|
||||
},
|
||||
errorString: "sip.response.audio.create postWait error: not a number",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
|
||||
registration, ok := processor.GetProcessorRegistration("sip.response.audio.create")
|
||||
if !ok {
|
||||
t.Fatalf("sip.response.audio.create processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "sip.response.audio.create",
|
||||
Params: test.params,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
if test.errorString != err.Error() {
|
||||
t.Fatalf("sip.response.audio.create got error '%s', expected '%s'", err.Error(), test.errorString)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
|
||||
|
||||
if err == nil {
|
||||
t.Fatalf("sip.response.audio.create expected to fail but succeeded, got: %v", got)
|
||||
}
|
||||
|
||||
if err.Error() != test.errorString {
|
||||
t.Fatalf("sip.response.audio.create got error '%s', expected '%s'", err.Error(), test.errorString)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkSipResponseAudioCreate(b *testing.B) {
|
||||
registration, ok := processor.GetProcessorRegistration("sip.response.audio.create")
|
||||
if !ok {
|
||||
b.Fatalf("sip.response.audio.create processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "sip.response.audio.create",
|
||||
Params: map[string]any{
|
||||
"preWait": 0,
|
||||
"audioFile": "good.wav",
|
||||
"postWait": 0,
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
b.Fatalf("sip.response.audio.create failed to create processor: %s", err)
|
||||
}
|
||||
|
||||
count := 0
|
||||
for b.Loop() {
|
||||
_, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: count})
|
||||
if err != nil {
|
||||
b.Fatalf("sip.response.audio.create processing failed: %s", err)
|
||||
}
|
||||
count++
|
||||
}
|
||||
}
|
||||
@@ -1,251 +0,0 @@
|
||||
package processor_test
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/common"
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
)
|
||||
|
||||
func TestSipResponseDTMFCreateFromRegistry(t *testing.T) {
|
||||
registration, ok := processor.GetProcessorRegistration("sip.response.dtmf.create")
|
||||
if !ok {
|
||||
t.Fatalf("sip.response.dtmf.create processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "sip.response.dtmf.create",
|
||||
Params: map[string]any{
|
||||
"preWait": 0,
|
||||
"digits": "good.wav",
|
||||
"postWait": 0,
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to filter sip.response.dtmf.create processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "sip.response.dtmf.create" {
|
||||
t.Fatalf("sip.response.dtmf.create processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
}
|
||||
|
||||
func TestGoodSipResponseDTMFCreate(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
params map[string]any
|
||||
payload any
|
||||
expected any
|
||||
}{
|
||||
{
|
||||
name: "basic",
|
||||
params: map[string]any{
|
||||
"preWait": 0,
|
||||
"digits": "12345",
|
||||
"postWait": 0,
|
||||
},
|
||||
payload: nil,
|
||||
expected: processor.SipDTMFResponse{
|
||||
PreWait: 0,
|
||||
PostWait: 0,
|
||||
Digits: "12345",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "template digits",
|
||||
params: map[string]any{
|
||||
"preWait": 0,
|
||||
"digits": "{{.Payload}}",
|
||||
"postWait": 0,
|
||||
},
|
||||
payload: "67890",
|
||||
expected: processor.SipDTMFResponse{
|
||||
PreWait: 0,
|
||||
PostWait: 0,
|
||||
Digits: "67890",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
|
||||
registration, ok := processor.GetProcessorRegistration("sip.response.dtmf.create")
|
||||
if !ok {
|
||||
t.Fatalf("sip.response.dtmf.create processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "sip.response.dtmf.create",
|
||||
Params: test.params,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("sip.response.dtmf.create failed to create processor: %s", err)
|
||||
}
|
||||
|
||||
got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
|
||||
if err != nil {
|
||||
t.Fatalf("sip.response.dtmf.create processing failed: %s", err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(got.Payload, test.expected) {
|
||||
t.Fatalf("sip.response.dtmf.create got %+v (%T), expected %+v (%T)", got.Payload, got.Payload, test.expected, test.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestBadSipResponseDTMFCreate(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
params map[string]any
|
||||
payload any
|
||||
errorString string
|
||||
}{
|
||||
{
|
||||
name: "missing preWait param",
|
||||
params: map[string]any{
|
||||
"digits": "good.wav",
|
||||
"postWait": 0,
|
||||
},
|
||||
errorString: "sip.response.dtmf.create preWait error: not found",
|
||||
},
|
||||
{
|
||||
name: "non-numeric preWait param",
|
||||
params: map[string]any{
|
||||
"preWait": "not a number",
|
||||
"digits": "good.wav",
|
||||
"postWait": 0,
|
||||
},
|
||||
errorString: "sip.response.dtmf.create preWait error: not a number",
|
||||
},
|
||||
{
|
||||
name: "missing digits param",
|
||||
params: map[string]any{
|
||||
"preWait": 0,
|
||||
"postWait": 0,
|
||||
},
|
||||
errorString: "sip.response.dtmf.create digits error: not found",
|
||||
},
|
||||
{
|
||||
name: "non-string digits param",
|
||||
params: map[string]any{
|
||||
"preWait": 0,
|
||||
"digits": 12345,
|
||||
"postWait": 0,
|
||||
},
|
||||
errorString: "sip.response.dtmf.create digits error: not a string",
|
||||
},
|
||||
{
|
||||
name: "digits template syntax error",
|
||||
params: map[string]any{
|
||||
"preWait": 0,
|
||||
"digits": "{{.Unclosed",
|
||||
"postWait": 0,
|
||||
},
|
||||
errorString: "template: digits:1: unclosed action",
|
||||
},
|
||||
{
|
||||
name: "digits template error",
|
||||
params: map[string]any{
|
||||
"preWait": 0,
|
||||
"digits": "{{.NonExistentField}} ",
|
||||
"postWait": 0,
|
||||
},
|
||||
errorString: "template: digits:1:2: executing \"digits\" at <.NonExistentField>: can't evaluate field NonExistentField in type common.WrappedPayload",
|
||||
},
|
||||
{
|
||||
name: "invalid digits template result",
|
||||
payload: "nhf",
|
||||
params: map[string]any{
|
||||
"preWait": 0,
|
||||
"digits": "{{.Payload}}",
|
||||
"postWait": 0,
|
||||
},
|
||||
errorString: "sip.response.dtmf.create result of digits template contains invalid characters",
|
||||
},
|
||||
{
|
||||
name: "missing postWait param",
|
||||
params: map[string]any{
|
||||
"preWait": 0,
|
||||
"digits": "good.wav",
|
||||
},
|
||||
errorString: "sip.response.dtmf.create postWait error: not found",
|
||||
},
|
||||
{
|
||||
name: "non-numeric postWait param",
|
||||
params: map[string]any{
|
||||
"preWait": 0,
|
||||
"digits": "good.wav",
|
||||
"postWait": "not a number",
|
||||
},
|
||||
errorString: "sip.response.dtmf.create postWait error: not a number",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
|
||||
registration, ok := processor.GetProcessorRegistration("sip.response.dtmf.create")
|
||||
if !ok {
|
||||
t.Fatalf("sip.response.dtmf.create processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "sip.response.dtmf.create",
|
||||
Params: test.params,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
if test.errorString != err.Error() {
|
||||
t.Fatalf("sip.response.dtmf.create got error '%s', expected '%s'", err.Error(), test.errorString)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
|
||||
|
||||
if err == nil {
|
||||
t.Fatalf("sip.response.dtmf.create expected to fail but succeeded, got: %v", got)
|
||||
}
|
||||
|
||||
if err.Error() != test.errorString {
|
||||
t.Fatalf("sip.response.dtmf.create got error '%s', expected '%s'", err.Error(), test.errorString)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkSipResponseDTMFCreate(b *testing.B) {
|
||||
registration, ok := processor.GetProcessorRegistration("sip.response.dtmf.create")
|
||||
if !ok {
|
||||
b.Fatalf("sip.response.dtmf.create processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "sip.response.dtmf.create",
|
||||
Params: map[string]any{
|
||||
"preWait": 0,
|
||||
"digits": "{{.Payload}}",
|
||||
"postWait": 0,
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
b.Fatalf("sip.response.dtmf.create failed to create processor: %s", err)
|
||||
}
|
||||
|
||||
count := 0
|
||||
for b.Loop() {
|
||||
_, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: count})
|
||||
if err != nil {
|
||||
b.Fatalf("sip.response.dtmf.create processing failed: %s", err)
|
||||
}
|
||||
count++
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ func TestStringCreateFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "string.create",
|
||||
Params: map[string]any{
|
||||
"template": "{{.Payload}}",
|
||||
@@ -25,6 +26,10 @@ func TestStringCreateFromRegistry(t *testing.T) {
|
||||
t.Fatalf("failed to create string.create processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("string.create processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "string.create" {
|
||||
t.Fatalf("string.create processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -16,12 +16,17 @@ func TestStringDecodeFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "string.decode",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create string.decode processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("string.decode processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "string.decode" {
|
||||
t.Fatalf("string.decode processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
@@ -17,12 +17,17 @@ func TestStringEncodeFromRegistry(t *testing.T) {
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "string.encode",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create string.encode processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("string.encode processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "string.encode" {
|
||||
t.Fatalf("string.encode processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user