Skip to content

Commit

Permalink
Merge pull request #28 from 100mslive/0.2.7Release
Browse files Browse the repository at this point in the history
  • Loading branch information
ygit authored Feb 21, 2022
2 parents 106a54c + 2978913 commit 7beea97
Show file tree
Hide file tree
Showing 20 changed files with 458 additions and 184 deletions.
4 changes: 4 additions & 0 deletions Example/HMSSDKExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
9174C9F726FCB53900FD7C04 /* 100ms.gif in Resources */ = {isa = PBXBuildFile; fileRef = 9174C9F626FCB53900FD7C04 /* 100ms.gif */; };
91CB89C32705E0BF00F26322 /* PreJoinPreviewViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91CB89C22705E0BF00F26322 /* PreJoinPreviewViewController.swift */; };
91CB89C52705E0D400F26322 /* RolePreviewViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91CB89C42705E0D400F26322 /* RolePreviewViewController.swift */; };
91E1F37F27C395A200F76E47 /* PreviewPeersListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91E1F37E27C395A200F76E47 /* PreviewPeersListViewController.swift */; };
91E7E145268C70F2001D988E /* PreviewViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91E7E144268C70F2001D988E /* PreviewViewController.swift */; };
91FCE9542770C62E00034F96 /* HLSStreamViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91FCE9532770C62E00034F96 /* HLSStreamViewController.swift */; };
91FCE9562770C63B00034F96 /* HLSSettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91FCE9552770C63B00034F96 /* HLSSettingsViewController.swift */; };
Expand Down Expand Up @@ -69,6 +70,7 @@
9174C9F626FCB53900FD7C04 /* 100ms.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = 100ms.gif; sourceTree = "<group>"; };
91CB89C22705E0BF00F26322 /* PreJoinPreviewViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PreJoinPreviewViewController.swift; sourceTree = "<group>"; };
91CB89C42705E0D400F26322 /* RolePreviewViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RolePreviewViewController.swift; sourceTree = "<group>"; };
91E1F37E27C395A200F76E47 /* PreviewPeersListViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PreviewPeersListViewController.swift; sourceTree = "<group>"; };
91E7E144268C70F2001D988E /* PreviewViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreviewViewController.swift; sourceTree = "<group>"; };
91FCE9532770C62E00034F96 /* HLSStreamViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HLSStreamViewController.swift; sourceTree = "<group>"; };
91FCE9552770C63B00034F96 /* HLSSettingsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HLSSettingsViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -235,6 +237,7 @@
isa = PBXGroup;
children = (
EC8CEE51261E297F002DC12E /* PeersListViewController.swift */,
91E1F37E27C395A200F76E47 /* PreviewPeersListViewController.swift */,
EC8CEE52261E297F002DC12E /* PeersListTableViewCell.swift */,
EC8CEE53261E297F002DC12E /* PeersList.storyboard */,
);
Expand Down Expand Up @@ -476,6 +479,7 @@
EC8CEE8F261E297F002DC12E /* LoginViewController.swift in Sources */,
91FCE9562770C63B00034F96 /* HLSSettingsViewController.swift in Sources */,
EC8CEE7D261E297F002DC12E /* ChatViewController.swift in Sources */,
91E1F37F27C395A200F76E47 /* PreviewPeersListViewController.swift in Sources */,
91457ADC2751197D00DCFCBD /* PeerMetadata.swift in Sources */,
EC8CEE82261E297F002DC12E /* MeetingViewController.swift in Sources */,
9174C9F426FCB46200FD7C04 /* RTMPSettingsViewController.swift in Sources */,
Expand Down
26 changes: 21 additions & 5 deletions Example/HMSSDKExample/Login/Base.lproj/Login.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="18122" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="JHd-X7-1X6">
<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="JHd-X7-1X6">
<device id="retina5_9" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19519"/>
<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 @@ -165,8 +165,8 @@
<action selector="backButtonTapped:" destination="CB4-9g-lxH" eventType="touchUpInside" id="Arz-EE-WOH"/>
</connections>
</button>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="center" spacing="48" translatesAutoresizingMaskIntoConstraints="NO" id="lig-Kg-1vh">
<rect key="frame" x="0.0" y="316" width="375" height="180"/>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="center" spacing="20" translatesAutoresizingMaskIntoConstraints="NO" id="lig-Kg-1vh">
<rect key="frame" x="0.0" y="294" width="375" height="224"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" spacing="48" translatesAutoresizingMaskIntoConstraints="NO" id="uet-JR-n1P">
<rect key="frame" x="99.666666666666686" y="0.0" width="176" height="64"/>
Expand Down Expand Up @@ -213,8 +213,23 @@
</button>
</subviews>
</stackView>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="q1x-9c-s1z">
<rect key="frame" x="128" y="84" width="119" height="52"/>
<color key="backgroundColor" systemColor="linkColor"/>
<constraints>
<constraint firstAttribute="height" constant="52" id="WYU-vS-yLb"/>
</constraints>
<fontDescription key="fontDescription" style="UICTFontTextStyleTitle3"/>
<color key="tintColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<inset key="contentEdgeInsets" minX="0.0" minY="2" maxX="0.0" maxY="0.0"/>
<inset key="imageEdgeInsets" minX="-8" minY="0.0" maxX="0.0" maxY="0.0"/>
<state key="normal" title="3 peers in room"/>
<connections>
<action selector="peerListTapped:" destination="CB4-9g-lxH" eventType="touchUpInside" id="8Wh-o9-vWJ"/>
</connections>
</button>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacingType="standard" translatesAutoresizingMaskIntoConstraints="NO" id="uRj-if-AyW">
<rect key="frame" x="8" y="112" width="359" height="68"/>
<rect key="frame" x="8" y="156" width="359" height="68"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="sar-qp-8u8">
<rect key="frame" x="15" y="8" width="329" height="52"/>
Expand Down Expand Up @@ -272,6 +287,7 @@
<navigationItem key="navigationItem" id="K7u-NR-vFb"/>
<connections>
<outlet property="joinButton" destination="sar-qp-8u8" id="b9z-ga-RIY"/>
<outlet property="peerListButton" destination="q1x-9c-s1z" id="Z1e-iK-3mJ"/>
<outlet property="previewView" destination="yC4-5P-J60" id="Nrc-lI-BSl"/>
<outlet property="publishAudioButton" destination="Dlj-dE-oPY" id="Tee-VK-1Ka"/>
<outlet property="publishVideoButton" destination="CIN-yc-MeB" id="3nf-Q8-YqS"/>
Expand Down
52 changes: 48 additions & 4 deletions Example/HMSSDKExample/Login/PreJoinPreviewViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ class PreJoinPreviewViewController: PreviewViewController {

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

@IBOutlet weak var peerListButton: UIButton! {
didSet {
peerListButton.contentEdgeInsets = UIEdgeInsets.init(top: 10, left: 20, bottom: 10, right: 20)
peerListButton.isHidden = true
Utilities.drawCorner(on: peerListButton)
}
}

@IBOutlet private weak var joinButton: UIButton! {
didSet {
Utilities.drawCorner(on: joinButton)
Expand All @@ -24,6 +31,17 @@ class PreJoinPreviewViewController: PreviewViewController {
joinButton.isEnabled = false
setupInteractor()
observeBroadcast()
UIApplication.shared.isIdleTimerDisabled = true
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
UIApplication.shared.isIdleTimerDisabled = true
}

func cleanup() {
interactor.leave()
UIApplication.shared.isIdleTimerDisabled = false
}

private func setupInteractor() {
Expand All @@ -32,6 +50,20 @@ class PreJoinPreviewViewController: PreviewViewController {
self?.setupTracks(tracks: tracks)
self?.joinButton.isEnabled = true
}

interactor.onMetadataUpdate = { [weak self] in
self?.updateParticipants()
}
}

private func updateParticipants() {
guard let room = interactor.hmsSDK?.room else {
return
}

let count = room.peerCount ?? 0
peerListButton.isHidden = count == 0
peerListButton.setTitle("\(count) peer(s) in room", for: .normal)
}

private func observeBroadcast() {
Expand All @@ -46,7 +78,7 @@ class PreJoinPreviewViewController: PreviewViewController {
alert.addAction(UIAlertAction(title: "Okay",
style: .default,
handler: { _ in
self?.interactor.leave()
self?.cleanup()
self?.navigationController?.popToRootViewController(animated: true)
}))
strongSelf.present(alert, animated: true) {
Expand All @@ -55,9 +87,9 @@ class PreJoinPreviewViewController: PreviewViewController {
}
}
}

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

Expand All @@ -74,5 +106,17 @@ class PreJoinPreviewViewController: PreviewViewController {

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

@IBAction private func peerListTapped(_ sender: UIButton) {
guard let viewController = UIStoryboard(name: Constants.peersList, bundle: nil)
.instantiateViewController(withIdentifier: Constants.peersListPreview) as? PreviewPeersListViewController else {
return
}

viewController.roomName = roomName
viewController.interactor = interactor

present(viewController, animated: true)
}

}
3 changes: 1 addition & 2 deletions Example/HMSSDKExample/Login/PreviewViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class PreviewViewController: UIViewController {

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


// MARK: - View Modifiers

Expand All @@ -48,7 +48,6 @@ class PreviewViewController: UIViewController {

// MARK: - Action Handlers


@IBAction func cameraTapped(_ sender: UIButton) {
sender.isSelected = !sender.isSelected
videoTrack?.setMute(sender.isSelected)
Expand Down
37 changes: 18 additions & 19 deletions Example/HMSSDKExample/Meeting/HLSStreamViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,79 +10,78 @@ import UIKit
import AVFoundation

class HLSStreamViewController: UIViewController {

var player: AVPlayer?
var playerView: PlayerView!
var retriesLeft = 0

var streamURL: URL? {
didSet {
if (oldValue == streamURL) {
if oldValue == streamURL {
return
}
stop()
retriesLeft = 10
}
}

override func loadView() {
playerView = PlayerView()
view = playerView
}

var playerItem: AVPlayerItem?

func play() {
guard let streamURL = streamURL else {
return
}



// Create asset to be played
print("Trying to play: \(streamURL.absoluteString)")
let asset = AVAsset(url: streamURL)

let assetKeys = [
"playable",
"playable"
]
// Create a new AVPlayerItem with the asset and an
// array of asset keys to be automatically loaded
let item = AVPlayerItem(asset: asset,
automaticallyLoadedAssetKeys: assetKeys)

// Register as an observer of the player item's status property
item.addObserver(self,
forKeyPath: #keyPath(AVPlayerItem.status),
options: [.old, .new],
context: nil)
playerItem = item

if player == nil {
player = AVPlayer(playerItem: item)
playerView.player = player
} else {
player?.replaceCurrentItem(with: item)
}
}

func stop() {
player?.pause()
}

override func observeValue(forKeyPath keyPath: String?,
of object: Any?,
change: [NSKeyValueChangeKey : Any]?,
change: [NSKeyValueChangeKey: Any]?,
context: UnsafeMutableRawPointer?) {
if keyPath == #keyPath(AVPlayerItem.status) {
let status: AVPlayerItem.Status

// Get the status change from the change dictionary
if let statusNumber = change?[.newKey] as? NSNumber {
status = AVPlayerItem.Status(rawValue: statusNumber.intValue)!
} else {
status = .unknown
}

// Switch over the status
switch status {
case .readyToPlay:
Expand All @@ -96,7 +95,7 @@ class HLSStreamViewController: UIViewController {
guard let self = self else {
return
}

if self.retriesLeft > 0 {
self.retriesLeft = self.retriesLeft - 1
self.play()
Expand All @@ -117,7 +116,7 @@ class PlayerView: UIView {
override class var layerClass: AnyClass {
return AVPlayerLayer.self
}

var player: AVPlayer? {
get {
(layer as? AVPlayerLayer)?.player
Expand Down
20 changes: 11 additions & 9 deletions Example/HMSSDKExample/Meeting/HMSSDKInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@ final class HMSSDKInteractor: HMSUpdateListener {
internal var onRemovedFromRoom: ((HMSRemovedFromRoomNotification) -> Void)?
internal var onRecordingUpdate: (() -> Void)?
internal var onHLSUpdate: (() -> Void)?
internal var onMetadataUpdate: (() -> Void)?
internal var updatedMuteStatus: ((HMSAudioTrack) -> Void)?

// MARK: - Instance Properties

internal var messages = [HMSMessage]()

internal var isRecording: Bool {
get {
guard let room = hmsSDK?.room else { return false }
return room.browserRecordingState.running || room.serverRecordingState.running
}
}

internal var isStreaming: Bool {
get {
guard let room = hmsSDK?.room else { return false }
Expand Down Expand Up @@ -154,16 +155,18 @@ final class HMSSDKInteractor: HMSUpdateListener {

func on(room: HMSRoom, update: HMSRoomUpdate) {
print(#function, room.name ?? "", update.description)

switch update {
case .browserRecordingStateUpdated, .rtmpStreamingStateUpdated:
onRecordingUpdate?()
case .hlsStreamingStateUpdated:
onHLSUpdate?()
case .metaDataUpdated:
onMetadataUpdate?()
default:
break
}

}

func on(roleChangeRequest: HMSRoleChangeRequest) {
Expand All @@ -186,23 +189,22 @@ final class HMSSDKInteractor: HMSUpdateListener {
func on(removedFromRoom notification: HMSRemovedFromRoomNotification) {
onRemovedFromRoom?(notification)
}

func on(remoteAudioStats: HMSRemoteAudioStats, track: HMSRemoteAudioTrack, peer: HMSPeer) {
NotificationCenter.default.post(name: Constants.trackStatsUpdated, object: peer, userInfo: ["stats": remoteAudioStats, "track": track, "peer": peer])
}

func on(remoteVideoStats: HMSRemoteVideoStats, track: HMSRemoteVideoTrack, peer: HMSPeer) {
NotificationCenter.default.post(name: Constants.trackStatsUpdated, object: peer, userInfo: ["stats": remoteVideoStats, "track": track, "peer": peer])
}

func on(localAudioStats: HMSLocalAudioStats, track: HMSLocalAudioTrack, peer: HMSPeer) {
NotificationCenter.default.post(name: Constants.trackStatsUpdated, object: peer, userInfo: ["stats": localAudioStats, "track": track, "peer": peer])
}

func on(localVideoStats: HMSLocalVideoStats, track: HMSLocalVideoTrack, peer: HMSPeer) {
NotificationCenter.default.post(name: Constants.trackStatsUpdated, object: peer, userInfo: ["stats": localVideoStats, "track": track, "peer": peer])
}


// MARK: - Role Actions

Expand Down
Loading

0 comments on commit 7beea97

Please sign in to comment.