Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ScreenShare works only once #3

Open
enzofrancescaHM opened this issue Feb 9, 2023 · 6 comments
Open

ScreenShare works only once #3

enzofrancescaHM opened this issue Feb 9, 2023 · 6 comments

Comments

@enzofrancescaHM
Copy link

enzofrancescaHM commented Feb 9, 2023

In the example, you can share the screen only once, the first time everything works without problems, but if you press disable screen share and the press again to share another time, nothing happens.
I think there are 2 different causes:

  1. the screen share is always paused, never stopped, a more correct approach should be to stop the tracks using somethig similar to:
  if(type === 'screenshare')
            {              
              screenshareStream.getTracks().forEach(function(track){
                track.stop();
              });
              screenshareStream = null;
            }

this approach has the benefit that it really close the screen sharing

  1. even using the approach above when you press again the share button the producer starts and is received from the other connected people, but nothing is shown.

Have you got some hints? Some area where I can investigate?
Thanks in advance

@Vesper0704
Copy link
Owner

Sorry for not replying for such a long time. I've been busy with my school matters.
I wonder if by ...and the press again to share another time, nothing happens., do you mean there are no streams rendered? I've tested many times and it seems the stream can be controlled to display/disappear normally like this:
Kapture 2023-11-17 at 21 19 28

Maybe you mean choose another brand new screenshare stream?

@Vesper0704
Copy link
Owner

@enzofrancescaHM Hi, I just looked into it and found out how to satisfy your requirement. By default, the disable button just pauses the stream initialized before, and if you want to destroy the stream completely and start an entirely new stream next time, you should call removeLocalMediaStream to remove the stream, and the corresponding producer will be closed as well in the adapter. By this, if you press the enable button next time, you should call navigator.mediaDevices.getDisplayMedia() and addLocalMediaStream again, which generates a new producer and notify other clients to consumer the stream.
In this way, you can successfully yield and transmit new stream to others. However, the networked-video-source doesn't update the new stream automatically after the first time. You can set the srcObject manually maybe, or by this :document.querySelector('a-plane[networked-video-source="streamName: screenshare"]').components['networked-video-source']._setMediaStream(stream). I am not familiar with NAF, maybe @vincentfretin can help you with that?

@vincentfretin
Copy link

I fixed this kind of issue not long ago in the basic-multi-streams.html example to register a track ended listener that calls removeLocalMediaStream, see the changes in networked-aframe/networked-aframe#421

@Vesper0704
Copy link
Owner

@vincentfretin Thanks! But I have got a question here: When I use stream.getTracks().forEach(track => stream.removeTrack(track) to remove the track, the removetrack listener is not invoked. But if I replace removetrack with inactive, it works.
Here is the example:

          // Listen for the 'removetrack' event on the MediaStream
          // that is emitted when the remote screen sharing stops.

          // newStream.addEventListener('removetrack', () => {
          // didn't invoke here?
          //   this._clearMediaStream();
          //   this._waitForMediaStream();
          // });

            newStream.oninactive = () => {
              // it works
              console.log('removed track', newStream);
              this._clearMediaStream();
              this._waitForMediaStream();
            };

Is there anything wrong, or is it better to listen the inactive event as well?

@vincentfretin
Copy link

The "removetrack" event may be specific to how the open-easyrtc lib is creating a new Stream object and adding and removing tracks, so may not work with mediasoup.
If the inactive event works for mediasoup, that's good.

@Vesper0704
Copy link
Owner

Thanks, that makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants