Commit 022a5c41 authored by Wandenberg's avatar Wandenberg

documentation review

parent 746e14a9
h1(#changelog). Changelog h1(#changelog). Changelog
* Added support to use variables as value on push_stream_allowed_origins directive
* Removed global variables to allow have more than one http block on the same Nginx instance
* Added initial support to send binary data
* Added support to get old messages using time and tag to all wrappers on pushstream.js
* Added push_stream_timeout_with_body directive to indicate whether send a full message on timed out long polling connections, or not * Added push_stream_timeout_with_body directive to indicate whether send a full message on timed out long polling connections, or not
* Removed default value from push_stream_padding_by_user_agent directive, it was "[A|a]ndroid 2,4097,4097:[S|s]afari,1025,0" * Removed default value from push_stream_padding_by_user_agent directive, it was "[A|a]ndroid 2,4097,4097:[S|s]afari,1025,0"
* Change the publish message action through a WebSocket connection to add the message to all subscribed channels * Change the publish message action through a WebSocket connection to add the message to all subscribed channels
...@@ -15,6 +19,7 @@ h1(#changelog). Changelog ...@@ -15,6 +19,7 @@ h1(#changelog). Changelog
** longPollingByHeaders -> messagesControlByArgument (value must be changed appropriately) ** longPollingByHeaders -> messagesControlByArgument (value must be changed appropriately)
** reconnecttimeout -> reconnectOnTimeoutInterval ** reconnecttimeout -> reconnectOnTimeoutInterval
** checkChannelAvailabilityInterval -> reconnectOnChannelUnavailableInterval ** checkChannelAvailabilityInterval -> reconnectOnChannelUnavailableInterval
** secondsAgo -> messagesPublishedAfter
* Removed some javascript client configurations * Removed some javascript client configurations
** longPollingInterval ** longPollingInterval
* Fix lazy reload * Fix lazy reload
......
This diff is collapsed.
...@@ -8,13 +8,15 @@ h2(#push_stream_channels_statistics). push_stream_channels_statistics <a name="p ...@@ -8,13 +8,15 @@ h2(#push_stream_channels_statistics). push_stream_channels_statistics <a name="p
*release version:* _0.2.0_ *release version:* _0.2.0_
Defines a location as a source of statistics. You can use this location to get statistics about a specific, group or all channels, in a resumed ou summarized way. Defines a location as a source of statistics. You can use this location to get statistics about a specific, group or all channels, in a resumed or summarized way.
To get statistics about all channels in a summarized way you have to make a GET in this location without specify a name in the push_stream_channels_path directive. To get statistics about:
To get statistics about all channels in a detailed way you have to specify "ALL" in the push_stream_channels_path. - all channels in a summarized way, you have to make a GET in this location without specify a name in the push_stream_channels_path directive.
To get statistics about prefixed channels in a detailed way you have to specify "_prefix_*" in the push_stream_channels_path. - all channels in a detailed way, you have to specify "ALL" in the push_stream_channels_path.
To get statistics about a channel you have to specify the name in the push_stream_channels_path. - prefixed channels in a detailed way, you have to specify "_prefix_ *" in the push_stream_channels_path.
- a channel, you have to specify the name in the push_stream_channels_path.
- some channels, you have to specify their names in the push_stream_channels_path.
You can get statistics in the formats plain, xml, yaml and json. The default is json, to change this behavior you can use *Accept* header parameter passing values like "text/plain", "application/xml", "application/yaml" and "application/json" respectivelly. You can get statistics in the formats plain, xml, yaml and json. The default is json, to change this behavior you can use *Accept* header parameter passing values like "text/plain", "application/xml", "application/yaml" and "application/json" respectively.
<pre> <pre>
location /channels-stats { location /channels-stats {
...@@ -26,4 +28,5 @@ You can get statistics in the formats plain, xml, yaml and json. The default is ...@@ -26,4 +28,5 @@ You can get statistics in the formats plain, xml, yaml and json. The default is
# /channels-stats?id=ALL -> get statistics about all channels in a detailed way # /channels-stats?id=ALL -> get statistics about all channels in a detailed way
# /channels-stats?id=channel_* -> get statistics about all channels which starts with 'channel_' # /channels-stats?id=channel_* -> get statistics about all channels which starts with 'channel_'
# /channels-stats?id=channel_id -> get statistics about a channel # /channels-stats?id=channel_id -> get statistics about a channel
# /channels-stats?id=channel_id_1/channel_id_5 -> get statistics about some channels
</pre> </pre>
...@@ -2,14 +2,15 @@ h1(#main_configuration). Main Configuration ...@@ -2,14 +2,15 @@ h1(#main_configuration). Main Configuration
h2(#push_stream_shared_memory_size). push_stream_shared_memory_size <a name="push_stream_shared_memory_size" href="#">&nbsp;</a> h2(#push_stream_shared_memory_size). push_stream_shared_memory_size <a name="push_stream_shared_memory_size" href="#">&nbsp;</a>
*syntax:* _push_stream_shared_memory_size size_ *syntax:* _push_stream_shared_memory_size size [name]_
*default:* _32M_ *default:* _none_
*context:* _http_ *context:* _http_
The size of the memory chunk this module will use to store published messages, channels and other shared structures. The size of the memory chunk this module will use to store published messages, channels and other shared structures.
When this memory is full any new request for publish a message or subscribe a channel will receive an 500 Internal Server Error response. When this memory is full any new request for publish a message or subscribe a channel will receive an 500 Internal Server Error response.
If you have more than one http block on same Nginx instance and do not want they share the same memory, you can set different names to each one with the optional argument _name_.
h2(#push_stream_channel_deleted_message_text). push_stream_channel_deleted_message_text <a name="push_stream_channel_deleted_message_text" href="#">&nbsp;</a> h2(#push_stream_channel_deleted_message_text). push_stream_channel_deleted_message_text <a name="push_stream_channel_deleted_message_text" href="#">&nbsp;</a>
...@@ -48,8 +49,9 @@ h2(#push_stream_channel_inactivity_time). push_stream_channel_inactivity_time <a ...@@ -48,8 +49,9 @@ h2(#push_stream_channel_inactivity_time). push_stream_channel_inactivity_time <a
*release version:* _0.3.5_ *release version:* _0.3.5_
The length of time after what a channel will be considered inactive, counted after the last message was published on it or the last subscriber leave it. The length of time after what a channel will be considered inactive, counted after the last message was published on it or the last subscriber entered on it.
After this time the channel will no longer be available and will be moved to the trash queue. After this time the channel will no longer be available and will be moved to the trash queue.
When the "push_stream_authorized_channels_only":push_stream_authorized_channels_only is set to on, the inactivity time is only used to know when the channel should be moved to trash.
h2(#push_stream_message_ttl). push_stream_message_ttl <a name="push_stream_message_ttl" href="#">&nbsp;</a> h2(#push_stream_message_ttl). push_stream_message_ttl <a name="push_stream_message_ttl" href="#">&nbsp;</a>
...@@ -132,4 +134,4 @@ The string prefix used to identify a wildcard channel, example: when you set thi ...@@ -132,4 +134,4 @@ The string prefix used to identify a wildcard channel, example: when you set thi
A wildcard channel is technically equals to a normal one. It is intended to be used when the "push_stream_authorized_channels_only":push_stream_authorized_channels_only is set to on. A wildcard channel is technically equals to a normal one. It is intended to be used when the "push_stream_authorized_channels_only":push_stream_authorized_channels_only is set to on.
[push_stream_authorized_channels_only]https://github.com/wandenberg/nginx-push-stream-module/blob/master/docs/directives/subscribers.textile#push_stream_authorized_channels_only [push_stream_authorized_channels_only]subscribers.textile#push_stream_authorized_channels_only
...@@ -9,9 +9,9 @@ h2(#push_stream_publisher). push_stream_publisher <a name="push_stream_publisher ...@@ -9,9 +9,9 @@ h2(#push_stream_publisher). push_stream_publisher <a name="push_stream_publisher
*context:* _location_ *context:* _location_
Defines a location as a message publisher. Requests to a publisher location are treated as messages to be sent to subscribers. Defines a location as a message publisher. Requests to a publisher location are treated as messages to be sent to subscribers.
This location supports three http methods: This location supports the following http methods:
GET, make possible to get statistics about the channel GET, make possible to get statistics about the channel
POST, publish a message to the channel POST/PUT, publish a message to the channel
DELETE, remove any existent stored messages, disconnect any subscriber, and delete the channel. Available only if _admin_ value is used in this directive. DELETE, remove any existent stored messages, disconnect any subscriber, and delete the channel. Available only if _admin_ value is used in this directive.
<pre> <pre>
......
...@@ -10,9 +10,8 @@ h2(#push_stream_subscriber). push_stream_subscriber <a name="push_stream_subscri ...@@ -10,9 +10,8 @@ h2(#push_stream_subscriber). push_stream_subscriber <a name="push_stream_subscri
Defines a location as a subscriber. This location represents a subscriber's interface to a channel's message queue. Defines a location as a subscriber. This location represents a subscriber's interface to a channel's message queue.
This location only supports GET http method to receive published messages. This location only supports GET http method to receive published messages.
And has three possible values to set push mode: streaming, polling, long-polling. The default values is streaming. The polling and long-polling modes could be set by the request header *X-Nginx-PushStream-Mode* overriding push_stream_subscriber directive value, except for websocket.
The polling and long-polling modes could be set by the request header *X-Nginx-PushStream-Mode* overriding push_stream_subscriber directive value. The eventsource mode enable "Event Source":eventsource_ref support for subscribers, using the headers Event-ID and Event-Type on publish is possible to set values to _id:_ and _event:_ attributes on message sent to subscribers.
The eventsource mode enable "Event Source":eventsource_ref support for subscribers. Using headers Event-ID and Event-Type on publish is possible to set values to _id:_ and _event:_ attributes on message sent to subscribers.
The websocket mode enable subscriber to use WebSocket protocol. The websocket mode enable subscriber to use WebSocket protocol.
...@@ -75,9 +74,8 @@ A string representing a set of channels id and backtrack desired messages separa ...@@ -75,9 +74,8 @@ A string representing a set of channels id and backtrack desired messages separa
The backtrack means the amount of old messages from each of the channels that will be delivered to the subscriber. On the example will be 3 messages from channel1, 5 from channel2 and 2 from channel3. The backtrack means the amount of old messages from each of the channels that will be delivered to the subscriber. On the example will be 3 messages from channel1, 5 from channel2 and 2 from channel3.
Backtrack isn't needed, you can only sign channels without get old messages, or you can mix things. Backtrack isn't needed, you can only sign channels without get old messages, or you can mix things.
More accepted examples: _/channel1_ , _/channel1/channel2_ , _/channel1.b5/channel2_ , _/channel1/channel2.b6_ , ... More accepted examples: _/channel1_ , _/channel1/channel2_ , _/channel1.b5/channel2_ , _/channel1/channel2.b6_ , ...
Must be present on location of the push_stream_subscriber.
"*How can it be used on a publisher location?*":push_stream_channels_path "*How is it used on a publisher location?*":push_stream_channels_path
<pre> <pre>
location /sub/(.*) { location /sub/(.*) {
...@@ -168,7 +166,6 @@ h2(#push_stream_subscriber_connection_ttl). push_stream_subscriber_connection_tt ...@@ -168,7 +166,6 @@ h2(#push_stream_subscriber_connection_ttl). push_stream_subscriber_connection_tt
*context:* _location (push_stream_subscriber)_ *context:* _location (push_stream_subscriber)_
The length of time a subscriber will stay connected before it is considered expired and disconnected. If you do not want subscribers to be automatically disconnected, just not set this directive. The length of time a subscriber will stay connected before it is considered expired and disconnected. If you do not want subscribers to be automatically disconnected, just not set this directive.
But, this operation is very important to help Nginx recycle memory consumed to send messages to susbscriber, allocated at pool request.
h2(#push_stream_longpolling_connection_ttl). push_stream_longpolling_connection_ttl <a name="push_stream_longpolling_connection_ttl" href="#">&nbsp;</a> h2(#push_stream_longpolling_connection_ttl). push_stream_longpolling_connection_ttl <a name="push_stream_longpolling_connection_ttl" href="#">&nbsp;</a>
...@@ -182,7 +179,6 @@ h2(#push_stream_longpolling_connection_ttl). push_stream_longpolling_connection_ ...@@ -182,7 +179,6 @@ h2(#push_stream_longpolling_connection_ttl). push_stream_longpolling_connection_
*release version:* _0.3.1_ *release version:* _0.3.1_
The length of time a long polling subscriber will stay connected waiting for a message before it is disconnected. If you do not want subscribers to be automatically disconnected, just not set this directive and push_stream_longpolling_connection_ttl directive. The length of time a long polling subscriber will stay connected waiting for a message before it is disconnected. If you do not want subscribers to be automatically disconnected, just not set this directive and push_stream_longpolling_connection_ttl directive.
But, this operation is very important to help Nginx recycle memory consumed to send messages to susbscriber, allocated at pool request.
h2(#push_stream_timeout_with_body). push_stream_timeout_with_body <a name="push_stream_timeout_with_body" href="#">&nbsp;</a> h2(#push_stream_timeout_with_body). push_stream_timeout_with_body <a name="push_stream_timeout_with_body" href="#">&nbsp;</a>
...@@ -208,7 +204,7 @@ h2(#push_stream_websocket_allow_publish). push_stream_websocket_allow_publish <a ...@@ -208,7 +204,7 @@ h2(#push_stream_websocket_allow_publish). push_stream_websocket_allow_publish <a
*release version:* _0.3.2_ *release version:* _0.3.2_
Enable a WebSocket subscriber send messages to the channel it is connected (the first, if connected in more than one) through the same connection it is receiving the messages, using _send_ method from WebSocket interface. Enable a WebSocket subscriber send messages to the channel(s) it is connected through the same connection it is receiving the messages, using _send_ method from WebSocket interface.
h2(#push_stream_last_received_message_time). push_stream_last_received_message_time <a name="push_stream_last_received_message_time" href="#">&nbsp;</a> h2(#push_stream_last_received_message_time). push_stream_last_received_message_time <a name="push_stream_last_received_message_time" href="#">&nbsp;</a>
...@@ -221,7 +217,7 @@ h2(#push_stream_last_received_message_time). push_stream_last_received_message_t ...@@ -221,7 +217,7 @@ h2(#push_stream_last_received_message_time). push_stream_last_received_message_t
*release version:* _0.3.3_ *release version:* _0.3.3_
Set the time when last message was received to the server knows which messages has to be sent to subscriber. Is a replacement for If-Modified-Since header. Example, $arg_time indicate that the value will be take from time argument. Set the time when last message was received. With that the server knows which messages has to be sent to subscriber. Is a replacement for If-Modified-Since header. Example, $arg_time indicate that the value will be taken from time argument.
h2(#push_stream_last_received_message_tag). push_stream_last_received_message_tag <a name="push_stream_last_received_message_tag" href="#">&nbsp;</a> h2(#push_stream_last_received_message_tag). push_stream_last_received_message_tag <a name="push_stream_last_received_message_tag" href="#">&nbsp;</a>
...@@ -234,7 +230,7 @@ h2(#push_stream_last_received_message_tag). push_stream_last_received_message_ta ...@@ -234,7 +230,7 @@ h2(#push_stream_last_received_message_tag). push_stream_last_received_message_ta
*release version:* _0.3.3_ *release version:* _0.3.3_
Set the tag of the last message received to the server knows which messages has to be sent to subscriber. Is a replacement for If-None-Match header. Example, $arg_tag indicate that the value will be take from tag argument. Set the tag of the last received message. With that the server knows which messages has to be sent to subscriber. Is a replacement for If-None-Match header. Example, $arg_tag indicate that the value will be taken from tag argument.
h2(#push_stream_last_event_id). push_stream_last_event_id <a name="push_stream_last_event_id" href="#">&nbsp;</a> h2(#push_stream_last_event_id). push_stream_last_event_id <a name="push_stream_last_event_id" href="#">&nbsp;</a>
...@@ -247,7 +243,7 @@ h2(#push_stream_last_event_id). push_stream_last_event_id <a name="push_stream_l ...@@ -247,7 +243,7 @@ h2(#push_stream_last_event_id). push_stream_last_event_id <a name="push_stream_l
*release version:* _0.4.0_ *release version:* _0.4.0_
Set the last event id of a message to the server knows which messages has to be sent to subscriber. Is a replacement for Last-Event-Id header. Example, $arg_last_event indicate that the value will be take from last_event argument. Set the last event id of a message. With that the server knows which messages has to be sent to subscriber. Is a replacement for Last-Event-Id header. Example, $arg_last_event indicate that the value will be taken from last_event argument.
h2(#push_stream_user_agent). push_stream_user_agent <a name="push_stream_user_agent" href="#">&nbsp;</a> h2(#push_stream_user_agent). push_stream_user_agent <a name="push_stream_user_agent" href="#">&nbsp;</a>
...@@ -287,7 +283,9 @@ h2(#push_stream_allowed_origins). push_stream_allowed_origins <a name="push_stre ...@@ -287,7 +283,9 @@ h2(#push_stream_allowed_origins). push_stream_allowed_origins <a name="push_stre
*release version:* _0.3.4_ *release version:* _0.3.4_
Set the value used on the Access-Control-Allow-Origin header to allow cross domain requests by javascript. Set the value used on the Access-Control-Allow-Origin header to allow cross domain requests by javascript.
You can use a variable as value to this directive.
When this directive is set, the module will set Access-Control-Allow-Methods and Access-Control-Allow-Headers headers with proper values.
[eventsource_ref]http://dev.w3.org/html5/eventsource/ [eventsource_ref]http://dev.w3.org/html5/eventsource/
[push_stream_authorized_channels_only]https://github.com/wandenberg/nginx-push-stream-module/blob/master/docs/directives/subscribers.textile#push_stream_authorized_channels_only [push_stream_authorized_channels_only]subscribers.textile#push_stream_authorized_channels_only
[push_stream_channels_path]https://github.com/wandenberg/nginx-push-stream-module/blob/master/docs/directives/publishers.textile#push_stream_channels_path [push_stream_channels_path]publishers.textile#push_stream_channels_path
...@@ -133,6 +133,81 @@ If needed you can change this behavior changing the javascript usage, like the e ...@@ -133,6 +133,81 @@ If needed you can change this behavior changing the javascript usage, like the e
</html> </html>
</pre> </pre>
h2(#getting_old_messages). Getting old messages
To get old messages you can set a backtrack, an event id or a time in the past.
To proper work on reconnections you should set ==~tag~ and ~time~== on the message template, and configure the server to receive the values.
*Server:*
<pre>
location /pub {
# activate publisher (admin) mode for this location
push_stream_publisher admin;
# query string based channel id
push_stream_channels_path $arg_id;
# store messages in memory
push_stream_store_messages on;
}
location ~ /ev/(.*) {
# activate event source mode for this location
push_stream_subscriber eventsource;
# positional channel path
push_stream_channels_path $1;
push_stream_last_received_message_time "$arg_time";
push_stream_last_received_message_tag "$arg_tag";
# message template
push_stream_message_template "{\"id\":~id~,\"channel\":\"~channel~\",\"text\":\"~text~\",\"tag\":\"~tag~\",\"time\":\"~time~\"}";
# ping frequency
push_stream_ping_message_interval 10s;
}
</pre>
*Client:*
<pre>
<!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>Event Source Example</title>
</head>
<body>
<p>Messages:</p>
<div id="messages" style="width:800px;height:300px;overflow:scroll;"></div>
<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 messageReceived(text, id, channel) {
document.getElementById('messages').innerHTML += id + ': ' + text + '<br>';
};
var pushstream = new PushStream({
host: window.location.hostname,
port: window.location.port,
modes: "eventsource",
messagesPublishedAfter: 5,
messagesControlByArgument: true
});
pushstream.onmessage = messageReceived;
pushstream.addChannel('ch1');
pushstream.connect();
// ]]>
</script>
</body>
</html>
</pre>
*Observations:* *Observations:*
* _push_stream_message_template_ should be exactly like as the example to be used with PushStream class * _push_stream_message_template_ should be exactly like as the example to be used with PushStream class
......
...@@ -35,7 +35,6 @@ Create a html page with the content on **Client** part, access it from browser a ...@@ -35,7 +35,6 @@ Create a html page with the content on **Client** part, access it from browser a
# ping frequency # ping frequency
push_stream_ping_message_interval 10s; push_stream_ping_message_interval 10s;
} }
</pre> </pre>
*Client:* *Client:*
...@@ -107,7 +106,6 @@ If needed you can change this behavior changing the javascript usage, like the e ...@@ -107,7 +106,6 @@ If needed you can change this behavior changing the javascript usage, like the e
# ping frequency # ping frequency
push_stream_ping_message_interval 10s; push_stream_ping_message_interval 10s;
} }
</pre> </pre>
*Client:* *Client:*
...@@ -147,6 +145,85 @@ If needed you can change this behavior changing the javascript usage, like the e ...@@ -147,6 +145,85 @@ If needed you can change this behavior changing the javascript usage, like the e
</html> </html>
</pre> </pre>
h2(#getting_old_messages). Getting old messages
To get old messages you can set a backtrack, an event id or a time in the past.
To proper work on reconnections you should set ==~tag~ and ~time~== on the message template, and configure the server to receive the values.
*Server:*
<pre>
location /pub {
# activate publisher (admin) mode for this location
push_stream_publisher admin;
# query string based channel id
push_stream_channels_path $arg_id;
# store messages in memory
push_stream_store_messages on;
}
location ~ /sub/(.*) {
# activate subscriber (streaming) mode for this location
push_stream_subscriber;
# positional channel path
push_stream_channels_path $1;
push_stream_last_received_message_time "$arg_time";
push_stream_last_received_message_tag "$arg_tag";
# header to be sent when receiving new subscriber connection
push_stream_header_template "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n<meta http-equiv=\"Cache-Control\" content=\"no-store\">\r\n<meta http-equiv=\"Cache-Control\" content=\"no-cache\">\r\n<meta http-equiv=\"Pragma\" content=\"no-cache\">\r\n<meta http-equiv=\"Expires\" content=\"Thu, 1 Jan 1970 00:00:00 GMT\">\r\n<script type=\"text/javascript\">\r\nwindow.onError = null;\r\ntry{ document.domain = (window.location.hostname.match(/^(\d{1,3}\.){3}\d{1,3}$/)) ? window.location.hostname : window.location.hostname.split('.').slice(-1 * Math.max(window.location.hostname.split('.').length - 1, (window.location.hostname.match(/(\w{4,}\.\w{2}|\.\w{3,})$/) ? 2 : 3))).join('.');}catch(e){}\r\nparent.PushStream.register(this);\r\n</script>\r\n</head>\r\n<body>";
# message template
push_stream_message_template "<script>p(~id~,'~channel~','~text~','~event-id~', '~time~', '~tag~');</script>";
# footer to be sent when finishing subscriber connection
push_stream_footer_template "</body></html>";
# content-type
default_type "text/html; charset=utf-8";
# ping frequency
push_stream_ping_message_interval 10s;
}
</pre>
*Client:*
<pre>
<!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>Event Source Example</title>
</head>
<body>
<p>Messages:</p>
<div id="messages" style="width:800px;height:300px;overflow:scroll;"></div>
<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 messageReceived(text, id, channel) {
document.getElementById('messages').innerHTML += id + ': ' + text + '<br>';
};
var pushstream = new PushStream({
host: window.location.hostname,
port: window.location.port,
modes: "stream",
messagesPublishedAfter: 5,
messagesControlByArgument: true
});
pushstream.onmessage = messageReceived;
pushstream.addChannel('ch1');
pushstream.connect();
// ]]>
</script>
</body>
</html>
</pre>
*Observations:* *Observations:*
* _push_stream_message_template_ should be exactly like as the example to be used with PushStream class * _push_stream_message_template_ should be exactly like as the example to be used with PushStream class
......
...@@ -194,7 +194,7 @@ If needed you can change this behavior using some additional directives and chan ...@@ -194,7 +194,7 @@ If needed you can change this behavior using some additional directives and chan
host: window.location.hostname, host: window.location.hostname,
port: window.location.port, port: window.location.port,
modes: "longpolling", modes: "longpolling",
longPollingByHeaders: false, messagesControlByArgument: true,
tagArgument: 'tag', //this is the default value, you have to change it to be the same value used on push_stream_last_received_message_tag directive tagArgument: 'tag', //this is the default value, you have to change it to be the same value used on push_stream_last_received_message_tag directive
timeArgument: 'time' //this is the default value, you have to change it to be the same value used on push_stream_last_received_message_time directive timeArgument: 'time' //this is the default value, you have to change it to be the same value used on push_stream_last_received_message_time directive
}); });
...@@ -273,7 +273,6 @@ _The configuration in the example is the same used on long polling, just forcing ...@@ -273,7 +273,6 @@ _The configuration in the example is the same used on long polling, just forcing
host: window.location.hostname, host: window.location.hostname,
port: window.location.port, port: window.location.port,
modes: "longpolling", modes: "longpolling",
longPollingByHeaders: false,
tagArgument: 'tag', //this is the default value, you have to change it to be the same value used on push_stream_last_received_message_tag directive tagArgument: 'tag', //this is the default value, you have to change it to be the same value used on push_stream_last_received_message_tag directive
timeArgument: 'time', //this is the default value, you have to change it to be the same value used on push_stream_last_received_message_time directive timeArgument: 'time', //this is the default value, you have to change it to be the same value used on push_stream_last_received_message_time directive
useJSONP: true, //this is used only to force jsonp usage on example, it is automatic true when the domains are different useJSONP: true, //this is used only to force jsonp usage on example, it is automatic true when the domains are different
...@@ -288,6 +287,80 @@ _The configuration in the example is the same used on long polling, just forcing ...@@ -288,6 +287,80 @@ _The configuration in the example is the same used on long polling, just forcing
</html> </html>
</pre> </pre>
h2(#getting_old_messages). Getting old messages
To get old messages you can set a backtrack, an event id or a time in the past.
To proper work on reconnections you should set ==~tag~ and ~time~== on the message template, and configure the server to receive the values.
*Server:*
<pre>
location /pub {
# activate publisher (admin) mode for this location
push_stream_publisher admin;
# query string based channel id
push_stream_channels_path $arg_id;
# store messages in memory
push_stream_store_messages on;
}
location ~ /lp/(.*) {
# activate long-polling mode for this location
push_stream_subscriber long-polling;
# positional channel path
push_stream_channels_path $1;
push_stream_last_received_message_time "$arg_time";
push_stream_last_received_message_tag "$arg_tag";
# message template
push_stream_message_template "{\"id\":~id~,\"channel\":\"~channel~\",\"text\":\"~text~\",\"tag\":\"~tag~\",\"time\":\"~time~\"}";
# connection timeout
push_stream_longpolling_connection_ttl 30s;
}
</pre>
*Client:*
<pre>
<!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>Event Source Example</title>
</head>
<body>
<p>Messages:</p>
<div id="messages" style="width:800px;height:300px;overflow:scroll;"></div>
<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 messageReceived(text, id, channel) {
document.getElementById('messages').innerHTML += id + ': ' + text + '<br>';
};
var pushstream = new PushStream({
host: window.location.hostname,
port: window.location.port,
modes: "longpolling",
messagesPublishedAfter: 5,
messagesControlByArgument: true
});
pushstream.onmessage = messageReceived;
pushstream.addChannel('ch1');
pushstream.connect();
// ]]>
</script>
</body>
</html>
</pre>
*Observations:* *Observations:*
* _push_stream_message_template_ should be exactly like as the example to be used with PushStream class * _push_stream_message_template_ should be exactly like as the example to be used with PushStream class
...@@ -137,8 +137,82 @@ If needed you can change this behavior changing the javascript usage, like the e ...@@ -137,8 +137,82 @@ If needed you can change this behavior changing the javascript usage, like the e
</html> </html>
</pre> </pre>
h2(#getting_old_messages). Getting old messages
To get old messages you can set a backtrack, an event id or a time in the past.
To proper work on reconnections you should set ==~tag~ and ~time~== on the message template, and configure the server to receive the values.
*Server:*
<pre>
location /pub {
# activate publisher (admin) mode for this location
push_stream_publisher admin;
# query string based channel id
push_stream_channels_path $arg_id;
# store messages in memory
push_stream_store_messages on;
}
location ~ /ws/(.*) {
# activate websocket mode for this location
push_stream_subscriber websocket;
# positional channel path
push_stream_channels_path $1;
push_stream_last_received_message_time "$arg_time";
push_stream_last_received_message_tag "$arg_tag";
# message template
push_stream_message_template "{\"id\":~id~,\"channel\":\"~channel~\",\"text\":\"~text~\",\"tag\":\"~tag~\",\"time\":\"~time~\"}";
# ping frequency
push_stream_ping_message_interval 10s;
}
</pre>
*Client:*
<pre>
<!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>Event Source Example</title>
</head>
<body>
<p>Messages:</p>
<div id="messages" style="width:800px;height:300px;overflow:scroll;"></div>
<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 messageReceived(text, id, channel) {
document.getElementById('messages').innerHTML += id + ': ' + text + '<br>';
};
var pushstream = new PushStream({
host: window.location.hostname,
port: window.location.port,
modes: "websocket",
messagesPublishedAfter: 5,
messagesControlByArgument: true
});
pushstream.onmessage = messageReceived;
pushstream.addChannel('ch1');
pushstream.connect();
// ]]>
</script>
</body>
</html>
</pre>
*Observations:* *Observations:*
* _push_stream_message_template_ should be exactly like as the example to be used with PushStream class * _push_stream_message_template_ should be exactly like as the example to be used with PushStream class
* WebSocket, EventSource and Forever iFrame may be combined setting _/ws_, _/sub_ and _/ev_ locations on same server and setting *modes: "websocket|eventsource|stream"* on client. With that if the browser supports Websocket or Event Source, it will use it, if not it will use iFrame, following the order on _modes_ attribute. * WebSocket, EventSource and Forever iFrame may be combined setting _/ws_, _/sub_ and _/ev_ locations on same server and setting *modes: "websocket|eventsource|stream"* on client. With that if the browser supports Websocket or Event Source, it will use it, if not it will use iFrame, following the order on _modes_ attribute.
...@@ -41,10 +41,12 @@ Example: ...@@ -41,10 +41,12 @@ Example:
| pingtimeout | 30000 | number | the amount of time to consider that a connection does not receive a ping message (in milliseconds) | | pingtimeout | 30000 | number | the amount of time to consider that a connection does not receive a ping message (in milliseconds) |
| reconnectOnTimeoutInterval | 3000 | number | the amount of time to do a new connection after a timeout happens (in milliseconds) | | reconnectOnTimeoutInterval | 3000 | number | the amount of time to do a new connection after a timeout happens (in milliseconds) |
| reconnectOnChannelUnavailableInterval | 60000 | number | the amount of time to do a new connection after receives a 403, indicating that a channel is unavailable (in milliseconds) | | reconnectOnChannelUnavailableInterval | 60000 | number | the amount of time to do a new connection after receives a 403, indicating that a channel is unavailable (in milliseconds) |
| secondsAgo | - | number | get messages published at less than this time, on the first connection using long polling | | messagesPublishedAfter | - | number/date | get messages published at less than this time, on the first connection |
| longPollingByHeaders | true | boolean | when to use time and tag values by headers instead of arguments on long polling connections | | lastEventId | - | string | get messages published after the message with this event id |
| tagArgument | 'tag' | string | argument name to send tag value on long polling connections, specially used on JSONP mode | | messagesControlByArgument | true | boolean | when to use time and tag values by headers instead of arguments on long polling connections |
| timeArgument | 'time' | string | argument name to send time value on long polling connections, specially used on JSONP mode | | tagArgument | 'tag' | string | argument name to send tag value, specially used on JSONP mode |
| timeArgument | 'time' | string | argument name to send time value, specially used on JSONP mode |
| eventIdArgument | 'eventid' | string | argument name to send eventid value, specially used on JSONP mode |
| useJSONP | false | boolean | when to use JSONP mode on long polling connections, mandatorily true when current domain or port is different from the target server (cross domain restrictions) | | useJSONP | false | boolean | when to use JSONP mode on long polling connections, mandatorily true when current domain or port is different from the target server (cross domain restrictions) |
| urlPrefixPublisher | '/pub' | string | the location prefix used to post messages | | urlPrefixPublisher | '/pub' | string | the location prefix used to post messages |
| urlPrefixStream | '/sub' | string | the location prefix used to do Stream mode connections | | urlPrefixStream | '/sub' | string | the location prefix used to do Stream mode connections |
......
...@@ -18,12 +18,12 @@ This command run the tests using nginx *executable* located at _/usr/local/nginx ...@@ -18,12 +18,12 @@ This command run the tests using nginx *executable* located at _/usr/local/nginx
To change this behavior use the commands bellow To change this behavior use the commands bellow
<pre> <pre>
NGINX_EXEC="../build/nginx-1.1.15/objs/nginx" rake spec # to change default path for nginx executable NGINX_EXEC="../build/nginx-1.2.0/objs/nginx" rake spec # to change default path for nginx executable
NGINX_HOST="my_machine" rake spec # to change default hostname NGINX_HOST="my_machine" rake spec # to change default hostname
NGINX_PORT=9889 rake spec # to change default port NGINX_PORT=9889 rake spec # to change default port
NGINX_WORKERS=2 rake spec # to change dafault number of workers used NGINX_WORKERS=2 rake spec # to change dafault number of workers used
and can combine any of these parameters, like: and can combine any of these parameters, like:
NGINX_PORT=9889 NGINX_EXEC="../build/nginx-1.1.15/objs/nginx" rake spec NGINX_PORT=9889 NGINX_EXEC="../build/nginx-1.2.0/objs/nginx" rake spec
</pre> </pre>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment