caddy_peerjs_server

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2026 License: Apache-2.0 Imports: 20 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

caddy-peerjs-server

A simple (maybe uncompleted) implement of peerjs-server in caddy extensions

[!NOTE] This is not an official repository of the Caddy Web Server organization.

Syntax

peerjs_server [<matcher>] {
	[path <string>]
	[key <string>]
	[expire_timeout <duration>]
	[alive_timeout <duration>]
	[concurrent_limit <uint>]
	[queue_limit <uint>]
	[allow_discovery [<bool>]]
	[transmission_extend <string>...]
}

These params are defined like this, mostly the same as peerjs/peerjs-server

Scalar options accept exactly one argument, except allow_discovery, which can also appear without an argument. transmission_extend requires at least one message type. Unknown options, excess arguments, and nested option blocks are rejected. Custom id_manager / JSON client_id_manager configuration is not implemented and is rejected rather than silently ignored (JSON null is allowed).

Timeouts must be positive after defaults are applied; zero selects the default. Paths must start with /. Each configuration instance owns its expiration worker; cleanup cancels and waits for that worker before clearing its signaling state.

Variable Type Default Description
Path
path
string "/" The server responds for requests to the root URL + path. Example: Set to /myapp for [http://127.0.0.1:9000/myapp](vscode-file://vscode-app/d:/Storage/Softwares/Microsoft VS Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html)
Key
key
string "peerjs" Connection key that clients must provide to call API methods
ExpireTimeout
expire_timeout
time.Duration 5000ms Time after which a sent message will expire, triggering an EXPIRE message to sender
AliveTimeout
alive_timeout
time.Duration 60000ms Timeout for broken connections. Server destroys client connection if no data received
ConcurrentLimit
concurrent_limit
uint 64 Maximum number of concurrent client connections to WebSocket server
QueueLimit
queue_limit
uint 16 [Additional] Maximum number of messages in the queue for each client
AllowDiscovery
allow_discovery
bool false Allow GET /peers HTTP API method to get array of all connected client IDs; allow_discovery exist or with value true means true; otherwise false
TransmissionExtend
transmission_extend
[]string nil [Additional] MessageTypes allowed to be transmitted beyond standard ones

Limitations

Only support http/1.1

This extension uses github.com/coder/websocket v1.8.15 with HTTP/1.1 WebSocket handshakes. Keep the internal HTTP/1.1 listener and reverse-proxy bridge shown in the example; direct HTTP/2 Extended CONNECT is not enabled.

Documentation

Index

Constants

View Source
const ENABLE_TRACE bool = false
View Source
const WS_PATH string = "peerjs"

Variables

This section is empty.

Functions

This section is empty.

Types

type PeerJSServer

type PeerJSServer struct {

	// Path (string). The server responds for requests to the root URL + path.
	// E.g. Set the path to /myapp and run server on 9000 port via peerjs --port 9000 --path /myapp Then open http://127.0.0.1:9000/myapp - you should see a JSON reponse.
	// Default: "/"
	Path string `json:"path,omitempty"`

	// Connection key (string). Client must provide it to call API methods.
	// Default: "peerjs"
	Key string `json:"key,omitempty"`

	// The amount of time after which a message sent will expire, the sender will then receive a EXPIRE message (milliseconds).
	// Default: 5000
	ExpireTimeout time.Duration `json:"expire_timeout,omitempty"`

	// Timeout for broken connection (milliseconds).
	// If the server doesn't receive any data from client (includes pong messages), the client's connection will be destroyed.
	// Default: 60000
	AliveTimeout time.Duration `json:"alive_timeout,omitempty"`

	// Maximum number of clients' connections to WebSocket server
	// Default: 64
	ConcurrentLimit uint `json:"concurrent_limit,omitempty"`

	// [Additional] Maximum number of messages in the queue for each client
	// Default: 16
	QueueLimit uint `json:"queue_limit,omitempty"`

	// Allow to use GET /peers http API method to get an array of ids of all connected clients
	AllowDiscovery bool `json:"allow_discovery,omitempty"`

	// [Additional] Other MesseageType (`type`) in protocol.Message that allowed to be transmitted
	TransmissionExtend []string `json:"transmission_extend,omitempty"`

	// Reserved for future custom ID managers; non-null configuration is rejected.
	ClientIdManagerRaw json.RawMessage `json:"client_id_manager,omitempty" caddy:"namespace=http.handlers.peerjs_server inline_key=id_manager"`
	// contains filtered or unexported fields
}

func (*PeerJSServer) CaddyModule

func (*PeerJSServer) CaddyModule() caddy.ModuleInfo

func (*PeerJSServer) Cleanup

func (pjs *PeerJSServer) Cleanup() error

Cleanup implements caddy.CleanerUpper.

func (*PeerJSServer) FillDefault

func (pjs *PeerJSServer) FillDefault() error

func (*PeerJSServer) Provision

func (pjs *PeerJSServer) Provision(ctx caddy.Context) error

Provision implements caddy.Provisioner.

func (*PeerJSServer) ServeHTTP

func (pjs *PeerJSServer) ServeHTTP(w http.ResponseWriter, req *http.Request, h caddyhttp.Handler) error

ServeHTTP implements caddyhttp.MiddlewareHandler.

func (*PeerJSServer) UnmarshalCaddyfile

func (pjs *PeerJSServer) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

UnmarshalCaddyfile implements caddyfile.Unmarshaler.

peerjs_server [<matcher>] {
	[path <string>]
	[key <string>]
	[expire_timeout <duration>]
	[alive_timeout <duration>]
	[concurrent_limit <uint>]
	[queue_limit <uint>]
	[allow_discovery [<bool>]]
	[transmission_extend <string>...]
}

func (*PeerJSServer) Validate

func (pjs *PeerJSServer) Validate() error

Validate implements caddy.Validator.

type ZapLoggerWrapper

type ZapLoggerWrapper struct {
	// contains filtered or unexported fields
}

func (*ZapLoggerWrapper) Debug

func (z *ZapLoggerWrapper) Debug(msg string, id string)

Debug implements peerjs_server.IFunctionalLogger.

func (*ZapLoggerWrapper) DebugWithError

func (z *ZapLoggerWrapper) DebugWithError(msg string, id string, err error)

DebugWithError implements peerjs_server.IFunctionalLogger.

func (*ZapLoggerWrapper) Error

func (z *ZapLoggerWrapper) Error(msg string, id string, err error)

Error implements peerjs_server.IFunctionalLogger.

func (*ZapLoggerWrapper) Info

func (z *ZapLoggerWrapper) Info(msg string, id string)

Info implements peerjs_server.IFunctionalLogger.

func (*ZapLoggerWrapper) TraceExpireCheck

func (z *ZapLoggerWrapper) TraceExpireCheck(msgs map[string]utils.Iterable[msgstorage.IMessage])

TraceExpireCheck implements peerjs_server.IFunctionalLogger.

func (*ZapLoggerWrapper) TraceMessage

func (z *ZapLoggerWrapper) TraceMessage(id string, msg *protocol.Message)

TraceMessage implements peerjs_server.IFunctionalLogger.

func (*ZapLoggerWrapper) Warn

func (z *ZapLoggerWrapper) Warn(msg string, id string, err error)

Warn implements peerjs_server.IFunctionalLogger.

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL