Skip to content

Commit

Permalink
Merge pull request #141 from team-telnyx/feat/WEBRTC-2351-multiple-creds
Browse files Browse the repository at this point in the history
[WEBRTC-2351] [Feat] Support Multiple credentials in demo app
  • Loading branch information
gbattistel authored Nov 20, 2024
2 parents 9285280 + 5c27fd6 commit 68c179c
Show file tree
Hide file tree
Showing 14 changed files with 625 additions and 75 deletions.
60 changes: 54 additions & 6 deletions TelnyxRTC.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
3BC03B592CC2653700FD2B29 /* TelnyxRTC.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B368BEC025EDDB610032AE52 /* TelnyxRTC.framework */; };
3BC03B5E2CC2659500FD2B29 /* Pods_TelnyxRTC.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8A11DAA0171B02D67683620E /* Pods_TelnyxRTC.framework */; };
3BF1D5842BEB7B8F0097453F /* TelnyxRTC.podspec in Resources */ = {isa = PBXBuildFile; fileRef = 3BF1D5832BEB7B8F0097453F /* TelnyxRTC.podspec */; };
995BF7132CE7E8F100454076 /* WebRTCEnvironmentExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 995BF7122CE7E8EB00454076 /* WebRTCEnvironmentExtension.swift */; };
995BF7162CE7EB2600454076 /* SipUserCredential.swift in Sources */ = {isa = PBXBuildFile; fileRef = 995BF7152CE7EB2200454076 /* SipUserCredential.swift */; };
995BF71C2CE7EC0600454076 /* SipCredentialsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 995BF71A2CE7EBF800454076 /* SipCredentialsManager.swift */; };
995BF7202CE8175B00454076 /* SipCredentialsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 995BF71F2CE8175200454076 /* SipCredentialsViewController.swift */; };
995BF7222CE818A400454076 /* SipCredentialsViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 995BF7212CE818A400454076 /* SipCredentialsViewController.xib */; };
995BF7242CE8474A00454076 /* UISipCredentialHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 995BF7232CE8471B00454076 /* UISipCredentialHeaderView.swift */; };
B309D13D25EF119E00A2AADF /* Starscream.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B309D11125EF107F00A2AADF /* Starscream.framework */; };
B309D1D625F020B300A2AADF /* Message.swift in Sources */ = {isa = PBXBuildFile; fileRef = B309D1D525F020B300A2AADF /* Message.swift */; };
B309D1DB25F020D400A2AADF /* Method.swift in Sources */ = {isa = PBXBuildFile; fileRef = B309D1DA25F020D400A2AADF /* Method.swift */; };
Expand Down Expand Up @@ -134,6 +140,12 @@
65B0B19B5206EECCAE2E29CA /* Pods_TelnyxRTC_TelnyxRTCTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_TelnyxRTC_TelnyxRTCTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
711958501DD45FDFBD112FC6 /* Pods-TelnyxRTC.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TelnyxRTC.debug.xcconfig"; path = "Target Support Files/Pods-TelnyxRTC/Pods-TelnyxRTC.debug.xcconfig"; sourceTree = "<group>"; };
8A11DAA0171B02D67683620E /* Pods_TelnyxRTC.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_TelnyxRTC.framework; sourceTree = BUILT_PRODUCTS_DIR; };
995BF7122CE7E8EB00454076 /* WebRTCEnvironmentExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebRTCEnvironmentExtension.swift; sourceTree = "<group>"; };
995BF7152CE7EB2200454076 /* SipUserCredential.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SipUserCredential.swift; sourceTree = "<group>"; };
995BF71A2CE7EBF800454076 /* SipCredentialsManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SipCredentialsManager.swift; sourceTree = "<group>"; };
995BF71F2CE8175200454076 /* SipCredentialsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SipCredentialsViewController.swift; sourceTree = "<group>"; };
995BF7212CE818A400454076 /* SipCredentialsViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SipCredentialsViewController.xib; sourceTree = "<group>"; };
995BF7232CE8471B00454076 /* UISipCredentialHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UISipCredentialHeaderView.swift; sourceTree = "<group>"; };
A7CE9BEFEDE503E7BC7BE3C8 /* Pods_TelnyxWebRTCDemo.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_TelnyxWebRTCDemo.framework; sourceTree = BUILT_PRODUCTS_DIR; };
B309D11125EF107F00A2AADF /* Starscream.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Starscream.framework; sourceTree = BUILT_PRODUCTS_DIR; };
B309D1D525F020B300A2AADF /* Message.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Message.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -245,6 +257,31 @@
path = Pods;
sourceTree = "<group>";
};
995BF7142CE7EB0B00454076 /* Models */ = {
isa = PBXGroup;
children = (
995BF7152CE7EB2200454076 /* SipUserCredential.swift */,
);
path = Models;
sourceTree = "<group>";
};
995BF71D2CE7EC5000454076 /* Managers */ = {
isa = PBXGroup;
children = (
995BF71A2CE7EBF800454076 /* SipCredentialsManager.swift */,
);
path = Managers;
sourceTree = "<group>";
};
995BF71E2CE8174B00454076 /* ViewControllers */ = {
isa = PBXGroup;
children = (
995BF71F2CE8175200454076 /* SipCredentialsViewController.swift */,
995BF7212CE818A400454076 /* SipCredentialsViewController.xib */,
);
path = ViewControllers;
sourceTree = "<group>";
};
B309D1D425F020A300A2AADF /* Verto */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -282,6 +319,7 @@
B309D1FB25F028F100A2AADF /* Views */ = {
isa = PBXGroup;
children = (
995BF7232CE8471B00454076 /* UISipCredentialHeaderView.swift */,
B309D27A25F17C1700A2AADF /* UIIncomingCallView.xib */,
B309D27925F17C1700A2AADF /* UIIncomingCallView.swift */,
B309D1FC25F0291100A2AADF /* UISettingsView.xib */,
Expand Down Expand Up @@ -365,8 +403,11 @@
isa = PBXGroup;
children = (
B3B1D9A22654546E008D28C9 /* TelnyxWebRTCDemo.entitlements */,
995BF71D2CE7EC5000454076 /* Managers */,
995BF7142CE7EB0B00454076 /* Models */,
B3E1032F25F7F93000227DCE /* Resources */,
B309D1FB25F028F100A2AADF /* Views */,
995BF71E2CE8174B00454076 /* ViewControllers */,
B3AF24A825EE84410062EDA9 /* Extensions */,
B368BEEA25EDDD060032AE52 /* AppDelegate.swift */,
B368BEEE25EDDD060032AE52 /* ViewController.swift */,
Expand Down Expand Up @@ -440,6 +481,7 @@
B3AF24A825EE84410062EDA9 /* Extensions */ = {
isa = PBXGroup;
children = (
995BF7122CE7E8EB00454076 /* WebRTCEnvironmentExtension.swift */,
B3AF24A925EE84570062EDA9 /* UIViewControllerExtension.swift */,
B3B1D9A326545807008D28C9 /* UserDefaultExtension.swift */,
B32AE8BE26D6D69E00C7C6F4 /* ViewControllerVoIPExtension.swift */,
Expand Down Expand Up @@ -618,6 +660,7 @@
B368BEF425EDDD070032AE52 /* Assets.xcassets in Resources */,
B3E1033325F7F94900227DCE /* ringback_tone.mp3 in Resources */,
B368BEF225EDDD060032AE52 /* Main.storyboard in Resources */,
995BF7222CE818A400454076 /* SipCredentialsViewController.xib in Resources */,
B309D24E25F0717B00A2AADF /* UICallScreen.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -784,13 +827,18 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
995BF7132CE7E8F100454076 /* WebRTCEnvironmentExtension.swift in Sources */,
B3B1D9A426545807008D28C9 /* UserDefaultExtension.swift in Sources */,
B32AE8BB26D6952500C7C6F4 /* AppDelegateCallKitExtension.swift in Sources */,
995BF7242CE8474A00454076 /* UISipCredentialHeaderView.swift in Sources */,
B3AF24AA25EE84570062EDA9 /* UIViewControllerExtension.swift in Sources */,
995BF7202CE8175B00454076 /* SipCredentialsViewController.swift in Sources */,
B309D25325F071DD00A2AADF /* UICallScreen.swift in Sources */,
B3B8F53726E7D4EF0007B583 /* AppDelegateTelnyxVoIPExtension.swift in Sources */,
B309D27B25F17C1700A2AADF /* UIIncomingCallView.swift in Sources */,
B368BEEF25EDDD060032AE52 /* ViewController.swift in Sources */,
995BF7162CE7EB2600454076 /* SipUserCredential.swift in Sources */,
995BF71C2CE7EC0600454076 /* SipCredentialsManager.swift in Sources */,
B368BEEB25EDDD060032AE52 /* AppDelegate.swift in Sources */,
B309D20225F0291B00A2AADF /* UISettingsView.swift in Sources */,
B32AE8BF26D6D69E00C7C6F4 /* ViewControllerVoIPExtension.swift in Sources */,
Expand Down Expand Up @@ -982,7 +1030,7 @@
"@loader_path/Frameworks",
"$(BUILT_PRODUCTS_DIR)/Starscream",
);
MARKETING_VERSION = 0.1.13;
MARKETING_VERSION = 0.1.38;
PRODUCT_BUNDLE_IDENTIFIER = com.telnyx.WebRTCSDK;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
Expand Down Expand Up @@ -1016,7 +1064,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 0.1.13;
MARKETING_VERSION = 0.1.38;
PRODUCT_BUNDLE_IDENTIFIER = com.telnyx.WebRTCSDK;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
Expand Down Expand Up @@ -1073,7 +1121,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = TelnyxWebRTCDemo/TelnyxWebRTCDemo.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 32;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = YKUVNPU9FS;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = TelnyxWebRTCDemo/Info.plist;
Expand All @@ -1082,7 +1130,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.1.19;
MARKETING_VERSION = 0.1.20;
PRODUCT_BUNDLE_IDENTIFIER = com.telnyx.webrtcapp;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand All @@ -1098,7 +1146,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = TelnyxWebRTCDemo/TelnyxWebRTCDemo.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 32;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = YKUVNPU9FS;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = TelnyxWebRTCDemo/Info.plist;
Expand All @@ -1107,7 +1155,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.1.19;
MARKETING_VERSION = 0.1.20;
PRODUCT_BUNDLE_IDENTIFIER = com.telnyx.webrtcapp;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand Down
2 changes: 1 addition & 1 deletion TelnyxWebRTCDemo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ extension AppDelegate: PKPushRegistryDelegate {
// Store incoming token in user defaults
let userDefaults = UserDefaults.standard
let deviceToken = credentials.token.reduce("", {$0 + String(format: "%02X", $1) })
userDefaults.savePushToken(pushToken: deviceToken)
userDefaults.savePushToken(deviceToken)
print("Device push token: \(deviceToken)")
}
}
Expand Down
5 changes: 3 additions & 2 deletions TelnyxWebRTCDemo/Extensions/AppDelegateCallKitExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,9 @@ extension AppDelegate : CXProviderDelegate {
serverConfig = TxServerConfiguration(environment: .production)
}

let sipUser = userDefaults.getSipUser()
let password = userDefaults.getSipUserPassword()
let selectedCredentials = SipCredentialsManager.shared.getSelectedCredential()
let sipUser = selectedCredentials?.username ?? ""
let password = selectedCredentials?.password ?? ""
let deviceToken = userDefaults.getPushToken()
//Sets the login credentials and the ringtone/ringback configurations if required.
//Ringtone / ringback tone files are not mandatory.
Expand Down
78 changes: 30 additions & 48 deletions TelnyxWebRTCDemo/Extensions/UserDefaultExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,63 +8,45 @@
import Foundation
import TelnyxRTC

fileprivate let PUSH_DEVICE_TOKEN = ""

fileprivate let SIP_USER = "SIP_USER"
fileprivate let SIP_USER_PASSWORD = "SIP_USER_PASSWORD"
fileprivate let CALL_DESTINATION = "CALL_DESTINATION"
fileprivate let WEBRTC_ENVIRONMENT = "WEBRTC_ENVIRONMENT"
enum UserDefaultsKey: String {
case selectedSipCredential = "SELECTED_SIP_CREDENTIAL"
case sipCredentials = "SIP_CREDENTIALS"
case pushDeviceToken = "PUSH_DEVICE_TOKEN"
case callDestination = "CALL_DESTINATION"
case webrtcEnvironment = "WEBRTC_ENVIRONMENT"
}

extension UserDefaults {

func savePushToken(pushToken: String) {
let userDefaults = UserDefaults.standard
userDefaults.set(pushToken, forKey: PUSH_DEVICE_TOKEN)
userDefaults.synchronize()

// MARK: - Push Token
func savePushToken(_ pushToken: String) {
set(pushToken, forKey: UserDefaultsKey.pushDeviceToken.rawValue)
}

func deletePushToken() {
let userDefaults = UserDefaults.standard
userDefaults.removeObject(forKey: PUSH_DEVICE_TOKEN)
userDefaults.synchronize()
removeObject(forKey: UserDefaultsKey.pushDeviceToken.rawValue)
}

func getPushToken() -> String {
let userDefaults = UserDefaults.standard
return userDefaults.string(forKey: PUSH_DEVICE_TOKEN) ?? ""
}

func saveUser(sipUser: String, password: String) {
let userDefaults = UserDefaults.standard
userDefaults.set(sipUser, forKey: SIP_USER)
userDefaults.set(password, forKey: SIP_USER_PASSWORD)
userDefaults.synchronize()
}

func saveCallDestination(callDestination: String) {
let userDefaults = UserDefaults.standard
userDefaults.set(callDestination, forKey: CALL_DESTINATION)
userDefaults.synchronize()
}

func getSipUser() -> String {
let userDefaults = UserDefaults.standard
return userDefaults.string(forKey: SIP_USER) ?? ""
return string(forKey: UserDefaultsKey.pushDeviceToken.rawValue) ?? ""
}

func getSipUserPassword() -> String {
let userDefaults = UserDefaults.standard
return userDefaults.string(forKey: SIP_USER_PASSWORD) ?? ""

func saveCallDestination(_ callDestination: String) {
set(callDestination, forKey: UserDefaultsKey.callDestination.rawValue)
}

func saveEnvironment(environment: WebRTCEnvironment) {
let userDefaults = UserDefaults.standard
userDefaults.set((environment == .development) ? "development" : "production", forKey: WEBRTC_ENVIRONMENT)
userDefaults.synchronize()

func getCallDestination() -> String {
return string(forKey: UserDefaultsKey.callDestination.rawValue) ?? ""
}

func getEnvironment() -> WebRTCEnvironment {
let userDefaults = UserDefaults.standard
return (userDefaults.string(forKey: WEBRTC_ENVIRONMENT) == "development") ? .development : .production
let value = string(forKey: UserDefaultsKey.webrtcEnvironment.rawValue) ?? ""
return WebRTCEnvironment.fromString(value)
}

func saveEnvironment(_ environment: WebRTCEnvironment) {
let value = environment.toString()
set(value, forKey: UserDefaultsKey.webrtcEnvironment.rawValue)
}
}

9 changes: 5 additions & 4 deletions TelnyxWebRTCDemo/Extensions/ViewControllerVoIPExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ extension ViewController : VoIPDelegate {
print("ViewController:: TxClientDelegate onClientError() error: \(error)")
let noActiveCalls = self.telnyxClient?.calls.filter { $0.value.callState == .ACTIVE || $0.value.callState == .HELD }.isEmpty

if(noActiveCalls != true){
if noActiveCalls != true {
return
}

Expand All @@ -70,13 +70,14 @@ extension ViewController : VoIPDelegate {
self.incomingCallView.isHidden = true
self.appDelegate.executeEndCallAction(uuid: UUID());

if(error.self is NWError){
if error.self is NWError {
print("ERROR: socket connectiontion error \(error)")
} else {
print("ERROR: client error \(error)")
}

}

self.telnyxClient?.disconnect()
}

func onClientReady() {
Expand All @@ -86,7 +87,7 @@ extension ViewController : VoIPDelegate {
self.socketStateLabel.text = "Client ready"
self.settingsView.isHidden = true
self.callView.isHidden = false
if(!self.incomingCall){
if !self.incomingCall {
self.incomingCallView.isHidden = true
}
}
Expand Down
24 changes: 24 additions & 0 deletions TelnyxWebRTCDemo/Extensions/WebRTCEnvironmentExtension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import TelnyxRTC

extension WebRTCEnvironment {

func toString() -> String {
switch self {
case .development:
return "development"
case .production:
return "production"
}
}

static func fromString(_ value: String) -> WebRTCEnvironment {
switch value {
case "development":
return .development
case "production":
return .production
default:
return .production
}
}
}
Loading

0 comments on commit 68c179c

Please sign in to comment.