/*============自定义对象===========*/
/*
* 方法:Array.remove(dx) 通过遍历,重构数组
* 功能:删除数组元素.
* 参数:dx删除元素的下标.
*/
Array.prototype.remove=function(dx)
{
if(isNaN(dx)||dx>this.length){return false;}
for(var i=0,n=0;i<this.length;i++)
{
if(this[i]!=this[dx])
{
this[n++]=this[i]
}
}
this.length-=1
}
/*寻找元素在数组中的位置*/
Array.prototype.indexOf = function (obj) {
for (var i = 0; i < this.length; i++) {
if (this[i] == obj) {
return i;
}
}
return -1;
}
//生成GUID,加上时间
function newGuid()
{
var guid = "";
for (var i = 1; i <= 32; i++){
var n = Math.floor(Math.random()*16.0).toString(16);
guid += n;
if((i==8)||(i==12)||(i==16)||(i==20))
guid += "-";
}
guid+="_"+new Date().getTime();
return guid;
}
//声明消息对象
function SfjWsMsg(key,value){
this.key=key;
this.value=value;
this.loginguid=null; //当前登录标识
this.identifyid=null;//每条消息唯一标识
this.state=null;//消息状态
}
/*============缓存管理===========*/
function HisMsgCache(){
this.msgcache=new Array();
//添加消息到缓存,
//hidelog notnull-不显示 null-显示(默认值)
this.addMsgToCache = function(userId,msg,hidelog){
if (!this.msgcache[userId]){
this.msgcache[userId]=new Array();
}
var msglist=this.msgcache[userId];
if (!hidelog){
console.log('User['+userId+'] addMsgToCache:'+msg);
}
msglist.push(msg);
}
//移除消息从缓存中
this.delMsgFromCache=function(userId,msg){
var msglist=this.msgcache[use