Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] NearbyNetwork 광고, 검색 기능 리팩터링 #148

Merged
merged 7 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 122 additions & 0 deletions NearbyNetwork/NearbyNetwork.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

/* Begin PBXBuildFile section */
002DEC952D22A99F00ED7EE3 /* RefactoredNearbyNetworkService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 002DEC942D22A99F00ED7EE3 /* RefactoredNearbyNetworkService.swift */; };
002DEC9D2D23C33C00ED7EE3 /* NearbyNetworkTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 002DEC9C2D23C33C00ED7EE3 /* NearbyNetworkTests.swift */; };
002DEC9E2D23C33C00ED7EE3 /* NearbyNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5B7C6E652CDB6A560024704A /* NearbyNetwork.framework */; platformFilter = ios; };
00549AD62CEDDDB700DF8F6C /* MCSessionState+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00549AD52CEDDDB100DF8F6C /* MCSessionState+.swift */; };
00549AD82CEDDDCF00DF8F6C /* MCSession+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00549AD72CEDDDCF00DF8F6C /* MCSession+.swift */; };
0080E86A2CE19EC40095B958 /* NearbyNetworkService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0080E8672CE19EC40095B958 /* NearbyNetworkService.swift */; };
Expand All @@ -18,6 +20,16 @@
A83D2AB42D23C09F007EC41F /* NearbyNetworkKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = A83D2AB32D23C09F007EC41F /* NearbyNetworkKey.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
002DEC9F2D23C33C00ED7EE3 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 5B7C6E5C2CDB6A560024704A /* Project object */;
proxyType = 1;
remoteGlobalIDString = 5B7C6E642CDB6A560024704A;
remoteInfo = NearbyNetwork;
};
/* End PBXContainerItemProxy section */

/* Begin PBXCopyFilesBuildPhase section */
5B7C6EC12CDB6C6E0024704A /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
Expand All @@ -34,6 +46,8 @@

/* Begin PBXFileReference section */
002DEC942D22A99F00ED7EE3 /* RefactoredNearbyNetworkService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RefactoredNearbyNetworkService.swift; sourceTree = "<group>"; };
002DEC9A2D23C33C00ED7EE3 /* NearbyNetworkTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NearbyNetworkTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
002DEC9C2D23C33C00ED7EE3 /* NearbyNetworkTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NearbyNetworkTests.swift; sourceTree = "<group>"; };
00549AD52CEDDDB100DF8F6C /* MCSessionState+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MCSessionState+.swift"; sourceTree = "<group>"; };
00549AD72CEDDDCF00DF8F6C /* MCSession+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MCSession+.swift"; sourceTree = "<group>"; };
0080E8672CE19EC40095B958 /* NearbyNetworkService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NearbyNetworkService.swift; sourceTree = "<group>"; };
Expand All @@ -45,6 +59,14 @@
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
002DEC972D23C33C00ED7EE3 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
002DEC9E2D23C33C00ED7EE3 /* NearbyNetwork.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
5B7C6E622CDB6A560024704A /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
Expand All @@ -56,6 +78,14 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
002DEC9B2D23C33C00ED7EE3 /* NearbyNetworkTests */ = {
isa = PBXGroup;
children = (
002DEC9C2D23C33C00ED7EE3 /* NearbyNetworkTests.swift */,
);
path = NearbyNetworkTests;
sourceTree = "<group>";
};
00549AD32CEDDDA300DF8F6C /* Common */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -98,6 +128,7 @@
isa = PBXGroup;
children = (
0080E8692CE19EC40095B958 /* NearbyNetwork */,
002DEC9B2D23C33C00ED7EE3 /* NearbyNetworkTests */,
5B7C6EBD2CDB6C6E0024704A /* Frameworks */,
5B7C6E662CDB6A560024704A /* Products */,
);
Expand All @@ -107,6 +138,7 @@
isa = PBXGroup;
children = (
5B7C6E652CDB6A560024704A /* NearbyNetwork.framework */,
002DEC9A2D23C33C00ED7EE3 /* NearbyNetworkTests.xctest */,
);
name = Products;
sourceTree = "<group>";
Expand All @@ -132,6 +164,24 @@
/* End PBXHeadersBuildPhase section */

/* Begin PBXNativeTarget section */
002DEC992D23C33C00ED7EE3 /* NearbyNetworkTests */ = {
isa = PBXNativeTarget;
buildConfigurationList = 002DECA32D23C33C00ED7EE3 /* Build configuration list for PBXNativeTarget "NearbyNetworkTests" */;
buildPhases = (
002DEC962D23C33C00ED7EE3 /* Sources */,
002DEC972D23C33C00ED7EE3 /* Frameworks */,
002DEC982D23C33C00ED7EE3 /* Resources */,
);
buildRules = (
);
dependencies = (
002DECA02D23C33C00ED7EE3 /* PBXTargetDependency */,
);
name = NearbyNetworkTests;
productName = NearbyNetworkTests;
productReference = 002DEC9A2D23C33C00ED7EE3 /* NearbyNetworkTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
5B7C6E642CDB6A560024704A /* NearbyNetwork */ = {
isa = PBXNativeTarget;
buildConfigurationList = 5B7C6E6B2CDB6A560024704A /* Build configuration list for PBXNativeTarget "NearbyNetwork" */;
Expand Down Expand Up @@ -161,8 +211,12 @@
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1540;
LastUpgradeCheck = 1600;
TargetAttributes = {
002DEC992D23C33C00ED7EE3 = {
CreatedOnToolsVersion = 15.4;
};
5B7C6E642CDB6A560024704A = {
CreatedOnToolsVersion = 16.0;
LastSwiftMigration = 1600;
Expand All @@ -184,11 +238,19 @@
projectRoot = "";
targets = (
5B7C6E642CDB6A560024704A /* NearbyNetwork */,
002DEC992D23C33C00ED7EE3 /* NearbyNetworkTests */,
);
};
/* End PBXProject section */

/* Begin PBXResourcesBuildPhase section */
002DEC982D23C33C00ED7EE3 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
5B7C6E632CDB6A560024704A /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -220,6 +282,14 @@
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
002DEC962D23C33C00ED7EE3 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
002DEC9D2D23C33C00ED7EE3 /* NearbyNetworkTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
5B7C6E612CDB6A560024704A /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
Expand All @@ -236,7 +306,50 @@
};
/* End PBXSourcesBuildPhase section */

/* Begin PBXTargetDependency section */
002DECA02D23C33C00ED7EE3 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
platformFilter = ios;
target = 5B7C6E642CDB6A560024704A /* NearbyNetwork */;
targetProxy = 002DEC9F2D23C33C00ED7EE3 /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */

/* Begin XCBuildConfiguration section */
002DECA12D23C33C00ED7EE3 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = VKW8W27KRV;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = kr.codesquad.boostcamp9.NearbyNetworkTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
002DECA22D23C33C00ED7EE3 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = VKW8W27KRV;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = kr.codesquad.boostcamp9.NearbyNetworkTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
};
5B7C6E6C2CDB6A560024704A /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
Expand Down Expand Up @@ -446,6 +559,15 @@
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
002DECA32D23C33C00ED7EE3 /* Build configuration list for PBXNativeTarget "NearbyNetworkTests" */ = {
isa = XCConfigurationList;
buildConfigurations = (
002DECA12D23C33C00ED7EE3 /* Debug */,
002DECA22D23C33C00ED7EE3 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
5B7C6E5F2CDB6A560024704A /* Build configuration list for PBXProject "NearbyNetwork" */ = {
isa = XCConfigurationList;
buildConfigurations = (
Expand Down
27 changes: 24 additions & 3 deletions NearbyNetwork/NearbyNetwork/Sources/NearbyNetworkBrowser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@ import Foundation
import Network
import OSLog

final class NearbyNetworkBrowser {
public protocol NearbyNetworkBrowserDelegate: AnyObject {
func nearbyNetworkBrowserDidFindPeer(
_ sender: NearbyNetworkBrowser,
hostName: String,
connectedPeerInfo: [String])
}

public final class NearbyNetworkBrowser {
let nwBrowser: NWBrowser
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

외부에서 browser를 직접 접근 하는 경우가 있을까요?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이런,,따로 외부에서 browser에 접근하는 경우가 없기 때문에 private으로 바꾸도록 하겠습니다!!

private let browserQueue: DispatchQueue
private let serviceType: String
private let logger: Logger
weak var delegate: NearbyNetworkBrowserDelegate?

init(serviceType: String) {
nwBrowser = NWBrowser(
Expand All @@ -33,8 +41,21 @@ final class NearbyNetworkBrowser {
for result in results {
switch result.metadata {
case .bonjour(let foundedPeerData):
// TODO: - 추후 발견한 데이터 이용
print("")
let dictionary = foundedPeerData.dictionary
guard
let hostName = dictionary[NearbyNetworkKey.host.rawValue],
let connectedPeerInfo = dictionary[NearbyNetworkKey.connectedPeerInfo.rawValue]
else {
logger.log(level: .error, "connection의 데이터 값이 유효하지 않습니다.")
return
}

delegate?.nearbyNetworkBrowserDidFindPeer(
self,
hostName: hostName,
connectedPeerInfo: connectedPeerInfo
.split(separator: ",")
.map { String($0) })
default:
logger.log(level: .error, "알 수 없는 피어가 발견되었습니다.")
}
Expand Down
2 changes: 1 addition & 1 deletion NearbyNetwork/NearbyNetwork/Sources/NearbyNetworkKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by 최정인 on 12/31/24.
//

enum NearbyNetworkKey: String {
public enum NearbyNetworkKey: String {
case host
case connectedPeerInfo
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ import Network
import OSLog

// TODO: - 추후 기능 동작 확인 후 NearbyNetworkService 대체
final class RefactoredNearbyNetworkService {
var connectionDelegate: NearbyNetworkConnectionDelegate? = nil
public final class RefactoredNearbyNetworkService {
public var connectionDelegate: NearbyNetworkConnectionDelegate? = nil
private let serviceName: String
private let serviceType: String
private let peerID: UUID
private let nearbyNetworkListener: NearbyNetworkListener
private let nearbyNetworkBrowser: NearbyNetworkBrowser
private let logger: Logger
public var foundPeerHandler: ((_ hostName: String, _ connectedPeerInfo: [String]) -> Void)?

public init(serviceName: String, serviceType: String) throws {
public init(serviceName: String, serviceType: String) {
peerID = UUID()
logger = Logger()
nearbyNetworkListener = NearbyNetworkListener(
Expand All @@ -30,15 +31,17 @@ final class RefactoredNearbyNetworkService {
nearbyNetworkBrowser = NearbyNetworkBrowser(serviceType: serviceType)
self.serviceName = serviceName
self.serviceType = serviceType
nearbyNetworkBrowser.delegate = self
}
}

// MARK: - NearbyNetworkInterface 메서드 구현
extension RefactoredNearbyNetworkService: NearbyNetworkInterface {
var reciptDataPublisher: AnyPublisher<Data, Never> {
public var reciptDataPublisher: AnyPublisher<Data, Never> {
return Just<Data>(Data()).eraseToAnyPublisher()
}

var reciptURLPublisher: AnyPublisher<(url: URL, dataInfo: DataInformationDTO), Never> {
public var reciptURLPublisher: AnyPublisher<(url: URL, dataInfo: DataInformationDTO), Never> {
// TODO: - will be deprecated
guard let url = URL(string: "https://naver.com") else { fatalError() }
let dataInfo = DataInformationDTO(
Expand All @@ -49,45 +52,57 @@ extension RefactoredNearbyNetworkService: NearbyNetworkInterface {
.eraseToAnyPublisher()
}

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

func stopSearching() {
public func stopSearching() {
nearbyNetworkBrowser.stopSearching()
}

func startPublishing(with info: [String: String]) {
public func startPublishing(with info: [String: String]) {
// TODO: - will be deprecated
}

func startPublishing(with hostName: String, connectedPeerInfo: [String]) {
public func startPublishing(with hostName: String, connectedPeerInfo: [String]) {
nearbyNetworkListener.startPublishing(
hostName: hostName,
connectedPeerInfo: connectedPeerInfo)
}

func stopPublishing() {
public func stopPublishing() {
nearbyNetworkListener.stopPublishing()
}

func disconnectAll() {
public func disconnectAll() {

}

func joinConnection(connection: NetworkConnection, context: RequestedContext) throws {
public func joinConnection(connection: NetworkConnection, context: RequestedContext) throws {

}

func send(data: Data) {
public func send(data: Data) {

}

func send(fileURL: URL, info: DataInformationDTO) async {
public func send(fileURL: URL, info: DataInformationDTO) async {
// TODO: - will be deprecated
}

func send(fileURL: URL, info: DataInformationDTO, to connection: NetworkConnection) async {
public func send(fileURL: URL, info: DataInformationDTO, to connection: NetworkConnection) async {
// TODO: - will be deprecated
}
}

// MARK: - NearbyNetworkBrowserDelegate
extension RefactoredNearbyNetworkService: NearbyNetworkBrowserDelegate {
public func nearbyNetworkBrowserDidFindPeer(
_ sender: NearbyNetworkBrowser,
hostName: String,
connectedPeerInfo: [String]
) {
guard let foundPeerHandler else { return }
foundPeerHandler(hostName, connectedPeerInfo)
}
}
Loading