100mslive / 100ms-ios-sdk

iOS Video Conferencing SDK & Sample App
MIT License
53 stars 12 forks source link

Screen Share and render shared screen [iOS] #27

Closed BhavinBhadani closed 2 years ago

BhavinBhadani commented 2 years ago

I am trying to figure out how can I display screen shared by web app to my device as I don't find anything into doc and it just crashed in iOS app when it shared from web app?. The other question is when can we expect screen share feature from iOS side as well?

gzerad commented 2 years ago

There is no special handling required to render screen share on iOS. You will get a HMSVideoTrack just like for regualr video, and the track source will be equal to screen. Could you attach a crash log perhaps? Regarding sharing screen from ios there is no fixed date atm, but most likely end of feb / early march.

BhavinBhadani commented 2 years ago

Hi, Here is the screenshot for the crash

Screenshot 2022-02-11 at 3 44 09 PM
gzerad commented 2 years ago

This does not look screen share specific to me. Seems like this is due to improper configuration of UIDiffableDataSource cant tell more without looking at the code.

BhavinBhadani commented 2 years ago

@gzerad I'm using DiffableDataSource with HMSPeer and not with HMSViewModel because I want some kind of filters which is not worked with HMSViewModel. So, here the code that creates the issue

 private func applySnapshot(animatingDifferences: Bool = true) {
    guard let diffableDataSource = diffableDataSource else { return }
    let sections = dataSource.sections
    var snapshot = Snapshot()
    snapshot.appendSections(sections)
    sections.forEach { section in
        if let activePeers = getActivePeers() {
            var spectators: [HMSPeer] = []
            var mutableSpectators: [HMSPeer] = []

            section.models.forEach { model in
                if let customerId = model.peer.customerUserID {
                    if activePeers.contains(customerId) {
                        spectators.append(model.peer)
                    } else {
                        mutableSpectators.append(model.peer)
                    }
                }
            }

            mutableSpectators.forEach { spectator in
                if let remoteAudio = spectator.audioTrack as? HMSRemoteAudioTrack {
                    remoteAudio.setVolume(0)
                }
            }

            spectators.forEach { spectator in
                if let remoteAudio = spectator.audioTrack as? HMSRemoteAudioTrack {
                    remoteAudio.setVolume(1)
                }
            }

            snapshot.appendItems(spectators, toSection: section)
        }
    }
    diffableDataSource.apply(snapshot, animatingDifferences: animatingDifferences)
}
gzerad commented 2 years ago

UIDiffableDataSource needs all the elements to be unique, if you are using HMSPeer instead of HMSViewModel you need to make sure that single HMSPeer can't be added twice. The default behavior of HMSDataSource is to create a HMSViewModel for each video track that HMSPeer is currently publishing. So if you just loop over and extract HMSPeer you will get that peer two times in case peer is sharing both video and screen tracks. Can you describe what was the filters you wanted to create? Have you tried setting filter property on HMSDataSource with a filtering closure?

gzerad commented 2 years ago

Also I have noticed that you are trying to manually mute some users. Using "roles" might work better for you, see this guide for reference.

BhavinBhadani commented 2 years ago

@gzerad Regarding filter, I am doing some filtering based on firebase data which we set for different purpose and based on that I am filtering data. I first tried to do that using HMSViewModel but it didn't work. So, I have to achive that using HMSPeer. I already post a issue recently for the filter as well

BhavinBhadani commented 2 years ago

@gzerad How to render a screen share cell in to mobile?

ygit commented 2 years ago

@BhavinBhadani a screen share is akin to any other video track. Set it to an instance of HMSVideoView.

A screen share track comes in as an HMSRemoteVideoTrack within auxiliaryTracks of the HMSPeer object.

You can get this either from the onTrackUpdate or just check for this in the HMSPeer who is sharing the screen.

Ensure to set videoContentMode of HMSVideoView to UIViewContentModeScaleAspectFit so that there's no clipping of the screen share.

StackHelp commented 2 years ago

@gzerad When we rotate spectators, the video view hangs and sometimes displays a black screen when rotating from landscape to portrait. Do you know how to resolve it?