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
684ca330
Commit
684ca330
authored
Apr 29, 2012
by
Wandenberg Peixoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding a timeout onerror callback to non JSONP long polling connections
parent
b98f25ef
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
9 deletions
+25
-9
pushstream.js
misc/js/pushstream.js
+25
-9
No files found.
misc/js/pushstream.js
View file @
684ca330
...
...
@@ -151,16 +151,20 @@
_send
:
function
(
settings
,
post
)
{
settings
=
settings
||
{};
settings
.
timeout
=
settings
.
timeout
||
30000
;
var
xhr
=
Ajax
.
_getXHRObject
();
if
(
!
xhr
||!
settings
.
url
)
return
;
Ajax
.
clear
(
settings
);
xhr
.
onreadystatechange
=
function
()
{
if
(
xhr
.
readyState
==
4
)
{
Ajax
.
clear
(
settings
);
if
(
settings
.
afterReceive
)
settings
.
afterReceive
(
xhr
);
if
(
xhr
.
status
==
200
)
{
if
(
settings
.
success
)
settings
.
success
(
xhr
.
responseText
);
}
else
{
if
(
settings
.
error
)
settings
.
error
(
xhr
.
status
);
if
(
settings
.
error
)
settings
.
error
(
xhr
.
status
||
304
);
}
}
}
...
...
@@ -182,10 +186,19 @@
if
(
settings
.
beforeSend
)
settings
.
beforeSend
(
xhr
);
var
onerror
=
function
()
{
try
{
xhr
.
abort
();
}
catch
(
e
)
{
/* ignore error on closing */
}
Ajax
.
clear
(
settings
);
settings
.
error
(
304
);
};
if
(
post
)
{
xhr
.
setRequestHeader
(
"
Accept
"
,
"
application/json
"
);
xhr
.
setRequestHeader
(
"
Content-type
"
,
"
application/x-www-form-urlencoded
"
);
}
else
{
settings
.
timeoutId
=
window
.
setTimeout
(
onerror
,
settings
.
timeout
+
2000
);
}
xhr
.
send
(
body
);
return
xhr
;
},
...
...
@@ -198,16 +211,20 @@
}
},
clear
:
function
(
settings
)
{
_clear_timeout
:
function
(
settings
)
{
if
(
settings
.
timeoutId
)
{
settings
.
timeoutId
=
window
.
clearTimeout
(
settings
.
timeoutId
);
}
},
clear
:
function
(
settings
)
{
Ajax
.
_clear_timeout
(
settings
);
Ajax
.
_clear_script
(
document
.
getElementById
(
settings
.
scriptId
));
},
jsonp
:
function
(
settings
)
{
settings
.
timeout
=
settings
.
timeout
||
30000
;
Ajax
.
clear
(
settings
);
var
head
=
document
.
head
||
document
.
getElementsByTagName
(
"
head
"
)[
0
];
var
script
=
document
.
createElement
(
"
script
"
);
...
...
@@ -232,7 +249,7 @@
if
(
settings
.
beforeOpen
)
settings
.
beforeOpen
({});
if
(
settings
.
beforeSend
)
settings
.
beforeSend
({});
settings
.
timeoutId
=
window
.
setTimeout
(
onerror
,
settings
.
timeout
+
1
0
);
settings
.
timeoutId
=
window
.
setTimeout
(
onerror
,
settings
.
timeout
+
200
0
);
settings
.
scriptId
=
settings
.
scriptId
||
new
Date
().
getTime
();
script
.
setAttribute
(
"
src
"
,
addTimestampToUrl
(
settings
.
url
)
+
'
&
'
+
Ajax
.
_parse_data
(
settings
));
...
...
@@ -515,7 +532,7 @@
ifr
.
onload
=
linker
(
onerrorCallback
,
this
);
this
.
connection
=
ifr
;
}
this
.
frameloadtimer
=
setTimeout
(
linker
(
onerrorCallback
,
this
),
this
.
pushstream
.
timeout
);
this
.
frameloadtimer
=
window
.
setTimeout
(
linker
(
onerrorCallback
,
this
),
this
.
pushstream
.
timeout
);
},
register
:
function
(
iframeWindow
)
{
...
...
@@ -542,7 +559,7 @@
setPingTimer
:
function
()
{
if
(
this
.
pingtimer
)
clearTimer
(
this
.
pingtimer
);
this
.
pingtimer
=
setTimeout
(
linker
(
onerrorCallback
,
this
),
this
.
pushstream
.
pingtimeout
);
this
.
pingtimer
=
window
.
setTimeout
(
linker
(
onerrorCallback
,
this
),
this
.
pushstream
.
pingtimeout
);
}
};
...
...
@@ -586,19 +603,18 @@
this
.
xhrSettings
.
data
.
callback
=
"
PushStreamManager[
"
+
this
.
pushstream
.
id
+
"
].wrapper.onmessage
"
;
}
this
.
_internalListen
();
this
.
opentimer
=
setTimeout
(
linker
(
onopenCallback
,
this
),
5000
);
this
.
opentimer
=
window
.
setTimeout
(
linker
(
onopenCallback
,
this
),
5000
);
Log4js
.
info
(
"
[LongPolling] connecting to:
"
,
this
.
xhrSettings
.
url
);
},
_listen
:
function
()
{
if
(
this
.
_internalListenTimeout
)
clearTimer
(
this
.
_internalListenTimeout
);
this
.
_internalListenTimeout
=
setTimeout
(
this
.
_linkedInternalListen
,
this
.
pushstream
.
longPollingInterval
);
this
.
_internalListenTimeout
=
window
.
setTimeout
(
this
.
_linkedInternalListen
,
this
.
pushstream
.
longPollingInterval
);
},
_internalListen
:
function
()
{
if
(
this
.
connectionEnabled
)
{
if
(
this
.
useJSONP
)
{
Ajax
.
clear
(
this
.
xhrSettings
);
Ajax
.
jsonp
(
this
.
xhrSettings
);
}
else
if
(
!
this
.
connection
)
{
this
.
connection
=
Ajax
.
load
(
this
.
xhrSettings
);
...
...
@@ -890,7 +906,7 @@
_reconnect
:
function
(
timeout
)
{
if
(
this
.
_keepConnected
&&
!
this
.
reconnecttimer
&&
(
this
.
readyState
!=
PushStream
.
CONNECTING
))
{
Log4js
.
info
(
"
trying to reconnect in
"
,
timeout
);
this
.
reconnecttimer
=
setTimeout
(
linker
(
this
.
_connect
,
this
),
timeout
);
this
.
reconnecttimer
=
window
.
setTimeout
(
linker
(
this
.
_connect
,
this
),
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