Hunter.Streaming.Event (hunter v0.8.0)

Copy Markdown View Source

A parsed event from Mastodon's streaming WebSocket

Fields

  • streams - the stream names this event was delivered on
  • type - the event type, e.g. "update", "notification", "delete"
  • payload - the decoded payload: an entity struct for known types, the bare id string for delete/announcement.delete, nil for payload-less events, or the raw payload for unknown types

Summary

Functions

Parses a raw WebSocket text frame into an event.

Types

t()

@type t() :: %Hunter.Streaming.Event{
  payload: term(),
  streams: [String.t()],
  type: String.t()
}

Functions

parse(frame)

@spec parse(binary()) :: {:ok, t()} | {:error, term()}

Parses a raw WebSocket text frame into an event.

Mastodon frames look like {"stream": ["user"], "event": "update", "payload": "<JSON string>"} — the payload is itself JSON-encoded, except for delete (a bare id) and payload-less events. Unknown event types are passed through with the raw payload so new server-side types keep flowing.