wait for any state

_wait_for_multiple_events.wait_for_any_state(state_list, seconds_timeout=120)

Wait for a state change in any of a list of call channel objects.

Required argument:
  • object_list

    a list of call channels.

  • state_list

    this is a list containing the current state of each call channel in object_list.

  • seconds_timeout

    time allocated in seconds to wait for a state change. Default is 120.

This function will also return if an object’s state is IDLE or ERROR when the function is called.

This function will return a list containing the current state of each call channel object supplied in object_list.

Usage example:

from prosody.uas import Error, Hangup, wait_for_any_state

def main(channel, application_instance_id, file_man, my_log, application_parameters):

    # start a call on the outbound channel
    out_channel = channel.ExtraChannel[0]
    if out_channel.start_call('sip:3301@127.0.0.1:5060;user=phone', call_from='bob@1234') is True:

        # get the current state of the two channels
        state = channel.state()
        out_state = out_channel.state()

        # wait for a state change in either channel, e.g.
        # channel going to IDLE or out_channel going to ringing
        state, out_state = wait_for_any_state([channel, out_channel], [state, out_state])

        # the inbound call might have gone IDLE
        if state == channel.State.IDLE:
            raise Hangup('channel state is IDLE')

        if out_state == out_channel.State.RING_OUTGOING:
            # perhaps do something here, e.g. put ringing on the inbound channel
            channel.ring()

        elif out_state == out_channel.State.ANSWERED:
            # do something here, e.g. answer the inbound call
            state = channel.answer()