123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\webscoket;
- use app\services\user\UserServices;
- use qiniu\utils\Arr;
- use think\facade\Log;
- /**
- * socket 事件基础类
- * Class BaseHandler
- * @package app\webscoket
- */
- abstract class BaseHandler
- {
- /**
- * @var Manager
- */
- protected $manager;
- /**
- * @var Room
- */
- protected $room;
- /**
- * @var int
- */
- protected $fd;
- /**
- * 用户聊天端
- * @var int|null
- */
- protected $formType;
- /**
- * 登陆
- * @param array $data
- * @param Response $response
- * @return mixed
- */
- abstract public function login(array $data, Response $response);
- /**
- * 事件入口
- * @param $event
- * @return null |null
- */
- public function handle($event)
- {
- [$method, $result, $manager, $room] = $event;
- $this->manager = $manager;
- $this->room = $room;
- $this->fd = array_shift($result);
- $this->formType = array_shift($result);
- if (method_exists($this, $method)) {
- if ($method == 'login' && is_string($result[0])) {
- $result[0] = ['token' => $result[0]];
- }
- return $this->{$method}(...$result);
- } else {
- Log::error('socket 回调事件' . $method . '不存在,消息内容为:' . json_encode($result));
- return null;
- }
- }
- /**
- * 聊天事件
- * @param array $data
- * @param Response $response
- */
- abstract public function chat(array $data, Response $response);
- /**
- * 切换用户聊天
- * @param array $data
- * @param Response $response
- */
- abstract public function to_chat(array $data, Response $response);
- /**
- * 测试原样返回
- * @param array $data
- * @param Response $response
- * @return bool|\think\response\Json|null
- */
- public function test(array $data, Response $response)
- {
- return $response->success($data);
- }
- /**
- * 关闭连接触发
- * @param array $data
- * @param Response $response
- */
- public function close(array $data, Response $response)
- {
- $uid = $data['uid'] ?? 0;
- if ($uid) {
- }
- }
- }
|