Skip to content

Commit

Permalink
[refactor] #12 NI, MPC 매니저 로직 일부 유즈케이스로 이동
Browse files Browse the repository at this point in the history
- 매니저에서 관리할 필요가 없는 로직들을 제거했습니다.
- 데이터 인코딩
- DTO 변환

Co-Authored-By: YOON JI SEONG <[email protected]>
  • Loading branch information
Kelly-Chui and green-yoon87 committed Jan 14, 2025
1 parent 771fb63 commit 13278b3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 25 deletions.
29 changes: 6 additions & 23 deletions SniffMeet/SniffMeet/Source/LocalNetwork/MPC/MPCManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,18 @@ final class MPCManager: NSObject {
SNMLogger.error("error sending \(error.localizedDescription)")
}
}

func sendData(profile: DogProfileDTO) {
func sendData(data: Data) {
guard !session.connectedPeers.isEmpty else {
SNMLogger.log("no one is connected")
return
}

do {
let dataToSend = MPCProfileDropDTO(token: nil, profile: profile, transitionMessage: nil)
let encodedData = try JSONEncoder().encode(dataToSend)
SNMLogger.info("encodedData is \(encodedData)")
sendProfileData(data: encodedData)

try self.session.send(data, toPeers: session.connectedPeers, with: .reliable)
SNMLogger.log("DogProfileInfo 전송 성공")
} catch {
SNMLogger.error("DogProfileInfo 전송 실패: \(error.localizedDescription)")
SNMLogger.error("DogProfileInfo 전송 실패 \(error.localizedDescription)")
}
}

Expand All @@ -131,20 +128,6 @@ final class MPCManager: NSObject {
SNMLogger.error("error sending \(error.localizedDescription)")
}
}

private func updateProfile(dogInfo: UserInfo) {
guard let userID = SessionManager.shared.session?.user?.userID else { return }
profile = DogProfileDTO(id: userID, name: dogInfo.name, keywords: dogInfo.keywords, profileImage: dogInfo.profileImage)
}

private func sendProfileData(data: Data) {
do {
try self.session.send(data, toPeers: session.connectedPeers, with: .reliable)
SNMLogger.log("DogProfileInfo 전송 성공")
} catch {
SNMLogger.error("DogProfileInfo 전송 실패 \(error.localizedDescription)")
}
}
}

// MARK: - MCSessionDelegate
Expand Down
3 changes: 1 addition & 2 deletions SniffMeet/SniffMeet/Source/LocalNetwork/NI/NIManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ import NearbyInteraction

final class NIManager: NSObject {
private var niSession: NISession?
private var mpcManager: MPCManager
private var cancellables = Set<AnyCancellable>()

private let minDistance: Float = 0.09
private let maxDistance: Float = 0.15
private let minDirection: simd_float3 = simd_float3(-0.6, -0.3, -1.0)
private let maxDirection: simd_float3 = simd_float3(0.6, 0.3, -0.8)

@Published var niPaired: Bool = false
var mpcManager: MPCManager
var isViewTransitioning = PassthroughSubject<Bool, Never>()
var viewTransitionInfo = Set<String>()

Expand Down

0 comments on commit 13278b3

Please sign in to comment.