Call center management

I’ll explain the Idea and the architecture then I’ll present the issue

I want to mimic the cellular service provider.
I created a database with users and the amount of seconds I allow them to talk.
For each user I create an extension (using bulk import, “fwconsole bi --type=‘extensions’ new_extension.csv”)
I created an App on the users phone that uses Dart and Flatter and connects to asterisk using WSS, WebRTC
Every 10 sec the app sends an API request (which I call a BIP) and the backend subtract 10 sec from the user’s usage
At the last BIP When a user run out of time I search for the users channel (“asterisk -rx ‘pjsip list channels’”)
and send HANGUP (asterisk -rx ‘channel request hangup PJSIP/xxxx-yyyyyyyy’
I also remove the extension by deleting data directly from the DB
then reload “fwconsole reload” (like pressing on apply settings)

the system works almost great, but
when I add a user more seconds to talk, I re-create the extension
Then I FAILED to perform a good call,
HANGUP CAUSE I noticed are 127, 44, 16 , and sometimes RTP lack of audio after several seconds
I also noticed that the endpoint still exists
“pjsip show endpoints”
also the contacts
“pjsip show contacts”

what is the correct way to achieve my goal and control the connected users?
how do I disconnect the WebSocket of a user?
how do I debug and understand the reason why there is no audio when I re-create an extension I previously deleted?

I use FreePBX
Current PBX Version:
Current System Version: 12.7.8-2011-5.sng7
Asterisk 16.13.0
All modules are up to date

thank you for your help

The Dial() application in Asterisk provides options to limit the length of the call. This might be more direct for you than searching through the channels list to find out what to hang up.

It could be OS level timers affecting TCP timeouts. You might try adjusting those on your server.

On the Asterisk CLI you can run “rtp set debug on” to see exactly the moment it stops. Further examination of the SIP INVITE via “pjsip set debug on” might also help you.