Skip to content

Commit

Permalink
Merge pull request #42 from 100mslive/0.3.2Release
Browse files Browse the repository at this point in the history
0.3.2 Release
  • Loading branch information
pawan-100ms authored Jul 1, 2022
2 parents d903c3e + 5a775ea commit 23bd356
Show file tree
Hide file tree
Showing 13 changed files with 138 additions and 80 deletions.
42 changes: 34 additions & 8 deletions Example/HMSSDKExample/Login/LoginViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ final class LoginViewController: UIViewController {
Utilities.drawCorner(on: joinMeetingButton)
}
}

var shouldShowPreview: Bool {
UserDefaults.standard.object(forKey: Constants.showVideoPreview) == nil || UserDefaults.standard.bool(forKey: Constants.showVideoPreview)
}

// MARK: - View Lifecycle

Expand Down Expand Up @@ -170,20 +174,42 @@ final class LoginViewController: UIViewController {
return
}

guard let name = alertController.textFields?[0].text, !name.isEmpty,
let viewController = self.storyboard?.instantiateViewController(identifier: Constants.previewControllerIdentifier) as? PreJoinPreviewViewController
else {
guard let name = alertController.textFields?[0].text, !name.isEmpty else {
dismiss(animated: true)
let message = "Enter Name!"
showErrorAlert(with: message)
return
}

viewController.user = name
viewController.roomName = room


save(name, room)


if shouldShowPreview {
preview(name: name, room: room)
} else {
join(name: name, room: room)
}
}

