gocast

package module
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

README

gocast

testing

forked from github.com/vishen/go-chromecast

goal

  • make a easy to use library for chromecast with documentation and examples

TODOs

  • error handling
  • fix race conditions
  • remove more stuff

removed libs

  • github.com/mitchellh/go-homedir
  • github.com/pkg/errors
  • github.com/sirupsen/logrus
  • github.com/h2non/filetype

Documentation

Overview

Package api is a generated protocol buffer package.

It is generated from these files:

api/cast_channel.proto

It has these top-level messages:

CastMessage
AuthChallenge
AuthResponse
AuthError
DeviceAuthMessage

Index

Constants

This section is empty.

Variables

View Source
var (
	// ConnectHeader Known Payload headers
	ConnectHeader     = PayloadHeader{Type: "CONNECT"}
	CloseHeader       = PayloadHeader{Type: "CLOSE"}
	GetStatusHeader   = PayloadHeader{Type: "GET_STATUS"}
	PongHeader        = PayloadHeader{Type: "PONG"}         // Response to PING payload
	LaunchHeader      = PayloadHeader{Type: "LAUNCH"}       // Launches a new chromecast app
	StopHeader        = PayloadHeader{Type: "STOP"}         // Stop playing current media
	PlayHeader        = PayloadHeader{Type: "PLAY"}         // Plays / unpauses the running app
	PauseHeader       = PayloadHeader{Type: "PAUSE"}        // Pauses the running app
	SeekHeader        = PayloadHeader{Type: "SEEK"}         // Seek into the running app
	VolumeHeader      = PayloadHeader{Type: "SET_VOLUME"}   // Sets the volume
	LoadHeader        = PayloadHeader{Type: "LOAD"}         // Loads an application onto the chromecast
	QueueLoadHeader   = PayloadHeader{Type: "QUEUE_LOAD"}   // Loads an application onto the chromecast
	QueueUpdateHeader = PayloadHeader{Type: "QUEUE_UPDATE"} // Loads an application onto the chromecast
)
View Source
var AuthError_ErrorType_name = map[int32]string{
	0: "INTERNAL_ERROR",
	1: "NO_TLS",
}
View Source
var AuthError_ErrorType_value = map[string]int32{
	"INTERNAL_ERROR": 0,
	"NO_TLS":         1,
}
View Source
var CastMessage_PayloadType_name = map[int32]string{
	0: "STRING",
	1: "BINARY",
}
View Source
var CastMessage_PayloadType_value = map[string]int32{
	"STRING": 0,
	"BINARY": 1,
}
View Source
var CastMessage_ProtocolVersion_name = map[int32]string{
	0: "CASTV2_1_0",
}
View Source
var CastMessage_ProtocolVersion_value = map[string]int32{
	"CASTV2_1_0": 0,
}

Functions

func DiscoverCastDNSEntries

func DiscoverCastDNSEntries(ctx context.Context, iface *net.Interface) (<-chan CastEntry, error)

DiscoverCastDNSEntries will return a channel with any cast dns entries found.

Types

type Application

type Application struct {
	// contains filtered or unexported fields
}

func NewApplication

func NewApplication(opts ...ApplicationOption) *Application

func (*Application) AddMessageFunc

func (a *Application) AddMessageFunc(f CastMessageFunc)

func (*Application) Close

func (a *Application) Close(stopMedia bool) error

func (*Application) LoadApp

func (a *Application) LoadApp(appID, contentID string) error

func (*Application) Media

func (a *Application) Media() *Media

func (*Application) MediaFinished

func (a *Application) MediaFinished()

func (*Application) MediaStart

func (a *Application) MediaStart()

MediaStart TODO: Clean-up: these Media* methods are a hack around trying to use the mediaFinished channel when it hasn't been properly set up. This is happening because there is some instances where we don't have any running media ('watch' command) but yet the 'mediaFinished' is littered throughout the codebase. This needs a redesign now that we do things other than just loading and playing media files.

func (*Application) MediaWait

func (a *Application) MediaWait()

func (*Application) Next

func (a *Application) Next() error

func (*Application) Pause

func (a *Application) Pause() error

func (*Application) Previous

func (a *Application) Previous() error

func (*Application) Seek

func (a *Application) Seek(value int) error

func (*Application) SeekFromStart

func (a *Application) SeekFromStart(value int) error

func (*Application) SeekToTime

func (a *Application) SeekToTime(value float32) error

func (*Application) SetMuted

func (a *Application) SetMuted(value bool) error

func (*Application) SetVolume

func (a *Application) SetVolume(value float32) error

func (*Application) Skip

func (a *Application) Skip() error

