How to wait for registration?

Hello.
I need to wait for registration after I have sent push message from a dialplan (using AGI).

How can I do that, and how reliable the result will be?

I have seen similar question, where OP was advised to use DEVICE_STATE functon.
But I cannot find information - what exactly that function do?
Does it pings a peer in some way?

And is it possible to do the same thing from AGI script (which is called from dialplan)?
Because checking device state inn AGI script is more suitable for me.

But, even if DEVICE_STATE returns device state from some cache, is it possible to wait for sertainly fresh registration?
And by fresh Imean second or two ago.

DEVICE_STATE is documented here[1]. It just retrieves the current device state. There is nothing built in to “wait for a fresh registration”.

[1] DEVICE_STATE - Asterisk Documentation

Thanks for the reply, but it is still unclear.

What does it mean? How it retrieves device state?
Sends a request to the device?
Or checks a local cache for information about last registration?
What exactly the function do?
And can it behaviour be emulated in an AGI program?

It sends no request. It is based on the local state. Whether it is registered, whether it is in a call, if qualify is enabled whether it is reachable.

The dialplan function can be called from an AGI using the GET VARIABLE functionality.

Again, thanks for help.
Could you explain or provide a link do a documentation, where described a method of calling GET VARIABLE from AGI script (I am using python, but i guess it should be possible with other languages).
Should I just write GET VARIABLE <…> to stdout and then read from stdin, or I should do it in some other way?

And which variable should I read to get peer status?

And Is there a way to get time of last registration (preferrably from AGI script)?

I’m using a loop like this:

    performed_loops = 0
    total_loops = 10
    loop_delay = .5

    # Loop timeout in seconds, is determined by multiplying total_loops with loop_delay.
    while performed_loops < total_loops:
        agi.debug_output("***** Loop start")
        found_matching_user_agent = False
        pjsip_aor_count = agi.get_aor_count(endpoint)
        endpoint_contacts = agi.get_enpoint_contacts(endpoint)
        for endpoint_contact in endpoint_contacts:
            contact_user_agent = agi.get_contact_information(endpoint_contact, agi.CONTACT_INFO_USER_AGENT)

            if contact_user_agent is not None:

                if is_expected_user_agent(contact_user_agent):
                    found_matching_user_agent = True
                    break

        if found_matching_user_agent:
            break

        time.sleep(loop_delay)
        performed_loops += 1
        agi.debug_output("***** Loop end")

The contacts are retrieved using
get full variable

Checking the variable PJSIP_AOR to get the contacts for the user, then checking them individually using PJSIP_CONTACT

The above loop also check the user agent, as we want to specifically look for our own softphone application, and for the AGI class used, it’s my own construction, but the function names should be descriptive enough to tell you what you need to do in what order, and I’ve put the relevant information on how to get the information, above.

If you check the contacts BEFORE sending the notification, then enters a loop checking the contacts after it’s sent, you can just compare the before and after lists, to spot new registrations. However, you MIGHT have situations, where the client is already registered before the notification is sent. (Eg. the application is already open on the device) Keep that in mind, and make some sort of escape from you loop, in a relevant maner, either looking for a specific registration, a specific user agent, or just any registration at all.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.