Skip to content

Commit

Permalink
Feat: 통화 기초 기능 구현
Browse files Browse the repository at this point in the history
마이크를 통한 전달 화인
#18
  • Loading branch information
hhyukjin committed Feb 12, 2024
1 parent e734005 commit 61712f4
Show file tree
Hide file tree
Showing 23 changed files with 994 additions and 13 deletions.
Binary file added .DS_Store
Binary file not shown.
Binary file modified iOS/Ringo/.DS_Store
Binary file not shown.
76 changes: 76 additions & 0 deletions iOS/Ringo/Ringo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@
/* Begin PBXBuildFile section */
940C25642B73D20900E069D0 /* ConnectionCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 940C25632B73D20900E069D0 /* ConnectionCollectionViewCell.swift */; };
940C25662B74EF4D00E069D0 /* FriendService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 940C25652B74EF4D00E069D0 /* FriendService.swift */; };
940C25722B7A88FB00E069D0 /* Config.swift in Sources */ = {isa = PBXBuildFile; fileRef = 940C25712B7A88FB00E069D0 /* Config.swift */; };
940C25782B7A899500E069D0 /* RTCStates.swift in Sources */ = {isa = PBXBuildFile; fileRef = 940C25752B7A899500E069D0 /* RTCStates.swift */; };
940C25792B7A899500E069D0 /* SessionDescription.swift in Sources */ = {isa = PBXBuildFile; fileRef = 940C25762B7A899500E069D0 /* SessionDescription.swift */; };
940C257A2B7A899500E069D0 /* IceCandidate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 940C25772B7A899500E069D0 /* IceCandidate.swift */; };
940C25832B7A89AB00E069D0 /* Message.swift in Sources */ = {isa = PBXBuildFile; fileRef = 940C257C2B7A89AB00E069D0 /* Message.swift */; };
940C25842B7A89AB00E069D0 /* WebSocketProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 940C257E2B7A89AB00E069D0 /* WebSocketProvider.swift */; };
940C25852B7A89AB00E069D0 /* NativeWebSocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 940C257F2B7A89AB00E069D0 /* NativeWebSocket.swift */; };
940C25862B7A89AB00E069D0 /* StarscreamProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 940C25802B7A89AB00E069D0 /* StarscreamProvider.swift */; };
940C25872B7A89AB00E069D0 /* WebRTCClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 940C25812B7A89AB00E069D0 /* WebRTCClient.swift */; };
940C25882B7A89AB00E069D0 /* SignalingClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 940C25822B7A89AB00E069D0 /* SignalingClient.swift */; };
940C258A2B7A8FA900E069D0 /* CallService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 940C25892B7A8FA900E069D0 /* CallService.swift */; };
94470A8A2B71050700F0A942 /* Alamofire in Frameworks */ = {isa = PBXBuildFile; productRef = 94470A892B71050700F0A942 /* Alamofire */; };
94470A8D2B710A3100F0A942 /* Starscream in Frameworks */ = {isa = PBXBuildFile; productRef = 94470A8C2B710A3100F0A942 /* Starscream */; };
94470A902B710CE500F0A942 /* WebRTC in Frameworks */ = {isa = PBXBuildFile; productRef = 94470A8F2B710CE500F0A942 /* WebRTC */; };
Expand All @@ -33,6 +44,17 @@
/* Begin PBXFileReference section */
940C25632B73D20900E069D0 /* ConnectionCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectionCollectionViewCell.swift; sourceTree = "<group>"; };
940C25652B74EF4D00E069D0 /* FriendService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FriendService.swift; sourceTree = "<group>"; };
940C25712B7A88FB00E069D0 /* Config.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Config.swift; sourceTree = "<group>"; };
940C25752B7A899500E069D0 /* RTCStates.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RTCStates.swift; sourceTree = "<group>"; };
940C25762B7A899500E069D0 /* SessionDescription.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SessionDescription.swift; sourceTree = "<group>"; };
940C25772B7A899500E069D0 /* IceCandidate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IceCandidate.swift; sourceTree = "<group>"; };
940C257C2B7A89AB00E069D0 /* Message.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Message.swift; sourceTree = "<group>"; };
940C257E2B7A89AB00E069D0 /* WebSocketProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WebSocketProvider.swift; sourceTree = "<group>"; };
940C257F2B7A89AB00E069D0 /* NativeWebSocket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NativeWebSocket.swift; sourceTree = "<group>"; };
940C25802B7A89AB00E069D0 /* StarscreamProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StarscreamProvider.swift; sourceTree = "<group>"; };
940C25812B7A89AB00E069D0 /* WebRTCClient.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WebRTCClient.swift; sourceTree = "<group>"; };
940C25822B7A89AB00E069D0 /* SignalingClient.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SignalingClient.swift; sourceTree = "<group>"; };
940C25892B7A8FA900E069D0 /* CallService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CallService.swift; sourceTree = "<group>"; };
94470A922B7163E900F0A942 /* Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Model.swift; sourceTree = "<group>"; };
94470A942B71680100F0A942 /* SigninService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SigninService.swift; sourceTree = "<group>"; };
94470A962B717DC300F0A942 /* ConnectionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectionViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -67,6 +89,48 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
940C256A2B79EC5700E069D0 /* WebRTC */ = {
isa = PBXGroup;
children = (
940C257B2B7A89AB00E069D0 /* Services */,
940C25742B7A899500E069D0 /* Extensions */,
940C25712B7A88FB00E069D0 /* Config.swift */,
940C25892B7A8FA900E069D0 /* CallService.swift */,
);
path = WebRTC;
sourceTree = "<group>";
};
940C25742B7A899500E069D0 /* Extensions */ = {
isa = PBXGroup;
children = (
940C25752B7A899500E069D0 /* RTCStates.swift */,
940C25762B7A899500E069D0 /* SessionDescription.swift */,
940C25772B7A899500E069D0 /* IceCandidate.swift */,
);
path = Extensions;
sourceTree = "<group>";
};
940C257B2B7A89AB00E069D0 /* Services */ = {
isa = PBXGroup;
children = (
940C257C2B7A89AB00E069D0 /* Message.swift */,
940C257D2B7A89AB00E069D0 /* WebSocketProvider */,
940C25812B7A89AB00E069D0 /* WebRTCClient.swift */,
940C25822B7A89AB00E069D0 /* SignalingClient.swift */,
);
path = Services;
sourceTree = "<group>";
};
940C257D2B7A89AB00E069D0 /* WebSocketProvider */ = {
isa = PBXGroup;
children = (
940C257E2B7A89AB00E069D0 /* WebSocketProvider.swift */,
940C257F2B7A89AB00E069D0 /* NativeWebSocket.swift */,
940C25802B7A89AB00E069D0 /* StarscreamProvider.swift */,
);
path = WebSocketProvider;
sourceTree = "<group>";
};
94470A912B71157C00F0A942 /* Screens */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -99,6 +163,7 @@
945CF9792B67E1CD00396E4E /* Ringo */ = {
isa = PBXGroup;
children = (
940C256A2B79EC5700E069D0 /* WebRTC */,
94470A912B71157C00F0A942 /* Screens */,
945CF97A2B67E1CD00396E4E /* AppDelegate.swift */,
945CF97C2B67E1CD00396E4E /* SceneDelegate.swift */,
Expand Down Expand Up @@ -201,16 +266,27 @@
945603212B6D2F06002F4B33 /* Canvas.swift in Sources */,
94470A972B717DC300F0A942 /* ConnectionViewController.swift in Sources */,
945603132B6AC07D002F4B33 /* TabBarViewController.swift in Sources */,
940C25782B7A899500E069D0 /* RTCStates.swift in Sources */,
940C25852B7A89AB00E069D0 /* NativeWebSocket.swift in Sources */,
945CF97F2B67E1CD00396E4E /* ViewController.swift in Sources */,
940C25642B73D20900E069D0 /* ConnectionCollectionViewCell.swift in Sources */,
940C257A2B7A899500E069D0 /* IceCandidate.swift in Sources */,
945603192B6AC365002F4B33 /* AccountViewController.swift in Sources */,
940C258A2B7A8FA900E069D0 /* CallService.swift in Sources */,
945CF97B2B67E1CD00396E4E /* AppDelegate.swift in Sources */,
945603172B6AC2D3002F4B33 /* RecentsViewController.swift in Sources */,
940C25872B7A89AB00E069D0 /* WebRTCClient.swift in Sources */,
945603232B6D31D9002F4B33 /* ContactsTableViewCell.swift in Sources */,
945CF97D2B67E1CD00396E4E /* SceneDelegate.swift in Sources */,
94470A932B7163E900F0A942 /* Model.swift in Sources */,
940C25662B74EF4D00E069D0 /* FriendService.swift in Sources */,
940C25792B7A899500E069D0 /* SessionDescription.swift in Sources */,
945603152B6AC22A002F4B33 /* ContactsViewController.swift in Sources */,
940C25722B7A88FB00E069D0 /* Config.swift in Sources */,
940C25842B7A89AB00E069D0 /* WebSocketProvider.swift in Sources */,
940C25882B7A89AB00E069D0 /* SignalingClient.swift in Sources */,
940C25832B7A89AB00E069D0 /* Message.swift in Sources */,
940C25862B7A89AB00E069D0 /* StarscreamProvider.swift in Sources */,
9456031D2B6BF44A002F4B33 /* FriendRequestViewController.swift in Sources */,
94470A952B71680100F0A942 /* SigninService.swift in Sources */,
);
Expand Down
Binary file not shown.
Binary file modified iOS/Ringo/Ringo/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion iOS/Ringo/Ringo/ConnectionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ConnectionViewController: UIViewController {
let translateBtn = UIButton()
let hangUpBtn = UIButton()

let randomNames = ["민준", "서준"]
let randomNames = ["example", "example2"]

override func viewDidLoad() {
super.viewDidLoad()
Expand Down
11 changes: 11 additions & 0 deletions iOS/Ringo/Ringo/ContactsTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
import UIKit
import SnapKit

protocol ContactsTableViewCellDelegate: AnyObject {
func pressedButton()
}

class ContactsTableViewCell: UITableViewCell {

static let identifier = "ContactsTableViewCell"
Expand All @@ -21,6 +25,8 @@ class ContactsTableViewCell: UITableViewCell {
let paddingView = UIView()
let paddingView2 = UIView()

var delegate: ContactsTableViewCellDelegate?

override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
setUpView()
Expand Down Expand Up @@ -53,6 +59,7 @@ class ContactsTableViewCell: UITableViewCell {
call.configuration = .plain()
call.configuration?.imagePadding = 10
call.configuration?.baseForegroundColor = .systemGreen
call.addTarget(self, action: #selector(callBtnAction), for: .touchUpInside)

stackView.axis = .vertical
stackView.alignment = .leading
Expand Down Expand Up @@ -102,6 +109,10 @@ class ContactsTableViewCell: UITableViewCell {
super.setSelected(selected, animated: animated)
moreStackView.isHidden = !selected
}

@objc func callBtnAction(){
delegate?.pressedButton()
}
}

// MARK: - stackview border
Expand Down
2 changes: 2 additions & 0 deletions iOS/Ringo/Ringo/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSMicrophoneUsageDescription</key>
<string>Need microphone access for use device&apos;s mic</string>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
Expand Down
16 changes: 15 additions & 1 deletion iOS/Ringo/Ringo/Screens/ContactsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,12 @@ extension ContactsViewController: UITableViewDataSource {

cell.name.text = randomNames[indexPath.row]
cell.selectionStyle = .none
cell.delegate = self

return cell
}
}
// MARK: - Sign in
// MARK: - Load Friends
extension ContactsViewController {

func loadFriends() {
Expand Down Expand Up @@ -134,6 +135,19 @@ extension ContactsViewController {
}
}

// MARK: - Load Friends
extension ContactsViewController: ContactsTableViewCellDelegate {

func pressedButton() {
CallService.shared.webRTCClient.offer { (sdp) in
CallService.shared.signalClient.send(sdp: sdp)
}
let connectionVC = ConnectionViewController()
connectionVC.modalPresentationStyle = .fullScreen
present(connectionVC, animated: true,completion: nil)
}

}
// MARK: - canvas 이용하기
import SwiftUI
@available(iOS 13.0.0, *)
Expand Down
81 changes: 73 additions & 8 deletions iOS/Ringo/Ringo/Screens/TabBarViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@

import UIKit
import SnapKit
import WebRTC

class TabBarViewController: UITabBarController{

override func viewDidLoad() {
super.viewDidLoad()

CallService.shared.webRTCClient.delegate = self
CallService.shared.signalClient.delegate = self
CallService.shared.signalClient.connect()

view.backgroundColor = .systemBackground

tabBar.backgroundColor = .init(white: 1, alpha: 0.8)
Expand All @@ -31,13 +36,73 @@ class TabBarViewController: UITabBarController{
}
}

// MARK: canvas 이용하기
import SwiftUI
@available(iOS 13.0.0, *)
struct TabBarViewControllerPreView: PreviewProvider {
static var previews: some View {
// 사용할 뷰 컨트롤러를 넣어주세요
TabBarViewController()
.toPreview()
extension TabBarViewController: SignalClientDelegate {
func signalClientDidConnect(_ signalClient: SignalingClient) {
print("signal connect")
}

func signalClientDidDisconnect(_ signalClient: SignalingClient) {
print("signal disconnect")
}

func signalClient(_ signalClient: SignalingClient, didReceiveRemoteSdp sdp: RTCSessionDescription) {
print("Received remote sdp")
CallService.shared.webRTCClient.set(remoteSdp: sdp) { (error) in
DispatchQueue.main.async {
let alert = UIAlertController(title: "Call", message: "", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Refuse", style: .destructive, handler: nil))
alert.addAction(UIAlertAction(title: "Accept", style: .default, handler: { action in
self.acceptCall()
}))
self.present(alert, animated: true, completion: nil)
}
}
}

func signalClient(_ signalClient: SignalingClient, didReceiveCandidate candidate: RTCIceCandidate) {
CallService.shared.webRTCClient.set(remoteCandidate: candidate) { error in
print("Received remote candidate : \(candidate)")
}
}

func acceptCall() {
CallService.shared.webRTCClient.answer { (localSdp) in
CallService.shared.signalClient.send(sdp: localSdp)
}
let connectionVC = ConnectionViewController()
connectionVC.modalPresentationStyle = .fullScreen
self.present(connectionVC, animated: true,completion: nil)
}

}

extension TabBarViewController: WebRTCClientDelegate {
func webRTCClient(_ client: WebRTCClient, didDiscoverLocalCandidate candidate: RTCIceCandidate) {
print("discovered local candidate")
CallService.shared.signalClient.send(candidate: candidate)
}

func webRTCClient(_ client: WebRTCClient, didChangeConnectionState state: RTCIceConnectionState) {
print("change connection state : \(state)")
}

func webRTCClient(_ client: WebRTCClient, didReceiveData data: Data) {
DispatchQueue.main.async {
let message = String(data: data, encoding: .utf8) ?? "(Binary: \(data.count) bytes)"
let alert = UIAlertController(title: "Message from WebRTC", message: message, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil))
self.present(alert, animated: true, completion: nil)
}
}
}

//// MARK: canvas 이용하기
//import SwiftUI
//@available(iOS 13.0.0, *)
//struct TabBarViewControllerPreView: PreviewProvider {
// static var previews: some View {
// // 사용할 뷰 컨트롤러를 넣어주세요
// TabBarViewController()
// .toPreview()
// }
//}
21 changes: 18 additions & 3 deletions iOS/Ringo/Ringo/Screens/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class ViewController: UIViewController {
input_email.layer.cornerRadius = 5
input_email.keyboardType = .emailAddress
input_email.autocapitalizationType = .none
input_email.autocorrectionType = .no
input_email.spellCheckingType = .no

stackView.axis = .vertical
stackView.alignment = .fill
Expand Down Expand Up @@ -116,6 +118,9 @@ class ViewController: UIViewController {
input_passwd.rightView = showBtn
input_passwd.rightViewMode = .always
input_passwd.autocapitalizationType = .none
input_passwd.delegate = self
input_passwd.autocorrectionType = .no
input_passwd.spellCheckingType = .no

error.layer.isHidden = true
error.setTitle(" Incorrect password. Please check your password.", for: .normal)
Expand Down Expand Up @@ -219,6 +224,11 @@ class ViewController: UIViewController {
make.trailing.equalTo(apple.snp.leading).offset(-20)
}
}
// 빈 화면 터치 시 키보드 내리기
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
view.endEditing(true)
}

@objc func onPressSignin(_ sender: UIButton) {
login()
}
Expand Down Expand Up @@ -270,9 +280,7 @@ extension ViewController {
// UserDefaults.standard.set(data.data?.jwtToken, forKey: "jwtToken")
let nav = UINavigationController()
nav.modalPresentationStyle = .fullScreen
nav.navigationBar.barTintColor = .white
// nav.navigationBar.tintColor = UIColor(w: 42)


//네비게이션 중복 수정 1/31
nav.navigationBar.isHidden = true

Expand Down Expand Up @@ -301,3 +309,10 @@ extension ViewController {
}
}
}
// MARK: - canvas 이용하기
extension ViewController: UITextFieldDelegate {
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
}
Binary file added iOS/Ringo/Ringo/WebRTC/.DS_Store
Binary file not shown.
22 changes: 22 additions & 0 deletions iOS/Ringo/Ringo/WebRTC/CallService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// CallService.swift
// Ringo
//
// Created by 강진혁 on 2/13/24.
//

import Foundation

class CallService {

static let shared = CallService()

private let config = Config.default
var signalClient: SignalingClient
var webRTCClient: WebRTCClient

init() {
self.signalClient = SignalingClient(webSocket: NativeWebSocket(url: self.config.signalingServerUrl))
self.webRTCClient = WebRTCClient(iceServers: self.config.webRTCIceServers)
}
}
Loading

0 comments on commit 61712f4

Please sign in to comment.