Camera

Provides a consistent API to the camera on all platforms.

Accessing the camera is very easy across many devices. For privacy reasons, a browser requires users' consent before accessing the camera. It is strongly recommended that best practices are followed to give the users an optimal experience and increasing the engagement rate of your audience. (See here, for examples.)

Compatibility: Due to browser requirements, VideoStack is only able to access the camera on iOS 11 or later, and Android 6 or later.

Example

var cameraLayer = new VideoStack.CameraLayer();
cameraLayer.requestUserMedia(function() {});

var convenienceLayer = new VideoStack.ConvenienceLayer(cameraLayer, {
  outputResolution: [ 1024, 1024 ],
  context
});

var renderer = new VideoStack.AnimationLoop();
renderer.start(function() {
  convenienceLayer.render();
});

getUserMedia(onSuccess, onError, [options, context])

Dispatch request for user's camera feed

Argument Type Description
onSuccess Function Callback function that receives an object as an argument with its context bound to the optionally provided context argument.

  • function(e)
  • e.videoLayer {VideoLayer}
    An instance of a VideoLayer as described above, where the video source is the camera feed.
  • e.selfie {Boolean}
    Whether the feed comes from the selfie camera.
onError Function Callback function that receives an Error as an argument with its context bound to the optionally provided context argument.

  • function(err)
  • err {Error}
    Error provided for failure to attain video feed.

options Object Object describing requested constraints on camera feed (optional). (Note: these requests are not guaranteed to be followed, as browser implementations vary.)

  • options.autoplay {Boolean}
    Whether video feed autoplays.
  • options.selfie {Boolean}
    Whether selfie camera should be used.
  • options.dimensions['width', 'height'] {Number}
    Requested dimensions of camera feed.
context Object Context in which to invoke the callback (optional).