Skip to content

Instantly share code, notes, and snippets.

@Xsmael
Last active November 4, 2019 12:03
Show Gist options
  • Save Xsmael/4bcd3fe1599011b2094a19e0e1faf2f7 to your computer and use it in GitHub Desktop.
Save Xsmael/4bcd3fe1599011b2094a19e0e1faf2f7 to your computer and use it in GitHub Desktop.
angular-faye tutorial example
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