正在显示
2 个修改的文件
包含
20 行增加
和
16 行删除
| @@ -77,7 +77,7 @@ class EverSocket extends Emiter { | @@ -77,7 +77,7 @@ class EverSocket extends Emiter { | ||
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | _clear() { | 79 | _clear() { |
| 80 | - this._emit(EverSocket.CLOSED); | 80 | + //this._emit(EverSocket.CLOSED); |
| 81 | loger.log('WebSocket,Timers销毁'); | 81 | loger.log('WebSocket,Timers销毁'); |
| 82 | window.clearInterval(this.pingTimer); | 82 | window.clearInterval(this.pingTimer); |
| 83 | window.clearInterval(this.pongTimer); | 83 | window.clearInterval(this.pongTimer); |
| @@ -10,51 +10,55 @@ | @@ -10,51 +10,55 @@ | ||
| 10 | 10 | ||
| 11 | //let loger = Loger.getLoger('MediaModule'); | 11 | //let loger = Loger.getLoger('MediaModule'); |
| 12 | 12 | ||
| 13 | -let counter=0; | 13 | +/*let counter=0; |
| 14 | let callBackDelay=1; | 14 | let callBackDelay=1; |
| 15 | let callBackFun; | 15 | let callBackFun; |
| 16 | -let isStart=false; | 16 | +let isStart=false;*/ |
| 17 | class TimerCounter { | 17 | class TimerCounter { |
| 18 | constructor() { | 18 | constructor() { |
| 19 | this.timer=0; | 19 | this.timer=0; |
| 20 | this.delay=1000; | 20 | this.delay=1000; |
| 21 | + this.counter=0; | ||
| 22 | + this.callBackDelay=1; | ||
| 23 | + this.callBackFun=null; | ||
| 24 | + this.isStart=false; | ||
| 21 | } | 25 | } |
| 22 | 26 | ||
| 23 | addTimerCallBack(_callBackFun,_callBackDelay){ | 27 | addTimerCallBack(_callBackFun,_callBackDelay){ |
| 24 | - callBackFun=_callBackFun; | ||
| 25 | - callBackDelay=_callBackDelay; | 28 | + this.callBackFun=_callBackFun; |
| 29 | + this.callBackDelay=_callBackDelay; | ||
| 26 | } | 30 | } |
| 27 | //开计时 | 31 | //开计时 |
| 28 | startTimer(_position=0) { | 32 | startTimer(_position=0) { |
| 29 | - if(isStart) return; | ||
| 30 | - isStart=true; | 33 | + if(this.isStart) return; |
| 34 | + this.isStart=true; | ||
| 31 | if(_position&&parseInt(_position)>0){ | 35 | if(_position&&parseInt(_position)>0){ |
| 32 | - counter=_position; | 36 | + this.counter=_position; |
| 33 | }else { | 37 | }else { |
| 34 | - counter=0; | 38 | + this.counter=0; |
| 35 | } | 39 | } |
| 36 | - console.log("startTimer",counter); | 40 | + console.log("startTimer",this.counter); |
| 37 | this.timerClear(); | 41 | this.timerClear(); |
| 38 | this.timerStart(); | 42 | this.timerStart(); |
| 39 | 43 | ||
| 40 | } | 44 | } |
| 41 | //停止 | 45 | //停止 |
| 42 | stopTimer(){ | 46 | stopTimer(){ |
| 43 | - console.log("stopTimer",counter); | ||
| 44 | - isStart=false; | 47 | + console.log("stopTimer",this.counter); |
| 48 | + this.isStart=false; | ||
| 45 | this.timerClear(); | 49 | this.timerClear(); |
| 46 | } | 50 | } |
| 47 | //计数 | 51 | //计数 |
| 48 | updateCounter(){ | 52 | updateCounter(){ |
| 49 | - counter++; | 53 | + this.counter++; |
| 50 | //this.counter++; | 54 | //this.counter++; |
| 51 | //console.log("TimerCounter",counter); | 55 | //console.log("TimerCounter",counter); |
| 52 | - if(callBackFun!=null&&counter%callBackDelay==0){ | ||
| 53 | - callBackFun(); | 56 | + if(this.callBackFun!=null&&this.counter%this.callBackDelay==0){ |
| 57 | + this.callBackFun(); | ||
| 54 | } | 58 | } |
| 55 | } | 59 | } |
| 56 | timerStart(){ | 60 | timerStart(){ |
| 57 | - this.timer= setInterval(this.updateCounter, this.delay); | 61 | + this.timer= setInterval(this.updateCounter.bind(this), this.delay); |
| 58 | } | 62 | } |
| 59 | timerClear(){ | 63 | timerClear(){ |
| 60 | clearInterval(this.timer); | 64 | clearInterval(this.timer); |
-
请 注册 或 登录 后发表评论