gcast

package
v0.0.0-...-a1b9eeb Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2020 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultReceiverAppID = "CC1AD845"
	YouTubeReceiverAppID = "233637DE"
)

Common receiver app IDs.

Variables

View Source
var (
	ErrReceiverNotReady = errors.New("receiver not ready")
	ErrInvalidMedia     = errors.New("invalid media")
)

Errors used by the Sender.

Functions

func Discover

func Discover(ctx context.Context) (<-chan *DeviceInfo, error)

Discover returns a channel with DeviceInfo found via mDNS.

Types

type DeviceCapability

type DeviceCapability uint

DeviceCapability represents one of the defined device capabilities.

const (
	None           DeviceCapability = 0
	VideoOut       DeviceCapability = 1 << 0
	VideoIn        DeviceCapability = 1 << 1
	AudioOut       DeviceCapability = 1 << 2
	AudioIn        DeviceCapability = 1 << 3
	DevMode        DeviceCapability = 1 << 4
	MultizoneGroup DeviceCapability = 1 << 5
)

Defined Google Cast device capabilities.

Source: https://github.com/chromium/chromium/blob/master/components/cast_channel/cast_socket.h#L46

func (DeviceCapability) String

func (c DeviceCapability) String() string

String returns the string representation of the device capability.

type DeviceInfo

type DeviceInfo struct {
	UUID  uuid.UUID
	Name  string `json:"name"`
	Model string

	IPv4 net.IP
	IPv6 net.IP
	Port int
	// contains filtered or unexported fields
}

func GetDeviceInfo

func GetDeviceInfo(ip net.IP) (*DeviceInfo, error)

func (*DeviceInfo) Capabilities

func (d *DeviceInfo) Capabilities() []DeviceCapability

Capabilities returns a list of device capabilities.

func (*DeviceInfo) CapableOf

func (d *DeviceInfo) CapableOf(capabilities ...DeviceCapability) bool

CapableOf returns true if the device has all given capabilities.

func (*DeviceInfo) TCPAddr

func (d *DeviceInfo) TCPAddr() *net.TCPAddr

TCPAddr returns IPv4 and Port as net.TCPAddr.

type MediaInformation

type MediaInformation struct {
	ContentID   string        `json:"contentId"`
	ContentType string        `json:"contentType"`
	StreamType  string        `json:"streamType"`
	Metadata    MediaMetadata `json:"metadata,omitempty"`
	Duration    float64       `json:"duration,omitempty"`
}

MediaInformation represents a media stream.

Ref: https://developers.google.com/cast/docs/reference/messages#MediaInformation

type MediaMetadata

type MediaMetadata map[string]interface{}

MediaMetadata represents a generic media artifact.

Ref: https://developers.google.com/cast/docs/reference/messages#GenericMediaMetadata

https://developers.google.com/cast/docs/reference/messages#Image

func (MediaMetadata) ImageURL

func (m MediaMetadata) ImageURL() *url.URL

ImageURL returns the URL of the image.

func (MediaMetadata) Subtitle

func (m MediaMetadata) Subtitle() string

Subtitle returns the descriptive subtitle of the content.

func (MediaMetadata) Title

func (m MediaMetadata) Title() string

Title returns the descriptive title of the content.

type MediaSession

type MediaSession struct {
	MediaSessionID         int               `json:"mediaSessionId"`
	Media                  *MediaInformation `json:"media,omitempty"`
	PlaybackRate           float32           `json:"playbackRate"`
	PlayerState            string            `json:"playerState"`
	IdleReason             string            `json:"idleReason,omitempty"`
	CurrentTime            float64           `json:"currentTime"`
	SupportedMediaCommands int               `json:"supportedMediaCommands"`
}

MediaSession represents the current status of a single session.

type MediaStatus

type MediaStatus struct {
	Status []*MediaSession `json:"status"`
}

MediaStatus represents the current status of the media artifact with respect to the session.

https://developers.google.com/cast/docs/reference/messages#MediaStatus

type Receiver

type Receiver struct {
	*DeviceInfo
	// contains filtered or unexported fields
}

Receiver represents a Google Cast device.

func (*Receiver) Application

func (r *Receiver) Application() *ReceiverApplication

Application returns the current running receiver application, if any.

func (*Receiver) Close

func (r *Receiver) Close() error

Close closes the connection to the receiver.

func (*Receiver) Connect

func (r *Receiver) Connect() error

Connect makes a connection to the receiver.

func (*Receiver) IsConnected

func (r *Receiver) IsConnected() bool

IsConnected returns true if there is an active connection to the receiver device.

func (*Receiver) Launch

func (r *Receiver) Launch(appID string) error

Launch starts an new receiver application.

func (*Receiver) Load

func (r *Receiver) Load(senderID string, media *MediaInformation) error

Load loads new content into the media player.

Ref: https://developers.google.com/cast/docs/reference/messages#Load

func (*Receiver) Pause

func (r *Receiver) Pause(senderID string, mediaSessionID int) error

Pause pauses playback of the current content.

https://developers.google.com/cast/docs/reference/messages#Pause

func (*Receiver) Play

func (r *Receiver) Play(senderID string, mediaSessionID int) error

Play begins playback of the loaded media content from the current playback position.

https://developers.google.com/cast/docs/reference/messages#Play

func (*Receiver) Seek

func (r *Receiver) Seek(senderID string, mediaSessionID int, pos float64) error

