
import WebsocketHeartbeat from "./WebsocketHeartbeat";

var server = "";  
if (process.env.NODE_ENV === 'development') {
    server = "ws://localhost:7018/imserver/r:";
}else{
    server = "wss://im.yjf.runtzh.com/imserver/r:";  
    //server = "ws://139.186.77.83:7018/imserver/r:";  
}

export default {
    socket: {},
    hasLogin:false,
    initSocket: function(uid,reset) {
        if(typeof(WebSocket) === "undefined"){
            console.log("您的浏览器不支持socket")
        }else{
            // 实例化socket
            if(!this.socket || reset){
                console.log("实例化socket");
                //this.socket = new WebSocket(server+uid);
                this.socket=new WebsocketHeartbeat({
                    url: server+uid,
                    userId:'r:'+uid,
                    pingTimeout: 15000,
                    pongTimeout: 10000
                });
                let that=this;
                // this.socket.onopen = function () {
                //     console.log('connect success');
                //     console.log('send massage: test');
                //     websocketHeartbeatJs.send('test');
                //     setTimeout(() => {
                //         console.log(`wait ${websocketHeartbeatJs.opts.pingTimeout} ms will hava '${websocketHeartbeatJs.opts.pingMsg}'`);
                //     }, 1500);
                // }

                // that.$notify.success({
                //     title: '正在呼叫'+mobile,
                //     showClose: false
                // });

                this.hasLogin=true;
            }
            
        }
    }
}