func (*Application) Start

func (a *Application) Start(addr string, port int) error

func (*Application) Status

func (a *Application) Status() (*PayloadApplication, *Media, *Volume)

func (*Application) Stop

func (a *Application) Stop() error

func (*Application) StopMedia

func (a *Application) StopMedia() error

func (*Application) Unpause

func (a *Application) Unpause() error

func (*Application) Update

func (a *Application) Update() error

func (*Application) Volume

func (a *Application) Volume() *Volume

type ApplicationOption

type ApplicationOption func(*Application)

func WithConnectionRetries

func WithConnectionRetries(connectionRetries int) ApplicationOption

func WithIface

func WithIface(iface *net.Interface) ApplicationOption

type AuthChallenge

type AuthChallenge struct {
	XXX_unrecognized []byte `json:"-"`
}

Messages for authentication protocol between a sender and a receiver.

func (*AuthChallenge) ProtoMessage

func (*AuthChallenge) ProtoMessage()

func (*AuthChallenge) Reset

func (m *AuthChallenge) Reset()

func (*AuthChallenge) String

func (m *AuthChallenge) String() string

type AuthError

type AuthError struct {
	ErrorType        *AuthError_ErrorType `protobuf:"varint,1,req,name=error_type,enum=api.AuthError_ErrorType" json:"error_type,omitempty"`
	XXX_unrecognized []byte               `json:"-"`
}

func (*AuthError) GetErrorType

func (m *AuthError) GetErrorType() AuthError_ErrorType

func (*AuthError) ProtoMessage

func (*AuthError) ProtoMessage()

func (*AuthError) Reset

func (m *AuthError) Reset()

func (*AuthError) String

func (m *AuthError) String() string

type AuthError_ErrorType

type AuthError_ErrorType int32
const (
	AuthError_INTERNAL_ERROR AuthError_ErrorType = 0
	AuthError_NO_TLS         AuthError_ErrorType = 1
)

func (AuthError_ErrorType) Enum

func (AuthError_ErrorType) String

func (x AuthError_ErrorType) String() string

func (*AuthError_ErrorType) UnmarshalJSON

func (x *AuthError_ErrorType) UnmarshalJSON(data []byte) error

type AuthResponse

type AuthResponse struct {
	Signature             []byte `protobuf:"bytes,1,req,name=signature" json:"signature,omitempty"`
	ClientAuthCertificate []byte `protobuf:"bytes,2,req,name=client_auth_certificate" json:"client_auth_certificate,omitempty"`
	XXX_unrecognized      []byte `json:"-"`
}

func (*AuthResponse) GetClientAuthCertificate

func (m *AuthResponse) GetClientAuthCertificate() []byte

func (*AuthResponse) GetSignature

func (m *AuthResponse) GetSignature() []byte

func (*AuthResponse) ProtoMessage

func (*AuthResponse) ProtoMessage()

func (*AuthResponse) Reset

func (m *AuthResponse) Reset()

func (*AuthResponse) String

func (m *AuthResponse) String() string

type CastEntry

type CastEntry struct {
	AddrV4     net.IP
	AddrV6     net.IP
	Port       int
	Name       string
	Host       string
	UUID       string
	Device     string
	Status     string
	DeviceName string
	InfoFields map[string]string
}

CastEntry is the concrete cast entry type.

func (CastEntry) GetAddr

func (e CastEntry) GetAddr() string

GetAddr returns the IPV4 of a cast entry if it is not nil otherwise the IPV6.

func (CastEntry) GetName

func (e CastEntry) GetName() string

GetName returns the identified name of a cast entry.

func (CastEntry) GetPort

func (e CastEntry) GetPort() int

GetPort returns the port of a cast entry.

func (CastEntry) GetUUID

func (e CastEntry) GetUUID() string

GetUUID returns a unqiue id of a cast entry.

type CastMessage

type CastMessage struct {
	ProtocolVersion *CastMessage_ProtocolVersion `protobuf:"varint,1,req,name=protocol_version,enum=api.CastMessage_ProtocolVersion" json:"protocol_version,omitempty"`
	// source and destination ids identify the origin and destination of the
	// message.  They are used to route messages between endpoints that share a
	// device-to-device channel.
	//
	// For messages between applications:
	//   - The sender application id is a unique identifier generated on behalf of
	//     the sender application.
	//   - The receiver id is always the the session id for the application.
	//
	// For messages to or from the sender or receiver platform, the special ids
	// 'sender-0' and 'receiver-0' can be used.
	//
	// For messages intended for all endpoints using a given channel, the
	// wildcard destination_id '*' can be used.
	SourceId      *string `protobuf:"bytes,2,req,name=source_id" json:"source_id,omitempty"`
	DestinationId *string `protobuf:"bytes,3,req,name=destination_id" json:"destination_id,omitempty"`
	// This is the core multiplexing key.  All messages are sent on a namespace
	// and endpoints sharing a channel listen on one or more namespaces.  The
	// namespace defines the protocol and semantics of the message.
	Namespace   *string                  `protobuf:"bytes,4,req,name=namespace" json:"namespace,omitempty"`
	PayloadType *CastMessage_PayloadType `protobuf:"varint,5,req,name=payload_type,enum=api.CastMessage_PayloadType" json:"payload_type,omitempty"`
	// Depending on payload_type, exactly one of the following optional fields
	// will always be set.
	PayloadUtf8      *string `protobuf:"bytes,6,opt,name=payload_utf8" json:"payload_utf8,omitempty"`
	PayloadBinary    []byte  `protobuf:"bytes,7,opt,name=payload_binary" json:"payload_binary,omitempty"`
	XXX_unrecognized []byte  `json:"-"`
}

func (*CastMessage) GetDestinationId

func (m *CastMessage) GetDestinationId() string

func (*CastMessage) GetNamespace

func (m *CastMessage) GetNamespace() string

func (*CastMessage) GetPayloadBinary

func (m *CastMessage) GetPayloadBinary() []byte

func (*CastMessage) GetPayloadType

func (m *CastMessage) GetPayloadType() CastMessage_PayloadType

func (*CastMessage) GetPayloadUtf8

func (m *CastMessage) GetPayloadUtf8() string

func (*CastMessage) GetProtocolVersion

func (m *CastMessage) GetProtocolVersion() CastMessage_ProtocolVersion

func (*CastMessage) GetSourceId

func (m *CastMessage) GetSourceId() string

func (*CastMessage) ProtoMessage

func (*CastMessage) ProtoMessage()

func (*CastMessage) Reset

func (m *CastMessage) Reset()

func (*CastMessage) String

func (m *CastMessage) String() string

type CastMessageFunc

type CastMessageFunc func(*CastMessage)

type CastMessage_PayloadType

type CastMessage_PayloadType int32

What type of data do we have in this message.

const (
	CastMessage_STRING CastMessage_PayloadType = 0
	CastMessage_BINARY CastMessage_PayloadType = 1
)

func (CastMessage_PayloadType) Enum

func (CastMessage_PayloadType) String

func (x CastMessage_PayloadType) String() string

func (*CastMessage_PayloadType) UnmarshalJSON

func (x *CastMessage_PayloadType) UnmarshalJSON(data []byte) error

type CastMessage_ProtocolVersion

type CastMessage_ProtocolVersion int32

CastMessage_ProtocolVersion Always pass a version of the protocol for future compatibility requirements.

const (
	CastMessage_CASTV2_1_0 CastMessage_ProtocolVersion = 0
)

func (CastMessage_ProtocolVersion) Enum

func (CastMessage_ProtocolVersion) String

func (*CastMessage_ProtocolVersion) UnmarshalJSON

func (x *CastMessage_ProtocolVersion) UnmarshalJSON(data []byte) error

type Connection

type Connection struct {
	// contains filtered or unexported fields
}

func NewConnection

func NewConnection(recvMsgChan chan *CastMessage) *Connection

func (*Connection) Close

func (c *Connection) Close() error

func (*Connection) LocalAddr

func (c *Connection) LocalAddr() (addr string, err error)

func (*Connection) Send

func (c *Connection) Send(requestID int, payload Payload, sourceID, destinationID, namespace string) error

func (*Connection) SetDebug

func (c *Connection) SetDebug(debug bool)

func (*Connection) Start

func (c *Connection) Start(addr string, port int) error

type DeviceAuthMessage

type DeviceAuthMessage struct {
	// Request fields
	Challenge *AuthChallenge `protobuf:"bytes,1,opt,name=challenge" json:"challenge,omitempty"`
	// Response fields
	Response         *AuthResponse `protobuf:"bytes,2,opt,name=response" json:"response,omitempty"`
	Error            *AuthError    `protobuf:"bytes,3,opt,name=error" json:"error,omitempty"`
	XXX_unrecognized []byte        `json:"-"`
}

func (*DeviceAuthMessage) GetChallenge

func (m *DeviceAuthMessage) GetChallenge() *AuthChallenge

func (*DeviceAuthMessage) GetError

func (m *DeviceAuthMessage) GetError() *AuthError

func (*DeviceAuthMessage) GetResponse