Seek sets the current playback position to pos, which is the number of seconds since beginning of content

func (*Receiver) Session

func (r *Receiver) Session(senderID string) (*MediaSession, time.Time)

GetSession returns the last known status of the media session.

func (*Receiver) SetVolume

func (r *Receiver) SetVolume(vol *ReceiverVolume) error

SetVolume sets the receiver volume.

func (*Receiver) Stop

func (r *Receiver) Stop(senderID string, mediaSessionID int) error

Stop stops the playback and unload the current content

https://developers.google.com/cast/docs/reference/messages#Stop

func (*Receiver) Volume

func (r *Receiver) Volume() *ReceiverVolume

Volume returns the receiver volume, if known.

type ReceiverApplication

type ReceiverApplication struct {
	AppID               string              `json:"appId"`
	Name                string              `json:"displayName"`
	IconURL             string              `json:"iconUrl"`
	StatusText          string              `json:"statusText"`
	IsIdleScreen        bool                `json:"isIdleScreen"`
	SupportedNamespaces []map[string]string `json:"namespaces"`
	SessionID           string              `json:"sessionId"`
	TransportID         string              `json:"transportId"`
}

ReceiverApplication represents an instance of receiver application.

type ReceiverStatus

type ReceiverStatus struct {
	castv2.Header
	Status struct {
		Applications []*ReceiverApplication `json:"applications,omitempty"`
		Volume       *ReceiverVolume        `json:"volume"`
	} `json:"status"`
}

ReceiverStatus represents the devices status of the receiver.

type ReceiverVolume

type ReceiverVolume struct {
	ControlType  string  `json:"controlType,omitempty"`
	Level        float64 `json:"level,omitempty"`
	Muted        bool    `json:"muted,omitempty"`
	StepInterval float64 `json:"stepInterval,omitempty"`
}

ReceiverVolume represents the volume of the receiver device.

type Sender

type Sender struct {
	ID string
	// contains filtered or unexported fields
}

A Sender is a sender app instance that controls media playback on the receiver. Its ID, which should be unique, is used to identify itself when communicating with the receiver.

func Find

func Find(hints ...string) (*Sender, error)

Find returns a Sender for the first device found with matching hints.

func NewSender

func NewSender(id string, dev *DeviceInfo) (*Sender, error)

NewSender returns a new Sender and connects to the device.

func (*Sender) Close

func (s *Sender) Close() error

Close closes the connected receiver, if any.

func (*Sender) IsBuffering

func (s *Sender) IsBuffering() bool

IsBuffering returns true if playback is effectively paused due to buffer underflow.

func (*Sender) IsIdle

func (s *Sender) IsIdle() bool

IsIdle returns true if the recevier device does not have an receiver app running or have media playback stopped.

func (*Sender) IsMuted

func (s *Sender) IsMuted() bool

IsMuted returns true if the receiver is muted.

func (*Sender) IsPaused

func (s *Sender) IsPaused() bool

IsPaused returns true if playback is paused due to user request.

func (*Sender) IsPlaying

func (s *Sender) IsPlaying() bool

IsPlaying returns true if the recevier is actively playing content.

func (*Sender) Load

func (s *Sender) Load(mediaURL *url.URL, mediaMetadata omnicast.MediaMetadata) error

Load casts media to the receiver and starts playback.

func (*Sender) MediaDuration

func (s *Sender) MediaDuration() time.Duration

MediaDuration returns the duration of current loaded media.

func (*Sender) MediaMetadata

func (s *Sender) MediaMetadata() omnicast.MediaMetadata

MediaMetadata returns the metadata of current loaded media.

func (*Sender) MediaURL

func (s *Sender) MediaURL() *url.URL

MediaURL returns the URL of current loaded media.

func (*Sender) Mute

func (s *Sender) Mute()

Mute mutes the receiver.

func (*Sender) Name

func (s *Sender) Name() string

func (*Sender) Pause

func (s *Sender) Pause()

Pause pauses playback of the current content.

func (*Sender) Play

func (s *Sender) Play()

Play begins playback of the loaded media content from the current playback position.

func (*Sender) PlaybackPosition

func (s *Sender) PlaybackPosition() time.Duration

PlaybackPosition returns the current position of media playback from the beginning of media content. For live streams, it returns the time since playback started.

func (*Sender) PlaybackRate

func (s *Sender) PlaybackRate() float32

PlaybackRate returns the ratio of speed that media is played at.

func (*Sender) PlayerState

func (s *Sender) PlayerState() string

PlayerState return the current playback state.

func (*Sender) SeekTo

func (s *Sender) SeekTo(pos time.Duration)

SeekTo sets the current playback position to pos,

func (*Sender) SetVolumeLevel

func (s *Sender) SetVolumeLevel(level float64)

SetVolumeLevel sets receiver volume level.

func (*Sender) Stop

func (s *Sender) Stop()

Stop stops the playback and unload the current content

func (*Sender) Unmute

func (s *Sender) Unmute()

Unmute unmutes the receiver.

func (*Sender) VolumeLevel

func (s *Sender) VolumeLevel() float64

VolumeLevel returns receiver volume as a number between 0.0 and 1.0.

Directories

Path Synopsis
internal
castv2
Package castv2 provides a low-level implementation of Google Cast V2 protocol.
Package castv2 provides a low-level implementation of Google Cast V2 protocol.

Jump to

Keyboard shortcuts

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