Skip to content

CanvasRenderingContext2D.prototype.drawImage is now asynchronous #676

@NAllred91

Description

@NAllred91

YOU MUST read first!

Please use Community Forum for general technical discussions and questions.

  • I have used Google with the error message or bug in association with the library and Cordova words to make sure the issue I'm reporting is only related to iOSRTC.
  • I have provided steps to reproduce (e.g. using sample app code https://github.com/cordova-rtc/cordova-plugin-iosrtc-sample or updated extra/renderer-and-libwebrtc-tests.js file).
  • I have provided versions of third party library name, ios, Xcode and plugin version and adapter.js version if used.

Note: If the checkboxes above are not checked (which you do after the issue is posted), the issue will be closed, removing this checkbox will result in automatic closed issue.

Versions affected

  • Cordova version (e.g 7.1.0): 10.0.0
  • Cordova iOS version (e.g 5.1.0): 6.2.0
  • Plugin version (e.g 6.0.12): 6.0.20
  • iOS version (e.g 10.2): 13
  • Xcode version (e.g 11.1 - 11A1027): 12.4

Description

The following patch of CanvasRenderingContext2D.prototype.drawImage has made drawImage asynchronous. This presents a problem when you want to call getImageData immediately after drawImage. Using a setTimeout to call getImageData will kind of work, but it might be better if drawImage returned a promise after it has been patched?

Referenced comment

6.0.15 support CanvasRenderingContext2D.drawImage on VideoElement with iosrtc MediaStream

03e4a0d

// 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);
		        drawImage.apply(context, args);
		    });
		    img.setAttribute("src", "data:image/jpg;base64," + data);
	  	});
	} else {
		return drawImage.apply(context, args);
	}

Originally posted by @hthetiot in #116 (comment)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions