
<script src="<?php echo e(socketurl('/socket.io/socket.io.js')); ?>" defer></script>
<script>
    (function () {
        if (window.socket) { return; }   // include ซ้ำในหน้าเดียวกันก็ไม่ต่อซ้ำ

        var pendingEmits = [];
        var pendingOns   = [];
        var real         = null;

        window.socket = {
            emit: function () {
                if (real) { real.emit.apply(real, arguments); }
                else { pendingEmits.push(arguments); }
            },
            on: function () {
                if (real) { real.on.apply(real, arguments); }
                else { pendingOns.push(arguments); }
            },
            get connected() { return real ? real.connected : false; }
        };

        document.addEventListener('DOMContentLoaded', function () {
            if (typeof io === 'undefined') {
                console.warn('[socket] โหลด socket.io ไม่ได้ — ข้ามการเชื่อมต่อ realtime (หน้าเว็บส่วนอื่นทำงานปกติ)');
                return;
            }

            real = io.connect(<?php echo json_encode(socketurl(), 15, 512) ?>);

            pendingOns.forEach(function (args) { real.on.apply(real, args); });
            pendingEmits.forEach(function (args) { real.emit.apply(real, args); });
            pendingOns = [];
            pendingEmits = [];
        });
    })();
</script>
<?php /**PATH D:\laragon\htdocs\screening\resources\views/components/socket_boot.blade.php ENDPATH**/ ?>