How to Scan Fingerprints with Async PHP and React Native

  • In an amazing article on SitePoint, Christopher Pitt demonstrates how to create an async PHP server that can requests a fingerprint scan on the client side.
  • He uses React Native, WebSocket, an async PHP server, PHP preprocessing, … Really amazing stuff.
  • We will also set up an asynchronous HTTP server, with a web socket connection to the app.
  • We will follow this up by adding fingerprint scanning capabilities to the app, and asking for these fingerprint scans from the HTTP server.
  • Then we will build an endpoint through which GET requests can request a fingerprint scan and wait for one to occur.

In an amazing article on SitePoint, Christopher Pitt demonstrates how to create an async PHP server that can requests a fingerprint scan on the client side. He uses React Native, WebSocket, an async PHP server, PHP preprocessing, … Really amazing stuff.
Continue reading “How to Scan Fingerprints with Async PHP and React Native”

How to Scan Fingerprints with Async PHP and React Native — SitePoint

How to Scan Fingerprints with Async PHP and #reactnative  #reactjs

  • Our composer.json file could look something like:
    {
    “scripts”: {
    “dev”: “vendor/bin/aerys -d -c loader.php”,
    “prod”: “vendor/bin/aerys -c loader.php”
    },
    “require”: {
    “amphp/aerys”: “dev-amp_v2”,
    “pre/kitchen-sink”: “^0.1.0”
    },
    “autoload”: {
    “psr-4”: {
    “App\\”: “app”
    }
    },
    “config”: {
    “process-timeout”: 0
    },
    “minimum-stability”: “dev”,
    “prefer-stable”: true
    }

    This is from composer.json in the server project

    We can also set up a placeholder for requesting scans, along with an HTTP GET route to get to it:
    namespace App\Action;

    use Aerys\Request;
    use Aerys\Response;

    class ScanAction
    {
    public function __invoke(Request $request, Response $response)
    {
    $response-end(“requesting a scan…”);
    }
    }

    This is from app/Action/ScanAction.

  • pre in the server project

    use Aerys\Router;
    use App\Action\ScanAction;

    return (Router $router) = {
    $router-route(
    “GET”, “/scan”, new ScanAction
    );
    };

    This is from routes/web.

  • pre in the server project

    And we can start the server up with a server config file and pre-processor loader script:
    $port = 8080;

    $host = new $port);

    $host-use($router = Aerys\router());

    $web = process ‘http://127.0.0.1:{$port}’ | pbcopy”);

    This is from config.pre in the server project

    return Pre\processAndRequire(__DIR__ . “

  • Let’s add web sockets to our server:
    namespace App\Socket;

    use Aerys\Request;
    use Aerys\Response;
    use Aerys\Websocket;
    use Aerys\Websocket\Endpoint;
    use FingerprintSocket implements Websocket
    {
    private $endpoint;
    private $connections = [];

    public function onStart(Endpoint $endpoint)
    {
    $this-endpoint = $endpoint;
    }

    public function onHandshake(Request $request,
    Response $response)
    {
    // $origin = $request-getHeader(“origin”);
    //
    // if ($origin !

  • == “http://127.0.0.1:8080”) {
    // $response-setStatus(403);
    // $response-end(“origin not allowed”);
    // return null;
    // }

    $info = return $info[“client_addr”];
    }

    public function onOpen(int $clientId, $address)
    {
    $this-connections[$clientId] = $address;
    }

    public function onData(int $clientId, Message $message)
    {
    $body = yield $message;

    yield $this-endpoint-send(
    $payload, $clientId
    );
    }

    public function onClose(int $clientId,
    int $code, string $reason)
    {
    }

    public function onStop()
    {
    // nothing to see here…
    }
    }

    This is from in the server project

    use Aerys\Router;
    use App\Action\ScanAction;
    use (Router $router) = {
    $router-route(
    “GET”, “/scan”, new ScanAction
    );

    $router-route(
    “GET”, “/ws”, Aerys\websocket(new FingerprintSocket)
    );
    };

    This is from routes/web.

In this comprehensive and advanced tutorial, Chris shows us how to scan fingerprints with Async PHP and React Native. The future is here!
Continue reading “How to Scan Fingerprints with Async PHP and React Native — SitePoint”