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

[Feature] 근거리 통신 모듈에 URL을 이용한 통신 메서드 추가 #103

Merged
merged 5 commits into from
Nov 20, 2024

Conversation

taipaise
Copy link
Collaborator

🌁 Background

  • 단순 data만 receive 했을 때 어떤 entity로 디코딩 해야하는지 알 수 없는 문제가 발생했습니다.
  • MCSession의 send 메서드에 local File의 URL과, 이름을 지정해서 보낼 수 있는 메서드가 있어 이걸 활용해 전송하기로 했습니다.

👩‍💻 Contents

  • 근거리 통신 모듈의 delegate가 너무 많은 역할을 수행하고 있다 느껴졌습니다. 해당 모듈을 사용하는 repository에서 사용하지 않는 인터페이스가 발생할 가능성이 있다고 판단하여 delegate 프로토콜을 두 개로 나누었습니다. 링크
  • @ekrud99 @choijungp 생참 팀에서 현재 사용하고 있는 WhiteboardObject에도 영향이 가는 작업이기 때문에 확인해주시면 감사하겠습니다. 적절한 delegate 명이 있다면 수정하도록 하겠습니다.
  • 근거리 통신 모듈에 URL을 이용한 송신, 수신 메서드를 구현했습니다.

✅ Testing

  • Framework의 동작이기 때문에 따로 테스트하지는 않았습니다.

📝 Review Note

  • 에러 처리에 대한 정책이 필요하다고 생각합니다. 다만 아직은 구현이 더 급하기 때문에 조금 후순위로 미뤄도 괜찮을 것 같습니다.
  • MCSessionsendResource 메서드는 완료 핸들러를 통해 비동기 이벤트를 처리하는데요, 이를 Swift Concurrency로 래핑하였습니다.
  • sendResource를 통해 데이터를 전송하는 방식은 일반 send와는 다르게 peer에게 1:1로 데이터를 송신합니다. 따라서 반복문으로 연결된 피어들에게 데이터를 전송해줘야 했습니다. 좀 더 효율적으로 전송하기 위해 TaskGroup을 이용하여 데이터를 병렬 전송하는 방법을 선택했습니다.

📣 Related Issue

📬 Reference

@taipaise taipaise self-assigned this Nov 20, 2024
@taipaise taipaise added this to the 데이터 송수신 milestone Nov 20, 2024
@taipaise taipaise force-pushed the feature/transferFileData branch 2 times, most recently from c0adb53 to 044ee71 Compare November 20, 2024 10:19
Copy link
Member

@eemdeeks eemdeeks left a comment

Choose a reason for hiding this comment

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

고생하셨습니다!!

swift concurrency가 알고있는 것보다 공부할 것이 더 많군요..

Comment on lines +69 to +72
func nearbyNetwork(
_ sender: NearbyNetworkInterface,
didReceiveURL URL: URL,
info: DataInformationDTO)
Copy link
Member

Choose a reason for hiding this comment

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

style: 닫히는 괄호가 밑으로 내려와야 하는 것 같습니다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

요 부분은 저희 같이 이야기 나눈대로 현상유지하도록 하겠습니다 :)

Comment on lines 23 to 24
toPeer: peer
) { error in
Copy link
Member

Choose a reason for hiding this comment

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

style: 소괄호 올라가 있어야 할 것 같습니다ㅜㅜ

새로 생성 해 준것이라고 착각했었네요...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

바로 수정하겠습니다!!!!!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

e626d5c 반영했습니다!!

) async throws {
typealias Continuation = CheckedContinuation<Void, Error>

try await withCheckedThrowingContinuation { (continuation: Continuation) in
Copy link
Member

Choose a reason for hiding this comment

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

이것을 통해 swift Concurrency처럼 사용할 수 있게 해주는 군요..!

이부분은 공부를 해봐야할 것 같습니다..!ㅜㅜ

Copy link
Collaborator

Choose a reason for hiding this comment

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

꺆 !!!!!!!!!!!!!! 쏘 어렵 ... 내일 설명해주기 .......................................

Comment on lines +109 to +122
await withTaskGroup(of: Void.self) { taskGroup in
session.connectedPeers.forEach { peer in
taskGroup.addTask {
do {
try await self.session.sendResource(
at: fileURL,
withName: infoJsonString,
toPeer: peer)
} catch {
self.logger.log(level: .error, "\(peer)에게 file 데이터 전송 실패")
}
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

이부분도 공부해보겠습니다!

Copy link
Collaborator

Choose a reason for hiding this comment

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

다시봐도 어렵네유

Copy link
Collaborator

@choijungp choijungp left a comment

Choose a reason for hiding this comment

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

어푸푸 어푸푸푸 어푸푸 어푸푸푸푸 굉장히 어려운 부분 .....................................
Concurrency 공부할 기회를 주셔서 감사 ..... 😇👏🏻

@@ -8,7 +8,7 @@
import Foundation

public protocol NearbyNetworkInterface {
var delegate: NearbyNetworkDelegate? { get set }
var connectionDelegate: NearbyNetworkConnectionDelegate? { get set }
Copy link
Collaborator

Choose a reason for hiding this comment

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

그러니까 근거리통신 연결 로직을 NearbyNetworkConnectionDelegate가,
근거리통신 송수신 로직을 NearbyNetworkReceiptDelegate가 담당하게 되는게 맞나요 ??

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

똑똑한 조이 맞습니다!!

import Foundation

public struct DataInformationDTO: Codable {
let identifier: UUID
Copy link
Collaborator

Choose a reason for hiding this comment

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

단순 궁금증인데 다른 Entity들은 id로 되어 있는데 이 친구는 왜 identifier로 췤 하는지 ?? 요

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

id 로 수정하겠습니다

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

e626d5c 반영했습니다!!

) async throws {
typealias Continuation = CheckedContinuation<Void, Error>

try await withCheckedThrowingContinuation { (continuation: Continuation) in
Copy link
Collaborator

Choose a reason for hiding this comment

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

꺆 !!!!!!!!!!!!!! 쏘 어렵 ... 내일 설명해주기 .......................................

@taipaise taipaise force-pushed the feature/transferFileData branch from e626d5c to 2c0bf1d Compare November 20, 2024 14:44
@taipaise taipaise force-pushed the feature/transferFileData branch from 2c0bf1d to 6db839f Compare November 20, 2024 14:48
@taipaise taipaise merged commit 621694e into develop Nov 20, 2024
1 check passed
@taipaise taipaise deleted the feature/transferFileData branch November 21, 2024 04:24
Copy link
Collaborator

@ekrud99 ekrud99 left a comment

Choose a reason for hiding this comment

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

고생하셨씁니다!

Comment on lines +109 to +122
await withTaskGroup(of: Void.self) { taskGroup in
session.connectedPeers.forEach { peer in
taskGroup.addTask {
do {
try await self.session.sendResource(
at: fileURL,
withName: infoJsonString,
toPeer: peer)
} catch {
self.logger.log(level: .error, "\(peer)에게 file 데이터 전송 실패")
}
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

다시봐도 어렵네유

@@ -55,3 +55,19 @@ public protocol NearbyNetworkDelegate: AnyObject {
/// 주변 기기와의 연결에 실패했을 때 실행됩니다.
func nearbyNetworkCannotConnect(_ sender: NearbyNetworkInterface)
}

public protocol NearbyNetworkReceiptDelegate: AnyObject {
Copy link
Collaborator

Choose a reason for hiding this comment

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

connection, receipt 적절한 기준으로 잘 나눈거같아용

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] 파일 데이터 수신 기능 구현 [Feature] 파일 데이터 송신 기능 구현
4 participants