edge/pkg/module/cast/arcast/device.go

58 lines
1.3 KiB
Go

package arcast
import (
"context"
"net"
"forge.cadoles.com/arcad/arcast/pkg/client"
"forge.cadoles.com/arcad/arcast/pkg/server"
"forge.cadoles.com/arcad/edge/pkg/module/cast"
"github.com/pkg/errors"
"gitlab.com/wpetit/goweb/logger"
)
const DeviceTypeArcast cast.DeviceType = "arcast"
type Device struct {
player *client.Player
}
// DeviceHost implements cast.Device.
func (d *Device) DeviceHost() net.IP {
rawPreferredIP, err := server.FindPreferredLocalAddress(d.player.IPs...)
if err != nil {
logger.Error(context.Background(), "could not find preferred local address", logger.CapturedE(errors.WithStack(err)))
return d.player.IPs[0]
}
preferredIP := net.ParseIP(rawPreferredIP)
if preferredIP == nil {
logger.Error(context.Background(), "could not parse device preferred ip", logger.F("rawPreferredIP", rawPreferredIP))
return d.player.IPs[0]
}
return preferredIP
}
// DeviceID implements cast.Device.
func (d *Device) DeviceID() string {
return d.player.ID
}
// DeviceName implements cast.Device.
func (d *Device) DeviceName() string {
return d.player.ID
}
// DevicePort implements cast.Device.
func (d *Device) DevicePort() int {
return d.player.Port
}
// DeviceType implements cast.Device.
func (d *Device) DeviceType() cast.DeviceType {
return DeviceTypeArcast
}
var _ cast.Device = &Device{}