Skip to content
Snippets Groups Projects
Commit 13f94f29 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk
Browse files

account: add UPnP settings

Change-Id: I55ce4049e63da5bee308ef8a983aa2bb344e18ec
parent 47034ff6
Branches
No related tags found
No related merge requests found
...@@ -151,6 +151,8 @@ internal enum L10n { ...@@ -151,6 +151,8 @@ internal enum L10n {
internal static let turnUsername = L10n.tr("Localizable", "accountPage.turnUsername", fallback: "TURN username") internal static let turnUsername = L10n.tr("Localizable", "accountPage.turnUsername", fallback: "TURN username")
/// UNBLOCK /// UNBLOCK
internal static let unblockContact = L10n.tr("Localizable", "accountPage.unblockContact", fallback: "UNBLOCK") internal static let unblockContact = L10n.tr("Localizable", "accountPage.unblockContact", fallback: "UNBLOCK")
/// Use UPnP
internal static let upnpEnabled = L10n.tr("Localizable", "accountPage.upnpEnabled", fallback: "Use UPnP")
/// username: not registered /// username: not registered
internal static let usernameNotRegistered = L10n.tr("Localizable", "accountPage.usernameNotRegistered", fallback: "username: not registered") internal static let usernameNotRegistered = L10n.tr("Localizable", "accountPage.usernameNotRegistered", fallback: "username: not registered")
/// Enter desired username /// Enter desired username
......
...@@ -622,6 +622,30 @@ class MeViewController: EditProfileViewController, StoryboardBased, ViewModelBas ...@@ -622,6 +622,30 @@ class MeViewController: EditProfileViewController, StoryboardBased, ViewModelBas
}) })
.disposed(by: cell.disposeBag) .disposed(by: cell.disposeBag)
return cell return cell
case .upnpEnabled:
let cell = DisposableCell()
cell.backgroundColor = UIColor.jamiBackgroundColor
cell.textLabel?.text = L10n.AccountPage.upnpEnabled
let switchView = UISwitch()
cell.selectionStyle = .none
cell.accessoryType = UITableViewCell.AccessoryType.disclosureIndicator
cell.accessoryView = switchView
self.viewModel.upnpEnabled
.asObservable()
.startWith(self.viewModel.upnpEnabled.value)
.observe(on: MainScheduler.instance)
.bind(to: switchView.rx.value)
.disposed(by: cell.disposeBag)
switchView.rx
.isOn.changed
.debounce(Durations.switchThrottlingDuration.toTimeInterval(), scheduler: MainScheduler.instance)
.distinctUntilChanged()
.asObservable()
.subscribe(onNext: {[weak self] enable in
self?.viewModel.enableUpnp(enable: enable)
})
.disposed(by: cell.disposeBag)
return cell
case .turnServer: case .turnServer:
let cell = self let cell = self
.configureTurnCell(cellType: .turnServer, .configureTurnCell(cellType: .turnServer,
......
...@@ -63,6 +63,7 @@ enum SettingsSection: SectionModelType { ...@@ -63,6 +63,7 @@ enum SettingsSection: SectionModelType {
case turnUsername case turnUsername
case turnPassword case turnPassword
case turnRealm case turnRealm
case upnpEnabled
} }
var items: [SectionRow] { var items: [SectionRow] {
...@@ -241,7 +242,8 @@ class MeViewModel: ViewModel, Stateable { ...@@ -241,7 +242,8 @@ class MeViewModel: ViewModel, Stateable {
.turnServer, .turnServer,
.turnUsername, .turnUsername,
.turnPassword, .turnPassword,
.turnRealm])) .turnRealm,
.upnpEnabled]))
}() }()
lazy var otherJamiSettings: Observable<SettingsSection> = { lazy var otherJamiSettings: Observable<SettingsSection> = {
...@@ -804,6 +806,13 @@ class MeViewModel: ViewModel, Stateable { ...@@ -804,6 +806,13 @@ class MeViewModel: ViewModel, Stateable {
turnEnabled.accept(enable) turnEnabled.accept(enable)
} }
func enableUpnp(enable: Bool) {
guard self.upnpEnabled.value != enable,
let account = self.accountService.currentAccount else { return }
self.accountService.enableUpnp(enable: enable, accountId: account.id)
upnpEnabled.accept(enable)
}
func enableKeepAlive(enable: Bool) { func enableKeepAlive(enable: Bool) {
guard self.keepAliveEnabled.value != enable, guard self.keepAliveEnabled.value != enable,
let account = self.accountService.currentAccount else { return } let account = self.accountService.currentAccount else { return }
...@@ -821,6 +830,16 @@ class MeViewModel: ViewModel, Stateable { ...@@ -821,6 +830,16 @@ class MeViewModel: ViewModel, Stateable {
} }
return BehaviorRelay<Bool>(value: true) return BehaviorRelay<Bool>(value: true)
}() }()
lazy var upnpEnabled: BehaviorRelay<Bool> = {
if let account = self.accountService.currentAccount,
let details = account.details {
let enable = details.get(withConfigKeyModel:
ConfigKeyModel.init(withKey: .accountUpnpEnabled)).boolValue
return BehaviorRelay<Bool>(value: enable)
}
return BehaviorRelay<Bool>(value: true)
}()
let turnServer = BehaviorRelay<String>(value: "") let turnServer = BehaviorRelay<String>(value: "")
let turnUsername = BehaviorRelay<String>(value: "") let turnUsername = BehaviorRelay<String>(value: "")
let turnPassword = BehaviorRelay<String>(value: "") let turnPassword = BehaviorRelay<String>(value: "")
......
...@@ -286,6 +286,7 @@ ...@@ -286,6 +286,7 @@
"accountPage.turnUsername" = "TURN username"; "accountPage.turnUsername" = "TURN username";
"accountPage.turnPassword" = "TURN password"; "accountPage.turnPassword" = "TURN password";
"accountPage.turnRealm" = "TURN realm"; "accountPage.turnRealm" = "TURN realm";
"accountPage.upnpEnabled" = "Use UPnP";
//Account //Account
"account.sipUsername" = "User Name"; "account.sipUsername" = "User Name";
......
...@@ -941,6 +941,10 @@ class AccountsService: AccountAdapterDelegate { ...@@ -941,6 +941,10 @@ class AccountsService: AccountAdapterDelegate {
self.switchAccountPropertyTo(state: enable, accountId: accountId, property: ConfigKeyModel(withKey: ConfigKey.turnEnable)) self.switchAccountPropertyTo(state: enable, accountId: accountId, property: ConfigKeyModel(withKey: ConfigKey.turnEnable))
} }
func enableUpnp(enable: Bool, accountId: String) {
self.switchAccountPropertyTo(state: enable, accountId: accountId, property: ConfigKeyModel(withKey: ConfigKey.accountUpnpEnabled))
}
func setTurnSettings(accountId: String, server: String, username: String, password: String, realm: String) { func setTurnSettings(accountId: String, server: String, username: String, password: String, realm: String) {
let details = self.getAccountDetails(fromAccountId: accountId) let details = self.getAccountDetails(fromAccountId: accountId)
details.set(withConfigKeyModel: ConfigKeyModel(withKey: ConfigKey.turnServer), withValue: server) details.set(withConfigKeyModel: ConfigKeyModel(withKey: ConfigKey.turnServer), withValue: server)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment