sipgo

package module
v0.13.2-0...-dad6682 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2025 License: BSD-2-Clause Imports: 13 Imported by: 0

README

SIPGO

Go Report Card License GitHub go.mod Go version

LiveKit wrapper on top of emiago/sipgo. It will be gone once all changes are merged upstream.

For now, this package preserves an older version of signaling functions, while using the upstream SIP parser, formatter and the message types.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientRequestAddRecordRoute

func ClientRequestAddRecordRoute(c *Client, r *sip.Request) error

ClientRequestAddRecordRoute is option for adding record route header Based on proxy setup https://www.rfc-editor.org/rfc/rfc3261#section-16

func ClientRequestAddVia

func ClientRequestAddVia(c *Client, r *sip.Request) error

ClientRequestAddVia is option for adding via header Based on proxy setup https://www.rfc-editor.org/rfc/rfc3261.html#section-16.6

func ClientRequestDecreaseMaxForward

func ClientRequestDecreaseMaxForward(c *Client, r *sip.Request) error

Based on proxy setup https://www.rfc-editor.org/rfc/rfc3261#section-16 ClientRequestDecreaseMaxForward should be used when forwarding request. It decreases max forward in case of 0 it returnes error

func GenerateTLSConfig

func GenerateTLSConfig(certFile string, keyFile string, rootPems []byte) (*tls.Config, error)

GenerateTLSConfig creates basic tls.Config that you can pass for ServerTLS It needs rootPems for client side

func Init

func Init()

Types

type Client

type Client struct {
	*UserAgent
	// contains filtered or unexported fields
}

func NewClient

func NewClient(ua *UserAgent, options ...ClientOption) (*Client, error)

NewClient creates client handle for user agent

func (*Client) Close

func (c *Client) Close() error

Close client handle. UserAgent must be closed for full transaction and transport layer closing.

func (*Client) GetHostname

func (c *Client) GetHostname() string

func (*Client) TransactionRequest

func (c *Client) TransactionRequest(req *sip.Request, options ...ClientRequestOption) (sip.ClientTransaction, error)

TransactionRequest uses transaction layer to send request and returns transaction NOTE: By default request will not be cloned and it will populate request with missing headers unless options are used

In most cases you want this as you will retry with additional headers

Following header fields will be added if not exist to have correct SIP request: To, From, CSeq, Call-ID, Max-Forwards, Via

Passing options will override this behavior, that is it is expected that you have request fully built This is useful when using client handle in proxy building as request are already parsed

func (*Client) WriteRequest

func (c *Client) WriteRequest(req *sip.Request, options ...ClientRequestOption) error

WriteRequest sends request directly to transport layer Behavior is same as TransactionRequest Non-transaction ACK request should be passed like this

type ClientOption

type ClientOption func(c *Client) error

func WithClientAddr

func WithClientAddr(addr string) ClientOption

WithClientAddr is merge of WithClientHostname and WithClientPort addr is format <host>:<port>

func WithClientHostname

func WithClientHostname(hostname string) ClientOption

WithClientHost allows setting default route host default it will be used user agent IP

func WithClientLogger

func WithClientLogger(logger *slog.Logger) ClientOption

WithClientLogger allows customizing client logger

func WithClientPort

func WithClientPort(port int) ClientOption

WithClientPort allows setting default route port

type ClientRequestOption

type ClientRequestOption func(c *Client, req *sip.Request) error

type RequestHandler

type RequestHandler func(log *slog.Logger, req *sip.Request, tx sip.ServerTransaction)

RequestHandler is a callback that will be called on the incoming request

type Server

type Server struct {
	*UserAgent
	// contains filtered or unexported fields
}

Server is a SIP server

func NewServer

func NewServer(ua *UserAgent, options ...ServerOption) (*Server, error)

NewServer creates new instance of SIP server handle. Allows creating server transaction handlers It uses User Agent transport and transaction layer

func (*Server) Close

func (srv *Server) Close() error

Close server handle. UserAgent must be closed for full transaction and transport layer closing.

func (*Server) ListenAndServe

func (srv *Server) ListenAndServe(ctx context.Context, network string, addr string) error

Serve will fire all listeners Network supported: udp, tcp, ws

func (*Server) ListenAndServeTLS

func (srv *Server) ListenAndServeTLS(ctx context.Context, network string, addr string, conf *tls.Config) error

Serve will fire all listeners that are secured. Network supported: tls, wss

func (*Server) OnAck

func (srv *Server) OnAck(handler RequestHandler)

OnAck registers Ack request handler

func (*Server) OnBye

func (srv *Server) OnBye(handler RequestHandler)

OnBye registers Bye request handler

func (*Server) OnCancel

func (srv *Server) OnCancel(handler RequestHandler)

OnCancel registers Cancel request handler

func (*Server) OnInfo

func (srv *Server) OnInfo(handler RequestHandler)

OnInfo registers Info request handler

func (*Server) OnInvite

func (srv *Server) OnInvite(handler RequestHandler)

OnInvite registers Invite request handler

func (*Server) OnMessage

func (srv *Server) OnMessage(handler RequestHandler)

OnMessage registers Message request handler

func (*Server) OnNoRoute

func (srv *Server) OnNoRoute(handler RequestHandler)

OnNoRoute registers no route handler default is handling is responding 405 Method Not allowed This allows customizing your response for any non handled message

Example
// Creating no route handler allows you to respond for non handled (non routed) requests
ua, _ := NewUA()
srv, _ := NewServer(ua)

srv.OnNoRoute(func(req *sip.Request, tx sip.ServerTransaction) {
	res := sip.NewResponseFromRequest(req, 405, "Method Not Allowed", nil)
	// Send response directly and let transaction terminate
	if err := srv.WriteResponse(res); err != nil {
		srv.log.Error("respond '405 Method Not Allowed' failed", "err", err)
	}
})

func (*Server) OnNotify

func (srv *Server) OnNotify(handler RequestHandler)

OnNotify registers Notify request handler

func (*Server) OnOptions

func (srv *Server) OnOptions(handler RequestHandler)

OnOptions registers Options request handler

func (*Server) OnPrack

func (srv *Server) OnPrack(handler RequestHandler)

OnPrack registers Prack request handler

func (*Server) OnPublish

func (srv *Server) OnPublish(handler RequestHandler)

OnPublish registers Publish request handler

func (*Server) OnRefer

func (srv *Server) OnRefer(handler RequestHandler)

OnRefer registers Refer request handler

func (*Server) OnRegister

func (srv *Server) OnRegister(handler RequestHandler)

OnRegister registers Register request handler

func (*Server) OnRequest

func (srv *Server) OnRequest(method sip.RequestMethod, handler RequestHandler)

OnRequest registers new request callback. Can be used as generic way to add handler

func (*Server) OnSubscribe

func (srv *Server) OnSubscribe(handler RequestHandler)

OnSubscribe registers Subscribe request handler

func (*Server) OnUpdate

func (srv *Server) OnUpdate(handler RequestHandler)

OnUpdate registers Update request handler

func (*Server) RegisteredMethods

func (srv *Server) RegisteredMethods() []string

RegisteredMethods returns list of registered handlers. Can be used for constructing Allow header

func (*Server) ServeRequest

func (srv *Server) ServeRequest(f func(r *sip.Request))

ServeRequest can be used as middleware for preprocessing message

func (*Server) ServeTCP

func (srv *Server) ServeTCP(l net.Listener) error

ServeTCP starts serving request on TCP type listener.

func (*Server) ServeTLS

func (srv *Server) ServeTLS(l net.Listener) error

ServeTLS starts serving request on TLS type listener.

func (*Server) ServeUDP

func (srv *Server) ServeUDP(l net.PacketConn) error

ServeUDP starts serving request on UDP type listener.

func (*Server) ServeWS

func (srv *Server) ServeWS(l net.Listener) error

ServeWS starts serving request on WS type listener.

func (*Server) ServeWSS

func (srv *Server) ServeWSS(l net.Listener) error

ServeWS starts serving request on WS type listener.

func (*Server) TransportLayer

func (srv *Server) TransportLayer() *transport.Layer

Transport is function to get transport layer of server Can be used for modifying

func (*Server) WriteResponse

func (srv *Server) WriteResponse(r *sip.Response) error

WriteResponse will proxy message to transport layer. Use it in stateless mode

type ServerDialog

type ServerDialog struct {
	Server
	// contains filtered or unexported fields
}

ServerDialog is extension of Server to support Dialog handling

func NewServerDialog

func NewServerDialog(ua *UserAgent, options ...ServerOption) (*ServerDialog, error)

func (*ServerDialog) OnDialog

func (s *ServerDialog) OnDialog(f func(d sip.Dialog))

OnDialog allows monitoring new dialogs

func (*ServerDialog) OnDialogChan

func (s *ServerDialog) OnDialogChan(ch chan sip.Dialog)

OnDialogChan same as onDialog but we channel instead callback func

type ServerOption

type ServerOption func(s *Server) error

func WithServerLogger

func WithServerLogger(logger *slog.Logger) ServerOption

WithServerLogger allows customizing server logger

type UserAgent

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

func NewUA

func NewUA(options ...UserAgentOption) (*UserAgent, error)

NewUA creates User Agent User Agent will create transport and transaction layer Check options for customizing user agent

func (*UserAgent) Close

func (ua *UserAgent) Close() error

func (*UserAgent) GetIP

func (ua *UserAgent) GetIP() net.IP

func (*UserAgent) TransactionLayer

func (ua *UserAgent) TransactionLayer() *transaction.Layer

func (*UserAgent) TransportLayer

func (ua *UserAgent) TransportLayer() *transport.Layer

type UserAgentOption

type UserAgentOption func(s *UserAgent) error

func WithUserAgenTLSConfig

func WithUserAgenTLSConfig(c *tls.Config) UserAgentOption

WithUserAgenTLSConfig allows customizing default tls config.

func WithUserAgent

func WithUserAgent(ua string) UserAgentOption

WithUserAgent changes user agent name Default: sipgo

func WithUserAgentDNSResolver

func WithUserAgentDNSResolver(r *net.Resolver) UserAgentOption

WithUserAgentDNSResolver allows customizing default DNS resolver for transport layer

func WithUserAgentIP

func WithUserAgentIP(ip net.IP) UserAgentOption

WithUserAgentIP sets local IP that will be used in building request If not used IP will be resolved Deprecated: Use on client WithClientHostname WithClientPort

func WithUserAgentLogger

func WithUserAgentLogger(log *slog.Logger) UserAgentOption

Directories

Path Synopsis
Originally forked from https://github.com/ghettovoice/gosip by @ghetovoice
Originally forked from https://github.com/ghettovoice/gosip by @ghetovoice

Jump to

Keyboard shortcuts

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