迁移游戏延迟初始化脚本
This commit is contained in:
@@ -39,6 +39,7 @@ export {
|
|||||||
} from "./chat-room/baccarat-loss-cover-admin.js";
|
} from "./chat-room/baccarat-loss-cover-admin.js";
|
||||||
export { bindBaccaratLossCoverControls } from "./chat-room/baccarat-loss-cover.js";
|
export { bindBaccaratLossCoverControls } from "./chat-room/baccarat-loss-cover.js";
|
||||||
export { bindGameHallControls } from "./chat-room/game-hall.js";
|
export { bindGameHallControls } from "./chat-room/game-hall.js";
|
||||||
|
export { bindGameBootstrapControls, deferChatGameBootstrap } from "./chat-room/game-bootstrap.js";
|
||||||
export { bindGamePanelControls } from "./chat-room/game-panels.js";
|
export { bindGamePanelControls } from "./chat-room/game-panels.js";
|
||||||
export { bindHolidayModalControls, openHolidayRunFromSystemMessage } from "./chat-room/holiday-modal.js";
|
export { bindHolidayModalControls, openHolidayRunFromSystemMessage } from "./chat-room/holiday-modal.js";
|
||||||
export {
|
export {
|
||||||
@@ -121,6 +122,7 @@ import {
|
|||||||
} from "./chat-room/baccarat-loss-cover-admin.js";
|
} from "./chat-room/baccarat-loss-cover-admin.js";
|
||||||
import { bindBaccaratLossCoverControls } from "./chat-room/baccarat-loss-cover.js";
|
import { bindBaccaratLossCoverControls } from "./chat-room/baccarat-loss-cover.js";
|
||||||
import { bindGameHallControls } from "./chat-room/game-hall.js";
|
import { bindGameHallControls } from "./chat-room/game-hall.js";
|
||||||
|
import { bindGameBootstrapControls, deferChatGameBootstrap } from "./chat-room/game-bootstrap.js";
|
||||||
import { bindGamePanelControls } from "./chat-room/game-panels.js";
|
import { bindGamePanelControls } from "./chat-room/game-panels.js";
|
||||||
import { bindHolidayModalControls, openHolidayRunFromSystemMessage } from "./chat-room/holiday-modal.js";
|
import { bindHolidayModalControls, openHolidayRunFromSystemMessage } from "./chat-room/holiday-modal.js";
|
||||||
import {
|
import {
|
||||||
@@ -214,6 +216,8 @@ if (typeof window !== "undefined") {
|
|||||||
closeCurrentBaccaratLossCoverEvent,
|
closeCurrentBaccaratLossCoverEvent,
|
||||||
bindBaccaratLossCoverControls,
|
bindBaccaratLossCoverControls,
|
||||||
bindGameHallControls,
|
bindGameHallControls,
|
||||||
|
bindGameBootstrapControls,
|
||||||
|
deferChatGameBootstrap,
|
||||||
bindGamePanelControls,
|
bindGamePanelControls,
|
||||||
bindHolidayModalControls,
|
bindHolidayModalControls,
|
||||||
openHolidayRunFromSystemMessage,
|
openHolidayRunFromSystemMessage,
|
||||||
@@ -298,6 +302,7 @@ if (typeof window !== "undefined") {
|
|||||||
window.bankShowMsg = bankShowMsg;
|
window.bankShowMsg = bankShowMsg;
|
||||||
window.closeBankModal = closeBankModal;
|
window.closeBankModal = closeBankModal;
|
||||||
window.fetchBankRanking = fetchBankRanking;
|
window.fetchBankRanking = fetchBankRanking;
|
||||||
|
window.deferChatGameBootstrap = deferChatGameBootstrap;
|
||||||
window.openBankModal = openBankModal;
|
window.openBankModal = openBankModal;
|
||||||
window.switchBankTab = switchBankTab;
|
window.switchBankTab = switchBankTab;
|
||||||
window.toggleBankRankSort = toggleBankRankSort;
|
window.toggleBankRankSort = toggleBankRankSort;
|
||||||
@@ -321,6 +326,7 @@ if (typeof window !== "undefined") {
|
|||||||
bindBaccaratLossCoverAdminControls();
|
bindBaccaratLossCoverAdminControls();
|
||||||
bindBaccaratLossCoverControls();
|
bindBaccaratLossCoverControls();
|
||||||
bindGameHallControls();
|
bindGameHallControls();
|
||||||
|
bindGameBootstrapControls();
|
||||||
bindGamePanelControls();
|
bindGamePanelControls();
|
||||||
bindHolidayModalControls();
|
bindHolidayModalControls();
|
||||||
bindBankControls();
|
bindBankControls();
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
// 聊天室游戏延迟初始化工具,避免非关键游戏逻辑抢占首屏渲染资源。
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 延迟执行非关键游戏初始化。
|
||||||
|
*
|
||||||
|
* @param {Function} callback
|
||||||
|
* @param {number} [timeout]
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
export function deferChatGameBootstrap(callback, timeout = 2500) {
|
||||||
|
if (typeof callback !== "function") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("requestIdleCallback" in window) {
|
||||||
|
window.requestIdleCallback(callback, { timeout });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
window.setTimeout(callback, Math.min(timeout, 1200));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 暴露游戏延迟初始化入口给存量游戏面板脚本。
|
||||||
|
*
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
export function bindGameBootstrapControls() {
|
||||||
|
if (typeof window === "undefined") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
window.deferChatGameBootstrap = deferChatGameBootstrap;
|
||||||
|
}
|
||||||
@@ -214,26 +214,7 @@
|
|||||||
@include('chat.partials.daily-sign-in-modal')
|
@include('chat.partials.daily-sign-in-modal')
|
||||||
|
|
||||||
{{-- ═══════════ 游戏面板(partials/games/ 子目录,各自独立,包含 CSS + HTML + JS) ═══════════ --}}
|
{{-- ═══════════ 游戏面板(partials/games/ 子目录,各自独立,包含 CSS + HTML + JS) ═══════════ --}}
|
||||||
<script>
|
{{-- deferChatGameBootstrap 已迁移到 resources/js/chat-room/game-bootstrap.js --}}
|
||||||
/**
|
|
||||||
* 延迟执行非关键游戏初始化,避免首屏聊天室渲染时同时抢占网络和主线程。
|
|
||||||
*
|
|
||||||
* @param {Function} callback 初始化回调
|
|
||||||
* @param {number} timeout 最长等待时间
|
|
||||||
*/
|
|
||||||
window.deferChatGameBootstrap = function(callback, timeout = 2500) {
|
|
||||||
if (typeof callback !== 'function') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ('requestIdleCallback' in window) {
|
|
||||||
window.requestIdleCallback(callback, { timeout });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
window.setTimeout(callback, Math.min(timeout, 1200));
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
@include('chat.partials.games.baccarat-panel')
|
@include('chat.partials.games.baccarat-panel')
|
||||||
@include('chat.partials.games.slot-machine')
|
@include('chat.partials.games.slot-machine')
|
||||||
@include('chat.partials.games.mystery-box')
|
@include('chat.partials.games.mystery-box')
|
||||||
|
|||||||
Reference in New Issue
Block a user