修复:全员清屏广播不生效
- ScreenCleared 改用 ShouldBroadcastNow 绕过队列,避免 Horizon 未重启问题 - Echo 监听移入 DOMContentLoaded + 500ms 重试,确保 window.Echo 就绪后再注册 - 添加 console.log 便于调试
This commit is contained in:
@@ -14,11 +14,11 @@ namespace App\Events;
|
||||
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class ScreenCleared implements ShouldBroadcast
|
||||
class ScreenCleared implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
|
||||
@@ -514,10 +514,16 @@
|
||||
document.getElementById('room-title-display').innerText = e.detail.title;
|
||||
});
|
||||
|
||||
// ── 管理员全员清屏事件(直接用 Echo 监听,不依赖编译产物) ───────
|
||||
if (window.Echo) {
|
||||
// ── 管理员全员清屏事件(等待 Echo 就绪后监听) ───────
|
||||
function setupScreenClearedListener() {
|
||||
if (!window.Echo || !window.chatContext) {
|
||||
// Echo 或 chatContext 还没就绪,延迟重试
|
||||
setTimeout(setupScreenClearedListener, 500);
|
||||
return;
|
||||
}
|
||||
window.Echo.join(`room.${window.chatContext.roomId}`)
|
||||
.listen('ScreenCleared', (e) => {
|
||||
console.log('收到全员清屏事件:', e);
|
||||
const operator = e.operator;
|
||||
|
||||
// 清除公聊窗口(say1)所有消息
|
||||
@@ -550,7 +556,10 @@
|
||||
say1.scrollTop = say1.scrollHeight;
|
||||
}
|
||||
});
|
||||
console.log('ScreenCleared 监听器已注册');
|
||||
}
|
||||
// DOMContentLoaded 后启动,确保 Vite 编译的 JS 已加载
|
||||
document.addEventListener('DOMContentLoaded', setupScreenClearedListener);
|
||||
|
||||
// ── 发送消息(Enter 发送) ───────────────────────
|
||||
document.getElementById('content').addEventListener('keydown', function(e) {
|
||||
|
||||
Reference in New Issue
Block a user