Using pjsua2 with pytest - Scope problem of EndPoint

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi

I'm trying to set up some tests using pjsua2 and pytest. However I encountered some problems with EndPoints and Accounts. I took the standard pjsua2 Python demo (https://www.pjsip.org/docs/book-latest/html/intro_pjsua2.html#using-in-python-application) and tried to make some structure of it.

The example below works fine. However if I make the created EndPoint object global by removing the "#", then the "onRegState" callback is not called.

Why?

My problem is that if I try to use the same EndPoint for two tests with two different accounts, then my account classes does not work.


import time
import pjsua2 as pj
from pjsua2 import Account

# Subclass to extend the Account and get notifications etc.
class myAccount(Account):
  def onRegState(self, prm):
      print ("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX***OnRegState: " + prm.reason)

def _EndPoint():
        ep_cfg = pj.EpConfig()
        ep_cfg.uaConfig.threadCnt = 0
        # global ep
        ep = pj.Endpoint()
        ep.libCreate()
        ep.libInit(ep_cfg)

        # 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();
        return ep

def account():
  acfg = pj.AccountConfig();
  acfg.idUri = "sip:test@xxxxxxxxx";
  acfg.regConfig.registrarUri = "sip:pjsip.org";
  acfg.idUri = "sip:u1@192.168.2.9:5069";
  acfg.regConfig.registrarUri = "sip:192.168.2.9:5069";
  cred = pj.AuthCredInfo("digest", "*", "test", 0, "pwtest");
  acfg.sipConfig.authCreds.append( cred );
  # Create the account
  acc = myAccount();
  acc.create(acfg);
  return acc

def pjsua2_test():
  e = _EndPoint()
  a = account()
  time.sleep(10);
  return



-- 
-------------------- Med Liberalistiske Hilsner ----------------------
   Civilingeniør, Kjeld Flarup - Mit sind er mere åbent end min tegnebog
   Sofienlundvej 6B, 7560 Hjerm, Tlf: 40 29 41 49
   Den ikke akademiske hjemmeside for liberalismen - www.liberalismen.dk

_______________________________________________
Visit our blog: http://blog.pjsip.org

pjsip mailing list
pjsip@xxxxxxxxxxxxxxx
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org

[Index of Archives]     [Asterisk Users]     [Asterisk App Development]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [Linux API]
  Powered by Linux