feat(module,cast): enhance casting device discovery speed
Some checks failed
arcad/edge/pipeline/head There was a failure building this commit

This commit is contained in:
2023-04-20 19:20:52 +02:00
parent 7b6e39088d
commit 90020d6ea6
7 changed files with 485 additions and 208 deletions

View File

@ -5,7 +5,7 @@ import (
"log"
"time"
"github.com/barnybug/go-cast/discovery"
"forge.cadoles.com/arcad/edge/pkg/module/cast"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
)
@ -14,21 +14,26 @@ func ScanCommand() *cli.Command {
return &cli.Command{
Name: "scan",
Usage: "Scan network for casting devices",
Flags: []cli.Flag{},
Flags: []cli.Flag{
&cli.DurationFlag{
Name: "timeout",
Aliases: []string{"t"},
Value: 30 * time.Second,
},
},
Action: func(ctx *cli.Context) error {
service := discovery.NewService(ctx.Context)
defer service.Stop()
timeout := ctx.Duration("timeout")
go func() {
if err := service.Run(ctx.Context, time.Second); err != nil && !errors.Is(err, context.DeadlineExceeded) {
log.Fatalf("%+v", errors.WithStack(err))
}
}()
searchCtx, cancel := context.WithTimeout(ctx.Context, timeout)
defer cancel()
found := service.Found()
devices, err := cast.SearchDevices(searchCtx)
if err != nil {
log.Fatalf("%+v", errors.WithStack(err))
}
for device := range found {
log.Printf("[DEVICE] %s %s %s:%d", device.Uuid(), device.Name(), device.IP().String(), device.Port())
for dev := range devices {
log.Printf("[DEVICE] %s %s %s:%d", dev.UUID, dev.Name, dev.Host.String(), dev.Port)
}
return nil