Hello,
We have a very basic Stasis application setup.
exten => 8000,1,noop("Incoming call")
same => n,stasis(hello-world)
same => n,hangup(16)
We’re getting a behaviour we’re trying to understand. When we call in to our stasis app and exit our python app (the ws subscriber), the call terminates after ~5 seconds. This is despite us sending an /answer.
But if we start MoH on the channel id, then exit our python app the call remains in the stasis and will remain there until we can re-open our app.
Attaching our python code for convenience. If we would call on_start_survive() instead of on_start() the call would survive the app crash/restart.
#!/usr/bin/python3
import asyncio
import websockets
import requests
import json
class ARIParser:
def __init__(self):
self.ari = ARIRequester()
def parse_event(self, ari_event : str) -> None:
# ARI Event dictionary
message = json.loads(ari_event)
# Channel id xxxxxxxxxxx.yyyyyy
channel_id = channel_id
if message["type"] == "StasisStart":
""" A new call entered our stasis app """
self.ari.on_start(channel_id)
class ARIRequester:
def on_start(self, channel_id : str) -> None:
""" Answer channel """
r = requests.post(f"http://localhost:8088/ari/channels/{channel_id}/answer", auth=('X', 'Y'))
def on_start_survive(self, channel_id : str) -> None:
""" Answer channel AND start MoH"""
r = requests.post(f"http://localhost:8088/ari/channels/{channel_id}/answer", auth=('X', 'Y'))
r = requests.post(f"http://localhost:8088/ari/channels/{channel_id}/moh?mohClass=default", auth=('X', 'Y'))
async def subscribe():
async with websockets.connect(f"ws://localhost:8088/ari/events?api_key=X:Y&app=hello-world") as websocket:
async for message in websocket:
parser.parse_event(message)
parser = ARIParser()
asyncio.get_event_loop().run_until_complete(subscribe())
What makes the call in our case survive our Python app crash/restart? And what makes it terminate?