Skip to content

Commit

Permalink
refactor: Searching 메서드 통합
Browse files Browse the repository at this point in the history
  • Loading branch information
ekrud99 committed Nov 30, 2024
1 parent a7f0093 commit abb72bb
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,12 @@ public protocol NearbyNetworkInterface {
var reciptDataPublisher: AnyPublisher<Data, Never> { get }
var reciptURLPublisher: AnyPublisher<(url: URL, dataInfo: DataInformationDTO), Never> { get }
var connectionDelegate: NearbyNetworkConnectionDelegate? { get set }

/// 주변 기기를 검색합니다.
func startSearching()


/// 주변 기기 검색을 중지합니다.
func stopSearching()

/// 주변 기기 검색을 중지 후 다시 시작합니다.
func restartSearching()
/// 주변 기기를 검색합니다.
func startSearching()

/// 주변에 내 기기를 정보와 함께 알립니다.
/// - Parameter data: 담을 정보
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ public final class WhiteboardRepository: WhiteboardRepositoryInterface {
nearbyNetwork.startPublishing(with: participantsInfo)
}

public func startSearching() {
nearbyNetwork.startSearching()
}

public func disconnectWhiteboard() {
nearbyNetwork.disconnectAll()
nearbyNetwork.stopPublishing()
Expand All @@ -64,8 +60,8 @@ public final class WhiteboardRepository: WhiteboardRepositoryInterface {
nearbyNetwork.stopSearching()
}

public func restartSearching() {
nearbyNetwork.restartSearching()
public func startSearching() {
nearbyNetwork.startSearching()
}

private func updatePublishingInfo(myProfile: Profile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@ public protocol WhiteboardRepositoryInterface {
/// - Parameter myProfile: 나의 프로필
func startPublishing(myProfile: Profile)

/// 주변 화이트보드를 탐색합니다.
func startSearching()

/// 화이트보드 탐색을 중지합니다.
func stopSearching()

/// 화이트보드 탐색을 중단 후 다시 시작합니다.
func restartSearching()
/// 화이트보드 탐색을 시작합니다.
func startSearching()

/// 화이트보드와 연결을 끊습니다.
func disconnectWhiteboard()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ public protocol WhiteboardUseCaseInterface {
/// 주변에 내 기기를 정보와 함께 알립니다.
func startPublishingWhiteboard()

/// 주변 화이트보드를 탐색합니다.
func startSearchingWhiteboard()

/// 화이트보드와 연결을 끊습니다.
/// 화이트보드와 연결을 끊습니다.
func disconnectWhiteboard()

/// 선택한 화이트보드와 연결을 시도합니다.
Expand All @@ -29,6 +26,6 @@ public protocol WhiteboardUseCaseInterface {
/// 화이트보드 탐색을 중지합니다.
func stopSearchingWhiteboard()

/// 화이트보드 탐색을 중단 후 다시 시작합니다.
func refreshWhiteboardList()
/// 주변 화이트보드를 탐색합니다.
func startSearchingWhiteboards()
}
8 changes: 2 additions & 6 deletions Domain/Domain/Sources/UseCase/WhiteboardUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ public final class WhiteboardUseCase: WhiteboardUseCaseInterface {
whiteboardRepository.startPublishing(myProfile: myProfile)
}

public func startSearchingWhiteboard() {
whiteboardRepository.startSearching()
}

public func stopSearchingWhiteboard() {
whiteboardRepository.stopSearching()
}
Expand All @@ -55,8 +51,8 @@ public final class WhiteboardUseCase: WhiteboardUseCaseInterface {
try whiteboardRepository.joinWhiteboard(whiteboard: whiteboard, myProfile: profile)
}

public func refreshWhiteboardList() {
whiteboardRepository.restartSearching()
public func startSearchingWhiteboards() {
whiteboardRepository.startSearching()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,11 @@ public final class NearbyNetworkService: NSObject {

// MARK: - NearbyNetworkInterface
extension NearbyNetworkService: NearbyNetworkInterface {
public func startSearching() {
serviceBrowser.startBrowsingForPeers()
}

public func stopSearching() {
serviceBrowser.stopBrowsingForPeers()
}

public func restartSearching() {
public func startSearching() {
serialQueue.sync {
serviceBrowser.stopBrowsingForPeers()
foundPeers.removeAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public final class WhiteboardListViewController: UIViewController {

public override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
viewModel.action(input: .searchWhiteboard)
viewModel.action(input: .startSearchingWhiteboards)
}

public override func viewDidDisappear(_ animated: Bool) {
Expand Down Expand Up @@ -267,7 +267,7 @@ public final class WhiteboardListViewController: UIViewController {
}

private func refreshWhiteboardList() {
viewModel.action(input: .refreshWhiteboardList)
viewModel.action(input: .startSearchingWhiteboards)
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { [weak self] in
self?.refreshControl.endRefreshing()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ public final class WhiteboardListViewModel: ViewModel {

enum Input {
case createWhiteboard
case searchWhiteboard
case joinWhiteboard(whiteboard: Whiteboard)
case stopSearchingWhiteboard
case refreshWhiteboardList
case startSearchingWhiteboards
}

struct Output {
Expand All @@ -39,13 +38,11 @@ public final class WhiteboardListViewModel: ViewModel {
switch input {
case .createWhiteboard:
createWhiteboard()
case .searchWhiteboard:
searchWhiteboard()
case .joinWhiteboard(let whiteboard):
joinWhiteboard(whiteboard: whiteboard)
case .stopSearchingWhiteboard:
stopSearchingWhiteboard()
case .refreshWhiteboardList:
case .startSearchingWhiteboards:
refreshWhiteboardList()
}
}
Expand All @@ -56,10 +53,6 @@ public final class WhiteboardListViewModel: ViewModel {
whiteboardSubject.send(whiteboard)
}

private func searchWhiteboard() {
whiteboardUseCase.startSearchingWhiteboard()
}

private func joinWhiteboard(whiteboard: Whiteboard) {
do {
try whiteboardUseCase.joinWhiteboard(whiteboard: whiteboard)
Expand All @@ -73,6 +66,6 @@ public final class WhiteboardListViewModel: ViewModel {
}

private func refreshWhiteboardList() {
whiteboardUseCase.refreshWhiteboardList()
whiteboardUseCase.startSearchingWhiteboards()
}
}

0 comments on commit abb72bb

Please sign in to comment.