etro-node
Version:
A wrapper to run Etro in Node
45 lines (43 loc) • 1.37 kB
HTML
<html>
<head>
<script src="../node_modules/etro/dist/etro.js"></script>
<script>
(function () {
function readBlob (blob) {
return new Promise(function(resolve, reject) {
var fileReader = new FileReader()
fileReader.readAsArrayBuffer(blob)
fileReader.onerror = reject
fileReader.onload = function() {
// Convert to array (otherwise, it won't be sent to node correctly).
var typedArray = new Uint8Array(fileReader.result)
var array = Array.prototype.slice.call(typedArray)
resolve(array)
}
})
}
// Until Etro supports exporting streams, use this custom method.
/**
* Exports the movie as a byte array
* The reason for this method is that passing blobs to node causes problems,
* so we pass the raw byte array of the movie to node.
*
* @return {Promise<number[]>} the byte array
*/
etro.Movie.prototype.recordRaw = function () {
var that = this
var args = arguments
return new Promise(function (resolve, reject) {
etro.Movie.prototype.record.apply(that, args)
.then(function (blob) {
readBlob(blob).then(resolve)
})
})
}
})()
</script>
</head>
<body>
</body>
</html>