Models¶
Models representing FreeSWITCH entities
-
class
switchio.models.Call(uuid, session)¶ A collection of sessions which together compose a “phone call”.
-
append(sess)¶ Append a session to this call and update the ref to the last recently added session
-
first¶ A reference to the session making up the initial leg of this call
-
get_peer(sess)¶ Convenience helper which can determine whether sess is one of first or last and returns the other when the former is true
-
hangup()¶ Hangup up this call
-
last¶ A reference to the session making up the final leg of this call
-
-
class
switchio.models.Events(event=None)¶ Event collection which for most intents and purposes should quack like a
collections.deque. Data lookups are delegated to the internal deque of events in lilo order.-
get(key, default=None)¶ Return default if not found Should be faster then handling the key error?
-
pprint(index=0)¶ Print serialized event data in chronological order to stdout
-
update(event)¶ Append an ESL.ESLEvent
-
-
class
switchio.models.Job(future=None, sess_uuid=None, callback=None, event=None, client_id=None, con=None, kwargs={})¶ A background job future. The interface closely matches multiprocessing.pool.AsyncResult.
Parameters: -
done()¶ Return
Trueif this job was successfully cancelled or finished running.
-
fail(resp, *args, **kwargs)¶ Fail this job optionally adding an exception for its result
-
get(timeout=None)¶ Get the result for this job waiting up to timeout seconds. Raises TimeoutError on if job does complete within alotted time.
-
log¶ Local logger instance.
-
ready()¶ Return bool indicating whether job has completed
-
result¶ The final result
-
successful()¶ Return bool determining whether job completed without error
-
update(event)¶ Update job state/data using an event
-
wait(timeout=None)¶ Wait until job has completed or timeout has expired
-
-
exception
switchio.models.JobError¶
-
class
switchio.models.Session(event, event_loop=None, uuid=None, con=None)¶ Session API and state tracking.
-
breakmedia()¶ Stop playback of media on this session and move on in the dialplan.
-
bridge(dest_url=None, profile=None, gateway=None, proxy=None, params=None)¶ Bridge this session using uuid_broadcast (so async). By default the current profile is used to bridge to the SIP Request-URI.
-
broadcast(path, leg='', delay=None, hangup_cause=None)¶ Execute an application async on a chosen leg(s) with optional hangup afterwards. If provided tell FS to schedule the app
delayseconds in the future. Uses either of the uuid_broadcast or sched_broadcast commands.
-
bypass_media(state)¶ Re-invite a bridged node out of the media path for this session
-
clear_tasks()¶ Clear all scheduled tasks for this session.
-
deflect(uri)¶ Send a refer to the client. The only parameter should be the SIP URI to contact (with or without “sip:”):
<action application="deflect" data="sip:someone@somewhere.com" />
-
echo()¶ Echo back all audio recieved.
-
execute(cmd, arg='', params='', loops=1)¶ Execute an application async.
-
get(key, default=None)¶ Get latest event header field for key.
-
hangup(cause='NORMAL_CLEARING')¶ Hangup this session with the provided cause hangup type keyword.
-
host¶ Return the hostname/ip address for the host which this session is currently active
-
is_inbound()¶ Return bool indicating whether this is an inbound session
-
is_outbound()¶ Return bool indicating whether this is an outbound session
-
log¶ Local logger instance.
-
mute(direction='write', level=1)¶ Mute the current session. level determines the degree of comfort noise to generate if > 1.
-
park()¶ Park this session
-
playback(args, start_sample=None, endless=False, leg='aleg', params=None)¶ Playback a file on this session
Parameters:
-
poll(events, timeout=None, return_when='FIRST_COMPLETED')¶ Poll for any of a set of event types to be received for this session.
-
record(action, path, rx_only=True)¶ Record audio from this session to a local file on the slave filesystem using the uuid_record command:
uuid_record <uuid> [start|stop|mask|unmask] <path> [<limit>]
-
recv(name, timeout=None)¶ Return an awaitable which resumes once the event-type
nameis received for this session.
-
respond(response)¶ Respond immediately with the following response code. see the FreeSWITCH respond dialplan application
-
sched_dtmf(delay, sequence, tone_duration=None)¶ Schedule dtmf sequence to be played on this channel.
Parameters:
-
sched_hangup(timeout, cause='NORMAL_CLEARING')¶ Schedule this session to hangup after timeout seconds.
-
send_dtmf(sequence, duration='w')¶ Send a dtmf sequence with constant tone durations
-
setvar(var, value)¶ Set variable to value
-
setvars(params)¶ Set all variables in map params with a single command
-
speak(text, engine='flite', voice='kal', timer_name='')¶ Speak, young switch (alpha).
-
start_record(path, rx_only=False, stereo=False, rate=16000)¶ Record audio from this session to a local file on the slave filesystem using the record_session cmd. By default recordings are sampled at 16kHz.
-
stop_record(path='all', delay=0)¶ Stop recording audio from this session to a local file on the slave filesystem using the stop_record_session cmd.
-
time¶ Time stamp for the most recent received event
-
unmute(**kwargs)¶ Unmute the write buffer for this session
-
unsetvar(var)¶ Unset a channel var.
-
update(event)¶ Update state/data using an ESL.ESLEvent
-
uptime¶ Time elapsed since the Session.create_ev to the most recent received event.
-
-
exception
switchio.models.TimeoutError¶