OnCallMediastate soll ausgelöst werden, aber es passiert nie. :
Sicherstellen, dass der Anruf tatsächlich beantwortet wird, bevor erwartet wird, dass OnCallMediastate ausgelöst wird. Überprüfen Sie, ob Medienverhandlungen stattfinden.import pjsua2 as pj
import time
import os
from colorama import Fore
AUDIO_FILE = "./test.wav"
if not os.path.exists(AUDIO_FILE):
print(Fore.RED + f"Error: File {AUDIO_FILE} not found!" + Fore.RESET)
exit(1)
class Account(pj.Account):
def __init__(self):
super().__init__()
self.call = None # Hold active call
def onRegState(self, prm):
print(Fore.RED + f"*** Registration State: {prm.code} - {prm.reason}" + Fore.RESET)
def onIncomingCall(self, prm):
self.call = pj.Call(self, prm.callId)
call_prm = pj.CallOpParam()
print(Fore.GREEN + "*** Incoming call received!" + Fore.RESET)
# Ringing
call_prm.statusCode = 180
self.call.answer(call_prm)
print(Fore.YELLOW + "
time.sleep(2)
# Answer the call
call_prm.statusCode = 200
self.call.answer(call_prm)
print(Fore.GREEN + "
def onCallMediaState(self, prm):
print(Fore.GREEN + "
if not self.call:
print(Fore.RED + "
return
ci = self.call.getInfo() # Get call info
print(Fore.CYAN + f"
for mi in ci.media:
print(Fore.CYAN + f"🎙 Media Type: {mi.type}, Status: {mi.status}" + Fore.RESET)
if mi.type == pj.PJMEDIA_TYPE_AUDIO and mi.status == pj.PJSUA_CALL_MEDIA_ACTIVE:
print(Fore.GREEN + f"
try:
# Create audio player
self.player = pj.AudioMediaPlayer()
self.player.createPlayer(AUDIO_FILE)
# Get call audio media
audioMedia = self.call.getAudioMedia(mi.index)
# Transmit audio to the call
self.player.startTransmit(audioMedia)
print(Fore.GREEN + "
# Play for 10 seconds then hang up
time.sleep(10)
self.call.hangup()
print(Fore.RED + "*** Call ended." + Fore.RESET)
except Exception as e:
print(Fore.RED + f"Error processing media: {e}" + Fore.RESET)
def pjsua2_test():
ep_cfg = pj.EpConfig()
ep = pj.Endpoint()
ep.libCreate()
ep.libInit(ep_cfg)
sipTpConfig = pj.TransportConfig()
sipTpConfig.port = 5060
ep.transportCreate(pj.PJSIP_TRANSPORT_UDP, sipTpConfig)
ep.libStart()
print(Fore.RED + "*** PJSUA2 library started." + Fore.RESET)
sip_domain = "***"
sip_user = "***"
sip_password = "***"
acfg = pj.AccountConfig()
acfg.idUri = f"sip:{sip_user}@{sip_domain}:5060"
acfg.regConfig.registrarUri = f"sip:{sip_domain}:5060"
cred = pj.AuthCredInfo("digest", "*", sip_user, 0, sip_password)
acfg.sipConfig.authCreds.append(cred)
acc = Account()
acc.create(acfg)
print(Fore.RED + "*** SIP account created." + Fore.RESET)
time.sleep(60)
ep.libDestroy()
print(Fore.RED + "*** PJSUA2 library destroyed." + Fore.RESET)
if __name__ == "__main__":
pjsua2_test()
< /code>
Ich habe die folgenden Schritte ausprobiert, um das Problem zu debuggen: < /p>
Verifizierte Anrufregistrierung - Das SIP -Konto registriert erfolgreich, und eingehende Anrufe werden empfangen.
Überprüfte Anrufbeantwortung - Der Anruf wird mit StatusCode = 200 beantwortet, und der Anrufstatus scheint aktiv zu sein. BR /> Überprüfte Medienverhandlungen - Ich habe die SIP -Protokollierung ermöglicht, um festzustellen, ob Medienverhandlungen stattfinden, aber ich konnte keine offensichtlichen Probleme finden. Gedruckte Mediendetails, aber es wird nie in diese Funktion eingetragen. /> Ich hatte erwartet, dass OncallMediastate nach dem Aufruf ausgelöst wird, sodass ich eine Audio -Datei abspielen kann. Diese Funktion wird jedoch nie aufgerufen, und es wird kein Audio übertragen.
Wie kann ich sicherstellen>