Last active
November 4, 2019 12:03
-
-
Save Xsmael/4bcd3fe1599011b2094a19e0e1faf2f7 to your computer and use it in GitHub Desktop.
angular-faye tutorial example
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
var app = angular.module('myapp', ['faye']) | |
app.factory('FayeFactory', function ($faye, $location) { | |
return $faye("http://localhost:8888/" ); | |
}); | |
app.controller("testController", function ($scope, FayeFactory) { | |
// CONNECTIVITY MONITORING: | |
FayeFactory.client.on('transport:down', function () { | |
console.warn('Faye client lost connection to server, unable to publish or receive'); | |
}); | |
FayeFactory.client.on('transport:up', function () { | |
console.info('Faye client connected!'); | |
}); | |
// PUBLISHING: | |
var jsonObj= {name:"Jo"}; | |
FayeFactory.publish('/channel', jsonObj}); | |
// SUBSCRIBING: | |
FayeFactory.subscribe('/another/channel', function (data) { | |
console.log('Data received'); | |
console.log(data); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment