2023-04-05 15:12:51 +02:00
|
|
|
package cast
|
|
|
|
|
|
|
|
import (
|
2024-01-12 12:11:41 +01:00
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
2023-04-05 15:12:51 +02:00
|
|
|
"forge.cadoles.com/arcad/edge/pkg/module/cast"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
func LoadURLCommand() *cli.Command {
|
|
|
|
return &cli.Command{
|
|
|
|
Name: "load-url",
|
|
|
|
Usage: "Load `URL` in casting device",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "device",
|
|
|
|
Aliases: []string{"d"},
|
|
|
|
Required: true,
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "url",
|
|
|
|
Aliases: []string{"u"},
|
|
|
|
Required: true,
|
|
|
|
},
|
2024-01-12 12:11:41 +01:00
|
|
|
&cli.DurationFlag{
|
|
|
|
Name: "timeout",
|
|
|
|
Aliases: []string{"t"},
|
|
|
|
Value: 10 * time.Second,
|
|
|
|
},
|
2023-04-05 15:12:51 +02:00
|
|
|
},
|
|
|
|
Action: func(ctx *cli.Context) error {
|
|
|
|
device := ctx.String("device")
|
|
|
|
url := ctx.String("url")
|
2024-01-12 12:11:41 +01:00
|
|
|
timeout := ctx.Duration("timeout")
|
|
|
|
|
|
|
|
timeoutCtx, cancel := context.WithTimeout(ctx.Context, timeout)
|
|
|
|
defer cancel()
|
2023-04-05 15:12:51 +02:00
|
|
|
|
2024-01-12 12:11:41 +01:00
|
|
|
if err := cast.StopCast(timeoutCtx, device); err != nil {
|
2023-04-05 15:12:51 +02:00
|
|
|
return errors.WithStack(err)
|
|
|
|
}
|
|
|
|
|
2024-01-12 12:11:41 +01:00
|
|
|
if err := cast.LoadURL(timeoutCtx, device, url); err != nil {
|
2023-04-05 15:12:51 +02:00
|
|
|
return errors.WithStack(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|