"Fossies" - the Fresh Open Source Software Archive

Member "jitsi-meet-5187/ios/sdk/src/callkit/JMCallKitEmitter.swift" (2 Aug 2021, 3748 Bytes) of package /linux/misc/jitsi-meet-5187.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 Atlassian Pty Ltd
    3  *
    4  * Licensed under the Apache License, Version 2.0 (the "License");
    5  * you may not use this file except in compliance with the License.
    6  * You may obtain a copy of the License at
    7  *
    8  *     http://www.apache.org/licenses/LICENSE-2.0
    9  *
   10  * Unless required by applicable law or agreed to in writing, software
   11  * distributed under the License is distributed on an "AS IS" BASIS,
   12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   13  * See the License for the specific language governing permissions and
   14  * limitations under the License.
   15  */
   16 
   17 import AVKit
   18 import CallKit
   19 import Foundation
   20 
   21 internal final class JMCallKitEmitter: NSObject, CXProviderDelegate {
   22 
   23     private let listeners = NSMutableArray()
   24     private var pendingMuteActions = Set<UUID>()
   25 
   26     internal override init() {}
   27 
   28     // MARK: - Add/remove listeners
   29 
   30     func addListener(_ listener: JMCallKitListener) {
   31         if (!listeners.contains(listener)) {
   32             listeners.add(listener)
   33         }
   34     }
   35 
   36     func removeListener(_ listener: JMCallKitListener) {
   37         listeners.remove(listener)
   38     }
   39 
   40     // MARK: - Add mute action
   41 
   42     func addMuteAction(_ actionUUID: UUID) {
   43         pendingMuteActions.insert(actionUUID)
   44     }
   45 
   46     // MARK: - CXProviderDelegate
   47 
   48     func providerDidReset(_ provider: CXProvider) {
   49         listeners.forEach {
   50             let listener = $0 as! JMCallKitListener
   51             listener.providerDidReset?()
   52         }
   53         pendingMuteActions.removeAll()
   54     }
   55 
   56     func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
   57         listeners.forEach {
   58             let listener = $0 as! JMCallKitListener
   59             listener.performAnswerCall?(UUID: action.callUUID)
   60         }
   61 
   62         action.fulfill()
   63     }
   64 
   65     func provider(_ provider: CXProvider, perform action: CXEndCallAction) {
   66         listeners.forEach {
   67             let listener = $0 as! JMCallKitListener
   68             listener.performEndCall?(UUID: action.callUUID)
   69         }
   70 
   71         action.fulfill()
   72     }
   73 
   74     func provider(_ provider: CXProvider, perform action: CXSetMutedCallAction) {
   75         let uuid = pendingMuteActions.remove(action.uuid)
   76 
   77         // Avoid mute actions ping-pong: if the mute action was caused by
   78         // the JS side (we requested a transaction) don't call the delegate
   79         // method. If it was called by the provider itself (when the user presses
   80         // the mute button in the CallKit view) then call the delegate method.
   81         //
   82         // NOTE: don't try to be clever and remove this. Been there, done that.
   83         // Won't work.
   84         if (uuid == nil) {
   85             listeners.forEach {
   86                 let listener = $0 as! JMCallKitListener
   87                 listener.performSetMutedCall?(UUID: action.callUUID, isMuted: action.isMuted)
   88             }
   89         }
   90 
   91         action.fulfill()
   92     }
   93 
   94     func provider(_ provider: CXProvider, perform action: CXStartCallAction) {
   95         listeners.forEach {
   96             let listener = $0 as! JMCallKitListener
   97             listener.performStartCall?(UUID: action.callUUID, isVideo: action.isVideo)
   98         }
   99 
  100         action.fulfill()
  101     }
  102 
  103     func provider(_ provider: CXProvider,
  104                   didActivate audioSession: AVAudioSession) {
  105         listeners.forEach {
  106             let listener = $0 as! JMCallKitListener
  107             listener.providerDidActivateAudioSession?(session: audioSession)
  108         }
  109     }
  110 
  111     func provider(_ provider: CXProvider,
  112                   didDeactivate audioSession: AVAudioSession) {
  113         listeners.forEach {
  114             let listener = $0 as! JMCallKitListener
  115             listener.providerDidDeactivateAudioSession?(session: audioSession)
  116         }
  117     }
  118 }