mirror of https://github.com/OpenVidu/openvidu.git
Fix issue 107
parent
b55faf831b
commit
d40285ccc5
|
@ -189,6 +189,7 @@ export class OpenVidu {
|
|||
publishVideo: (typeof properties.publishVideo !== 'undefined') ? properties.publishVideo : true,
|
||||
resolution: this.isMediaStreamTrack(properties.videoSource) ? undefined : ((typeof properties.resolution !== 'undefined') ? properties.resolution : '640x480'),
|
||||
videoSource: (typeof properties.videoSource !== 'undefined') ? properties.videoSource : undefined,
|
||||
keepTracksOnDispose: (typeof properties.videoSource !== 'undefined') ? properties.keepTracksOnDispose : false,
|
||||
filter: properties.filter
|
||||
};
|
||||
} else {
|
||||
|
|
|
@ -74,7 +74,7 @@ export class Publisher extends StreamManager {
|
|||
constructor(targEl: string | HTMLElement, properties: PublisherProperties, openvidu: OpenVidu) {
|
||||
super(new Stream((!!openvidu.session) ? openvidu.session : new Session(openvidu), { publisherProperties: properties, mediaConstraints: {} }), targEl);
|
||||
this.properties = properties;
|
||||
this.openvidu = openvidu;
|
||||
this.openvidu = openvidu;
|
||||
|
||||
this.stream.ee.on('local-stream-destroyed', (reason: string) => {
|
||||
this.stream.isLocalStreamPublished = false;
|
||||
|
|
|
@ -117,6 +117,16 @@ export class Stream implements EventDispatcher {
|
|||
}
|
||||
} = {};
|
||||
|
||||
/**
|
||||
* Keeps tracks unstopped on disposal. Allows to keep tracks running if session is diposed
|
||||
*
|
||||
* This property may be useful if a publisher is started with a previously existing
|
||||
* track which should keep running after disposal, e.g. if you start your webcam
|
||||
* in a <video> element and want to keep it running after OpenVidu session closed
|
||||
*
|
||||
*/
|
||||
keepTracksOnDispose = false;
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
|
@ -205,6 +215,9 @@ export class Stream implements EventDispatcher {
|
|||
this.typeOfVideo = this.isSendScreen() ? 'SCREEN' : 'CAMERA';
|
||||
}
|
||||
}
|
||||
|
||||
this.keepTracksOnDispose = !!this.outboundStreamOpts.publisherProperties.keepTracksOnDispose;
|
||||
|
||||
if (!!this.outboundStreamOpts.publisherProperties.filter) {
|
||||
this.filter = this.outboundStreamOpts.publisherProperties.filter;
|
||||
}
|
||||
|
@ -360,7 +373,7 @@ export class Stream implements EventDispatcher {
|
|||
*/
|
||||
disposeWebRtcPeer(): void {
|
||||
if (this.webRtcPeer) {
|
||||
this.webRtcPeer.dispose();
|
||||
this.webRtcPeer.dispose(this.keepTracksOnDispose);
|
||||
}
|
||||
if (this.speechEvent) {
|
||||
this.speechEvent.stop();
|
||||
|
@ -376,12 +389,14 @@ export class Stream implements EventDispatcher {
|
|||
*/
|
||||
disposeMediaStream(): void {
|
||||
if (this.mediaStream) {
|
||||
this.mediaStream.getAudioTracks().forEach((track) => {
|
||||
track.stop();
|
||||
});
|
||||
this.mediaStream.getVideoTracks().forEach((track) => {
|
||||
track.stop();
|
||||
});
|
||||
if (!this.keepTracksOnDispose) {
|
||||
this.mediaStream.getAudioTracks().forEach((track) => {
|
||||
track.stop();
|
||||
});
|
||||
this.mediaStream.getVideoTracks().forEach((track) => {
|
||||
track.stop();
|
||||
});
|
||||
}
|
||||
delete this.mediaStream;
|
||||
}
|
||||
console.info((!!this.outboundStreamOpts ? 'Local ' : 'Remote ') + "MediaStream from 'Stream' with id [" + this.streamId + '] is now disposed');
|
||||
|
|
|
@ -88,4 +88,10 @@ export interface PublisherProperties {
|
|||
*/
|
||||
filter?: Filter;
|
||||
|
||||
/**
|
||||
* Whether to stop the published video tracks after disposal or to keep them (useful if you set your own track as videoSource and you need to keep it aftger disposal)
|
||||
* @default false
|
||||
*/
|
||||
keepTracksOnDispose? : boolean;
|
||||
|
||||
}
|
|
@ -101,7 +101,7 @@ export class WebRtcPeer {
|
|||
/**
|
||||
* This method frees the resources used by WebRtcPeer
|
||||
*/
|
||||
dispose() {
|
||||
dispose(keepTracksOnDispose = false) {
|
||||
console.debug('Disposing WebRtcPeer');
|
||||
try {
|
||||
if (this.pc) {
|
||||
|
@ -112,7 +112,7 @@ export class WebRtcPeer {
|
|||
this.localCandidatesQueue = [];
|
||||
|
||||
this.pc.getLocalStreams().forEach(str => {
|
||||
this.streamStop(str);
|
||||
this.streamStop(str, keepTracksOnDispose);
|
||||
});
|
||||
|
||||
// FIXME This is not yet implemented in firefox
|
||||
|
@ -244,9 +244,11 @@ export class WebRtcPeer {
|
|||
});
|
||||
}
|
||||
|
||||
private streamStop(stream: MediaStream): void {
|
||||
private streamStop(stream: MediaStream, keepTracksOnDispose = false): void {
|
||||
stream.getTracks().forEach(track => {
|
||||
track.stop();
|
||||
if (!keepTracksOnDispose) {
|
||||
track.stop();
|
||||
}
|
||||
stream.removeTrack(track);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue