Created
May 18, 2017 21:28
-
-
Save ettoreleandrotognoli/b9869a2bb8dd61e3e42b614710d95fba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import threading | |
import uuid | |
from asterisk.ami import AMIClient, AMIClientAdapter | |
client = AMIClient() | |
client.login('user', 'password') | |
adapter = AMIClientAdapter(client) | |
end = threading.Event() | |
peers = [] | |
# recebe os eventos de PeerEntry | |
def add_peer_listener(event, **kwargs): | |
peers.append(event) | |
# recebe o evento de PeerlistComplete | |
def end_peer_listener(event, **kwargs): | |
end.set() | |
actionId = uuid.uuid1().hex | |
add_listener = client.add_event_listener(on_PeerEntry=add_peer_listener, ActionID=actionId) | |
end_listener = client.add_event_listener(on_PeerlistComplete=end_peer_listener, ActionID=actionId) | |
future = adapter.Sippeers(ActionID=actionId) | |
# aguarda o PeerlistComplete | |
end.wait() | |
client.remove_event_listener(add_listener) | |
client.remove_event_listener(end_listener) | |
for peer in peers: | |
print peer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment