Created
March 29, 2015 01:12
-
-
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
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
// 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