Skip to content

Commit

Permalink
separate editing channels for different maps
Browse files Browse the repository at this point in the history
  • Loading branch information
ViditChitkara committed Aug 21, 2019
1 parent c52a65b commit 8470929
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions app/assets/javascripts/channels/concurrent_editing.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
/* Handles all the frontend interactions with action cable and the server. */

App.concurrent_editing = App.cable.subscriptions.create("ConcurrentEditingChannel", {
App.concurrent_editing = App.cable.subscriptions.create(
{
channel: "ConcurrentEditingChannel",
mapSlug: window.location.href.split("/").pop()
}, {
connected: function() {
// Called when the subscription is ready for use on the server
},
Expand All @@ -20,7 +24,8 @@ App.concurrent_editing = App.cable.subscriptions.create("ConcurrentEditingChanne
* which is responsible for broadcasting the updated warpables
* to all the user's connected to the concurrent_editing channel. */
return this.perform("sync", {
changes: changes
changes: changes,
map_slug: window.location.href.split("/").pop()
});
}
});
4 changes: 2 additions & 2 deletions app/channels/concurrent_editing_channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class ConcurrentEditingChannel < ApplicationCable::Channel

def subscribed
# Called first to connect user to the channel.
stream_from "concurrent_editing_channel"
stream_from "concurrent_editing_channel:#{params[:mapSlug]}"
end

def unsubscribed
Expand All @@ -12,6 +12,6 @@ def unsubscribed

def sync(changes)
# Responsible for broadcasting the updated warpables or simply images to the user's connected on this channel.
ActionCable.server.broadcast 'concurrent_editing_channel', changes
ActionCable.server.broadcast "concurrent_editing_channel:#{changes["map_slug"]}", changes
end
end

0 comments on commit 8470929

Please sign in to comment.