Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
brainfood
/
ofbiz-comet-messenger
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
6cb0abfd
authored
2015-04-27 18:08:39 -0500
by
Ean Schuessler
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge branch 'BF-5084' of /home/git/repositories/brainfood/ofbiz-comet-messenger
2 parents
b8a609a2
565ebb2e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
13 deletions
src/com/brainfood/ofbiz/CometMessengerServlet.java
webapp/scripts/messenger.js
src/com/brainfood/ofbiz/CometMessengerServlet.java
View file @
6cb0abf
...
...
@@ -79,6 +79,7 @@ public class CometMessengerServlet extends HttpServlet implements CometProcessor
response
.
setHeader
(
"X-Accel-Buffering"
,
"No"
);
if
(
event
.
getEventType
()
==
CometEvent
.
EventType
.
BEGIN
)
{
Debug
.
logInfo
(
"Begin for session: "
+
request
.
getSession
(
true
).
getId
(),
module
);
event
.
getHttpServletRequest
().
setAttribute
(
"org.apache.tomcat.comet.timeout"
,
new
Integer
(
0xFFFFFFFF
));
PrintWriter
writer
=
response
.
getWriter
();
writer
.
println
(
"{\"channel\":\"system\", \"message\":\"CONNECT\"}"
);
writer
.
flush
();
...
...
webapp/scripts/messenger.js
View file @
6cb0abf
define
([],
function
()
{
var
listeners
=
[]
;
var
channels
=
{}
;
var
messenger
=
{
process
:
function
()
{
var
self
=
this
;
var
url
=
"/comet/messenger"
var
request
=
new
XMLHttpRequest
();
var
responseLength
=
0
;
...
...
@@ -10,22 +11,19 @@ define([], function() {
request
.
onreadystatechange
=
function
()
{
if
(
request
.
readyState
==
3
||
request
.
readyState
==
4
)
{
if
(
request
.
status
==
200
){
if
(
request
.
onreadystatechange
)
{
request
.
onreadystatechange
=
null
;
}
if
(
request
.
responseText
)
{
var
newText
=
request
.
responseText
.
substr
(
responseLength
);
if
(
newText
.
length
>
0
)
{
for
(
var
i
=
0
;
i
<
listeners
.
length
;
i
++
)
{
listeners
[
i
](
newText
);
}
self
.
deliver
(
newText
);
}
responseLength
=
request
.
responseText
.
length
;
}
}
if
(
request
.
readyState
==
4
)
{
// Request is complete. Remove existing callback.
request
.
onreadystatechange
=
null
;
if
(
request
.
status
==
200
)
{
messenger
.
process
(
);
setTimeout
(
function
()
{
messenger
.
process
();
},
500
);
}
else
{
console
.
log
(
'Error, retrying in 5 seconds'
);
setTimeout
(
function
()
{
messenger
.
process
();
},
5000
);
...
...
@@ -35,14 +33,33 @@ define([], function() {
};
request
.
send
(
null
);
},
deliver
:
function
(
newText
)
{
try
{
var
json
=
JSON
.
parse
(
newText
);
if
(
json
.
channel
&&
channels
[
json
.
channel
])
{
for
(
var
i
=
0
;
i
<
channels
[
json
.
channel
].
length
;
i
++
)
{
channels
[
json
.
channel
][
i
](
json
);
}
}
}
catch
(
err
)
{
console
.
log
(
'Error processing COMETd message'
,
newText
,
err
);
}
},
addListener
:
function
(
listener
)
{
listeners
.
push
(
listener
);
this
.
addListener
(
'ALL'
,
listener
);
},
removeListener
:
function
(
listener
)
{
var
index
=
listeners
.
indexOf
(
listener
);
if
(
index
>
-
1
)
{
array
.
splice
(
index
,
1
);
addListener
:
function
(
channel
,
listener
)
{
if
(
!
channels
[
channel
])
{
channels
[
channel
]
=
[];
}
channels
[
channel
].
push
(
listener
);
},
removeListener
:
function
(
listener
)
{
this
.
removeListener
(
'ALL'
,
listener
);
},
removeListener
:
function
(
channel
,
listener
)
{
console
.
log
(
'Remove listener from channel'
,
listener
,
channel
);
}
}
messenger
.
process
();
...
...
Please
register
or
sign in
to post a comment