Skip to content

Commit

Permalink
Implement CanvasRenderingContext2D.prototype.drawImage SHIM to suppor…
Browse files Browse the repository at this point in the history
…t video to canvas capture
  • Loading branch information
hthetiot committed Oct 17, 2020
1 parent c0bfa9a commit 03e4a0d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions js/iosrtc.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,25 @@ function registerGlobals(doNotRestoreCallbacksSupport) {
window.MediaStream = MediaStream;
window.webkitMediaStream = MediaStream;
window.MediaStreamTrack = MediaStreamTrack;

// Apply CanvasRenderingContext2D.drawImage monkey patch
var drawImage = CanvasRenderingContext2D.prototype.drawImage;
CanvasRenderingContext2D.prototype.drawImage = function (arg) {
var args = Array.prototype.slice.call(arguments);
var context = this;
if (arg instanceof HTMLVideoElement && arg.render) {
arg.render.save(function (data) {
var img = new window.Image();
img.addEventListener("load", function () {
args.splice(0, 1, img.src);
drawImage.apply(context, args);
});
img.setAttribute("src", "data:image/jpg;base64," + data);
});
} else {
return drawImage.apply(context, args);
}
};
}

function dump() {
Expand Down

1 comment on commit 03e4a0d

@calebboyd
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hthetiot Replying to: #586 (comment)

Looks good to me. Gosh the canvas APIs are bad...
The only downside to this is that potentially large backpressure could be created by the caller since we're swallowing the callback to a slow bridge call (70-80ms based on the loud cordova log instrumentation).

Please sign in to comment.