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.
-
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.
-
The broadcasted data is finally caught by the received function of app/javascripts/channels/concurrent_editing.js
-
Finally the received function calls the synchronizeData function to update all the fresh data on the map.
-
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.
-
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