君哥求解

function websocketClass(a) {
    var b = this;
    this.wsobj = !1,
    this.wshost = "",
    this.onopen = function () {},
    this.onmessage = function () {},
    this.onclose = function () {},
    this.onerror = function () {},
    this.reimfrom = "rockdemo",
    this.adminid = "1",
    this.sendname = "1",
    this._init = function () {
        if (a) for (var c in a) this[c] = a[c];
        "undefined" == typeof WebSocket ? (WEB_SOCKET_SWF_LOCATION = "res/swf/WebSocketMain.swf", WEB_SOCKET_DEBUG = !0, $.getScript("res/js/swfobject.js", function () {
            b._contect()
        })) : this._contect()
    },
    this._contect = function () {
        this.wsobj = new WebSocket(this.wshost),
        this.wsobj.onopen = function (a) {
            b._onopen(a)
        },
        this.wsobj.onmessage = function (a) {
            b._onmessage(a)
        },
        this.wsobj.onclose = function (a) {
            b._onclose(a)
        },
        this.wsobj.onerror = function (a) {
            b._onerror(a)
        }
    },
    this.connect = function () {
        this._contect()
    },
    this._onopen = function (a) {
        this.onopen(this, a),
        this.send({
            atype: "connect"
        })
    },
    this._onmessage = function (a) {
        var b = a.data;
        this.onmessage(b, this)
    },
    this._onclose = function (a) {
        this.onclose(this, a)
    },
    this._onerror = function (a) {
        this.onerror(this, a)
    },
    this.send = function (a) {
        var b = this.objecttostr(a);
        return this.wsobj.send(b)
    },
    this.objecttostr = function (a) {
        var b, d, c = "",
            e = js.apply({
                from: this.reimfrom,
                adminid: this.adminid,
                atype: "send",
                sendname: this.sendname
            }, a);
        for (b in e) d = e[b],
        c += ',"' + b + '":"' + d + '"';
        return "" != c && (c = c.substr(1)),
        "{" + c + "}"
    },
    this._init()
}

使用

websocketobj = new websocketClass({
		adminid:adminid,
		reimfrom:fromrecid,
		wshost:fromwshost,
		sendname:adminname,
		onerror:function(o,ws){
			connectbool=false;
			js.msg('msg','无法连接服务器1<br><span id="lianmiao"></span><a href="javascript:;" onclick="return connectserver()">[重连]</a>',-1);
			relianshotime(30);
		},
		onmessage:function(str){
			connectbool=true;
			var a=js.decode(str);
			im.receivemesb(a);
		},
		onopen:function(){
			connectbool=true;
			js.msg('none');
			im.initnotify();
		},
		onclose:function(){
			if(otherlogin)return;
			connectbool=false;
			js.msg('msg','连接已经断开了<br><span id="lianmiao"></span><a href="javascript:;" onclick="return connectserver()">[重连]</a>',-1);
			notifyobj.playerrsound();
			relianshotime(30);
		}
	});

 

转载于:https://my.oschina.net/u/2416644/blog/907861

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值