@@ -11,28 +11,19 @@ export default class PollingProxy extends Proxy {
1111 this . timer = 0
1212 this . timeout = 0
1313 this . interval = 1000
14- this . xhr = null
15- this . needReconnect = true
14+ this . stopped = false
1615 this . responder = new Async ( this . onMessage , this . onError , this )
16+
1717 this . poll ( )
1818 }
1919
20- onMessage ( data ) {
20+ poll ( ) {
21+ clearTimeout ( this . timer )
2122 clearTimeout ( this . timeout )
2223
23- this . timer = setTimeout ( ( ) => {
24- this . poll ( )
25- } , this . interval )
26-
27- this . fireEvent ( 'messageReceived' , data )
28- }
24+ this . timeout = setTimeout ( ( ) => this . onTimeout ( ) , 30 * 1000 )
2925
30- poll ( ) {
31- this . timeout = setTimeout ( ( ) => {
32- this . onTimeout ( )
33- } , 30 * 1000 )
34-
35- this . xhr = Request . get ( {
26+ Request . get ( {
3627 url : this . restUrl ,
3728 isAsync : true ,
3829 asyncHandler : this . responder
@@ -43,27 +34,32 @@ export default class PollingProxy extends Proxy {
4334 clearTimeout ( this . timer )
4435 clearTimeout ( this . timeout )
4536
46- this . needReconnect = false
47-
48- if ( this . xhr ) {
49- this . xhr . abort ( )
50- }
37+ this . stopped = true
5138 }
5239
5340 onTimeout ( ) {
54- this . xhr && this . xhr . abort ( )
41+ clearTimeout ( this . timeout )
42+
43+ this . poll ( )
5544 }
5645
57- onError ( ) {
46+ onMessage ( data ) {
5847 clearTimeout ( this . timer )
5948 clearTimeout ( this . timeout )
6049
61- if ( this . needReconnect ) {
62- this . xhr = null
50+ if ( ! this . stopped ) {
51+ this . timer = setTimeout ( ( ) => this . poll ( ) , this . interval )
52+
53+ this . fireEvent ( 'messageReceived' , data )
54+ }
55+ }
56+
57+ onError ( ) {
58+ clearTimeout ( this . timer )
59+ clearTimeout ( this . timeout )
6360
64- this . timer = setTimeout ( ( ) => {
65- this . poll ( )
66- } , this . interval )
61+ if ( ! this . stopped ) {
62+ this . timer = setTimeout ( ( ) => this . poll ( ) , this . interval )
6763 }
6864 }
6965}
0 commit comments