{"size": 2456, "ext": "js", "max_stars_repo_path": "src/minicap_process.js", "max_stars_repo_name": "opersys/remote-interface", "max_stars_repo_stars_event_min_datetime": "2016-05-26T06:13:10.000Z", "max_stars_repo_stars_event_max_datetime": "2019-01-10T04:04:20.000Z", "max_issues_repo_path": "src/minicap_process.js", "max_issues_repo_name": "opersys/remote-interface", "max_issues_repo_issues_event_min_datetime": "2017-04-06T19:37:33.000Z", "max_issues_repo_issues_event_max_datetime": "2017-04-06T19:37:33.000Z", "max_forks_repo_path": "src/minicap_process.js", "max_forks_repo_name": "opersys/remote-interface", "max_forks_repo_forks_event_min_datetime": "2017-03-11T13:41:14.000Z", "max_forks_repo_forks_event_max_datetime": "2020-01-07T02:37:45.000Z"}
{"max_stars_count": 6, "max_issues_count": 1, "max_forks_count": 3, "avg_line_length": 31.4871794872, "max_line_length": 99, "alphanum_fraction": 0.6567589577}
/*
 * Copyright (C) 2015-2016 Opersys inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

var util = require("util");
var path = require("path");
var fs = require("fs");
var uuid = require("uuid");

var props = require("./props.js");
var DaemonProcess = require("./daemon_process.js");
var debug = require("debug")("RI.Proc.Minicap");

var Minicap = function (props) {
    DaemonProcess.call(this, ["minicap"]);
    this._props = props;
};

util.inherits(Minicap, DaemonProcess);

Minicap.prototype.socketName = function () {
    return this._socketName;
};

Minicap.prototype._arguments = function (initialSize, currentSize, currentRotation, argsCallback) {
    var self = this;
    var abi = this._props["ro.product.cpu.abi"];
    var sdk = this._props["ro.build.version.sdk"];
    var rel = this._props["ro.build.version.release"];
    var bin, libdir, exec;

    bin = sdk >= 16 ? "minicap" : "minicap-nopie";
    var args = [
        "-d", "0",
        "-S",
        "-n", self._socketName,
        "-P", initialSize.x + "x" + initialSize.y +
        "@" + currentSize.x + "x" + currentSize.y + "/" + currentRotation
    ];

    libdir = path.join(process.cwd(), "_bin", "minicap", "android-" + rel, abi);

    if (!fs.existsSync(libdir))
        libdir = path.join(process.cwd(), "_bin", "minicap", "android-" + sdk, abi);

    process.env["LD_LIBRARY_PATH"] = libdir;
    this._debug("LD_LIBRARY_PATH = " + libdir);

    exec = path.join(process.cwd(), "_bin", "minicap", abi, bin);
    argsCallback(exec, args);
};

Minicap.prototype.startCapture = function (initialSize, currentSize, currentRotation) {
    var self = this;

    DaemonProcess.prototype.start.apply(this);

    this._socketName = uuid.v1();

    self._arguments(initialSize, currentSize, currentRotation, function (exec, args) {
        var fullArgs = args.concat(["-n", self._socketName]);
        self._start(exec, fullArgs);
    });
};

module.exports = Minicap;