Skip to content

Commit

Permalink
0.0.5 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
gzerad committed Jul 2, 2021
1 parent b7a7747 commit 982cbb5
Show file tree
Hide file tree
Showing 52 changed files with 1,191 additions and 390 deletions.
4 changes: 4 additions & 0 deletions Example/HMSSDKExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
47A9246A36F23DA04FBCBF59 /* libPods-HMSSDKExampleTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C7FC9D2F3EF12C4D334C808 /* libPods-HMSSDKExampleTests.a */; };
607FACEC1AFB9204008FA782 /* Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACEB1AFB9204008FA782 /* Tests.swift */; };
91EE0E55268F334200BBC391 /* PreviewViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91EE0E54268F334200BBC391 /* PreviewViewController.swift */; };
E44618962E5579DC60167A75 /* libPods-HMSSDKExample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5FD07183472B4CF2C889F80E /* libPods-HMSSDKExample.a */; };
EC8CEE71261E297F002DC12E /* Settings.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = EC8CEE40261E297F002DC12E /* Settings.storyboard */; };
EC8CEE72261E297F002DC12E /* SettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC8CEE42261E297F002DC12E /* SettingsViewController.swift */; };
Expand Down Expand Up @@ -68,6 +69,7 @@
607FACEB1AFB9204008FA782 /* Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tests.swift; sourceTree = "<group>"; };
66D4752BDADE442DD46B46ED /* Pods-HMSSDKExampleTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HMSSDKExampleTests.release.xcconfig"; path = "Target Support Files/Pods-HMSSDKExampleTests/Pods-HMSSDKExampleTests.release.xcconfig"; sourceTree = "<group>"; };
734B1D7A6C1764B998A1C53C /* Pods-HMSSDKExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HMSSDKExample.release.xcconfig"; path = "Target Support Files/Pods-HMSSDKExample/Pods-HMSSDKExample.release.xcconfig"; sourceTree = "<group>"; };
91EE0E54268F334200BBC391 /* PreviewViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PreviewViewController.swift; sourceTree = "<group>"; };
EC7807E7261E2B1C0021903D /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/LaunchScreen.strings; sourceTree = "<group>"; };
EC8CEE41261E297F002DC12E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Settings.storyboard; sourceTree = "<group>"; };
EC8CEE42261E297F002DC12E /* SettingsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -251,6 +253,7 @@
isa = PBXGroup;
children = (
EC8CEE6F261E297F002DC12E /* LoginViewController.swift */,
91EE0E54268F334200BBC391 /* PreviewViewController.swift */,
EC8CEE48261E297F002DC12E /* Login.storyboard */,
);
path = Login;
Expand Down Expand Up @@ -442,6 +445,7 @@
EC8CEE78261E297F002DC12E /* HMSSDKInteractor.swift in Sources */,
EC8CEE81261E297F002DC12E /* BadgeButton.swift in Sources */,
EC8CEE8D261E297F002DC12E /* AppDelegate.swift in Sources */,
91EE0E55268F334200BBC391 /* PreviewViewController.swift in Sources */,
EC8CEE84261E297F002DC12E /* RoomService.swift in Sources */,
EC8CEE87261E297F002DC12E /* Constants.swift in Sources */,
EC8CEE7A261E297F002DC12E /* PeersListViewController.swift in Sources */,
Expand Down
222 changes: 150 additions & 72 deletions Example/HMSSDKExample/Login/Base.lproj/Login.storyboard

Large diffs are not rendered by default.

135 changes: 9 additions & 126 deletions Example/HMSSDKExample/Login/LoginViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,51 +45,18 @@ final class LoginViewController: UIViewController {
}
}

@IBOutlet private weak var publishVideoButton: UIButton! {
didSet {
UserDefaults.standard.set(true, forKey: Constants.publishVideo)
}
}

@IBOutlet private weak var publishAudioButton: UIButton! {
didSet {
UserDefaults.standard.set(true, forKey: Constants.publishAudio)
}
}

@IBOutlet private weak var cameraPreview: UIView!

private var session: AVCaptureSession?
private var input: AVCaptureDeviceInput?
private var output: AVCapturePhotoOutput?
private var previewLayer: AVCaptureVideoPreviewLayer?

