
<script>
    socket.on('chat message', function(msg) {
        console.log(msg, msg != '', msg != undefined);
        if (msg != '' && msg != undefined) {
            if (msg == 1|| msg == '1') {
                var source_num = $('#camera_2').val()
                if (source_num == 1 || source_num == '1' || source_num == undefined) {
                    $("#btn-capture").trigger("click");
                } else if (source_num == 2 || source_num == '2') {
                    $("#btn-capture").trigger("click");
                    $("#btn-capture2").trigger("click");
                }
            }

            if (msg == 2|| msg == '2') {
                if(timer1Seconds > 0){
                    $("#vdo_stop").trigger("click");
                }else{
                    $("#vdo_start").trigger("click");
                }
            }

            if (msg.includes('size')) {
                var vdo_size = msg.split('_')
                var size_format = (Math.round(parseFloat(vdo_size[1]) * 100) / 100).toFixed(2)
                console.log(size_format);
                $(`#${vdo_size[0]}`).html(`${size_format}`)
            }

            if (msg.includes('scope') && !msg.includes('procedure')) {
                var scope_split = msg.split('_')
                source_id = scope_split[0].replace('scope', 'source')
                var pic_name = "<?php echo e(@$olympus_disabled); ?>" != 'true' ? "<?php echo e(@$olympus_picname); ?>" :
                    "<?php echo e(@$fuji_picname); ?>"
                var img_url = `<?php echo e(@$ocr_img); ?>/<?php echo e(@$hn); ?>_crop_${pic_name}`
                ocr_image(img_url, source_id)
                var ocr = $(`#${source_id}`).val()
                // save camera name
                if (ocr != undefined && ocr != '') {
                    $.post("<?php echo e(url('api/jquery')); ?>", {
                        event: 'savejson_checkbox',
                        id: '<?php echo e(@$cid); ?>',
                        idhtml: 'case_scope',
                        value: ocr
                    }, function(data, status) {});
                }
            }


        }
    })

    let timefix = '<?php echo e(date("dHis")); ?>';
    setTimeout(() => {
        socket.emit('obs', `{"event":"check_open_other","time":"${timefix}"}`);
    }, 1000);
    socket.on('obs', function(msg) {
        let obj = JSON.parse(msg);
        if(obj.event == 'check_open_other'){
            socket.emit('obs', `{"event":"reponse_open_other","time":"${timefix}"}`);
        }

        if(obj.event == 'reponse_open_other'){
            if(obj.time < timefix){
                window.location.replace("<?php echo e(url('endoindex')); ?>");
            }else{
                socket.emit('obs', `{"event":"casedata","cid":"<?php echo e($cid); ?>","hn":"<?php echo e(@$case->case_hn); ?>","procedure":"<?php echo e(@$case->procedurename); ?>","department":"<?php echo e(@$case->department); ?>"}`);
            }
        }

        if(obj.event == 'vdo_size'){
            console.log(obj.size);
            $("#size1").html(obj.size);
        }

        if(obj.event == 'device_lost'){
            alert('Device lost');
        }
    });
</script>

<script>
    socket.on('filename', function(msg) {
        if (msg.includes('.jpg')) {
            sound_capture.play();
            console.log(msg);
            imageSHOW(msg);
            <?php if(@$feature->liveconsult): ?>
                liveconsult(msg);
            <?php endif; ?>
        }
    })
</script>
<?php /**PATH D:\laragon\htdocs\screening\resources\views/endocapture/camera/obs/js_socket.blade.php ENDPATH**/ ?>