Skip to content

Commit

Permalink
0.0.8 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
gzerad committed Jul 26, 2021
1 parent 57a1475 commit d055068
Show file tree
Hide file tree
Showing 48 changed files with 420 additions and 317 deletions.
4 changes: 0 additions & 4 deletions Example/HMSSDKExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
EC8CEE7D261E297F002DC12E /* ChatViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC8CEE56261E297F002DC12E /* ChatViewController.swift */; };
EC8CEE7F261E297F002DC12E /* ChatTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC8CEE59261E297F002DC12E /* ChatTableViewCell.swift */; };
EC8CEE80261E297F002DC12E /* Chat.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = EC8CEE5A261E297F002DC12E /* Chat.storyboard */; };
EC8CEE81261E297F002DC12E /* BadgeButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC8CEE5C261E297F002DC12E /* BadgeButton.swift */; };
EC8CEE82261E297F002DC12E /* MeetingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC8CEE5D261E297F002DC12E /* MeetingViewController.swift */; };
EC8CEE84261E297F002DC12E /* RoomService.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC8CEE5F261E297F002DC12E /* RoomService.swift */; };
EC8CEE85261E297F002DC12E /* VideoCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC8CEE60261E297F002DC12E /* VideoCollectionViewCell.swift */; };
Expand Down Expand Up @@ -68,7 +67,6 @@
EC8CEE56261E297F002DC12E /* ChatViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChatViewController.swift; sourceTree = "<group>"; };
EC8CEE59261E297F002DC12E /* ChatTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChatTableViewCell.swift; sourceTree = "<group>"; };
EC8CEE5B261E297F002DC12E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Chat.storyboard; sourceTree = "<group>"; };
EC8CEE5C261E297F002DC12E /* BadgeButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BadgeButton.swift; sourceTree = "<group>"; };
EC8CEE5D261E297F002DC12E /* MeetingViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MeetingViewController.swift; sourceTree = "<group>"; };
EC8CEE5F261E297F002DC12E /* RoomService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RoomService.swift; sourceTree = "<group>"; };
EC8CEE60261E297F002DC12E /* VideoCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VideoCollectionViewCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -217,7 +215,6 @@
EC8CEE56261E297F002DC12E /* ChatViewController.swift */,
EC8CEE59261E297F002DC12E /* ChatTableViewCell.swift */,
EC8CEE5A261E297F002DC12E /* Chat.storyboard */,
EC8CEE5C261E297F002DC12E /* BadgeButton.swift */,
);
path = Chat;
sourceTree = "<group>";
Expand Down Expand Up @@ -430,7 +427,6 @@
EC8CEE8A261E297F002DC12E /* Utilities.swift in Sources */,
EC8CEE86261E297F002DC12E /* MeetingViewModel.swift in Sources */,
EC8CEE78261E297F002DC12E /* HMSSDKInteractor.swift in Sources */,
EC8CEE81261E297F002DC12E /* BadgeButton.swift in Sources */,
EC8CEE8D261E297F002DC12E /* AppDelegate.swift in Sources */,
EC8CEE84261E297F002DC12E /* RoomService.swift in Sources */,
EC8CEE87261E297F002DC12E /* Constants.swift in Sources */,
Expand Down
3 changes: 1 addition & 2 deletions Example/HMSSDKExample/Meeting/Base.lproj/Meeting.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@
<action selector="micTapped:" destination="mjG-Ba-if7" eventType="touchUpInside" id="bth-WE-Rka"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Cxf-bq-abg" customClass="BadgeButton" customModule="HMSSDKExample" customModuleProvider="target">
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Cxf-bq-abg">
<rect key="frame" x="191.66666666666666" y="0.0" width="83.666666666666657" height="44"/>
<constraints>
<constraint firstAttribute="height" constant="44" id="RA3-dL-P1E"/>
Expand Down Expand Up @@ -370,7 +370,6 @@
<nil key="simulatedTopBarMetrics"/>
<nil key="simulatedBottomBarMetrics"/>
<connections>
<outlet property="badgeButton" destination="Cxf-bq-abg" id="1mm-tg-yyk"/>
<outlet property="collectionView" destination="DyH-bp-NTF" id="pNW-T6-NPM"/>
<outlet property="loadingIcon" destination="oQb-0c-kLb" id="wkn-qX-R21"/>
<outlet property="publishAudioButton" destination="hKQ-0T-b7l" id="ubh-Yl-SjS"/>
Expand Down
86 changes: 0 additions & 86 deletions Example/HMSSDKExample/Meeting/Chat/BadgeButton.swift

