diff --git a/nirvana-ios.xcodeproj/project.pbxproj b/nirvana-ios.xcodeproj/project.pbxproj index af50bd7..51e8f80 100644 --- a/nirvana-ios.xcodeproj/project.pbxproj +++ b/nirvana-ios.xcodeproj/project.pbxproj @@ -17,6 +17,7 @@ 890919A42781845D0025F4BB /* AlertToast in Frameworks */ = {isa = PBXBuildFile; productRef = 890919A32781845D0025F4BB /* AlertToast */; }; 890919A7278299590025F4BB /* RuleBook.swift in Sources */ = {isa = PBXBuildFile; fileRef = 890919A6278299590025F4BB /* RuleBook.swift */; }; 890919AB2782DC760025F4BB /* ProgressBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 890919AA2782DC760025F4BB /* ProgressBarView.swift */; }; + 890919B1278401E00025F4BB /* woosh.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = 890919B0278401E00025F4BB /* woosh.mp3 */; }; 890C245D277BF628009B4A30 /* AgoraRtcKit in Frameworks */ = {isa = PBXBuildFile; productRef = 890C245C277BF628009B4A30 /* AgoraRtcKit */; }; 890C2460277BF896009B4A30 /* AgoraViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 890C245F277BF896009B4A30 /* AgoraViewController.swift */; }; 890C2462277BF935009B4A30 /* CallView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 890C2461277BF935009B4A30 /* CallView.swift */; }; @@ -109,6 +110,7 @@ 8909199D278155920025F4BB /* UserStatusView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserStatusView.swift; sourceTree = ""; }; 890919A6278299590025F4BB /* RuleBook.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RuleBook.swift; sourceTree = ""; }; 890919AA2782DC760025F4BB /* ProgressBarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgressBarView.swift; sourceTree = ""; }; + 890919B0278401E00025F4BB /* woosh.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = woosh.mp3; sourceTree = ""; }; 890C245F277BF896009B4A30 /* AgoraViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AgoraViewController.swift; sourceTree = ""; }; 890C2461277BF935009B4A30 /* CallView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CallView.swift; sourceTree = ""; }; 890C2463277BFA97009B4A30 /* AgroRep.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AgroRep.swift; sourceTree = ""; }; @@ -210,6 +212,7 @@ isa = PBXGroup; children = ( 8909199B277EFDF30025F4BB /* joinSound.mp3 */, + 890919B0278401E00025F4BB /* woosh.mp3 */, 89091998277EFDCC0025F4BB /* leaveSound.mp3 */, ); path = sounds; @@ -626,6 +629,7 @@ 891A15E827653A7100B26659 /* Preview Assets.xcassets in Resources */, 8909199C277EFDF30025F4BB /* joinSound.mp3 in Resources */, 891A15E527653A7100B26659 /* Assets.xcassets in Resources */, + 890919B1278401E00025F4BB /* woosh.mp3 in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/nirvana-ios/Views/InnerCircle/InnerCircleViewModel.swift b/nirvana-ios/Views/InnerCircle/InnerCircleViewModel.swift index 14d4591..de11875 100644 --- a/nirvana-ios/Views/InnerCircle/InnerCircleViewModel.swift +++ b/nirvana-ios/Views/InnerCircle/InnerCircleViewModel.swift @@ -148,41 +148,57 @@ extension InnerCircleViewModel { if self.audioLocalUrl != nil { // upload to the cloud storage - self.cloudStorageService.uploadLocalUrl(localFileUrl: self.audioLocalUrl!) {[weak self] audioDataUrl in - if audioDataUrl == nil { - print("there was an error in uploading file") - self?.toast = .problemSendingClip - return - } - - let newMessage = Message(sendId: sender.id!, receivId: receiver.id!, audioDUrl: audioDataUrl!.absoluteString) - - // create a new message in firestore with the url for receiving user to automatically get notified - self?.firestoreService.createMessage(message: newMessage) {[weak self] res in - print(res) - - switch res { - case .success: - - self?.toast = .clipSent - - // sending push notification if there was a device token for this friend - if receiver.deviceToken != nil && receiver.nickname != nil { - self?.pushNotificationService.sendPushNotification(to: receiver.deviceToken!, title: "🌱Nirvana", body: "continue your conversation with \(sender.nickname ?? "your friend")") + DispatchQueue.global(qos: .background).async { + self.cloudStorageService.uploadLocalUrl(localFileUrl: self.audioLocalUrl!) {[weak self] audioDataUrl in + if audioDataUrl == nil { + print("there was an error in uploading file") + DispatchQueue.main.async { + self?.toast = .problemSendingClip } + return + } + + let newMessage = Message(sendId: sender.id!, receivId: receiver.id!, audioDUrl: audioDataUrl!.absoluteString) + + // create a new message in firestore with the url for receiving user to automatically get notified + self?.firestoreService.createMessage(message: newMessage) {[weak self] res in + print(res) - // delete local audio file from user's phone so that it doesn't take crazy space - print("stopped recording: file about to get deleted from \(self?.getTemporaryDirectory()) with filename: \(self?.audioLocalUrl)") - - try? FileManager.default.removeItem(at: (self?.audioLocalUrl)!) - case .error(let err): - print(err) - self?.toast = .problemSendingClip - default: - self?.toast = .problemSendingClip + DispatchQueue.main.async { + switch res { + case .success: + // play woosh + if let wooshFilePath = URL(string: Bundle.main.path(forResource: "woosh", ofType: "mp3") ?? "") { + print(wooshFilePath) + + self?.stopPlayingAnyAudio() + self?.queuePlayer = AVQueuePlayer(playerItem: AVPlayerItem(url: wooshFilePath)) + self?.queuePlayer.automaticallyWaitsToMinimizeStalling = false + self?.queuePlayer.play() + } + + self?.toast = .clipSent + + // sending push notification if there was a device token for this friend + if receiver.deviceToken != nil && receiver.nickname != nil { + self?.pushNotificationService.sendPushNotification(to: receiver.deviceToken!, title: "🌱Nirvana", body: "continue your conversation with \(sender.nickname ?? "your friend")") + } + + // delete local audio file from user's phone so that it doesn't take crazy space + print("stopped recording: file about to get deleted from \(self?.getTemporaryDirectory()) with filename: \(self?.audioLocalUrl)") + + try? FileManager.default.removeItem(at: (self?.audioLocalUrl)!) + case .error(let err): + print(err) + self?.toast = .problemSendingClip + default: + self?.toast = .problemSendingClip + } + } } } } + } else { print("nothing recorded, can't send") diff --git a/nirvana-ios/sounds/woosh.mp3 b/nirvana-ios/sounds/woosh.mp3 new file mode 100644 index 0000000..f65c2ce Binary files /dev/null and b/nirvana-ios/sounds/woosh.mp3 differ