getting basic call to backend for a token but it's messy as hellll!!!!
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
890C2460277BF896009B4A30 /* AgoraViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 890C245F277BF896009B4A30 /* AgoraViewController.swift */; };
|
||||
890C2462277BF935009B4A30 /* CallView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 890C2461277BF935009B4A30 /* CallView.swift */; };
|
||||
890C2464277BFA97009B4A30 /* AgroRep.swift in Sources */ = {isa = PBXBuildFile; fileRef = 890C2463277BFA97009B4A30 /* AgroRep.swift */; };
|
||||
890C2466277C5711009B4A30 /* AgoraService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 890C2465277C5711009B4A30 /* AgoraService.swift */; };
|
||||
891060E4277359B900F14509 /* CloudStorageService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 891060E3277359B900F14509 /* CloudStorageService.swift */; };
|
||||
891060E82774460500F14509 /* FirebaseInAppMessaging-Beta in Frameworks */ = {isa = PBXBuildFile; productRef = 891060E72774460500F14509 /* FirebaseInAppMessaging-Beta */; };
|
||||
891060EA2774460500F14509 /* FirebaseInAppMessagingSwift-Beta in Frameworks */ = {isa = PBXBuildFile; productRef = 891060E92774460500F14509 /* FirebaseInAppMessagingSwift-Beta */; };
|
||||
@@ -92,6 +93,7 @@
|
||||
890C245F277BF896009B4A30 /* AgoraViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AgoraViewController.swift; sourceTree = "<group>"; };
|
||||
890C2461277BF935009B4A30 /* CallView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CallView.swift; sourceTree = "<group>"; };
|
||||
890C2463277BFA97009B4A30 /* AgroRep.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AgroRep.swift; sourceTree = "<group>"; };
|
||||
890C2465277C5711009B4A30 /* AgoraService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AgoraService.swift; sourceTree = "<group>"; };
|
||||
891060E3277359B900F14509 /* CloudStorageService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CloudStorageService.swift; sourceTree = "<group>"; };
|
||||
891060E527743FEB00F14509 /* nirvana-ios.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "nirvana-ios.entitlements"; sourceTree = "<group>"; };
|
||||
89110713277166D6005797FA /* UserFriends.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserFriends.swift; sourceTree = "<group>"; };
|
||||
@@ -435,6 +437,7 @@
|
||||
89F05BA3276ACC060002E9C7 /* ContactService.swift */,
|
||||
89B46E70276893E200B74255 /* AuthSessionStore.swift */,
|
||||
89A107E4277476CC00B971FD /* PushNotificationService.swift */,
|
||||
890C2465277C5711009B4A30 /* AgoraService.swift */,
|
||||
);
|
||||
path = Services;
|
||||
sourceTree = "<group>";
|
||||
@@ -601,6 +604,7 @@
|
||||
89F05B9B276A87920002E9C7 /* ContactsViewModel.swift in Sources */,
|
||||
896CE6FE27707E6B00DB474E /* CircleNavigationView.swift in Sources */,
|
||||
89AD5573276DD790001658E0 /* SplashView.swift in Sources */,
|
||||
890C2466277C5711009B4A30 /* AgoraService.swift in Sources */,
|
||||
89F18AEC276E92BF00115B1E /* CustomExtensions.swift in Sources */,
|
||||
89F18AF1276ECAA300115B1E /* RouterView.swift in Sources */,
|
||||
89F18AEE276EB55C00115B1E /* ServiceState.swift in Sources */,
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
<EnvironmentVariables>
|
||||
<EnvironmentVariable
|
||||
key = "nirvana-server-url"
|
||||
value = "http://localhost:3000/"
|
||||
value = "http://192.168.50.26:3000/"
|
||||
isEnabled = "YES">
|
||||
</EnvironmentVariable>
|
||||
</EnvironmentVariables>
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// AgoraService.swift
|
||||
// nirvana-ios
|
||||
//
|
||||
// Created by Arjun Patel on 12/29/21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import FirebaseAuth
|
||||
import Firebase
|
||||
|
||||
class AgoraService {
|
||||
func getAgoraUserToken(channelName: String) {
|
||||
let currentUser = Auth.auth().currentUser
|
||||
currentUser?.getIDTokenForcingRefresh(true) { idToken, error in
|
||||
if let error = error {
|
||||
// Handle error
|
||||
return;
|
||||
}
|
||||
|
||||
// Send token to your backend via HTTPS
|
||||
// ...
|
||||
let baseUrl = ProcessInfo.processInfo.environment["nirvana-server-url"] ?? "http://localhost:3000"
|
||||
let reqUrl = baseUrl + "agoraToken?channelName=" + channelName
|
||||
guard let url = URL(string: reqUrl) else { fatalError("Missing URL") }
|
||||
|
||||
var urlRequest = URLRequest(url: url)
|
||||
urlRequest.addValue(idToken!, forHTTPHeaderField: "authorization")
|
||||
|
||||
let dataTask = URLSession.shared.dataTask(with: urlRequest) { (data, response, error) in
|
||||
if let error = error {
|
||||
print("Request error: ", error)
|
||||
return
|
||||
}
|
||||
|
||||
guard let response = response as? HTTPURLResponse else { return }
|
||||
|
||||
if response.statusCode == 200 {
|
||||
guard let data = data else { return }
|
||||
print("the token is: \(data)")
|
||||
}
|
||||
}
|
||||
|
||||
dataTask.resume()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -140,7 +140,7 @@ final class AuthSessionStore: ObservableObject, SessionStore {
|
||||
}
|
||||
}
|
||||
|
||||
func getCurrentUserId() -> String? {
|
||||
static func getCurrentUserId() -> String? {
|
||||
return Auth.auth().currentUser?.uid
|
||||
}
|
||||
|
||||
@@ -214,7 +214,7 @@ extension AuthSessionStore {
|
||||
}
|
||||
|
||||
// can't get proper listeners working if don't have current user's id
|
||||
let currUserId = self.getCurrentUserId()
|
||||
let currUserId = AuthSessionStore.getCurrentUserId()
|
||||
if currUserId == nil {
|
||||
print("no user id available to initiate data listeners")
|
||||
return
|
||||
@@ -457,7 +457,7 @@ extension AuthSessionStore {
|
||||
print("user already has status: \(userStatus)")
|
||||
}
|
||||
else {
|
||||
if let uid = self.getCurrentUserId() {
|
||||
if let uid = AuthSessionStore.getCurrentUserId() {
|
||||
self.firestoreService.updateUserStatus(userId: uid, userStatus: userStatus) {res in
|
||||
print(res)
|
||||
}
|
||||
|
||||
@@ -266,6 +266,9 @@ struct CircleGridView: View {
|
||||
if self.authSessionStore.friendsArr.count > 0 {
|
||||
scrollReaderValue.scrollTo(self.selectedFriendIndex)
|
||||
}
|
||||
|
||||
// get this user's agora token
|
||||
self.innerCircleVM.getAgoraToken()
|
||||
}
|
||||
} // scrollview reader
|
||||
.fullScreenCover(isPresented: $showCall, content: {
|
||||
|
||||
@@ -21,6 +21,7 @@ class InnerCircleViewModel: ObservableObject {
|
||||
private let cloudStorageService = CloudStorageService()
|
||||
private let firestoreService = FirestoreService()
|
||||
private let pushNotificationService = PushNotificationService()
|
||||
private let agoraService = AgoraService()
|
||||
|
||||
init() {
|
||||
// separate set up for listening vs recording
|
||||
@@ -139,3 +140,14 @@ extension InnerCircleViewModel {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
extension InnerCircleViewModel {
|
||||
func getAgoraToken() {
|
||||
if let uid = AuthSessionStore.getCurrentUserId() {
|
||||
self.agoraService.getAgoraUserToken(channelName: uid)
|
||||
}
|
||||
else {
|
||||
print("no user authenticated to get an agora token")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user