<commit_before>var AutoBed = (function () {
    'use strict';

    var logTimer = null;
    var log = function (txt, permanent) {
	permanent = (permanent === undefined) ? false : permanent;
        var logDiv =  document.getElementById('log');
        logDiv.innerHTML = txt;
        console.log(txt);
        if (logTimer !== null) {
            clearTimeout(logTimer);
        }
	if (!permanent) {
		logTimer = setTimeout( function () {logDiv.innerHTML = 'Ready';}, 3000);
	}
    }

    var sendOKFlag = false;
    var sendTimer = null;

    var sendCmd = function (cmd) {
        if (sendOKFlag) {
            ws.send(cmd.toString())
            sendTimer = setTimeout(function(){ sendCmd(cmd) }, 75)
        } else {
            clearTimeout(sendTimer);
        }
    }

    var setupButtonCBs = function (buttonElement) {
        buttonElement.addEventListener("mouseup", function(event){
    	        sendOKFlag = false;
	        clearTimeout(sendTimer);
	    });
        buttonElement.addEventListener("mouseout", function(event){
	        sendOKFlag = false;
	        clearTimeout(sendTimer);
	    });
        buttonElement.addEventListener("mouseleave", function(event){
	        sendOKFlag = false;
	        clearTimeout(sendTimer);
	    });
        buttonElement.addEventListener("mousedown", function(event) {
            if (event.which === 1) { // Only respond to left mouse button (right will stick button down)
	            sendOKFlag = true;
	            sendCmd(event.target.value);
	    }
	    });
    };
    var heartBeatTimer, lastBeatTime;
    var checkHeartBeat = function () {
        if (new Date() - lastBeatTime > 5000) {
            ws.close()
	}
	ws.send('----heartbeat----')
    }

    var onOpen = function () {
	var disconElems = document.querySelectorAll('.disconnected')
	for (var i=0; i<disconElems.length; i+=1) {
            disconElems[i].className = disconElems[i].className.replace("disconnected", "connected")
 	}
	heartBeatTimer = setInterval(checkHeartBeat, 1000);
        setupButtonCBs(document.getElementById("head-up"));
        setupButtonCBs(document.getElementById("bed-up"));
        setupButtonCBs(document.getElementById("legs-up"));
        setupButtonCBs(document.getElementById("head-down"));
        setupButtonCBs(document.getElementById("bed-down"));
        setupButtonCBs(document.getElementById("legs-down"));
        log("Connected to AutoBed.")
    }

    var onMessage = function (msg) {
        console.log("WS Received: ", msg);
	if (msg.data === '----heartbeat----') {
            lastBeatTime = new Date();
        }
    }

    var onClose = function () {
	log("Connection to Autobed Controller Closed", true)
	var conElems = document.querySelectorAll('.connected')
	for (var i=0; i<conElems.length; i+=1) {
            conElems[i].className = conElems[i].className.replace("connected", "disconnected")
 	}
    }<commit_msg>10 second heartbeat timeout in js. Checked<commit_after>var AutoBed = (function () {
    'use strict';

    var logTimer = null;
    var log = function (txt, permanent) {
	permanent = (permanent === undefined) ? false : permanent;
        var logDiv =  document.getElementById('log');
        logDiv.innerHTML = txt;
        console.log(txt);
        if (logTimer !== null) {
            clearTimeout(logTimer);
        }
	if (!permanent) {
		logTimer = setTimeout( function () {logDiv.innerHTML = 'Ready';}, 3000);
	}
    }

    var sendOKFlag = false;
    var sendTimer = null;

    var sendCmd = function (cmd) {
        if (sendOKFlag) {
            ws.send(cmd.toString())
            sendTimer = setTimeout(function(){ sendCmd(cmd) }, 75)
        } else {
            clearTimeout(sendTimer);
        }
    }

    var setupButtonCBs = function (buttonElement) {
        buttonElement.addEventListener("mouseup", function(event){
    	        sendOKFlag = false;
	        clearTimeout(sendTimer);
	    });
        buttonElement.addEventListener("mouseout", function(event){
	        sendOKFlag = false;
	        clearTimeout(sendTimer);
	    });
        buttonElement.addEventListener("mouseleave", function(event){
	        sendOKFlag = false;
	        clearTimeout(sendTimer);
	    });
        buttonElement.addEventListener("mousedown", function(event) {
            if (event.which === 1) { // Only respond to left mouse button (right will stick button down)
	            sendOKFlag = true;
	            sendCmd(event.target.value);
	    }
	    });
    };
    var heartBeatTimer, lastBeatTime;
    var checkHeartBeat = function () {
        if (new Date() - lastBeatTime > 11000) {
            ws.close()
            ws.onclose()
	} else {
	    ws.send('----heartbeat----')
	}
    }

    var onOpen = function () {
	var disconElems = document.querySelectorAll('.disconnected')
	for (var i=0; i<disconElems.length; i+=1) {
            disconElems[i].className = disconElems[i].className.replace("disconnected", "connected")
 	}
	heartBeatTimer = setInterval(checkHeartBeat, 5000);
        setupButtonCBs(document.getElementById("head-up"));
        setupButtonCBs(document.getElementById("bed-up"));
        setupButtonCBs(document.getElementById("legs-up"));
        setupButtonCBs(document.getElementById("head-down"));
        setupButtonCBs(document.getElementById("bed-down"));
        setupButtonCBs(document.getElementById("legs-down"));
        log("Connected to AutoBed.")
    }

    var onMessage = function (msg) {
	if (msg.data === '----heartbeat----') {
            lastBeatTime = new Date();
        }
    }

    var onClose = function () {
	log("Connection to Autobed Controller Closed", true)
        clearTimeout(heartBeatTimer);
	var conElems = document.querySelectorAll('.connected')
	for (var i=0; i<conElems.length; i+=1) {
            conElems[i].className = conElems[i].className.replace("connected", "disconnected")
 	}
    }
{'fraction_non_alphanumeric': 0.13692307692307693, 'fraction_numerical': 0.007008547008547009, 'mean_word_length': 2.593980343980344, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3065799', 'n_tokens_mistral': 1778, 'n_tokens_neox': 1660, 'n_words': 336}