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
347a76ad
Commit
347a76ad
authored
Dec 19, 2010
by
Wandenberg Peixoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sample chat application
parent
95a85754
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
538 additions
and
0 deletions
+538
-0
chat.html
misc/examples/chat.html
+99
-0
jquery-1.4.2.min.js
misc/examples/js/jquery-1.4.2.min.js
+154
-0
log4js.js
misc/examples/js/log4js.js
+26
-0
pushstream.js
misc/examples/js/pushstream.js
+259
-0
No files found.
misc/examples/chat.html
0 → 100644
View file @
347a76ad
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta
http-equiv=
"Content-type"
content=
"text/html; charset=utf-8"
/>
<title>
Chat - Push Stream Module Example
</title>
</head>
<body>
<form
action=
"/pub"
method=
"POST"
>
<p>
<span
style=
"display: block; float: left; width: 55px;"
>
satus:
</span>
<span
class=
"online"
style=
"display:none; color:green"
>
online
</span>
<span
class=
"offline"
style=
"display:block; color:red"
>
offline
</span>
</p>
<p>
<label
for=
"room"
>
Room:
</label>
<input
type=
"text"
name=
"room"
value=
"example"
id=
"room"
/>
</p>
<p>
<label
for=
"nick"
>
Nick:
</label>
<input
type=
"text"
name=
"nick"
value=
""
id=
"nick"
/>
</p>
<p>
<label
for=
"chat"
>
Chat:
</label>
<textarea
name=
"chat"
rows=
"8"
cols=
"40"
id=
"chat"
readonly=
"readonly"
></textarea>
</p>
<p>
<label
for=
"message"
>
Text:
</label>
<textarea
name=
"message"
rows=
"2"
cols=
"40"
id=
"message"
></textarea>
</p>
<p><input
type=
"submit"
value=
"Send"
id=
"sendButton"
/></p>
</form>
<script
src=
"js/jquery-1.4.2.min.js"
type=
"text/javascript"
language=
"javascript"
charset=
"utf-8"
></script>
<script
src=
"js/log4js.js"
type=
"text/javascript"
language=
"javascript"
charset=
"utf-8"
></script>
<script
src=
"js/pushstream.js"
type=
"text/javascript"
language=
"javascript"
charset=
"utf-8"
></script>
<script
type=
"text/javascript"
language=
"javascript"
charset=
"utf-8"
>
//
<!
[
CDATA
[
$
(
function
()
{
function
onSendText
()
{
$
(
"
#message
"
).
val
(
''
);
};
function
_manageEvent
(
eventMessage
)
{
if
(
eventMessage
!=
''
)
{
var
values
=
$
.
parseJSON
(
eventMessage
);
var
line
=
values
.
nick
+
'
:
'
+
values
.
text
;
if
(
$
(
"
#chat
"
).
val
()
==
''
)
{
$
(
"
#chat
"
).
val
(
line
);
}
else
{
$
(
"
#chat
"
).
val
(
line
+
'
\n
'
+
$
(
"
#chat
"
).
val
());
}
}
};
function
_statuschanged
()
{
if
(
PushStream
.
status
==
5
)
{
$
(
"
.offline
"
).
hide
();
$
(
"
.online
"
).
show
();
}
else
{
$
(
"
.online
"
).
hide
();
$
(
"
.offline
"
).
show
();
}
};
$
(
"
#room
"
).
change
(
function
(){
if
(
PushStream
.
status
==
5
)
{
PushStream
.
disconnect
();
}
$
(
"
#chat
"
).
val
(
''
);
PushStream
.
joinChannel
(
$
(
"
#room
"
).
val
(),
10
);
PushStream
.
connect
();
});
$
(
"
#sendButton
"
).
click
(
function
(){
if
((
$
(
"
#nick
"
).
val
()
!=
""
)
&&
(
$
(
"
#message
"
).
val
()
!=
""
)
&&
(
$
(
"
#room
"
).
val
()
!=
""
))
{
$
.
post
(
'
/pub?id=
'
+
$
(
"
#room
"
).
val
(),
'
{"nick":"
'
+
$
(
"
#nick
"
).
val
()
+
'
", "text":"
'
+
$
(
"
#message
"
).
val
()
+
'
"}
'
,
onSendText
);
}
else
{
alert
(
"
nick, room and text are required
"
);
}
return
false
;
});
var
now
=
new
Date
();
var
_hostId
=
(
now
.
getTime
()
+
""
+
(
Math
.
random
()
*
10000
)).
replace
(
'
.
'
,
''
);
PushStream
.
host
=
window
.
location
.
hostname
;
PushStream
.
port
=
window
.
location
.
port
;
PushStream
.
hostid
=
_hostId
;
PushStream
.
registerEventCallback
(
"
process
"
,
_manageEvent
);
PushStream
.
registerEventCallback
(
"
statuschanged
"
,
_statuschanged
);
PushStream
.
joinChannel
(
$
(
"
#room
"
).
val
(),
10
);
PushStream
.
connect
();
});
// ]]>
</script>
</body>
</html>
misc/examples/js/jquery-1.4.2.min.js
0 → 100644
View file @
347a76ad
This diff is collapsed.
Click to expand it.
misc/examples/js/log4js.js
0 → 100644
View file @
347a76ad
Log4js
=
{
logLevel
:
'
error
'
,
/* debug, info, error */
logOutputId
:
'
Log4jsLogOutput
'
,
debug
:
function
(
logstr
)
{
Log4js
.
_log
(
logstr
,
'
debug
'
);
},
info
:
function
(
logstr
)
{
Log4js
.
_log
(
logstr
,
'
info
'
);
},
error
:
function
(
logstr
)
{
Log4js
.
_log
(
logstr
,
'
error
'
);
},
_log
:
function
(
logstr
,
level
)
{
if
((
Log4js
.
logLevel
===
level
)
||
(
'
error
'
===
level
)
||
(
Log4js
.
logLevel
===
'
debug
'
)
)
{
if
(
window
.
console
)
{
window
.
console
.
log
(
logstr
);
}
else
if
(
document
.
getElementById
(
Log4js
.
logOutputId
))
{
document
.
getElementById
(
Log4js
.
logOutputId
).
innerHTML
+=
logstr
+
"
<br/>
"
;
}
}
}
};
misc/examples/js/pushstream.js
0 → 100644
View file @
347a76ad
PushStream
=
{
callbacks
:
{
process
:
function
()
{},
reset
:
function
()
{},
eof
:
function
()
{},
statuschanged
:
function
()
{}
},
host
:
null
,
port
:
80
,
hostid
:
null
,
status
:
0
,
channelcount
:
0
,
channels
:
{},
lastrequest
:
0
,
frameref
:
null
,
frameloadtimer
:
null
,
frameloadingtimeout
:
15000
,
pingtimer
:
null
,
pingingtimeout
:
30000
,
reconnecttimer
:
null
,
reconnecttimeout
:
3000
,
checkChannelAvailabilityInterval
:
60000
,
backtrackDefault
:
10
,
mode
:
'
iframe
'
,
connect
:
function
()
{
Log4js
.
debug
(
'
entering connect
'
);
if
(
!
PushStream
.
host
)
throw
"
PushStream host not specified
"
;
if
(
isNaN
(
PushStream
.
port
))
throw
"
PushStream port not specified
"
;
if
(
!
PushStream
.
channelcount
)
throw
"
No channels specified
"
;
if
(
!
PushStream
.
hostid
)
PushStream
.
hostid
=
t
+
""
+
Math
.
floor
(
Math
.
random
()
*
1000000
);
document
.
domain
=
PushStream
.
extract_xss_domain
(
document
.
domain
);
if
(
PushStream
.
status
)
PushStream
.
disconnect
();
PushStream
.
setStatus
(
1
);
var
now
=
new
Date
();
var
t
=
now
.
getTime
();
PushStream
.
loadFrame
(
PushStream
.
getSubsUrl
());
PushStream
.
lastrequest
=
t
;
Log4js
.
debug
(
'
leaving connect
'
);
},
reconnect
:
function
(
interval
)
{
if
(
PushStream
.
status
!=
6
)
{
PushStream
.
reconnecttimer
=
setTimeout
(
PushStream
.
connect
,
interval
||
PushStream
.
reconnecttimeout
);
}
},
disconnect
:
function
()
{
Log4js
.
debug
(
'
entering disconnect
'
);
if
(
PushStream
.
status
)
{
PushStream
.
clearPingtimer
();
PushStream
.
clearFrameloadtimer
();
PushStream
.
clearReconnecttimer
();
if
(
typeof
CollectGarbage
==
'
function
'
)
CollectGarbage
();
if
(
PushStream
.
status
!=
6
)
PushStream
.
setStatus
(
0
);
Log4js
.
info
(
"
Disconnected
"
);
}
Log4js
.
debug
(
'
leaving disconnect
'
);
},
joinChannel
:
function
(
channelname
,
backtrack
)
{
Log4js
.
debug
(
'
entering joinChannel
'
);
if
(
typeof
(
PushStream
.
channels
[
channelname
])
!=
"
undefined
"
)
throw
"
Cannot join channel
"
+
channelname
+
"
: already subscribed
"
;
PushStream
.
channels
[
channelname
]
=
{
backtrack
:
backtrack
,
lastmsgreceived
:
-
1
};
Log4js
.
info
(
"
Joined channel
"
+
channelname
);
PushStream
.
channelcount
++
;
if
(
PushStream
.
status
!=
0
)
PushStream
.
connect
();
Log4js
.
debug
(
'
leaving joinChannel
'
);
},
loadFrame
:
function
(
url
)
{
try
{
if
(
!
PushStream
.
frameref
)
{
var
transferDoc
=
new
ActiveXObject
(
"
htmlfile
"
);
PushStream
.
frameref
=
transferDoc
;
}
PushStream
.
frameref
.
open
();
PushStream
.
frameref
.
write
(
"
<html><script>
"
);
PushStream
.
frameref
.
write
(
"
document.domain=
\"
"
+
(
document
.
domain
)
+
"
\"
;
"
);
PushStream
.
frameref
.
write
(
"
</
"
+
"
script></html>
"
);
PushStream
.
frameref
.
parentWindow
.
PushStream
=
PushStream
;
PushStream
.
frameref
.
close
();
var
ifrDiv
=
PushStream
.
frameref
.
createElement
(
"
div
"
);
PushStream
.
frameref
.
appendChild
(
ifrDiv
);
ifrDiv
.
innerHTML
=
"
<iframe src=
\"
"
+
url
+
"
\"
onload=
\"
PushStream.frameload();
\"
></iframe>
"
;
}
catch
(
e
)
{
if
(
!
PushStream
.
frameref
)
{
var
ifr
=
document
.
createElement
(
"
IFRAME
"
);
ifr
.
style
.
width
=
"
10px
"
;
ifr
.
style
.
height
=
"
10px
"
;
ifr
.
style
.
border
=
"
none
"
;
ifr
.
style
.
position
=
"
absolute
"
;
ifr
.
style
.
top
=
"
-10px
"
;
ifr
.
style
.
marginTop
=
"
-10px
"
;
ifr
.
style
.
zIndex
=
"
-20
"
;
ifr
.
PushStream
=
PushStream
;
ifr
.
onload
=
PushStream
.
frameload
;
document
.
body
.
appendChild
(
ifr
);
PushStream
.
frameref
=
ifr
;
}
PushStream
.
frameref
.
setAttribute
(
"
src
"
,
url
);
}
Log4js
.
info
(
"
Loading URL '
"
+
url
+
"
' into frame...
"
);
PushStream
.
frameloadtimer
=
setTimeout
(
PushStream
.
frameloadtimeout
,
PushStream
.
frameloadingtimeout
);
},
frameload
:
function
()
{
Log4js
.
info
(
"
Frame loaded whitout streaming
"
);
PushStream
.
clearFrameloadtimer
();
PushStream
.
setStatus
(
8
);
PushStream
.
reconnect
(
PushStream
.
checkChannelAvailabilityInterval
);
},
frameloadtimeout
:
function
()
{
Log4js
.
info
(
"
Frame load timeout
"
);
PushStream
.
clearFrameloadtimer
();
PushStream
.
setStatus
(
3
);
PushStream
.
reconnect
(
PushStream
.
frameloadingtimeout
);
},
register
:
function
(
ifr
)
{
PushStream
.
clearFrameloadtimer
();
ifr
.
p
=
PushStream
.
process
;
ifr
.
r
=
PushStream
.
reset
;
ifr
.
eof
=
PushStream
.
eof
;
PushStream
.
setStatus
(
4
);
PushStream
.
setPingtimer
();
Log4js
.
info
(
"
Frame registered
"
);
},
pingtimeout
:
function
()
{
Log4js
.
info
(
"
Ping timeout
"
);
PushStream
.
setStatus
(
7
);
PushStream
.
clearPingtimer
();
PushStream
.
reconnect
();
},
process
:
function
(
id
,
channel
,
data
)
{
Log4js
.
info
(
"
Message received
"
);
PushStream
.
setStatus
(
5
);
PushStream
.
clearPingtimer
();
if
(
id
==
-
1
)
{
Log4js
.
debug
(
"
Ping
"
);
}
else
if
(
typeof
(
PushStream
.
channels
[
channel
])
!=
"
undefined
"
)
{
Log4js
.
debug
(
"
Message
"
+
id
+
"
received on channel
"
+
channel
+
"
(last id on channel:
"
+
PushStream
.
channels
[
channel
].
lastmsgreceived
+
"
)
\n
"
+
data
);
PushStream
.
callbacks
[
"
process
"
](
data
);
PushStream
.
channels
[
channel
].
lastmsgreceived
=
id
;
}
PushStream
.
setPingtimer
();
},
reset
:
function
()
{
if
(
PushStream
.
status
!=
6
)
{
Log4js
.
info
(
"
Stream reset
"
);
PushStream
.
callbacks
[
"
reset
"
]();
PushStream
.
reconnect
();
}
},
eof
:
function
()
{
Log4js
.
info
(
"
Received end of stream, will not reconnect
"
);
PushStream
.
callbacks
[
"
eof
"
]();
PushStream
.
setStatus
(
6
);
PushStream
.
disconnect
();
},
setStatus
:
function
(
newstatus
)
{
// Statuses: 0 = Uninitialised,
// 1 = Loading stream,
// 2 = Loading controller frame,
// 3 = Controller frame timeout, retrying.
// 4 = Controller frame loaded and ready
// 5 = Receiving data
// 6 = End of stream, will not reconnect
// 7 = Ping Timeout
// 8 = Frame loaded whitout streaming, channel problably empty or not exists
if
(
PushStream
.
status
!=
newstatus
)
{
Log4js
.
info
(
'
PushStream.status
'
+
newstatus
);
PushStream
.
status
=
newstatus
;
PushStream
.
callbacks
[
"
statuschanged
"
](
newstatus
);
}
},
registerEventCallback
:
function
(
evt
,
funcRef
)
{
Function
.
prototype
.
andThen
=
function
(
g
)
{
var
f
=
this
;
var
a
=
PushStream
.
arguments
return
function
(
args
)
{
f
(
a
);
g
(
args
);
}
};
if
(
typeof
PushStream
.
callbacks
[
evt
]
==
"
function
"
)
{
PushStream
.
callbacks
[
evt
]
=
(
PushStream
.
callbacks
[
evt
]).
andThen
(
funcRef
);
}
else
{
PushStream
.
callbacks
[
evt
]
=
funcRef
;
}
},
extract_xss_domain
:
function
(
old_domain
)
{
if
(
old_domain
.
match
(
/^
(\d{1,3}\.){3}\d{1,3}
$/
))
return
old_domain
;
domain_pieces
=
old_domain
.
split
(
'
.
'
);
return
domain_pieces
.
slice
(
-
2
,
domain_pieces
.
length
).
join
(
"
.
"
);
},
getSubsUrl
:
function
()
{
var
surl
=
"
http://
"
+
PushStream
.
host
+
((
PushStream
.
port
==
80
)?
""
:
"
:
"
+
PushStream
.
port
)
+
"
/sub
"
;
for
(
var
c
in
PushStream
.
channels
)
{
var
channelinfo
=
"
/
"
+
c
+
PushStream
.
getBacktrack
(
c
);
surl
+=
channelinfo
;
}
var
now
=
new
Date
();
surl
+=
"
?nc=
"
+
now
.
getTime
();
return
surl
;
},
getBacktrack
:
function
(
channelName
)
{
var
channel
=
PushStream
.
channels
[
channelName
];
if
(
channel
.
backtrack
!=
0
)
{
var
backtrack
=
"
.b
"
if
(
channel
.
backtrack
>
0
)
{
backtrack
+=
channel
.
backtrack
}
else
{
backtrack
+=
PushStream
.
backtrackDefault
;
}
return
backtrack
;
}
else
return
""
;
},
clearPingtimer
:
function
()
{
if
(
PushStream
.
pingtimer
)
{
clearTimeout
(
PushStream
.
pingtimer
);
PushStream
.
pingtimer
=
null
;
}
},
setPingtimer
:
function
()
{
PushStream
.
clearPingtimer
();
PushStream
.
pingtimer
=
setTimeout
(
PushStream
.
pingtimeout
,
PushStream
.
pingingtimeout
);
},
clearFrameloadtimer
:
function
()
{
if
(
PushStream
.
frameloadtimer
)
{
if
(
PushStream
.
frameloadtimer
)
clearTimeout
(
PushStream
.
frameloadtimer
);
PushStream
.
frameloadtimer
=
null
;
}
},
clearReconnecttimer
:
function
()
{
if
(
PushStream
.
reconnecttimer
)
{
if
(
PushStream
.
reconnecttimer
)
clearTimeout
(
PushStream
.
reconnecttimer
);
PushStream
.
reconnecttimer
=
null
;
}
}
};
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