Skip to content

Commit

Permalink
[fix] #12 프로필 데이터를 가지지 않고 데이터 로드 역할을 맡지 않도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
green-yoon87 committed Jan 14, 2025
1 parent 1e93eca commit 0326a31
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions SniffMeet/SniffMeet/Source/LocalNetwork/MPC/MPCManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,19 @@ extension String {
}

final class MPCManager: NSObject {
let dataManager = LocalDataManager()
let advertiser: MPCAdvertiser
let browser: MPCBrowser
let session: MCSession
let mypeerID: MCPeerID
var dog: UserInfo?
var profile: DogProfileDTO?

private var cancellables = Set<AnyCancellable>()

@Published var paired: Bool = false

var receivedTokenPublisher = PassthroughSubject<Data, Never>()
var receivedDataPublisher = PassthroughSubject<DogProfileDTO, Never>()
var receivedViewTransitionPublisher = PassthroughSubject<String, Never>()
var isAvailableToBeConnected: Bool = false {
didSet {
do {
dog = try dataManager.loadData(forKey: "dogInfo", type: UserInfo.self)
updateProfile(dogInfo: dog ?? UserInfo.example)
} catch {
SNMLogger.error("loadData error : \(error)")
}

if isAvailableToBeConnected {
advertiser.startAdvertising()
browser.startBrowsing()
Expand Down Expand Up @@ -107,7 +96,6 @@ final class MPCManager: NSObject {
SNMLogger.log("no one is connected")
return
}

do {
try self.session.send(data, toPeers: session.connectedPeers, with: .reliable)
SNMLogger.log("DogProfileInfo 전송 성공")
Expand Down Expand Up @@ -147,7 +135,6 @@ extension MPCManager: MCSessionDelegate {
self.paired = true
self.isAvailableToBeConnected = false
SNMLogger.info("ConnectedPeers: \(session.connectedPeers)")
sendData(profile: profile ?? DogProfileDTO.example)
}
default:
Task { @MainActor in
Expand All @@ -156,7 +143,11 @@ extension MPCManager: MCSessionDelegate {
}
}

func session(_ session: MCSession, didReceive data: Data, fromPeer peerID: MCPeerID) {
func session(
_ session: MCSession,
didReceive data: Data,
fromPeer peerID: MCPeerID
) {
SNMLogger.info("didReceive bytes \(data.count) bytes")

do {
Expand Down

0 comments on commit 0326a31

Please sign in to comment.