Skip to Content
Naylence Docs are in active development. Share feedback in Discord.
ConceptsListeners

Listeners

Transport listeners are pluggable components that handle network-level ingress connections for nodes. They manage server lifecycle tied to node lifecycle—starting when a node starts and stopping when it stops.

What Listeners Do

Listeners serve as the entry points for external connections to a node:

  • Accept inbound connections over various transports (HTTP, WebSocket, browser channels)
  • Route incoming messages to the node for processing
  • Manage server lifecycle automatically with the node
  • Provide callback grants for reverse connections (allowing parents to connect back to children)

A useful mental model: if a node is like a service, listeners are like the network interfaces that service binds to.

Available Listener Types

Server-Side Listeners (Node.js / Python)

ListenerPurpose
HttpListenerStateless HTTP ingress for envelope delivery
WebSocketListenerPersistent WebSocket connections for node attachment
AgentHttpGatewayListenerSimplified HTTP API for agent RPC and messaging

Browser-Only Listeners (TypeScript)

ListenerPurpose
InPageListenerSame-page communication via EventTarget
BroadcastChannelListenerCross-tab/window communication via BroadcastChannel API

Browser listeners enable fabric communication entirely within the browser, useful for single-page applications where multiple components need to communicate via the fabric protocol.

Configuration

Listeners are configured in the listeners array within a node configuration:

