AgentSkillsCN

realtime

通过Action Cable与Trailblazer Operations实现实时通信模式。在构建WebSocket通道、广播更新,或处理实时功能时,可选用此方法。内容涵盖频道组织、权限控制、消息传递模式,以及操作的广播机制。

SKILL.md
--- frontmatter
name: realtime
description: Real-time communication patterns with Action Cable and Trailblazer Operations. Use when implementing WebSocket channels, broadcasting updates, or handling real-time features. Covers channel organization, authorization, messaging patterns, and operation broadcasting.

Realtime (Action Cable + Trailblazer 2.1)

Dependencies

  • actioncable
  • trailblazer-operation
  • trailblazer-rails

Channels Organization (Pattern)

  • app/channels/ hosts channel classes
  • One channel per domain concept (game/room)
  • Authorization happens in subscribed
  • Use stream_for with domain instances
  • Keep channels thin and delegate logic to Operations

Messages (Pattern)

  • JSON payloads with type and small deltas
  • Include timestamps in broadcasts

Operations Broadcasting (Pattern)

  • Broadcast inside Operations after successful state changes
  • Example: Game::BroadcastChannel.broadcast_to(game, { type: 'player_moved', ... })

See Channels for requirements.