Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

faye

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

faye

Simple pub/sub messaging for the web

  • 1.4.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
556K
increased by7.48%
Maintainers
1
Weekly downloads
 
Created

What is faye?

Faye is a publish-subscribe messaging system based on the Bayeux protocol. It is designed to be used in both Node.js and browser environments, allowing for real-time messaging and communication between clients and servers.

What are faye's main functionalities?

Publish-Subscribe Messaging

This code demonstrates how to set up a Faye server and client for publish-subscribe messaging. The server listens on port 8000, and the client subscribes to the '/messages' channel to receive messages. The client also publishes a message to the same channel.

const faye = require('faye');

// Create a new Faye server
const server = new faye.NodeAdapter({mount: '/faye', timeout: 45});

// Start the server
server.listen(8000);

// Create a client
const client = new faye.Client('http://localhost:8000/faye');

// Subscribe to a channel
client.subscribe('/messages', function(message) {
  console.log('Received message:', message);
});

// Publish a message to the channel
client.publish('/messages', {text: 'Hello, world!'});

Client-Server Communication

This code demonstrates client-server communication using Faye. The server is set up to listen on port 8000, and the client subscribes to the '/chat' channel to handle incoming messages. The client also publishes a message to the '/chat' channel.

const faye = require('faye');

// Create a new Faye server
const server = new faye.NodeAdapter({mount: '/faye', timeout: 45});

// Start the server
server.listen(8000);

// Create a client
const client = new faye.Client('http://localhost:8000/faye');

// Define a function to handle incoming messages
function handleMessage(message) {
  console.log('Received message:', message);
}

// Subscribe to a channel
client.subscribe('/chat', handleMessage);

// Publish a message to the channel
client.publish('/chat', {user: 'Alice', text: 'Hi there!'});

Browser Integration

This code demonstrates how to integrate Faye with a browser environment. It includes the Faye browser script and sets up a client that subscribes to the '/notifications' channel to receive messages. The client also publishes a message to the same channel.

<script src="https://cdn.jsdelivr.net/npm/faye/browser/faye-browser-min.js"></script>
<script>
  // Create a client
  var client = new Faye.Client('http://localhost:8000/faye');

  // Subscribe to a channel
  client.subscribe('/notifications', function(message) {
    console.log('Received notification:', message);
  });

  // Publish a message to the channel
  client.publish('/notifications', {title: 'New Notification', body: 'You have a new message!'});
</script>

Other packages similar to faye

Keywords

FAQs

Package last updated on 31 Jul 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc