Documentation
¶
Index ¶
- Constants
- Variables
- func Debug(format string, v ...interface{})
- func EnableDateTime()
- func EnableDebug()
- func EnableFatal()
- func Error(format string, v ...interface{})
- func Fatal(format string, v ...interface{})
- func Info(format string, v ...interface{})
- func LogColorReset(level LogLevel) string
- func LogColorSet(level LogLevel) string
- func LogPrefix(level LogLevel) string
- func LogTimestamp() string
- func SetOutputToFile(logFilePath *string)
- func StringInSlice(str string, list []string) bool
- func Warn(format string, v ...interface{})
- type Client
- type LogLevel
- type Message
- type OutboundServer
- type SocketConnection
- func (sc *SocketConnection) Api(command string) error
- func (sc *SocketConnection) BgApi(command string) error
- func (c *SocketConnection) Close() error
- func (sc *SocketConnection) Connect() error
- func (c *SocketConnection) Connected() (ok bool)
- func (c *SocketConnection) Dial(network string, addr string, timeout time.Duration) (net.Conn, error)
- func (c *SocketConnection) Execute(command, args string, sync bool) (m *Message, err error)
- func (sc *SocketConnection) ExecuteAnswer(args string, sync bool) (m *Message, err error)
- func (sc *SocketConnection) ExecuteHangup(uuid string, args string, sync bool) (m *Message, err error)
- func (sc *SocketConnection) ExecuteSet(key string, value string, sync bool) (m *Message, err error)
- func (c *SocketConnection) ExecuteUUID(uuid string, command string, args string, sync bool) (m *Message, err error)
- func (sc *SocketConnection) Exit() error
- func (c *SocketConnection) Handle()
- func (c *SocketConnection) OriginatorAddr() net.Addr
- func (c *SocketConnection) ReadMsg() (*Message, error)
- func (c *SocketConnection) ReconnectIfNeeded() (err error)
- func (c *SocketConnection) Send(cmd string) error
- func (c *SocketConnection) SendEvent(eventName string, eventHeaders []string, eventBody string) error
- func (c *SocketConnection) SendMany(cmds []string) error
- func (c *SocketConnection) SendMsg(msg map[string]string, uuid, data string) (m *Message, err error)
Constants ¶
const ( LogLColorReset = "\033[0m" LogLColorRed = "\033[31m" LogLColorGreen = "\033[32m" LogLColorYellow = "\033[33m" LogLColorBlue = "\033[34m" LogLColorPurple = "\033[35m" LogLColorCyan = "\033[36m" LogLColorWhite = "\033[37m" LogLColorBold = "\033[1m" LogLColorBoldReset = "\033[22m" LogLColorUnderline = "\033[4m" LogLColorReversed = "\033[7m" )
Variables ¶
var ( EInvalidCommandProvided = "Invalid command provided. Command cannot contain \\r and/or \\n. Provided command is: %s" ECouldNotReadMIMEHeaders = "Error while reading MIME headers: %s" EInvalidContentLength = "Unable to get size of content-length: %s" EUnsuccessfulReply = "Got error while reading from reply command: %s" ECouldNotReadyBody = "Got error while reading reader body: %s" EUnsupportedMessageType = "Unsupported message type! We got '%s'. Supported types are: %v " ECouldNotDecode = "Could not decode/unescape message: %s" ECouldNotStartListener = "Got error while attempting to start listener: %s" EListenerConnection = "Listener connection error: %s" EInvalidServerAddr = "Please make sure to pass along valid address. You've passed: \"%s\"" EUnexpectedAuthHeader = "Expected auth/request content type. Got %s" EInvalidPassword = "Could not authenticate against freeswitch with provided password: %s" ECouldNotCreateMessage = "Error while creating new message: %s" ECouldNotSendEvent = "Must send at least one event header, detected `%d` header" )
var ( // Size of buffer when we read from connection. // 1024 << 6 == 65536 ReadBufferSize = 1024 << 6 // 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 Fatal ¶
func Fatal(format string, v ...interface{})
Fatal sends a fatal log message and stop the execution of the program.
func LogColorReset ¶
func LogColorSet ¶
func LogTimestamp ¶
func LogTimestamp() string
func SetOutputToFile ¶
func SetOutputToFile(logFilePath *string)
func StringInSlice ¶
StringInSlice - Will check if string in list. This is equivalent to python if x in []
Types ¶
type Client ¶
type Client struct { SocketConnection Proto string `json:"freeswitch_protocol"` Addr string `json:"freeswitch_addr"` Passwd string `json:"freeswitch_password"` Timeout int `json:"freeswitch_connection_timeout"` }
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) Authenticate ¶
Authenticate - Method used to authenticate client against freeswitch. In case of any errors durring so we will return error.
func (*Client) EstablishConnection ¶
EstablishConnection - Will attempt to establish connection against freeswitch and create new SocketConnection
type LogLevel ¶
type LogLevel uint32
LogLevel type.
const ( // FatalLevel should be used in fatal situations, the app will exit. FatalLevel LogLevel = iota // ErrorLevel should be used when someone should really look at the error. ErrorLevel // InfoLevel should be used during normal operations. InfoLevel // WarnLevel should be used for things should be addressed at some point. WarnLevel // DebugLevel should be used only during development. DebugLevel )
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 NewMessage ¶
NewMessage - Will build and execute parsing against received freeswitch message. As return will give brand new Message{} for you to use it.
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 OutboundServer ¶
type OutboundServer struct { net.Listener Addr string `json:"address"` Proto string Conns chan SocketConnection }
OutboundServer - In case you need to start server, this Struct have it covered
func NewOutboundServer ¶
func NewOutboundServer(addr string) (*OutboundServer, error)
NewOutboundServer - Will instanciate new outbound server
func (*OutboundServer) Start ¶
func (s *OutboundServer) Start() error
Start - Will start new outbound server
func (*OutboundServer) Stop ¶
func (s *OutboundServer) Stop()
Stop - Will close server connection once SIGTERM/Interrupt is received
type SocketConnection ¶
Main connection against ESL - Gotta add more description here
func (*SocketConnection) Api ¶
func (sc *SocketConnection) Api(command string) error
BgApi - Helper designed to attach api in front of the command so that you do not need to write it
func (*SocketConnection) BgApi ¶
func (sc *SocketConnection) BgApi(command string) error
BgApi - Helper designed to attach bgapi in front of the command so that you do not need to write it
func (*SocketConnection) Close ¶
func (c *SocketConnection) Close() error
Close - Will close down net connection and return error if error happen
func (*SocketConnection) Connect ¶
func (sc *SocketConnection) Connect() error
Connect - Helper designed to help you handle connection. Each outbound server when handling needs to connect e.g. accept connection in order for you to do answer, hangup or do whatever else you wish to do
func (*SocketConnection) Connected ¶
func (c *SocketConnection) Connected() (ok bool)
Connected checks if socket connected. Can be extended with pings TODO - add better connection handling
- use heartbeat events from freeswitch
- add bool to SocketConnection 'connected' that is changed on certain errors
func (*SocketConnection) Dial ¶
func (c *SocketConnection) 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 (*SocketConnection) Execute ¶
func (c *SocketConnection) Execute(command, args string, sync bool) (m *Message, err error)
Execute - Helper fuck to execute commands with its args and sync/async mode
func (*SocketConnection) ExecuteAnswer ¶
func (sc *SocketConnection) ExecuteAnswer(args string, sync bool) (m *Message, err error)
ExecuteHangup - Helper desgned to help with executing Answer against active ESL session
func (*SocketConnection) ExecuteHangup ¶
func (sc *SocketConnection) ExecuteHangup(uuid string, args string, sync bool) (m *Message, err error)
ExecuteHangup - Helper desgned to help with executing Hangup against active ESL session
func (*SocketConnection) ExecuteSet ¶
Set - Helper that you can use to execute SET application against active ESL session
func (*SocketConnection) ExecuteUUID ¶
func (c *SocketConnection) ExecuteUUID(uuid string, command string, args string, sync bool) (m *Message, err error)
ExecuteUUID - Helper fuck to execute uuid specific commands with its args and sync/async mode
func (*SocketConnection) Exit ¶
func (sc *SocketConnection) Exit() error
Exit - Used to send exit signal to ESL. It will basically hangup call and close connection
func (*SocketConnection) Handle ¶
func (c *SocketConnection) Handle()
Handle - Will handle new messages and close connection when there are no messages left to process
func (*SocketConnection) OriginatorAddr ¶
func (c *SocketConnection) OriginatorAddr() net.Addr
OriginatorAdd - Will return originator address known as net.RemoteAddr() This will actually be a freeswitch address
func (*SocketConnection) ReadMsg ¶
func (c *SocketConnection) ReadMsg() (*Message, error)
ReadMsg - Will read message from channels and return them back accordingy. If error is received, error will be returned. If not, message will be returned back!
func (*SocketConnection) ReconnectIfNeeded ¶
func (c *SocketConnection) ReconnectIfNeeded() (err error)
ReconnectIfNeeded if not connected, attempt reconnect if allowed
func (*SocketConnection) Send ¶
func (c *SocketConnection) Send(cmd string) error
Send - Will send raw message to open net connection
func (*SocketConnection) SendEvent ¶
func (c *SocketConnection) SendEvent(eventName string, eventHeaders []string, eventBody string) error
SendEvent - Will loop against passed event headers If you don't need a event body, pass in empty string ""
func (*SocketConnection) SendMany ¶
func (c *SocketConnection) SendMany(cmds []string) error
SendMany - Will loop against passed commands and return 1st error if error happens