Skip to content

Commit

Permalink
1.8.1 (315)
Browse files Browse the repository at this point in the history
  • Loading branch information
denis15yo committed Sep 13, 2024
1 parent 4abe157 commit ae312a9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
27 changes: 24 additions & 3 deletions submodules/TelegramCallsUI/Sources/PresentationCall.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import UniversalMediaPlayer
import AccountContext
import DeviceProximity
import PhoneNumberFormat
// MARK: Nicegram NCG-5828 call recording
import NGLogging
//

public final class PresentationCallImpl: PresentationCall {
public let context: AccountContext
Expand Down Expand Up @@ -631,8 +634,8 @@ public final class PresentationCallImpl: PresentationCall {
}
case let .terminated(_, _, options):
// MARK: Nicegram NCG-5828 call recording
self.sharedAudioDevice?.stopNicegramRecording { [weak self] path, duration, data in
self?.saveCall(with: path, duration: duration, data: data)
self.sharedAudioDevice?.stopNicegramRecording { [weak self] path, duration in
self?.saveCall(with: path, duration: duration)
}
//
self.audioSessionShouldBeActive.set(true)
Expand Down Expand Up @@ -1078,7 +1081,14 @@ public final class PresentationCallImpl: PresentationCall {
}

// MARK: Nicegram NCG-5828 call recording
private func saveCall(with path: String, duration: Double, data: Data) {
private func loadData(from path: String) async throws -> Data {
let fileURL = URL(fileURLWithPath: path)
let (data, _) = try await URLSession.shared.data(from: fileURL)

return data
}

private func writeAudioToSaved(from path: String, duration: Double, data: Data) {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd_HH:mm:ss"

Expand Down Expand Up @@ -1130,5 +1140,16 @@ public final class PresentationCallImpl: PresentationCall {
messages: [message]
).start()
}

private func saveCall(with path: String, duration: Double) {
Task {
do {
let data = try await loadData(from: path)
writeAudioToSaved(from: path, duration: duration, data: data)
} catch {
ngLog("[\(#file)]-[\(#function)]-[\(#line)] Error load call data from wave file: \(error.localizedDescription)")
}
}
}
//
}
2 changes: 1 addition & 1 deletion submodules/TelegramVoip/Sources/OngoingCallContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ public final class OngoingCallContext {
self.impl.startNicegramRecording()
}

public func stopNicegramRecording(callback: ((String, Double, Data) -> Void)?) {
public func stopNicegramRecording(callback: ((String, Double) -> Void)?) {
self.impl.stopNicegramRecording(callback)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
// MARK: Nicegram NCG-5828 call recording
-(void)InitNicegramCallRecording:(NSString* _Nonnull)path;
-(void)StartNicegramRecording;
-(void)StopNicegramRecording:(void(^_Nullable)(NSString* _Nonnull, double, NSData* _Nonnull))completion;
-(void)StopNicegramRecording:(void(^_Nullable)(NSString* _Nonnull, double))completion;
-(void)SetRecordOutputFolder:(NSString* _Nonnull)path;
//
@end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,15 @@ -(void)StartNicegramRecording {
});
}

-(void)StopNicegramRecording:(void(^_Nullable)(NSString* _Nonnull, double, NSData* _Nonnull))completion {
-(void)StopNicegramRecording:(void(^_Nullable)(NSString* _Nonnull, double))completion {
_audioDeviceModule->perform([completion](tgcalls::SharedAudioDeviceModule *audioDeviceModule) {
audioDeviceModule->audioDeviceModule()->StopNicegramRecording([completion](const std::string& outputFilePath,
double durationInSeconds,
std::vector<int16_t> rawData) {
NSString *path = [NSString stringWithUTF8String: outputFilePath.c_str()];
NSData *data = [NSData dataWithBytes: rawData.data() length: sizeof(rawData)];

if (completion != NULL) {
completion(path, durationInSeconds, data);
completion(path, durationInSeconds);
}
});
});
Expand Down

0 comments on commit ae312a9

Please sign in to comment.