accountsetting.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. #
  2. # pjsua Python GUI Demo
  3. #
  4. # Copyright (C)2013 Teluu Inc. (http://www.teluu.com)
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. #
  20. import sys
  21. if sys.version_info[0] >= 3: # Python 3
  22. import tkinter as tk
  23. from tkinter import ttk
  24. from tkinter import messagebox as msgbox
  25. else:
  26. import Tkinter as tk
  27. import tkMessageBox as msgbox
  28. import ttk
  29. import pjsua2 as pj
  30. import endpoint
  31. import application
  32. class Dialog(tk.Toplevel):
  33. """
  34. This implements account settings dialog to manipulate account settings.
  35. """
  36. def __init__(self, parent, cfg):
  37. tk.Toplevel.__init__(self, parent)
  38. self.transient(parent)
  39. self.parent = parent
  40. self.geometry("+100+100")
  41. self.title('Account settings')
  42. self.frm = ttk.Frame(self)
  43. self.frm.pack(expand='yes', fill='both')
  44. self.isOk = False
  45. self.cfg = cfg
  46. self.createWidgets()
  47. def doModal(self):
  48. if self.parent:
  49. self.parent.wait_window(self)
  50. else:
  51. self.wait_window(self)
  52. return self.isOk
  53. def createWidgets(self):
  54. # The notebook
  55. self.frm.rowconfigure(0, weight=1)
  56. self.frm.rowconfigure(1, weight=0)
  57. self.frm.columnconfigure(0, weight=1)
  58. self.frm.columnconfigure(1, weight=1)
  59. self.wTab = ttk.Notebook(self.frm)
  60. self.wTab.grid(column=0, row=0, columnspan=2, padx=10, pady=10, ipadx=20, ipady=20, sticky=tk.N+tk.S+tk.W+tk.E)
  61. # Main buttons
  62. btnOk = ttk.Button(self.frm, text='Ok', command=self.onOk)
  63. btnOk.grid(column=0, row=1, sticky=tk.E, padx=20, pady=10)
  64. btnCancel = ttk.Button(self.frm, text='Cancel', command=self.onCancel)
  65. btnCancel.grid(column=1, row=1, sticky=tk.W, padx=20, pady=10)
  66. # Tabs
  67. self.createBasicTab()
  68. self.createSipTab()
  69. self.createMediaTab()
  70. self.createMediaNatTab()
  71. def createBasicTab(self):
  72. # Prepare the variables to set/receive values from GUI
  73. self.cfgPriority = tk.IntVar(value=self.cfg.priority)
  74. self.cfgAccId = tk.StringVar(value=self.cfg.idUri)
  75. self.cfgRegistrar = tk.StringVar(value=self.cfg.regConfig.registrarUri)
  76. self.cfgRegisterOnAdd = tk.BooleanVar(value=self.cfg.regConfig.registerOnAdd)
  77. self.cfgUsername = tk.StringVar()
  78. self.cfgPassword = tk.StringVar()
  79. if len(self.cfg.sipConfig.authCreds):
  80. self.cfgUsername.set( self.cfg.sipConfig.authCreds[0].username )
  81. self.cfgPassword.set( self.cfg.sipConfig.authCreds[0].data )
  82. self.cfgProxy = tk.StringVar()
  83. if len(self.cfg.sipConfig.proxies):
  84. self.cfgProxy.set( self.cfg.sipConfig.proxies[0] )
  85. # Build the tab page
  86. frm = ttk.Frame(self.frm)
  87. frm.columnconfigure(0, weight=1)
  88. frm.columnconfigure(1, weight=2)
  89. row = 0
  90. ttk.Label(frm, text='Priority:').grid(row=row, column=0, sticky=tk.E, pady=2)
  91. tk.Spinbox(frm, from_=0, to=9, textvariable=self.cfgPriority, width=2).grid(row=row, column=1, sticky=tk.W, padx=6)
  92. row += 1
  93. ttk.Label(frm, text='ID (URI):').grid(row=row, column=0, sticky=tk.E, pady=2)
  94. ttk.Entry(frm, textvariable=self.cfgAccId, width=32).grid(row=row, column=1, sticky=tk.W, padx=6)
  95. row += 1
  96. ttk.Label(frm, text='Registrar URI:').grid(row=row, column=0, sticky=tk.E, pady=2)
  97. ttk.Entry(frm, textvariable=self.cfgRegistrar, width=32).grid(row=row, column=1, sticky=tk.W, padx=6)
  98. row += 1
  99. ttk.Checkbutton(frm, text='Register on add', variable=self.cfgRegisterOnAdd).grid(row=row, column=1, sticky=tk.W, padx=6, pady=2)
  100. row += 1
  101. ttk.Label(frm, text='Optional proxy URI:').grid(row=row, column=0, sticky=tk.E, pady=2)
  102. ttk.Entry(frm, textvariable=self.cfgProxy, width=32).grid(row=row, column=1, sticky=tk.W, padx=6)
  103. row += 1
  104. ttk.Label(frm, text='Auth username:').grid(row=row, column=0, sticky=tk.E, pady=2)
  105. ttk.Entry(frm, textvariable=self.cfgUsername, width=16).grid(row=row, column=1, sticky=tk.W, padx=6)
  106. row += 1
  107. ttk.Label(frm, text='Password:').grid(row=row, column=0, sticky=tk.E, pady=2)
  108. ttk.Entry(frm, textvariable=self.cfgPassword, show='*', width=16).grid(row=row, column=1, sticky=tk.W, padx=6, pady=2)
  109. self.wTab.add(frm, text='Basic Settings')
  110. def createSipTab(self):
  111. # Prepare the variables to set/receive values from GUI
  112. self.cfgPrackUse = tk.IntVar(value=self.cfg.callConfig.prackUse)
  113. self.cfgTimerUse = tk.IntVar(value=self.cfg.callConfig.timerUse)
  114. self.cfgTimerExpires = tk.IntVar(value=self.cfg.callConfig.timerSessExpiresSec)
  115. self.cfgPublish = tk.BooleanVar(value=self.cfg.presConfig.publishEnabled)
  116. self.cfgMwiEnabled = tk.BooleanVar(value=self.cfg.mwiConfig.enabled)
  117. self.cfgEnableContactRewrite = tk.BooleanVar(value=self.cfg.natConfig.contactRewriteUse != 0)
  118. self.cfgEnableViaRewrite = tk.BooleanVar(value=self.cfg.natConfig.viaRewriteUse != 0)
  119. self.cfgEnableSdpRewrite = tk.BooleanVar(value=self.cfg.natConfig.sdpNatRewriteUse != 0)
  120. self.cfgEnableSipOutbound = tk.BooleanVar(value=self.cfg.natConfig.sipOutboundUse != 0)
  121. self.cfgKaInterval = tk.IntVar(value=self.cfg.natConfig.udpKaIntervalSec)
  122. # Build the tab page
  123. frm = ttk.Frame(self.frm)
  124. frm.columnconfigure(0, weight=1)
  125. frm.columnconfigure(1, weight=2)
  126. row = 0
  127. ttk.Label(frm, text='100rel/PRACK:').grid(row=row, column=0, sticky=tk.E, pady=2)
  128. ttk.Radiobutton(frm, text='Only offer PRACK', value=pj.PJSUA_100REL_NOT_USED, variable=self.cfgPrackUse).grid(row=row, column=1, sticky=tk.W, padx=6)
  129. row += 1
  130. ttk.Radiobutton(frm, text='Offer and use if remote supports', value=pj.PJSUA_100REL_OPTIONAL, variable=self.cfgPrackUse).grid(row=row, column=1, sticky=tk.W, padx=6)
  131. row += 1
  132. ttk.Radiobutton(frm, text='Required', value=pj.PJSUA_100REL_MANDATORY, variable=self.cfgPrackUse).grid(row=row, column=1, sticky=tk.W, padx=6)
  133. row += 1
  134. ttk.Label(frm, text='Session Timer:').grid(row=row, column=0, sticky=tk.E, pady=2)
  135. ttk.Radiobutton(frm, text='Not offered', value=pj.PJSUA_SIP_TIMER_INACTIVE, variable=self.cfgTimerUse).grid(row=row, column=1, sticky=tk.W, padx=6)
  136. row += 1
  137. ttk.Radiobutton(frm, text='Optional', value=pj.PJSUA_SIP_TIMER_OPTIONAL, variable=self.cfgTimerUse).grid(row=row, column=1, sticky=tk.W, padx=6)
  138. row += 1
  139. ttk.Radiobutton(frm, text='Required', value=pj.PJSUA_SIP_TIMER_REQUIRED, variable=self.cfgTimerUse).grid(row=row, column=1, sticky=tk.W, padx=6)
  140. row += 1
  141. ttk.Radiobutton(frm, text="Always use", value=pj.PJSUA_SIP_TIMER_ALWAYS, variable=self.cfgTimerUse).grid(row=row, column=1, sticky=tk.W, padx=6)
  142. row += 1
  143. ttk.Label(frm, text='Session Timer Expiration:').grid(row=row, column=0, sticky=tk.E, pady=2)
  144. tk.Spinbox(frm, from_=90, to=7200, textvariable=self.cfgTimerExpires, width=5).grid(row=row, column=1, sticky=tk.W, padx=6)
  145. ttk.Label(frm, text='(seconds)').grid(row=row, column=1, sticky=tk.E)
  146. row += 1
  147. ttk.Label(frm, text='Presence:').grid(row=row, column=0, sticky=tk.E, pady=2)
  148. ttk.Checkbutton(frm, text='Enable PUBLISH', variable=self.cfgPublish).grid(row=row, column=1, sticky=tk.W, padx=6, pady=2)
  149. row += 1
  150. ttk.Label(frm, text='Message Waiting Indication:').grid(row=row, column=0, sticky=tk.E, pady=2)
  151. ttk.Checkbutton(frm, text='Enable MWI', variable=self.cfgMwiEnabled).grid(row=row, column=1, sticky=tk.W, padx=6, pady=2)
  152. row += 1
  153. ttk.Label(frm, text='NAT Traversal:').grid(row=row, column=0, sticky=tk.E, pady=2)
  154. ttk.Checkbutton(frm, text='Enable Contact Rewrite', variable=self.cfgEnableContactRewrite).grid(row=row, column=1, sticky=tk.W, padx=6, pady=2)
  155. row += 1
  156. ttk.Checkbutton(frm, text='Enable Via Rewrite', variable=self.cfgEnableViaRewrite).grid(row=row, column=1, sticky=tk.W, padx=6, pady=2)
  157. row += 1
  158. ttk.Checkbutton(frm, text='Enable SDP IP Address Rewrite', variable=self.cfgEnableSdpRewrite).grid(row=row, column=1, sticky=tk.W, padx=6, pady=2)
  159. row += 1
  160. ttk.Checkbutton(frm, text='Enable SIP Outbound Extension', variable=self.cfgEnableSipOutbound).grid(row=row, column=1, sticky=tk.W, padx=6, pady=2)
  161. row += 1
  162. ttk.Label(frm, text='UDP Keep-Alive Interval:').grid(row=row, column=0, sticky=tk.E, pady=2)
  163. tk.Spinbox(frm, from_=0, to=3600, textvariable=self.cfgKaInterval, width=5).grid(row=row, column=1, sticky=tk.W, padx=6)
  164. ttk.Label(frm, text='(seconds) Zero to disable.').grid(row=row, column=1, sticky=tk.E)
  165. self.wTab.add(frm, text='SIP Features')
  166. def createMediaTab(self):
  167. # Prepare the variables to set/receive values from GUI
  168. self.cfgMedPort = tk.IntVar(value=self.cfg.mediaConfig.transportConfig.port)
  169. self.cfgMedPortRange = tk.IntVar(value=self.cfg.mediaConfig.transportConfig.portRange)
  170. self.cfgMedLockCodec = tk.BooleanVar(value=self.cfg.mediaConfig.lockCodecEnabled)
  171. self.cfgMedSrtp = tk.IntVar(value=self.cfg.mediaConfig.srtpUse)
  172. self.cfgMedSrtpSecure = tk.IntVar(value=self.cfg.mediaConfig.srtpSecureSignaling)
  173. self.cfgMedIpv6 = tk.BooleanVar(value=self.cfg.mediaConfig.ipv6Use==pj.PJSUA_IPV6_ENABLED)
  174. # Build the tab page
  175. frm = ttk.Frame(self.frm)
  176. frm.columnconfigure(0, weight=1)
  177. frm.columnconfigure(1, weight=21)
  178. row = 0
  179. ttk.Label(frm, text='Secure RTP (SRTP):').grid(row=row, column=0, sticky=tk.E, pady=2)
  180. ttk.Radiobutton(frm, text='Disable', value=pj.PJMEDIA_SRTP_DISABLED, variable=self.cfgMedSrtp).grid(row=row, column=1, sticky=tk.W, padx=6)
  181. row += 1
  182. ttk.Radiobutton(frm, text='Mandatory', value=pj.PJMEDIA_SRTP_MANDATORY, variable=self.cfgMedSrtp).grid(row=row, column=1, sticky=tk.W, padx=6)
  183. row += 1
  184. ttk.Radiobutton(frm, text='Optional (non-standard)', value=pj.PJMEDIA_SRTP_OPTIONAL, variable=self.cfgMedSrtp).grid(row=row, column=1, sticky=tk.W, padx=6)
  185. row += 1
  186. ttk.Label(frm, text='SRTP signaling:').grid(row=row, column=0, sticky=tk.E, pady=2)
  187. ttk.Radiobutton(frm, text='Does not require secure signaling', value=0, variable=self.cfgMedSrtpSecure).grid(row=row, column=1, sticky=tk.W, padx=6)
  188. row += 1
  189. ttk.Radiobutton(frm, text='Require secure next hop (TLS)', value=1, variable=self.cfgMedSrtpSecure).grid(row=row, column=1, sticky=tk.W, padx=6)
  190. row += 1
  191. ttk.Radiobutton(frm, text='Require secure end-to-end (SIPS)', value=2, variable=self.cfgMedSrtpSecure).grid(row=row, column=1, sticky=tk.W, padx=6)
  192. row += 1
  193. ttk.Label(frm, text='RTP transport start port:').grid(row=row, column=0, sticky=tk.E, pady=2)
  194. tk.Spinbox(frm, from_=0, to=65535, textvariable=self.cfgMedPort, width=5).grid(row=row, column=1, sticky=tk.W, padx=6)
  195. ttk.Label(frm, text='(0: any)').grid(row=row, column=1, sticky=tk.E, pady=2)
  196. row += 1
  197. ttk.Label(frm, text='Port range:').grid(row=row, column=0, sticky=tk.E, pady=2)
  198. tk.Spinbox(frm, from_=0, to=65535, textvariable=self.cfgMedPortRange, width=5).grid(row=row, column=1, sticky=tk.W, padx=6)
  199. ttk.Label(frm, text='(0: not limited)').grid(row=row, column=1, sticky=tk.E, pady=2)
  200. row += 1
  201. ttk.Label(frm, text='Lock codec:').grid(row=row, column=0, sticky=tk.E, pady=2)
  202. ttk.Checkbutton(frm, text='Enable', variable=self.cfgMedLockCodec).grid(row=row, column=1, sticky=tk.W, padx=6, pady=2)
  203. row += 1
  204. ttk.Label(frm, text='Use IPv6:').grid(row=row, column=0, sticky=tk.E, pady=2)
  205. ttk.Checkbutton(frm, text='Yes', variable=self.cfgMedIpv6).grid(row=row, column=1, sticky=tk.W, padx=6, pady=2)
  206. self.wTab.add(frm, text='Media settings')
  207. def createMediaNatTab(self):
  208. # Prepare the variables to set/receive values from GUI
  209. self.cfgSipUseStun = tk.IntVar(value = self.cfg.natConfig.sipStunUse)
  210. self.cfgMediaUseStun = tk.IntVar(value = self.cfg.natConfig.mediaStunUse)
  211. self.cfgIceEnabled = tk.BooleanVar(value = self.cfg.natConfig.iceEnabled)
  212. self.cfgIceAggressive = tk.BooleanVar(value = self.cfg.natConfig.iceAggressiveNomination)
  213. self.cfgAlwaysUpdate = tk.BooleanVar(value = True if self.cfg.natConfig.iceAlwaysUpdate else False)
  214. self.cfgIceNoHostCands = tk.BooleanVar(value = True if self.cfg.natConfig.iceMaxHostCands == 0 else False)
  215. self.cfgTurnEnabled = tk.BooleanVar(value = self.cfg.natConfig.turnEnabled)
  216. self.cfgTurnServer = tk.StringVar(value = self.cfg.natConfig.turnServer)
  217. self.cfgTurnConnType = tk.IntVar(value = self.cfg.natConfig.turnConnType)
  218. self.cfgTurnUser = tk.StringVar(value = self.cfg.natConfig.turnUserName)
  219. self.cfgTurnPasswd = tk.StringVar(value = self.cfg.natConfig.turnPassword)
  220. # Build the tab page
  221. frm = ttk.Frame(self.frm)
  222. frm.columnconfigure(0, weight=1)
  223. frm.columnconfigure(1, weight=2)
  224. row = 0
  225. ttk.Label(frm, text='SIP STUN Usage:').grid(row=row, column=0, sticky=tk.E, pady=2)
  226. ttk.Radiobutton(frm, text='Default', value=pj.PJSUA_STUN_USE_DEFAULT, variable=self.cfgSipUseStun).grid(row=row, column=1, sticky=tk.W, padx=6)
  227. row += 1
  228. ttk.Radiobutton(frm, text='Disable', value=pj.PJSUA_STUN_USE_DISABLED, variable=self.cfgSipUseStun).grid(row=row, column=1, sticky=tk.W, padx=6)
  229. row += 1
  230. ttk.Label(frm, text='Media STUN Usage:').grid(row=row, column=0, sticky=tk.E, pady=2)
  231. ttk.Radiobutton(frm, text='Default', value=pj.PJSUA_STUN_USE_DEFAULT, variable=self.cfgMediaUseStun).grid(row=row, column=1, sticky=tk.W, padx=6)
  232. row += 1
  233. ttk.Radiobutton(frm, text='Disable', value=pj.PJSUA_STUN_USE_DISABLED, variable=self.cfgMediaUseStun).grid(row=row, column=1, sticky=tk.W, padx=6)
  234. row += 1
  235. ttk.Label(frm, text='ICE:').grid(row=row, column=0, sticky=tk.E, pady=2)
  236. ttk.Checkbutton(frm, text='Enable', variable=self.cfgIceEnabled).grid(row=row, column=1, sticky=tk.W, padx=6, pady=2)
  237. row += 1
  238. ttk.Checkbutton(frm, text='Use aggresive nomination', variable=self.cfgIceAggressive).grid(row=row, column=1, sticky=tk.W, padx=6, pady=2)
  239. row += 1
  240. ttk.Checkbutton(frm, text='Always re-INVITE after negotiation', variable=self.cfgAlwaysUpdate).grid(row=row, column=1, sticky=tk.W, padx=6, pady=2)
  241. row += 1
  242. ttk.Checkbutton(frm, text='Disable host candidates', variable=self.cfgIceNoHostCands).grid(row=row, column=1, sticky=tk.W, padx=6, pady=2)
  243. row += 1
  244. ttk.Label(frm, text='TURN:').grid(row=row, column=0, sticky=tk.E, pady=2)
  245. ttk.Checkbutton(frm, text='Enable', variable=self.cfgTurnEnabled).grid(row=row, column=1, sticky=tk.W, padx=6, pady=2)
  246. row += 1
  247. ttk.Label(frm, text='TURN server:').grid(row=row, column=0, sticky=tk.E, pady=2)
  248. ttk.Entry(frm, textvariable=self.cfgTurnServer, width=20).grid(row=row, column=1, sticky=tk.W, padx=6)
  249. ttk.Label(frm, text='host[:port]').grid(row=row, column=1, sticky=tk.E, pady=6)
  250. row += 1
  251. ttk.Label(frm, text='TURN connection:').grid(row=row, column=0, sticky=tk.E, pady=2)
  252. ttk.Radiobutton(frm, text='UDP', value=pj.PJ_TURN_TP_UDP, variable=self.cfgTurnConnType).grid(row=row, column=1, sticky=tk.W, padx=6)
  253. row += 1
  254. ttk.Radiobutton(frm, text='TCP', value=pj.PJ_TURN_TP_TCP, variable=self.cfgTurnConnType).grid(row=row, column=1, sticky=tk.W, padx=6)
  255. row += 1
  256. ttk.Label(frm, text='TURN username:').grid(row=row, column=0, sticky=tk.E, pady=2)
  257. ttk.Entry(frm, textvariable=self.cfgTurnUser, width=16).grid(row=row, column=1, sticky=tk.W, padx=6)
  258. row += 1
  259. ttk.Label(frm, text='TURN password:').grid(row=row, column=0, sticky=tk.E, pady=2)
  260. ttk.Entry(frm, textvariable=self.cfgTurnPasswd, show='*', width=16).grid(row=row, column=1, sticky=tk.W, padx=6)
  261. self.wTab.add(frm, text='NAT settings')
  262. def onOk(self):
  263. # Check basic settings
  264. errors = "";
  265. if not self.cfgAccId.get():
  266. errors += "Account ID is required\n"
  267. if self.cfgAccId.get():
  268. if not endpoint.validateSipUri(self.cfgAccId.get()):
  269. errors += "Invalid SIP ID URI: '%s'\n" % (self.cfgAccId.get())
  270. if self.cfgRegistrar.get():
  271. if not endpoint.validateSipUri(self.cfgRegistrar.get()):
  272. errors += "Invalid SIP registrar URI: '%s'\n" % (self.cfgRegistrar.get())
  273. if self.cfgProxy.get():
  274. if not endpoint.validateSipUri(self.cfgProxy.get()):
  275. errors += "Invalid SIP proxy URI: '%s'\n" % (self.cfgProxy.get())
  276. if self.cfgTurnEnabled.get():
  277. if not self.cfgTurnServer.get():
  278. errors += "TURN server is required\n"
  279. if errors:
  280. msgbox.showerror("Error detected:", errors)
  281. return
  282. # Basic settings
  283. self.cfg.priority = self.cfgPriority.get()
  284. self.cfg.idUri = self.cfgAccId.get()
  285. self.cfg.regConfig.registrarUri = self.cfgRegistrar.get()
  286. self.cfg.regConfig.registerOnAdd = self.cfgRegisterOnAdd.get()
  287. while len(self.cfg.sipConfig.authCreds):
  288. self.cfg.sipConfig.authCreds.pop()
  289. if self.cfgUsername.get():
  290. cred = pj.AuthCredInfo()
  291. cred.scheme = "digest"
  292. cred.realm = "*"
  293. cred.username = self.cfgUsername.get()
  294. cred.data = self.cfgPassword.get()
  295. self.cfg.sipConfig.authCreds.append(cred)
  296. while len(self.cfg.sipConfig.proxies):
  297. self.cfg.sipConfig.proxies.pop()
  298. if self.cfgProxy.get():
  299. self.cfg.sipConfig.proxies.append(self.cfgProxy.get())
  300. # SIP features
  301. self.cfg.callConfig.prackUse = self.cfgPrackUse.get()
  302. self.cfg.callConfig.timerUse = self.cfgTimerUse.get()
  303. self.cfg.callConfig.timerSessExpiresSec = self.cfgTimerExpires.get()
  304. self.cfg.presConfig.publishEnabled = self.cfgPublish.get()
  305. self.cfg.mwiConfig.enabled = self.cfgMwiEnabled.get()
  306. self.cfg.natConfig.contactRewriteUse = 1 if self.cfgEnableContactRewrite.get() else 0
  307. self.cfg.natConfig.viaRewriteUse = 1 if self.cfgEnableViaRewrite.get() else 0
  308. self.cfg.natConfig.sdpNatRewriteUse = 1 if self.cfgEnableSdpRewrite.get() else 0
  309. self.cfg.natConfig.sipOutboundUse = 1 if self.cfgEnableSipOutbound.get() else 0
  310. self.cfg.natConfig.udpKaIntervalSec = self.cfgKaInterval.get()
  311. # Media
  312. self.cfg.mediaConfig.transportConfig.port = self.cfgMedPort.get()
  313. self.cfg.mediaConfig.transportConfig.portRange = self.cfgMedPortRange.get()
  314. self.cfg.mediaConfig.lockCodecEnabled = self.cfgMedLockCodec.get()
  315. self.cfg.mediaConfig.srtpUse = self.cfgMedSrtp.get()
  316. self.cfg.mediaConfig.srtpSecureSignaling = self.cfgMedSrtpSecure.get()
  317. self.cfg.mediaConfig.ipv6Use = pj.PJSUA_IPV6_ENABLED if self.cfgMedIpv6.get() else pj.PJSUA_IPV6_DISABLED
  318. # NAT
  319. self.cfg.natConfig.sipStunUse = self.cfgSipUseStun.get()
  320. self.cfg.natConfig.mediaStunUse = self.cfgMediaUseStun.get()
  321. self.cfg.natConfig.iceEnabled = self.cfgIceEnabled.get()
  322. self.cfg.natConfig.iceAggressiveNomination = self.cfgIceAggressive .get()
  323. self.cfg.natConfig.iceAlwaysUpdate = self.cfgAlwaysUpdate.get()
  324. self.cfg.natConfig.iceMaxHostCands = 0 if self.cfgIceNoHostCands.get() else -1
  325. self.cfg.natConfig.turnEnabled = self.cfgTurnEnabled.get()
  326. self.cfg.natConfig.turnServer = self.cfgTurnServer.get()
  327. self.cfg.natConfig.turnConnType = self.cfgTurnConnType.get()
  328. self.cfg.natConfig.turnUserName = self.cfgTurnUser.get()
  329. self.cfg.natConfig.turnPasswordType = 0
  330. self.cfg.natConfig.turnPassword = self.cfgTurnPasswd.get()
  331. self.isOk = True
  332. self.destroy()
  333. def onCancel(self):
  334. self.destroy()
  335. if __name__ == '__main__':
  336. application.main()