Documentation
¶
Overview ¶
FreeSWITCH Event Socket library for the Go programming language.
eventsocket supports both inbound and outbound event socket connections, acting either as a client connecting to FreeSWITCH or as a server accepting connections from FreeSWITCH to control calls.
Reference: http://wiki.freeswitch.org/wiki/Event_Socket http://wiki.freeswitch.org/wiki/Event_Socket_Outbound
WORK IN PROGRESS, USE AT YOUR OWN RISK.
Index ¶
- Constants
- func ListenAndServe(addr string, fn HandleFunc) error
- type Connection
- func (h *Connection) ApiCommand(command string) (*Event, error)
- func (h *Connection) Close()
- func (h *Connection) Command(command string) (*Event, error)
- func (h *Connection) Execute(appName, appArg string, lock bool) (*Event, error)
- func (h *Connection) ExecuteUUID(uuid, appName, appArg string) (*Event, error)
- func (h *Connection) ReadEvent() (*Event, error)
- func (h *Connection) RemoteAddr() net.Addr
- func (h *Connection) SendEvent(eventName string, evt EVT, appData string) (*Event, error)
- func (h *Connection) SendEventNotify(user, contentType, content string) (*Event, error)
- func (h *Connection) SendMsg(m MSG, uuid, appData string) (*Event, error)
- type EVT
- type Event
- type EventHeader
- type HandleFunc
- type MSG
Constants ¶
const ( ContentTypePLAIN = "text/plain" ContentTypeJSON = "application/json" ContentTypeXML = "application/xml" )
Variables ¶
This section is empty.
Functions ¶
func ListenAndServe ¶
func ListenAndServe(addr string, fn HandleFunc) error
ListenAndServe listens for incoming connections from FreeSWITCH and calls HandleFunc in a new goroutine for each client.
Example:
func main() { eventsocket.ListenAndServe(":9090", handler) } func handler(c *eventsocket.Connection) { ev, err := c.Command("connect") // must always start with this ev.PrettyPrint() // print event to the console ... c.Command("myevents") for { ev, err = c.ReadEvent() ... } }
Types ¶
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection is the event socket connection handler.
func Dial ¶
func Dial(addr, passwd string) (*Connection, error)
Dial attemps to connect to FreeSWITCH and authenticate.
Example:
c, _ := eventsocket.Dial("localhost:8021", "ClueCon") ev, _ := c.Command("events plain ALL") // or events json ALL for { ev, _ = c.ReadEvent() ev.PrettyPrint() ... }
func (*Connection) ApiCommand ¶ added in v0.1.1
func (h *Connection) ApiCommand(command string) (*Event, error)
ApiCommand sends a 'api command' to the server and returns a response Event.
See https://freeswitch.org/confluence/display/FREESWITCH/mod_event_socket#mod_event_socket-3.CommandDocumentation for details.
func (*Connection) Command ¶
func (h *Connection) Command(command string) (*Event, error)
Command sends a single command to the server and returns a response Event.
See https://freeswitch.org/confluence/display/FREESWITCH/mod_event_socket#mod_event_socket-3.CommandDocumentation for details.
func (*Connection) Execute ¶
func (h *Connection) Execute(appName, appArg string, lock bool) (*Event, error)
Execute is a shortcut to SendMsg with call-command: execute without UUID, suitable for use on outbound event socket connections (acting as server).
Example:
Execute("playback", "/tmp/test.wav", false)
See https://freeswitch.org/confluence/display/FREESWITCH/mod_event_socket#mod_event_socket-3.9sendmsg for details.
func (*Connection) ExecuteUUID ¶
func (h *Connection) ExecuteUUID(uuid, appName, appArg string) (*Event, error)
ExecuteUUID is similar to Execute, but takes a UUID and no lock. Suitable for use on inbound event socket connections (acting as client).
func (*Connection) ReadEvent ¶
func (h *Connection) ReadEvent() (*Event, error)
ReadEvent reads and returns events from the server. It supports both plain or json, but *not* XML.
When subscribing to events (e.g. `Command("events json ALL")`) it makes no difference to use plain or json. ReadEvent will parse them and return all headers and the body (if any) in an Event struct.
func (*Connection) RemoteAddr ¶
func (h *Connection) RemoteAddr() net.Addr
RemoteAddr returns the remote addr of the connection.
func (*Connection) SendEvent ¶
SendEvent sends events to FreeSWITCH and returns a response Event.
Example:
SendEvent("CUSTOM", EVT{ "profile": "internal", "content-length": string(contentLen), "content-type": contentType, "host": "192.168.160.10", }, content)
eventName is the name of the sendevent, such as CUSTOM, SEND_MESSAGE, NOTIFY Keys with empty values are ignored; appData is optional. If appData is set, "content-length" and "content-type" headers are expected (lower case!).
See https://freeswitch.org/confluence/display/FREESWITCH/mod_event_socket#mod_event_socket-3.9sendmsg for details.
func (*Connection) SendEventNotify ¶
func (h *Connection) SendEventNotify(user, contentType, content string) (*Event, error)
SendEventNotify execute sendevent with NOTIFY event.
--------------------------------------------------
sendevent NOTIFY profile: internal event-string: check-sync content-type: application/simple-message-summary content-length: 2 user: 1005 host: 192.168.10.4 OK
--------------------------------------------------
func (*Connection) SendMsg ¶
func (h *Connection) SendMsg(m MSG, uuid, appData string) (*Event, error)
SendMsg sends messages to FreeSWITCH and returns a response Event.
Examples:
SendMsg(MSG{ "call-command": "hangup", "hangup-cause": "we're done!", }, "", "") SendMsg(MSG{ "call-command": "execute", "execute-app-name": "playback", "execute-app-arg": "/tmp/test.wav", }, "", "")
Keys with empty values are ignored; uuid and appData are optional. If appData is set, a "content-length" header is expected (lower case!).
See https://freeswitch.org/confluence/display/FREESWITCH/mod_event_socket#mod_event_socket-3.9sendmsg for details.
type EVT ¶
EVT is the container used by SendEvent to store event sent to FreeSWITCH. It's support sendevent command only
See https://freeswitch.org/confluence/display/FREESWITCH/mod_event_socket#mod_event_socket-3.9sendmsg for details.
type Event ¶
type Event struct { Header EventHeader // Event headers, key:val Body string // Raw body, available in some events }
Event represents a FreeSWITCH event.
func (*Event) GetInt ¶
GetInt returns an Event value converted to int, or an error if conversion is not possible.
func (*Event) PrettyPrint ¶
func (r *Event) PrettyPrint()
PrettyPrint prints Event headers and body to the standard output.
type EventHeader ¶
type EventHeader map[string]interface{}
EventHeader represents events as a pair of key:value.
type HandleFunc ¶
type HandleFunc func(*Connection)
HandleFunc is the function called on new incoming connections.
type MSG ¶
MSG is the container used by SendMsg to store messages sent to FreeSWITCH. It's supposed to be populated with directives supported by the sendmsg command only, like "call-command: execute".
See https://freeswitch.org/confluence/display/FREESWITCH/mod_event_socket#mod_event_socket-3.9sendmsg for details.