mess around with support WASM builds

This commit is contained in:
Joel Wetzell
2026-03-30 14:46:35 -05:00
parent 882af2948a
commit 050ada6a70
31 changed files with 487 additions and 6 deletions

View File

@@ -1,3 +1,5 @@
//go:build !js
package processor
import (

View File

@@ -1,3 +1,5 @@
//go:build !js
package processor
import (

View File

@@ -21,6 +21,11 @@ type HTTPRequestDo struct {
URL *template.Template
}
type HTTPResponse struct {
Status int
Body []byte
}
func (hrd *HTTPRequestDo) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
templateData := wrappedPayload

View File

@@ -1,3 +1,5 @@
//go:build !js
package processor
import (
@@ -17,11 +19,6 @@ type HTTPResponseCreate struct {
config config.ProcessorConfig
}
type HTTPResponse struct {
Status int
Body []byte
}
func (hrc *HTTPResponseCreate) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
templateData := wrappedPayload

View File

@@ -1,3 +1,5 @@
//go:build !js
package processor
import (

View File

@@ -1,3 +1,5 @@
//go:build !js
package processor
import (

View File

@@ -1,3 +1,5 @@
//go:build !js
package processor
import (

View File

@@ -1,3 +1,5 @@
//go:build !js
package processor
import (

View File

@@ -1,3 +1,5 @@
//go:build !js
package processor
import (

View File

@@ -1,3 +1,5 @@
//go:build !js
package processor
import (

View File

@@ -0,0 +1,102 @@
//go:build js
package processor
import (
"bytes"
"context"
"fmt"
"html/template"
"log/slog"
"syscall/js"
"github.com/google/jsonschema-go/jsonschema"
"github.com/jwetzell/showbridge-go/internal/common"
"github.com/jwetzell/showbridge-go/internal/config"
)
type WebSet struct {
config config.ProcessorConfig
ModuleId string
ElementId string
Property string
Value *template.Template
logger *slog.Logger
}
func (kvs *WebSet) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
element := js.Global().Get("document").Call("getElementById", kvs.ElementId)
if element.IsNull() || element.IsUndefined() {
wrappedPayload.End = true
return wrappedPayload, fmt.Errorf("web.set unable to find element with id: %s", kvs.ElementId)
}
var valueBuffer bytes.Buffer
err := kvs.Value.Execute(&valueBuffer, wrappedPayload)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
element.Set(kvs.Property, valueBuffer.String())
return wrappedPayload, nil
}
func (kvs *WebSet) Type() string {
return kvs.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "web.set",
Title: "Set Web Element Property",
ParamsSchema: &jsonschema.Schema{
Type: "object",
Properties: map[string]*jsonschema.Schema{
"id": {
Title: "Element ID",
Type: "string",
},
"property": {
Title: "Property",
Type: "string",
},
"value": {
Title: "Value",
Type: "string",
},
},
Required: []string{"id", "property", "value"},
AdditionalProperties: nil,
},
New: func(config config.ProcessorConfig) (Processor, error) {
params := config.Params
idString, err := params.GetString("id")
if err != nil {
return nil, fmt.Errorf("web.set id error: %w", err)
}
propertyString, err := params.GetString("property")
if err != nil {
return nil, fmt.Errorf("web.set property error: %w", err)
}
valueString, err := params.GetString("value")
if err != nil {
return nil, fmt.Errorf("web.set value error: %w", err)
}
valueTemplate, err := template.New("template").Parse(valueString)
if err != nil {
return nil, err
}
return &WebSet{config: config, ElementId: idString, Property: propertyString, Value: valueTemplate, logger: slog.Default().With("component", "processor", "type", config.Type)}, nil
},
})
}