-
Notifications
You must be signed in to change notification settings - Fork 2
[FIX/#130] 2. 여러 사용자가 연결되지 않는 문제를 수정합니다. #131
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
Changes from all commits
0fa2717
96600e0
d927a22
2a2d7cd
2ca7099
85463d1
c1fdfe1
f81063c
db88276
c985489
b7b7d7c
cb833b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,8 +44,9 @@ public final class ConnectionClientImpl: ConnectionClient { | |
| self.signalingService.send( | ||
| type: .offerSDP, | ||
| sdp: sdp, | ||
| userID: myID, | ||
| roomID: remoteUserInfo.roomID | ||
| roomID: remoteUserInfo.roomID, | ||
| offerID: myID, | ||
| answerID: nil | ||
| ) | ||
| } | ||
| } | ||
|
|
@@ -82,26 +83,85 @@ public final class ConnectionClientImpl: ConnectionClient { | |
| } | ||
|
|
||
| private func bindSignalingService() { | ||
| self.signalingService.didReceiveRemoteSdpPublisher.sink { [weak self] sdp in | ||
| guard let self else { return } | ||
|
|
||
| guard self.webRTCService.peerConnection.remoteDescription == nil else { return } | ||
| self.webRTCService.set(remoteSdp: sdp) { error in | ||
| // MARK: 이미 방에 있던 놈들이 받는 이벤트 | ||
| self.signalingService.didReceiveOfferSdpPublisher | ||
| .filter { [weak self] _ in self?.remoteUserInfo != nil } | ||
| .sink { [weak self] sdpMessage in | ||
| guard let self else { return } | ||
| let remoteSDP = sdpMessage.rtcSessionDescription | ||
|
|
||
| PTGDataLogger.log("didReceiveRemoteSdpPublisher sink!! \(remoteSDP)") | ||
|
|
||
| // MARK: remoteDescription이 있으면 이미 연결된 클라이언트 | ||
| guard self.webRTCService.peerConnection.remoteDescription == nil else { | ||
| PTGDataLogger.log("remoteSDP가 이미 있어요!") | ||
| return | ||
| } | ||
| PTGDataLogger.log("remoteSDP가 없어요! remoteSDP 저장하기 직전") | ||
| guard let userInfo = self.remoteUserInfo else { | ||
| PTGDataLogger.log("answer를 받을 remote User가 없어요!! 비상!!!") | ||
| return | ||
| } | ||
|
|
||
| guard userInfo.id == sdpMessage.offerID else { | ||
| PTGDataLogger.log("Offer를 보낸 유저가 일치하지 않습니다.") | ||
| return | ||
| } | ||
|
|
||
| guard self.webRTCService.peerConnection.localDescription == nil else { | ||
| PTGDataLogger.log("localSDP가 이미 있어요!") | ||
| return | ||
| } | ||
|
|
||
| self.webRTCService.set(remoteSdp: remoteSDP) { error in | ||
| PTGDataLogger.log("remoteSDP가 저장되었어요!") | ||
|
|
||
| if let error { PTGDataLogger.log(error.localizedDescription) } | ||
|
|
||
| guard self.webRTCService.peerConnection.localDescription == nil else { return } | ||
| self.webRTCService.answer { sdp in | ||
| guard let userInfo = self.remoteUserInfo else { return } | ||
| self.signalingService.send( | ||
| type: .answerSDP, | ||
| sdp: sdp, | ||
| userID: userInfo.id, | ||
| roomID: userInfo.roomID | ||
| roomID: userInfo.roomID, | ||
| offerID: userInfo.id, | ||
| answerID: sdpMessage.answerID | ||
| ) | ||
|
Comment on lines
+116
to
128
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이친구도 직접 webRTCService를 참조해서 set을 호출하는거보다, guard 하는부분과 set하는 부분을 명시적으로 두 함수로 분리하면 가독성이 더 좋을 것 같아요. |
||
| } | ||
| } | ||
| }.store(in: &cancellables) | ||
|
|
||
| self.signalingService.didReceiveAnswerSdpPublisher | ||
| .filter { [weak self] _ in self?.remoteUserInfo != nil } | ||
| .sink { [weak self] sdpMessage in | ||
| guard let self else { return } | ||
| let remoteSDP = sdpMessage.rtcSessionDescription | ||
|
|
||
| guard let userInfo = remoteUserInfo else { | ||
| PTGDataLogger.log("UserInfo가 없어요") | ||
| return | ||
| } | ||
|
|
||
| guard userInfo.id == sdpMessage.answerID else { | ||
| return | ||
| } | ||
|
|
||
| guard self.webRTCService.peerConnection.localDescription != nil else { | ||
| PTGDataLogger.log("localDescription이 없어요") | ||
| return | ||
| } | ||
|
|
||
| guard self.webRTCService.peerConnection.remoteDescription == nil else { | ||
| PTGDataLogger.log("remoteDescription이 있어요") | ||
| return | ||
| } | ||
|
Comment on lines
+133
to
+156
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기도 마찬가지로 분리하면 가독성이 좋을 것 같아요 |
||
|
|
||
| self.webRTCService.set(remoteSdp: remoteSDP) { error in | ||
| if let error = error { | ||
| PTGDataLogger.log("Error setting remote SDP: \(error.localizedDescription)") | ||
| } | ||
| } | ||
| }.store(in: &cancellables) | ||
|
|
||
| self.signalingService.didReceiveCandidatePublisher.sink { [weak self] candidate in | ||
| guard let self else { return } | ||
| self.webRTCService.set(remoteCandidate: candidate) { _ in } | ||
|
|
@@ -119,8 +179,8 @@ public final class ConnectionClientImpl: ConnectionClient { | |
| self.signalingService.send( | ||
| type: .iceCandidate, | ||
| candidate: candidate, | ||
| userID: remoteUserInfo.id, | ||
| roomID: remoteUserInfo.roomID | ||
| roomID: remoteUserInfo.roomID, | ||
| userID: remoteUserInfo.id | ||
| ) | ||
| }.store(in: &cancellables) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import Foundation | ||
| import AVFoundation | ||
|
|
||
| enum AppPermissionManager { | ||
| static func requestCameraPermission() { | ||
| AVCaptureDevice.requestAccess(for: .video) { granted in | ||
| if granted { | ||
| print("카메라 권한 허용됨") | ||
| } else { | ||
| print("카메라 권한 거부됨") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| static func requestMicrophonePermission() { | ||
| AVCaptureDevice.requestAccess(for: .audio) { granted in | ||
| if granted { | ||
| print("마이크 권한 허용됨") | ||
| } else { | ||
| print("마이크 권한 거부됨") | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+4
to
+24
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 추후 매니저에서 마이크 버튼 on/off 할때도 권한 여부를 확인할 필요가 있을 것 같아요. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import Foundation | ||
| // swiftlint:disable identifier_name | ||
| enum Secrets { | ||
| static var BASE_URL: URL? { | ||
| let urlString = Bundle.main.object(forInfoDictionaryKey: "BASE_URL") as? String ?? "" | ||
| return URL(string: urlString) | ||
| } | ||
|
|
||
| static var STUN_SERVERS: [String]? { | ||
| guard let serversString = Bundle.main.infoDictionary?["STUN_SERVERS"] as? String else { | ||
| return nil | ||
| } | ||
| return serversString.components(separatedBy: ",") | ||
| } | ||
| } |
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.
아래 set을 시키지 않기 위함이 주 목적이라면, guard 하는 부분은 따로 private 메서드로 빼주는 건 어떨까요?