Module: YrbLite::ActionCable::Sync::ClassMethods
- Defined in:
- lib/yrb_lite/action_cable/sync.rb
Instance Method Summary collapse
-
#max_frame_bytes(bytes = :__unset__) ⇒ Object
Maximum size, in decoded bytes, of an incoming document/awareness frame.
-
#on_change(&block) ⇒ Object
Record every document change durably before it is applied or distributed.
-
#on_load(&block) ⇒ Object
Load persisted document state.
Instance Method Details
#max_frame_bytes(bytes = :__unset__) ⇒ Object
Maximum size, in decoded bytes, of an incoming document/awareness frame. Oversized frames are dropped before base64 decode and before native parsing, so a client can’t force huge allocations/CPU (a DoS vector). Defaults to DEFAULT_MAX_FRAME_BYTES; set to nil to disable the cap.
91 92 93 94 95 96 |
# File 'lib/yrb_lite/action_cable/sync.rb', line 91 def max_frame_bytes(bytes = :__unset__) @max_frame_bytes = bytes unless bytes == :__unset__ return @max_frame_bytes if defined?(@max_frame_bytes) superclass.respond_to?(:max_frame_bytes) ? superclass.max_frame_bytes : DEFAULT_MAX_FRAME_BYTES end |
#on_change(&block) ⇒ Object
Record every document change durably before it is applied or distributed. Called synchronously with (key, update), where update is the exact CRDT delta. If the block raises, the change is rejected: neither acknowledged nor broadcast to other subscribers.
The block runs in the *channel instance’s* context (via instance_exec), so it can call the channel’s own methods (current_user, params, a per-connection Current.* accessor) directly, with no thread-local plumbing. on_change always fires from within sync_receive.
80 81 82 83 84 85 |
# File 'lib/yrb_lite/action_cable/sync.rb', line 80 def on_change(&block) @on_change = block if block return @on_change if defined?(@on_change) && @on_change superclass.respond_to?(:on_change) ? superclass.on_change : nil end |
#on_load(&block) ⇒ Object
Load persisted document state. Called once per key with (key); return a binary Y.js update (or nil for a fresh document). The block runs in the channel instance’s context, the same as on_change (see below).
64 65 66 67 68 69 |
# File 'lib/yrb_lite/action_cable/sync.rb', line 64 def on_load(&block) @on_load = block if block return @on_load if defined?(@on_load) && @on_load superclass.respond_to?(:on_load) ? superclass.on_load : nil end |