Skip to content

Safeguard against a potential resource leak(media streams) due to user missuse  #561

@bmsan

Description

@bmsan

Description

Users improperly using videojs-record with external triggers(user defined buttons) might call
player.record().getDevice(); multiple times before trying to use stopDevice().
In this case multiple media streams would get created but only the last one would be freed when calling stopDevice()
The implication would be that the webcam would remain on even after stopDevice() is called.

When would this situation be encountered?

Eg: let's say the user creates an external button "start webcam" which calls getDevice, 
but doesn't handle thoroughly the state of the system to see if it is actually ok to call getDevice. 
Someone visiting the website might press that button multiple times 
(maybe he doesn't notice the the request for video/audio permissions) after the first press.

Potential way to add an extra safeguard

Before

//videojs.record.js
value: function onDeviceReady(stream) {
....
// At this point this.stream could already be initialized,
// if the user didn't properly dispose of it the resource would never be released.
// ( the webcam would remain on after player.record().stopDevice() ).
this.stream = stream;

With a safeguard things could look something like:

//videojs.record.js
value: function onDeviceReady(stream) {
....
 if stream_is_initialized(this) {
    this.stream.getTracks().forEach(track => track.stop());
}
this.stream = stream;

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions