Documentation ¶
Overview ¶
Package eventsocket send command and wait return.
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 ¶
- func ListenAndServe(addr string, fn HandleFunc) error
- type Connection
- func (h *Connection) APICreateUUID() (string, error)
- func (h *Connection) APILoadModule(modulename string) (bool, error)
- func (h *Connection) APIModuleExists(modulename string) (bool, error)
- func (h *Connection) APIReloadModule(modulename string) (bool, error)
- func (h *Connection) APIUnloadModule(modulename string) (bool, error)
- func (h *Connection) APPAcd(data string) error
- func (h *Connection) APPAnswer() error
- func (h *Connection) APPBridge(data string) error
- func (h *Connection) APPFifo(data string) error
- func (h *Connection) APPHangup(data string) error
- func (h *Connection) APPPreAnswer() error
- func (h *Connection) APPSet(data string) error
- func (h *Connection) Auth(password string) error
- func (h *Connection) Close()
- func (h *Connection) EVENT()
- func (h *Connection) Execute(appName, appArg string, lock bool) (*Event, error)
- func (h *Connection) ExecuteDptools(appName, appArg string, lock bool) (*Event, error)
- func (h *Connection) ExecuteDptoolsEx(uuid, appName, appArg string) (*Event, error)
- func (h *Connection) ExecuteEx(uuid, appName, appArg string) (*Event, error)
- func (h *Connection) Exit() error
- func (h *Connection) Filter()
- func (h *Connection) FilterDelete()
- func (h *Connection) Hangup(cause string) error
- func (h *Connection) HangupEx(uuid, cause string) (*Event, error)
- func (h *Connection) Linger() error
- func (h *Connection) Log(level string) error
- func (h *Connection) NixEvent(format string, enames ...string) error
- func (h *Connection) NoEvents() error
- func (h *Connection) NoLinger() error
- func (h *Connection) NoLog() error
- func (h *Connection) Nomedia() error
- func (h *Connection) ReadEvent() (*Event, error)
- func (h *Connection) RemoteAddr() net.Addr
- func (h *Connection) Send(command string) (*Event, error)
- func (h *Connection) SendApiCommandSync(cmd string) (string, error)
- func (h *Connection) SendBgapiCommandAsync(cmd string) (uuid string, e error)
- func (h *Connection) SendCommand(cmd string) error
- func (h *Connection) SendCommandEx(cmd string) (*Event, error)
- func (h *Connection) SendEvent()
- func (h *Connection) SendMSG(uuid string, m MSG, content string) (*Event, error)
- func (h *Connection) SendMsg(m MSG, uuid, appData string) (*Event, error)
- func (h *Connection) Unicast() error
- func (h *Connection) Xferext() error
- type Event
- type EventHeader
- type HandleFunc
- type MSG
Constants ¶
This section is empty.
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.Send("connect") // must always start with this ev.PrettyPrint() // print event to the console ... c.Send("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.Send("events plain ALL") // or events json ALL for { ev, _ = c.ReadEvent() ev.PrettyPrint() ... }
func (*Connection) APICreateUUID ¶
func (h *Connection) APICreateUUID() (string, error)
APICreateUUID function. send api command "api create_uuid" and response uuid.
https://freeswitch.org/confluence/display/FREESWITCH/mod_commands#mod_commands-create_uuid
func (*Connection) APILoadModule ¶
func (h *Connection) APILoadModule(modulename string) (bool, error)
func (*Connection) APIModuleExists ¶
func (h *Connection) APIModuleExists(modulename string) (bool, error)
APIModuleExists function. send api command "api module_exists modulename" and response true or false.
https://freeswitch.org/confluence/display/FREESWITCH/mod_commands#mod_commands-module_exists
func (*Connection) APIReloadModule ¶
func (h *Connection) APIReloadModule(modulename string) (bool, error)
func (*Connection) APIUnloadModule ¶
func (h *Connection) APIUnloadModule(modulename string) (bool, error)
func (*Connection) APPAcd ¶
func (h *Connection) APPAcd(data string) error
APPFifo function, dptools fifo.
<action application="fifo" data="myqueue in /tmp/exit-message.wav /tmp/music-on-hold.wav"/>
<action application="fifo" data="myqueue out nowait /tmp/caller-found.wav /tmp/agent-music-on-hold.wav"/>
https://freeswitch.org/confluence/display/FREESWITCH/mod_fifo
func (*Connection) APPAnswer ¶
func (h *Connection) APPAnswer() error
APPAnswer function
<action application="answer"/>
https://freeswitch.org/confluence/display/FREESWITCH/mod_dptools%3A+answer
func (*Connection) APPBridge ¶
func (h *Connection) APPBridge(data string) error
APPBridge function, dptools bridge.
<action application="bridge" data="endpoint/gateway/gateway_name/address"/>
https://freeswitch.org/confluence/display/FREESWITCH/mod_dptools%3A+bridge
func (*Connection) APPFifo ¶
func (h *Connection) APPFifo(data string) error
APPFifo function, dptools fifo.
<action application="fifo" data="myqueue in /tmp/exit-message.wav /tmp/music-on-hold.wav"/>
<action application="fifo" data="myqueue out nowait /tmp/caller-found.wav /tmp/agent-music-on-hold.wav"/>
https://freeswitch.org/confluence/display/FREESWITCH/mod_fifo
func (*Connection) APPHangup ¶
func (h *Connection) APPHangup(data string) error
APPHangup function
<action application="hangup" data="USER_BUSY"/>
https://freeswitch.org/confluence/display/FREESWITCH/mod_dptools%3A+hangup
func (*Connection) APPPreAnswer ¶
func (h *Connection) APPPreAnswer() error
APPAnswer function
<action application="pre_answer"/>
https://freeswitch.org/confluence/display/FREESWITCH/mod_dptools%3A+pre+answer
func (*Connection) APPSet ¶
func (h *Connection) APPSet(data string) error
APPSet function, dptools set.
<action application="set" data="effective_caller_id_number=12345678"/>
https://freeswitch.org/confluence/display/FREESWITCH/mod_dptools%3A+set
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). https://developer.signalwire.com/freeswitch/FreeSWITCH-Explained/Modules/mod_event_socket_1048924/#3911-execute https://developer.signalwire.com/freeswitch/FreeSWITCH-Explained/Modules/mod_dptools_1970333/#-c
3.9.1 Commands
3.9.1.1 execute
Execute("playback", "/tmp/test.wav", false)
func (*Connection) ExecuteDptools ¶
func (h *Connection) ExecuteDptools(appName, appArg string, lock bool) (*Event, error)
ExecuteDptools Execute is a shortcut to SendMsg with call-command: execute without UUID,
suitable for use on outbound event socket connections (acting as server).
Execute("set", "a=b", true)
func (*Connection) ExecuteDptoolsEx ¶
func (h *Connection) ExecuteDptoolsEx(uuid, appName, appArg string) (*Event, error)
ExecuteDptoolsEx is similar to Execute, but takes a UUID and no lock. Suitable for use on inbound event socket connections (acting as client).
func (*Connection) ExecuteEx ¶
func (h *Connection) ExecuteEx(uuid, appName, appArg string) (*Event, error)
ExecuteEx is similar to Execute, but takes a UUID and no lock. Suitable for use on inbound event socket connections (acting as client).
func (*Connection) FilterDelete ¶
func (h *Connection) FilterDelete()
FilterDelete function. filter delete event.
3.7 FilterDelete https://developer.signalwire.com/freeswitch/FreeSWITCH-Explained/Modules/mod_event_socket_1048924#36-filter
func (*Connection) Hangup ¶
func (h *Connection) Hangup(cause string) error
Hangup function.
3.9.1.2 hangup
sendmsg <uuid>
call-command: hangup
hangup-cause: <one of the causes listed below>
https://github.com/signalwire/freeswitch/blob/master/src/switch_channel.c switch_cause_table.
func (*Connection) HangupEx ¶
func (h *Connection) HangupEx(uuid, cause string) (*Event, error)
HangupEx function, hangup with uuid
func (*Connection) Log ¶
func (h *Connection) Log(level string) error
func (*Connection) NixEvent ¶
func (h *Connection) NixEvent(format string, enames ...string) error
NixEvent function.
nixevent <event types | ALL | CUSTOM custom event sub-class>
3.14 nixevent
func (*Connection) NoEvents ¶
func (h *Connection) NoEvents() error
NoEvents function.
3.15 noevents
func (*Connection) NoLinger ¶
func (h *Connection) NoLinger() error
eventsocket send nolinger.
3.4 nolinger
func (*Connection) Nomedia ¶
func (h *Connection) Nomedia() error
Nomedia function.
sendmsg <uuid> call-command: nomedia nomedia-uuid: <noinfo>
3.9.1.4 nomedia
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. `Send("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) Send ¶
func (h *Connection) Send(command string) (*Event, error)
Send sends a single command to the server and returns a Event.
See https://developer.signalwire.com/freeswitch/FreeSWITCH-Explained/Modules/mod_event_socket_1048924#3-command-documentation for details.
func (*Connection) SendApiCommandSync ¶
func (h *Connection) SendApiCommandSync(cmd string) (string, error)
eventsocket send api command return api response body.
3.1 api, blocking mode.
command api: https://developer.signalwire.com/freeswitch/FreeSWITCH-Explained/Modules/mod_event_socket_1048924#31-api
mod_command: https://developer.signalwire.com/freeswitch/FreeSWITCH-Explained/Modules/mod_commands_1966741/#--
func (*Connection) SendBgapiCommandAsync ¶
func (h *Connection) SendBgapiCommandAsync(cmd string) (uuid string, e error)
eventsocket send bgapi command return command reply Job-UUID.
3.2 bgapi, non-blocking mode.
https://developer.signalwire.com/freeswitch/FreeSWITCH-Explained/Modules/mod_commands_1966741/#--
func (*Connection) SendCommand ¶
func (h *Connection) SendCommand(cmd string) error
SendCommand function send command and return send result.
func (*Connection) SendCommandEx ¶
func (h *Connection) SendCommandEx(cmd string) (*Event, error)
SendCommandEx function,return event.
func (*Connection) SendEvent ¶
func (h *Connection) SendEvent()
SendEvent function. send event.
3.8 SendEvent
3.8.1.1 Switch phone MWI led (tested on yealink)
3.8.1.2 Make Snom phones reread their settings from the settings server
3.8.1.3 sendevent examples with a message body
3.8.1.4 SIP Proxy Example
3.8.1.5 Sipura/Linksys/Cisco phone or ATA to resync config with a specified profile URL
3.8.1.6 Example usage for CSTA event:
3.8.1.7 Display a text message on a Snom 370 or Snom 820
func (*Connection) SendMSG ¶
SendMSG function. send msg.
https://freeswitch.org/confluence/display/FREESWITCH/mod_event_socket#mod_event_socket-3.9sendmsg
func (*Connection) SendMsg ¶
func (h *Connection) SendMsg(m MSG, uuid, appData string) (*Event, error)
SendMsg function.
3.9 sendmsg
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".
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://developer.signalwire.com/freeswitch/FreeSWITCH-Explained/Modules/mod_event_socket_1048924#39-sendmsg for details.
func (*Connection) Unicast ¶
func (h *Connection) Unicast() error
Unicast function. unicast is used to hook up mod_spandsp for faxing over a socket.
3.9.1.3 unicast
func (*Connection) Xferext ¶
func (h *Connection) Xferext() error
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.