Class: LooseLeaf::CollaborationChannel
- Inherits:
-
ApplicationCable::Channel
- Object
- ApplicationCable::Channel
- LooseLeaf::CollaborationChannel
- Defined in:
- app/channels/loose_leaf/collaboration_channel.rb
Overview
An ActionCable channel for TLooseLeaf
Instance Attribute Summary collapse
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
Instance Method Summary collapse
-
#document(data) ⇒ Object
Subscribe to changes to a document.
- #operation(data) ⇒ Object
- #subscribed ⇒ Object
Instance Attribute Details
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
4 5 6 |
# File 'app/channels/loose_leaf/collaboration_channel.rb', line 4 def client_id @client_id end |
Instance Method Details
#document(data) ⇒ Object
Subscribe to changes to a document
13 14 15 16 17 18 19 20 21 22 |
# File 'app/channels/loose_leaf/collaboration_channel.rb', line 13 def document(data) document = collaborative_model.find_by_collaborative_key(data['id']) @documents ||= [] @documents << document send_attribute_versions(document) stream_from "loose_leaf.documents.#{document.id}.operations" end |
#operation(data) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/channels/loose_leaf/collaboration_channel.rb', line 24 def operation(data) data = ActiveSupport::HashWithIndifferentAccess.new(data) document = collaborative_model.find_by_collaborative_key(data[:document_id]) version, operation = document.apply_operation(data) data[:sent_version] = data[:version] data[:version] = version data[:operation] = operation.to_a ActionCable.server.broadcast "loose_leaf.documents.#{document.id}.operations", data end |
#subscribed ⇒ Object
6 7 8 9 10 |
# File 'app/channels/loose_leaf/collaboration_channel.rb', line 6 def subscribed @client_id = SecureRandom.uuid transmit action: 'subscribed', client_id: client_id end |