let socket = io();
const roomId = document.getElementById('cookie-img').dataset.roomId;

function incrementCount() {
    let count = parseInt(document.querySelector('#count h2').innerHTML);
    document.querySelector('#count h2').innerHTML = (count+1).toString();
}

document.getElementById('cookie-img').addEventListener('click', e => {
    socket.emit('click', roomId);
    incrementCount();
});

socket.on('change', sourceRoomId => {
    if(sourceRoomId === roomId) {
        incrementCount();
    }
});