Exemplo n.º 1
0
    ob_start();
    imagegif($im);
    imagedestroy($im);
    return ob_get_clean();
}
function sendEmptyFrameAfter($gifServer)
{
    return function ($request, $response) use($gifServer) {
        $gifServer($request, $response);
        $gifServer->addFrame(createGifFrame(['']));
    };
}
$loop = React\EventLoop\Factory::create();
$socket = new React\Socket\Server($loop);
$http = new React\Http\Server($socket);
$gifServer = new React\Gifsocket\Server($loop);
$messages = [];
$addMessage = function ($message) use($gifServer, &$messages) {
    $messages[] = $message;
    if (count($messages) > 18) {
        $messages = array_slice($messages, count($messages) - 18);
    }
    $frame = createGifFrame($messages);
    $gifServer->addFrame($frame);
};
$stdin = new React\Stream\Stream(STDIN, $loop);
$stdin->on('data', function ($data) use($addMessage) {
    $messages = explode("\n", trim($data));
    foreach ($messages as $message) {
        $addMessage($message);
    }
Exemplo n.º 2
0
    ob_start();
    imagegif($im);
    imagedestroy($im);
    return ob_get_clean();
}
function sendEmptyFrameAfter($gifServer)
{
    return function ($request, $response) use($gifServer) {
        $gifServer($request, $response);
        $gifServer->addFrame(createGifFrame(['']));
    };
}
$loop = React\EventLoop\Factory::create();
$socket = new React\Socket\Server($loop);
$http = new React\Http\Server($socket);
$gifServer = new React\Gifsocket\Server($loop);
$messages = [];
$addMessage = function ($message) use($gifServer, &$messages) {
    $messages[] = $message;
    if (count($messages) > 18) {
        $messages = array_slice($messages, count($messages) - 18);
    }
    $frame = createGifFrame($messages);
    $gifServer->addFrame($frame);
};
$router = new React\Gifsocket\Router(['/socket.gif' => sendEmptyFrameAfter($gifServer), '/' => function ($request, $response) use($loop) {
    $response->writeHead(200, ['Content-Type' => 'text/html']);
    $fd = fopen(__DIR__ . '/views/index.html', 'r');
    $template = new React\Stream\Stream($fd, $loop);
    $template->pipe($response);
}, '/message' => function ($request, $response) use($addMessage) {