Mooncore.Endpoint.Socket.Handler (mooncore v0.2.5)

Copy Markdown

WebSocket connection handler.

Manages WebSocket connections: authentication, channel subscriptions, message routing, and binary protocol support.

Connection Flow

  1. Client connects to /ws — upgrade via WebSockAdapter
  2. Handler.init/1 — sets up state, subscribes to user channels if authed
  3. Client sends messages — text (JSON) or binary (metadata + payload)
  4. Handler routes to action pipeline or handles control messages

Special Messages

  • "ping""pong"
  • "time" → server timestamp
  • "channel_list" → list of subscribed channels
  • "quit" → close connection
  • ["jwt", token] → authenticate and subscribe to channels
  • ["join", channel] → subscribe to channel (requires role)
  • ["leave", channel] → unsubscribe from channel
  • Any JSON object with "action" key → dispatched to action pipeline

Summary

Functions

handle_in(arg, state)

handle_info(arg, state)

handle_map(message, state)

init(list)

terminate(reason, state)