-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
52 changed files
with
1,191 additions
and
390 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
222 changes: 150 additions & 72 deletions
222
Example/HMSSDKExample/Login/Base.lproj/Login.storyboard
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
Oops, something went wrong.