-
Notifications
You must be signed in to change notification settings - Fork 465
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
openvidu-browser: stopping tracks even if no initialized by OpenVidu #107
Comments
This is already included in a patch in the development master branch of OpenVidu Browser library. Will be available in the next release. |
And yes, that is the commit that included the change. |
solved in current master ✔️ |
Hi, Could you provide a sample code replicating the issue? This way we can assure the problem still exists and if so properly fix it. Thanks. |
It's not that easy to provide a mininmal working example, this one is showing the basic approach without the "token" magic which is done via WebSockets communication with a NodeJS backend in my case. Expected / wanted behaviour:
That way, I establish sessions only when required, but people are "on standby" with granted consent. Barebone example to show the issue (token magic missing!!!)
On disconnect, a lots of events are triggered (https://openvidu.io/docs/how-do-i/leave-session/) and one of them (streamDestroyed) kills the tracks regardless of the origin by calling disposeMediaStream:
Hope that helps to clarify the issue... |
Hi again, Can you please confirm the following behaviour?: If you subscribe to event
You can do that with a snippet like this: publisher.on('streamDestroyed', event => console.log('Event streamDestroyed dispatched by Publisher'); If it does, then we will add a fix to avoid the disposal of custom MediaStream objects |
Either way, the behaviour you stated in your sample code is not really the expected use of OpenVidu session objects. All OpenVidu connections to the session (one for each user) should be kept alive as long as the video conference is running. To unpublish a stream you should simply call Regards |
sorry, didn't find the time to dig into this. After Christmas, I'll update to 2.7.0 and recheck this one Agreed on your comment on the session, but those can be indeed different conferences - I do some kind of classroom m:n screensharing where students join a virtual room to show a screen on the digital whiteboard hosted by the teachers via browsers only, some kind of m:n approach. I want to keep the consent after the application got it once after login, so the screen share must keep "running". By not ending the sessions, i would have m*n sessions opened in the background :) |
Closing for inactivity |
I refactored the working example to keep the session. Expected behaviour: after unpublishing, the video should still be running. I can confirm that
shows up in the console and verified using the method you proposed. Below the new example using the openvidu demo servers to test "in real". BTW: it would be good to state somewhere in the docs that getDisplayMedia has a quite strict same-origin-policy. It seems not to be possible to call getDisplayMedia from a script which is from a different origin. As you see below in the example, I also tried to load OpenVidu from jsdeliver and this leads to
|
I have the same problem, but I fear that
makes the pattern above impossible. It is perfectly reasonable to setup local audio and video before entering the conference. Leaving the conference should not destroy MediaTracks which were created before entering. If it does it would be nice to have a A workaround requires much restructuring of the application: const publisher = OpenVidu.initPublisher(undefined, {
audioSource: localAudioTrack,
videoSource: localVideoTrack,
publishAudio: false,
publishVideo: false
});
openViduSession.connect(theAccessToken);
openViduSession.publish(publisher);
// …
// "enter" the conference
openViduSession.signal({data: "enter"});
publisher.publishAudio(true);
publisher.publishVideo(true);
// …
// "leave" the conference
openViduSession.signal({data: "leave"});
publisher.publishAudio(false);
publisher.publishVideo(false); to simulate entering and leaving the conference while the local MediaStreamTracks keep running. |
I patched my uncompressed distribution (Note that this is openvidu v. 2.11.0) Index: web_modules/openvidu-browser.js
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- web_modules/openvidu-browser.js (date 1597766287751)
+++ web_modules/openvidu-browser.js (date 1597766287751)
@@ -4904,15 +4904,17 @@
/**
* @hidden
*/
- Stream.prototype.disposeMediaStream = function () {
+ Stream.prototype.disposeMediaStream = function (shouldNotStopTracks) {
if (this.mediaStream) {
+ if (!shouldNotStopTracks) {
this.mediaStream.getAudioTracks().forEach(function (track) {
- track.stop();
+ track.stop();
});
this.mediaStream.getVideoTracks().forEach(function (track) {
- track.stop();
+ track.stop();
});
- delete this.mediaStream;
+ }
+ delete this.mediaStream;
}
console.info((!!this.outboundStreamOpts ? 'Local ' : 'Remote ') + "MediaStream from 'Stream' with id [" + this.streamId + '] is now disposed');
};
@@ -5946,7 +5948,9 @@
}
}
// Dispose the MediaStream local object
- this.stream.disposeMediaStream();
+ // see https://github.com/OpenVidu/openvidu/issues/107
+ this.stream.disposeMediaStream(true);
+
// Remove from DOM all video elements associated to this Stream, if there's a StreamManager defined
// (method Session.subscribe must have been called)
if (this.stream.streamManager) |
If a session disconnects, MediaTracks are stopped regarding of their origin. This also stops tracks coming from custom sources, i.e. a track is given to OpenVidu.initPublisher's videoSource
This breaks playing in video tags which should be kept also after OpenVidu stops.
The text was updated successfully, but these errors were encountered: