ettoreleandrotognoli / python-ami

Python AMI Client
BSD 3-Clause "New" or "Revised" License
107 stars 66 forks source link

Problem with event handling #15

Closed ghost closed 6 years ago

ghost commented 6 years ago

My code:

from asterisk.ami import AMIClient
from asterisk.ami import SimpleAction

client = AMIClient(address='127.0.0.1',port=5038)
client.login(username='username',secret='password')

def event_listener(event,**kwargs):
    print(event)

client.add_event_listener(event_listener, white_list=['EndpointDetail'])

action = SimpleAction(
            'PJSIPShowEndpoint',
            Endpoint='test'
        )

res = client.send_action(action).response

print(event)

How to access the response at print(event)? I want to access the returned data in the main thread.

ettoreleandrotognoli commented 6 years ago

I want write something to help collect events generated by an action, but I don't have time at the moment.

I think you can write something like that for while:

from asterisk.ami import AMIClient
from asterisk.ami import SimpleAction

client = AMIClient(address='127.0.0.1',port=5038)
client.login(username='username',secret='password')

events = []

def event_listener(event,**kwargs):
    events.append(event)

client.add_event_listener(event_listener, white_list=['EndpointDetail'])

action = SimpleAction(
     'PJSIPShowEndpoint',
     Endpoint='test'
)

res = client.send_action(action).response

print(events)
adeshpandey commented 6 years ago

add_event_listener does not catch all the events in the successful action, I am initiating Originate action but none of the events is caught in the case of a successful dial and action exits without waiting for the hangup event in the synchronous call.

ettoreleandrotognoli commented 6 years ago

I don't know what is the problem, can you show some code?

romkazor commented 6 years ago

@adeshpandey No, that's not how it works. For hangup you can catch event Hangup. Close this.