diff --git a/.gitignore b/.gitignore index 75728c61..530536dc 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ *.xcworkspace/ project.xcworkspace/ xcuserdata/ +DerivedData/ # Podfiles Pods/ diff --git a/TelnyxRTC/Telnyx/Models/Params.swift b/TelnyxRTC/Telnyx/Models/Params.swift index c25b9b2f..367ed91a 100644 --- a/TelnyxRTC/Telnyx/Models/Params.swift +++ b/TelnyxRTC/Telnyx/Models/Params.swift @@ -26,3 +26,14 @@ struct XHeader: Codable { let name: String let value: String } + +func appendCustomHeaders(customHeaders:[String:String]) -> [Any] { + var xHeaders = [Any]() + customHeaders.keys.forEach { key in + var header = [String:String]() + header["name"] = key + header["value"] = customHeaders[key] + xHeaders.append(header) + } + return xHeaders +} diff --git a/TelnyxRTC/Telnyx/TxClient.swift b/TelnyxRTC/Telnyx/TxClient.swift index babfd48b..ade0ed6d 100644 --- a/TelnyxRTC/Telnyx/TxClient.swift +++ b/TelnyxRTC/Telnyx/TxClient.swift @@ -169,18 +169,6 @@ public class TxClient { let currentRoute = AVAudioSession.sharedInstance().currentRoute - func isSppeakerEnabled() -> Bool { - for output in currentRoute.outputs { - switch output.portType { - case AVAudioSession.Port.builtInSpeaker: - return true - default: - break - } - } - return false - } - /// Client must be registered in order to receive or place calls. public var isRegistered: Bool { get { @@ -689,7 +677,7 @@ extension TxClient : SocketDelegate { let callUUIDString = params["callID"] as? String, let callUUID = UUID(uuidString: callUUIDString), let call = calls[callUUID] { - call.handleVertoMessage(message: vertoMessage,dataMessage: message,txClient: self) + call.handleVertoMessage(message: vertoMessage, dataMessage: message, txClient: self) } diff --git a/TelnyxRTC/Telnyx/Verto/AnswerMessage.swift b/TelnyxRTC/Telnyx/Verto/AnswerMessage.swift index 59055a3a..637db714 100644 --- a/TelnyxRTC/Telnyx/Verto/AnswerMessage.swift +++ b/TelnyxRTC/Telnyx/Verto/AnswerMessage.swift @@ -18,7 +18,6 @@ class AnswerMessage : Message { var params = [String: Any]() var dialogParams = [String: Any]() - var xHeaders = [Any]() // Merge callInfo into dialogParams callInfo.encode().forEach { (key, value) in dialogParams[key] = value } // Merge callOptions into dialogParams @@ -29,13 +28,7 @@ class AnswerMessage : Message { params["sessionId"] = sessionId params["sdp"] = sdp if(!customHeaders.isEmpty){ - customHeaders.keys.forEach { key in - var header = [String:String]() - header["name"] = key - header["value"] = customHeaders[key] - xHeaders.append(header) - } - dialogParams["custom_headers"] = xHeaders + dialogParams["custom_headers"] = appendCustomHeaders(customHeaders: customHeaders) } params["dialogParams"] = dialogParams super.init(params, method: .ANSWER) diff --git a/TelnyxRTC/Telnyx/Verto/InviteMessage.swift b/TelnyxRTC/Telnyx/Verto/InviteMessage.swift index a1533dbf..09e21ec1 100644 --- a/TelnyxRTC/Telnyx/Verto/InviteMessage.swift +++ b/TelnyxRTC/Telnyx/Verto/InviteMessage.swift @@ -19,7 +19,6 @@ class InviteMessage : Message { ) { var params = [String: Any]() var dialogParams = [String: Any]() - var xHeaders = [Any]() dialogParams["callID"] = callInfo.callId.uuidString.lowercased() dialogParams["destination_number"] = callOptions.destinationNumber dialogParams["remote_caller_id_name"] = callOptions.remoteCallerName @@ -32,13 +31,7 @@ class InviteMessage : Message { dialogParams["screenShare"] = callOptions.screenShare dialogParams["userVariables"] = callOptions.userVariables if(!customHeaders.isEmpty){ - customHeaders.keys.forEach { key in - var header = [String:String]() - header["name"] = key - header["value"] = customHeaders[key] - xHeaders.append(header) - } - dialogParams["custom_headers"] = xHeaders + dialogParams["custom_headers"] = appendCustomHeaders(customHeaders: customHeaders) } if let clientState = callOptions.clientState { dialogParams["clientState"] = clientState diff --git a/TelnyxRTC/Telnyx/WebRTC/Call.swift b/TelnyxRTC/Telnyx/WebRTC/Call.swift index 408b5840..3b46ff4a 100644 --- a/TelnyxRTC/Telnyx/WebRTC/Call.swift +++ b/TelnyxRTC/Telnyx/WebRTC/Call.swift @@ -288,7 +288,7 @@ extension Call { Logger.log.e(message: "Call:: Please enter a destination number.") return } - invite(callerName: callerName, callerNumber: callerNumber, destinationNumber: destinationNumber, clientState: clientState,customHeaders: customHeaders) + invite(callerName: callerName, callerNumber: callerNumber, destinationNumber: destinationNumber, clientState: clientState, customHeaders: customHeaders) } /// Hangup or reject an incoming call. diff --git a/TelnyxWebRTCDemo/Extensions/AppDelegateCallKitExtension.swift b/TelnyxWebRTCDemo/Extensions/AppDelegateCallKitExtension.swift index f4bbb90d..57cc92ab 100644 --- a/TelnyxWebRTCDemo/Extensions/AppDelegateCallKitExtension.swift +++ b/TelnyxWebRTCDemo/Extensions/AppDelegateCallKitExtension.swift @@ -156,7 +156,7 @@ extension AppDelegate : CXProviderDelegate { func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) { print("AppDelegate:: ANSWER call action: callKitUUID [\(String(describing: self.callKitUUID))] action [\(action.callUUID)]") - self.telnyxClient?.answerFromCallkit(answerAction: action,customHeaders: ["X-test-answer":"ios-test"]) + self.telnyxClient?.answerFromCallkit(answerAction: action, customHeaders: ["X-test-answer":"ios-test"]) } func provider(_ provider: CXProvider, perform action: CXEndCallAction) { diff --git a/TelnyxWebRTCDemo/Extensions/ViewControllerVoIPExtension.swift b/TelnyxWebRTCDemo/Extensions/ViewControllerVoIPExtension.swift index d1a42527..dc4ef8d6 100644 --- a/TelnyxWebRTCDemo/Extensions/ViewControllerVoIPExtension.swift +++ b/TelnyxWebRTCDemo/Extensions/ViewControllerVoIPExtension.swift @@ -132,12 +132,13 @@ extension ViewController : VoIPDelegate { print("ERROR: executeCall can't be performed. Check callerName - callerNumber and destinationNumber") return } + let headers = ["X-test1":"ios-test1", + "X-test2":"ios-test2"] let call = try telnyxClient?.newCall(callerName: callerName, callerNumber: callerNumber, destinationNumber: destinationNumber, - callId: callUUID,customHeaders: ["X-test1":"ios-test1", - "X-test2":"ios-test2"]) + callId: callUUID,customHeaders: headers) completionHandler(call) } catch let error { print("ViewController:: executeCall Error \(error)")