| | |
| | | /* |
| | | * @Author: your name |
| | | * @Date: 2021-12-24 10:26:10 |
| | | * @LastEditTime: 2021-12-24 17:11:44 |
| | | * @LastEditTime: 2021-12-24 17:21:42 |
| | | * @LastEditors: Please set LastEditors |
| | | * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE |
| | | * @FilePath: /hy-websocket/app/Controller/WebsocketController.php |
| | |
| | | use Hyperf\Contract\OnCloseInterface; |
| | | use Hyperf\Contract\OnMessageInterface; |
| | | use Hyperf\Contract\OnOpenInterface; |
| | | use Hyperf\Contract\OnHandShakeInterface; |
| | | use Hyperf\Utils\Codec\Json; |
| | | use Swoole\Http\Request; |
| | | use Swoole\Http\Response; |
| | | use Swoole\WebSocket\Frame; |
| | | use Swoole\WebSocket\Server; |
| | | use Hyperf\Redis\Redis; |
| | | use Hyperf\Di\Annotation\Inject; |
| | | use Hyperf\Config\Annotation\Value; |
| | | use App\Utils\guid; |
| | | use App\Utils\HashMap; |
| | | use App\Utils\Http; |
| | | use App\Utils\PcmToWave; |
| | | use App\Service\TransferService; |
| | | use Psr\Container\ContainerInterface; |
| | | use Hyperf\Logger\LoggerFactory; |
| | | use Hyperf\Contract\ConfigInterface; |
| | | class WebsocketController implements OnMessageInterface, OnOpenInterface, OnCloseInterface |
| | |
| | | * @var TransferService |
| | | */ |
| | | private $transferService; |
| | | /** |
| | | * |
| | | * @Inject |
| | | * @var HashMap |
| | | */ |
| | | private $HashMap; |
| | | //存放音频写入句柄 |
| | | /** |
| | | * |
| | | * @var \Psr\Log\LoggerInterface |
| | |
| | | $this->__handlePropertyHandler(__CLASS__); |
| | | // 第一个参数对应日志的 name, 第二个参数对应 config/autoload/logger.php 内的 key |
| | | $this->logger = $loggerFactory->get('log', 'default'); |
| | | //获取 server.php 里的内容 |
| | | $this->server_config = $this->config->get('server.servers', ''); |
| | | $this->allow_ip = $this->server_config[0]['allow_ip']; |
| | | $this->allow_ip = $this->config->get('allow_ip', ''); |
| | | } |
| | | public function onClose($server, int $fd, int $reactorId) : void |
| | | { |
| | |
| | | $action = substr($url, strrpos($url, "/") + 1); |
| | | switch ($action) { |
| | | case "reg": |
| | | $this->logger->info('reg', $frameData); |
| | | $groupId = $data['group_id']; |
| | | $session = $data['session_id']; |
| | | $this->bind($groupId, '', $frame->fd); |
| | |
| | | $server->push($frame->fd, json_encode($ret)); |
| | | break; |
| | | case "data": |
| | | $this->logger->info('data', $frameData); |
| | | $groupId = $data['group_id']; |
| | | $ret['event'] = "data"; |
| | | $ret['data'] = $data; |