uas

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package uas registers inbound (UAS-side) SIP method handlers on stack.Endpoint using typed callbacks.

Media path: after SDP negotiation yields a payload type and codec name (e.g. pcmu, pcma, opus), build RTP↔PCM paths with pkg/media and pkg/media/encoder (CreateEncode / CreateDecode, registry). Do not duplicate G.711/Opus/G.722 logic inside pkg/sip.

Inbound wiring (manual): before your INVITE handler, transaction.Manager.HandleInviteRequest; after sending a final, BeginInviteServer; on ACK, HandleAck.

Composable helpers (see server_tx.go): ChainInviteServerTx, AfterResponseSentBeginInviteServer, WithOnResponseSentAppended, ChainAckServerTx — wire mgr + stack.EndpointConfig.OnResponseSent + Handlers.

See also: pkg/sip/dialog, pkg/sip/session, pkg/sip/transaction (Register stack.MethodCancel → HandleCancelRequest).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AfterResponseSentBeginInviteServer

func AfterResponseSentBeginInviteServer(mgr *transaction.Manager, srvCtx context.Context, send transaction.SendFunc) func(*stack.Message, *stack.Message, *net.UDPAddr)

AfterResponseSentBeginInviteServer is equivalent to AfterResponseSentBeginServerTx for INVITE-only setups.

func AfterResponseSentBeginServerTx

func AfterResponseSentBeginServerTx(mgr *transaction.Manager, srvCtx context.Context, send transaction.SendFunc) func(*stack.Message, *stack.Message, *net.UDPAddr)

AfterResponseSentBeginServerTx registers the correct UAS server transaction after a final response is on the wire: INVITE → BeginInviteServer; other methods (OPTIONS, REGISTER, BYE, …) → BeginNonInviteServer.

func ErrorResponse

func ErrorResponse(req *stack.Message, status int, reason string) (*stack.Message, error)

ErrorResponse returns a minimal final error response (3xx–6xx) with optional Reason header text in StatusText.

func NewResponse

func NewResponse(req *stack.Message, status int, reason, body, contentType string) (*stack.Message, error)

NewResponse builds a SIP response with common headers copied from the request (From, To, Call-ID, CSeq, Via). body and contentType may be empty for no body (Content-Length: 0).

func WithOnResponseSentAppended

func WithOnResponseSentAppended(cfg stack.EndpointConfig, fn func(*stack.Message, *stack.Message, *net.UDPAddr)) stack.EndpointConfig

WithOnResponseSentAppended returns a copy of cfg with fn chained after the previous OnResponseSent (if any).

Types

type AckHandler

type AckHandler func(req *stack.Message, addr *net.UDPAddr) error

AckHandler handles inbound ACK (no response is sent on the same socket for ACK).

func ChainAckServerTx

func ChainAckServerTx(mgr *transaction.Manager, inner AckHandler) AckHandler

ChainAckServerTx invokes mgr.HandleAck before the application handler (dialog teardown, media stop, etc.).

type Handlers

type Handlers struct {
	Invite    InviteHandler
	Ack       AckHandler
	Bye       SimpleHandler
	Cancel    SimpleHandler
	Options   SimpleHandler
	Register  SimpleHandler
	Info      SimpleHandler
	Prack     SimpleHandler
	Subscribe SimpleHandler
	Notify    SimpleHandler
	Publish   SimpleHandler
	Refer     SimpleHandler
	Message   SimpleHandler
	Update    SimpleHandler
}

Handlers lists optional UAS callbacks. Nil fields are not registered. Register with (*stack.Endpoint).RegisterHandler via Handlers.Attach.

func WrapHandlersWithTransaction

func WrapHandlersWithTransaction(h Handlers, b TransactionBinding) Handlers

WrapHandlersWithTransaction returns a copy of h with INVITE / non-INVITE / CANCEL / ACK hooks chained in front of the transaction layer. If Mgr or Send is nil, h is returned unchanged.

func (Handlers) Attach

func (h Handlers) Attach(ep *stack.Endpoint) error

Attach registers all non-nil handlers on ep. If Options is nil, a default OPTIONS 200 handler is installed.

func (Handlers) AttachWithTransaction

func (h Handlers) AttachWithTransaction(ep *stack.Endpoint, b TransactionBinding) error

AttachWithTransaction appends AfterResponseSentBeginServerTx then registers wrapped handlers. Use when building a UAS: pass the same Manager and Send used for HandleInviteRequest / HandleCancelRequest.

type InviteHandler

type InviteHandler func(req *stack.Message, addr *net.UDPAddr) (*stack.Message, error)

InviteHandler handles an inbound INVITE. Return nil, nil to send nothing (rare); return an error to answer 500.

func ChainInviteServerTx

func ChainInviteServerTx(mgr *transaction.Manager, inner InviteHandler) InviteHandler

ChainInviteServerTx wraps an INVITE handler: duplicate INVITE retransmissions are absorbed by mgr (final resent inside HandleInviteRequest). If mgr is nil, inner is returned unchanged.

type SimpleHandler

type SimpleHandler func(req *stack.Message, addr *net.UDPAddr) (*stack.Message, error)

SimpleHandler handles a request that typically answers with a small final response (BYE, CANCEL, …).

func ChainNonInviteServerTx

func ChainNonInviteServerTx(mgr *transaction.Manager, inner SimpleHandler) SimpleHandler

ChainNonInviteServerTx absorbs duplicate non-INVITE requests (OPTIONS, REGISTER, BYE, …) before inner runs.

type TransactionBinding

type TransactionBinding struct {
	Mgr *transaction.Manager
	// Send must send requests/responses on the same UDP socket as ep (typically ep.Send).
	Send transaction.SendFunc
	// Ctx bounds background server timers; if nil, context.Background is used.
	Ctx context.Context
}

TransactionBinding wires a transaction.Manager and signaling Send path for UAS server-tx behavior.

Jump to

Keyboard shortcuts

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