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
- Variables
- func ListenAndServe(addr string, fn HandleFunc) error
- type Connection
- func (h *Connection) Close()
- func (h *Connection) Execute(appName, appArg string, lock bool) ([]string, error)
- func (h *Connection) ExecuteUUID(uuid, appName, appArg, appUUID string) ([]string, error)
- func (h *Connection) ReadEvent() ([]string, error)
- func (h *Connection) RemoteAddr() net.Addr
- func (h *Connection) Send(command string) ([]string, error)
- func (h *Connection) SendMsg(m MSG, uuid, appData string) ([]string, error)
- type Event
- type EventHeader
- type HandleFunc
- type MSG
Constants ¶
const ( AnswerState = iota + 1 Application ApplicationData ApplicationResponse ApplicationUUID CallDirection CallerAni CallerOrigCallerIDNumber CallerDestinationNumber CallerChannelAnsweredTime CallerChannelBridgedTime CallerChannelCreatedTime CallerChannelHangupTime CallerNetworkAddr CallerChannelProgressTime CallerUniqueID ChannelCallState ChannelCallUUID ChannelName ChannelState ChannelStateNumber CoreUUID DtmfDigit CustomHeaders UserToUser EventName EventDateGmt EventDateTimeStamp EventSourceIpv4 EventMsgBody EventSubClass HangupCause OtherLegUniqueID OtherLegDestinationNumber OtherLegChannelAnsweredTime OtherLegChannelName RecordFilePath UniqueID VariableCurrentApplication VariableSofiaProfileName VariableDomainName VariableSipCallID VariableSipFullFrom VariableSipFullTo VariableDetectSpeechResult VariableRecordSeconds VariableRecordStereo VariableSipInviteFailureStatus VariableDuration VariableSipHXInfo VariableDTMFResult VariableDTMFResultInvalid VariableBillSec VariablePlaybackTerminatorUsed VariableParentVerb VariableParentID VariableQueueID VariableOriginateSignalBond InstanceHashID // Conference Action ConferenceName ConferenceSize ConferenceUniqueId Floor Hear Hold MemberId MemberType MuteDetect Talking Speak ConfRecPath MillisecondsElapsed )
const FsEventMapSize = 100
Variables ¶
var MapKeyIndex = map[string]int{ "Answer-State": AnswerState, "Application": Application, "Application-Data": ApplicationData, "Application-Response": ApplicationResponse, "Application-Uuid": ApplicationUUID, "Call-Direction": CallDirection, "Caller-Ani": CallerAni, "Caller-Orig-Caller-Id-Number": CallerOrigCallerIDNumber, "Caller-Destination-Number": CallerDestinationNumber, "Caller-Channel-Answered-Time": CallerChannelAnsweredTime, "Caller-Channel-Bridged-Time": CallerChannelBridgedTime, "Caller-Channel-Created-Time": CallerChannelCreatedTime, "Caller-Channel-Hangup-Time": CallerChannelHangupTime, "Caller-Network-Addr": CallerNetworkAddr, "Caller-Channel-Progress-Time": CallerChannelProgressTime, "Caller-Unique-Id": CallerUniqueID, "Channel-Call-State": ChannelCallState, "Channel-Call-Uuid": ChannelCallUUID, "Channel-Name": ChannelName, "Channel-State": ChannelState, "Channel-State-Number": ChannelStateNumber, "Core-Uuid": CoreUUID, "Dtmf-Digit": DtmfDigit, "Event-Name": EventName, "Event-Date-Gmt": EventDateGmt, "Event-Date-Timestamp": EventDateTimeStamp, "Freeswitch-Ipv4": EventSourceIpv4, "Event-Msg-Body": EventMsgBody, "Event-Subclass": EventSubClass, "Hangup-Cause": HangupCause, "Other-Leg-Unique-Id": OtherLegUniqueID, "Other-Leg-Destination-Number": OtherLegDestinationNumber, "Other-Leg-Channel-Answered-Time": OtherLegChannelAnsweredTime, "Other-Leg-Channel-Name": OtherLegChannelName, "Record-File-Path": RecordFilePath, "Unique-Id": UniqueID, "Variable_current_application": VariableCurrentApplication, "Variable_sofia_profile_name": VariableSofiaProfileName, "Variable_domain_name": VariableDomainName, "Variable_sip_call_id": VariableSipCallID, "Variable_sip_full_from": VariableSipFullFrom, "Variable_sip_full_to": VariableSipFullTo, "Variable_detect_speech_result": VariableDetectSpeechResult, "Variable_record_seconds": VariableRecordSeconds, "Variable_record_stereo": VariableRecordStereo, "Variable_sip_invite_failure_status": VariableSipInviteFailureStatus, "Variable_duration": VariableDuration, "Variable_dtmfresultvar": VariableDTMFResult, "Variable_dtmfresultvar_invalid": VariableDTMFResultInvalid, "Variable_billsec": VariableBillSec, "Variable_playback_terminator_used": VariablePlaybackTerminatorUsed, "Variable_parent_verb": VariableParentVerb, "Variable_parent_id": VariableParentID, "Variable_queue_id": VariableQueueID, "Custom-Headers": CustomHeaders, "Variable_sip_h_user-to-user": UserToUser, "Variable_originate_signal_bond": VariableOriginateSignalBond, "VariableInstanceHash": InstanceHashID, "Action": Action, "Conference-Name": ConferenceName, "Conference-Size": ConferenceSize, "Conference-Unique-Id": ConferenceUniqueId, "Floor": Floor, "Hear": Hear, "Hold": Hold, "Member-Id": MemberId, "MemberType": MemberType, "MuteDetect": MuteDetect, "Talking": Talking, "Speak": Speak, "Path": ConfRecPath, "Milliseconds-Elapsed": MillisecondsElapsed, }
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) Execute ¶
func (h *Connection) Execute(appName, appArg string, lock bool) ([]string, 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 http://wiki.freeswitch.org/wiki/Event_Socket#execute for details.
func (*Connection) ExecuteUUID ¶
func (h *Connection) ExecuteUUID(uuid, appName, appArg, appUUID string) ([]string, 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() ([]string, 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) ([]string, error)
Send sends a single command to the server and returns a response Event.
See http://wiki.freeswitch.org/wiki/Event_Socket#Command_Documentation for details.
func (*Connection) SendMsg ¶
func (h *Connection) SendMsg(m MSG, uuid, appData string) ([]string, 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 http://wiki.freeswitch.org/wiki/Event_Socket#sendmsg 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 http://wiki.freeswitch.org/wiki/Event_Socket#sendmsg for details.