commons.swift 1.75 KB
Newer Older
jehan's avatar
jehan committed
//FIXME GPL

//  Created by QuentinArguillere on 17/08/2020.
//  Copyright © 2020 BelledonneCommunications. All rights reserved.
//

import Foundation
import linphonesw

jehan's avatar
jehan committed
//FIXME expliquer
func createAndInitializeAccount(core: Core, identity: String, password: String, withVoipPush: Bool = false, withRemotePush: Bool = false) throws -> Account {
	let factory = Factory.Instance
jehan's avatar
jehan committed
	
	let accountParams = try core.createAccountParams()
	let address = try factory.createAddress(addr: identity)
jehan's avatar
jehan committed
	let info = try factory.createAuthInfo(username: address.username, userid: nil, passwd: password, ha1: nil, realm: nil, domain: address.domain)
	try accountParams.setIdentityaddress(newValue: address)
jehan's avatar
jehan committed
	try accountParams.setServeraddr(newValue: "sip:" + address.domain + ";transport=tcp")
	accountParams.registerEnabled = true
	
	// This is necessary to register to the server and handle push Notifications. Make sure you have a certificate to match your app's bundle ID.
	accountParams.pushNotificationConfig?.provider = "apns.dev"
jehan's avatar
jehan committed
	//FIXME + de coomtaires
	accountParams.pushNotificationAllowed = withVoipPush
	accountParams.remotePushNotificationAllowed = withRemotePush
	core.addAuthInfo(info: info)
	return try core.createAccount(params: accountParams)
jehan's avatar
jehan committed

	var logsEnabled : Bool = true {
		didSet {
			LoggingService.Instance.logLevel = logsEnabled ? LogLevel.Debug: LogLevel.Fatal
		   }
	   }

	class LinphoneLoggingServiceImpl: LoggingServiceDelegate {
QuentinArguillere's avatar
QuentinArguillere committed
		func onLogMessageWritten(logService: LoggingService, domain: String, level: LogLevel, message: String) {
jehan's avatar
jehan committed
			print("Linphone logs: \(message)")
jehan's avatar
jehan committed
	init() 	{
		//FIXME commentaires
		LoggingService.Instance.addDelegate(delegate: LinphoneLoggingServiceImpl())
		LoggingService.Instance.logLevel = LogLevel.Debug