рдЬреЗрдб рдкреЛрд▓ рдХреЗ рд▓рд┐рдП рд▓рдВрдмреА рдкреЛрд▓рд┐рдВрдЧ рдП

рдиреЗрдЯрд╡рд░реНрдХ рдкрд░ Nginx рдФрд░ рдЬрд╛рд╡рд╛рд╕реНрдХреНрд░рд┐рдкреНрдЯ рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рдХреЗ рд▓рдВрдмреЗ рдорддрджрд╛рди рдХреЛ рдХреИрд╕реЗ рд▓рд╛рдЧреВ рдХрд┐рдпрд╛ рдЬрд╛рдП, рдмрд╣реБрдд рд╕рд╛рд░реА рд╕рд╛рдордЧреНрд░реА рд╣реИред рд▓реЗрдХрд┐рди рдореБрдЭреЗ рдЕрднреА рддрдХ рдкреВрд░рд╛ рдЧрд╛рдЗрдб рдирд╣реАрдВ рдорд┐рд▓рд╛ рд╣реИред Nginx рдХреЗ рддрд╣рдд рдореЙрдбреНрдпреВрд▓ рдХреЛ рд╕рдВрдХрд▓рд┐рдд рдХрд░рдиреЗ рдореЗрдВ рд╕рдорд╕реНрдпрд╛рдПрдВ рд╣реИрдВ, рдлрд┐рд░ рдмреНрд░рд╛рдЙрдЬрд╝рд░ рдореЗрдВ рд▓рдВрдмреЗ рдкреЛрд▓ рдЕрдиреБрд░реЛрдзреЛрдВ рдХреЗ рд▓рд┐рдП рдбрд╛рдЙрдирд▓реЛрдб рдЖрдЗрдХрдиред рдХрдЯ, рдкреВрд░реНрдг рд╕рд╛рдордЧреНрд░реА рдХреЗ рддрд╣рдд, рдЖрдк рдЗрд╕реЗ рд╕рд╣реА рдХреИрд╕реЗ рдХрд░ рд╕рдХрддреЗ рд╣реИрдВ?


рд▓рд┐рдирдХреНрд╕ рдХреЗ рддрд╣рдд Nginx рдореЙрдбреНрдпреВрд▓ рдХрд╛ рд╕рдВрдХрд▓рди


рдиреЗрдЧреНрдиреЗрдХреНрд╕ рд╕рд░реНрд╡рд░ рдореЗрдВ рд▓рдВрдмреЗ рдорддрджрд╛рди рдХрдиреЗрдХреНрд╢рди рдХрд╛ рд╕рдорд░реНрдерди рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП, рдЕрджреНрднреБрдд рдирдЧрдиреЗрдХреНрд╕-рдкреБрд╢-рд╕реНрдЯреНрд░реАрдо-рдореЙрдбреНрдпреВрд▓ рдореЙрдбреНрдпреВрд▓ рд▓рд╛рдЧреВ рдХрд┐рдпрд╛ рдЧрдпрд╛ рд╣реИред рдЪреВрдВрдХрд┐ рдпрд╣ рдЖрдзрд┐рдХрд╛рд░рд┐рдХ рд╡рд┐рддрд░рдг рдореЗрдВ рд╢рд╛рдорд┐рд▓ рдирд╣реАрдВ рд╣реИ, рдЗрд╕рд▓рд┐рдП рдЗрд╕реЗ Nginx рдХреЗ рд╕рд╛рде рдбрд╛рдЙрдирд▓реЛрдб, рдХреЙрдиреНрдлрд╝рд┐рдЧрд░ рдФрд░ рд╕рдВрдХрд▓рд┐рдд рдХрд░рдиреЗ рдХреА рдЖрд╡рд╢реНрдпрдХрддрд╛ рд╣реИред

рдЗрд╕рд╕реЗ рдкрд╣рд▓реЗ, рдЖрдкрдХреЗ рдкрд╛рд╕ рд╕рднреА рдЖрд╡рд╢реНрдпрдХ рдкреИрдХреЗрдЬ рд╕реНрдерд╛рдкрд┐рдд рд╣реЛрдиреЗ рдЪрд╛рд╣рд┐рдПред
apt-get install git apt-get install make apt-get install g++ apt-get install libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev 


рдЗрд╕рдХреЗ рдмрд╛рдж, рдЖрдкрдХреЛ nginx- рдкреБрд╢-рд╕реНрдЯреНрд░реАрдо-рдореЙрдбреНрдпреВрд▓, nginx рдореЙрдбреНрдпреВрд▓ рдХреЛ рд╕реНрд╡рдпрдВ рдбрд╛рдЙрдирд▓реЛрдб рдХрд░рдирд╛ рд╣реЛрдЧрд╛ рдФрд░ рдЙрдиреНрд╣реЗрдВ рдПрдХ рд╕рд╛рде рд╕рдВрдХрд▓рд┐рдд рдХрд░рдирд╛ рд╣реЛрдЧрд╛ред

рдЬреАрдЖрдИрдЯреА рд╕реЗ рдПрдХ рдкрд░рд┐рдпреЛрдЬрдирд╛ рдХрд╛ рдХреНрд▓реЛрди
 git clone http://github.com/wandenberg/nginx-push-stream-module.git 


рдбрд╛рдЙрдирд▓реЛрдб рдХрд░реЗрдВ рдФрд░ рдЦреЛрд▓ рдирд╡реАрдирддрдо nginx
 NGINX_PUSH_STREAM_MODULE_PATH=$PWD/nginx-push-stream-module wget http://nginx.org/download/nginx-1.2.6.tar.gz tar xzvf nginx-1.2.6.tar.gz 


рдХреЙрдиреНрдлрд╝рд┐рдЧрд░ рдФрд░ рд╕рдВрдХрд▓рди nginx рд╕рд╛рде nginx-рдзрдХреНрдХрд╛-рдзрд╛рд░рд╛ рдореЙрдбреНрдпреВрд▓
 cd nginx-1.2.6 ./configure --add-module=../nginx-push-stream-module make make install 


рдпрджрд┐ рдХреЛрдИ рд╕рдВрдХрд▓рди рддреНрд░реБрдЯрд┐рдпрд╛рдВ рдирд╣реАрдВ рд╣реИрдВ, рддреЛ рдЖрдк рдХрд░ рд░рд╣реЗ рд╣реИрдВред рд╣рдо рдпрд╣ рд╕рддреНрдпрд╛рдкрд┐рдд рдХрд░реЗрдВрдЧреЗ рдХрд┐ рд╣рдордиреЗ рд╡рд╛рд╕реНрддрд╡ рдореЗрдВ рдЙрд╕ nginx рдХреЛ рд╕реНрдерд╛рдкрд┐рдд рдХрд┐рдпрд╛ рд╣реИ рдФрд░ рдЕрдм рдЙрд╕рдХреЗ рдкрд╛рд╕ рд╡рд╛рд╕реНрддрд╡ рдореЗрдВ nginx-push-stream-рдореЙрдбреНрдпреВрд▓ рд╣реИ
 check: /usr/local/nginx/sbin/nginx -v test configuration: /usr/local/nginx/sbin/nginx -c $NGINX_PUSH_STREAM_MODULE_PATH/misc/nginx.conf -t 


рдЗрди рдЖрджреЗрд╢реЛрдВ рдХреЛ рдирд┐рд╖реНрдкрд╛рджрд┐рдд рдХрд░рдиреЗ рдХреЗ рдмрд╛рдж, рдЖрдкрдХреЛ рдпрд╣ рджреЗрдЦрдирд╛ рдЪрд╛рд╣рд┐рдП:
 nginx version: nginx/1.2.6 the configuration file $NGINX_PUSH_STREAM_MODULE_PATH/misc/nginx.conf syntax is ok configuration file $NGINX_PUSH_STREAM_MODULE_PATH/misc/nginx.conf test is successful 


рд▓реЙрдиреНрдЧ рдкреЛрд▓рд┐рдВрдЧ рдХрдиреЗрдХреНрд╢рдиреНрд╕ рдХреЗ рд▓рд┐рдП Nginx рдХреЛ рдХреЙрдиреНрдлрд╝рд┐рдЧрд░ рдХрд░рдирд╛


рд▓рдВрдмреЗ рдорддрджрд╛рди рд╕рдорд░реНрдерди рдХреЛ рдХреЙрдиреНрдлрд╝рд┐рдЧрд░ рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП, Nginx рдХреЙрдиреНрдлрд╝рд┐рдЧрд░реЗрд╢рди рдореЗрдВ, рдХрдо рд╕реЗ рдХрдо рджреЛ рдирд┐рдпрдВрддреНрд░рдХреЛрдВ рдХреЛ рдкрдВрдЬреАрдХреГрдд рд╣реЛрдирд╛ рдЪрд╛рд╣рд┐рдПред рдЧреНрд░рд╛рд╣рдХреЛрдВ рдХреЗ рд▓рд┐рдП рдкрд╣рд▓рд╛ (рдЬреЛ рд╕рдВрджреЗрд╢ рдкреНрд░рд╛рдкреНрдд рдХрд░реЗрдВрдЧреЗ), рджреВрд╕рд░рд╛ рд╕рдВрджреЗрд╢ рдХреЗ рдкреНрд░рдХрд╛рд╢рди рдХреЗ рд▓рд┐рдП (рдЬреЛ рд╕рдВрджреЗрд╢ рднреЗрдЬреЗрдВрдЧреЗ)ред

рд╢реЗрд╖ рд╕рд░реНрд╡рд░ рдорд╛рдкрджрдВрдбреЛрдВ рдХреЗ рдХреЙрдиреНрдлрд╝рд┐рдЧрд░реЗрд╢рди рдХреЛ рд╕реНрд╡реАрдХрд╛рд░ рдХрд░рддреЗ рд╣реБрдП, рдХреЙрдиреНрдлрд╝рд┐рдЧрд░реЗрд╢рди рдлрд╝рд╛рдЗрд▓ /usr/local/nginx/nginx.conf рдХреЛ рдЗрд╕ рддрд░рд╣ рджрд┐рдЦрдирд╛ рдЪрд╛рд╣рд┐рдП:
 ... http { ... server { listen 80; server_name stream.example.com; charset utf-8; location /pub { push_stream_publisher admin; set $push_stream_channel_id $arg_id; allow 1.1.1.1 # ip     } location ~ /sub/(.*) { push_stream_subscriber long-polling; set $push_stream_channels_path $1; push_stream_last_received_message_tag $arg_tag; push_stream_last_received_message_time $arg_time; push_stream_longpolling_connection_ttl 25s; } } } 


рдЗрд╕ рдЙрджрд╛рд╣рд░рдг рдореЗрдВ, / рдкрдм рд╕рдВрджреЗрд╢реЛрдВ рдХреЛ рдкреЛрд╕реНрдЯ рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП рдкрддрд╛ рд╣реИ, рдХреЗрд╡рд▓ рдЖрдкрдХрд╛ рд╕рд░реНрд╡рд░ (1.1.1.1) рдЬрд╣рд╛рдВ рд╕реЗ рдШрдЯрдирд╛рдПрдВ рдЖ рд░рд╣реА рд╣реИрдВ, рдЙрд╕реЗ рджреЗрдЦрдирд╛ рдЪрд╛рд╣рд┐рдП, / рдЙрдк рдЙрди рдЧреНрд░рд╛рд╣рдХреЛрдВ рдХреЗ рд▓рд┐рдП рдкрддрд╛ рд╣реИ рдЬрд┐рдиреНрд╣реЗрдВ рд╕рдВрджреЗрд╢ рднреЗрдЬреЗ рдЬрд╛рдПрдВрдЧреЗред рдЧреНрд░рд╛рд╣рдХреЛрдВ рдХреА рдкрд╣рдЪрд╛рди рдХрд░рдиреЗ рд╡рд╛рд▓реЗ рдкрд╣рдЪрд╛рдирдХрд░реНрддрд╛ рдХреЛ рдЙрдк / рдХреЗ рдмрд╛рдж рдкрд╛рд╕ рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИ, рдФрд░ рдЖрдИрдбреА рдкреИрд░рд╛рдореАрдЯрд░ / рдкрдм рдореЗрдВ рд╕реНрд╡реАрдХрд╛рд░ рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИред

рдЬрдм рд╣рдо рдЬрд╛рд╡рд╛рд╕реНрдХреНрд░рд┐рдкреНрдЯ рдкрд░ рд╕реНрдкрд░реНрд╢ рдХрд░рддреЗ рд╣реИрдВ рддреЛ рдмрд╣реБрдд рдорд╣рддреНрд╡рдкреВрд░реНрдг рдкреИрд░рд╛рдореАрдЯрд░ push_stream_last_received_message_tag рдФрд░ push_stream_last_received_message_time рдиреАрдЪреЗ рдЪрд░реНрдЪрд╛ рдХреА рдЬрд╛рдПрдЧреАред

рдХрд╛рдо рдХреЛ рд╕рдордЭрдиреЗ рдХреЗ рд▓рд┐рдП рдЙрджрд╛рд╣рд░рдг:
рдЖрдк рдХреЙрд▓ рдХрд░рдХреЗ рдХрдИ рдЧреНрд░рд╛рд╣рдХ рдмрдирд╛ рд╕рдХрддреЗ рд╣реИрдВ: stream.example.com/sub/1 , stream.example.com/sub/2 , stream.example.com/sub/3 ред рдЙрдирдореЗрдВ рд╕реЗ рдкреНрд░рддреНрдпреЗрдХ 25 рд╕реЗрдХрдВрдб рдХреЗ рд▓рд┐рдП Nginx рд╕рд░реНрд╡рд░ рдкрд░ "рд▓рдЯрдХрд╛" рд╣реЛрдЧрд╛ (push_stream_longpolling_connection_ttp)ред рдпрджрд┐ рд╣рдо POST рдЕрдиреБрд░реЛрдз рдХреЛ stream.example.com/pub?id=2 рдкрд░ рдХреЙрд▓ рдХрд░рддреЗ рд╣реИрдВ рдФрд░ рд╢рд░реАрд░ рдореЗрдВ "рд╣реЗрд▓реЛ" рд╕рдВрджреЗрд╢ рднреЗрдЬрддреЗ рд╣реИрдВ, рддреЛ рд╕рдмреНрд╕рдХреНрд░рд╛рдЗрдмрд░ / рд╣реИрдВрдЧ / рдСрди / 2 рдкрд░ рдкреНрд░рддрд┐рдХреНрд░рд┐рдпрд╛ "рд╣реИрд▓реЛ" рдкреНрд░рд╛рдкреНрдд рд╣реЛрдЧреАред рдлрд╛рдпрд░рдлреЙрдХреНрд╕ рдХреЗ рд▓рд┐рдП рдкреЛрд╕реНрдЯрд░ рдкреНрд▓рдЧрдЗрди рдореЗрдВ рдЗрд╕реЗ рдЬрд╛рдВрдЪрдирд╛ рд╕реБрд╡рд┐рдзрд╛рдЬрдирдХ рд╣реИред

рдЬрд╛рд╡рд╛рд╕реНрдХреНрд░рд┐рдкреНрдЯ рдореЗрдВ рдмрдирд╛рдпрд╛ рдЬрд╛ рд░рд╣рд╛ рд╣реИ рдЧреНрд░рд╛рд╣рдХреЛрдВ


рд╕рдмрд╕реЗ рдЕрдзрд┐рдХ рд╕рдВрднрд╛рд╡рдирд╛ рд╣реИ, рдЖрдкрдХреЛ рдмреНрд░рд╛рдЙрдЬрд╝рд░ рдореЗрдВ рдХрд┐рд╕реА рднреА рдбреЗрдЯрд╛ рдХреЛ рдЕрдкрдбреЗрдЯ рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП рд▓рдВрдмреЗ рдорддрджрд╛рди рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рдиреЗ рдХреА рдЖрд╡рд╢реНрдпрдХрддрд╛ рд╣реИ, рдФрд░ рдЗрд╕рдХреЗ рд▓рд┐рдП рдЖрдкрдХреЛ рдЬрд╛рд╡рд╛рд╕реНрдХреНрд░рд┐рдкреНрдЯ рдХреНрд▓рд╛рдЗрдВрдЯ рд▓рд┐рдЦрдиреЗ рдХреА рдЖрд╡рд╢реНрдпрдХрддрд╛ рд╣реИред

рдореИрдВ рд╡рд┐рднрд┐рдиреНрди рддрд░реАрдХреЛрдВ рдХреА рдХреЛрд╢рд┐рд╢ рдХреА, рд▓реЗрдХрд┐рди рдорд╛рдирдХ рдХреЗ рд▓рд┐рдП рдЪреБрдирд╛ XMLHttpRequest ред рдЕрдиреНрдп рд╡рд┐рдзрд┐рдпреЛрдВ рдХреА рддреБрд▓рдирд╛ рдореЗрдВ, рдЗрд╕рдХреЗ рдирд┐рдореНрдирд▓рд┐рдЦрд┐рдд рдлрд╛рдпрджреЗ рд╣реИрдВ:


рдЪрд░ рдХреЛ рд╕рдм-рд╡реЗ рдХрд░реЗрдВ - рдЧреНрд░рд╛рд╣рдХ рдХреЗ рд▓рд┐рдП рдПрдХ рдЕрджреНрд╡рд┐рддреАрдп рдореВрд▓реНрдп рд╕рдВрдЧреНрд░рд╣реАрдд рд╣реИ
 var LongPolling = { etag: 0, time: null, init: function () { var $this = this, xhr; if ($this.time === null) { $this.time = $this.dateToUTCString(new Date()); } if (window.XDomainRequest) { //  IE,     (-  IE8) setTimeout(function () { $this.poll_IE($this); }, 2000); } else { //  XMLHttpRequest  mcXHR = xhr = new XMLHttpRequest(); xhr.onreadystatechange = xhr.onload = function () { if (4 === xhr.readyState) { //    if (200 === xhr.status && xhr.responseText.length > 0) { //  Etag  Last-Modified  Header  $this.etag = xhr.getResponseHeader('Etag'); $this.time = xhr.getResponseHeader('Last-Modified'); //    $this.action(xhr.responseText); } if (xhr.status > 0) { //       $this.poll($this, xhr); } } }; //  long polling $this.poll($this, xhr); } }, poll: function ($this, xhr) { var timestamp = (new Date()).getTime(), url = 'http://stream.example.com/sub/' + subID + '?callback=?&v=' + timestamp; // timestamp       xhr.open('GET', url, true); xhr.setRequestHeader("If-None-Match", $this.etag); xhr.setRequestHeader("If-Modified-Since", $this.time); xhr.send(); }, //      poll(),   IE poll_IE: function ($this) { var xhr = new window.XDomainRequest(); var timestamp = (new Date()).getTime(), url = 'http://stream.example.com/sub/' + subID + '?callback=?&v=' + timestamp; xhr.onprogress = function () {}; xhr.onload = function () { $this.action(xhr.responseText); $this.poll_IE($this); }; xhr.onerror = function () { $this.poll_IE($this); }; xhr.open('GET', url, true); xhr.send(); }, action: function (event) { //  ,    -  ... }, valueToTwoDigits: function (value) { return ((value < 10) ? '0' : '') + value; }, //     UTC dateToUTCString: function () { var time = this.valueToTwoDigits(date.getUTCHours()) + ':' + this.valueToTwoDigits(date.getUTCMinutes()) + ':' + this.valueToTwoDigits(date.getUTCSeconds()); return this.days[date.getUTCDay()] + ', ' + this.valueToTwoDigits(date.getUTCDate()) + ' ' + this.months[date.getUTCMonth()] + ' ' + date.getUTCFullYear() + ' ' + time + ' GMT'; } } )ред getTime (), var LongPolling = { etag: 0, time: null, init: function () { var $this = this, xhr; if ($this.time === null) { $this.time = $this.dateToUTCString(new Date()); } if (window.XDomainRequest) { //  IE,     (-  IE8) setTimeout(function () { $this.poll_IE($this); }, 2000); } else { //  XMLHttpRequest  mcXHR = xhr = new XMLHttpRequest(); xhr.onreadystatechange = xhr.onload = function () { if (4 === xhr.readyState) { //    if (200 === xhr.status && xhr.responseText.length > 0) { //  Etag  Last-Modified  Header  $this.etag = xhr.getResponseHeader('Etag'); $this.time = xhr.getResponseHeader('Last-Modified'); //    $this.action(xhr.responseText); } if (xhr.status > 0) { //       $this.poll($this, xhr); } } }; //  long polling $this.poll($this, xhr); } }, poll: function ($this, xhr) { var timestamp = (new Date()).getTime(), url = 'http://stream.example.com/sub/' + subID + '?callback=?&v=' + timestamp; // timestamp       xhr.open('GET', url, true); xhr.setRequestHeader("If-None-Match", $this.etag); xhr.setRequestHeader("If-Modified-Since", $this.time); xhr.send(); }, //      poll(),   IE poll_IE: function ($this) { var xhr = new window.XDomainRequest(); var timestamp = (new Date()).getTime(), url = 'http://stream.example.com/sub/' + subID + '?callback=?&v=' + timestamp; xhr.onprogress = function () {}; xhr.onload = function () { $this.action(xhr.responseText); $this.poll_IE($this); }; xhr.onerror = function () { $this.poll_IE($this); }; xhr.open('GET', url, true); xhr.send(); }, action: function (event) { //  ,    -  ... }, valueToTwoDigits: function (value) { return ((value < 10) ? '0' : '') + value; }, //     UTC dateToUTCString: function () { var time = this.valueToTwoDigits(date.getUTCHours()) + ':' + this.valueToTwoDigits(date.getUTCMinutes()) + ':' + this.valueToTwoDigits(date.getUTCSeconds()); return this.days[date.getUTCDay()] + ', ' + this.valueToTwoDigits(date.getUTCDate()) + ' ' + this.months[date.getUTCMonth()] + ' ' + date.getUTCFullYear() + ' ' + time + ' GMT'; } } рд╕рдЪ); var LongPolling = { etag: 0, time: null, init: function () { var $this = this, xhr; if ($this.time === null) { $this.time = $this.dateToUTCString(new Date()); } if (window.XDomainRequest) { //  IE,     (-  IE8) setTimeout(function () { $this.poll_IE($this); }, 2000); } else { //  XMLHttpRequest  mcXHR = xhr = new XMLHttpRequest(); xhr.onreadystatechange = xhr.onload = function () { if (4 === xhr.readyState) { //    if (200 === xhr.status && xhr.responseText.length > 0) { //  Etag  Last-Modified  Header  $this.etag = xhr.getResponseHeader('Etag'); $this.time = xhr.getResponseHeader('Last-Modified'); //    $this.action(xhr.responseText); } if (xhr.status > 0) { //       $this.poll($this, xhr); } } }; //  long polling $this.poll($this, xhr); } }, poll: function ($this, xhr) { var timestamp = (new Date()).getTime(), url = 'http://stream.example.com/sub/' + subID + '?callback=?&v=' + timestamp; // timestamp       xhr.open('GET', url, true); xhr.setRequestHeader("If-None-Match", $this.etag); xhr.setRequestHeader("If-Modified-Since", $this.time); xhr.send(); }, //      poll(),   IE poll_IE: function ($this) { var xhr = new window.XDomainRequest(); var timestamp = (new Date()).getTime(), url = 'http://stream.example.com/sub/' + subID + '?callback=?&v=' + timestamp; xhr.onprogress = function () {}; xhr.onload = function () { $this.action(xhr.responseText); $this.poll_IE($this); }; xhr.onerror = function () { $this.poll_IE($this); }; xhr.open('GET', url, true); xhr.send(); }, action: function (event) { //  ,    -  ... }, valueToTwoDigits: function (value) { return ((value < 10) ? '0' : '') + value; }, //     UTC dateToUTCString: function () { var time = this.valueToTwoDigits(date.getUTCHours()) + ':' + this.valueToTwoDigits(date.getUTCMinutes()) + ':' + this.valueToTwoDigits(date.getUTCSeconds()); return this.days[date.getUTCDay()] + ', ' + this.valueToTwoDigits(date.getUTCDate()) + ' ' + this.months[date.getUTCMonth()] + ' ' + date.getUTCFullYear() + ' ' + time + ' GMT'; } } )ред getTime (), var LongPolling = { etag: 0, time: null, init: function () { var $this = this, xhr; if ($this.time === null) { $this.time = $this.dateToUTCString(new Date()); } if (window.XDomainRequest) { //  IE,     (-  IE8) setTimeout(function () { $this.poll_IE($this); }, 2000); } else { //  XMLHttpRequest  mcXHR = xhr = new XMLHttpRequest(); xhr.onreadystatechange = xhr.onload = function () { if (4 === xhr.readyState) { //    if (200 === xhr.status && xhr.responseText.length > 0) { //  Etag  Last-Modified  Header  $this.etag = xhr.getResponseHeader('Etag'); $this.time = xhr.getResponseHeader('Last-Modified'); //    $this.action(xhr.responseText); } if (xhr.status > 0) { //       $this.poll($this, xhr); } } }; //  long polling $this.poll($this, xhr); } }, poll: function ($this, xhr) { var timestamp = (new Date()).getTime(), url = 'http://stream.example.com/sub/' + subID + '?callback=?&v=' + timestamp; // timestamp       xhr.open('GET', url, true); xhr.setRequestHeader("If-None-Match", $this.etag); xhr.setRequestHeader("If-Modified-Since", $this.time); xhr.send(); }, //      poll(),   IE poll_IE: function ($this) { var xhr = new window.XDomainRequest(); var timestamp = (new Date()).getTime(), url = 'http://stream.example.com/sub/' + subID + '?callback=?&v=' + timestamp; xhr.onprogress = function () {}; xhr.onload = function () { $this.action(xhr.responseText); $this.poll_IE($this); }; xhr.onerror = function () { $this.poll_IE($this); }; xhr.open('GET', url, true); xhr.send(); }, action: function (event) { //  ,    -  ... }, valueToTwoDigits: function (value) { return ((value < 10) ? '0' : '') + value; }, //     UTC dateToUTCString: function () { var time = this.valueToTwoDigits(date.getUTCHours()) + ':' + this.valueToTwoDigits(date.getUTCMinutes()) + ':' + this.valueToTwoDigits(date.getUTCSeconds()); return this.days[date.getUTCDay()] + ', ' + this.valueToTwoDigits(date.getUTCDate()) + ' ' + this.months[date.getUTCMonth()] + ' ' + date.getUTCFullYear() + ' ' + time + ' GMT'; } } рд╕рдЪ); var LongPolling = { etag: 0, time: null, init: function () { var $this = this, xhr; if ($this.time === null) { $this.time = $this.dateToUTCString(new Date()); } if (window.XDomainRequest) { //  IE,     (-  IE8) setTimeout(function () { $this.poll_IE($this); }, 2000); } else { //  XMLHttpRequest  mcXHR = xhr = new XMLHttpRequest(); xhr.onreadystatechange = xhr.onload = function () { if (4 === xhr.readyState) { //    if (200 === xhr.status && xhr.responseText.length > 0) { //  Etag  Last-Modified  Header  $this.etag = xhr.getResponseHeader('Etag'); $this.time = xhr.getResponseHeader('Last-Modified'); //    $this.action(xhr.responseText); } if (xhr.status > 0) { //       $this.poll($this, xhr); } } }; //  long polling $this.poll($this, xhr); } }, poll: function ($this, xhr) { var timestamp = (new Date()).getTime(), url = 'http://stream.example.com/sub/' + subID + '?callback=?&v=' + timestamp; // timestamp       xhr.open('GET', url, true); xhr.setRequestHeader("If-None-Match", $this.etag); xhr.setRequestHeader("If-Modified-Since", $this.time); xhr.send(); }, //      poll(),   IE poll_IE: function ($this) { var xhr = new window.XDomainRequest(); var timestamp = (new Date()).getTime(), url = 'http://stream.example.com/sub/' + subID + '?callback=?&v=' + timestamp; xhr.onprogress = function () {}; xhr.onload = function () { $this.action(xhr.responseText); $this.poll_IE($this); }; xhr.onerror = function () { $this.poll_IE($this); }; xhr.open('GET', url, true); xhr.send(); }, action: function (event) { //  ,    -  ... }, valueToTwoDigits: function (value) { return ((value < 10) ? '0' : '') + value; }, //     UTC dateToUTCString: function () { var time = this.valueToTwoDigits(date.getUTCHours()) + ':' + this.valueToTwoDigits(date.getUTCMinutes()) + ':' + this.valueToTwoDigits(date.getUTCSeconds()); return this.days[date.getUTCDay()] + ', ' + this.valueToTwoDigits(date.getUTCDate()) + ' ' + this.months[date.getUTCMonth()] + ' ' + date.getUTCFullYear() + ' ' + time + ' GMT'; } } ',' var LongPolling = { etag: 0, time: null, init: function () { var $this = this, xhr; if ($this.time === null) { $this.time = $this.dateToUTCString(new Date()); } if (window.XDomainRequest) { //  IE,     (-  IE8) setTimeout(function () { $this.poll_IE($this); }, 2000); } else { //  XMLHttpRequest  mcXHR = xhr = new XMLHttpRequest(); xhr.onreadystatechange = xhr.onload = function () { if (4 === xhr.readyState) { //    if (200 === xhr.status && xhr.responseText.length > 0) { //  Etag  Last-Modified  Header  $this.etag = xhr.getResponseHeader('Etag'); $this.time = xhr.getResponseHeader('Last-Modified'); //    $this.action(xhr.responseText); } if (xhr.status > 0) { //       $this.poll($this, xhr); } } }; //  long polling $this.poll($this, xhr); } }, poll: function ($this, xhr) { var timestamp = (new Date()).getTime(), url = 'http://stream.example.com/sub/' + subID + '?callback=?&v=' + timestamp; // timestamp       xhr.open('GET', url, true); xhr.setRequestHeader("If-None-Match", $this.etag); xhr.setRequestHeader("If-Modified-Since", $this.time); xhr.send(); }, //      poll(),   IE poll_IE: function ($this) { var xhr = new window.XDomainRequest(); var timestamp = (new Date()).getTime(), url = 'http://stream.example.com/sub/' + subID + '?callback=?&v=' + timestamp; xhr.onprogress = function () {}; xhr.onload = function () { $this.action(xhr.responseText); $this.poll_IE($this); }; xhr.onerror = function () { $this.poll_IE($this); }; xhr.open('GET', url, true); xhr.send(); }, action: function (event) { //  ,    -  ... }, valueToTwoDigits: function (value) { return ((value < 10) ? '0' : '') + value; }, //     UTC dateToUTCString: function () { var time = this.valueToTwoDigits(date.getUTCHours()) + ':' + this.valueToTwoDigits(date.getUTCMinutes()) + ':' + this.valueToTwoDigits(date.getUTCSeconds()); return this.days[date.getUTCDay()] + ', ' + this.valueToTwoDigits(date.getUTCDate()) + ' ' + this.months[date.getUTCMonth()] + ' ' + date.getUTCFullYear() + ' ' + time + ' GMT'; } } 


рджреЛ рдорд╛рдкрджрдВрдбреЛрдВ etag рдФрд░ рд╕рдордп рдХрд╛ рдЙрд▓реНрд▓реЗрдЦ рдХрд░рдирд╛ рдорд╣рддреНрд╡рдкреВрд░реНрдг рд╣реИред
 xhr.setRequestHeader("If-None-Match", $this.etag); xhr.setRequestHeader("If-Modified-Since", $this.time); 

рдЙрдирдХреЗ рдмрд┐рдирд╛ рдХрд╛рдо рд▓рдВрдмреЗ рд╕рдордп рд╕реЗ рдорддрджрд╛рди рд╣рдореЗрд╢рд╛ рдирд╣реАрдВ рд╣реИ рдФрд░ рд╕рдВрджреЗрд╢ рдлрд┐рд░ рд╕реЗ рдХреЗ рдорд╛рдзреНрдпрдо рд╕реЗ рдЖрдпрд╛ рдерд╛ред рдЗрди рджреЛ рдорд╛рдкрджрдВрдбреЛрдВ рдХреА рдЬрд░реВрд░рдд рдирдЧреАрдирдХреНрд╕-рдкреБрд╢-рд╕реНрдЯреНрд░реАрдо-рдореЙрдбреНрдпреВрд▓ рджреНрд╡рд╛рд░рд╛ рдЙрди рд╕рдВрджреЗрд╢реЛрдВ рдХреА рдкрд╣рдЪрд╛рди рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП рд╣реИ рдЬреЛ рдЧреНрд░рд╛рд╣рдХ рдХреЛ рдЕрднреА рддрдХ рдирд╣реАрдВ рдорд┐рд▓реЗ рд╣реИрдВред рддреЛ рд╕реНрдерд┐рд░ рдСрдкрд░реЗрд╢рди рдХреЗ рд▓рд┐рдП рдмрд╣реБрдд рдЬрд░реВрд░реА рд╣реИред

рдирд┐рд╖реНрдХрд░реНрд╖ рдореЗрдВ


рдЗрд╕ рд╡рд┐рд╖рдп рдореЗрдВ рд╡рд░реНрдгрд┐рдд рд╡рд┐рдзрд┐ рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИ рдФрд░ рд╣рдорд╛рд░реЗ Cackle рдЯрд┐рдкреНрдкрдгреА рдкреНрд░рдгрд╛рд▓реА рдореЗрдВ рд╕рдлрд▓рддрд╛рдкреВрд░реНрд╡рдХ рдХрд╛рдо рдХрд░рддрд╛ рд╣реИ ред рд╣рд░ рджрд┐рди рд╣рдорд╛рд░реЗ рдкрд╛рд╕ рд▓рдЧрднрдЧ 20,000 - 30,000 рд╕рдорд╡рд░реНрддреА рдЧреНрд░рд╛рд╣рдХ рд╣реИрдВ, рдФрд░ рд╣рдордиреЗ рд╕рдВрджреЗрд╢ рд╡рд┐рддрд░рдг рдореЗрдВ рдХреЛрдИ рддреНрд░реБрдЯрд┐ рдирд╣реАрдВ рджреЗрдЦреА рд╣реИред рдЙрддреНрдкрд╛рджрди рд╕рдорд╛рдзрд╛рди рдХреЗ рд▓рд┐рдП, рдпрд╣ рд╡рд╣реА рд╣реИ рдЬреЛ рдЖрдкрдХреЛ рдЪрд╛рд╣рд┐рдПред

Source: https://habr.com/ru/post/In167895/


All Articles