// MARK: - View Lifecycle

override func viewDidLoad() {
super.viewDidLoad()

observeNotifications()

AVCaptureDevice.requestAccess(for: .video) { granted in
print(#function, "permission granted: ", granted)
}

AVCaptureDevice.requestAccess(for: .audio) { granted in
print(#function, "permission granted: ", granted)
}
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
joinMeetingIDField.text = UserDefaults.standard.string(forKey: Constants.roomIDKey) ?? Constants.defaultRoomID
settingsButton.imageView?.rotate()
setupCameraPreview()
}

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
updateCameraView()
}

override func willTransition(to newCollection: UITraitCollection,
Expand All @@ -98,54 +65,12 @@ final class LoginViewController: UIViewController {
super.willTransition(to: newCollection, with: coordinator)

coordinator.animate { _ in
self.updateCameraView()
self.joinMeetingIDField.resignFirstResponder()
}
}

// MARK: - View Modifiers

private func setupCameraPreview() {

session = AVCaptureSession()
output = AVCapturePhotoOutput()
if let camera = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .front) {
do {
input = try AVCaptureDeviceInput(device: camera)
} catch let error as NSError {
print(error)
input = nil
}

guard let input = input, let output = output, let session = session else { return }

if session.canAddInput(input) {
session.addInput(input)

if session.canAddOutput(output) {
session.addOutput(output)
}

let settings = AVCapturePhotoSettings()
let previewPixelType = settings.availablePreviewPhotoPixelFormatTypes.first!

let previewFormat = [kCVPixelBufferPixelFormatTypeKey as String: previewPixelType,
kCVPixelBufferWidthKey as String: view.frame.size.width,
kCVPixelBufferHeightKey as String: view.frame.size.height] as [String: Any]
settings.previewPhotoFormat = previewFormat

output.capturePhoto(with: settings, delegate: self)
}
}
}

private func updateCameraView() {
if let orientation = UIApplication.shared.windows.first?.windowScene?.interfaceOrientation {
let videoOrientation = AVCaptureVideoOrientation(rawValue: orientation.rawValue) ?? .portrait
previewLayer?.connection?.videoOrientation = videoOrientation
previewLayer?.frame = cameraPreview.bounds
}
}


// MARK: - Action Handlers

Expand All @@ -161,45 +86,21 @@ final class LoginViewController: UIViewController {

self.joinMeetingIDField.text = roomID

self.showInputAlert(flow: .join)
self.showInputAlert()
}
}

@objc private func dismissKeyboard(_ sender: Any) {
joinMeetingIDField.resignFirstResponder()
}

@IBAction private func cameraTapped(_ sender: UIButton) {

UserDefaults.standard.set(sender.isSelected, forKey: Constants.publishVideo)
sender.isSelected = !sender.isSelected

if let session = session {
if sender.isSelected {
if session.isRunning {
session.stopRunning()
previewLayer?.removeFromSuperlayer()
}
} else {
if !session.isRunning {
session.startRunning()
cameraPreview.layer.addSublayer(previewLayer ?? CALayer())
}
}
}
}

@IBAction private func micTapped(_ sender: UIButton) {
AVAudioSession.sharedInstance().requestRecordPermission { _ in }
UserDefaults.standard.set(sender.isSelected, forKey: Constants.publishAudio)
sender.isSelected = !sender.isSelected
}


@IBAction private func startMeetingTapped(_ sender: UIButton) {
showInputAlert(flow: .join)
showInputAlert()
}

