-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP action cable setup * basic action cable setup complete * minor change * minor changes * few changes * initial working functionality complete * Refactoring code * Adding Foreman gem * Scheduling Puma and Passenger servers * WIP action cable setup * basic action cable setup complete * minor change * minor changes * few changes * initial working functionality complete * Refactoring code * Adding Foreman gem * Scheduling Puma and Passenger servers * few minor fix * added a few tests * Refactoring connection module * Using strong params in requests * added documentation * added more docs * added tests * Using puma as dependency and correct image controller * added a few tests * a few changes * remove unnecessary render * few test fixes
- Loading branch information
1 parent
87e18ee
commit 843a719
Showing
25 changed files
with
299 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
passenger: passenger start | ||
puma: puma -C config/puma.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
The new synchronous editing feature | ||
=================================== | ||
|
||
With the introduction of ActionCable to our system, it has been possible | ||
to do perform real-time tasks quite easily. We have used rail's default | ||
action cable to make a _concurrent_editing_channel.rb_ in the _app/channels_ folder, | ||
to handle all the incoming requests and consists of all the business | ||
logic as well. At the frontend we have, _app/javascripts/channels/concurrent_editing.js_ which | ||
handles the logic at the browser or the frontend. | ||
|
||
## Flow of the feature: | ||
|
||
1. When the map is updated, the _speak_ method of _concurrent_editing.js_ is called which requests | ||
the _sync_ method of _concurrent_editing_channel.rb_ to broadcast the updated data to | ||
the connected users. | ||
|
||
2. The broadcasted data is finally caught by the _received_ function of _app/javascripts/channels/concurrent_editing.js_ | ||
|
||
3. Finally the _received_ function calls the _synchronizeData_ function to update | ||
all the fresh data on the map. | ||
|
||
|
||
## Testing: | ||
|
||
1. The _action-cable-testing_ gem is used for the feature's testing. It has some really | ||
cool testing functionality which was required for our use case. | ||
|
||
2. Currently we have separate tests written for connection related features and channel | ||
specific features. The relevant files are test/channels/concurrent_editing_channel_test.rb and | ||
test/channels/connection_test.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// | ||
//= require action_cable | ||
//= require_self | ||
//= require_tree ./channels | ||
|
||
(function() { | ||
this.App || (this.App = {}); | ||
|
||
App.cable = ActionCable.createConsumer(); | ||
|
||
}).call(this); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* Handles all the frontend interactions with action cable and the server. */ | ||
|
||
App.concurrent_editing = App.cable.subscriptions.create("ConcurrentEditingChannel", { | ||
connected: function() { | ||
// Called when the subscription is ready for use on the server | ||
}, | ||
|
||
disconnected: function() { | ||
// Called when the subscription has been terminated by the server | ||
}, | ||
|
||
received: function(data) { | ||
// Called when there's incoming data on the websocket for this channel | ||
window.mapKnitter.synchronizeData(data.changes); | ||
}, | ||
|
||
speak: function(changes) { | ||
/* Called when an image is updated from Map.js ('saveImage' function). | ||
* This function calls concurrent_editing_channel.rb's 'sync' method | ||
* 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 | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module ApplicationCable | ||
class Channel < ActionCable::Channel::Base | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module ApplicationCable | ||
class Connection < ActionCable::Connection::Base | ||
identified_by :current_user | ||
|
||
def connect | ||
self.current_user = find_verified_user | ||
end | ||
|
||
private | ||
|
||
def find_verified_user | ||
User.find(cookies.signed["user_id"]) | ||
rescue ActiveRecord::RecordNotFound | ||
reject_unauthorized_connection | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class ConcurrentEditingChannel < ApplicationCable::Channel | ||
# This class handles the server side logic of the actioncable communication. | ||
|
||
def subscribed | ||
# Called first to connect user to the channel. | ||
stream_from "concurrent_editing_channel" | ||
end | ||
|
||
def unsubscribed | ||
# Any cleanup needed when channel is unsubscribed | ||
end | ||
|
||
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 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.