/**
 * socket通信
 * @Author: huangjq
 * @Date:   2019-06-27
 * @Project jz
 */

const install = function(Vue) {
    if (window.WebSocket) {
        let ws = new WebSocket("ws://localhost:8001");

        ws.onopen = function(e) {
            console.log("连接服务器成功");
            ws.send("game2");
        };
        ws.onclose = function(e) {
            console.log("服务器关闭");
        };
        ws.onerror = function() {
            console.log("连接出错");
        };

        ws.onmessage = function(e) {
            let time = new Date();
            // this.$alert.info(`收到${e.data}`);
            infoFn({
                title: "消息",
                message: `收到${e.data}`
            });
            // infoFn();
            console.log(time + "的消息：" + e.data + "<br>");
        };
    }
};

/* istanbul ignore if */
if (typeof window !== "undefined" && window.Vue) {
    install(window.Vue);
}

export default {
    version: "1.0.0",
    install
};
