Код: Выделить всё
import pjsua2 as pj
import time
class MyAccount(pj.Account):
def onRegState(self, prm):
print("***OnRegState: " + prm.reason)
def onIncomingCall(self, iprm):
call = MyCall(self, iprm.callId)
prm = pj.CallOpParam()
prm.statusCode = 200
call.answer(prm)
class MyCall(pj.Call):
def __init__(self, account, call_id):
pj.Call.__init__(self, account, call_id)
def pjsua2_test():
# Create and initialize the library
ep_cfg = pj.EpConfig()
ep = pj.Endpoint()
ep.libCreate()
ep.libInit(ep_cfg)
ep.audDevManager().setNullDev()
# Create SIP transport. Error handling sample is shown
sipTpConfig = pj.TransportConfig()
sipTpConfig.port = 5060
ep.transportCreate(pj.PJSIP_TRANSPORT_UDP, sipTpConfig)
# Start the library
ep.libStart()
# Account configuration
acfg = pj.AccountConfig()
acfg.idUri = "sip:[email protected]";
acfg.regConfig.registrarUri = "sip:sip.pjsip.org";
cred = pj.AuthCredInfo("digest", "*", "test", 0, "pwtest");
acfg.sipConfig.authCreds.append( cred );
acfg.sipConfig.authCreds.append(cred)
# Create the account
acc = MyAccount()
acc.create(acfg)
return ep, acc # Return the endpoint to keep it alive
if __name__ == "__main__":
ep, acc = pjsua2_test()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
print("Exiting...")
finally:
ep.libDestroy()
На случай, если это интересно, я развернул на Vultr их образ Ubuntu 22.04 и следующий скрипт:
Код: Выделить всё
apt-get update && apt-get install -y build-essential libssl-dev libasound2-dev wget python3 python3-dev automake autoconf libtool libpcre2-dev bison && apt install -y python3-setuptools && cd /usr/src && wget https://github.com/swig/swig/archive/refs/tags/v4.2.1.tar.gz && tar -xvf v4.2.1.tar.gz && cd swig-4.2.1 && ./autogen.sh && ./configure && make && make install && cd /usr/src && wget https://github.com/pjsip/pjproject/archive/refs/tags/2.14.1.tar.gz && tar -xvf 2.14.1.tar.gz && cd pjproject* && ./configure CFLAGS="-fPIC" && make dep && make && make install && cd /usr/src/pjproject*/pjsip-apps/src/swig/python && make && make install && python3 setup.py install
Подробнее здесь: https://stackoverflow.com/questions/788 ... eved-calls