utility.js 733 Bytes
var blinkInterval;
var docTitle = document.title;

/**
 * 检查是否支持 websocket
 * @returns {boolean}
 */
exports.isSupport = function() {
    return !!window.WebSocket;
};

/**
 * 添加闪烁提醒
 * @returns {boolean}
 */
exports.addBlinkAlert = function() {
    if (blinkInterval) {
        clearInterval(blinkInterval);
    }

    blinkInterval = setInterval(function() {
        document.title = '您有新消息';
        setTimeout(function() {
            document.title = docTitle;
        }, 300);
    }, 600);
};

/**
 * 去除闪烁提醒
 * @returns {boolean}
 */
exports.removeBlinkAlert = function() {
    if (blinkInterval) {
        clearInterval(blinkInterval);
        document.title = docTitle;
    }
};