Skip to content

Instantly share code, notes, and snippets.

@zontan
Created July 6, 2020 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zontan/8f6befb7eb505f2501d50380e34f3713 to your computer and use it in GitHub Desktop.
Save zontan/8f6befb7eb505f2501d50380e34f3713 to your computer and use it in GitHub Desktop.
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