PHP code example of huang-yi / shadowfax
1. Go to this page and download the library: Download huang-yi/shadowfax library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
huang-yi / shadowfax example snippets
$app->register(HuangYi\Shadowfax\ShadowfaxServiceProvider::class);
namespace App\WebSocket;
use Illuminate\Http\Request;
use HuangYi\Shadowfax\Contracts\WebSocket\Connection;
use HuangYi\Shadowfax\Contracts\WebSocket\Handler;
use HuangYi\Shadowfax\Contracts\WebSocket\Message;
class EchoServer implements Handler
{
/**
* Handler for open event.
*
* @param \HuangYi\Shadowfax\Contracts\WebSocket\Connection $connection
* @param \Illuminate\Http\Request $request
* @return mixed
*/
public function onOpen(Connection $connection, Request $request)
{
$connection->send('connected');
}
/**
* Handler for message event.
*
* @param \HuangYi\Shadowfax\Contracts\WebSocket\Connection $connection
* @param \HuangYi\Shadowfax\Contracts\WebSocket\Message $message
* @return mixed
*/
public function onMessage(Connection $connection, Message $message)
{
$connection->send($message->getData());
}
/**
* Handler for close event.
*
* @param \HuangYi\Shadowfax\Contracts\WebSocket\Connection $connection
* @return mixed
*/
public function onClose(Connection $connection)
{
$connection->send('closed');
}
}
use App\WebSocket\EchoServer;
use HuangYi\Shadowfax\Facades\WebSocket;
WebSocket::listen('/echo', new EchoServer);
shell
php artisan shadowfax:publish