Namespace.register("U.CV");

//#region socket消息区域

//设置文件读取
U.CV.UL = function (URL, UOE, UEE, UME) {
    return new U.CV.ULinit(URL, UOE, UME).create(UME);
}

//获取文件设置
U.CV.ULinit = function (URL, UOE, UME) {
    this.USK; this.URL = URL || window.location.protocol + "//" + window.location.host; this.UOE = UOE;
}
//文件使用方法
U.CV.ULinit.prototype = {
    sockets: {},
    events: ["connect", "connect_failed", "error", "reconnecting", "reconnect", "disconnect"], //事件源
    create: function (UME) { //创建socketio
        if (this.sockets[this.URL]) { return this.sockets[this.URL]; }
        else {
            U.MD.DynamicLoad("http://socketio.1473.cn/socket.io/socket.io.js", "js", U.M.apply(this, [[this.Asyncreate, [UME]]])); //创建socketio文件
            return this;
        }
    },
    Asyncreate: function (UME) { //创建连接socket连接
        var i, j, _UOE = this.UOE, _UEE = this.UEE, _UDE = this.events, _USE = this.USK = io.connect(this.URL, UME || { "reopen delay": 3000, "connect timeout": 5000, "try multiple transports": true, "reconnect": true, "max reconnection attempts": 10 }); //生成socket通道
        for (i = 0; i < _UDE.length; i++) { _USE.on(_UDE[i], this[_UDE[i]]); } //事件监视
        for (i in _UOE) { if (_UOE.hasOwnProperty(i)) { _USE.on(i, U.M.apply(this, [[this.asyn, [_UOE[i]]]])); } } //添加消息接收设置
        for (i = 0; i < _UEE.length; i++) { this.emit.apply(this, U.Ut.isArguments(_UEE[i]) ? _UEE[i] : [_UEE[i]]); } this.UEE = []; //设置socket连接
    },
    abort: function () { //关闭连接
        this.USK.disconnect();
    },
    asyn: function (UDE) { //获取消息接收
        var _UAE = Array.prototype.slice.call(arguments); _UAE.splice(0, 1);
        (UDE) && (UDE.apply(null, _UAE)); //接收消息回调
    },
    on: function () { //绑定值
        var _UDE = arguments, _USE = this.USK;
        if (_UDE.length > 1) { _USE.on(_UDE[0], U.M.apply(this, [[this.on, [_UDE[1]]]])); } //设置
        else if (U.Ut.isObject(_UDE)) { _UDE.Each(function (UVE, UIE) { _USE.on(_UIE, U.M.apply(this, [[this.on, [asyn]]])); }) }
    },
    emit: function (UME) { //发送消息
        var i, _USE = this.USK;
        if (_USE) { if (U.Ut.isString(UME)) { _USE.emit.apply(_USE, arguments); } else { _$(UME).Each(function (UDE, UIE) { _USE.emit(UIE, UDE[UIE]); }); } } //发送消息
        else { (!this.UEE) && (this.UEE = []); this.UEE.push(U.Ut.isString(UME) ? arguments : UME); } return this; //等待消息发送
    },
    connect: function (UE) { //连接成功

    },
    "connect_failed": function (UE) { //无法连接到服务器

    },
    error: function () { //连接失败

    },
    reconnecting: function () { //不断的连接服务器

    },
    reconnect: function () { //重连成功

    },
    disconnect: function () { //退出连接

    }
};
//文件使用方法
//U.M.Setprototype(U.CV.ULinit, {
//    sockets: {},
//    events: ["connect", "connect_failed", "error", "reconnecting", "reconnect", "disconnect"], //事件源
//    create: function (UME) { //创建socketio
//        if (this.sockets[this.URL]) { return this.sockets[this.URL]; }
//        else {
//            U.MD.DynamicLoad("http://socketio.1473.cn/socket.io/socket.io.js", "js", U.M.apply(this, [[this.Asyncreate, [UME]]])); //创建socketio文件
//            return this;
//        }
//    },
//    Asyncreate: function (UME) { //创建连接socket连接
//        var i, j, _UOE = this.UOE, _UEE = this.UEE, _UDE = this.events, _USE = this.USK = io.connect(this.URL, UME || { "reopen delay": 3000, "connect timeout": 5000, "try multiple transports": true, "reconnect": true, "max reconnection attempts": 10 }); //生成socket通道
//        for (i = 0; i < _UDE.length; i++) { _USE.on(_UDE[i], this[_UDE[i]]); } //事件监视
//        for (i in _UOE) { if (_UOE.hasOwnProperty(i)) { _USE.on(i, U.M.apply(this, [[this.asyn, [_UOE[i]]]])); } } //添加消息接收设置
//        for (i = 0; i < _UEE.length; i++) { this.emit.apply(this, U.Ut.isArguments(_UEE[i]) ? _UEE[i] : [_UEE[i]]); } this.UEE = []; //设置socket连接
//    },
//    abort: function () { //关闭连接
//        this.USK.disconnect();
//    },
//    asyn: function (UDE) { //获取消息接收
//        var _UAE = Array.prototype.slice.call(arguments); _UAE.splice(0, 1);
//        (UDE) && (UDE.apply(null, _UAE)); //接收消息回调
//    },
//    on: function () { //绑定值
//        var _UDE = arguments, _USE = this.USK;
//        if (_UDE.length > 1) { _USE.on(_UDE[0], U.M.apply(this, [[this.on, [_UDE[1]]]])); } //设置
//        else if (U.Ut.isObject(_UDE)) { _UDE.Each(function (UVE, UIE) { _USE.on(_UIE, U.M.apply(this, [[this.on, [asyn]]])); }) }
//    },
//    emit: function (UME) { //发送消息
//        var i, _USE = this.USK;
//        if (_USE) { if (U.Ut.isString(UME)) { _USE.emit.apply(_USE, arguments); } else { _$(UME).Each(function (UDE, UIE) { _USE.emit(UIE, UDE[UIE]); }); } } //发送消息
//        else { (!this.UEE) && (this.UEE = []); this.UEE.push(U.Ut.isString(UME) ? arguments : UME); } return this; //等待消息发送
//    },
//    connect: function (UE) { //连接成功

//    },
//    "connect_failed": function (UE) { //无法连接到服务器

//    },
//    error: function () { //连接失败

//    },
//    reconnecting: function () { //不断的连接服务器

//    },
//    reconnect: function () { //重连成功

//    },
//    disconnect: function () { //退出连接

//    }
//});


//#endregion