caddy_peerjs_server

package module
v0.1.0-alpha Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

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

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 relies on github.com/gorilla/websocket , which have no support for http/2 currently.

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"`

	// [Additional] Allow to use GET /id http API method to get a new id
	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>...]
	[id_manager <subdirective>]
}

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