forked from jxy918/swoft-game
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
501 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace App\Listener; | ||
|
||
namespace App\Listener; | ||
|
||
|
||
use App\Http\Controller\ValidatorController; | ||
use ReflectionException; | ||
use Swoft\Bean\Annotation\Mapping\Inject; | ||
use Swoft\Bean\Exception\ContainerException; | ||
use Swoft\Co; | ||
use Swoft\Consul\Agent; | ||
use Swoft\Consul\Exception\ClientException; | ||
use Swoft\Consul\Exception\ServerException; | ||
use Swoft\Event\Annotation\Mapping\Listener; | ||
use Swoft\Event\EventHandlerInterface; | ||
use Swoft\Event\EventInterface; | ||
use Swoft\Http\Server\HttpServer; | ||
use Swoft\Server\SwooleEvent; | ||
use Swoole\Coroutine; | ||
|
||
/** | ||
* Class TcpServerListener | ||
* | ||
* @since 2.0 | ||
* | ||
* @Listener(SwooleEvent::RECEIVE) | ||
*/ | ||
class TcpServerListener implements EventHandlerInterface | ||
{ | ||
/** | ||
* @Inject() | ||
* | ||
* @var Agent | ||
*/ | ||
private $agent; | ||
|
||
/** | ||
* @param EventInterface $event | ||
* | ||
* @throws ReflectionException | ||
* @throws ContainerException | ||
* @throws ClientException | ||
* @throws ServerException | ||
*/ | ||
public function handle(EventInterface $event): void | ||
{ | ||
/* @var HttpServer $httpServer */ | ||
$httpServer = $event->getTarget(); | ||
|
||
var_dump('----------------------------------------'); | ||
|
||
// $this->agent->deregisterService('swoft'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
/** | ||
* This file is part of Swoft. | ||
* | ||
* @link https://swoft.org | ||
* @document https://doc.swoft.org | ||
* @contact group@swoft.org | ||
* @license https://github.com/swoft-cloud/swoft/blob/master/LICENSE | ||
*/ | ||
|
||
namespace App\WebSocket; | ||
|
||
use Swoft\Http\Message\Request; | ||
use Swoft\Http\Message\Response; | ||
use Swoft\WebSocket\Server\Annotation\Mapping\OnClose; | ||
use Swoft\WebSocket\Server\Annotation\Mapping\OnHandshake; | ||
use Swoft\WebSocket\Server\Annotation\Mapping\OnOpen; | ||
use Swoft\WebSocket\Server\Annotation\Mapping\OnMessage; | ||
use Swoft\WebSocket\Server\Annotation\Mapping\WsModule; | ||
use Swoole\WebSocket\Frame; | ||
use Swoole\WebSocket\Server; | ||
use function server; | ||
use const WEBSOCKET_OPCODE_BINARY; | ||
|
||
|
||
/** | ||
* Class VedioModule | ||
* | ||
* @WsModule( | ||
* "/vedio" | ||
* ) | ||
*/ | ||
class VedioModule | ||
{ | ||
|
||
/** | ||
* 在这里你可以验证握手的请求信息 | ||
* @OnHandshake() | ||
* @param Request $request | ||
* @param Response $response | ||
* @return array [bool, $response] | ||
*/ | ||
public function checkHandshake(Request $request, Response $response): array | ||
{ | ||
return [true, $response]; | ||
} | ||
|
||
/** | ||
* @OnOpen() | ||
* @param Request $request | ||
* @param int $fd | ||
*/ | ||
public function onOpen(Request $request, int $fd): void | ||
{ | ||
echo "vedio connnected #{$fd}..."; | ||
|
||
} | ||
|
||
/** | ||
* @OnMessage() | ||
* @param Server $server | ||
* @param Frame $frame | ||
*/ | ||
public function onMessage(Server $server, Frame $frame) | ||
{ | ||
//广播消息 | ||
echo "vedio message #{$frame->fd}...data:".$frame->data."\n"; | ||
if(!is_numeric($frame->data)) { | ||
//如果是录像数据, 发送二进制数据 | ||
$ret = server()->sendToAll($frame->data, 0, 50); | ||
var_dump($ret); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* On connection closed | ||
* - you can do something. eg. record log | ||
* | ||
* @OnClose() | ||
* @param Server $server | ||
* @param int $fd | ||
*/ | ||
public function onClose(Server $server, int $fd): void | ||
{ | ||
//清除登陆信息变量 | ||
echo "vedio close #{$fd}..."; | ||
} | ||
} |
Oops, something went wrong.