func (m *DeviceAuthMessage) GetResponse() *AuthResponse

func (*DeviceAuthMessage) ProtoMessage

func (*DeviceAuthMessage) ProtoMessage()

func (*DeviceAuthMessage) Reset

func (m *DeviceAuthMessage) Reset()

func (*DeviceAuthMessage) String

func (m *DeviceAuthMessage) String() string

type Image

type Image struct {
	URL    string `json:"url"`
	Height int    `json:"height"`
	Width  int    `json:"width"`
}

type LaunchRequest

type LaunchRequest struct {
	PayloadHeader
	AppId string `json:"appId"`
}

type LoadMediaCommand

type LoadMediaCommand struct {
	PayloadHeader
	Media       MediaItem   `json:"media"`
	CurrentTime int         `json:"currentTime"`
	Autoplay    bool        `json:"autoplay"`
	QueueData   QueueData   `json:"queueData"`
	CustomData  interface{} `json:"customData"`
}

type Media

type Media struct {
	MediaSessionId int     `json:"mediaSessionId"`
	PlayerState    string  `json:"playerState"`
	CurrentTime    float32 `json:"currentTime"`
	IdleReason     string  `json:"idleReason"`
	Volume         Volume  `json:"volume"`
	CurrentItemId  int     `json:"currentItemId"`
	LoadingItemId  int     `json:"loadingItemId"`

	Media MediaItem `json:"media"`
}

type MediaHeader

type MediaHeader struct {
	PayloadHeader
	MediaSessionId int     `json:"mediaSessionId"`
	CurrentTime    float32 `json:"currentTime"`
	RelativeTime   float32 `json:"relativeTime,omitempty"`
	ResumeState    string  `json:"resumeState"`
}

type MediaItem

type MediaItem struct {
	ContentId   string        `json:"contentId"`
	ContentType string        `json:"contentType"`
	StreamType  string        `json:"streamType"`
	Duration    float32       `json:"duration"`
	Metadata    MediaMetadata `json:"metadata"`
}

type MediaMetadata

type MediaMetadata struct {
	MetadataType int     `json:"metadataType"`
	Artist       string  `json:"artist"`
	Title        string  `json:"title"`
	Subtitle     string  `json:"subtitle"`
	Images       []Image `json:"images"`
	ReleaseDate  string  `json:"releaseDate"`
}

type MediaStatusResponse

type MediaStatusResponse struct {
	PayloadHeader
	Status []Media `json:"status"`
}

type Payload

type Payload interface {
	SetRequestId(id int)
}

type PayloadApplication

type PayloadApplication struct {
	AppId        string `json:"appId"`
	DisplayName  string `json:"displayName"`
	IsIdleScreen bool   `json:"isIdleScreen"`
	SessionId    string `json:"sessionId"`
	StatusText   string `json:"statusText"`
	TransportId  string `json:"transportId"`
}

type PayloadHeader

type PayloadHeader struct {
	Type      string `json:"type"`
	RequestId int    `json:"requestId,omitempty"`
}

func (*PayloadHeader) SetRequestId

func (p *PayloadHeader) SetRequestId(id int)

type QueueData

type QueueData struct {
	StartIndex int `json:"startIndex"`
}

type QueueLoad

type QueueLoad struct {
	PayloadHeader
	MediaSessionId int             `json:"mediaSessionId,omitempty"`
	CurrentTime    float32         `json:"currentTime"`
	StartIndex     int             `json:"startIndex"`
	RepeatMode     string          `json:"repeatMode"`
	Items          []QueueLoadItem `json:"items"`
}

type QueueLoadItem

type QueueLoadItem struct {
	Media            MediaItem `json:"media"`
	Autoplay         bool      `json:"autoplay"`
	PlaybackDuration int       `json:"playbackDuration"`
}

type QueueUpdate

type QueueUpdate struct {
	PayloadHeader
	MediaSessionId int `json:"mediaSessionId,omitempty"`
	Jump           int `json:"jump,omitempty"`
}

type ReceiverStatusRequest

type ReceiverStatusRequest struct {
	PayloadHeader
	Applications []PayloadApplication `json:"applications"`

	Volume Volume `json:"volume"`
}

type ReceiverStatusResponse

type ReceiverStatusResponse struct {
	PayloadHeader
	Status struct {
		Applications []PayloadApplication `json:"applications"`
		Volume       Volume               `json:"volume"`
	} `json:"status"`
}

type SetVolume

type SetVolume struct {
	PayloadHeader
	Volume Volume `json:"volume"`
}

type Volume

type Volume struct {
	Level float32 `json:"level,omitempty"`
	Muted bool    `json:"muted"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL