Skip to content

Commit 696cd9c

Browse files
authored
Merge pull request #67 from boostcampwm-2024/feat/#40-create-room-2
[FEAT/#40] ๋ฐฉ ์ƒ์„ฑ ์ž‘์—… 2 ์ง„ํ–‰์ค‘...
2 parents 439e4a5 + 30dcc7f commit 696cd9c

File tree

35 files changed

+467
-102
lines changed

35 files changed

+467
-102
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import Foundation
2+
import WebRTC
3+
4+
public class CapturableVideoView: RTCMTLVideoView {
5+
public var capturedImage: UIImage?
6+
7+
public override func setSize(_ size: CGSize) {
8+
super.setSize(size)
9+
}
10+
11+
public override func renderFrame(_ frame: RTCVideoFrame?) {
12+
guard let frame = frame else { return }
13+
14+
super.renderFrame(frame)
15+
capturedImage = convertFrameToImage(frame)
16+
}
17+
18+
private func convertFrameToImage(_ frame: RTCVideoFrame) -> UIImage? {
19+
// frame์˜ ๋ฒ„ํผ๋ฅผ CVPixelBuffer๋กœ ๊ฐ€์ ธ์˜ด
20+
guard let pixelBuffer = (frame.buffer as? RTCCVPixelBuffer)?.pixelBuffer else { return nil }
21+
22+
// CVPixelBuffer๋ฅผ CIImage๋กœ ๋ณ€ํ™˜
23+
let ciImage = CIImage(cvPixelBuffer: pixelBuffer).oriented(.right)
24+
25+
// CIImage๋ฅผ UIImage๋กœ ๋ณ€ํ™˜
26+
let context = CIContext(options: nil)
27+
if let cgImage = context.createCGImage(ciImage, from: ciImage.extent) {
28+
return UIImage(cgImage: cgImage)
29+
}
30+
return nil
31+
}
32+
}

โ€ŽPhotoGether/DataLayer/PhotoGetherData/PhotoGetherData/ConnectionClientImpl.swiftโ€Ž

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ public final class ConnectionClientImpl: ConnectionClient {
99

1010
public var receivedDataPublisher = PassthroughSubject<Data, Never>()
1111

12-
public var remoteVideoView: UIView = RTCMTLVideoView()
13-
public var localVideoView: UIView = RTCMTLVideoView()
12+
public var remoteVideoView: UIView = CapturableVideoView()
13+
public var localVideoView: UIView = CapturableVideoView()
1414

1515
public var peerID: String = ""
1616
public var roomID: String = ""
@@ -40,6 +40,27 @@ public final class ConnectionClientImpl: ConnectionClient {
4040
self.webRTCService.sendData(data)
4141
}
4242

43+
public func captureVideos() -> [UIImage] {
44+
let localCaptureImage = getCapturedVideos(isLocal: true)
45+
let remoteCaptureImage = getCapturedVideos(isLocal: false)
46+
47+
return [localCaptureImage, remoteCaptureImage]
48+
}
49+
50+
private func getCapturedVideos(isLocal: Bool) -> UIImage {
51+
let targetVideo = isLocal ? self.localVideoView : self.remoteVideoView
52+
53+
guard let videoView = targetVideo as? CapturableVideoView else {
54+
return UIImage()
55+
}
56+
57+
guard let capturedImage = videoView.capturedImage else {
58+
return UIImage()
59+
}
60+
61+
return capturedImage
62+
}
63+
4364
private func connect() {
4465
self.signalingService.connect()
4566
}
@@ -112,7 +133,7 @@ extension ConnectionClientImpl: WebRTCServiceDelegate {
112133
) {
113134
// TODO: ํ”ผ์–ด์ปค๋„ฅ์…˜ ์—ฐ๊ฒฐ ์ƒํƒœ ๋ณ€๊ฒฝ์— ๋”ฐ๋ฅธ ์ฒ˜๋ฆฌ
114135
}
115-
136+
116137
/// peerConnection์˜ remoteDataChannel ์— ๋ฐ์ดํ„ฐ๊ฐ€ ์ˆ˜์‹ ๋˜๋ฉด ํ˜ธ์ถœ๋จ
117138
public func webRTCService(
118139
_ service: WebRTCService,

โ€ŽPhotoGether/DataLayer/PhotoGetherData/PhotoGetherData/Interface/DTO/RequestDTO/RoomRequestDTO.swiftโ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ struct RoomRequestDTO: WebSocketRequestable {
55
var messageType: RoomMessageType
66
var message: Data?
77

8-
init(messageType: RoomMessageType, body: Data? = nil) {
8+
init(messageType: RoomMessageType, message: Data? = nil) {
99
self.messageType = messageType
10+
self.message = message
1011
}
1112

1213
enum RoomMessageType: String, Encodable {

โ€ŽPhotoGether/DataLayer/PhotoGetherData/PhotoGetherData/Interface/DTO/RequestDTO/SignalingRequestDTO.swiftโ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ struct SignalingRequestDTO: WebSocketRequestable {
55
var messageType: SignalingMessageType
66
var message: Data?
77

8-
init(messageType: SignalingMessageType = .signaling, body: Data? = nil) {
8+
init(messageType: SignalingMessageType = .signaling, message: Data? = nil) {
99
self.messageType = messageType
10+
self.message = message
1011
}
1112

1213
enum SignalingMessageType: String, Encodable {
File renamed without changes.

โ€ŽPhotoGether/DataLayer/PhotoGetherData/PhotoGetherData/ServiceImpl/RoomServiceImpl.swiftโ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public final class RoomServiceImpl: RoomService {
66
private let encoder = JSONEncoder()
77
private var webSocketClient: WebSocketClient
88

9-
init(webSocketClient: WebSocketClient) {
9+
public init(webSocketClient: WebSocketClient) {
1010
self.webSocketClient = webSocketClient
1111
}
1212

โ€ŽPhotoGether/DataLayer/PhotoGetherData/PhotoGetherData/ServiceImpl/SignalingServiceImpl.swiftโ€Ž

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ final public class SignalingServiceImpl: SignalingService {
2121
let message = SignalingMessage.sdp(SessionDescription(from: rtcSdp, peerID: peerID, roomID: roomID))
2222
do {
2323
let dataMessage = try self.encoder.encode(message)
24-
self.webSocketClient.send(data: dataMessage)
24+
let dto = SignalingRequestDTO(messageType: .signaling, message: dataMessage)
25+
let request = try self.encoder.encode(dto)
26+
27+
self.webSocketClient.send(data: request)
2528
} catch {
2629
debugPrint("Warning: Could not encode sdp: \(error)")
2730
}
@@ -31,7 +34,10 @@ final public class SignalingServiceImpl: SignalingService {
3134
let message = SignalingMessage.candidate(IceCandidate(from: rtcIceCandidate, peerID: peerID, roomID: roomID))
3235
do {
3336
let dataMessage = try self.encoder.encode(message)
34-
self.webSocketClient.send(data: dataMessage)
37+
let dto = SignalingRequestDTO(messageType: .signaling, message: dataMessage)
38+
let request = try self.encoder.encode(dto)
39+
40+
self.webSocketClient.send(data: request)
3541
} catch {
3642
debugPrint("Warning: Could not encode candidate: \(error)")
3743
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import UIKit
2+
import PhotoGetherDomainInterface
3+
4+
public final class CaptureVideosUseCaseImpl: CaptureVideosUseCase {
5+
public func execute() -> [UIImage] {
6+
let localImage = [connectionRepository.clients[0].captureVideos()[0]]
7+
let remoteImages = connectionRepository.clients.map { $0.captureVideos()[1] }
8+
9+
return localImage + remoteImages
10+
}
11+
12+
private let connectionRepository: ConnectionRepository
13+
14+
public init(connectionRepository: ConnectionRepository) {
15+
self.connectionRepository = connectionRepository
16+
}
17+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Foundation
2+
import UIKit
3+
import PhotoGetherDomainInterface
4+
5+
public final class GetLocalVideoUseCaseImpl: GetLocalVideoUseCase {
6+
public func execute() -> UIView {
7+
// TODO: ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์—์„œ ํ•˜๋‚˜์˜ localVideoView๋งŒ ๋“ค๊ณ  ์žˆ๋„๋ก ๋ณ€๊ฒฝ ์˜ˆ์ •
8+
connectionRepository.clients[0].localVideoView
9+
}
10+
11+
private let connectionRepository: ConnectionRepository
12+
13+
public init(connectionRepository: ConnectionRepository) {
14+
self.connectionRepository = connectionRepository
15+
}
16+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import Foundation
2+
import UIKit
3+
import PhotoGetherDomainInterface
4+
5+
public final class GetRemoteVideoUseCaseImpl: GetRemoteVideoUseCase {
6+
public func execute() -> [UIView] {
7+
connectionRepository.clients.map { $0.remoteVideoView }
8+
}
9+
10+
private let connectionRepository: ConnectionRepository
11+
12+
public init(connectionRepository: ConnectionRepository) {
13+
self.connectionRepository = connectionRepository
14+
}
15+
}

0 commit comments

Comments
ย (0)