private func showInputAlert(flow: MeetingFlow) {
private func showInputAlert() {

let title = "Join a Meeting"
let action = "Join"
Expand All @@ -217,13 +118,13 @@ final class LoginViewController: UIViewController {
alertController.addAction(UIAlertAction(title: "Cancel", style: .cancel))
alertController.addAction(UIAlertAction(title: action, style: .default) { [weak self] _ in

self?.handleActions(for: alertController, in: flow)
self?.handleActions(for: alertController)
})

present(alertController, animated: true)
}

private func handleActions(for alertController: UIAlertController, in flow: MeetingFlow) {
private func handleActions(for alertController: UIAlertController) {
var room: String

if !joinMeetingIDField.text!.isEmpty {
Expand All @@ -234,8 +135,7 @@ final class LoginViewController: UIViewController {
}

guard let name = alertController.textFields?[0].text, !name.isEmpty,
let viewController = UIStoryboard(name: Constants.meeting, bundle: nil)
.instantiateInitialViewController() as? MeetingViewController
let viewController = self.storyboard?.instantiateViewController(identifier: Constants.previewControllerIdentifier) as? PreviewViewController
else {
dismiss(animated: true)
let message = "Enter Name!"
Expand All @@ -244,7 +144,6 @@ final class LoginViewController: UIViewController {
}

viewController.user = name
viewController.flow = flow
viewController.roomName = room

save(name, room)
Expand Down Expand Up @@ -283,20 +182,4 @@ final class LoginViewController: UIViewController {
present(viewController, animated: true)
}
}

@available(iOS 11.0, *)
extension LoginViewController: AVCapturePhotoCaptureDelegate {

func photoOutput(_ output: AVCapturePhotoOutput,
didFinishProcessingPhoto photo: AVCapturePhoto,
error: Error?) {

if let session = session {
previewLayer = AVCaptureVideoPreviewLayer(session: session)
previewLayer?.videoGravity = .resizeAspectFill
updateCameraView()
cameraPreview.layer.addSublayer(previewLayer!)
session.startRunning()
}
}
}

98 changes: 98 additions & 0 deletions Example/HMSSDKExample/Login/PreviewViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
//
// PreviewViewController.swift
// HMSSDKExample
//
// Created by Dmitry Fedoseyev on 30.06.2021.
// Copyright © 2021 100ms. All rights reserved.
//

import UIKit
import HMSSDK

class PreviewViewController: UIViewController {

internal var user: String!
internal var roomName: String!

private var videoTrack: HMSLocalVideoTrack!
private var audioTrack: HMSLocalAudioTrack!
private var interactor: HMSSDKInteractor!

@IBOutlet private weak var previewView: HMSVideoView!

@IBOutlet private weak var publishVideoButton: UIButton!
@IBOutlet private weak var publishAudioButton: UIButton!
@IBOutlet private weak var joinButton: UIButton!

override func viewDidLoad() {
interactor = HMSSDKInteractor(for: user, in: roomName) {}
joinButton.isEnabled = false

interactor.onPreview = { [weak self] room, tracks in
self?.setupTracks(tracks: tracks)
self?.joinButton.isEnabled = true
}

_ = NotificationCenter.default.addObserver(forName: Constants.gotError,
object: nil,
queue: .main) { [weak self] notification in
if let strongSelf = self {
let message = notification.userInfo?["error"] as? String
let alert = UIAlertController(title: "ERROR! ❌",
message: message,
preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Okay",
style: .default,
handler: { _ in
self?.interactor.leave()
self?.navigationController?.popToRootViewController(animated: true)
}))
strongSelf.present(alert, animated: true) {
print(#function)
}
}
}
}

private func setupTracks(tracks: [HMSTrack]) {
for track in tracks {
if let videoTrack = track as? HMSLocalVideoTrack {
self.videoTrack = videoTrack
previewView.setVideoTrack(videoTrack)
}

if let audioTrack = track as? HMSLocalAudioTrack {
self.audioTrack = audioTrack
}
}
}

@IBAction private func backButtonTapped(_ sender: UIButton) {
interactor.leave()
navigationController?.popViewController(animated: true)
}

@IBAction private func startMeetingTapped(_ sender: UIButton) {
guard let viewController = UIStoryboard(name: Constants.meeting, bundle: nil)
.instantiateInitialViewController() as? MeetingViewController
else {
return
}

viewController.user = user
viewController.roomName = roomName
viewController.interactor = interactor

navigationController?.pushViewController(viewController, animated: true)
}

@IBAction private func cameraTapped(_ sender: UIButton) {
sender.isSelected = !sender.isSelected
videoTrack.setMute(sender.isSelected)
}

@IBAction private func micTapped(_ sender: UIButton) {
sender.isSelected = !sender.isSelected
audioTrack.setMute(sender.isSelected)
}
}
Loading

0 comments on commit 982cbb5

Please sign in to comment.