eventsocket

package
v0.0.0-...-d3d516d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 27, 2024 License: MIT Imports: 15 Imported by: 0

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

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) Auth

func (h *Connection) Auth(password string) error

Auth function.

3.11 auth

func (*Connection) Close

func (h *Connection) Close()

Close terminates the connection.

func (*Connection) EVENT

func (h *Connection) EVENT()

EVENT function. suscribe event.

3.5 EVENT https://developer.signalwire.com/freeswitch/FreeSWITCH-Explained/Modules/mod_event_socket_1048924#35-event

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)

https://developer.signalwire.com/freeswitch/FreeSWITCH-Explained/Modules/mod_event_socket_1048924/#3911-execute

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) Exit

func (h *Connection) Exit() error

Exit function.

3.10 exit

func (*Connection) Filter

func (h *Connection) Filter()

Filter function. filter event.

3.6 Filter https://developer.signalwire.com/freeswitch/FreeSWITCH-Explained/Modules/mod_event_socket_1048924#36-filter

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://developer.signalwire.com/freeswitch/FreeSWITCH-Explained/Troubleshooting-Debugging/Hangup-Cause-Code-Table_3964945/#q850-to-sip-code-table

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) NoLog

func (h *Connection) NoLog() error

NoLog function.

3.13 NoLog

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) SendCommand

func (h *Connection) SendCommand(cmd string) error

SendCommand function send command and return send result.

https://developer.signalwire.com/freeswitch/FreeSWITCH-Explained/Modules/mod_event_socket_1048924/#3-command-documentation

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

https://developer.signalwire.com/freeswitch/FreeSWITCH-Explained/Modules/mod_event_socket_1048924/#38-sendevent

func (*Connection) SendMSG

func (h *Connection) SendMSG(uuid string, m MSG, content string) (*Event, error)

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) Get

func (r *Event) Get(key string) string

Get returns an Event value, or "" if the key doesn't exist.

func (*Event) GetInt

func (r *Event) GetInt(key string) (int, error)

GetInt returns an Event value converted to int, or an error if conversion is not possible.

func (*Event) LogPrint

func (r *Event) LogPrint()

func (*Event) PrettyPrint

func (r *Event) PrettyPrint()

PrettyPrint prints Event headers and body to the standard output.

func (*Event) String

func (r *Event) String() string

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

type MSG map[string]string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL