feat(module): generalizing casting process
All checks were successful
arcad/edge/pipeline/head This commit looks good
All checks were successful
arcad/edge/pipeline/head This commit looks good
This commit is contained in:
@ -52,6 +52,9 @@ import (
|
||||
_ "forge.cadoles.com/arcad/edge/pkg/storage/driver/rpc"
|
||||
_ "forge.cadoles.com/arcad/edge/pkg/storage/driver/sqlite"
|
||||
|
||||
// Register casting device supported types
|
||||
_ "forge.cadoles.com/arcad/edge/pkg/module/cast/chromecast"
|
||||
|
||||
"forge.cadoles.com/arcad/edge/pkg/storage/share"
|
||||
)
|
||||
|
||||
|
@ -1,6 +1,9 @@
|
||||
package cast
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"forge.cadoles.com/arcad/edge/pkg/module/cast"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli/v2"
|
||||
@ -21,16 +24,25 @@ func LoadURLCommand() *cli.Command {
|
||||
Aliases: []string{"u"},
|
||||
Required: true,
|
||||
},
|
||||
&cli.DurationFlag{
|
||||
Name: "timeout",
|
||||
Aliases: []string{"t"},
|
||||
Value: 10 * time.Second,
|
||||
},
|
||||
},
|
||||
Action: func(ctx *cli.Context) error {
|
||||
device := ctx.String("device")
|
||||
url := ctx.String("url")
|
||||
timeout := ctx.Duration("timeout")
|
||||
|
||||
if err := cast.StopCast(ctx.Context, device); err != nil {
|
||||
timeoutCtx, cancel := context.WithTimeout(ctx.Context, timeout)
|
||||
defer cancel()
|
||||
|
||||
if err := cast.StopCast(timeoutCtx, device); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
if err := cast.LoadURL(ctx.Context, device, url); err != nil {
|
||||
if err := cast.LoadURL(timeoutCtx, device, url); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,8 @@ func Root() *cli.Command {
|
||||
Subcommands: []*cli.Command{
|
||||
ScanCommand(),
|
||||
LoadURLCommand(),
|
||||
StatusCommand(),
|
||||
StopCastCommand(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,9 @@ import (
|
||||
"forge.cadoles.com/arcad/edge/pkg/module/cast"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli/v2"
|
||||
|
||||
// Register casting device supported types
|
||||
_ "forge.cadoles.com/arcad/edge/pkg/module/cast/chromecast"
|
||||
)
|
||||
|
||||
func ScanCommand() *cli.Command {
|
||||
@ -18,7 +21,7 @@ func ScanCommand() *cli.Command {
|
||||
&cli.DurationFlag{
|
||||
Name: "timeout",
|
||||
Aliases: []string{"t"},
|
||||
Value: 30 * time.Second,
|
||||
Value: 10 * time.Second,
|
||||
},
|
||||
},
|
||||
Action: func(ctx *cli.Context) error {
|
||||
@ -32,8 +35,8 @@ func ScanCommand() *cli.Command {
|
||||
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)
|
||||
for _, dev := range devices {
|
||||
log.Printf("[DEVICE] %s %s %s %s:%d", dev.DeviceID(), dev.DeviceType(), dev.DeviceName(), dev.DeviceHost().String(), dev.DevicePort())
|
||||
}
|
||||
|
||||
return nil
|
||||
|
46
cmd/cli/command/cast/status.go
Normal file
46
cmd/cli/command/cast/status.go
Normal file
@ -0,0 +1,46 @@
|
||||
package cast
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"forge.cadoles.com/arcad/edge/pkg/module/cast"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
func StatusCommand() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "status",
|
||||
Usage: "Retrieve casting device status",
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "device",
|
||||
Aliases: []string{"d"},
|
||||
Required: true,
|
||||
},
|
||||
&cli.DurationFlag{
|
||||
Name: "timeout",
|
||||
Aliases: []string{"t"},
|
||||
Value: 10 * time.Second,
|
||||
},
|
||||
},
|
||||
Action: func(ctx *cli.Context) error {
|
||||
device := ctx.String("device")
|
||||
timeout := ctx.Duration("timeout")
|
||||
|
||||
getStatusCtx, cancel := context.WithTimeout(ctx.Context, timeout)
|
||||
defer cancel()
|
||||
|
||||
status, err := cast.GetStatus(getStatusCtx, device)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
log.Printf("[STATUS] %s %s", status.Title(), status.State())
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
42
cmd/cli/command/cast/stop_cast.go
Normal file
42
cmd/cli/command/cast/stop_cast.go
Normal file
@ -0,0 +1,42 @@
|
||||
package cast
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"forge.cadoles.com/arcad/edge/pkg/module/cast"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
func StopCastCommand() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "stop-cast",
|
||||
Usage: "Stop casting process on device",
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "device",
|
||||
Aliases: []string{"d"},
|
||||
Required: true,
|
||||
},
|
||||
&cli.DurationFlag{
|
||||
Name: "timeout",
|
||||
Aliases: []string{"t"},
|
||||
Value: 10 * time.Second,
|
||||
},
|
||||
},
|
||||
Action: func(ctx *cli.Context) error {
|
||||
device := ctx.String("device")
|
||||
timeout := ctx.Duration("timeout")
|
||||
|
||||
timeoutCtx, cancel := context.WithTimeout(ctx.Context, timeout)
|
||||
defer cancel()
|
||||
|
||||
if err := cast.StopCast(timeoutCtx, device); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user