esl

package module
v0.0.0-...-476fdef Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2021 License: MIT Imports: 18 Imported by: 0

README

esl

golang esl client

clone from goesl[https://github.com/0x19/goesl]
add filter and bgapi callback support.
see also:
lxfontes/go-eventsocket[https://github.com/lxfontes/go-eventsocket]
fiorix/go-eventsocket[https://github.com/fiorix/go-eventsocket]

Documentation

Index

Constants

View Source
const (
	TypeEventPlain  = `text/event-plain`
	TypeEventJSON   = `text/event-json`
	TypeEventXML    = `text/event-xml`
	TypeReply       = `command/reply`
	TypeAPIResponse = `api/response`
	TypeAuthRequest = `auth/request`
	TypeDisconnect  = `text/disconnect-notice`
)

response content type

View Source
const EndOfMessage = "\r\n\r\n"

EndOfMessage message end

View Source
const EventListenAll = "ALL"

EventListenAll listen all event key

Variables

View Source
var (
	ErrInvalidCommandProvided  = errors.New("Invalid command provided. Command cannot contain \\r and/or \\n")
	ErrCouldNotReadMIMEHeaders = errors.New("Error while reading MIME headers")
	ErrInvalidContentLength    = errors.New("Unable to get size of content-length")
	ErrUnsuccessfulReply       = errors.New("Got error while reading from reply command")
	ErrCouldNotReadBody        = errors.New("Got error while reading reader body")
	ErrUnsupportedMessageType  = errors.New("Unsupported message type")
	ErrCouldNotDecode          = errors.New("Could not decode/unescape message")
	ErrCouldNotStartListener   = errors.New("Got error while attempting to start listener")
	ErrListenerConnection      = errors.New("Listener connection error")
	ErrInvalidServerAddr       = errors.New("Please make sure to pass along valid address")
	ErrUnexpectedAuthHeader    = errors.New("Expected auth/request content type")
	ErrInvalidPassword         = errors.New("Could not authenticate against freeswitch with provided password")
	ErrCouldNotCreateMessage   = errors.New("Error while creating new message")
	ErrCouldNotSendEvent       = errors.New("Must send at least one event header")
	ErrTimeout                 = errors.New("Opration timeout")
	ErrConnClosed              = errors.New("Connection closed")
	ErrResponseChn             = errors.New("no response channels")
	ErrNotImplement            = errors.New("not implement")
)

errors

View Source
var (

	// ReadBufferSize Size of buffer when we read from connection.
	// 1024 << 6 == 65536
	ReadBufferSize = 1024 << 6

	// AvailableMessageTypes Freeswitch events that we can handle (have logic for it)
	AvailableMessageTypes = []string{"auth/request", "text/disconnect-notice", "text/event-json", "text/event-plain", "api/response", "command/reply"}
)

Functions

func ListenAndServe

func ListenAndServe(addr string, handler OutboundHandler) error

ListenAndServe outbound server

func StringInSlice

func StringInSlice(str string, list []string) bool

StringInSlice - Will check if string in list. This is equivalent to python if x in [] @TODO - What the fuck Nevio...

Types

type BgCallback

type BgCallback func(header map[string]string, body string)

BgCallback bgapi callback func

type Client

type Client struct {
	Connection

	Proto   string `json:"freeswitch_protocol"`
	Addr    string `json:"freeswitch_addr"`
	Passwd  string `json:"freeswitch_password"`
	Timeout int    `json:"freeswitch_connection_timeout"`
	// contains filtered or unexported fields
}

Client - In case you need to do inbound dialing against freeswitch server in order to originate call or see sofia statuses or whatever else you came up with

func NewClient

func NewClient(host string, port uint16, passwd string, timeout int) (*Client, error)

NewClient - Will initiate new client that will establish connection and attempt to authenticate against connected freeswitch server

func (*Client) DoAuth

func (c *Client) DoAuth(ctx context.Context, auth command.Auth) error

DoAuth authenticate client against freeswitch.

func (*Client) EstablishConnection

func (c *Client) EstablishConnection() error

EstablishConnection - Will attempt to establish connection against freeswitch and create new SocketConnection

func (*Client) Start

func (c *Client) Start(format, events string) error

Start start process loop

func (*Client) Stop

func (c *Client) Stop()

Stop stop process loop

type Connection

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

Connection Main connection against ESL - Gotta add more description here

func (*Connection) Close

func (c *Connection) Close()

Close close connection

func (*Connection) Dial

func (c *Connection) Dial(network string, addr string, timeout time.Duration) (net.Conn, error)

Dial - Will establish timedout dial against specified address. In this case, it will be freeswitch server

func (*Connection) EnableEvent

func (c *Connection) EnableEvent(ctx context.Context, events ...string) error

EnableEvent subscribe event format and type

func (*Connection) ExitAndClose

func (c *Connection) ExitAndClose()

ExitAndClose send exit and close connection

func (*Connection) Export

func (c *Connection) Export(ctx context.Context, key, value, uuid string) error

Export execute channel `export` command

func (*Connection) FilterEvent

func (c *Connection) FilterEvent(name string, cb EventHandler)

FilterEvent add event filter callback

func (*Connection) FilterHeader

func (c *Connection) FilterHeader(header, value string, cb EventHandler)

FilterHeader filter by header name and value, add callback

func (*Connection) SendCommand

func (c *Connection) SendCommand(ctx context.Context, cmd command.Command, fn ...EventHandler) (*RawResponse, error)

SendCommand send command to fs

func (*Connection) Set

func (c *Connection) Set(ctx context.Context, key, value, uuid string) error

Set execute channel `set` command

type Event

type Event struct {
	Headers textproto.MIMEHeader
	Body    []byte
}

Event struct

func (Event) GetHeader

func (e Event) GetHeader(header string) string

GetHeader Helper function that calls e.Header.Get

func (Event) GetName

func (e Event) GetName() string

GetName Helper function that returns the event name header

func (Event) GoString

func (e Event) GoString() string

GoString Implement the GoStringer interface for pretty printing (%#v)

func (Event) HasHeader

func (e Event) HasHeader(header string) bool

HasHeader Helper to check if the Event has a header

func (Event) String

func (e Event) String() string

String Implement the Stringer interface for pretty printing (%v)

type EventCallback

type EventCallback func(eventName string, header map[string]string, body string)

EventCallback event file callback func

type EventHandler

type EventHandler func(e *Event)

EventHandler event handler callback

type HeaderFilterCallback

type HeaderFilterCallback func(name, value string, header map[string]string, body string)

HeaderFilterCallback filter by header field callback func

type Message

type Message struct {
	Headers map[string]string
	Body    []byte
	// contains filtered or unexported fields
}

Message - Freeswitch Message that is received by GoESL. Message struct is here to help with parsing message and dumping its contents. In addition to that it's here to make sure received message is in fact message we wish/can support

func (*Message) Dump

func (m *Message) Dump() (resp string)

Dump - Will return message prepared to be dumped out. It's like prettify message for output

func (*Message) GetCallUUID

func (m *Message) GetCallUUID() string

GetCallUUID - Will return Caller-Unique-Id

func (*Message) GetHeader

func (m *Message) GetHeader(key string) string

GetHeader - Will return message header value, or "" if the key is not set.

func (Message) GoString

func (m Message) GoString() string

GoString implement the GoStringer interface for pretty printing (%#v)

func (*Message) Parse

func (m *Message) Parse() error

Parse - Will parse out message received from Freeswitch and basically build it accordingly for later use. However, in case of any issues func will return error.

func (Message) String

func (m Message) String() string

String - Will return message representation as string

type OutboundHandler

type OutboundHandler func(ctx context.Context, conn *Connection, response *RawResponse)

OutboundHandler connection handler

type RawResponse

type RawResponse struct {
	Headers textproto.MIMEHeader
	Body    []byte
}

RawResponse This struct contains all response data from FreeSWITCH

func (RawResponse) ChannelUUID

func (r RawResponse) ChannelUUID() string

ChannelUUID Helper to get the channel UUID. Calls GetHeader internally

func (RawResponse) GetHeader

func (r RawResponse) GetHeader(header string) string

GetHeader Helper function that calls RawResponse.Headers.Get. Result gets passed through url.PathUnescape

func (RawResponse) GetReply

func (r RawResponse) GetReply() string

GetReply Helper to get the Reply text from FreeSWITCH, uses the Reply-Text header primarily. Also will use the body if the Reply-Text header does not exist, this can be the case for TypeAPIResponse

func (RawResponse) GetVariable

func (r RawResponse) GetVariable(variable string) string

GetVariable Helper function to get "Variable_" headers. Calls GetHeader internally

func (RawResponse) GoString

func (r RawResponse) GoString() string

GoString Implement the GoStringer interface for pretty printing (%#v)

func (RawResponse) HasHeader

func (r RawResponse) HasHeader(header string) bool

HasHeader Helper to check if the RawResponse has a header

func (RawResponse) IsOk

func (r RawResponse) IsOk() bool

IsOk Helper to check response status, uses the Reply-Text header primarily. Calls GetReply internally

func (RawResponse) String

func (r RawResponse) String() string

String Implement the Stringer interface for pretty printing

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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