edge/cmd/cli/command/cast/scan.go
William Petit 90020d6ea6
Some checks failed
arcad/edge/pipeline/head There was a failure building this commit
feat(module,cast): enhance casting device discovery speed
2023-04-20 19:20:52 +02:00

43 lines
841 B
Go

package cast
import (
"context"
"log"
"time"
"forge.cadoles.com/arcad/edge/pkg/module/cast"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
)
func ScanCommand() *cli.Command {
return &cli.Command{
Name: "scan",
Usage: "Scan network for casting devices",
Flags: []cli.Flag{
&cli.DurationFlag{
Name: "timeout",
Aliases: []string{"t"},
Value: 30 * time.Second,
},
},
Action: func(ctx *cli.Context) error {
timeout := ctx.Duration("timeout")
searchCtx, cancel := context.WithTimeout(ctx.Context, timeout)
defer cancel()
devices, err := cast.SearchDevices(searchCtx)
if err != nil {
log.Fatalf("%+v", errors.WithStack(err))
}
for dev := range devices {
log.Printf("[DEVICE] %s %s %s:%d", dev.UUID, dev.Name, dev.Host.String(), dev.Port)
}
return nil
},
}
}