esl

package module
v0.0.0-...-d430b07 Latest Latest
Warning

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

Go to latest
Published: May 16, 2024 License: MIT Imports: 12 Imported by: 0

README

FreeSWITCH ESL Monitor

ch1 := make(chan esl.Event, 1)
ch2 := make(chan esl.Event, 1)

monitor := esl.
    New("127.0.0.1:8021", "ClueCon").
    Subscribe(ch1). // subscribe to all events
    Subscribe(ch2, 
        "CHANNEL_CREATE", 
        "CHANNEL_HANGUP", 
        "CHANNEL_HANGUP_COMPLETE",
    )

err := monitor.Run(context.TODO())

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotConnected    = errors.New("not connected")
	ErrAccessDenied    = errors.New("access denied")
	ErrInvalidPassword = errors.New("invalid password")
	ErrTimeout         = errors.New("timeout")
)

Monitor errors.

Functions

This section is empty.

Types

type Event

type Event map[string]string

Event represents an ESL event with headers and a body.

func (Event) Body

func (e Event) Body() string

Body returns the body of the event as a string.

func (Event) ContentLength

func (e Event) ContentLength() int

ContentLength returns the length of the body in the Event.

func (Event) ContentType

func (e Event) ContentType() string

ContentType returns the content type of the event.

func (Event) Get

func (e Event) Get(key string) string

Get returns the value associated with the given key from the Event's headers.

func (Event) IsCustom

func (e Event) IsCustom() bool

IsCustom returns true if the event is a custom event.

func (Event) LogValue

func (e Event) LogValue() slog.Value

LogValue returns the log value of the Event.

It returns a slog.Value that contains the name and sequence of the Event.

func (Event) Name

func (e Event) Name() string

Name returns the name of the event.

func (Event) Sequence

func (e Event) Sequence() int64

Sequence returns the event sequence as an int64.

func (Event) Timestamp

func (e Event) Timestamp() time.Time

Timestamp returns the timestamp of the event.

func (Event) Variable

func (e Event) Variable(name string) string

Variable returns the value of the variable with the given name.

type Monitor

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

Monitor represents a FreeSWITCH ESL Monitor instance.

func New

func New(addr, password string) *Monitor

New creates a new FreeSWITCH ESL Monitor instance.

If the address doesn't contain a port, use the default port (8021). Panic if the address is malformed.

func (*Monitor) Run

func (m *Monitor) Run(ctx context.Context) error

Run connects to the ESL server and subscribes to the events.

The connection is closed when the context is canceled or expired, and an error is returned. The error is the context error.

Returns an error if the connection fails or the authentication fails.

func (*Monitor) Subscribe

func (m *Monitor) Subscribe(send chan<- Event, events ...string) *Monitor

Subscribe adds a new subscriber to the Monitor.

The send channel is used to send events to the subscriber.

The events parameter is a list of event names. If no events are provided or the "*" wildcard is used, all events are subscribed.

func (*Monitor) WithCommandsTimeout

func (m *Monitor) WithCommandsTimeout(timeout time.Duration) *Monitor

WithCommandsTimeout sets the command timeout. The default command timeout is 5 seconds.

Used on authorization and subscription requests.

func (*Monitor) WithDialTimeout

func (m *Monitor) WithDialTimeout(timeout time.Duration) *Monitor

WithDialTimeout sets the dialer timeout.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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