imporvements

pull/560/head
ryanzhao 4 years ago
parent a8b8207154
commit 3de81ef2a0

@ -12,6 +12,7 @@ final class CallVC : UIViewController, WebRTCSessionDelegate {
var shouldAnswer = false var shouldAnswer = false
var isMuted = false var isMuted = false
var isVideoEnabled = false var isVideoEnabled = false
var shouldRestartCamera = true
var conversationVC: ConversationVC? = nil var conversationVC: ConversationVC? = nil
lazy var cameraManager: CameraManager = { lazy var cameraManager: CameraManager = {
@ -181,7 +182,7 @@ final class CallVC : UIViewController, WebRTCSessionDelegate {
view.backgroundColor = .black view.backgroundColor = .black
WebRTCSession.current = webRTCSession WebRTCSession.current = webRTCSession
setUpViewHierarchy() setUpViewHierarchy()
cameraManager.prepare() if shouldRestartCamera { cameraManager.prepare() }
touch(videoCapturer) touch(videoCapturer)
var contact: Contact? var contact: Contact?
Storage.read { transaction in Storage.read { transaction in
@ -192,9 +193,7 @@ final class CallVC : UIViewController, WebRTCSessionDelegate {
callInfoLabel.text = "Ringing..." callInfoLabel.text = "Ringing..."
Storage.write { transaction in Storage.write { transaction in
self.webRTCSession.sendPreOffer(to: self.sessionID, using: transaction).done { self.webRTCSession.sendPreOffer(to: self.sessionID, using: transaction).done {
self.webRTCSession.sendOffer(to: self.sessionID, using: transaction).done { self.webRTCSession.sendOffer(to: self.sessionID, using: transaction).retainUntilComplete()
self.minimizeButton.isHidden = false
}.retainUntilComplete()
}.retainUntilComplete() }.retainUntilComplete()
} }
answerButton.isHidden = true answerButton.isHidden = true
@ -272,18 +271,20 @@ final class CallVC : UIViewController, WebRTCSessionDelegate {
override func viewDidAppear(_ animated: Bool) { override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated) super.viewDidAppear(animated)
if (isVideoEnabled) { cameraManager.start() } if (isVideoEnabled && shouldRestartCamera) { cameraManager.start() }
shouldRestartCamera = true
} }
override func viewWillDisappear(_ animated: Bool) { override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated) super.viewWillDisappear(animated)
if (isVideoEnabled) { cameraManager.stop() } if (isVideoEnabled && shouldRestartCamera) { cameraManager.stop() }
} }
// MARK: Delegate // MARK: Delegate
func webRTCIsConnected() { func webRTCIsConnected() {
DispatchQueue.main.async { DispatchQueue.main.async {
self.callInfoLabel.text = "Connected" self.callInfoLabel.text = "Connected"
self.minimizeButton.isHidden = false
UIView.animate(withDuration: 0.5, delay: 1, options: [], animations: { UIView.animate(withDuration: 0.5, delay: 1, options: [], animations: {
self.callInfoLabel.alpha = 0 self.callInfoLabel.alpha = 0
}, completion: { _ in }, completion: { _ in
@ -339,6 +340,7 @@ final class CallVC : UIViewController, WebRTCSessionDelegate {
} }
@objc private func minimize() { @objc private func minimize() {
self.shouldRestartCamera = false
let miniCallView = MiniCallView(from: self) let miniCallView = MiniCallView(from: self)
miniCallView.show() miniCallView.show()
self.conversationVC?.showInputAccessoryView() self.conversationVC?.showInputAccessoryView()

@ -216,14 +216,6 @@ public final class NotificationServiceExtension : UNNotificationServiceExtension
private func handleSuccessForIncomingCall(for content: UNMutableNotificationContent) { private func handleSuccessForIncomingCall(for content: UNMutableNotificationContent) {
// TODO: poll for the real offer, play incoming call ring // TODO: poll for the real offer, play incoming call ring
if #available(iOSApplicationExtension 13.0, *) {
let request = BGAppRefreshTaskRequest(identifier: "com.loki-project.loki-messenger.refresh")
do {
try BGTaskScheduler.shared.submit(request)
} catch {
print("Could not schedule app refresh: \(error)")
}
}
contentHandler!(content) contentHandler!(content)
} }

@ -7,7 +7,7 @@ public final class Vibration {
private var vibrationTimer: Timer? private var vibrationTimer: Timer?
public func startVibration() { public func startVibration() {
vibrationTimer = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true) { _ in vibrationTimer = Timer.scheduledTimer(withTimeInterval: 2, repeats: true) { _ in
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate) AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
} }
} }

Loading…
Cancel
Save