-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is/feature/custom headers #111
Merged
Merged
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c2da6ec
New RTCCustomheaders Class
isaacakakpo1 29bdfb1
New Init CustomHeaders
isaacakakpo1 28d6630
Add Custom Headers to INVITE Messages
isaacakakpo1 f668c20
Log Custom Headers
isaacakakpo1 cbe6969
Version Update
isaacakakpo1 53d376b
Change DataClass to CustomHeaderData
isaacakakpo1 f8283f2
Updated Custom Headers File
isaacakakpo1 06834ee
Merge branch 'main'
isaacakakpo1 90b6ea7
Merge Main
isaacakakpo1 e01b952
Removed Derived Data
isaacakakpo1 e809675
Resolve Code Format Issues
isaacakakpo1 eb64fad
Code Review
isaacakakpo1 6050e79
Version Bump
isaacakakpo1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// Params.swift | ||
// TelnyxRTC | ||
// | ||
// Created by Isaac Akakpo on 19/10/2023. | ||
// | ||
|
||
import Foundation | ||
|
||
|
||
struct CustomHeaderData:Codable{ | ||
let jsonrpc:String | ||
let method:String | ||
let params:Params | ||
} | ||
|
||
struct Params: Codable { | ||
let dialogParams: DialogParams | ||
} | ||
|
||
struct DialogParams: Codable { | ||
let custom_headers: [XHeader] | ||
} | ||
|
||
struct XHeader: Codable { | ||
let name: String | ||
let value: String | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,6 +143,7 @@ public class TxClient { | |
private var gatewayState: GatewayStates = .NOREG | ||
private var isCallFromPush: Bool = false | ||
private var currentCallId:UUID = UUID() | ||
private var pendingAnswerHeaders = [String:String]() | ||
private var speakerOn:Bool = false | ||
|
||
func isSpeakerEnabled() -> Bool { | ||
|
@@ -165,6 +166,20 @@ public class TxClient { | |
RTCAudioSession.sharedInstance().isAudioEnabled = newValue | ||
} | ||
} | ||
|
||
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 { | ||
|
@@ -228,14 +243,21 @@ public class TxClient { | |
} | ||
|
||
/// To answer and control callKit active flow | ||
public func answerFromCallkit(answerAction:CXAnswerCallAction) { | ||
/// - Parameters: | ||
/// - answerAction : `CXAnswerCallAction` from callKit | ||
/// - customHeaders: (Optional) | ||
public func answerFromCallkit(answerAction:CXAnswerCallAction,customHeaders:[String:String] = [:]) { | ||
isaacakakpo1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.answerCallAction = answerAction | ||
///answer call if currentPushCall is not nil | ||
///This means the client has connected and we can safelyanswer | ||
if(self.calls[currentCallId] != nil){ | ||
self.calls[currentCallId]?.answer() | ||
self.calls[currentCallId]?.answer(customHeaders: customHeaders) | ||
answerCallAction?.fulfill() | ||
resetPushVariables() | ||
Logger.log.i(message: "answered from callkit") | ||
}else{ | ||
/// Let's Keep track od the `customHeaders` passed | ||
pendingAnswerHeaders = customHeaders | ||
} | ||
} | ||
|
||
|
@@ -378,16 +400,19 @@ extension TxClient { | |
/// - destinationNumber: The destination `SIP user address` (sip:[email protected]) or `phone number`. | ||
/// - callId: The current call UUID. | ||
/// - clientState: (optional) Custom state in string format encoded in base64 | ||
/// - customHeaders: (optional) Custom Headers to be passed over webRTC Messages, should be in the | ||
/// format `X-key:Value` `X` is required for headers to be passed. | ||
/// - Throws: | ||
/// - sessionId is required if user is not logged in | ||
/// - socket connection error if socket is not connected | ||
/// - destination number is required to start a call. | ||
/// - Returns: The call that has been created | ||
public func newCall(callerName: String, | ||
callerNumber: String, | ||
destinationNumber: String, | ||
callId: UUID, | ||
clientState: String? = nil) throws -> Call { | ||
callerNumber: String, | ||
destinationNumber: String, | ||
callId: UUID, | ||
clientState: String? = nil, | ||
customHeaders:[String:String] = [:]) throws -> Call { | ||
//User needs to be logged in to get a sessionId | ||
guard let sessionId = self.sessionId else { | ||
throw TxError.callFailed(reason: .sessionIdIsRequired) | ||
|
@@ -410,7 +435,7 @@ extension TxClient { | |
ringtone: self.txConfig?.ringtone, | ||
ringbackTone: self.txConfig?.ringBackTone, | ||
iceServers: self.serverConfiguration.webRTCIceServers) | ||
call.newCall(callerName: callerName, callerNumber: callerNumber, destinationNumber: destinationNumber, clientState: clientState) | ||
call.newCall(callerName: callerName, callerNumber: callerNumber, destinationNumber: destinationNumber, clientState: clientState,customHeaders: customHeaders) | ||
isaacakakpo1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
currentCallId = callId | ||
self.calls[callId] = call | ||
|
@@ -430,7 +455,8 @@ extension TxClient { | |
callId: UUID, | ||
remoteSdp: String, | ||
telnyxSessionId: String, | ||
telnyxLegId: String) { | ||
telnyxLegId: String, | ||
customHeaders:[String:String] = [:]) { | ||
|
||
guard let sessionId = self.sessionId, | ||
let socket = self.socket else { | ||
|
@@ -450,7 +476,7 @@ extension TxClient { | |
call.callInfo?.callerName = callerName | ||
call.callInfo?.callerNumber = callerNumber | ||
call.callOptions = TxCallOptions(audio: true) | ||
|
||
call.inviteCustomHeaders = customHeaders | ||
self.calls[callId] = call | ||
// propagate the incoming call to the App | ||
Logger.log.i(message: "TxClient:: push flow createIncomingCall \(call)") | ||
|
@@ -461,7 +487,7 @@ extension TxClient { | |
self.delegate?.onPushCall(call: call) | ||
//Answer is pending from push - Answer Call | ||
if(answerCallAction != nil){ | ||
call.answer() | ||
call.answer(customHeaders: pendingAnswerHeaders) | ||
answerCallAction?.fulfill() | ||
resetPushVariables() | ||
} | ||
|
@@ -663,7 +689,7 @@ extension TxClient : SocketDelegate { | |
let callUUIDString = params["callID"] as? String, | ||
let callUUID = UUID(uuidString: callUUIDString), | ||
let call = calls[callUUID] { | ||
call.handleVertoMessage(message: vertoMessage,txclient: self) | ||
call.handleVertoMessage(message: vertoMessage,dataMessage: message,txClient: self) | ||
isaacakakpo1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
|
||
|
@@ -709,12 +735,26 @@ extension TxClient : SocketDelegate { | |
if telnyxLegId.isEmpty { | ||
Logger.log.w(message: "TxClient:: Telnyx Leg ID unavailable on INVITE message") | ||
} | ||
|
||
var customHeaders = [String:String]() | ||
if params["dialogParams"] is [String:Any] { | ||
do { | ||
let dataDecoded = try JSONDecoder().decode(CustomHeaderData.self, from: message.data(using: .utf8)!) | ||
dataDecoded.params.dialogParams.custom_headers.forEach { xHeader in | ||
customHeaders[xHeader.name] = xHeader.value | ||
} | ||
print("Data Decode : \(dataDecoded)") | ||
} catch { | ||
print("decoding error: \(error)") | ||
} | ||
} | ||
self.createIncomingCall(callerName: callerName, | ||
callerNumber: callerNumber, | ||
callId: uuid, | ||
remoteSdp: sdp, | ||
telnyxSessionId: telnyxSessionId, | ||
telnyxLegId: telnyxLegId) | ||
telnyxLegId: telnyxLegId, | ||
customHeaders: customHeaders) | ||
} | ||
break; | ||
//Mark: to send meassage to pong | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
misspelling: double p in speaker