This file was deleted.

5 changes: 5 additions & 0 deletions Example/HMSSDKExample/Meeting/HMSSDKInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ final class HMSSDKInteractor: HMSUpdateListener {
var roles: [HMSRole]? {
hmsSDK?.roles
}

var currentRole: HMSRole? {
hmsSDK?.localPeer?.role
}


// MARK: - Setup Stream
Expand Down Expand Up @@ -127,6 +131,7 @@ final class HMSSDKInteractor: HMSUpdateListener {

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

func on(updated speakers: [HMSSpeaker]) {
Expand Down
139 changes: 75 additions & 64 deletions Example/HMSSDKExample/Meeting/MeetingViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import UIKit
import HMSSDK
import MediaPlayer

final class MeetingViewController: UIViewController {
final class MeetingViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate {

// MARK: - View Properties

Expand All @@ -32,8 +32,6 @@ final class MeetingViewController: UIViewController {

@IBOutlet private weak var collectionView: UICollectionView!

@IBOutlet private weak var badgeButton: BadgeButton!

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

Expand Down Expand Up @@ -112,8 +110,6 @@ final class MeetingViewController: UIViewController {
UIMenu(title: "Change Layout", image: nil, identifier: nil, options: [], children: menuItems)
}

private var chatBadgeCount = 0

// MARK: - View Lifecycle

override func viewDidLoad() {
Expand All @@ -140,75 +136,77 @@ final class MeetingViewController: UIViewController {
}

private func showPeerActionsMenu(for peer: HMSRemotePeer, on button: UIButton) {
let title = "Select action"

let alertController = UIAlertController(title: title,
message: nil,
preferredStyle: .actionSheet)


alertController.addAction(UIAlertAction(title: "Prompt to change role", style: .default) { [weak self, weak peer] _ in
guard let peer = peer else { return }
self?.showRoleChangePrompt(for: peer, force: false)
})
var actions = [UIAlertAction]()

alertController.addAction(UIAlertAction(title: "Force change role", style: .default) { [weak self, weak peer] _ in
guard let peer = peer else { return }
self?.showRoleChangePrompt(for: peer, force: true)
})
if canRoleChange() {
actions.append(UIAlertAction(title: "Prompt to change role", style: .default) { [weak self, weak peer] _ in
guard let peer = peer else { return }
self?.showRoleChangePrompt(for: peer, force: false)
})
actions.append(UIAlertAction(title: "Force change role", style: .default) { [weak self, weak peer] _ in
guard let peer = peer else { return }
self?.showRoleChangePrompt(for: peer, force: true)
})
}

alertController.addAction(UIAlertAction(title: "Select high layer", style: .default) { [weak peer] _ in
peer?.remoteVideoTrack()?.layer = .high
})
let layerNameMap: [HMSSimulcastLayer : String] = [ .high : "high", .mid : "mid", .low : "low" ]
peer.remoteVideoTrack()?.layerDefinitions?.forEach {
let layer = $0.layer
guard let layerName = layerNameMap[layer] else { return }
actions.append(UIAlertAction(title: "Select \(layerName) layer", style: .default) { [weak peer] _ in
peer?.remoteVideoTrack()?.layer = layer
})
}

alertController.addAction(UIAlertAction(title: "Select mid layer", style: .default) { [weak peer] _ in
peer?.remoteVideoTrack()?.layer = .mid
})
guard actions.count > 0 else {
return
}

alertController.addAction(UIAlertAction(title: "Select low layer", style: .default) { [weak peer] _ in
peer?.remoteVideoTrack()?.layer = .low
})
let alertController = UIAlertController(title: "Select action",
message: nil,
preferredStyle: .actionSheet)

actions.forEach { alertController.addAction($0) }

alertController.addAction(UIAlertAction(title: "Cancel", style: .cancel))

if let popoverController = alertController.popoverPresentationController {
alertController.modalPresentationStyle = .popover
popoverController.sourceView = button //to set the source of your alert
popoverController.sourceView = button
popoverController.sourceRect = button.bounds
popoverController.permittedArrowDirections = [] //to hide the arrow of any particular direction
popoverController.permittedArrowDirections = []
}
present(alertController, animated: true)
}

private func canRoleChange() -> Bool {
interactor?.currentRole?.permissions.changeRole ?? false
}

private func showRoleChangePrompt(for peer: HMSRemotePeer, force: Bool) {
let title = "Role change request"

let alertController = UIAlertController(title: title,
message: nil,
message: "\n\n\n\n\n\n\n\n\n",
preferredStyle: .alert)

alertController.addTextField { textField in
textField.placeholder = "Enter role"
textField.clearButtonMode = .always
textField.text = "teacher"
}


let pickerView = UIPickerView(frame:
CGRect(x: 0, y: 50, width: 270, height: 162))
pickerView.dataSource = self
pickerView.delegate = self

alertController.view.addSubview(pickerView)

alertController.addAction(UIAlertAction(title: "Cancel", style: .cancel))
alertController.addAction(UIAlertAction(title: "Send", style: .default) { [weak self, weak alertController] _ in
guard let roleName = alertController?.textFields?[0].text else {
return
}

let trimmedRoleName = roleName.trimmingCharacters(in: .whitespacesAndNewlines).lowercased()
guard !trimmedRoleName.isEmpty else { return }

guard let currentRoleName = peer.role?.name.lowercased(), trimmedRoleName != currentRoleName else {
self?.showRoleIsSameError(for: peer, role: roleName)
alertController.addAction(UIAlertAction(title: "Send", style: .default) { [weak self, weak pickerView] _ in
guard let rowIndex = pickerView?.selectedRow(inComponent: 0),
let targetRole = self?.interactor.roles?[rowIndex] else {
return
}

guard let targetRole = self?.interactor.roles?.first(where: { $0.name.lowercased() == trimmedRoleName }) else {
guard let currentRoleName = peer.role?.name, currentRoleName != targetRole.name else {
self?.showRoleIsSameError(for: peer, role: peer.role?.name ?? "")
return
}

Expand All @@ -232,6 +230,22 @@ final class MeetingViewController: UIViewController {

present(alertController, animated: true)
}

func numberOfComponents(in pickerView: UIPickerView) -> Int {
1
}

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
interactor.roles?.count ?? 0
}

func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
guard let role = interactor.roles?[row] else {
return ""
}

return role.name
}

override func viewWillDisappear(_ animated: Bool) {
if isMovingFromParent {
Expand Down Expand Up @@ -287,14 +301,7 @@ final class MeetingViewController: UIViewController {
}

private func observeBroadcast() {
_ = NotificationCenter.default.addObserver(forName: Constants.messageReceived,
object: nil,
queue: .main) { [weak self] _ in
if let strongSelf = self {
strongSelf.chatBadgeCount += 1
strongSelf.badgeButton.badge = "\(strongSelf.chatBadgeCount)"
}
}


_ = NotificationCenter.default.addObserver(forName: Constants.joinedRoom,
object: nil,
Expand Down Expand Up @@ -367,6 +374,12 @@ final class MeetingViewController: UIViewController {

viewController.interactor = viewModel.interactor
viewController.speakers = viewModel.speakers
viewController.onSettingsButtonTap = { [weak self] peer, button in
guard let remotePeer = peer as? HMSRemotePeer else { return }
self?.dismiss(animated: true, completion: {
self?.showPeerActionsMenu(for: remotePeer, on: button)
})
}

present(viewController, animated: true)
}
Expand Down Expand Up @@ -406,11 +419,7 @@ final class MeetingViewController: UIViewController {
}

viewController.interactor = viewModel.interactor

chatBadgeCount = 0

badgeButton.badge = nil


present(viewController, animated: true)
}

Expand All @@ -436,14 +445,16 @@ final class MeetingViewController: UIViewController {

if let videoTrack = localPeer.videoTrack as? HMSLocalVideoTrack {
publishVideoButton.isSelected = videoTrack.isMute()
publishVideoButton.isHidden = false
} else {
publishVideoButton.isSelected = true
publishVideoButton.isHidden = true
}

if let audioTrack = localPeer.audioTrack as? HMSLocalAudioTrack {
publishAudioButton.isSelected = audioTrack.isMute()
publishAudioButton.isHidden = false
} else {
publishAudioButton.isSelected = true
publishAudioButton.isHidden = true
}
}

Expand Down
Loading

0 comments on commit d055068

Please sign in to comment.