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
3abca999
Commit
3abca999
authored
Nov 19, 2014
by
Wandenberg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #88 using XDomainRequest for cross domain requests when it is available
parent
f0c40a18
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
16 deletions
+33
-16
pushstream.js
misc/js/pushstream.js
+33
-16
No files found.
misc/js/pushstream.js
View file @
3abca999
...
...
@@ -205,18 +205,22 @@ Authors: Wandenberg Peixoto <wandenberg@gmail.com>, Rogério Carvalho Schneider
};
var
Ajax
=
{
_getXHRObject
:
function
()
{
_getXHRObject
:
function
(
crossDomain
)
{
var
xhr
=
false
;
if
(
crossDomain
)
{
try
{
xhr
=
new
window
.
XDomainRequest
();
}
catch
(
e
)
{
}
if
(
xhr
)
{
return
xhr
;
}
}
try
{
xhr
=
new
window
.
XMLHttpRequest
();
}
catch
(
e1
)
{
try
{
xhr
=
new
window
.
XDomainRequest
(
);
}
try
{
xhr
=
new
window
.
ActiveXObject
(
"
Msxml2.XMLHTTP
"
);
}
catch
(
e2
)
{
try
{
xhr
=
new
window
.
ActiveXObject
(
"
M
sxml2
.XMLHTTP
"
);
}
try
{
xhr
=
new
window
.
ActiveXObject
(
"
M
icrosoft
.XMLHTTP
"
);
}
catch
(
e3
)
{
try
{
xhr
=
new
window
.
ActiveXObject
(
"
Microsoft.XMLHTTP
"
);
}
catch
(
e4
)
{
xhr
=
false
;
}
xhr
=
false
;
}
}
}
...
...
@@ -226,7 +230,7 @@ Authors: Wandenberg Peixoto <wandenberg@gmail.com>, Rogério Carvalho Schneider
_send
:
function
(
settings
,
post
)
{
settings
=
settings
||
{};
settings
.
timeout
=
settings
.
timeout
||
30000
;
var
xhr
=
Ajax
.
_getXHRObject
();
var
xhr
=
Ajax
.
_getXHRObject
(
settings
.
crossDomain
);
if
(
!
xhr
||!
settings
.
url
)
{
return
;
}
Ajax
.
clear
(
settings
);
...
...
@@ -268,8 +272,10 @@ Authors: Wandenberg Peixoto <wandenberg@gmail.com>, Rogério Carvalho Schneider
};
if
(
post
)
{
xhr
.
setRequestHeader
(
"
Accept
"
,
"
application/json
"
);
xhr
.
setRequestHeader
(
"
Content-type
"
,
"
application/x-www-form-urlencoded
"
);
if
(
xhr
.
setRequestHeader
)
{
xhr
.
setRequestHeader
(
"
Accept
"
,
"
application/json
"
);
xhr
.
setRequestHeader
(
"
Content-type
"
,
"
application/x-www-form-urlencoded
"
);
}
}
else
{
settings
.
timeoutId
=
window
.
setTimeout
(
onerror
,
settings
.
timeout
+
2000
);
}
...
...
@@ -462,6 +468,19 @@ Authors: Wandenberg Peixoto <wandenberg@gmail.com>, Rogério Carvalho Schneider
return
domainParts
.
slice
(
-
1
*
keepNumber
).
join
(
'
.
'
);
};
Utils
.
isCrossDomainUrl
=
function
(
url
)
{
if
(
!
url
)
{
return
false
;
}
var
parser
=
document
.
createElement
(
'
a
'
);
parser
.
href
=
url
;
return
(
window
.
location
.
protocol
!==
parser
.
protocol
)
||
(
window
.
location
.
hostname
!==
parser
.
hostname
)
||
(
window
.
location
.
port
!==
parser
.
port
);
};
var
linker
=
function
(
method
,
instance
)
{
return
function
()
{
return
method
.
apply
(
instance
,
arguments
);
...
...
@@ -735,11 +754,8 @@ Authors: Wandenberg Peixoto <wandenberg@gmail.com>, Rogério Carvalho Schneider
this
.
urlWithBacktrack
=
getSubscriberUrl
(
this
.
pushstream
,
this
.
pushstream
.
urlPrefixLongpolling
,
{},
true
);
this
.
urlWithoutBacktrack
=
getSubscriberUrl
(
this
.
pushstream
,
this
.
pushstream
.
urlPrefixLongpolling
,
{},
false
);
this
.
xhrSettings
.
url
=
this
.
urlWithBacktrack
;
var
domain
=
Utils
.
extract_xss_domain
(
this
.
pushstream
.
host
);
var
currentDomain
=
Utils
.
extract_xss_domain
(
window
.
location
.
hostname
);
var
port
=
this
.
pushstream
.
port
;
var
currentPort
=
window
.
location
.
port
?
Number
(
window
.
location
.
port
)
:
(
this
.
pushstream
.
useSSL
?
443
:
80
);
this
.
useJSONP
=
(
domain
!==
currentDomain
)
||
(
port
!==
currentPort
)
||
this
.
pushstream
.
useJSONP
;
this
.
xhrSettings
.
crossDomain
=
Utils
.
isCrossDomainUrl
(
this
.
urlWithBacktrack
);
this
.
useJSONP
=
this
.
xhrSettings
.
crossDomain
||
this
.
pushstream
.
useJSONP
;
this
.
xhrSettings
.
scriptId
=
"
PushStreamManager_
"
+
this
.
pushstream
.
id
;
if
(
this
.
useJSONP
)
{
this
.
pushstream
.
messagesControlByArgument
=
true
;
...
...
@@ -900,6 +916,7 @@ Authors: Wandenberg Peixoto <wandenberg@gmail.com>, Rogério Carvalho Schneider
this
.
channelsByArgument
=
settings
.
channelsByArgument
||
false
;
this
.
channelsArgument
=
settings
.
channelsArgument
||
'
channels
'
;
this
.
_crossDomain
=
Utils
.
isCrossDomainUrl
(
getPublisherUrl
(
this
));
for
(
var
i
=
0
;
i
<
this
.
modes
.
length
;
i
++
)
{
try
{
...
...
@@ -1077,7 +1094,7 @@ Authors: Wandenberg Peixoto <wandenberg@gmail.com>, Rogério Carvalho Schneider
this
.
wrapper
.
sendMessage
(
message
);
if
(
successCallback
)
{
successCallback
();
}
}
else
{
Ajax
.
post
({
url
:
getPublisherUrl
(
this
),
data
:
message
,
success
:
successCallback
,
error
:
errorCallback
});
Ajax
.
post
({
url
:
getPublisherUrl
(
this
),
data
:
message
,
success
:
successCallback
,
error
:
errorCallback
,
crossDomain
:
this
.
_crossDomain
});
}
}
};
...
...
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