feat:优化代码
parent
71bbfca2dc
commit
7cea815888
|
@ -18,22 +18,22 @@ class TalkEventConstant
|
||||||
/**
|
/**
|
||||||
* 键盘输入事件通知 - 事件名
|
* 键盘输入事件通知 - 事件名
|
||||||
*/
|
*/
|
||||||
const EVENT_KEYBOARD = 'event_keyboard';
|
const EVENT_TALK_KEYBOARD = 'event_talk_keyboard';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户在线状态通知 - 事件名
|
* 用户在线状态通知 - 事件名
|
||||||
*/
|
*/
|
||||||
const EVENT_ONLINE_STATUS = 'event_online_status';
|
const EVENT_LOGIN = 'event_login';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 聊天消息撤销通知 - 事件名
|
* 聊天消息撤销通知 - 事件名
|
||||||
*/
|
*/
|
||||||
const EVENT_REVOKE_TALK = 'event_revoke_talk';
|
const EVENT_TALK_REVOKE = 'event_talk_revoke';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 好友申请消息通知 - 事件名
|
* 好友申请消息通知 - 事件名
|
||||||
*/
|
*/
|
||||||
const EVENT_FRIEND_APPLY = 'event_friend_apply';
|
const EVENT_CONTACT_APPLY = 'event_contact_apply';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
|
@ -42,10 +42,10 @@ class TalkEventConstant
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
self::EVENT_TALK => '对话消息通知',
|
self::EVENT_TALK => '对话消息通知',
|
||||||
self::EVENT_KEYBOARD => '键盘输入事件通知',
|
self::EVENT_TALK_KEYBOARD => '键盘输入事件通知',
|
||||||
self::EVENT_ONLINE_STATUS => '用户在线状态通知',
|
self::EVENT_LOGIN => '用户在线状态通知',
|
||||||
self::EVENT_REVOKE_TALK => '聊天消息撤销通知',
|
self::EVENT_TALK_REVOKE => '聊天消息撤销通知',
|
||||||
self::EVENT_FRIEND_APPLY => '好友申请消息通知'
|
self::EVENT_CONTACT_APPLY => '好友申请消息通知'
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ class WebSocketController implements OnMessageInterface, OnOpenInterface, OnClos
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$isOnline) {
|
if (!$isOnline) {
|
||||||
event()->dispatch(new TalkEvent(TalkEventConstant::EVENT_ONLINE_STATUS, [
|
event()->dispatch(new TalkEvent(TalkEventConstant::EVENT_LOGIN, [
|
||||||
'user_id' => $user_id,
|
'user_id' => $user_id,
|
||||||
'status' => 1,
|
'status' => 1,
|
||||||
]));
|
]));
|
||||||
|
@ -133,7 +133,7 @@ class WebSocketController implements OnMessageInterface, OnOpenInterface, OnClos
|
||||||
$isOnline = $this->client->isOnlineAll($user_id);
|
$isOnline = $this->client->isOnlineAll($user_id);
|
||||||
if ($isOnline) return;
|
if ($isOnline) return;
|
||||||
|
|
||||||
event()->dispatch(new TalkEvent(TalkEventConstant::EVENT_ONLINE_STATUS, [
|
event()->dispatch(new TalkEvent(TalkEventConstant::EVENT_LOGIN, [
|
||||||
'user_id' => $user_id,
|
'user_id' => $user_id,
|
||||||
'status' => 0,
|
'status' => 0,
|
||||||
]));
|
]));
|
||||||
|
|
|
@ -50,8 +50,6 @@ class RedisWebsocketSubscribe extends AbstractProcess
|
||||||
//echo PHP_EOL . "chan : $chan , msg : $message";
|
//echo PHP_EOL . "chan : $chan , msg : $message";
|
||||||
$data = json_decode($message, true);
|
$data = json_decode($message, true);
|
||||||
|
|
||||||
var_dump("subscribe ====> {$message}");
|
|
||||||
|
|
||||||
$this->handleService->handle($data);
|
$this->handleService->handle($data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ class ContactApplyService
|
||||||
// 判断对方是否在线。如果在线发送消息通知
|
// 判断对方是否在线。如果在线发送消息通知
|
||||||
$isOnline = di()->get(SocketClientService::class)->isOnlineAll($friend_id);
|
$isOnline = di()->get(SocketClientService::class)->isOnlineAll($friend_id);
|
||||||
if ($isOnline) {
|
if ($isOnline) {
|
||||||
event()->dispatch(new TalkEvent(TalkEventConstant::EVENT_FRIEND_APPLY, [
|
event()->dispatch(new TalkEvent(TalkEventConstant::EVENT_CONTACT_APPLY, [
|
||||||
'apply_id' => $result->id,
|
'apply_id' => $result->id,
|
||||||
'type' => 1,
|
'type' => 1,
|
||||||
]));
|
]));
|
||||||
|
@ -103,7 +103,7 @@ class ContactApplyService
|
||||||
// 判断对方是否在线。如果在线发送消息通知
|
// 判断对方是否在线。如果在线发送消息通知
|
||||||
$isOnline = di()->get(SocketClientService::class)->isOnlineAll($info->user_id);
|
$isOnline = di()->get(SocketClientService::class)->isOnlineAll($info->user_id);
|
||||||
if ($isOnline) {
|
if ($isOnline) {
|
||||||
event()->dispatch(new TalkEvent(TalkEventConstant::EVENT_FRIEND_APPLY, [
|
event()->dispatch(new TalkEvent(TalkEventConstant::EVENT_CONTACT_APPLY, [
|
||||||
'apply_id' => $apply_id,
|
'apply_id' => $apply_id,
|
||||||
'type' => 2,
|
'type' => 2,
|
||||||
]));
|
]));
|
||||||
|
|
|
@ -282,7 +282,6 @@ class GroupService extends BaseService
|
||||||
Db::commit();
|
Db::commit();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
Db::rollBack();
|
Db::rollBack();
|
||||||
var_dump($e->getMessage());
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ class ReceiveHandleService
|
||||||
// 消息事件绑定
|
// 消息事件绑定
|
||||||
const EVENTS = [
|
const EVENTS = [
|
||||||
TalkEventConstant::EVENT_TALK => 'onTalk',
|
TalkEventConstant::EVENT_TALK => 'onTalk',
|
||||||
TalkEventConstant::EVENT_KEYBOARD => 'onKeyboard',
|
TalkEventConstant::EVENT_TALK_KEYBOARD => 'onKeyboard',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -79,7 +79,7 @@ class ReceiveHandleService
|
||||||
*/
|
*/
|
||||||
public function onKeyboard($server, Frame $frame, $data)
|
public function onKeyboard($server, Frame $frame, $data)
|
||||||
{
|
{
|
||||||
event()->dispatch(new TalkEvent(TalkEventConstant::EVENT_KEYBOARD, [
|
event()->dispatch(new TalkEvent(TalkEventConstant::EVENT_TALK_KEYBOARD, [
|
||||||
'sender_id' => (int)$data['sender_id'],
|
'sender_id' => (int)$data['sender_id'],
|
||||||
'receiver_id' => (int)$data['receiver_id'],
|
'receiver_id' => (int)$data['receiver_id'],
|
||||||
]));
|
]));
|
||||||
|
|
|
@ -25,16 +25,16 @@ class SubscribeHandleService
|
||||||
TalkEventConstant::EVENT_TALK => 'onConsumeTalk',
|
TalkEventConstant::EVENT_TALK => 'onConsumeTalk',
|
||||||
|
|
||||||
// 键盘输入事件
|
// 键盘输入事件
|
||||||
TalkEventConstant::EVENT_KEYBOARD => 'onConsumeKeyboard',
|
TalkEventConstant::EVENT_TALK_KEYBOARD => 'onConsumeKeyboard',
|
||||||
|
|
||||||
// 用户在线状态事件
|
// 用户在线状态事件
|
||||||
TalkEventConstant::EVENT_ONLINE_STATUS => 'onConsumeOnlineStatus',
|
TalkEventConstant::EVENT_LOGIN => 'onConsumeOnlineStatus',
|
||||||
|
|
||||||
// 聊天消息推送事件
|
// 聊天消息推送事件
|
||||||
TalkEventConstant::EVENT_REVOKE_TALK => 'onConsumeRevokeTalk',
|
TalkEventConstant::EVENT_TALK_REVOKE => 'onConsumeRevokeTalk',
|
||||||
|
|
||||||
// 好友申请相关事件
|
// 好友申请相关事件
|
||||||
TalkEventConstant::EVENT_FRIEND_APPLY => 'onConsumeFriendApply'
|
TalkEventConstant::EVENT_CONTACT_APPLY => 'onConsumeFriendApply'
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -133,7 +133,7 @@ class SubscribeHandleService
|
||||||
{
|
{
|
||||||
$fds = $this->clientService->findUserFds($data['data']['receiver_id']);
|
$fds = $this->clientService->findUserFds($data['data']['receiver_id']);
|
||||||
|
|
||||||
$this->push($fds, $this->toJson(TalkEventConstant::EVENT_KEYBOARD, $data['data']));
|
$this->push($fds, $this->toJson(TalkEventConstant::EVENT_TALK_KEYBOARD, $data['data']));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -157,7 +157,7 @@ class SubscribeHandleService
|
||||||
|
|
||||||
$fds = array_unique(array_merge(...$fds));
|
$fds = array_unique(array_merge(...$fds));
|
||||||
|
|
||||||
$this->push($fds, $this->toJson(TalkEventConstant::EVENT_ONLINE_STATUS, [
|
$this->push($fds, $this->toJson(TalkEventConstant::EVENT_LOGIN, [
|
||||||
'user_id' => $user_id,
|
'user_id' => $user_id,
|
||||||
'status' => $status
|
'status' => $status
|
||||||
]));
|
]));
|
||||||
|
@ -188,7 +188,7 @@ class SubscribeHandleService
|
||||||
|
|
||||||
if (!$fds) return;
|
if (!$fds) return;
|
||||||
|
|
||||||
$this->push($fds, $this->toJson(TalkEventConstant::EVENT_REVOKE_TALK, [
|
$this->push($fds, $this->toJson(TalkEventConstant::EVENT_TALK_REVOKE, [
|
||||||
'talk_type' => $record->talk_type,
|
'talk_type' => $record->talk_type,
|
||||||
'sender_id' => $record->user_id,
|
'sender_id' => $record->user_id,
|
||||||
'receiver_id' => $record->receiver_id,
|
'receiver_id' => $record->receiver_id,
|
||||||
|
@ -234,7 +234,7 @@ class SubscribeHandleService
|
||||||
'mobile' => $friendInfo->mobile,
|
'mobile' => $friendInfo->mobile,
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->push(array_unique($fds), $this->toJson(TalkEventConstant::EVENT_FRIEND_APPLY, $msg));
|
$this->push(array_unique($fds), $this->toJson(TalkEventConstant::EVENT_CONTACT_APPLY, $msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function toJson(string $event, array $data): string
|
private function toJson(string $event, array $data): string
|
||||||
|
|
|
@ -213,7 +213,7 @@ class TalkService extends BaseService
|
||||||
$result->is_revoke = 1;
|
$result->is_revoke = 1;
|
||||||
$result->save();
|
$result->save();
|
||||||
|
|
||||||
event()->dispatch(new TalkEvent(TalkEventConstant::EVENT_REVOKE_TALK, [
|
event()->dispatch(new TalkEvent(TalkEventConstant::EVENT_TALK_REVOKE, [
|
||||||
'record_id' => $result->id
|
'record_id' => $result->id
|
||||||
]));
|
]));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue