Class: ActionMerge::SyncChannel
- Inherits:
-
ActionCable::Channel::Base
- Object
- ActionCable::Channel::Base
- ActionMerge::SyncChannel
- Defined in:
- app/channels/action_merge/sync_channel.rb
Instance Method Summary collapse
Instance Method Details
#perform_action(data) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'app/channels/action_merge/sync_channel.rb', line 20 def perform_action(data) data.deep_symbolize_keys! if data.dig(:targetId).presence self.class.broadcast_to(@@peers[data[:targetId]], data) else @@peers.each do |id, peer| self.class.broadcast_to(peer, data) unless id == @peer&.to_gid_param end end end |
#subscribed ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/channels/action_merge/sync_channel.rb', line 8 def subscribed @model = ActiveSupport::Inflector.constantize(params[:syncable_type]).find(params[:syncable_id]) reject unless @model.(self) @peer = ActionMerge::Peer.new(params[:id], storageId: params.dig(:metadata, :storageId), isEphemeral: params.dig(:metadata, :isEphemeral), model: @model) @@peers[@peer.to_gid_param] = @peer stream_for @peer end |
#unsubscribed ⇒ Object
31 32 33 34 |
# File 'app/channels/action_merge/sync_channel.rb', line 31 def unsubscribed @@peers[@peer&.to_gid_param] = nil @peer = nil end |