edge/pkg/module/cast/device.go

42 lines
912 B
Go
Raw Normal View History

package cast
import "net"
type DeviceType string
type Device interface {
DeviceType() DeviceType
DeviceHost() net.IP
DevicePort() int
DeviceName() string
DeviceID() string
}
2024-01-12 14:02:53 +01:00
type legacyDevice struct {
Device `json:"-"`
UUID string `goja:"uuid" json:"uuid"`
Host string `goja:"host" json:"host"`
Port int `goja:"port" json:"port"`
Name string `goja:"name" json:"name"`
Type string `goja:"type" json:"type"`
}
func toLegacyDevice(device Device) *legacyDevice {
return &legacyDevice{
Device: device,
UUID: device.DeviceID(),
Host: device.DeviceHost().String(),
Port: device.DevicePort(),
Name: device.DeviceName(),
Type: string(device.DeviceType()),
}
}
func toLegacyDevices(devices ...Device) []*legacyDevice {
legacyDevices := make([]*legacyDevice, len(devices))
for i, d := range devices {
legacyDevices[i] = toLegacyDevice(d)
}
return legacyDevices
}