const config = { node: { type: 'Sentinel', listeners: [ { type: 'HttpListener', port: 8000, enabled: true, }, { type: 'WebSocketListener', port: 8000, enabled: true, }, ], // ... other config }, };
config = { "node": { "type": "Sentinel", "listeners": [ { "type": "HttpListener", "port": 8000, "enabled": True, }, { "type": "WebSocketListener", "port": 8000, "enabled": True, }, ], # ... other config }, }

Common Configuration Options

OptionTypeDefaultDescription
typestringrequiredListener type (e.g., HttpListener, WebSocketListener)
hoststring"0.0.0.0"Network interface to bind to
portnumber0Port to listen on (0 = OS-assigned)
enabledbooleantrueWhether the listener is active
authorizerobjectnullOptional per-listener authorization config

The enabled Flag

The enabled property allows you to selectively enable or disable listeners without modifying the configuration structure. This is particularly useful when using pre-built configurations like SENTINEL_CONFIG:

import { SENTINEL_CONFIG } from '@naylence/agent-sdk'; // SENTINEL_CONFIG includes HttpListener, WebSocketListener, and AgentHttpGatewayListener // Each can be enabled/disabled via environment variables: // - FAME_LISTENER_HTTP_ENABLED (default: true) // - FAME_LISTENER_WEBSOCKET_ENABLED (default: true) // - FAME_LISTENER_AGENT_HTTP_GATEWAY_ENABLED (default: false) const sentinel = new Sentinel(SENTINEL_CONFIG);
from naylence.agent import SENTINEL_CONFIG # SENTINEL_CONFIG includes HttpListener, WebSocketListener, and AgentHttpGatewayListener # Each can be enabled/disabled via environment variables: # - FAME_LISTENER_HTTP_ENABLED (default: true) # - FAME_LISTENER_WEBSOCKET_ENABLED (default: true) # - FAME_LISTENER_AGENT_HTTP_GATEWAY_ENABLED (default: false) sentinel = Sentinel(SENTINEL_CONFIG)

Disabled listeners are skipped during node initialization—they consume no resources and open no ports.

Listener Details

HttpListener

The HTTP listener provides a stateless REST-like interface for envelope delivery. It’s useful for:

  • Fire-and-forget message delivery
  • Request-response patterns over HTTP
  • Integration with load balancers and HTTP proxies
  • Environments where WebSocket connections aren’t practical

Endpoints:

  • POST /fame/v1/ingress/upstream — Deliver envelopes to the node

WebSocketListener

The WebSocket listener handles persistent connections for the fabric protocol. It’s the primary transport for:

  • Node attachment (downstream nodes connecting to sentinels)
  • Peer connections between sentinels
  • Long-lived bidirectional communication

Endpoints:

  • GET /fame/v1/attach/ws/downstream — Downstream node attachment
  • GET /fame/v1/attach/ws/peer — Peer sentinel attachment
  • GET /fame/v1/attach/ws/upstream — Upstream (callback) connections

AgentHttpGatewayListener

The Agent HTTP Gateway provides a simplified HTTP API for interacting with agents. It’s designed for external clients that want to invoke agent methods without implementing the full fabric protocol.

Endpoints:

  • POST /fame/v1/gateway/rpc — Synchronous RPC invocations
  • POST /fame/v1/gateway/messages — Asynchronous message delivery
  • GET /fame/v1/gateway/health — Health checks

The Agent HTTP Gateway is disabled by default in SENTINEL_CONFIG. Enable it by setting:

export FAME_LISTENER_AGENT_HTTP_GATEWAY_ENABLED=true

Additional configuration options:

OptionTypeDefaultDescription
basePathstring/fame/v1/gatewayBase path for gateway endpoints
limits.maxMethodLengthnumber256Maximum RPC method name length
limits.maxTargetAddrLengthnumber512Maximum target address length
limits.bodyLimitBytesnumber1048576Maximum request body size (1MB)

InPageListener (Browser)

The in-page listener uses a shared EventTarget for communication between components in the same page. All listeners and connectors with the same channel name share messages.

Configuration:

OptionTypeDefaultDescription
channelNamestring"naylence-fabric"Shared channel identifier
inboxCapacitynumber2048Maximum queued messages

BroadcastChannelListener (Browser)

The broadcast channel listener enables communication across browser tabs and windows using the BroadcastChannel API.

Configuration:

OptionTypeDefaultDescription
channelNamestring"naylence-fabric"Broadcast channel name
inboxCapacitynumber2048Maximum queued messages

How Listeners Work

Lifecycle

  1. Node initialization — Listeners register their routes with the HTTP server (or initialize browser channels)
  2. Node started — Listeners begin accepting connections
  3. Node stopped — Listeners stop accepting new connections and clean up

Pluggable Factory System

Listeners use Naylence’s pluggable factory system. Each listener type has a corresponding factory:

  • HttpListenerFactory → creates HttpListener
  • WebSocketListenerFactory → creates WebSocketListener
  • AgentHttpGatewayListenerFactory → creates AgentHttpGatewayListener
  • etc.

When you specify a listener configuration with a type field, the factory system:

  1. Looks up the registered factory for that type
  2. Calls the factory’s create() method with the configuration
  3. Returns the listener instance

This allows third-party packages to register custom listener types that integrate seamlessly with the configuration system.

Shared HTTP Server

Multiple listeners can share the same HTTP server. When you configure HttpListener and WebSocketListener on the same port, they share a single underlying server with different route prefixes:

listeners: - type: HttpListener port: 8000 # Routes: /fame/v1/ingress/* - type: WebSocketListener port: 8000 # Routes: /fame/v1/attach/* - type: AgentHttpGatewayListener port: 8000 # Routes: /fame/v1/gateway/*

Environment Variables

Control listener behavior via environment variables:

VariableDescriptionDefault
FAME_LISTENER_HTTP_ENABLEDEnable HTTP listenertrue
FAME_LISTENER_WEBSOCKET_ENABLEDEnable WebSocket listenertrue
FAME_LISTENER_AGENT_HTTP_GATEWAY_ENABLEDEnable Agent HTTP Gatewayfalse

These variables work with the pre-built SENTINEL_CONFIG from @naylence/agent-sdk.

When to Use Which Listener

ScenarioRecommended Listener(s)
Standard sentinel accepting node connectionsHttpListener + WebSocketListener
External API clients calling agentsAgentHttpGatewayListener
Browser SPA with in-page fabricInPageListener
Multi-tab browser applicationBroadcastChannelListener
HTTP-only environment (no WebSocket)HttpListener only

See Also

Last updated on