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
28d810db
Commit
28d810db
authored
Aug 25, 2013
by
Wandenberg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wrap some javascript methods on a Utils class to make tests easier
parent
7283136d
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
271 additions
and
25 deletions
+271
-25
Rakefile
misc/Rakefile
+1
-3
pushstream.js
misc/js/pushstream.js
+14
-12
PushStreamSpec.js
misc/spec/javascripts/PushStreamSpec.js
+79
-10
UtilsSpec.js
misc/spec/javascripts/UtilsSpec.js
+177
-0
No files found.
misc/Rakefile
View file @
28d810db
...
...
@@ -43,9 +43,7 @@ begin
destiny_path
=
File
.
dirname
(
file
).
gsub
(
/.*\/js\/?/
,
File
.
expand_path
(
'pushstream/js'
,
Dir
.
tmpdir
))
FileUtils
.
mkdir_p
(
destiny_path
)
content
=
File
.
read
file
content
.
gsub!
(
'(function (window, document, undefined) {'
,
''
)
content
.
gsub!
(
'if (window.PushStream) { return; }'
,
''
)
content
.
gsub!
(
'})(window, document);'
,
''
)
content
.
gsub!
(
'window.PushStream = PushStream;'
,
"window.PushStream = PushStream;
\n
window.Utils = Utils;"
)
File
.
open
(
File
.
join
(
destiny_path
,
File
.
basename
(
file
)),
'w'
)
{
|
f
|
f
.
write
content
}
end
end
...
...
misc/js/pushstream.js
View file @
28d810db
...
...
@@ -30,6 +30,8 @@
/* prevent duplicate declaration */
if
(
window
.
PushStream
)
{
return
;
}
var
Utils
=
{};
var
days
=
[
"
Sun
"
,
"
Mon
"
,
"
Tue
"
,
"
Wed
"
,
"
Thu
"
,
"
Fri
"
,
"
Sat
"
];
var
months
=
[
"
Jan
"
,
"
Feb
"
,
"
Mar
"
,
"
Apr
"
,
"
May
"
,
"
Jun
"
,
"
Jul
"
,
"
Aug
"
,
"
Sep
"
,
"
Oct
"
,
"
Nov
"
,
"
Dec
"
];
...
...
@@ -37,7 +39,7 @@
return
((
value
<
10
)
?
'
0
'
:
''
)
+
value
;
};
var
dateToUTCString
=
function
(
date
)
{
Utils
.
dateToUTCString
=
function
(
date
)
{
var
time
=
valueToTwoDigits
(
date
.
getUTCHours
())
+
'
:
'
+
valueToTwoDigits
(
date
.
getUTCMinutes
())
+
'
:
'
+
valueToTwoDigits
(
date
.
getUTCSeconds
());
return
days
[
date
.
getUTCDay
()]
+
'
,
'
+
valueToTwoDigits
(
date
.
getUTCDate
())
+
'
'
+
months
[
date
.
getUTCMonth
()]
+
'
'
+
date
.
getUTCFullYear
()
+
'
'
+
time
+
'
GMT
'
;
};
...
...
@@ -64,7 +66,7 @@
return
value
.
replace
(
/^
\s
*/
,
""
).
replace
(
/
\s
*$/
,
""
);
};
var
parseJSON
=
function
(
data
)
{
Utils
.
parseJSON
=
function
(
data
)
{
if
(
!
data
||
!
isString
(
data
))
{
return
null
;
}
...
...
@@ -310,10 +312,10 @@
return
(
text
)
?
window
.
unescape
(
text
)
:
''
;
};
var
parseMessage
=
function
(
messageText
,
keys
)
{
Utils
.
parseMessage
=
function
(
messageText
,
keys
)
{
var
msg
=
messageText
;
if
(
isString
(
messageText
))
{
msg
=
parseJSON
(
messageText
);
msg
=
Utils
.
parseJSON
(
messageText
);
}
var
message
=
{
...
...
@@ -377,7 +379,7 @@
return
url
;
};
var
extract_xss_domain
=
function
(
domain
)
{
Utils
.
extract_xss_domain
=
function
(
domain
)
{
// if domain is an ip address return it, else return ate least the last two parts of it
if
(
domain
.
match
(
/^
(\d{1,3}\.){3}\d{1,3}
$/
))
{
return
domain
;
...
...
@@ -407,7 +409,7 @@
/* common callbacks */
var
onmessageCallback
=
function
(
event
)
{
Log4js
.
info
(
"
[
"
+
this
.
type
+
"
] message received
"
,
arguments
);
var
message
=
parseMessage
(
event
.
data
,
this
.
pushstream
);
var
message
=
Utils
.
parseMessage
(
event
.
data
,
this
.
pushstream
);
this
.
pushstream
.
_onmessage
(
message
.
data
,
message
.
id
,
message
.
channel
,
message
.
eventid
,
true
);
};
...
...
@@ -526,7 +528,7 @@
StreamWrapper
.
prototype
=
{
connect
:
function
()
{
this
.
_closeCurrentConnection
();
var
domain
=
extract_xss_domain
(
this
.
pushstream
.
host
);
var
domain
=
Utils
.
extract_xss_domain
(
this
.
pushstream
.
host
);
try
{
document
.
domain
=
domain
;
}
catch
(
e
)
{
...
...
@@ -657,8 +659,8 @@
this
.
_closeCurrentConnection
();
this
.
connectionEnabled
=
true
;
this
.
xhrSettings
.
url
=
getSubscriberUrl
(
this
.
pushstream
,
this
.
pushstream
.
urlPrefixLongpolling
);
var
domain
=
extract_xss_domain
(
this
.
pushstream
.
host
);
var
currentDomain
=
extract_xss_domain
(
window
.
location
.
hostname
);
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
||
(
this
.
pushstream
.
useSSL
?
443
:
80
);
this
.
useJSONP
=
(
domain
!==
currentDomain
)
||
(
port
!==
currentPort
)
||
this
.
pushstream
.
longPollingUseJSONP
;
...
...
@@ -711,7 +713,7 @@
if
(
this
.
lastModified
===
null
)
{
var
date
=
new
Date
();
if
(
this
.
pushstream
.
secondsAgo
)
{
date
.
setTime
(
date
.
getTime
()
-
(
this
.
pushstream
.
secondsAgo
*
1000
));
}
this
.
lastModified
=
dateToUTCString
(
date
);
this
.
lastModified
=
Utils
.
dateToUTCString
(
date
);
}
if
(
!
this
.
pushstream
.
longPollingByHeaders
)
{
...
...
@@ -757,7 +759,7 @@
var
messages
=
isArray
(
responseText
)
?
responseText
:
responseText
.
split
(
"
\r\n
"
);
for
(
var
i
=
0
;
i
<
messages
.
length
;
i
++
)
{
if
(
messages
[
i
])
{
lastMessage
=
parseMessage
(
messages
[
i
],
this
.
pushstream
);
lastMessage
=
Utils
.
parseMessage
(
messages
[
i
],
this
.
pushstream
);
this
.
messagesQueue
.
push
(
lastMessage
);
if
(
!
this
.
pushstream
.
longPollingByHeaders
&&
lastMessage
.
time
)
{
this
.
etag
=
lastMessage
.
tag
;
...
...
@@ -820,7 +822,7 @@
this
.
wrappers
=
[];
this
.
wrapper
=
null
;
this
.
on
open
=
null
;
this
.
on
channeldeleted
=
null
;
this
.
onmessage
=
null
;
this
.
onerror
=
null
;
this
.
onstatuschange
=
null
;
...
...
misc/spec/javascripts/PushStreamSpec.js
View file @
28d810db
...
...
@@ -19,6 +19,12 @@ describe("PushStream", function() {
it
(
"
should define status code constants
"
,
function
()
{
expect
(
PushStream
.
CLOSED
).
toBeDefined
();
expect
(
PushStream
.
CONNECTING
).
toBeDefined
();
expect
(
PushStream
.
OPEN
).
toBeDefined
();
});
it
(
"
should has a PushStream instances manager
"
,
function
()
{
expect
(
PushStreamManager
).
toBeDefined
();
expect
(
PushStreamManager
instanceof
Array
).
toBeTruthy
();
});
});
...
...
@@ -45,20 +51,84 @@ describe("PushStream", function() {
expect
(
pushstream
.
readyState
).
toBe
(
PushStream
.
CLOSED
);
});
it
(
"
should use '/sub' as url prefix for stream
"
,
function
()
{
expect
(
pushstream
.
urlPrefixStream
).
toBe
(
'
/sub
'
);
describe
(
"
for operation timeouts
"
,
function
()
{
it
(
"
should has a connection timeout
"
,
function
()
{
expect
(
pushstream
.
timeout
).
toBe
(
15000
);
});
it
(
"
should has a ping message timeout
"
,
function
()
{
expect
(
pushstream
.
pingtimeout
).
toBe
(
30000
);
});
it
(
"
should has a reconnect interval, to be used when a timeout happens
"
,
function
()
{
expect
(
pushstream
.
reconnecttimeout
).
toBe
(
3000
);
});
it
(
"
should has a reconnect interval, to be used when a channel is unavailable
"
,
function
()
{
expect
(
pushstream
.
checkChannelAvailabilityInterval
).
toBe
(
60000
);
});
});
it
(
"
should use '/ev' as url prefix for event source
"
,
function
()
{
expect
(
pushstream
.
urlPrefixEventsource
).
toBe
(
'
/ev
'
);
describe
(
"
for url prefix
"
,
function
()
{
it
(
"
should use '/pub' for publish message
"
,
function
()
{
expect
(
pushstream
.
urlPrefixPublisher
).
toBe
(
'
/pub
'
);
});
it
(
"
should use '/sub' for stream
"
,
function
()
{
expect
(
pushstream
.
urlPrefixStream
).
toBe
(
'
/sub
'
);
});
it
(
"
should use '/ev' for event source
"
,
function
()
{
expect
(
pushstream
.
urlPrefixEventsource
).
toBe
(
'
/ev
'
);
});
it
(
"
should use '/lp' for long-polling
"
,
function
()
{
expect
(
pushstream
.
urlPrefixLongpolling
).
toBe
(
'
/lp
'
);
});
it
(
"
should use '/ws' for websocket
"
,
function
()
{
expect
(
pushstream
.
urlPrefixWebsocket
).
toBe
(
'
/ws
'
);
});
});
it
(
"
should use '/lp' as url prefix for long-polling
"
,
function
()
{
expect
(
pushstream
.
urlPrefixLongpolling
).
toBe
(
'
/lp
'
);
describe
(
"
for json keys
"
,
function
()
{
it
(
"
should has a key for 'id'
"
,
function
()
{
expect
(
pushstream
.
jsonIdKey
).
toBe
(
'
id
'
);
});
it
(
"
should has a key for 'channel'
"
,
function
()
{
expect
(
pushstream
.
jsonChannelKey
).
toBe
(
'
channel
'
);
});
it
(
"
should has a key for 'text'
"
,
function
()
{
expect
(
pushstream
.
jsonDataKey
).
toBe
(
'
text
'
);
});
it
(
"
should has a key for 'tag'
"
,
function
()
{
expect
(
pushstream
.
jsonTagKey
).
toBe
(
'
tag
'
);
});
it
(
"
should has a key for 'time'
"
,
function
()
{
expect
(
pushstream
.
jsonTimeKey
).
toBe
(
'
time
'
);
});
it
(
"
should has a key for 'eventid'
"
,
function
()
{
expect
(
pushstream
.
jsonEventIdKey
).
toBe
(
'
eventid
'
);
});
});
it
(
"
should use '/ws' as url prefix for websocket
"
,
function
()
{
expect
(
pushstream
.
urlPrefixWebsocket
).
toBe
(
'
/ws
'
);
describe
(
"
for arguments names
"
,
function
()
{
it
(
"
should has a argument for 'tag'
"
,
function
()
{
expect
(
pushstream
.
longPollingTagArgument
).
toBe
(
'
tag
'
);
});
it
(
"
should has a argument for 'time'
"
,
function
()
{
expect
(
pushstream
.
longPollingTimeArgument
).
toBe
(
'
time
'
);
});
it
(
"
should has a argument for 'channels'
"
,
function
()
{
expect
(
pushstream
.
channelsArgument
).
toBe
(
'
channels
'
);
});
});
it
(
"
should has all modes availables
"
,
function
()
{
...
...
@@ -66,7 +136,7 @@ describe("PushStream", function() {
});
it
(
"
should define callbacks attributes
"
,
function
()
{
expect
(
pushstream
.
on
open
).
toBeDefined
();
expect
(
pushstream
.
on
channeldeleted
).
toBeDefined
();
expect
(
pushstream
.
onmessage
).
toBeDefined
();
expect
(
pushstream
.
onerror
).
toBeDefined
();
expect
(
pushstream
.
onstatuschange
).
toBeDefined
();
...
...
@@ -147,5 +217,4 @@ describe("PushStream", function() {
});
});
});
});
misc/spec/javascripts/
PushStream
UtilsSpec.js
→
misc/spec/javascripts/UtilsSpec.js
View file @
28d810db
This diff is collapsed.
Click to expand it.
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