Python Client

From ProjectDiaStar

Jump to: navigation, search

Contents

Taipan

The taipan.py module is a Woomera client written in Python. It supports all Woomera request and event messages, including DiaStar specific extensions to the protocol. Applications interact with the library through three classes: Taipan, Event and Call.

A Taipan object is used to create connections to Woomera servers and to listen on these connections for incoming call events. When an incoming call event arrives, Taipan creates a Call object to manage the call and then repackages the event details into an application facing Event object, which it then passes to the application's event handler function. Outbound Call objects must be created explicitly by the application using the Taipan object.

Subversion repository

svn co svn://svn.projectdiastar.org/diastar/trunk/clients/python

Example

#!/usr/bin/python
#
# Demo application for the taipan library.
#
# Multi-media echo test. Answer call and connect media back to the caller.
#

import taipan   # Woomera client


# Handle events from the Woomera client.
# 
def on_event(event):

    if event.cause == taipan.Event.INCOMING:
        event.call.accept()
    elif event.cause == taipan.Event.ACCEPTED:
        event.call.answer()
    elif event.cause == taipan.Event.ANSWERED:
        event.call.updateMedia(event.call.rtp_audio, event.call.rtp_video)
    elif event.cause == taipan.Event.HANGUP:
        pass

  
# Entry point 
print "Using taipan version %s\n" % taipan.VERSION_STRING

# Create Woomera client with our event handler function. 
#
USER_AGENT = 'echo.py/1.0'
client = taipan.Taipan(on_event, USER_AGENT) 

# Connect to server and run work loop. Stop on ctrl-C.
#
try:

    client.listen('127.0.0.1', 42420)      
    client.loop()

except KeyboardInterrupt:

    client.stop()
    print "\nExiting..."

# EOF

API

Taipan

createCall(callid=None)

Create a call object. To create an outbound call the application should call this without a callid and use the new call object's makeCall api to dial out. The woomera server will provide the callid during call setup.

destroyCall(call)

Delete a call object.

listen(host, port)

Connect to the specified Woomera server and request notification of incoming call events

startTimer(seconds, event)

Start a timer. Granularity depends on asyncore.loop timeout.

loop()

Poll for async events and maintain timers.

stop()

Stop polling. Causes loop() to return.

Call

makeCall(src, dst)

Start a new outbound call by establishing a connection to the server.

accept()

Accept a new inbound call by establishing a connection to the server.

answer()

Answer an inbound call. The call must have been successfully accepted.

hangup(reason_code, reason_text)

End the call.

sendDtmf(digits)

Send dtmf digits to an established call.

play(audio_uri, video_uri, overlay, stop_digits, lang='en_US', repeat='1')

Play audio and video to an established call. To play audio or video only, use a empty string for the unused medium.

record(audio_uri, video_uri, stop_digits, beep='yes', max_time='infinite', lang='en_US')

Record audio and video from an established call. To record audio or video only, use a empty string for the unused medium.

stop()

Terminate the current play or record operation.

updateMedia(audio_rtp, video_rtp)

Update the rtp destination(s).

enableToneEvents()

Enable tone detection events.

disableToneEvents()

Disable tone detection events.

enableInfoEvents()

Enable INFO events.

disableInfoEvents()

Disable INFO events.

Events

Common attributes:

  • cause - name of the event e.g. ACCEPTED
  • call - call object associated with the event.

ACCEPTED

ANSWERED

  • connection_type

DTMF

  • digits

ENDPLAY

  • reason -
  • duration - milliseconds

ENDRECORD

  • reason
  • duration - milliseconds

ERROR

  • message

HANGUP

  • reason_code
  • reason_text

INCOMING

  • caller_address
  • called_address
  • called_uri

INFO

  • content_type
  • content

TIMER

  • identifier - application tag

TONE

  • tone - tone name

UPDATED

Personal tools