Edit

channel (config)

Environment: server.

BetaTelefunc Stream is in beta: breaking changes may occur in any version update.

// Environment: server
 
import { config } from 'telefunc'
 
config.channel = {
  reconnectTimeout: 60_000, // Hold channels open after disconnect (ms)
  idleTimeout: 60_000, // Keep connection alive after last channel closes (ms)
  pingInterval: 5_000, // Client ping interval (ms)
  connectTtl: 5_000, // Wait for client to connect to new channel (ms)
 
  // Text buffers
  serverReplayBuffer: 262_144, // Server replay buffer for text frames (bytes)
  clientReplayBuffer: 1_048_576, // Client replay buffer for text frames (bytes)
  bufferLimit: 524_288, // Per-peer buffer for text messages (bytes)
 
  // Binary buffers — separate budget so binary can never evict text
  serverReplayBufferBinary: 2_097_152, // Server replay buffer for binary frames (bytes)
  clientReplayBufferBinary: 2_097_152, // Client replay buffer for binary frames (bytes)
  bufferLimitBinary: 2_097_152 // Per-peer buffer for binary messages (bytes)
}
// Environment: server
 
import { config } from 'telefunc'
 
config.channel = {
  reconnectTimeout: 60_000,             // Hold channels open after disconnect (ms)
  idleTimeout: 60_000,                  // Keep connection alive after last channel closes (ms)
  pingInterval: 5_000,                  // Client ping interval (ms)
  connectTtl: 5_000,                    // Wait for client to connect to new channel (ms)
 
  // Text buffers
  serverReplayBuffer: 262_144,          // Server replay buffer for text frames (bytes)
  clientReplayBuffer: 1_048_576,        // Client replay buffer for text frames (bytes)
  bufferLimit: 524_288,                 // Per-peer buffer for text messages (bytes)
 
  // Binary buffers — separate budget so binary can never evict text
  serverReplayBufferBinary: 2_097_152,  // Server replay buffer for binary frames (bytes)
  clientReplayBufferBinary: 2_097_152,  // Client replay buffer for binary frames (bytes)
  bufferLimitBinary: 2_097_152,         // Per-peer buffer for binary messages (bytes)
}

This is the server-side config.channel — a separate object from the client-side config.channel.transports (telefunc/client).

What to tune: the defaults suit typical stream use cases; tune these only if you run into one of the issues below:

  • Slow/flaky clients dropping with NetworkError (isChannel: true) → raise reconnectTimeout (how long the server holds a channel open while a client is gone).
  • ChannelOverflowError while a peer is briefly offline → raise bufferLimit/bufferLimitBinary, or apply backpressure by await-ing your send()s.
  • Want reconnects to replay more history → raise the replay buffers; lower them to cap memory.

You usually define server-side configs (import { config } from 'telefunc') at your server entry. For example:

// /server/index.js
// Environment: server
 
import { config } from 'telefunc'
 
const app = express() // If you use Express.js
const app = new Hono() // If you use Hono
// ...
 
// Server configs can be set here
config.someServerSideSetting = 'some-value'
// /server/index.ts
// Environment: server
 
import { config } from 'telefunc'
 
const app = express() // If you use Express.js
const app = new Hono() // If you use Hono
// ...
 
// Server configs can be set here
config.someServerSideSetting = 'some-value'

See also