-
-
Save zontan/8f6befb7eb505f2501d50380e34f3713 to your computer and use it in GitHub Desktop.
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
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { | |
return remoteUserIDs.count + 1 | |
} | |
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { | |
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "videoCell", for: indexPath) | |
if indexPath.row == remoteUserIDs.count { //Put our local video last | |
if let videoCell = cell as? VideoCollectionViewCell { | |
let videoCanvas = AgoraRtcVideoCanvas() | |
videoCanvas.uid = callID | |
videoCanvas.view = videoCell.videoView | |
videoCanvas.renderMode = .fit | |
getAgoraEngine().setupLocalVideo(videoCanvas) | |
} | |
} else { | |
let remoteID = remoteUserIDs[indexPath.row] | |
if let videoCell = cell as? VideoCollectionViewCell { | |
let videoCanvas = AgoraRtcVideoCanvas() | |
videoCanvas.uid = remoteID | |
videoCanvas.view = videoCell.videoView | |
videoCanvas.renderMode = .fit | |
getAgoraEngine().setupRemoteVideo(videoCanvas) | |
print("Creating remote view of uid: \(remoteID)") | |
} | |
} | |
return cell | |
} | |
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { | |
let numFeeds = remoteUserIDs.count + 1 | |
let totalWidth = collectionView.frame.width - collectionView.adjustedContentInset.left - collectionView.adjustedContentInset.right | |
let totalHeight = collectionView.frame.height - collectionView.adjustedContentInset.top - collectionView.adjustedContentInset.bottom | |
if numFeeds == 1 { | |
return CGSize(width: totalWidth, height: totalHeight) | |
} else if numFeeds == 2 { | |
return CGSize(width: totalWidth, height: totalHeight / 2) | |
} else { | |
if indexPath.row == numFeeds { | |
return CGSize(width: totalWidth, height: totalHeight / 2) | |
} else { | |
return CGSize(width: totalWidth / CGFloat(numFeeds - 1), height: totalHeight / 2) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment