2023-04-05 15:12:51 +02:00
|
|
|
package cast
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"log"
|
|
|
|
"time"
|
|
|
|
|
2023-04-20 19:20:52 +02:00
|
|
|
"forge.cadoles.com/arcad/edge/pkg/module/cast"
|
2023-04-05 15:12:51 +02:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
func ScanCommand() *cli.Command {
|
|
|
|
return &cli.Command{
|
|
|
|
Name: "scan",
|
|
|
|
Usage: "Scan network for casting devices",
|
2023-04-20 19:20:52 +02:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.DurationFlag{
|
|
|
|
Name: "timeout",
|
|
|
|
Aliases: []string{"t"},
|
2024-01-12 12:11:41 +01:00
|
|
|
Value: 10 * time.Second,
|
2023-04-20 19:20:52 +02:00
|
|
|
},
|
|
|
|
},
|
2023-04-05 15:12:51 +02:00
|
|
|
Action: func(ctx *cli.Context) error {
|
2023-04-20 19:20:52 +02:00
|
|
|
timeout := ctx.Duration("timeout")
|
2023-04-05 15:12:51 +02:00
|
|
|
|
2023-04-20 19:20:52 +02:00
|
|
|
searchCtx, cancel := context.WithTimeout(ctx.Context, timeout)
|
|
|
|
defer cancel()
|
2023-04-05 15:12:51 +02:00
|
|
|
|
2023-04-20 19:20:52 +02:00
|
|
|
devices, err := cast.SearchDevices(searchCtx)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("%+v", errors.WithStack(err))
|
|
|
|
}
|
2023-04-05 15:12:51 +02:00
|
|
|
|
2024-01-12 12:11:41 +01:00
|
|
|
for _, dev := range devices {
|
|
|
|
log.Printf("[DEVICE] %s %s %s %s:%d", dev.DeviceID(), dev.DeviceType(), dev.DeviceName(), dev.DeviceHost().String(), dev.DevicePort())
|
2023-04-05 15:12:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|