85 lines
2.8 KiB
PHP
85 lines
2.8 KiB
PHP
<?php
|
|
$inputserver_sock = null;
|
|
$inputserver_ref = null;
|
|
$inputclients = null;
|
|
$inputserver_sock = null;
|
|
class InputDeviceServices
|
|
{
|
|
|
|
function loadInst()
|
|
{
|
|
static $inst = null;
|
|
|
|
if ($inst === null) {
|
|
$inst = new self;
|
|
}
|
|
return $inst;
|
|
}
|
|
|
|
function module_loaded()
|
|
{
|
|
self::API_Register();
|
|
return true;
|
|
}
|
|
|
|
function API_Register()
|
|
{
|
|
apiql::register("!OPEN/!INPUT/!SERVER[json]", "InputDeviceServices::InputServer");
|
|
apiql::register("!CLOSE/!INPUT/!SERVER","InputDeviceServices::CloseInputServer");
|
|
apiql::register("!CONNECT/!INPUT/!DEVICES[json]", "InputDeviceServices::Connect");
|
|
apiql::register("!DISCONNECT/!INPUT/!DEVICES","InputDeviceServices::Disconnect");
|
|
}
|
|
|
|
function CloseInputServer($sql)
|
|
{
|
|
global $inputserver_ref;
|
|
global $inputserver_sock;
|
|
$inputserver_sock->shutdown();
|
|
$inputserver_ref->terminate();
|
|
return true;
|
|
}
|
|
|
|
function InputServer($sql)
|
|
{
|
|
echo(var_dump($sql));
|
|
global $loop;
|
|
global $clients;
|
|
global $inputserver_ref;
|
|
global $inputserver_sock;
|
|
global $inputclients;
|
|
$keyboard = $sql['SERVER']['keyboard'];
|
|
$mouse = $sql['SERVER']['mouse'];
|
|
$inputserver_ref = new React\ChildProcess\Process('exec /opt/uinput-mapper/input-read '.$keyboard.' -G '.$mouse);
|
|
$inputserver_ref->on('exit', function($exitCode, $termSignal) {
|
|
|
|
});
|
|
$inputserver_sock = new React\Socket\Server($loop);
|
|
$inputclients = new SplObjectStorage();
|
|
$i = 0;
|
|
$inputserver_sock->on('connection', function($connection) use ($inputclients, &$i) {
|
|
LogEcho("Connection to Event Server.","UINPUT");
|
|
$connection->id = ++$i;
|
|
|
|
$inputclients->attach($connection);
|
|
});
|
|
$inputserver_sock->listen("5055", "0.0.0.0");
|
|
LogEcho("Event server started on port 5055", "UINPUT");
|
|
$loop->addTimer(0.001, function($timer) use ($inputserver_ref) {
|
|
$inputserver_ref->stdout->on('data', function($output) {
|
|
global $inputclients;
|
|
foreach($inputclients as $client)
|
|
{
|
|
$client->write($output);
|
|
}
|
|
});
|
|
});
|
|
$inputserver_ref->start($loop);
|
|
$ResponseArray = array("response_type"=>"success",
|
|
"response_msg"=>"Event server started on port 5055",
|
|
"event_server_code"=>"EVT_200",
|
|
"event_server_port"=>5055);
|
|
return json_encode($ResponseArray);
|
|
}
|
|
|
|
|
|
} |