deal with audio I/O change
This commit is contained in:
parent
67f979e014
commit
95c8606408
|
@ -10,6 +10,7 @@ public final class SessionCall: NSObject, WebRTCSessionDelegate {
|
|||
let callID: UUID // This is for CallKit
|
||||
let sessionID: String
|
||||
let mode: Mode
|
||||
var audioMode: AudioMode
|
||||
let webRTCSession: WebRTCSession
|
||||
let isOutgoing: Bool
|
||||
var remoteSDP: RTCSessionDescription? = nil
|
||||
|
@ -70,6 +71,14 @@ public final class SessionCall: NSObject, WebRTCSessionDelegate {
|
|||
case unanswered
|
||||
}
|
||||
|
||||
// MARK: Audio I/O mode
|
||||
enum AudioMode {
|
||||
case earpiece
|
||||
case speaker
|
||||
case headphone
|
||||
case bluetooth
|
||||
}
|
||||
|
||||
// MARK: Call State Properties
|
||||
var connectingDate: Date? {
|
||||
didSet {
|
||||
|
@ -141,6 +150,7 @@ public final class SessionCall: NSObject, WebRTCSessionDelegate {
|
|||
self.uuid = uuid
|
||||
self.callID = UUID()
|
||||
self.mode = mode
|
||||
self.audioMode = .earpiece
|
||||
self.webRTCSession = WebRTCSession.current ?? WebRTCSession(for: sessionID, with: uuid)
|
||||
self.isOutgoing = outgoing
|
||||
WebRTCSession.current = self.webRTCSession
|
||||
|
@ -258,6 +268,16 @@ public final class SessionCall: NSObject, WebRTCSessionDelegate {
|
|||
webRTCSession.attachLocalRenderer(renderer)
|
||||
}
|
||||
|
||||
// MARK: Audio I/O swithcing
|
||||
func switchAudioMode(mode: AudioMode) {
|
||||
audioMode = mode
|
||||
if mode == .speaker {
|
||||
webRTCSession.configureAudioSession(outputAudioPort: .speaker)
|
||||
} else {
|
||||
webRTCSession.configureAudioSession()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Delegate
|
||||
public func webRTCIsConnected() {
|
||||
guard !self.hasConnected else { return }
|
||||
|
|
|
@ -3,6 +3,7 @@ import SessionUIKit
|
|||
import SessionMessagingKit
|
||||
import SessionUtilitiesKit
|
||||
import UIKit
|
||||
import MediaPlayer
|
||||
|
||||
final class CallVC : UIViewController, VideoPreviewDelegate {
|
||||
let call: SessionCall
|
||||
|
@ -127,8 +128,21 @@ final class CallVC : UIViewController, VideoPreviewDelegate {
|
|||
return result
|
||||
}()
|
||||
|
||||
private lazy var volumeView: MPVolumeView = {
|
||||
let result = MPVolumeView()
|
||||
let image = UIImage(named: "Speaker")?.withRenderingMode(.alwaysTemplate)
|
||||
result.showsRouteButton = true
|
||||
result.setRouteButtonImage(image, for: UIControl.State.normal)
|
||||
result.set(.width, to: 60)
|
||||
result.set(.height, to: 60)
|
||||
result.tintColor = .white
|
||||
result.backgroundColor = UIColor(hex: 0x1F1F1F)
|
||||
result.layer.cornerRadius = 30
|
||||
return result
|
||||
}()
|
||||
|
||||
private lazy var operationPanel: UIStackView = {
|
||||
let result = UIStackView(arrangedSubviews: [switchCameraButton, videoButton, switchAudioButton])
|
||||
let result = UIStackView(arrangedSubviews: [switchCameraButton, videoButton, switchAudioButton, volumeView])
|
||||
result.axis = .horizontal
|
||||
result.spacing = Values.veryLargeSpacing
|
||||
return result
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "speaker.pdf",
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
Binary file not shown.
|
@ -261,7 +261,6 @@ public final class WebRTCSession : NSObject, RTCPeerConnectionDelegate {
|
|||
print("[Calls] ICE connection state changed to: \(state).")
|
||||
if state == .connected {
|
||||
delegate?.webRTCIsConnected()
|
||||
configureAudioSession()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -283,13 +282,13 @@ public final class WebRTCSession : NSObject, RTCPeerConnectionDelegate {
|
|||
}
|
||||
|
||||
extension WebRTCSession {
|
||||
private func configureAudioSession() {
|
||||
public func configureAudioSession(outputAudioPort: AVAudioSession.PortOverride = .none) {
|
||||
let audioSession = RTCAudioSession.sharedInstance()
|
||||
audioSession.lockForConfiguration()
|
||||
do {
|
||||
try audioSession.setCategory(AVAudioSession.Category.playAndRecord.rawValue)
|
||||
try audioSession.setMode(AVAudioSession.Mode.voiceChat.rawValue)
|
||||
try audioSession.overrideOutputAudioPort(.speaker)
|
||||
try audioSession.overrideOutputAudioPort(outputAudioPort)
|
||||
try audioSession.setActive(true)
|
||||
} catch let error {
|
||||
SNLog("Couldn't set up WebRTC audio session due to error: \(error)")
|
||||
|
|
Loading…
Reference in New Issue