Documentation
¶
Overview ¶
Package protocol defines the wire protocol for GopherCast audio streaming. Control messages are sent as JSON WebSocket TextMessages, while audio data is sent as binary WebSocket BinaryMessages with a 12-byte header.
Index ¶
Constants ¶
const AudioFrameHeaderSize = 12
AudioFrameHeaderSize is 12 bytes: 4B seq + 8B sample offset.
Variables ¶
This section is empty.
Functions ¶
func MarshalEnvelope ¶
func MarshalEnvelope(msgType MessageType, data any) ([]byte, error)
Types ¶
type AudioFrame ¶
func UnmarshalAudioFrame ¶
func UnmarshalAudioFrame(data []byte) (*AudioFrame, error)
func (*AudioFrame) MarshalBinary ¶
func (f *AudioFrame) MarshalBinary() []byte
type ClientInfo ¶
type ClientListMsg ¶
type ClientListMsg struct {
Clients []ClientInfo `json:"clients"`
}
ClientListMsg is broadcast from server to all clients when the client list changes.
type Envelope ¶
type Envelope struct {
Type MessageType `json:"type"`
Data json.RawMessage `json:"data"`
}
Envelope is the outer wrapper for all control messages.
func ParseEnvelope ¶
type HelloMsg ¶
type HelloMsg struct {
Name string `json:"name"`
AudioLatencyNs int64 `json:"audio_latency_ns,omitempty"`
}
HelloMsg is sent by the client immediately after connecting.
type MessageType ¶
type MessageType string
MessageType identifies the type of a control message.
const ( MsgHello MessageType = "hello" MsgServerState MessageType = "server_state" MsgClientList MessageType = "client_list" MsgStartPlayback MessageType = "start_playback" MsgStopPlayback MessageType = "stop_playback" MsgTrackChange MessageType = "track_change" MsgReject MessageType = "reject" )
type RejectMsg ¶
type RejectMsg struct {
Reason string `json:"reason"`
}
RejectMsg is sent from server to a client to reject a late connection.
type ServerState ¶
type ServerState string
const ( StateLobby ServerState = "lobby" StatePlaying ServerState = "playing" StateStopped ServerState = "stopped" )
type ServerStateMsg ¶
type ServerStateMsg struct {
State ServerState `json:"state"`
}
type StartPlaybackMsg ¶
type StartPlaybackMsg struct {
TrackTitle string `json:"track_title"`
SampleRate int `json:"sample_rate"`
Channels int `json:"channels"`
StartAtNs int64 `json:"start_at_ns"`
}
StartPlaybackMsg is sent from server to all clients to begin playback.
type StopPlaybackMsg ¶
type StopPlaybackMsg struct {
Reason string `json:"reason"`
}
StopPlaybackMsg is sent from server to all clients to stop playback.