     @IBOutlet weak var muteSwitch: UISwitch!
     @IBOutlet weak var speakerSwitch: UISwitch!
     
-    var deviceTokenString:String?
-
-    var voipRegistry:PKPushRegistry
+    var deviceTokenString: String?
+
+    var voipRegistry: PKPushRegistry
 
     var isSpinning: Bool
     var incomingAlertController: UIAlertController?
 
-    var callInvite:TVOCallInvite?
-    var call:TVOCall?
+    var callInvite: TVOCallInvite?
+    var call: TVOCall?
     var callKitCompletionCallback: ((Bool)->Swift.Void?)? = nil
 
-    let callKitProvider:CXProvider
-    let callKitCallController:CXCallController
+    let callKitProvider: CXProvider
+    let callKitCallController: CXCallController
+    var userInitiatedDisconnect: Bool = false
 
     required init?(coder aDecoder: NSCoder) {
         isSpinning = false


    @IBAction func placeCall(_ sender: UIButton) {
        if (self.call != nil && self.call?.state == .connected) {
            performEndCallAction(uuid: self.call!.uuid)
            self.toggleUIState(isEnabled: false, showCallControl: false)
        } else {

            NSLog("Call disconnected")
        }

        if !self.userInitiatedDisconnect {
            var reason = CXCallEndedReason.remoteEnded

            if error != nil {
                reason = .failed
            }

            self.callKitProvider.reportCall(with: call.uuid, endedAt: Date(), reason: reason)
        }

        callDisconnected()
    }
    
    func callDisconnected() {
        self.call = nil
        self.callKitCompletionCallback = nil
        self.userInitiatedDisconnect = false
        
        stopSpin()
        toggleUIState(isEnabled: true, showCallControl: false)
