"Fossies" - the Fresh Open Source Software Archive

Member "jitsi-meet-4434/ios/app/watchos/extension/ExtensionDelegate.swift" (25 Sep 2020, 4747 Bytes) of package /linux/misc/jitsi-meet-4434.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Swift source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*
    2  * Copyright @ 2018-present 8x8, Inc.
    3  * Copyright @ 2017-2018 Atlassian Pty Ltd
    4  *
    5  * Licensed under the Apache License, Version 2.0 (the "License");
    6  * you may not use this file except in compliance with the License.
    7  * You may obtain a copy of the License at
    8  *
    9  *     http://www.apache.org/licenses/LICENSE-2.0
   10  *
   11  * Unless required by applicable law or agreed to in writing, software
   12  * distributed under the License is distributed on an "AS IS" BASIS,
   13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14  * See the License for the specific language governing permissions and
   15  * limitations under the License.
   16  */
   17 
   18 import WatchConnectivity
   19 import WatchKit
   20 
   21 class ExtensionDelegate: NSObject, WCSessionDelegate, WKExtensionDelegate {
   22 
   23     var currentContext : JitsiMeetContext = JitsiMeetContext()
   24 
   25     static var currentJitsiMeetContext: JitsiMeetContext {
   26         get {
   27             return (WKExtension.shared().delegate as! ExtensionDelegate).currentContext
   28         }
   29     }
   30 
   31     func applicationDidFinishLaunching() {
   32         // Start Watch Connectivity
   33         if WCSession.isSupported() {
   34             let session  = WCSession.default
   35             session.delegate = self
   36             session.activate()
   37         }
   38     }
   39 
   40     func handle(_ backgroundTasks: Set<WKRefreshBackgroundTask>) {
   41         // Sent when the system needs to launch the application in the background to process tasks. Tasks arrive in a set, so loop through and process each one.
   42         for task in backgroundTasks {
   43             // Use a switch statement to check the task type
   44             switch task {
   45             case let backgroundTask as WKApplicationRefreshBackgroundTask:
   46                 // Be sure to complete the background task once you’re done.
   47                 backgroundTask.setTaskCompletedWithSnapshot(false)
   48             case let snapshotTask as WKSnapshotRefreshBackgroundTask:
   49                 // Snapshot tasks have a unique completion call, make sure to set your expiration date
   50                 snapshotTask.setTaskCompleted(restoredDefaultState: true, estimatedSnapshotExpiration: Date.distantFuture, userInfo: nil)
   51             case let connectivityTask as WKWatchConnectivityRefreshBackgroundTask:
   52                 // Be sure to complete the connectivity task once you’re done.
   53                 connectivityTask.setTaskCompletedWithSnapshot(false)
   54             case let urlSessionTask as WKURLSessionRefreshBackgroundTask:
   55                 // Be sure to complete the URL session task once you’re done.
   56                 urlSessionTask.setTaskCompletedWithSnapshot(false)
   57             default:
   58                 // make sure to complete unhandled task types
   59                 task.setTaskCompletedWithSnapshot(false)
   60             }
   61         }
   62     }
   63 
   64     func session(_ session: WCSession, activationDidCompleteWith
   65         activationState: WCSessionActivationState, error: Error?) {
   66         if let error = error {
   67             print("WATCH Session activation failed with error: \(error.localizedDescription)")
   68             return
   69         }
   70         print("WATCH Session activated with state: \(activationState.rawValue)")
   71     }
   72 
   73     func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any]) {
   74         DispatchQueue.main.async {
   75             let newContext = JitsiMeetContext(context: applicationContext)
   76 
   77             print("WATCH got new context: \(newContext.description)");
   78 
   79             // Update context on the root controller which displays the recent list
   80             let controller = WKExtension.shared().rootInterfaceController as! InterfaceController
   81             controller.updateUI(newContext)
   82 
   83             // If the current controller is not the in-call controller and we have a
   84             // conference URL, show the in-call controller
   85             if let currentController = WKExtension.shared().visibleInterfaceController as? InterfaceController {
   86                 // Go to the in-call controller only if the conference URL has changed, because the user may have
   87                 // clicked the back button
   88                 if newContext.conferenceURL != nil
   89                         && self.currentContext.conferenceURL != newContext.conferenceURL {
   90                       currentController.pushController(withName: "InCallController", context: newContext)
   91                 }
   92             } else if let inCallController = WKExtension.shared().visibleInterfaceController as? InCallController {
   93                 if newContext.conferenceURL == nil {
   94                       inCallController.popToRootController()
   95                 } else {
   96                       inCallController.updateUI(newContext)
   97                 }
   98             }
   99 
  100             self.currentContext = newContext;
  101         }
  102     }
  103 }