Documentation ¶
Overview ¶
* Copyright (c) 2020 Percipia * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. * * Contributor(s): * Andrew Querol <aquerol@percipia.com>
* Copyright (c) 2020 Percipia * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. * * Contributor(s): * Andrew Querol <aquerol@percipia.com>
* Copyright (c) 2020 Percipia * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. * * Contributor(s): * Andrew Querol <aquerol@percipia.com>
* Copyright (c) 2020 Percipia * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. * * Contributor(s): * Andrew Querol <aquerol@percipia.com>
* Copyright (c) 2020 Percipia * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. * * Contributor(s): * Andrew Querol <aquerol@percipia.com>
* Copyright (c) 2020 Percipia * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. * * Contributor(s): * Andrew Querol <aquerol@percipia.com>
* Copyright (c) 2020 Percipia * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. * * Contributor(s): * Andrew Querol <aquerol@percipia.com>
* Copyright (c) 2020 Percipia * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. * * Contributor(s): * Andrew Querol <aquerol@percipia.com>
Index ¶
- Constants
- Variables
- func BuildVars(format string, vars map[string]string) string
- func ListenAndServe(address string, handler OutboundHandler) error
- type Conn
- func (c *Conn) AnswerCall(ctx context.Context, uuid string) error
- func (c *Conn) Close()
- func (c *Conn) DebugEvents(w io.Writer) string
- func (c *Conn) DebugOff(id string)
- func (c *Conn) EnableEvents(ctx context.Context, formats ...string) error
- func (c *Conn) EnterpriseOriginateCall(ctx context.Context, background bool, vars map[string]string, bLeg Leg, ...) (*RawResponse, error)
- func (c *Conn) ExitAndClose()
- func (c *Conn) HangupCall(ctx context.Context, uuid, cause string) error
- func (c *Conn) OriginateCall(ctx context.Context, background bool, aLeg, bLeg Leg, vars map[string]string) (*RawResponse, error)
- func (c *Conn) Phrase(ctx context.Context, uuid, macro string, times int, wait bool) (*RawResponse, error)
- func (c *Conn) PhraseWithArg(ctx context.Context, uuid, macro string, argument interface{}, times int, ...) (*RawResponse, error)
- func (c *Conn) Playback(ctx context.Context, uuid, audioArgs string, times int, wait bool) (*RawResponse, error)
- func (c *Conn) RegisterEventListener(channelUUID string, listener EventListener) string
- func (c *Conn) RemoveEventListener(channelUUID string, id string)
- func (c *Conn) Say(ctx context.Context, uuid, audioArgs string, times int, wait bool) (*RawResponse, error)
- func (c *Conn) SendCommand(ctx context.Context, command command.Command) (*RawResponse, error)
- func (c *Conn) Speak(ctx context.Context, uuid, audioArgs string, times int, wait bool) (*RawResponse, error)
- func (c *Conn) WaitForDTMF(ctx context.Context, uuid string) (byte, error)
- type Event
- type EventListener
- type InboundOptions
- type Leg
- type Logger
- type NilLogger
- type NormalLogger
- type Options
- type OutboundHandler
- type OutboundOptions
- type RawResponse
- func (r RawResponse) ChannelUUID() string
- func (r RawResponse) GetHeader(header string) string
- func (r RawResponse) GetReply() string
- func (r RawResponse) GetVariable(variable string) string
- func (r RawResponse) GoString() string
- func (r RawResponse) HasHeader(header string) bool
- func (r RawResponse) IsOk() bool
- func (r RawResponse) String() string
Constants ¶
const ( TypeEventPlain = `text/event-plain` TypeEventJSON = `text/event-json` TypeEventXML = `text/event-xml` TypeReply = `command/reply` TypeAPIResponse = `api/response` TypeAuthRequest = `auth/request` TypeDisconnect = `text/disconnect-notice` )
const EndOfMessage = "\r\n\r\n"
const (
EventListenAll = "ALL"
)
Variables ¶
var DefaultInboundOptions = InboundOptions{ Options: DefaultOptions, Network: "tcp", Password: "ClueCon", AuthTimeout: 5 * time.Second, }
DefaultOutboundOptions - The default options used for creating the inbound connection
var DefaultOptions = Options{ Context: context.Background(), Logger: NormalLogger{}, ExitTimeout: 5 * time.Second, }
DefaultOptions - The default options used for creating the connection
var DefaultOutboundOptions = OutboundOptions{ Options: DefaultOptions, Network: "tcp", ConnectTimeout: 5 * time.Second, ConnectionDelay: 25 * time.Millisecond, }
DefaultOutboundOptions - The default options used for creating the outbound connection
Functions ¶
func BuildVars ¶
BuildVars - A helper that builds channel variable strings to be included in various commands to FreeSWITCH
func ListenAndServe ¶
func ListenAndServe(address string, handler OutboundHandler) error
- TODO: Review if we should have a rate limiting facility to prevent DoS attacks
- For our use it should be fine since we only want to listen on localhost
ListenAndServe - Open a new listener for outbound ESL connections from FreeSWITCH on the specified address with the provided connection handler
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
func Dial ¶
Dial - Connects to FreeSWITCH ESL at the provided address and authenticates with the provided password. onDisconnect is called when the connection is closed either by us, FreeSWITCH, or network error
func (*Conn) AnswerCall ¶
HangupCall - A helper to answer a call synchronously
func (*Conn) Close ¶
func (c *Conn) Close()
Close - Close our connection to FreeSWITCH without sending "exit". Protected by a sync.Once
func (*Conn) DebugEvents ¶
DebugEvents - A helper that will output all events to a logger
func (*Conn) EnableEvents ¶
func (*Conn) EnterpriseOriginateCall ¶
func (c *Conn) EnterpriseOriginateCall(ctx context.Context, background bool, vars map[string]string, bLeg Leg, aLegs ...Leg) (*RawResponse, error)
EnterpriseOriginateCall - Calls the originate function in FreeSWITCH using the enterprise method for calling multiple legs ":_:" If you want variables for each leg independently set them in the aLeg and bLeg strings Arguments: ctx context.Context for supporting context cancellation, background bool should we wait for the origination to complete vars map[string]string, channel variables to be passed to originate for both legs, contained in <> bLeg string The bLeg of the call aLegs ...string variadic argument for each aLeg to call
func (*Conn) ExitAndClose ¶
func (c *Conn) ExitAndClose()
ExitAndClose - Attempt to gracefully send FreeSWITCH "exit" over the ESL connection before closing our connection and stopping. Protected by a sync.Once
func (*Conn) HangupCall ¶
HangupCall - A helper to hangup a call asynchronously
func (*Conn) OriginateCall ¶
func (c *Conn) OriginateCall(ctx context.Context, background bool, aLeg, bLeg Leg, vars map[string]string) (*RawResponse, error)
OriginateCall - Calls the originate function in FreeSWITCH. If you want variables for each leg independently set them in the aLeg and bLeg Arguments: ctx context.Context for supporting context cancellation, background bool should we wait for the origination to complete aLeg, bLeg Leg The aLeg and bLeg of the call respectively vars map[string]string, channel variables to be passed to originate for both legs, contained in {}
func (*Conn) Phrase ¶
func (c *Conn) Phrase(ctx context.Context, uuid, macro string, times int, wait bool) (*RawResponse, error)
Phrase - Executes the mod_dptools phrase app
func (*Conn) PhraseWithArg ¶
func (c *Conn) PhraseWithArg(ctx context.Context, uuid, macro string, argument interface{}, times int, wait bool) (*RawResponse, error)
PhraseWithArg - Executes the mod_dptools phrase app with arguments
func (*Conn) Playback ¶
func (c *Conn) Playback(ctx context.Context, uuid, audioArgs string, times int, wait bool) (*RawResponse, error)
Playback - Executes the mod_dptools playback app
func (*Conn) RegisterEventListener ¶
func (c *Conn) RegisterEventListener(channelUUID string, listener EventListener) string
RegisterEventListener - Registers a new event listener for the specified channel UUID(or EventListenAll). Returns the registered listener ID used to remove it.
func (*Conn) RemoveEventListener ¶
RemoveEventListener - Removes the listener for the specified channel UUID with the listener ID returned from RegisterEventListener
func (*Conn) Say ¶
func (c *Conn) Say(ctx context.Context, uuid, audioArgs string, times int, wait bool) (*RawResponse, error)
Say - Executes the mod_dptools say app
func (*Conn) SendCommand ¶
SendCommand - Sends the specified ESL command to FreeSWITCH with the provided context. Returns the response data and any errors encountered.
type Event ¶
type Event struct { Headers textproto.MIMEHeader Body []byte }
type EventListener ¶
type EventListener func(event *Event)
type InboundOptions ¶
type InboundOptions struct { Options // Generic common options to both Inbound and Outbound Conn Network string // The network type to use, should always be tcp, tcp4, tcp6. Password string // The password used to authenticate with FreeSWITCH. Usually ClueCon OnDisconnect func() // An optional function to be called with the inbound connection gets disconnected AuthTimeout time.Duration // How long to wait for authentication to complete }
InboundOptions - Used to dial a new inbound ESL connection to FreeSWITCH
type Leg ¶
Leg This struct is used to specify the individual legs of a call for the originate helpers
type NormalLogger ¶
type NormalLogger struct{}
func (NormalLogger) Debug ¶
func (l NormalLogger) Debug(format string, args ...interface{})
func (NormalLogger) Error ¶
func (l NormalLogger) Error(format string, args ...interface{})
func (NormalLogger) Info ¶
func (l NormalLogger) Info(format string, args ...interface{})
func (NormalLogger) Warn ¶
func (l NormalLogger) Warn(format string, args ...interface{})
type Options ¶
type Options struct { Context context.Context // This specifies the base running context for the connection. If this context expires all connections will be terminated. Logger Logger // This specifies the logger to be used for any library internal messages. Can be set to nil to suppress everything. ExitTimeout time.Duration // How long should we wait for FreeSWITCH to respond to our "exit" command. 5 seconds is a sane default. }
Options - Generic options for an ESL connection, either inbound or outbound
type OutboundHandler ¶
type OutboundHandler func(ctx context.Context, conn *Conn, connectResponse *RawResponse)
type OutboundOptions ¶
type OutboundOptions struct { Options // Generic common options to both Inbound and Outbound Conn Network string // The network type to listen on, should be tcp, tcp4, or tcp6 ConnectTimeout time.Duration // How long should we wait for FreeSWITCH to respond to our "connect" command. 5 seconds is a sane default. ConnectionDelay time.Duration // How long should we wait after connection to start sending commands. 25ms is the recommended default otherwise we can close the connection before FreeSWITCH finishes starting it on their end. https://github.com/signalwire/freeswitch/pull/636 }
OutboundOptions - Used to open a new listener for outbound ESL connections from FreeSWITCH
func (OutboundOptions) ListenAndServe ¶
func (opts OutboundOptions) ListenAndServe(address string, handler OutboundHandler) error
ListenAndServe - Open a new listener for outbound ESL connections from FreeSWITCH with provided options and handle them with the specified handler
type RawResponse ¶
type RawResponse struct { Headers textproto.MIMEHeader Body []byte }
RawResponse This struct contains all response data from FreeSWITCH
func (RawResponse) ChannelUUID ¶
func (r RawResponse) ChannelUUID() string
ChannelUUID Helper to get the channel UUID. Calls GetHeader internally
func (RawResponse) GetHeader ¶
func (r RawResponse) GetHeader(header string) string
GetHeader Helper function that calls RawResponse.Headers.Get. Result gets passed through url.PathUnescape
func (RawResponse) GetReply ¶
func (r RawResponse) GetReply() string
GetReply Helper to get the Reply text from FreeSWITCH, uses the Reply-Text header primarily. Also will use the body if the Reply-Text header does not exist, this can be the case for TypeAPIResponse
func (RawResponse) GetVariable ¶
func (r RawResponse) GetVariable(variable string) string
GetVariable Helper function to get "Variable_" headers. Calls GetHeader internally
func (RawResponse) GoString ¶
func (r RawResponse) GoString() string
GoString Implement the GoStringer interface for pretty printing (%#v)
func (RawResponse) HasHeader ¶
func (r RawResponse) HasHeader(header string) bool
HasHeader Helper to check if the RawResponse has a header
func (RawResponse) IsOk ¶
func (r RawResponse) IsOk() bool
IsOk Helper to check response status, uses the Reply-Text header primarily. Calls GetReply internally
func (RawResponse) String ¶
func (r RawResponse) String() string
String Implement the Stringer interface for pretty printing
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
* Copyright (c) 2020 Percipia * * This Source Code Form is subject to the terms of the Mozilla Public * License, v.
|
* Copyright (c) 2020 Percipia * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. |
call
* Copyright (c) 2020 Percipia * * This Source Code Form is subject to the terms of the Mozilla Public * License, v.
|
* Copyright (c) 2020 Percipia * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. |
example
|
|
events
* Copyright (c) 2020 Percipia * * This Source Code Form is subject to the terms of the Mozilla Public * License, v.
|
* Copyright (c) 2020 Percipia * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. |
inbound
* Copyright (c) 2020 Percipia * * This Source Code Form is subject to the terms of the Mozilla Public * License, v.
|
* Copyright (c) 2020 Percipia * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. |
outbound
* Copyright (c) 2020 Percipia * * This Source Code Form is subject to the terms of the Mozilla Public * License, v.
|
* Copyright (c) 2020 Percipia * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. |