def resetTrace(self): if self.must_reset_trace_msrp: settings = SIPSimpleSettings() settings.logs.trace_msrp = False settings.save() self.must_reset_trace_msrp = False NotificationCenter().discard_observer(self, name="MSRPTransportTrace")
def _NH_XCAPManagerDidReloadData(self, notification): account = notification.sender.account settings = SIPSimpleSettings() offline_status = notification.data.offline_status status_icon = notification.data.status_icon try: offline_note = next(note for service in offline_status.pidf.services for note in service.notes) except (AttributeError, StopIteration): offline_note = None settings.presence_state.offline_note = offline_note settings.save() if status_icon: icon_hash = hashlib.sha512(status_icon.data).hexdigest() user_icon = UserIcon(status_icon.url, icon_hash) if not settings.presence_state.icon or settings.presence_state.icon.etag != icon_hash: # TODO: convert icon to PNG before saving it self.owner.saveUserIcon(status_icon.data, icon_hash) else: user_icon = None if settings.presence_state.icon: unlink(settings.presence_state.icon.path) settings.presence_state.icon = None settings.save() account.xcap.icon = user_icon account.save() # Cleanup old base64 encoded icons from payload if account.id not in self._cleanedup_accounts: self._cleanup_icons(account)
def _NH_AudioDevicesDidChange(self, notification): old_devices = set(notification.data.old_devices) new_devices = set(notification.data.new_devices) removed_devices = old_devices - new_devices if not removed_devices: return input_device = self.voice_audio_bridge.mixer.input_device output_device = self.voice_audio_bridge.mixer.output_device alert_device = self.alert_audio_bridge.mixer.output_device if self.voice_audio_bridge.mixer.real_input_device in removed_devices: input_device = 'system_default' if new_devices else None if self.voice_audio_bridge.mixer.real_output_device in removed_devices: output_device = 'system_default' if new_devices else None if self.alert_audio_bridge.mixer.real_output_device in removed_devices: alert_device = 'system_default' if new_devices else None self.voice_audio_bridge.mixer.set_sound_devices( input_device, output_device, self.voice_audio_bridge.mixer.ec_tail_length) self.alert_audio_bridge.mixer.set_sound_devices(None, alert_device, 0) settings = SIPSimpleSettings() settings.audio.input_device = self.voice_audio_bridge.mixer.input_device settings.audio.output_device = self.voice_audio_bridge.mixer.output_device settings.audio.alert_device = self.alert_audio_bridge.mixer.output_device settings.save()
def _save_certificates(sip_address, crt, key, ca): crt = crt.strip() + os.linesep key = key.strip() + os.linesep ca = ca.strip() + os.linesep X509Certificate(crt) X509PrivateKey(key) X509Certificate(ca) makedirs(ApplicationData.get('tls')) certificate_path = ApplicationData.get( os.path.join('tls', sip_address + '.crt')) certificate_file = open(certificate_path, 'w') os.chmod(certificate_path, 0600) certificate_file.write(crt + key) certificate_file.close() ca_path = ApplicationData.get(os.path.join('tls', 'ca.crt')) try: existing_cas = open(ca_path).read().strip() + os.linesep except: certificate_file = open(ca_path, 'w') certificate_file.write(ca) certificate_file.close() else: if ca not in existing_cas: certificate_file = open(ca_path, 'w') certificate_file.write(existing_cas + ca) certificate_file.close() settings = SIPSimpleSettings() settings.tls.ca_list = ca_path settings.save() return certificate_path
def save_certificates(self, sip_address, crt, key, ca): crt = crt.strip() + os.linesep key = key.strip() + os.linesep ca = ca.strip() + os.linesep X509Certificate(crt) X509PrivateKey(key) X509Certificate(ca) makedirs(ApplicationData.get('tls')) certificate_path = ApplicationData.get(os.path.join('tls', sip_address+'.crt')) file = open(certificate_path, 'w') os.chmod(certificate_path, 0600) file.write(crt+key) file.close() ca_path = ApplicationData.get(os.path.join('tls', 'ca.crt')) try: existing_cas = open(ca_path).read().strip() + os.linesep except: file = open(ca_path, 'w') file.write(ca) file.close() else: if ca not in existing_cas: file = open(ca_path, 'w') file.write(existing_cas+ca) file.close() settings = SIPSimpleSettings() settings.tls.ca_list = ca_path settings.save() return certificate_path
def _AH_GoogleContactsActionTriggered(self): settings = SIPSimpleSettings() if settings.google_contacts.authorization_token is not None: settings.google_contacts.authorization_token = None settings.save() self.google_contacts_dialog.hide() else: self.google_contacts_dialog.open()
def _NH_SIPApplicationWillStart(self, sender, data): settings = SIPSimpleSettings() settings.user_agent = "%s %s (MacOSX)" % ( NSApp.delegate().applicationName, self._version) BlinkLogger().log_info(u"Initializing SIP SIMPLE Client SDK %s" % sdk_version) build = str(NSBundle.mainBundle().infoDictionary().objectForKey_( "CFBundleVersion")) date = str(NSBundle.mainBundle().infoDictionary().objectForKey_( "BlinkVersionDate")) BlinkLogger().log_info(u"Build %s from %s" % (build, date)) self.migratePasswordsToKeychain() # Set audio settings compatible with AEC and Noise Supressor settings.audio.sample_rate = 16000 settings.audio.tail_length = 15 if settings.audio.enable_aec else 0 settings.save() BlinkLogger().log_info( u"Acoustic Echo Canceller is %s" % ('enabled' if settings.audio.enable_aec else 'disabled')) # Although this setting is set at enrollment time, people who have downloaded previous versions will not have it account_manager = AccountManager() for account in account_manager.iter_accounts(): must_save = False if account is not BonjourAccount( ) and account.sip.primary_proxy is None and account.sip.outbound_proxy and not account.sip.selected_proxy: account.sip.primary_proxy = account.sip.outbound_proxy must_save = True if account is not BonjourAccount( ) and settings.tls.verify_server != account.tls.verify_server: account.tls.verify_server = settings.tls.verify_server must_save = True if account.tls.certificate and os.path.basename( account.tls.certificate.normalized) != 'default.crt': account.tls.certificate = DefaultValue must_save = True if account.id.domain == "sip2sip.info": if account.server.settings_url is None: account.server.settings_url = "https://blink.sipthor.net/settings.phtml" must_save = True if not account.ldap.hostname: account.ldap.hostname = "ldap.sipthor.net" account.ldap.dn = "ou=addressbook, dc=sip2sip, dc=info" account.ldap.enabled = True must_save = True if must_save: account.save() logger = FileLogger() logger.start() self.ip_address_monitor.start()
def _NH_SIPApplicationDidStart(self, sender, data): settings = SIPSimpleSettings() settings.audio.enable_aec = settings.audio.echo_canceller.enabled settings.audio.sound_card_delay = settings.audio.echo_canceller.tail_length self._app.engine.enable_colorbar_device = False BlinkLogger().log_debug("SDK loaded") BlinkLogger().log_debug("SIP device ID: %s" % settings.instance_id) available_codecs_print = list(beautify_audio_codec(codec.decode()) for codec in self._app.engine._ua.available_codecs) codecs_print = list(beautify_audio_codec(codec) for codec in settings.rtp.audio_codec_list) BlinkLogger().log_info("Available audio codecs: %s" % ", ".join(available_codecs_print)) BlinkLogger().log_info("Enabled audio codecs: %s" % ", ".join(codecs_print)) if settings.audio.input_device is None: BlinkLogger().log_info("Switching audio input device to system default") settings.audio.input_device = 'system_default' if settings.audio.output_device is None: BlinkLogger().log_info("Switching audio output device to system default") settings.audio.output_device = 'system_default' if settings.audio.alert_device is None: BlinkLogger().log_info("Switching audio alert device to system default") settings.audio.alert_device = 'system_default' try: from VideoController import VideoController except ImportError: pass else: if settings.video.max_bitrate is not None and settings.video.max_bitrate > 10000: settings.video.max_bitrate = 4.0 available_video_codecs_print = list(beautify_video_codec(codec.decode()) for codec in self._app.engine._ua.available_video_codecs) video_codecs_print = list(beautify_video_codec(codec) for codec in settings.rtp.video_codec_list) BlinkLogger().log_info("Available video codecs: %s" % ", ".join(available_video_codecs_print)) BlinkLogger().log_info("Enabled video codecs: %s" % ", ".join(video_codecs_print)) BlinkLogger().log_info(u"Available video cameras: %s" % ", ".join(NSApp.delegate().video_devices)) if settings.video.device != "system_default" and settings.video.device != self._app.video_device.real_name and self._app.video_device.real_name != None: settings.video.device = self._app.video_device.real_name BlinkLogger().log_info(u"Using video camera %s" % self._app.video_device.real_name) elif settings.video.device is None: devices = list(device for device in self._app.engine.video_devices if device not in ('system_default', None)) if devices: BlinkLogger().log_info("Switching video camera to %s" % devices[0]) settings.video.device = devices[0] else: BlinkLogger().log_info("Using video camera %s" % self._app.video_device.real_name) settings.save() bonjour_account = BonjourAccount() if bonjour_account.enabled: for transport in settings.sip.transport_list: try: BlinkLogger().log_debug('Bonjour Account listens on %s' % bonjour_account.contact[transport]) except KeyError: pass self.init_configurations()
def _NH_VideoDevicesDidChange(self, notification): self.video_camera_menu.clear() # actions will be removed automatically from the action group because they are owned by the menu and only referenced in the action group if self.session_model.active_sessions: added_devices = set(notification.data.new_devices).difference(notification.data.old_devices) if added_devices: settings = SIPSimpleSettings() settings.video.device = added_devices.pop() settings.save() self.load_video_devices()
def windowWillClose_(self, notification): self.captureView.hide() NSApp.stopModalWithCode_(0) settings = SIPSimpleSettings() try: settings.video.auto_rotate_cameras = self.previous_auto_rotate_cameras settings.save() except AttributeError: pass
def _NH_CFGSettingsObjectDidChange(self, account, data): if isinstance(account, Account): if 'message_summary.enabled' in data.modified: if not account.message_summary.enabled: MWIData.remove(account) if 'audio.enable_aec' in data.modified: settings = SIPSimpleSettings() BlinkLogger().log_info(u"Acoustic Echo Canceller is %s" % ('enabled' if settings.audio.enable_aec else 'disabled')) settings.audio.tail_length = 15 if settings.audio.enable_aec else 0 settings.save()
def runModal(self): self.window.makeKeyAndOrderFront_(None) rc = NSApp.runModalForWindow_(self.window) self.window.orderOut_(self) if rc == NSOKButton: note = unicode(self.nameText.stringValue()) settings = SIPSimpleSettings() settings.presence_state.offline_note = note settings.save() return note return None
def runModal(self): self.window.makeKeyAndOrderFront_(None) rc = NSApp.runModalForWindow_(self.window) self.window.orderOut_(self) if rc == NSOKButton: note = str(self.nameText.stringValue()) settings = SIPSimpleSettings() settings.presence_state.offline_note = note settings.save() return note return None
def msrpRadioClicked_(self, sender): trace = sender.selectedCell().tag() settings = SIPSimpleSettings() settings.logs.trace_msrp_in_gui = trace if trace == Disabled: settings.logs.trace_msrp = settings.logs.trace_msrp_to_file elif trace == Simplified: settings.logs.trace_msrp = True elif trace == Full: settings.logs.trace_msrp = True settings.save()
def _NH_SIPApplicationDidStart(self, notification): settings = SIPSimpleSettings() if settings.presence_state.timestamp is None: settings.presence_state.timestamp = ISOTimestamp.now() settings.save() self.get_location([account for account in AccountManager().iter_accounts() if account is not BonjourAccount()]) self.publish() idle_timer = NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_(1.0, self, "updateIdleTimer:", None, True) NSRunLoop.currentRunLoop().addTimer_forMode_(idle_timer, NSRunLoopCommonModes) NSRunLoop.currentRunLoop().addTimer_forMode_(idle_timer, NSEventTrackingRunLoopMode)
def notificationsCheckboxClicked_(self, sender): settings = SIPSimpleSettings() settings.logs.trace_notifications_in_gui = bool(sender.state()) settings.logs.trace_notifications = settings.logs.trace_notifications_in_gui or settings.logs.trace_notifications_to_file settings.save() notification_center = NotificationCenter() if settings.logs.trace_notifications_in_gui: notification_center.add_observer(self) else: notification_center.discard_observer(self)
def _NH_CFGSettingsObjectDidChange(self, account, data): if isinstance(account, Account): if 'message_summary.enabled' in data.modified: if not account.message_summary.enabled: MWIData.remove(account) if 'audio.enable_aec' in data.modified: settings = SIPSimpleSettings() BlinkLogger().log_info( u"Acoustic Echo Canceller is %s" % ('enabled' if settings.audio.enable_aec else 'disabled')) settings.audio.tail_length = 15 if settings.audio.enable_aec else 0 settings.save()
def _NH_AudioDevicesDidChange(self, notification): self.output_device_menu.clear() # because actions are owned by the menu and only referenced by their corresponding action groups, self.input_device_menu.clear() # clearing the menus will result in the actions automatically disappearing from the corresponding self.alert_device_menu.clear() # action groups as well if self.session_model.active_sessions: added_devices = set(notification.data.new_devices).difference(notification.data.old_devices) if added_devices: new_device = added_devices.pop() settings = SIPSimpleSettings() settings.audio.input_device = new_device settings.audio.output_device = new_device settings.save() self.load_audio_devices()
def _NH_SIPApplicationWillStart(self, sender, data): settings = SIPSimpleSettings() settings.user_agent = "%s %s (MacOSX)" % (NSApp.delegate().applicationName, self._version) BlinkLogger().log_info(u"Initializing SIP SIMPLE Client SDK %s" % sdk_version) build = str(NSBundle.mainBundle().infoDictionary().objectForKey_("CFBundleVersion")) date = str(NSBundle.mainBundle().infoDictionary().objectForKey_("BlinkVersionDate")) BlinkLogger().log_info(u"Build %s from %s" % (build, date)) self.migratePasswordsToKeychain() # Set audio settings compatible with AEC and Noise Supressor settings.audio.sample_rate = 16000 settings.audio.tail_length = 15 if settings.audio.enable_aec else 0 settings.save() BlinkLogger().log_info(u"Acoustic Echo Canceller is %s" % ('enabled' if settings.audio.enable_aec else 'disabled')) # Although this setting is set at enrollment time, people who have downloaded previous versions will not have it account_manager = AccountManager() for account in account_manager.iter_accounts(): must_save = False if account is not BonjourAccount() and account.sip.primary_proxy is None and account.sip.outbound_proxy and not account.sip.selected_proxy: account.sip.primary_proxy = account.sip.outbound_proxy must_save = True if account is not BonjourAccount() and settings.tls.verify_server != account.tls.verify_server: account.tls.verify_server = settings.tls.verify_server must_save = True if account.tls.certificate and os.path.basename(account.tls.certificate.normalized) != 'default.crt': account.tls.certificate = DefaultValue must_save = True if account.id.domain == "sip2sip.info": if account.server.settings_url is None: account.server.settings_url = "https://blink.sipthor.net/settings.phtml" must_save = True if not account.ldap.hostname: account.ldap.hostname = "ldap.sipthor.net" account.ldap.dn = "ou=addressbook, dc=sip2sip, dc=info" account.ldap.enabled = True must_save = True if must_save: account.save() logger = FileLogger() logger.start() self.ip_address_monitor.start()
def sipRadioClicked_(self, sender): notification_center = NotificationCenter() trace = sender.selectedCell().tag() settings = SIPSimpleSettings() settings.logs.trace_sip_in_gui = trace if trace == Disabled: notification_center.discard_observer(self, name="DNSLookupTrace") settings.logs.trace_sip = settings.logs.trace_sip_to_file elif trace == Simplified: notification_center.add_observer(self, name="DNSLookupTrace") settings.logs.trace_sip = True elif trace == Full: notification_center.add_observer(self, name="DNSLookupTrace") settings.logs.trace_sip = True settings.save()
def speechRecognizer_didRecognizeCommand_(self, recognizer, command): if command == u'Reject': self.decideForAllSessionRequests(REJECT) self.stopSpeechRecognition() elif command == u'Busy': self.decideForAllSessionRequests(BUSY) self.stopSpeechRecognition() elif command in (u'Accept', u'Answer'): self.decideForAllSessionRequests(ACCEPT) self.stopSpeechRecognition() elif command in (u'Voicemail', u'Answering machine'): settings = SIPSimpleSettings() settings.answering_machine.enabled = not settings.answering_machine.enabled settings.save() if settings.answering_machine.enabled: self.stopSpeechRecognition()
def handle_settings(): settings = SIPSimpleSettings() if request.method == 'GET': # Retrieve settings return jsonify(get_state(settings)) else: # Update settings state = get_json(request) if not state: return error_response(400, 'error processing PUT body') try: set_state(settings, state) except ValueError, e: # TODO: some settings may have been applied, what do we do? return error_response(400, str(e)) settings.save() return jsonify(get_state(settings))
def _NH_VideoDevicesDidChange(self, notification): old_devices = set(notification.data.old_devices) new_devices = set(notification.data.new_devices) removed_devices = old_devices - new_devices if not removed_devices: return device = self.video_device.name if self.video_device.real_name in removed_devices: device = 'system_default' if new_devices else None settings = SIPSimpleSettings() self.video_device.set_camera(device, settings.video.resolution, settings.video.framerate) settings.video.device = self.video_device.name settings.save()
def _set_default_account(self, account): if account is not None and not account.enabled: raise ValueError("account %s is not enabled" % account.id) notification_center = NotificationCenter() settings = SIPSimpleSettings() with self._lock: old_account = self.accounts.get(settings.default_account, None) if account is old_account: return if account is None: settings.default_account = None else: settings.default_account = account.id settings.save() # we need to post the notification in the file-io thread in order to have it serialized after the # SIPAccountManagerDidAddAccount notification that is triggered when the account is saved the first # time, because save is executed in the file-io thread while this runs in the current thread. -Dan call_in_thread('file-io', notification_center.post_notification, 'SIPAccountManagerDidChangeDefaultAccount', sender=self, data=NotificationData(old_account=old_account, account=account))
def startOutgoing(self, is_update): if self.direction == "active": self.sessionController.log_info("Requesting remote screen...") else: self.sessionController.log_info("Offering local screen...") NSBundle.loadNibNamed_owner_("ScreenServerWindow", self) self.statusProgress.startAnimation_(None) self.statusWindow.setTitle_( NSLocalizedString("Screen Sharing with %s", "Window title") % self.sessionController.titleShort) settings = SIPSimpleSettings() if not settings.logs.trace_msrp: settings.logs.trace_msrp = True settings.save() self.must_reset_trace_msrp = True NotificationCenter().add_observer(self, name="MSRPTransportTrace") #self.statusItem.show(self) NotificationCenter().add_observer(self, sender=self.stream.handler) NotificationCenter().add_observer(self, sender=self.stream) self.changeStatus(STREAM_PROPOSING if is_update else STREAM_CONNECTING)
def xcapRadioClicked_(self, sender): notification_center = NotificationCenter() trace = sender.selectedCell().tag() settings = SIPSimpleSettings() settings.logs.trace_xcap_in_gui = trace if trace == Disabled: notification_center.discard_observer(self, name="XCAPManagerDidDiscoverServerCapabilities") notification_center.discard_observer(self, name="XCAPSubscriptionGotNotify") notification_center.discard_observer(self, name="XCAPManagerDidChangeState") settings.logs.trace_xcap = settings.logs.trace_xcap_to_file elif trace == Simplified: notification_center.add_observer(self, name="XCAPManagerDidDiscoverServerCapabilities") notification_center.add_observer(self, name="XCAPManagerDidChangeState") settings.logs.trace_xcap = True elif trace == Full: notification_center.add_observer(self, name="XCAPManagerDidDiscoverServerCapabilities") notification_center.add_observer(self, name="XCAPManagerDidChangeState") notification_center.add_observer(self, name="XCAPSubscriptionGotNotify") settings.logs.trace_xcap = True settings.save()
def _NH_AudioDevicesDidChange(self, notification): for action in self.output_device_menu.actions(): self.output_devices_group.removeAction(action) self.output_device_menu.removeAction(action) for action in self.input_device_menu.actions(): self.input_devices_group.removeAction(action) self.input_device_menu.removeAction(action) for action in self.alert_device_menu.actions(): self.alert_devices_group.removeAction(action) self.alert_device_menu.removeAction(action) if self.session_model.active_sessions: old_devices = set(notification.data.old_devices) new_devices = set(notification.data.new_devices) added_devices = new_devices - old_devices if added_devices: new_device = added_devices.pop() settings = SIPSimpleSettings() settings.audio.input_device = new_device settings.audio.output_device = new_device settings.save() self.load_audio_devices()
def add_certificate_authority(self, ca): # not used anymore, let users add CAs in keychain instead try: X509Certificate(ca) except GNUTLSError as e: BlinkLogger().log_error("Invalid Certificate Authority: %s" % e) return False settings = SIPSimpleSettings() must_save_ca = False if settings.tls.ca_list is not None: ca_path = settings.tls.ca_list.normalized else: tls_folder = ApplicationData.get('tls') if not os.path.exists(tls_folder): os.mkdir(tls_folder, 0o700) ca_path = os.path.join(tls_folder, 'ca.crt') must_save_ca = True try: existing_cas = open(ca_path, "r").read().strip() + os.linesep except: existing_cas = None ca_list = ca else: ca_list = existing_cas if ca in existing_cas else existing_cas + ca if ca_list != existing_cas: f = open(ca_path, "w") os.chmod(ca_path, 0o600) f.write(ca_list) f.close() BlinkLogger().log_debug("Added new Certificate Authority to %s" % ca_path) must_save_ca = True if must_save_ca: settings.tls.ca_list = ca_path settings.save() return True
def _NH_CFGSettingsObjectDidChange(self, account, data): if isinstance(account, Account): if 'message_summary.enabled' in data.modified: if not account.message_summary.enabled: MWIData.remove(account) if 'audio.echo_canceller.enabled' in data.modified: settings = SIPSimpleSettings() settings.audio.sample_rate = 32000 if settings.audio.echo_canceller.enabled and settings.audio.sample_rate not in ('16000', '32000') else 48000 spectrum = settings.audio.sample_rate/1000/2 if settings.audio.sample_rate/1000/2 < 20 else 20 BlinkLogger().log_info("Audio sample rate is set to %dkHz covering 0-%dkHz spectrum" % (settings.audio.sample_rate/1000, spectrum)) BlinkLogger().log_debug("Acoustic Echo Canceller is %s" % ('enabled' if settings.audio.echo_canceller.enabled else 'disabled')) if spectrum >=20: BlinkLogger().log_debug("For studio quality disable the option 'Use ambient noise reduction' in System Preferences > Sound > Input section.") settings.save() elif 'audio.sample_rate' in data.modified: settings = SIPSimpleSettings() spectrum = settings.audio.sample_rate/1000/2 if settings.audio.sample_rate/1000/2 < 20 else 20 if settings.audio.sample_rate == 48000: settings.audio.echo_canceller.enabled = False settings.audio.enable_aec = False settings.save() else: settings.audio.echo_canceller.enabled = True settings.audio.enable_aec = True settings.save()
def _NH_CFGSettingsObjectDidChange(self, account, data): if isinstance(account, Account): if 'message_summary.enabled' in data.modified: if not account.message_summary.enabled: MWIData.remove(account) if 'audio.echo_canceller.enabled' in data.modified: settings = SIPSimpleSettings() settings.audio.sample_rate = 32000 if settings.audio.echo_canceller.enabled and settings.audio.sample_rate not in ('16000', '32000') else 48000 spectrum = settings.audio.sample_rate/1000/2 if settings.audio.sample_rate/1000/2 < 20 else 20 BlinkLogger().log_info(u"Audio sample rate is set to %dkHz covering 0-%dkHz spectrum" % (settings.audio.sample_rate/1000, spectrum)) BlinkLogger().log_info(u"Acoustic Echo Canceller is %s" % ('enabled' if settings.audio.echo_canceller.enabled else 'disabled')) if spectrum >=20: BlinkLogger().log_info(u"For studio quality disable the option 'Use ambient noise reduction' in System Preferences > Sound > Input section.") settings.save() elif 'audio.sample_rate' in data.modified: settings = SIPSimpleSettings() spectrum = settings.audio.sample_rate/1000/2 if settings.audio.sample_rate/1000/2 < 20 else 20 if settings.audio.sample_rate == 48000: settings.audio.echo_canceller.enabled = False settings.audio.enable_aec = False settings.save() else: settings.audio.echo_canceller.enabled = True settings.audio.enable_aec = True settings.save()
def _NH_SIPApplicationWillStart(self, sender, data): settings = SIPSimpleSettings() _version = str(NSBundle.mainBundle().infoDictionary().objectForKey_("CFBundleShortVersionString")) settings.user_agent = "%s %s (MacOSX)" % (NSApp.delegate().applicationName, _version) BlinkLogger().log_info(u"SIP User Agent: %s" % settings.user_agent) self.migratePasswordsToKeychain() self.cleanupIcons() # Set audio settings compatible with AEC and Noise Supressor settings.audio.sample_rate = 32000 if settings.audio.echo_canceller.enabled else 48000 if NSApp.delegate().applicationName == 'SIP2SIP': settings.service_provider.help_url = 'http://wiki.sip2sip.info' settings.service_provider.name = 'SIP2SIP' settings.save() BlinkLogger().log_info(u"Audio engine sampling rate %dKHz covering 0-%dKHz spectrum" % (settings.audio.sample_rate/1000, settings.audio.sample_rate/1000/2)) BlinkLogger().log_info(u"Acoustic Echo Canceller is %s" % ('enabled' if settings.audio.echo_canceller.enabled else 'disabled')) # Although this setting is set at enrollment time, people who have downloaded previous versions will not have it account_manager = AccountManager() for account in account_manager.iter_accounts(): must_save = False if account is not BonjourAccount() and account.sip.primary_proxy is None and account.sip.outbound_proxy and not account.sip.selected_proxy: account.sip.primary_proxy = account.sip.outbound_proxy must_save = True if account is not BonjourAccount() and settings.tls.verify_server != account.tls.verify_server: account.tls.verify_server = settings.tls.verify_server must_save = True if account.tls.certificate and os.path.basename(account.tls.certificate.normalized) != 'default.crt': account.tls.certificate = DefaultValue must_save = True if must_save: account.save() logger = FileLogger() logger.start() self.ip_address_monitor.start()
def default_account(self, account): if account is not None and not account.enabled: raise ValueError("account %s is not enabled" % account.id) notification_center = NotificationCenter() settings = SIPSimpleSettings() with self._lock: old_account = self.accounts.get(settings.default_account, None) if account is old_account: return if account is None: settings.default_account = None else: settings.default_account = account.id settings.save() # we need to post the notification in the file-io thread in order to have it serialized after the # SIPAccountManagerDidAddAccount notification that is triggered when the account is saved the first # time, because save is executed in the file-io thread while this runs in the current thread. -Dan call_in_thread('file-io', notification_center.post_notification, 'SIPAccountManagerDidChangeDefaultAccount', sender=self, data=NotificationData(old_account=old_account, account=account))
def init_configurations(self): account_manager = AccountManager() settings = SIPSimpleSettings() # fixup default account self._selected_account = account_manager.default_account if self._selected_account is None: self._selected_account = account_manager.get_accounts()[0] # save default ca if needed ca = open(Resources.get('ca.crt'), "r").read().strip() try: X509Certificate(ca) except GNUTLSError as e: BlinkLogger().log_error("Invalid Certificate Authority: %s" % e) return tls_folder = ApplicationData.get('tls') if not os.path.exists(tls_folder): os.mkdir(tls_folder, 0o700) ca_path = os.path.join(tls_folder, 'ca.crt') try: existing_cas = open(ca_path, "r").read().strip() except Exception: existing_cas = None if ca == existing_cas: return with open(ca_path, "wb") as f: os.chmod(ca_path, 0o600) f.write(ca.encode()) BlinkLogger().log_debug("Added default Certificate Authority to %s" % ca_path) settings.tls.ca_list = ca_path settings.save()
def __init__(self, storage_folder=ApplicationData.get('photos'), high_res=False, history=True): self.history = history NSBundle.loadNibNamed_owner_("PhotoPicker", self) self.captureButton.setHidden_(True) self.previewButton.setHidden_(False) self.countdownCheckbox.setHidden_(True) self.mirrorButton.setHidden_(True) self.storage_folder = storage_folder self.high_res = high_res settings = SIPSimpleSettings() try: self.previous_auto_rotate_cameras = settings.video.auto_rotate_cameras settings.video.auto_rotate_cameras = False settings.save() except AttributeError: pass if self.high_res: self.photoView.setCropSize_() if not self.history: self.tabView.selectTabViewItem_(self.cameraTabView) self.previewButton.setHidden_(True) #self.countdownCheckbox.setHidden_(False) self.mirrorButton.setHidden_(False) self.captureButton.setHidden_(False) self.notification_center = NotificationCenter() self.notification_center.add_observer( self, name="VideoDeviceDidChangeCamera") self.notification_center.add_observer(self, name="CameraSnapshotDidSucceed")
def _NH_SIPApplicationWillStart(self, sender, data): settings = SIPSimpleSettings() _version = str(NSBundle.mainBundle().infoDictionary().objectForKey_("CFBundleShortVersionString")) settings.user_agent = "%s %s (MacOSX)" % (NSApp.delegate().applicationName, _version) BlinkLogger().log_debug("SIP User Agent: %s" % settings.user_agent) settings.save() self.migratePasswordsToKeychain() self.cleanupIcons() # Set audio settings compatible with AEC and Noise Suppression settings.audio.sample_rate = 32000 if settings.audio.echo_canceller.enabled else 48000 if NSApp.delegate().service_provider_help_url and settings.service_provider.help_url != NSApp.delegate().service_provider_help_url: settings.service_provider.help_url = NSApp.delegate().service_provider_help_url settings.save() if NSApp.delegate().service_provider_name and settings.service_provider.name != NSApp.delegate().service_provider_name: settings.service_provider.name = NSApp.delegate().service_provider_name settings.save() BlinkLogger().log_debug("Audio engine sampling rate %dKHz covering 0-%dKHz spectrum" % (settings.audio.sample_rate/1000, settings.audio.sample_rate/1000/2)) BlinkLogger().log_debug("Acoustic Echo Canceller is %s" % ('enabled' if settings.audio.echo_canceller.enabled else 'disabled')) account_manager = AccountManager() for account in account_manager.iter_accounts(): must_save = False if account is not BonjourAccount() and account.sip.primary_proxy is None and account.sip.outbound_proxy and not account.sip.selected_proxy: account.sip.primary_proxy = account.sip.outbound_proxy if account is not BonjourAccount() and settings.tls.verify_server != account.tls.verify_server: account.tls.verify_server = settings.tls.verify_server if account.tls.certificate and os.path.basename(account.tls.certificate.normalized) != 'default.crt': account.tls.certificate = DefaultValue if account.rtp.encryption_type == '': account.rtp.encryption.enabled = False elif account.rtp.encryption_type == 'opportunistic': account.rtp.encryption.enabled = True account.rtp.encryption.key_negotiation = 'opportunistic' elif account.rtp.encryption_type == 'sdes_optional': account.rtp.encryption.enabled = True account.rtp.encryption.key_negotiation = 'sdes_optional' elif account.rtp.encryption_type == 'sdes_mandatory': account.rtp.encryption.enabled = True account.rtp.encryption.key_negotiation = 'sdes_mandatory' elif account.rtp.encryption_type == 'zrtp': account.rtp.encryption.enabled = True account.rtp.encryption.key_negotiation = 'zrtp' account.save() logger = FileLogger() logger.start() self.ip_address_monitor.start()
def changeVideoDevice_(self, sender): settings = SIPSimpleSettings() BlinkLogger().log_info('Switching to %s video camera' % sender.representedObject()) settings.video.device = sender.representedObject() settings.save()
def _AH_AutoAcceptFilesTriggered(self, checked): settings = SIPSimpleSettings() settings.file_transfer.auto_accept = checked settings.save()
def _AH_GoogleContactsActionTriggered(self): settings = SIPSimpleSettings() settings.google_contacts.enabled = not settings.google_contacts.enabled settings.save()
def _SH_MuteButtonClicked(self, muted): settings = SIPSimpleSettings() settings.audio.muted = muted settings.save()
def _SH_SilentButtonClicked(self, silent): settings = SIPSimpleSettings() settings.audio.silent = silent settings.save()
def changeVideoDevice_(self, sender): settings = SIPSimpleSettings() settings.video.device = sender.representedObject() settings.save()
def _AH_AudioOutputDeviceChanged(self, action): settings = SIPSimpleSettings() settings.audio.output_device = action.data() settings.save()
def _AH_VideoDeviceChanged(self, action): settings = SIPSimpleSettings() settings.video.device = action.data() settings.save()
def _AH_EnableAnsweringMachineActionTriggered(self, checked): settings = SIPSimpleSettings() settings.answering_machine.enabled = checked settings.save()
existing_cas = None ca_list = ca else: ca_list = existing_cas if ca in existing_cas else existing_cas + ca if ca_list != existing_cas: f = open(ca_path, "w") os.chmod(ca_path, 0600) f.write(ca_list) f.close() BlinkLogger().log_debug(u"Added new Certificate Authority to %s" % ca_path) must_save_ca = True if must_save_ca: settings.tls.ca_list = ca_path settings.save() return True def save_certificates(self, response): passport = response["passport"] address = response["sip_address"] tls_folder = ApplicationData.get('tls') if not os.path.exists(tls_folder): os.mkdir(tls_folder, 0700) ca = passport["ca"].strip() + os.linesep self.add_certificate_authority(ca) crt = passport["crt"].strip() + os.linesep
def engineCheckboxClicked_(self, sender): settings = SIPSimpleSettings() settings.logs.trace_pjsip_in_gui = bool(sender.state()) settings.logs.trace_pjsip = settings.logs.trace_pjsip_in_gui or settings.logs.trace_pjsip_to_file settings.save()
def _AH_AutoAcceptChatActionTriggered(self, checked): settings = SIPSimpleSettings() settings.chat.auto_accept = checked settings.save()
ca_list = ca else: ca_list = existing_cas if ca in existing_cas else existing_cas + ca if ca_list != existing_cas: f = open(ca_path, "w") os.chmod(ca_path, 0600) f.write(ca_list) f.close() BlinkLogger().log_info(u"Added new Certificate Authority to %s" % ca_path) must_save_ca = True if must_save_ca: settings.tls.ca_list = ca_path settings.save() return True def save_certificates(self, response): passport = response["passport"] address = response["sip_address"] tls_folder = ApplicationData.get('tls') if not os.path.exists(tls_folder): os.mkdir(tls_folder, 0700) ca = passport["ca"].strip() + os.linesep self.add_certificate_authority(ca) crt = passport["crt"].strip() + os.linesep
def toggleAutoRotate_(self, sender): settings = SIPSimpleSettings() settings.video.auto_rotate_cameras = not settings.video.auto_rotate_cameras settings.save()
def _AH_ReceivedMessagesSoundActionTriggered(self, checked): settings = SIPSimpleSettings() settings.sounds.play_message_alerts = checked settings.save()