Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nginx-push-stream-module
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
nginx-push-stream-module
Commits
9f47902e
Commit
9f47902e
authored
Nov 17, 2014
by
Wandenberg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #120 cleanup long polling connections when a timeout or a connection error happens
parent
5be47b0e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
9 deletions
+32
-9
pushstream.js
misc/js/pushstream.js
+32
-9
No files found.
misc/js/pushstream.js
View file @
9f47902e
...
@@ -231,6 +231,8 @@ Authors: Wandenberg Peixoto <wandenberg@gmail.com>, Rogério Carvalho Schneider
...
@@ -231,6 +231,8 @@ Authors: Wandenberg Peixoto <wandenberg@gmail.com>, Rogério Carvalho Schneider
Ajax
.
clear
(
settings
);
Ajax
.
clear
(
settings
);
settings
.
xhr
=
xhr
;
xhr
.
onreadystatechange
=
function
()
{
xhr
.
onreadystatechange
=
function
()
{
if
(
xhr
.
readyState
===
4
)
{
if
(
xhr
.
readyState
===
4
)
{
Ajax
.
clear
(
settings
);
Ajax
.
clear
(
settings
);
...
@@ -260,8 +262,8 @@ Authors: Wandenberg Peixoto <wandenberg@gmail.com>, Rogério Carvalho Schneider
...
@@ -260,8 +262,8 @@ Authors: Wandenberg Peixoto <wandenberg@gmail.com>, Rogério Carvalho Schneider
if
(
settings
.
beforeSend
)
{
settings
.
beforeSend
(
xhr
);
}
if
(
settings
.
beforeSend
)
{
settings
.
beforeSend
(
xhr
);
}
var
onerror
=
function
()
{
var
onerror
=
function
()
{
try
{
xhr
.
abort
();
}
catch
(
e
)
{
/* ignore error on closing */
}
Ajax
.
clear
(
settings
);
Ajax
.
clear
(
settings
);
try
{
xhr
.
abort
();
}
catch
(
e
)
{
/* ignore error on closing */
}
settings
.
error
(
304
);
settings
.
error
(
304
);
};
};
...
@@ -276,6 +278,12 @@ Authors: Wandenberg Peixoto <wandenberg@gmail.com>, Rogério Carvalho Schneider
...
@@ -276,6 +278,12 @@ Authors: Wandenberg Peixoto <wandenberg@gmail.com>, Rogério Carvalho Schneider
return
xhr
;
return
xhr
;
},
},
_clear_xhr
:
function
(
xhr
)
{
if
(
xhr
)
{
xhr
.
onreadystatechange
=
null
;
}
},
_clear_script
:
function
(
script
)
{
_clear_script
:
function
(
script
)
{
// Handling memory leak in IE, removing and dereference the script
// Handling memory leak in IE, removing and dereference the script
if
(
script
)
{
if
(
script
)
{
...
@@ -288,9 +296,18 @@ Authors: Wandenberg Peixoto <wandenberg@gmail.com>, Rogério Carvalho Schneider
...
@@ -288,9 +296,18 @@ Authors: Wandenberg Peixoto <wandenberg@gmail.com>, Rogério Carvalho Schneider
settings
.
timeoutId
=
clearTimer
(
settings
.
timeoutId
);
settings
.
timeoutId
=
clearTimer
(
settings
.
timeoutId
);
},
},
_clear_jsonp
:
function
(
settings
)
{
var
callbackFunctionName
=
settings
.
data
.
callback
;
if
(
callbackFunctionName
)
{
window
[
callbackFunctionName
]
=
function
()
{
window
[
callbackFunctionName
]
=
null
;
};
}
},
clear
:
function
(
settings
)
{
clear
:
function
(
settings
)
{
Ajax
.
_clear_timeout
(
settings
);
Ajax
.
_clear_timeout
(
settings
);
Ajax
.
_clear_jsonp
(
settings
);
Ajax
.
_clear_script
(
document
.
getElementById
(
settings
.
scriptId
));
Ajax
.
_clear_script
(
document
.
getElementById
(
settings
.
scriptId
));
Ajax
.
_clear_xhr
(
settings
.
xhr
);
},
},
jsonp
:
function
(
settings
)
{
jsonp
:
function
(
settings
)
{
...
@@ -303,10 +320,8 @@ Authors: Wandenberg Peixoto <wandenberg@gmail.com>, Rogério Carvalho Schneider
...
@@ -303,10 +320,8 @@ Authors: Wandenberg Peixoto <wandenberg@gmail.com>, Rogério Carvalho Schneider
var
onerror
=
function
()
{
var
onerror
=
function
()
{
Ajax
.
clear
(
settings
);
Ajax
.
clear
(
settings
);
var
callbackFunctionName
=
settings
.
data
.
callback
;
if
(
callbackFunctionName
)
{
window
[
callbackFunctionName
]
=
function
()
{
window
[
callbackFunctionName
]
=
null
;
};
}
var
endTime
=
getTime
();
var
endTime
=
getTime
();
settings
.
error
(((
endTime
-
startTime
)
>
settings
.
timeout
/
2
)
?
304
:
0
);
settings
.
error
(((
endTime
-
startTime
)
>
settings
.
timeout
/
2
)
?
304
:
403
);
};
};
var
onload
=
function
()
{
var
onload
=
function
()
{
...
@@ -314,10 +329,19 @@ Authors: Wandenberg Peixoto <wandenberg@gmail.com>, Rogério Carvalho Schneider
...
@@ -314,10 +329,19 @@ Authors: Wandenberg Peixoto <wandenberg@gmail.com>, Rogério Carvalho Schneider
settings
.
load
();
settings
.
load
();
};
};
var
onsuccess
=
function
()
{
settings
.
afterSuccess
=
true
;
settings
.
success
.
apply
(
null
,
arguments
);
};
script
.
onerror
=
onerror
;
script
.
onerror
=
onerror
;
script
.
onload
=
script
.
onreadystatechange
=
function
(
eventLoad
)
{
script
.
onload
=
script
.
onreadystatechange
=
function
(
eventLoad
)
{
if
(
!
script
.
readyState
||
/loaded|complete/
.
test
(
script
.
readyState
))
{
if
(
!
script
.
readyState
||
/loaded|complete/
.
test
(
script
.
readyState
))
{
onload
();
if
(
settings
.
afterSuccess
)
{
onload
();
}
else
{
onerror
();
}
}
}
};
};
...
@@ -326,11 +350,10 @@ Authors: Wandenberg Peixoto <wandenberg@gmail.com>, Rogério Carvalho Schneider
...
@@ -326,11 +350,10 @@ Authors: Wandenberg Peixoto <wandenberg@gmail.com>, Rogério Carvalho Schneider
settings
.
timeoutId
=
window
.
setTimeout
(
onerror
,
settings
.
timeout
+
2000
);
settings
.
timeoutId
=
window
.
setTimeout
(
onerror
,
settings
.
timeout
+
2000
);
settings
.
scriptId
=
settings
.
scriptId
||
getTime
();
settings
.
scriptId
=
settings
.
scriptId
||
getTime
();
settings
.
afterSuccess
=
null
;
var
callbackFunctionName
=
settings
.
data
.
callback
;
if
(
callbackFunctionName
)
{
window
[
callbackFunctionName
]
=
function
()
{
window
[
callbackFunctionName
]
=
null
;
};
}
settings
.
data
.
callback
=
settings
.
scriptId
+
"
_onmessage_
"
+
getTime
();
settings
.
data
.
callback
=
settings
.
scriptId
+
"
_onmessage_
"
+
getTime
();
window
[
settings
.
data
.
callback
]
=
settings
.
success
;
window
[
settings
.
data
.
callback
]
=
on
success
;
script
.
setAttribute
(
"
src
"
,
addParamsToUrl
(
settings
.
url
,
extend
({},
settings
.
data
,
currentTimestampParam
())));
script
.
setAttribute
(
"
src
"
,
addParamsToUrl
(
settings
.
url
,
extend
({},
settings
.
data
,
currentTimestampParam
())));
script
.
setAttribute
(
"
async
"
,
"
async
"
);
script
.
setAttribute
(
"
async
"
,
"
async
"
);
...
@@ -778,12 +801,12 @@ Authors: Wandenberg Peixoto <wandenberg@gmail.com>, Rogério Carvalho Schneider
...
@@ -778,12 +801,12 @@ Authors: Wandenberg Peixoto <wandenberg@gmail.com>, Rogério Carvalho Schneider
},
},
onerror
:
function
(
status
)
{
onerror
:
function
(
status
)
{
this
.
_closeCurrentConnection
();
if
(
this
.
pushstream
.
_keepConnected
)
{
/* abort(), called by disconnect(), call this callback, but should be ignored */
if
(
this
.
pushstream
.
_keepConnected
)
{
/* abort(), called by disconnect(), call this callback, but should be ignored */
if
(
status
===
304
)
{
if
(
status
===
304
)
{
this
.
_listen
();
this
.
_listen
();
}
else
{
}
else
{
Log4js
.
info
(
"
[LongPolling] error (disconnected by server):
"
,
status
);
Log4js
.
info
(
"
[LongPolling] error (disconnected by server):
"
,
status
);
this
.
_closeCurrentConnection
();
this
.
pushstream
.
_onerror
({
type
:
((
status
===
403
)
||
(
this
.
pushstream
.
readyState
===
PushStream
.
CONNECTING
))
?
"
load
"
:
"
timeout
"
});
this
.
pushstream
.
_onerror
({
type
:
((
status
===
403
)
||
(
this
.
pushstream
.
readyState
===
PushStream
.
CONNECTING
))
?
"
load
"
:
"
timeout
"
});
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment