Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save karimbutt/f2130da868e58c4ffc43 to your computer and use it in GitHub Desktop.
Save karimbutt/f2130da868e58c4ffc43 to your computer and use it in GitHub Desktop.
Shows how to send a message to a channel on your Angular frontend from anywhere in your Rails app
// ANGULAR: Listen/bind to a channel on the angular side in the Angular controller
$scope.dispatcher = new WebSocketRails(ROUTE_IN_RAILS_FOR_WS);
var channel = $scope.dispatcher.subscribe('motion_detector');
channel.bind('status', function(response) {
$scope.motionDetectorStatus = response.status
});
# RAILS: Send a message to a channel on the Rails side. You can do this from anywhere in your Rails app
WebsocketRails[:motion_detector].trigger 'status', {status: "No motion currently detected"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment