Documentation
¶
Overview ¶
Package channels implements the upstream Phoenix Channels V2 wire protocol served at /appengine/v1/socket/websocket. It is the compatibility counterpart to the Astrate-native socket in internal/appengine/stream.
Index ¶
Constants ¶
const ( EventPhxJoin = "phx_join" EventPhxReply = "phx_reply" EventPhxLeave = "phx_leave" EventPhxClose = "phx_close" EventPhxError = "phx_error" EventHeartbeat = "heartbeat" // TopicHeartbeat is the reserved topic for heartbeat messages. TopicHeartbeat = "phoenix" )
Event-name constants used by the Phoenix V2 protocol.
const ( EventWatch = "watch" EventUnwatch = "unwatch" EventNewEvent = "new_event" )
Event-name constants for the watch/unwatch/new_event cycle.
const DefaultMailbox = 64
DefaultMailbox is the mailbox capacity used when AddMember is given a non-positive buffer.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
API serves the Phoenix V2 WebSocket endpoint.
type Bus ¶
type Bus interface {
Subscribe(realm string, f stream.Filter, buffer int) (<-chan stream.Event, func())
}
Bus is the subset of *stream.Bus a room needs. *stream.Bus satisfies it.
type Frame ¶
Frame is one Phoenix V2 message on the wire, encoded as a five-element JSON array: [join_ref, ref, topic, event, payload]. A nil JoinRef or Ref is marshalled as JSON null; the two are distinguished from the empty string.
func Err ¶
Err is a convenience wrapper over Reply that sends an "error" status with a reason field.
func Reply ¶
Reply builds a phx_reply answer to in. The JoinRef and Ref are echoed from in so the client can route the reply to its caller. The payload is {"status":"<status>","response":<response>}. A nil response renders as {}.
func (Frame) MarshalJSON ¶
MarshalJSON renders the frame as a five-element JSON array. A nil JoinRef or Ref becomes JSON null. A nil or zero-length Payload becomes {}.
func (*Frame) UnmarshalJSON ¶
UnmarshalJSON parses a five-element JSON array back into the frame. It rejects anything that is not a JSON array of exactly five elements.
type Member ¶
type Member struct {
// contains filtered or unexported fields
}
Member is a joined socket with its own mailbox.
func (*Member) Dropped ¶
Dropped reports how many envelopes were discarded because the mailbox was full.
func (*Member) Events ¶
func (m *Member) Events() <-chan triggers.SimpleEvent
Events returns the mailbox channel.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is a topic→room map.
type Room ¶
type Room struct {
// contains filtered or unexported fields
}
Room is one Phoenix topic.
func (*Room) AddMember ¶
AddMember registers a member with a mailbox of the given capacity. A non-positive buffer selects DefaultMailbox.
func (*Room) Watch ¶
func (rm *Room) Watch(req WatchRequest) error
Watch compiles and stores a watch.
type WatchRequest ¶
type WatchRequest struct {
Name string `json:"name"`
DeviceID string `json:"device_id"`
GroupName string `json:"group_name"`
SimpleTrigger json.RawMessage `json:"simple_trigger"`
}
WatchRequest is the watch payload DTO, exactly as the client sends it.
GroupName is a top-level field, measured against upstream (channels.json, 2026-08-22): a group_name nested inside simple_trigger is refused by upstream's changeset, and one at the top level is what its authorization path is built from. Astrate used to read it only from simple_trigger, which meant an upstream-shaped group watch silently degraded into a device-shaped path check.