李勇

1.修改计时的内部变量

... ... @@ -77,7 +77,7 @@ class EverSocket extends Emiter {
}
_clear() {
this._emit(EverSocket.CLOSED);
//this._emit(EverSocket.CLOSED);
loger.log('WebSocket,Timers销毁');
window.clearInterval(this.pingTimer);
window.clearInterval(this.pongTimer);
... ...
... ... @@ -10,51 +10,55 @@
//let loger = Loger.getLoger('MediaModule');
let counter=0;
/*let counter=0;
let callBackDelay=1;
let callBackFun;
let isStart=false;
let isStart=false;*/
class TimerCounter {
constructor() {
this.timer=0;
this.delay=1000;
this.counter=0;
this.callBackDelay=1;
this.callBackFun=null;
this.isStart=false;
}
addTimerCallBack(_callBackFun,_callBackDelay){
callBackFun=_callBackFun;
callBackDelay=_callBackDelay;
this.callBackFun=_callBackFun;
this.callBackDelay=_callBackDelay;
}
//开计时
startTimer(_position=0) {
if(isStart) return;
isStart=true;
if(this.isStart) return;
this.isStart=true;
if(_position&&parseInt(_position)>0){
counter=_position;
this.counter=_position;
}else {
counter=0;
this.counter=0;
}
console.log("startTimer",counter);
console.log("startTimer",this.counter);
this.timerClear();
this.timerStart();
}
//停止
stopTimer(){
console.log("stopTimer",counter);
isStart=false;
console.log("stopTimer",this.counter);
this.isStart=false;
this.timerClear();
}
//计数
updateCounter(){
counter++;
this.counter++;
//this.counter++;
//console.log("TimerCounter",counter);
if(callBackFun!=null&&counter%callBackDelay==0){
callBackFun();
if(this.callBackFun!=null&&this.counter%this.callBackDelay==0){
this.callBackFun();
}
}
timerStart(){
this.timer= setInterval(this.updateCounter, this.delay);
this.timer= setInterval(this.updateCounter.bind(this), this.delay);
}
timerClear(){
clearInterval(this.timer);
... ...