I have a canvas that I want to have it's stream and send it to another user by webrtc. I can get the stream of it and show that in video tag.
var canvas = document.createElement("CANVAS");
var stream = canvas.captureStream(25);
var track = stream.getVideoTracks()[0];
console.log(track);
As you can see in track Object there is a property named canvas. It causes an Error in my code because I use a library that need a MediaStreamTrack not MediaStreamTrack that contains a canvas property.
Is there a way to get rid of that canvas property?
I've already tried delete the property but it didn't work. And also I used this below code but still doesn't work.
var canvas = document.createElement("CANVAS");
var stream = canvas.captureStream(25);
var track = stream.getVideoTracks()[0];
var {canvas, ...rest} = track;
console.log(canvas);
console.log(rest);
I think the CanvasCaptureMediaStreamTrack is a readOnly variable.
What can I do?
It would probably be good to update your library, because if it fails because of that added property, it will fail again some time in the future when new properties will be added to this interface.
You can overwrite this property and set it to
undefined, usingObject.defineProperty:You can delete this property on the
CanvasCaptureMediaStreamTrackprototype (and thus remove it from all instances):You could even pass a Proxy instead,
But really, that you have to resort on this is just very bad smell. For one I highly doubt that your library will work with current Firefox which still uses a deprecated
CanvasCaptureMediaStreaminterface instead of theCanvasCaptureMediaStreamTrackone.And if you really need to convert a
CanvasCaptureMediaStreamTrackto a bareMediaStreamTrack, then you can make the browser work twice as needed: