Documentation
¶
Overview ¶
Package sip is a minimal SIP phone, a dialer and a listener of calls: Dial and DialContext return a call once it is answered, Accept the next call the phone answered. A call is a net.Conn of its RTP media, so any packet stream runs over it: mediactl.Stream sends, mediactl.Echo answers.
Index ¶
- Variables
- type Call
- func (c *Call) Close() error
- func (c *Call) Done() <-chan struct{}
- func (c *Call) EndReason() string
- func (c *Call) Hangup(ctx context.Context) error
- func (c *Call) ID() string
- func (c *Call) LocalAddr() net.Addr
- func (c *Call) Read(p []byte) (int, error)
- func (c *Call) RemoteAddr() net.Addr
- func (c *Call) RemoteMedia() netip.AddrPort
- func (c *Call) SetDeadline(t time.Time) error
- func (c *Call) SetReadDeadline(t time.Time) error
- func (c *Call) SetWriteDeadline(t time.Time) error
- func (c *Call) Stats() mediartp.Stats
- func (c *Call) String() string
- func (c *Call) Write(p []byte) (int, error)
- type Config
- type Phone
- func (p *Phone) Accept() (net.Conn, error)
- func (p *Phone) Addr() net.Addr
- func (p *Phone) Close() error
- func (p *Phone) Dial(ctx context.Context, uri string) (*Call, error)
- func (p *Phone) DialContext(ctx context.Context, _, address string) (net.Conn, error)
- func (p *Phone) Incoming() <-chan *Call
- func (p *Phone) Ping(ctx context.Context, uri string) error
- func (p *Phone) Registered() <-chan Registration
- type Registration
- type StatusError
Constants ¶
This section is empty.
Variables ¶
var CloseTimeout = 5 * time.Second
CloseTimeout bounds the BYE of a call closed as a conn.
Functions ¶
This section is empty.
Types ¶
type Call ¶
type Call struct {
// contains filtered or unexported fields
}
Call is a call of a phone, and a net.Conn of its media: its writes leave as the payloads of RTP packets to the peer's media address, its reads return the payloads of the RTP packets received, both on a single socket. Closing it hangs up.
func (*Call) Hangup ¶
Hangup ends the call with a BYE, unless the call has ended. A hangup while another is in flight waits for that one and returns its result.
func (*Call) RemoteAddr ¶
RemoteAddr returns the peer's RTP address.
func (*Call) RemoteMedia ¶
RemoteMedia returns the address the call sends RTP to.
func (*Call) SetDeadline ¶
SetDeadline sets the deadlines of the media socket.
func (*Call) SetReadDeadline ¶
SetReadDeadline sets the read deadline of the media socket.
func (*Call) SetWriteDeadline ¶
SetWriteDeadline sets the write deadline of the media socket.
type Config ¶
type Config struct {
// Net is the network the phone runs over; nil is the host network.
Net transport.Net
// Addr is the ip:port the phone answers calls at over UDP; empty picks a port on every
// interface.
Addr string
// Username and Password answer the digest challenges of the INVITEs the phone sends.
Username, Password string
// AnswerDelay is how long the phone rings before it answers.
AnswerDelay time.Duration
// Registrar makes the phone a registrar too: it takes REGISTERs and dials an AOR registered
// with it over the flow the AOR registered on (RFC 5626).
Registrar bool
// LoggerFactory makes the phone's logger; nil logs nothing.
LoggerFactory logging.LoggerFactory
}
Config is the configuration of a phone.
type Phone ¶
type Phone struct {
// contains filtered or unexported fields
}
Phone is a SIP phone over UDP. Every peer has a conn of its own: a dialed call its dialed conn, the callers the conns the listener accepts. The local address of a conn is the phone's address on it.
func (*Phone) Accept ¶
Accept returns the next call the phone answered, once acknowledged: the phone is a net.Listener of calls. It fails once the phone is closed.
func (*Phone) Dial ¶
Dial calls a SIP URI and returns the call once it is answered. An AOR registered with a registrar phone is called at its Contact over the flow it registered on. Cancelling the context before the answer cancels the call.
func (*Phone) DialContext ¶
DialContext calls the SIP URI of address, over UDP whatever the network: the phone is a dialer of calls.
func (*Phone) Ping ¶
Ping sends an OPTIONS to the URI on a flow of its own and returns nil on a 2xx: the SIP peer at the URI's address takes requests. A URI with no user part addresses a proxy itself.
func (*Phone) Registered ¶
func (p *Phone) Registered() <-chan Registration
Registered returns the REGISTERs a registrar phone took.
type Registration ¶
type Registration struct {
// AOR is the address of record, Contact the address it is reached at.
AOR, Contact sip.Uri
// Expires is the expiry the phone granted, zero for a removed binding.
Expires time.Duration
}
Registration is a REGISTER a registrar phone took.
type StatusError ¶
StatusError is a final non-2xx response to a request.
func (*StatusError) Error ¶
func (e *StatusError) Error() string