private func join(name: String, room: String) {
guard let viewController = UIStoryboard(name: Constants.meeting, bundle: nil)
.instantiateInitialViewController() as? MeetingViewController
else {
return
}

viewController.interactor = HMSSDKInteractor(for: name, in: room)

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

private func preview(name: String, room: String) {
guard let viewController = self.storyboard?.instantiateViewController(identifier: Constants.previewControllerIdentifier) as? PreJoinPreviewViewController
else {
return
}

viewController.interactor = HMSSDKInteractor(for: name, in: room)

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
import UIKit

class PreJoinPreviewViewController: PreviewViewController {

internal var user: String!
internal var roomName: String!
@IBOutlet weak var networkQualityView: NetworkQualityView!
@IBOutlet weak var peerListButton: UIButton! {
didSet {
Expand All @@ -32,6 +29,7 @@ class PreJoinPreviewViewController: PreviewViewController {
joinButton.isEnabled = false
setupInteractor()
startObservingNotifications()
interactor.preview()
UIApplication.shared.isIdleTimerDisabled = true
}

Expand All @@ -46,7 +44,6 @@ class PreJoinPreviewViewController: PreviewViewController {
}

private func setupInteractor() {
interactor = HMSSDKInteractor(for: user, in: roomName) {}
interactor.onPreview = { [weak self] _, tracks in
self?.setupTracks(tracks: tracks)
self?.joinButton.isEnabled = true
Expand Down Expand Up @@ -116,8 +113,6 @@ class PreJoinPreviewViewController: PreviewViewController {
return
}

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

navigationController?.pushViewController(viewController, animated: true)
Expand All @@ -130,7 +125,6 @@ class PreJoinPreviewViewController: PreviewViewController {
return
}

viewController.roomName = roomName
viewController.interactor = interactor

present(viewController, animated: true)
Expand Down
2 changes: 2 additions & 0 deletions Example/HMSSDKExample/Meeting/Chat/ChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ extension ChatViewController {
if let peer = message.sender {
name = peer.name
isLocal = (peer.peerID == interactor?.hmsSDK?.localPeer?.peerID)
} else {
name = "Bot"
}

guard let name = name else { return }
Expand Down
91 changes: 56 additions & 35 deletions Example/HMSSDKExample/Meeting/HMSSDKInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import HMSSDK
final class HMSSDKInteractor: HMSUpdateListener {

private(set) var hmsSDK: HMSSDK?
let user: String
let room: String

internal var onPreview: ((HMSRoom, [HMSTrack]) -> Void)?
internal var onRoleChange: ((HMSRoleChangeRequest) -> Void)?
Expand Down Expand Up @@ -49,20 +51,27 @@ final class HMSSDKInteractor: HMSUpdateListener {
// MARK: - Setup SDK

init(for user: String,
in room: String,
_ completion: @escaping () -> Void) {

in room: String) {
self.user = user
self.room = room
setupPlugins()

RoomService.setup(for: user, room) { [weak self] token in
guard let token = token else {
print(#function, "Error fetching token")
return
}

self?.setup(for: user, token: token, room)

completion()
setupSDK()
}

private func setupSDK() {
hmsSDK = HMSSDK.build { sdk in
sdk.appGroup = "group.live.100ms.videoapp"

let videoSettings = HMSVideoTrackSettings(codec: .VP8,
resolution: .init(width: 320, height: 180),
maxBitrate: 512,
maxFrameRate: 25,
cameraFacing: .front,
trackDescription: "Just a normal video track", videoPlugins: self.videoPlugins)

let audioSettings = HMSAudioTrackSettings(maxBitrate: 32, trackDescription: "Just a normal audio track")
sdk.trackSettings = HMSTrackSettings(videoSettings: videoSettings, audioSettings: audioSettings)
sdk.logger = self
}
}

Expand Down Expand Up @@ -90,35 +99,47 @@ final class HMSSDKInteractor: HMSUpdateListener {
}

private func setup(for user: String, token: String, _ room: String) {


hmsSDK = HMSSDK.build { sdk in
sdk.analyticsLevel = .verbose
sdk.appGroup = "group.live.100ms.videoapp"

let videoSettings = HMSVideoTrackSettings(codec: .VP8,
resolution: .init(width: 320, height: 180),
maxBitrate: 512,
maxFrameRate: 25,
cameraFacing: .front,
trackDescription: "Just a normal video track", videoPlugins: self.videoPlugins)

let audioSettings = HMSAudioTrackSettings(maxBitrate: 32, trackDescription: "Just a normal audio track")
sdk.trackSettings = HMSTrackSettings(videoSettings: videoSettings, audioSettings: audioSettings)
sdk.logger = self

guard let config = config else { return }
hmsSDK?.join(config: config, delegate: self)
}

func fetchConfig(completion: @escaping ((HMSConfig?) -> Void)) {
guard config == nil else {
completion(config)
return
}

RoomService.fetchToken(for: user, room) { [weak self] token in
guard let token = token, let self = self else {
print(#function, "Error fetching token")
completion(nil)
return
}

config = HMSConfig(userName: user, authToken: token, captureNetworkQualityInPreview: true)
self.config = HMSConfig(userName: self.user, authToken: token, captureNetworkQualityInPreview: true)

guard let config = config else { return }
hmsSDK?.preview(config: config, delegate: self)
completion(self.config)
}
}

func preview() {
fetchConfig { [weak self] config in
guard let config = config, let self = self else { return }
self.hmsSDK?.preview(config: config, delegate: self)
}
}

internal func join() {
guard let config = config else { return }
hmsSDK?.join(config: config, delegate: self)
func join() {
fetchConfig { [weak self] config in
guard let config = config, let self = self else { return }
self.hmsSDK?.join(config: config, delegate: self)
}
}

internal func leave() {
func leave() {
hmsSDK?.leave()
}

Expand Down Expand Up @@ -170,7 +191,7 @@ final class HMSSDKInteractor: HMSUpdateListener {

messages.append(message)
NotificationCenter.default.post(name: Constants.messageReceived, object: nil)
Utilities.showToast(message: "💬 \(message.sender!.name) sent you a message")
Utilities.showToast(message: "💬 \(message.sender?.name ?? "Unknown sender") sent you a message")
}

func on(updated speakers: [HMSSpeaker]) {
Expand Down
14 changes: 12 additions & 2 deletions Example/HMSSDKExample/Meeting/MeetingViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ final class MeetingViewController: UIViewController {

// MARK: - View Properties

internal var user: String!
internal var roomName: String!
var user: String {
interactor.user
}

var roomName: String {
interactor.room
}

internal var interactor: HMSSDKInteractor!

@IBOutlet weak var hlsContainer: UIView!
Expand Down Expand Up @@ -116,6 +122,8 @@ final class MeetingViewController: UIViewController {
viewModel?.showRoleChangePrompt = { [weak self] peer, force in
self?.showRoleChangePrompt(for: peer, force: force)
}

interactor.join()
}

override func viewWillAppear(_ animated: Bool) {
Expand Down Expand Up @@ -148,11 +156,13 @@ final class MeetingViewController: UIViewController {
hlsController?.streamURL = nil
hlsController?.stop()
collectionView.isHidden = false
interactor.hmsSDK?.resumeAfterExternalAudioPlayback()
return
}

collectionView.isHidden = true
hlsContainer.isHidden = false
interactor.hmsSDK?.prepareForExternalAudioPlayback()
hlsController?.streamURL = interactor?.hmsSDK?.room?.hlsStreamingState.variants.first?.url
hlsController?.play()
}
Expand Down
1 change: 0 additions & 1 deletion Example/HMSSDKExample/Meeting/MeetingViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ final class MeetingViewModel: NSObject,

self.interactor = interactor
setupDataSource()
interactor.join()

setup(collectionView)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ final class RTMPSettingsViewController: FormViewController {
<<< SwitchRow("recordingSwitch") {
$0.title = "Record"
}
form +++ Section("")
<<< IntRow("rtmpResolutionHeight"){
$0.title = "Resolution Height"
}
<<< IntRow("rtmpResolutionWidth") {
$0.title = "Resolution Width"
}
form +++ Section("")
<<< ButtonRow {
$0.title = "Start"
Expand Down Expand Up @@ -75,10 +82,17 @@ final class RTMPSettingsViewController: FormViewController {
if let inputURLs = values["rtmpURLs"] as? [Any] {
rtmpURLs = inputURLs.compactMap { $0 as? URL }
}


var resolution: HMSVideoResolution?
if let height = values["rtmpResolutionHeight"] as? Int,
let width = values["rtmpResolutionWidth"] as? Int,
height > 0 && width > 0 {
resolution = HMSVideoResolution(width: width, height: height)
}

let recordingEnabled = (values["recordingSwitch"] as? Bool) ?? false

let config = HMSRTMPConfig(meetingURL: meetingURL, rtmpURLs: rtmpURLs, record: recordingEnabled)
let config = HMSRTMPConfig(meetingURL: meetingURL, rtmpURLs: rtmpURLs, record: recordingEnabled, resolution: resolution)
delegate?.rtmpSettingsController(self, didSelect: config)
navigationController?.popViewController(animated: true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ final class PreviewPeersListViewController: UIViewController {

@IBOutlet private weak var table: UITableView!

internal var roomName: String!
var roomName: String {
interactor.room
}

@IBOutlet weak var roomNameButton: UIButton! {
didSet {
Expand Down
14 changes: 2 additions & 12 deletions Example/HMSSDKExample/Meeting/RoomService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,9 @@
import Foundation

struct RoomService {

static func setup(for user: String,
_ room: String,
completion: @escaping (String?) -> Void) {

getToken(for: user, room) { (token) in
completion(token)
}
}

// MARK: - Room Token

private static func getToken(for user: String,
static func fetchToken(for user: String,
_ room: String,
completion: @escaping (String?) -> Void) {

Expand All @@ -43,7 +33,7 @@ struct RoomService {
}
}

private static func requestToken(for user: String,
static func requestToken(for user: String,
_ roomID: String,
completion: @escaping (String?, Error?) -> Void) {

Expand Down
8 changes: 4 additions & 4 deletions Example/HMSSDKExample/Settings/Base.lproj/Settings.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="YWG-tV-MYB">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="20037" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="YWG-tV-MYB">
<device id="retina6_0" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19519"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/>
<capability name="Image references" minToolsVersion="12.0"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="Stack View standard spacing" minToolsVersion="9.0"/>
Expand Down Expand Up @@ -190,8 +190,8 @@
<stackView opaque="NO" contentMode="scaleToFill" distribution="equalSpacing" alignment="center" spacingType="standard" translatesAutoresizingMaskIntoConstraints="NO" id="mZr-8l-hGw">
<rect key="frame" x="15" y="335" width="360" height="31"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Show Video Preview before joining" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Tki-g3-ooM">
<rect key="frame" x="0.0" y="7" width="222.66666666666666" height="17"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Show Preview Screen Before Joining" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Tki-g3-ooM">
<rect key="frame" x="0.0" y="7" width="235.66666666666666" height="17"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
Expand Down
Loading

0 comments on commit 23bd356

Please sign in to comment.