Class: Mbeditor::CollaborationChannel
- Inherits:
-
Object
- Object
- Mbeditor::CollaborationChannel
show all
- Includes:
- ChannelAuthentication
- Defined in:
- app/channels/mbeditor/collaboration_channel.rb
Overview
Per-file relay edge for realtime collaborative editing. The channel never
interprets the opaque Yjs bytes it carries — it persists them through
CollaborationDocStore and relays them to the other subscribers on a stream
keyed by a digest of the workspace-relative path. It degrades gracefully
when ActionCable is absent, matching the EditorChannel conditional-base
pattern.
Constant Summary
collapse
- STREAM_PREFIX =
"mbeditor_collab"
Mbeditor::ChannelAuthentication::LOG_THROTTLE_SECONDS
Instance Method Summary
collapse
last_logged, #mbeditor_auth_hook, #mbeditor_authenticated?, #mbeditor_log_denial
Instance Method Details
#awareness(data) ⇒ Object
50
51
52
53
54
55
|
# File 'app/channels/mbeditor/collaboration_channel.rb', line 50
def awareness(data)
bytes = data["awareness"]
return if bytes.nil?
relay("type" => "awareness", "awareness" => bytes)
end
|
#doc_update(data) ⇒ Object
34
35
36
37
38
39
40
|
# File 'app/channels/mbeditor/collaboration_channel.rb', line 34
def doc_update(data)
bytes = data["update"]
return if bytes.nil?
CollaborationDocStore.record_update(room_key, bytes)
relay("type" => "doc_update", "update" => bytes)
end
|
#snapshot(data) ⇒ Object
42
43
44
45
46
47
48
|
# File 'app/channels/mbeditor/collaboration_channel.rb', line 42
def snapshot(data)
bytes = data["snapshot"]
return if bytes.nil?
CollaborationDocStore.replace_snapshot(room_key, bytes)
relay("type" => "snapshot", "snapshot" => bytes)
end
|
#subscribed ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
|
# File 'app/channels/mbeditor/collaboration_channel.rb', line 17
def subscribed
return unless mbeditor_authenticated?
@path = params[:path].to_s
return reject if @path.empty? && respond_to?(:reject, true)
stream_from stream_name if respond_to?(:stream_from)
CollaborationDocStore.join(room_key)
@joined = true
transmit_initial_state
end
|
#unsubscribed ⇒ Object
29
30
31
32
|
# File 'app/channels/mbeditor/collaboration_channel.rb', line 29
def unsubscribed
CollaborationDocStore.leave(room_key) if @joined
@joined = false
end
|