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
dce9048a
Commit
dce9048a
authored
Nov 11, 2011
by
Wandenberg Peixoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding sendMessage method on javascript library
parent
73100936
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
8 deletions
+49
-8
chat.html
misc/examples/chat.html
+1
-1
chat_longpolling.html
misc/examples/chat_longpolling.html
+1
-1
pushstream.js
misc/js/pushstream.js
+47
-6
No files found.
misc/examples/chat.html
View file @
dce9048a
...
...
@@ -92,7 +92,7 @@
$
(
"
#sendButton
"
).
click
(
function
(){
if
((
$
(
"
#nick
"
).
val
()
!=
""
)
&&
(
$
(
"
#message
"
).
val
()
!=
""
)
&&
(
$
(
"
#room
"
).
val
()
!=
""
))
{
$
.
post
(
'
/pub?id=
'
+
$
(
"
#room
"
).
val
(),
'
{"nick":"
'
+
$
(
"
#nick
"
).
val
()
+
'
", "text":"
'
+
$
(
"
#message
"
).
val
()
+
'
"}
'
,
onSendText
);
pushstream
.
sendMessage
(
'
{"nick":"
'
+
$
(
"
#nick
"
).
val
()
+
'
", "text":"
'
+
$
(
"
#message
"
).
val
()
+
'
"}
'
,
onSendText
);
}
else
{
alert
(
"
nick, room and text are required
"
);
}
...
...
misc/examples/chat_longpolling.html
View file @
dce9048a
...
...
@@ -92,7 +92,7 @@
$
(
"
#sendButton
"
).
click
(
function
(){
if
((
$
(
"
#nick
"
).
val
()
!=
""
)
&&
(
$
(
"
#message
"
).
val
()
!=
""
)
&&
(
$
(
"
#room
"
).
val
()
!=
""
))
{
$
.
post
(
'
/pub?id=
'
+
$
(
"
#room
"
).
val
(),
'
{"nick":"
'
+
$
(
"
#nick
"
).
val
()
+
'
", "text":"
'
+
$
(
"
#message
"
).
val
()
+
'
"}
'
,
onSendText
);
pushstream
.
sendMessage
(
'
{"nick":"
'
+
$
(
"
#nick
"
).
val
()
+
'
", "text":"
'
+
$
(
"
#message
"
).
val
()
+
'
"}
'
,
onSendText
);
}
else
{
alert
(
"
nick, room and text are required
"
);
}
...
...
misc/js/pushstream.js
View file @
dce9048a
...
...
@@ -53,7 +53,7 @@
};
var
Ajax
=
{
getXHRObject
:
function
()
{
_
getXHRObject
:
function
()
{
var
xhr
=
false
;
try
{
xhr
=
new
window
.
ActiveXObject
(
"
Msxml2.XMLHTTP
"
);
}
catch
(
e1
)
{
...
...
@@ -67,15 +67,15 @@
}
return
xhr
;
},
load
:
function
(
settings
)
{
_send
:
function
(
settings
,
post
)
{
settings
=
settings
||
{};
var
cache
=
settings
.
cache
||
true
;
var
xhr
=
Ajax
.
getXHRObject
();
var
xhr
=
Ajax
.
_
getXHRObject
();
if
(
!
xhr
||!
settings
.
url
)
return
;
var
url
=
settings
.
url
+
((
cache
)
?
""
:
settings
.
url
+
((
settings
.
url
.
indexOf
(
"
?
"
)
+
1
)
?
"
&
"
:
"
?
"
)
+
"
_=
"
+
new
Date
().
getTime
());
var
url
=
settings
.
url
+
((
cache
||
post
)
?
""
:
settings
.
url
+
((
settings
.
url
.
indexOf
(
"
?
"
)
+
1
)
?
"
&
"
:
"
?
"
)
+
"
_=
"
+
new
Date
().
getTime
());
xhr
.
open
(
"
GET
"
,
url
,
true
);
xhr
.
open
(
((
post
)
?
"
POST
"
:
"
GET
"
)
,
url
,
true
);
xhr
.
onreadystatechange
=
function
()
{
if
(
xhr
.
readyState
==
4
)
{
...
...
@@ -88,8 +88,19 @@
}
}
if
(
settings
.
beforeSend
)
settings
.
beforeSend
(
xhr
);
xhr
.
send
(
null
);
if
(
post
)
{
xhr
.
setRequestHeader
(
"
Accept
"
,
"
application/json
"
);
xhr
.
setRequestHeader
(
"
Content-type
"
,
"
application/x-www-form-urlencoded
"
);
}
xhr
.
send
((
post
)
?
settings
.
data
:
null
);
return
xhr
;
},
load
:
function
(
settings
)
{
return
Ajax
.
_send
(
settings
,
false
);
},
post
:
function
(
settings
)
{
return
Ajax
.
_send
(
settings
,
true
);
}
};
...
...
@@ -117,6 +128,22 @@
return
url
;
};
var
getPublisherUrl
=
function
(
pushstream
)
{
var
channel
=
""
;
var
url
=
(
pushstream
.
useSSL
)
?
"
https://
"
:
"
http://
"
;
url
+=
pushstream
.
host
;
url
+=
((
pushstream
.
port
!=
80
)
&&
(
pushstream
.
port
!=
443
))
?
(
"
:
"
+
pushstream
.
port
)
:
""
;
url
+=
pushstream
.
urlPrefixPublisher
;
for
(
var
channelName
in
pushstream
.
channels
)
{
if
(
!
pushstream
.
channels
.
hasOwnProperty
||
pushstream
.
channels
.
hasOwnProperty
(
channelName
))
{
channel
=
channelName
;
break
;
}
}
url
+=
"
?id=
"
+
channel
;
return
url
;
};
var
extract_xss_domain
=
function
(
domain
)
{
// if domain is a ip address return it, else return the last two parts of it
return
(
domain
.
match
(
/^
(\d{1,3}\.){3}\d{1,3}
$/
))
?
domain
:
domain
.
split
(
'
.
'
).
slice
(
-
2
).
join
(
'
.
'
);
...
...
@@ -409,6 +436,7 @@
this
.
reconnecttimer
=
null
;
this
.
urlPrefixPublisher
=
settings
.
urlPrefixPublisher
||
'
/pub
'
;
this
.
urlPrefixStream
=
settings
.
urlPrefixStream
||
'
/sub
'
;
this
.
urlPrefixEventsource
=
settings
.
urlPrefixEventsource
||
'
/ev
'
;
this
.
urlPrefixLongpolling
=
settings
.
urlPrefixLongpolling
||
'
/lp
'
;
...
...
@@ -562,9 +590,22 @@
Log4js
.
info
(
"
trying to reconnect in
"
,
timeout
);
this
.
reconnecttimer
=
setTimeout
(
linker
(
this
.
_connect
,
this
),
timeout
);
}
},
sendMessage
:
function
(
message
,
successCallback
,
errorCallback
)
{
if
(
this
.
wrapper
.
type
===
WebSocketWrapper
.
TYPE
)
{
this
.
wrapper
.
sendMessage
(
message
);
if
(
successCallback
)
successCallback
();
}
else
{
Ajax
.
post
({
url
:
getPublisherUrl
(
this
),
data
:
message
,
success
:
successCallback
,
error
:
errorCallback
});
}
}
};
PushStream
.
sendMessage
=
function
(
url
,
message
,
successCallback
,
errorCallback
)
{
Ajax
.
post
({
url
:
url
,
data
:
message
,
success
:
successCallback
,
error
:
errorCallback
});
};
// to make server header template more clear, it calls register and
// by a url parameter we find the stream wrapper instance
PushStream
.
register
=
function
(
iframe
)
{
...
...
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