-
Notifications
You must be signed in to change notification settings - Fork 0
[DEV-21] 네트워크 초대 요청 송수신 로직 구현 #54
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
base: develop
Are you sure you want to change the base?
Conversation
yungu0010
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생하셨습니다! 궁금한 점 코멘트 남겼어요ㅎ.ㅎ 제가 잘 이해하지 못한 부분이 있다면 설명 부탁드립니다!
| @@ -1,17 +1,18 @@ | |||
| // | |||
| // SessionProvider.swift | |||
| // NetworkSessionManager.swift | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
감사합니다👍
|
|
||
| // MARK: - Private Methods | ||
|
|
||
| private func setupCallbacks() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
p2: 내부 로직을 setupHostCallback과 setupClientCallback으로 분리해도 좋을 것 같네요!
|
|
||
| public var onLocalNetworkPermissionGranted: (() -> Void)? | ||
| public var onLocalNetworkPermissionDenied: ((Error) -> Void)? | ||
| public var onInviteReceived: ((_ from: String) -> Void)? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
p1: ConnectionSessionProvider 프로토콜에 함께 선언해주면 좋을 것 같아요!
| } | ||
|
|
||
| // 메세지 전송 패킷 | ||
| public struct GamePacket: Codable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
p1: public으로 설정하신 이유가 있는지 궁금합니다! 외부 모듈에서도 해당 Packet의 구조를 알아야하나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
다음 PR UI 작업에서 데이터 전달시 사용할 예정입니다!
| public var onInviteAccepted: (() -> Void)? | ||
| public var onInviteDeclined: (() -> Void)? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
p2: 부울 값을 담는 클로저로 통합해서 Router에서 분기처리를 하는 방법도 있을 것 같아요~!(취향차이인 것 같아서 참고만 해주세요)
| public var onInviteAccepted: (() -> Void)? | |
| public var onInviteDeclined: (() -> Void)? | |
| public var onInviteStateDecided: ((Bool) -> Void)? |
| private let decoder = JSONDecoder() | ||
| private let encoder = JSONEncoder() | ||
|
|
||
| private var incomingInviteConnection: NWConnection? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
p1: 이렇게 되면 Host는 한 번에 하나의 초대만 관리할 수 있는 것으로 보여요.
디바이스 A, B, C가 있을 때
- B가 A에게 초대
- A가 고민 중
- 그 사이 C가 A에게 초대
이 경우 A는 하나의 connection만 관리하기 때문에 B의 초대에 응답을 할 수 없게될 것 같습니다!(잘못 이해했다면 말씀해주세요)
이런 경우를 처리하기 위해 hostManager에서 connections라는 배열을 두었는데, 여러개의 connections을 관리할 수 있도록 개선이 필요해보여요!
host에서 직접 connection을 관리하고, NetworkSession은 데이터 파싱만 하는 구조를 가지는게 어떨까요.. ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오호 감사합니다!
NetworkSessionManager가 초대 요청에 대한 응답처리도 해야되는데
초대 요청에 대한 응답을 누구한테 줄지 NetworkSessionManager의 handleReceivedData에서 packet을 파싱해서 내용을 보고 누가 보낸 것인지 구분이 필요할 것 같아요! UI에서 packet으로 초대 요청자의 닉네임을 보내오니까 (connection을 패킷에 넣을 수는 없고)
여기서 딕셔너리([닉네임: NWConnection])로 구분해서 사용해도 될 것 같습니당!
| } | ||
| } | ||
|
|
||
| public func sendGamePacket(_ packet: GamePacket, to peer: Peer? = nil) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
p1: Peer가 옵셔널인 이유가 무엇인가요? 초대 요청을 하려면 항상 Peer가 존재해야하는 것 아닌가요?_?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
초대와 수락 응답에 해당 함수를 공통으로 사용하려고 했었고,
수락 응답시에는 이미 연결되어 있는 connection을 저장해놨으니까 peer객체가 필요 없어서 옵셔널로 했었습니다!
근데 요청용과 초대 응답의 함수를 분리하는게 나을 것 같기도 합니다! 위에 수정하면서 고민해볼게요!
leesungkug
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
코드 잘 봤습니다! 윤돌이 말해준 것처럼 커넥션 관리하는 부분만 수정되면 좋을 것 같아요
| } | ||
| } | ||
|
|
||
| private func handleReceivedData(_ data: Data, from connection: NWConnection? = nil) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
p2: 나중에 게임 데이터 송수신 시에는 현재 연결된 커넥션을 재사용하거나, 별도 채널을 열어 처리할 수도 있을 것 같아요. 그래서 게임 통신을 구현할 때 메서드 이름만 봐도 초대 데이터 처리 역할이 드러나도록 네이밍을 가져가면 좋을 것 같아요.
oyobbeb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
회의때 말했던 내용들 다시 작성해보았어요~! 👍🏼
| } | ||
|
|
||
| // 메세지 전송 패킷 | ||
| public struct GamePacket: Codable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
p1: GamePacket 이라는 이름이 NetworkKit아래에 있어서 어색한 것 같아요! General한 근거리 통신 혹은 NetworkPacket과 같이 도메인 내용이 없어도 될 것 같아요!
GameMessageType도 동일하게 생각해요!
| // 메세지 전송 패킷 | ||
| public struct GamePacket: Codable { | ||
| public let type: GameMessageType | ||
| public let senderNickname: String |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: senderIdentifier와 같은 느낌도 괜찮을 것 같아요!
ea30610 to
e4379b6
Compare
- GameMessageType: 주고 받을 메세지 타입 정보 - GamePacket: 실제로 주고 받을 메세지 전송 패킷 refs: DEV-21
- HostManager, ClientManager에서 서로 데이터 수신시 NetworkSessionManager에게 전달하기 위함. refs: DEV-21
- handleReceivedData: ClientManager, HostManager에서 전달받은 onDataReceived 클로저의 데이터를 처리하여 추후 UI로 전달 - sendGamePacket: UI에서 GamePacket data(초대/ 수락 및 거절 응답)를 보내기 위함. refs: DEV-21
- onInviteReceived, onInviteResponse, onInviteCanceled 클로저 추가 - requestInvite, replyToInvite 메소드 추가 refs: DEV-21
- sendGamePacket 한개로 초대 / 수락응답을 모두 처리하려고 했으나 역할에 따른 분리가 필요하다고 생각하여 변경 - requestInvite의 데이터 전송 전 연결 체크를 위해 client.connectToHost(endpoint: peer.endpoint) 수정 refs: DEV-21
…e protocol, NetworkPacketHeader, InvitationPacket추가 refs: DEV-21
refs: DEV-21
2b0127f to
391cd70
Compare
요약
네트워크 초대 요청 송수신 로직을 구현하였습니다.
작업 목록
작업 내용
1. 네트워크 패킷 구조 추상화 (NetworkKit)
2. NetworkSessionManager 수신 로직 (Handle Received Data)
3. 제네릭(Generic) 기반 전송 메소드 구현
closes DEV-21