Documentation
¶
Index ¶
- Constants
- Variables
- func ListenAndServe(addr string, handler OutboundHandler) error
- func StringInSlice(str string, list []string) bool
- type BgCallback
- type Client
- type Connection
- func (c *Connection) Close()
- func (c *Connection) Dial(network string, addr string, timeout time.Duration) (net.Conn, error)
- func (c *Connection) EnableEvent(ctx context.Context, events ...string) error
- func (c *Connection) ExitAndClose()
- func (c *Connection) Export(ctx context.Context, key, value, uuid string) error
- func (c *Connection) FilterEvent(name string, cb EventHandler)
- func (c *Connection) FilterHeader(header, value string, cb EventHandler)
- func (c *Connection) SendCommand(ctx context.Context, cmd command.Command, fn ...EventHandler) (*RawResponse, error)
- func (c *Connection) Set(ctx context.Context, key, value, uuid string) error
- type Event
- type EventCallback
- type EventHandler
- type HeaderFilterCallback
- type Message
- type OutboundHandler
- type RawResponse
- func (r RawResponse) ChannelUUID() string
- func (r RawResponse) GetHeader(header string) string
- func (r RawResponse) GetReply() string
- func (r RawResponse) GetVariable(variable string) string
- func (r RawResponse) GoString() string
- func (r RawResponse) HasHeader(header string) bool
- func (r RawResponse) IsOk() bool
- func (r RawResponse) String() string
Constants ¶
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
const EndOfMessage = "\r\n\r\n"
EndOfMessage message end
const EventListenAll = "ALL"
EventListenAll listen all event key
Variables ¶
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
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 ¶
StringInSlice - Will check if string in list. This is equivalent to python if x in [] @TODO - What the fuck Nevio...
Types ¶
type BgCallback ¶
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 ¶
NewClient - Will initiate new client that will establish connection and attempt to authenticate against connected freeswitch server
func (*Client) EstablishConnection ¶
EstablishConnection - Will attempt to establish connection against freeswitch and create new SocketConnection
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection Main connection against ESL - Gotta add more description here
func (*Connection) Dial ¶
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
type Event ¶
type Event struct { Headers textproto.MIMEHeader Body []byte }
Event struct
type EventCallback ¶
EventCallback event file callback func
type HeaderFilterCallback ¶
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 ¶
Dump - Will return message prepared to be dumped out. It's like prettify message for output
func (*Message) GetCallUUID ¶
GetCallUUID - Will return Caller-Unique-Id
func (*Message) GetHeader ¶
GetHeader - Will return message header value, or "" if the key is not set.
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