How to use faye - 10 common examples

To help you get started, we’ve selected a few faye examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github opitzconsulting / phonegap-proxy / server.js View on Github external
// ------------------
// Setup
// ------------------
var express = require('express');
var app = express();
var http = require('http');
var faye = require('faye');

app.use(express.static(__dirname));

var server = http.createServer(app);
var bayeux = new faye.NodeAdapter({mount: '/faye', timeout: 45});
bayeux.attach(server);



var port = 9000;
server.listen(port);
console.log("listening on port "+port);
github Jonovono / spotluck / lib / server.js View on Github external
var http = require('http'),
    faye = require('faye');

var redis = require("redis"),
    client = redis.createClient();

client.on("error", function(err) {
  console.log("Error " + err);
});

var bayeux = new faye.NodeAdapter({mount: '/faye', timeout: 45});

function sendUpdate(channel, num) {
  console.log('Sending update ' + channel + ' of num ' + num);
  var ev = {}
  ev.event = 'stat';
  ev.count = parseInt(num);
  bayeux.getClient().publish(channel, ev)
}

// Handle non-Bayeux requests
var server = http.createServer(function(request, response) {
  response.writeHead(200, {'Content-Type': 'text/plain'});
  response.end('Hello, non-Bayeux request');
});

bayeux.on('subscribe', function(clientId, channel) {
github GMOD / jbrowse / node / add-track-json.js View on Github external
}
	    trackListJson.tracks = newTracks
	})

	// write the new track list
	var trackListOutputData = JSON.stringify (trackListJson, null, 2)
	if (opt.options.stdout) {
	    process.stdout.write (trackListOutputData + "\n")
	} else {
	    fs.writeFileSync (trackListPath, trackListOutputData)
	}

	// publish notifications
	var publishUrl = opt.options['notify']
	if (publishUrl) {
	    var client = new faye.Client (publishUrl)
	    var secret = opt.options['secret']
	    if (secret)
		client.addExtension({
		    outgoing: function(message, callback) {
			message.ext = message.ext || {};
			message.ext.password = secret;
			callback(message);
		    }
		});

	    if (logging)
		client.addExtension({
		    outgoing: function(message, callback) {
			console.log ('client outgoing', message);
			callback(message);
		    }
github GMOD / jbrowse / node / message-server.js View on Github external
])              // create Getopt instance
.bindHelp()     // bind option 'help' to default action
.parseSystem(); // parse command line

var serverPath = opt.options['root'] || '/faye';
var serverPort = opt.options['port'] || 8000;
var serverTimeout = opt.options['timeout'] || 45;
var logging = opt.options['messages'];

if (serverPath[0] != '/') {
    serverPath = '/' + serverPath
}

// Start faye server
var server = http.createServer(),
    bayeux = new faye.NodeAdapter({mount: serverPath, timeout: serverTimeout});

var secret = opt.options['secret']
if (secret)
    bayeux.addExtension({
	incoming: function(message, callback) {
	    if (message.channel.match(/^\/(tracks|alert|log)/)) {
		var password = message.ext && message.ext.password;
		if (password !== secret)
		    message.error = '403::Password required';
	    }
	    callback(message);
	},

	outgoing: function(message, callback) {
	    if (message.ext)
		delete message.ext.password;
github nodeca / nodeca.core / lib / autoload / hooks / init / faye.js View on Github external
function initFaye() {
    // Parse redis url
    let redisConfig = redisUrl.parse((N.config.database || {}).redis);

    // Init adapter
    let bayeux = new faye.NodeAdapter({
      mount: '/io/live',
      timeout: 10000,
      ping: 25000,
      engine: {
        type: fayeRedis,
        host: redisConfig.hostname,
        port: redisConfig.port,
        password: redisConfig.password,
        database: redisConfig.database,
        namespace: 'nodeca'
      }
    });

    // Add WebSocket server
    bayeux.addWebsocketExtension(deflate);
github BBGInnovate / Sports-Data-Application-Suite / sportsfayserver / server.js View on Github external
/** 
 * @fileOverview 	I am the Faye Messaging Server.
 * @author 			John Allen 
 * @version 		1.0.0
 * @module 			server.js
 */

/* *************************** Required Classes **************************** */
var http = require('http');
var https = require('https');
var faye = require('faye');
var fs = require('fs');

/* *************************** Constructor Code **************************** */
var bayeux = new faye.NodeAdapter({mount: '/faye', timeout: 45});

var secret = '78654323MyVeryL0ngStr1ngTh4tIsC00l4ndYouC4ntT0uchThi5IfY0uTry9907654';

// by default we will ALWAYS run under SSL
var runUnderSSL = false;

// if in dev (local) start the server this way: node server.js false
if (process.argv[2] !== undefined && process.argv[2] === 'false'){
	runUnderSSL = false;
}

// launch using SSL...
if( runUnderSSL ){

	var options = {
	  key: fs.readFileSync('/etc/apache2/SSL/soccer-epl-home.voanews.com.key'),
github logv / snorkel / snorkel / node_modules / superfluous / node_modules / primus.io / node_modules / primus / transformers / faye / server.js View on Github external
module.exports = function server() {
  var faye = require('faye')
    , primus = this.primus
    , Spark = this.Spark;

  this.service = new faye.NodeAdapter({
      mount: primus.pathname
    , timeout: 45
  });

  //
  // We've received a new connection, create a new Spark. The Spark will
  // automatically announce it self as a new connection once it's created (after
  // the next tick).
  //
  this.service.on('connection', function connection(socket) {
    var spark = new Spark(
        socket.handshake.headers  // HTTP request headers.
      , socket.handshake.address  // IP address.
      , socket.handshake.query    // Optional query string.
      , socket.id                 // Unique connection id
    );
github BBGInnovate / Sports-Data-Application-Suite / sportsdataprovider / FayeService.js View on Github external
*					with interacting with the Faye Server.
 * @author 			John Allen 
 * @version 		1.0.0
 * @module 			FayeService.js
 */

/* *************************** Required Classes **************************** */
var faye = require('faye');
var Config = require('./Config');
var util = require('util');
var log = require('./Logger.js');

/* *************************** Constructor Code **************************** */
var config = Config.getConfig();

var fayClient = new faye.Client(config.faye.url);

// we need to send the password to the server so lets add an extension to do
// this.
fayClient.addExtension({
	outgoing: function( message, callback ) {

		message.ext = message.ext || {};
		message.ext.password = config.faye.publishPassword;

		callback( message );
	}
});


/* *************************** Public Methods ****************************** */
/**
github jsforce / jsforce / lib / api / streaming.js View on Github external
Streaming.prototype._createClient = function(forChannelName, extensions) {
  // forChannelName is advisory, for an API workaround. It does not restrict or select the channel.
  var needsReplayFix = typeof forChannelName === 'string' && forChannelName.indexOf('/u/') === 0;
  var endpointUrl = [
    this._conn.instanceUrl,
    // special endpoint "/cometd/replay/xx.x" is only available in 36.0.
    // See https://releasenotes.docs.salesforce.com/en-us/summer16/release-notes/rn_api_streaming_classic_replay.htm
    "cometd" + (needsReplayFix === true && this._conn.version === "36.0" ? "/replay" : ""),
    this._conn.version
  ].join('/');
  var fayeClient = new Faye.Client(endpointUrl, {});
  fayeClient.setHeader('Authorization', 'OAuth '+this._conn.accessToken);
  if (extensions instanceof Array) {
    extensions.forEach(function(extension) {
      fayeClient.addExtension(extension);
    });
  }
  if (fayeClient._dispatcher.getConnectionTypes().indexOf('callback-polling') === -1) {
    // prevent streaming API server error
    fayeClient._dispatcher.selectTransport('long-polling');
    fayeClient._dispatcher._transport.batching = false;
  }
  return fayeClient;
};
github fontello / fontello / lib / init / server / realtime.js View on Github external
module.exports.attach = function attach(server, next) {
  var faye = new Faye.NodeAdapter({ mount: '/faye' });

  if (process.env.FAYE_LOGLEVEL) {
    // This produces lots of logs, which are usefull
    // only during development of RT things.
    // USAGE: FAYE_LOGLEVEL=info ./fontello.js server
    Faye.Logging.logLevel = process.env.FAYE_LOGLEVEL;
  }

  // FIXME: Replace dummy active_clients inc/dec with real heartbeat/timeouts
  faye.bind('handshake',  function () { module.exports.activeClients++; });
  faye.bind('disconnect', function () { module.exports.activeClients--; });

  var curr_users_count = 0;
  setInterval(function () {
    if (module.exports.activeClients !== curr_users_count) {
      curr_users_count = module.exports.activeClients;
      faye.getClient().publish('/stats/users_online', curr_users_count);
    }
  }, 10000);

  faye.attach(server);
  next();

faye

Simple pub/sub messaging for the web

Apache-2.0
Latest version published 4 years ago

Package Health Score

64 / 100
Full package analysis