yaffle / eventsource Goto Github PK
View Code? Open in Web Editor NEWa polyfill for http://www.w3.org/TR/eventsource/
License: MIT License
a polyfill for http://www.w3.org/TR/eventsource/
License: MIT License
I have the sse running in a frame to maintain the persistent connection while navigating to various pages in a different frame. Whenever I click the "back" button, the connection to the server is lost. It will reconnect after the heartbeat timeout. Is this expected behavior? This does not happen when using IE.
Hi,
I use token sent in the Authorization header to authenticate/authorized the user for every xhr request. With SSE, it does not seems to be sent. I set the withCredentials flag, but it didn't changed anaything.
How can I have the token sent with the request that open the SSE ?
I would like to send cookies to server. IE11 native EventSource does not do it.
I`ve modified your code to send cookies via:
// Add cookies if document has them
if (document.cookie) {
xhr.setRequestHeader("Cookie", document.cookie);
}
Is it possible to send cookies using EventSource API?
As far as I understand I can only send something adding it to url (via query string our Authorization header).
eventsource.js file contain following security bridges:
User Input validation, Code injection.
Is any mitigation plan exists? secure version or hardening guide?
Thanks
Hi,
We are interested in using EventSource in an upcoming project. However, we need fallback support for older browsers. What we would like to do is that in browsers that do not support either EventSource or XDomainRequest to fall back to getting all the events as a single XMLHttpRequest request.
I realize for a lot of applications of EventSource this is not very useful but for us it would be suitable fallback behavior. If we were to fork your project to add this capability then any advice from you on how best to approach this would be greatly appreciated.
Thanks in advance,
David
Hi!
Wonder if you find feasible to follow the spec:
The url attribute must return the absolute URL that resulted from resolving the value that was passed to the constructor.
--Vladimir
Following the SSE spec, my server sends a 204 when it wants the client to stop connecting
Event stream requests can be redirected using HTTP 301 and 307 redirects as with normal HTTP requests. Clients will reconnect if the connection is closed; a client can be told to stop reconnecting using the HTTP 204 No Content response code.
However this library does not obey that and floods console with errors.
Uncaught Error: EventSource's response has a status 204 No Content that is not 200. Aborting the connection.
Uncaught Error: EventSource's response has a status 204 No Content that is not 200. Aborting the connection.
Uncaught Error: EventSource's response has a status 204 No Content that is not 200. Aborting the connection.
Uncaught Error: EventSource's response has a status 204 No Content that is not 200. Aborting the connection.
Uncaught Error: EventSource's response has a status 204 No Content that is not 200. Aborting the connection.
Uncaught Error: EventSource's response has a status 204 No Content that is not 200. Aborting the connection.
...
in eventsource.js on line 234 I get this error in IE8:
EventSource's response has a Content-Type specifying an unsupported type: . Aborting the connection
(The Content-type is empty string)
Hello,
I've got "Uncaught Error: INVALID_STATE_ERR: DOM Exception 11" in Google Chrome 18 after couple of minutes without new messages.
How it could be fixed?
Thanks.
Hello, I'm at a loss to make the polyfill work with IE8 & IE9.
I'm using Rails ActionController : live streaming, working well on all browsers and IE10+
But no chance on IE9-.
I see many potential points to look at, and all take a very long time to debug, maybe you will be able to orient me towards the most probable chokepoint?
Request:
Key Value
Request GET /sse/sse/382?lastEventId=&r=5939317963395745 HTTP/1.1
Accept /
Origin http://192.168.0.10:3000
Accept-Language en-GB
Accept-Encoding gzip, deflate
User-Agent Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
Host 192.168.0.10:3000
DNT 1
Connection Keep-Alive
Cache-Control no-cache
Response:
Key Value
Response HTTP/1.1 200 OK
X-Frame-Options ALLOWALL
Content-Type text/event-stream
Access-Control-Allow-Origin http://192.168.0.10:3000
Cache-Control no-cache
Access-Control-Allow-Methods GET, POST, OPTIONS
Access-Control-Max-Age 1728000
Access-Control-Allow-Credentials true
Vary Origin
P3P CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
X-Request-Id 2692b893-d8c5-43f5-8411-ea3eb153b5d7
X-Runtime 0.239124
Transfer-Encoding chunked
arr=Array.new(2049)
sse.write ":"+arr.join(" ")+"\n"
sse.write "retry: 2000\n"
and rest of the message + "\n\n"
I'm sending this when connecting the SSE only, and not in every chunk (I tried to send it for every chunk at first but it didn't change anything). Is this the correct way of doing it? I believe so, and the padding doesnt cause any issue in other browsers.
"heartbeat" , I was already using one (every 15 seconds) to make the controller awake of dying threads (following http://stackoverflow.com/questions/18970458/redis-actioncontrollerlive-threads-not-dying). The only difference I could see with your code is that I was previously sending "{event: 'heartbeat', data:'heartbeat'}\n\n" while you talked about a comment message, so now I'm sending ":keepalive "+DateTime.now.to_s+"\n\n". But it doesn't change anything
add ids to events. As of now I dont use any ids. May that break the polyfill process??
I tried to print some log from the polyfill code to see where it broke and it happens a line 322, because isLoadEnd=true; Indeed if I override this function so that isLoadEnd stays false:
function onLoadEnd() {
//onProgress(true);
//LV
onProgress(false);
}
then the connection stays open - but I still dont have data coming in, and anyway this must be wrong as I have no clue what is onLoadEnd(), or what this line is for:
// XDomainRequest#abort removes onprogress, onerror, onload
xhr.onload = xhr.onerror = onLoadEnd;
Any clue? Already spent one week to make Rails ActionController live + Puma work on my app, I'd rather not spend another one to make it IE8/IE9 compatible (not practical to not use SSE for some browsers only on the app).
Many thanks,
L
We use EventSource in our local HTTP server implementation. Currently it doesn't work offline due to that code:
if (navigator.onLine === false) {
// "online" event is not supported under Web Workers
// https://bugs.webkit.org/show_bug.cgi?id=118832
timeout = setTimeout(onTimeout, 500);
return;
}
I think the condition should be something like that:
if (navigator.onLine === false && location.hostname !== '127.0.0.1' && location.hostname !== 'localhost')
Hi!
Since shim is done by means of various XHR flavors, which all have #send() method, I believe it would be useful to expose this method from polyfill object, and augment native EventSource with such method. That way we'd have bidirectional channel out-of-the-box. The rationale is that all dirty work for determining the best XHR flavor available in target browser already is done. Please, consider and comment.
TIA,
--Vladimir
The following code statement -
var isXHR = isCORSSupported;
var Transport = isCORSSupported ? XHR : (XDR != undefined ? XDR : undefined);
is making these assumptions:
This results in failure to use this polyfill where XHR does not have CORS support.
The latest release doesn't seem to be available on npm yet. :)
Cheers!
I'm getting js error SECURITY_ERR: DOM Exception 18
on in place:
var isEventSourceSupported = function () {
if (global.EventSource !== undefined) {
try {
var es = new global.EventSource("data:text/event-stream;charset=utf-8,");
es.close();
return es.withCredentials === false &&
es.url !== ""; // to filter out Opera 12 implementation
} catch (error) {
throwError(error);
}
}
return false;
};
By line es.close();
Line 490 in 62be4ad
PhantomJS 1.9.8
I work on a project which uses Yaffle/EventSource and server-sent events. I came across a problem while trying to test the SSE functionality with Selenium Firefox WebDriver. The problem is that WebDriver's any operations(ex, findElement
, getCurrentUrl
and so on) are blocked while EventSource's connection is open.
I tried to fix this problem, but I couldn't. Does anyone have any idea to avoid this blocking issue?
The followings are the code that reproduces this problem.
This PHP code below provides both functionalities of server side and client side of server-sent events. This file is hosted as http://192.168.0.77/tests/stream.php
.
I wrote two client code for comparison. The first one uses XMLHtttpRequest
and another uses EventSource
.
<?php
function stream()
{
// server side code
header("Content-Type: text/event-stream");
header("Cache-Control: no-cache");
header("Access-Control-Allow-Origin: *");
for ($i = 5; $i >= 0; $i--) {
echo 'data: ' . $i . "\n\n";
ob_flush();
flush();
sleep(1);
}
}
if (isset($_GET['stream'])) {
stream();
exit;
}
$use = isset($_GET['use']) ? $_GET['use'] : "xhr";
// following is client side code.
?>
<!DOCTYPE html>
<h1>Stream (<?= $use ?>)</h1>
<div>Response:</div>
<pre id="response"></pre>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://raw.githubusercontent.com/Yaffle/EventSource/63b50221ea2c9440fae84d6f98895b911db43807/eventsource.js"></script>
<script>
(function () {
var STREAM_URL = './stream.php?stream';
// client code one
function xhr() {
var xhr = new XMLHttpRequest();
xhr.open('GET', STREAM_URL);
xhr.seenBytes = 0;
xhr.onreadystatechange = function () {
if (xhr.readyState > 2) {
var newData = xhr.responseText.substr(xhr.seenBytes);
$("#response").append(newData);
xhr.seenBytes = xhr.responseText.length;
}
};
xhr.send();
}
// client code two
function eventsource() {
var es = new EventSource(STREAM_URL);
es.addEventListener('message', function (event) {
$("#response").append(event.data + "\n");
if (event.data == 0) es.close();
}, false);
}
<?= $use ?>(); // function is dynamically provided by PHP.
}());
</script>
</html>
This is Scala code which drives Selenium WebDriver.
import org.openqa.selenium.By
import org.openqa.selenium.remote.{ DesiredCapabilities, RemoteWebDriver }
import org.scalatest.FunSuite
class ServerSentEventsSpec extends FunSuite {
test("with `XMLHttpRequest`") {
val hubUrl = "http://192.168.0.1:5556/wd/hub"
val driver = new RemoteWebDriver(new java.net.URL(hubUrl), DesiredCapabilities.firefox())
driver.get("http://192.168.0.77/tests/stream.php?use=xhr")
println(new java.util.Date())
val text = driver.findElement(By.xpath("//html")).getText // This line is not blocked.
println(text)
println(new java.util.Date())
driver.quit()
}
test("with `EventSource`") {
val hubUrl = "http://192.168.0.1:5556/wd/hub"
val driver = new RemoteWebDriver(new java.net.URL(hubUrl), DesiredCapabilities.firefox())
driver.get("http://192.168.0.77/tests/stream.php?use=eventsource")
println(new java.util.Date())
val text = driver.findElement(By.xpath("//html")).getText // This line is blocked for about 5 seconds!
println(text)
println(new java.util.Date())
driver.quit()
}
}
XMLHttpRequest
"In this case, Firefox WebDriver could immediately get the text of the web page .
Thu Nov 27 07:59:39 UTC 2014
Stream (xhr)
Response:
data: 5
Thu Nov 27 07:59:39 UTC 2014
EventSource
"In this case, as you can see, Firefox WebDriver waited until EventSource
received all events.
Thu Nov 27 07:59:32 UTC 2014
Stream (eventsource)
Response:
5
4
3
2
1
0
Thu Nov 27 07:59:37 UTC 2014
In Internet Explorer 9, I get an "Unspecified error" at line 373 (xhr.send).
The same script on the same machine is working fine with FF.
Do you have any idea where this could come from ?
I can give you debug data if you need.
Right now I can tell you that Transport is set to global.XDomainRequest (xhr2 and global.ProgressEvent are undefined).
In the past, the recommendation was to use this polyfill for all clients even if their browser had a native implementation. I believe the reasoning was that the native implementations were buggy and issues were not fixed very quickly.
Is this still the recommendation? Are the native implementations of EventSource now more stable/performant than the polyfill? I'm working on a project using SSE and initially planned to only use the polyfill for IE and Edge. Now I'm wondering if I should use the polyfill across the board.
We have used this polyfill in an WebView in an Android app. Unfortunately, it crashes the app on Android 4.4.2 (noticed on multiple devices, e.g. Samsung GT-I9505), the line responsible for the crash is that:
var es = new global.EventSource("data:text/event-stream;charset=utf-8,");
You can reproduce it with only this one line in an empty WebView.
This is what appears in the device log:
F/libc ( 6834): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 6860 (example.webviewtest)
I/chromium( 6834): [INFO:CONSOLE(0)] "EventSource cannot load data:text/event-stream;charset=utf-8,. Cross origin requests are only supported for HTTP.", source: http://192.168.0.1/wahlcomputer/ (0)
E/MP-Decision( 2116): num online cores: 4 reqd : 2 available : 4 rq_depth:1.500000 hotplug_avg_load_dw: 123
E/MP-Decision( 2116): DOWN cpu:3 core_idx:3 Ns:3.100000 Ts:240 rq:1.500000 seq:245.000000
E/MP-Decision( 2116): DOWN cpu:2 core_idx:2 Ns:2.100000 Ts:240 rq:1.500000 seq:245.000000
E/MP-Decision( 2116): num online cores: 2 reqd : 1 available : 4 rq_depth:0.000000 hotplug_avg_load_dw: 19
E/MP-Decision( 2116): DOWN cpu:1 core_idx:1 Ns:1.100000 Ts:190 rq:0.000000 seq:42.000000
D/SSRMv2:CustomFrequencyManagerService( 816): releaseDVFSLockLocked : Getting Lock type frm List : DVFS_MIN_LIMIT frequency : 1350000 uid : 1000 pid : 816 tag : ACTIVITY_RESUME_BOOSTER@9
I/DEBUG ( 268): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG ( 268): Build fingerprint: 'samsung/jfltexx/jflte:4.4.2/KOT49H/I9505XXUGNG8:user/release-keys'
I/DEBUG ( 268): Revision: '11'
I/DEBUG ( 268): pid: 6834, tid: 6860, name: example.webviewtest >>> com.example.webviewtest <<<
I/DEBUG ( 268): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000000
I/ServiceKeeper( 816): In getpackagename pid = 816 uid = 1000 package name = android
I/ServiceKeeper( 816): In getpackagename pid = 816 uid = 1000 package name = android
V/AudioPolicyManagerBase( 281): stopOutput() output 2, stream 1, session 142
V/AudioPolicyManagerBase( 281): changeRefCount() stream 1, count 0
W/AudioPolicyManagerBase( 281): stream type [13], return media strategy
W/AudioPolicyManagerBase( 281): stream type [13], return media strategy
W/AudioPolicyManagerBase( 281): stream type [13], return media strategy
W/AudioPolicyManagerBase( 281): stream type [13], return media strategy
W/AudioPolicyManagerBase( 281): stream type [13], return media strategy
W/AudioPolicyManagerBase( 281): stream type [13], return media strategy
V/AudioPolicyManagerBase( 281): getNewDevice() selected device 0
V/AudioPolicyManagerBase( 281): setOutputDevice() output 2 device 0000 force 0 delayMs 192
V/AudioPolicyManagerBase( 281): setOutputDevice() prevDevice 0002
W/AudioPolicyManagerBase( 281): stream type [13], return media strategy
W/AudioPolicyManagerBase( 281): stream type [13], return media strategy
V/AudioPolicyManagerBase( 281): setOutputDevice() setting same device 0000 or null device for output 2
I/DEBUG ( 268): r0 00000000 r1 00000000 r2 00000003 r3 0000002c
I/DEBUG ( 268): r4 7c470a10 r5 740673a7 r6 00000000 r7 7a5d16d8
I/DEBUG ( 268): r8 74a506d5 r9 00000001 sl 7a75d508 fp 78ae6ac8
I/DEBUG ( 268): ip 00000001 sp 78c1a078 lr 74a506bf pc 74a4f95e cpsr 200b0030
I/DEBUG ( 268): d0 0000000000000000 d1 0000000000000000
I/DEBUG ( 268): d2 00200072006f0066 d3 0050005400540048
I/DEBUG ( 268): d4 e12fff1ee28dd004 d5 78ae5b6ce7f001f1
I/DEBUG ( 268): d6 43145dc7435a393c d7 412e848000000000
I/DEBUG ( 268): d8 41d55b0af9811661 d9 3fe0000000000000
I/DEBUG ( 268): d10 0000000000000000 d11 0000000000000000
I/DEBUG ( 268): d12 0000000000000000 d13 0000000000000000
I/DEBUG ( 268): d14 0000000000000000 d15 0000000000000000
I/DEBUG ( 268): d16 0070007400740068 d17 0031002f002f003a
I/DEBUG ( 268): d18 0031002e00320039 d19 0034002e00380036
I/DEBUG ( 268): d20 003000300031002e d21 006800610077002f
I/DEBUG ( 268): d22 006d006f0063006c d23 0065007400750070
I/DEBUG ( 268): d24 3f95c966ebf3f9e8 d25 bf95c966c155d531
I/DEBUG ( 268): d26 402213664f3f26db d27 4000000000000000
I/DEBUG ( 268): d28 3ffcea4783f8a3fe d29 bfcc400000000026
I/DEBUG ( 268): d30 3ff0000000000000 d31 40c3880000000005
I/DEBUG ( 268): scr 3a000013
I/DEBUG ( 268):
I/DEBUG ( 268): backtrace:
I/DEBUG ( 268): #00 pc 00db495e /system/lib/libwebviewchromium.so
I/DEBUG ( 268): #01 pc 00db56bb /system/lib/libwebviewchromium.so
I/DEBUG ( 268): #02 pc 005881bb /system/lib/libwebviewchromium.so
I/DEBUG ( 268): #03 pc 005882d3 /system/lib/libwebviewchromium.so
I/DEBUG ( 268): #04 pc 00588635 /system/lib/libwebviewchromium.so
I/DEBUG ( 268): #05 pc 00588677 /system/lib/libwebviewchromium.so
I/DEBUG ( 268): #06 pc 00625ad7 /system/lib/libwebviewchromium.so
I/DEBUG ( 268): #07 pc 00db4e37 /system/lib/libwebviewchromium.so
I/DEBUG ( 268): #08 pc 00db556b /system/lib/libwebviewchromium.so
I/DEBUG ( 268): #09 pc 00778081 /system/lib/libwebviewchromium.so
I/DEBUG ( 268): #10 pc 00b6e7ab /system/lib/libwebviewchromium.so
I/DEBUG ( 268): #11 pc 00b7781b /system/lib/libwebviewchromium.so
I/DEBUG ( 268): #12 pc 00000b78 <unknown>
I/DEBUG ( 268):
I/DEBUG ( 268): stack:
I/DEBUG ( 268): 78c1a038 7c46cb90
I/DEBUG ( 268): 78c1a03c 00000000
I/DEBUG ( 268): 78c1a040 74ea35f0 /system/lib/libwebviewchromium.so
I/DEBUG ( 268): 78c1a044 2182472c
I/DEBUG ( 268): 78c1a048 78c1a0bc [stack:6860]
I/DEBUG ( 268): 78c1a04c 00000003
I/DEBUG ( 268): 78c1a050 00000001
I/DEBUG ( 268): 78c1a054 00000001
I/DEBUG ( 268): 78c1a058 00000001
I/DEBUG ( 268): 78c1a05c 740673a1 /system/lib/libwebviewchromium.so
I/DEBUG ( 268): 78c1a060 00000000
I/DEBUG ( 268): 78c1a064 2182472c
I/DEBUG ( 268): 78c1a068 78c1a0a0 [stack:6860]
I/DEBUG ( 268): 78c1a06c 78ff6de4
I/DEBUG ( 268): 78c1a070 00000000
I/DEBUG ( 268): 78c1a074 7c470a10
I/DEBUG ( 268): #00 78c1a078 7c470a10
I/DEBUG ( 268): 78c1a07c 00000000
I/DEBUG ( 268): 78c1a080 00000003
I/DEBUG ( 268): 78c1a084 7c470a10
I/DEBUG ( 268): 78c1a088 740673a7 /system/lib/libwebviewchromium.so
I/DEBUG ( 268): 78c1a08c 74a506bf /system/lib/libwebviewchromium.so
I/DEBUG ( 268): #01 78c1a090 00000000
I/DEBUG ( 268): 78c1a094 73fc7709 /system/lib/libwebviewchromium.so
I/DEBUG ( 268): 78c1a098 78c1a0dc [stack:6860]
I/DEBUG ( 268): 78c1a09c 7a5d1870
I/DEBUG ( 268): 78c1a0a0 7a5d1870
I/DEBUG ( 268): 78c1a0a4 78ff6dd8
I/DEBUG ( 268): 78c1a0a8 74c11aab /system/lib/libwebviewchromium.so
I/DEBUG ( 268): 78c1a0ac 7c46d6e0
I/DEBUG ( 268): 78c1a0b0 74c11aab /system/lib/libwebviewchromium.so
I/DEBUG ( 268): 78c1a0b4 7c46d6e0
I/DEBUG ( 268): 78c1a0b8 74b9e413 /system/lib/libwebviewchromium.so
I/DEBUG ( 268): 78c1a0bc 78ff6dd8
I/DEBUG ( 268): 78c1a0c0 7c46d6e0
I/DEBUG ( 268): 78c1a0c4 74b9e413 /system/lib/libwebviewchromium.so
I/DEBUG ( 268): 78c1a0c8 74c11aab /system/lib/libwebviewchromium.so
I/DEBUG ( 268): 78c1a0cc 7c46d6e0
I/DEBUG ( 268): ........ ........
I/DEBUG ( 268): #02 78c1a0e8 78c1a0f8 [stack:6860]
I/DEBUG ( 268): 78c1a0ec 73fc85b9 /system/lib/libwebviewchromium.so
I/DEBUG ( 268): 78c1a0f0 7a5d16d8
I/DEBUG ( 268): 78c1a0f4 7a5d1850
I/DEBUG ( 268): 78c1a0f8 7a5d1870
I/DEBUG ( 268): 78c1a0fc 7a5d1850
I/DEBUG ( 268): 78c1a100 00000000
I/DEBUG ( 268): 78c1a104 7c46d6e0
I/DEBUG ( 268): 78c1a108 7a5d1870
I/DEBUG ( 268): 78c1a10c 74000000 /system/lib/libwebviewchromium.so
I/DEBUG ( 268): 78c1a110 7dace518
I/DEBUG ( 268): 78c1a114 7a5d16d8
I/DEBUG ( 268): 78c1a118 78c1a260 [stack:6860]
I/DEBUG ( 268): 78c1a11c 00000001
I/DEBUG ( 268): 78c1a120 74f3fe54 /system/lib/libwebviewchromium.so
I/DEBUG ( 268): 78c1a124 742232d7 /system/lib/libwebviewchromium.so
I/DEBUG ( 268):
I/DEBUG ( 268): memory near r4:
I/DEBUG ( 268): 7c4709f0 00000000 00000000 00000000 00000000
I/DEBUG ( 268): 7c470a00 78b05360 7a5c6be0 00320039 0000011b
I/DEBUG ( 268): 7c470a10 74f2aa58 00000002 74f4bbd8 74f2aab8
I/DEBUG ( 268): 7c470a20 74f2aaf0 21824780 00000000 00000001
I/DEBUG ( 268): 7c470a30 00750001 00000000 00000004 00000000
I/DEBUG ( 268): 7c470a40 ffffffff 00000000 ffffffff 00000000
I/DEBUG ( 268): 7c470a50 ffffffff 00000000 ffffffff 00000005
I/DEBUG ( 268): 7c470a60 00000020 00000000 ffffffff 00000000
I/DEBUG ( 268): 7c470a70 ffffffff 00000000 7c46d6e0 00000000
I/DEBUG ( 268): 7c470a80 00000000 7c46d730 00000000 ffffffff
I/DEBUG ( 268): 7c470a90 74f2aa40 00000008 00000000 00000000
I/DEBUG ( 268): 7c470aa0 00000000 00000000 00000000 00000000
I/DEBUG ( 268): 7c470ab0 ffffffff 00000000 00000000 7c470a10
I/DEBUG ( 268): 7c470ac0 74a4fe99 00000000 00000000 00000000
I/DEBUG ( 268): 7c470ad0 00000000 00000000 00000000 00000000
I/DEBUG ( 268): 7c470ae0 00000000 00000000 00000000 00000000
I/DEBUG ( 268):
I/DEBUG ( 268): memory near r5:
I/DEBUG ( 268): 74067384 f7fc4620 b148fe18 46399b0c e88d4632
I/DEBUG ( 268): 74067394 462b0018 043cf8d0 fa34f1eb e8bdb005
I/DEBUG ( 268): 740673a4 f1a083f0 f7ff0054 0000bfc5 4604b5f7
I/DEBUG ( 268): 740673b4 32ecf8d0 f890b1db b9c662e9 ad026800
I/DEBUG ( 268): 740673c4 7140f8d0 f75d2004 4909fe59 31084479
I/DEBUG ( 268): 740673d4 f8456001 46200d04 47b84629 f5c24628
I/DEBUG ( 268): 740673e4 4630fb40 fd00f5b8 f8842201 bdfe22e9
I/DEBUG ( 268): 740673f4 00e39404 4604b5f8 460e6882 eb036803
I/DEBUG ( 268): 74067404 eb030581 e0030782 0b04f855 fcecf5b8
I/DEBUG ( 268): 74067414 d1f942bd bdf860a6 43f7e92d 27004604
I/DEBUG ( 268): 74067424 0954f100 f8d4e02c 68050618 a8016007
I/DEBUG ( 268): 74067434 f5c29701 f8d4fb16 b9091620 e9e0f5b5
I/DEBUG ( 268): 74067444 8618f8d4 f8564646 f5b80b04 f8d4fccd
I/DEBUG ( 268): 74067454 f8d42620 46403618 eb034631 ebc60c82
I/DEBUG ( 268): 74067464 f5b5020c f8d4ea04 1e410620 1620f8c4
I/DEBUG ( 268): 74067474 4628682a 68934649 46284798 fcb4f5b8
I/DEBUG ( 268):
I/DEBUG ( 268): memory near r7:
I/DEBUG ( 268): 7a5d16b8 00000000 00000000 00000000 00000000
E/MP-Decision( 2116): num online cores: 1 reqd : 2 available : 4 rq_depth:2.200000 hotplug_avg_load_dw: 57
E/MP-Decision( 2116): UP cpu:1 core_idx:1 Nw:1.900000 Tw:140 rq:2.200000 seq:49.000000
I/DEBUG ( 268): 7a5d16c8 00000000 00000000 00000000 000000f3
I/DEBUG ( 268): 7a5d16d8 7a5d0001 00000000 00000004 00000000
I/DEBUG ( 268): 7a5d16e8 ffffffff 00000000 ffffffff 00000000
I/DEBUG ( 268): 7a5d16f8 ffffffff 00000000 ffffffff 00000005
I/DEBUG ( 268): 7a5d1708 00000020 00000000 ffffffff 00000000
I/DEBUG ( 268): 7a5d1718 ffffffff 00000000 7c46d6e0 00000000
I/DEBUG ( 268): 7a5d1728 00000000 00000000 ffc00000 41dfffff
I/DEBUG ( 268): 7a5d1738 00000000 00000000 ffffffff 00000000
I/DEBUG ( 268): 7a5d1748 ffffffff 00000000 ffffffff 00000000
I/DEBUG ( 268): 7a5d1758 ffffffff 00000000 ffffffff 00000000
I/DEBUG ( 268): 7a5d1768 ffffffff 00000000 ffffffff 00000000
I/DEBUG ( 268): 7a5d1778 ffffffff 00000000 00000000 00000000
I/DEBUG ( 268): 7a5d1788 78a81778 7dace5d0 00000008 00000007
I/DEBUG ( 268): 7a5d1798 00000003 00000000 00000000 00000000
I/DEBUG ( 268): 7a5d17a8 00000001 00000000 00000000 00000000
I/DEBUG ( 268):
I/DEBUG ( 268): memory near r8:
I/DEBUG ( 268): 74a506b4 47a8ab0b f7ff4620 980bf94d f574b108
I/DEBUG ( 268): 74a506c4 b013db31 bf00bd30 001c14b1 0014ddfd
I/DEBUG ( 268): 74a506d4 000cf1a0 bf86f7ff 460eb573 46044615
I/DEBUG ( 268): 74a506e4 b112b930 0028f102 f5a8e02e e02bfce1
I/DEBUG ( 268): 74a506f4 f5714610 6803f373 e016b30b 0001f022
I/DEBUG ( 268): 74a50704 6840e000 6863bb00 462aa802 f8401c59
I/DEBUG ( 268): 74a50714 60614d04 f5c24631 4605f187 b1109801
I/DEBUG ( 268): 74a50724 f6903004 4628d9fb a902e00e f8413008
I/DEBUG ( 268): 74a50734 46694d08 dc2df5df d1e22800 68a2e7e2
I/DEBUG ( 268): 74a50744 0001f012 e7ddd1da b5f7bd7c 4606460f
I/DEBUG ( 268): 74a50754 f018a801 683dfa82 603b2300 f5b19c01
I/DEBUG ( 268): 74a50764 6862f875 46284601 ffb6f7ff 46204601
I/DEBUG ( 268): 74a50774 fa1cf018 1d28b115 d9d0f690 f367f578
I/DEBUG ( 268): 74a50784 460568a2 b11a6860 f5a86811 4602fe29
I/DEBUG ( 268): 74a50794 46304629 f5b0f577 f6fb4620 4630f6fb
I/DEBUG ( 268): 74a507a4 0000bdfe b087b530 9d0b4604 980d990c
I/DEBUG ( 268):
I/DEBUG ( 268): memory near sl:
I/DEBUG ( 268): 7a75d4e8 00000000 00000000 7a75d4e8 7a75d4e8
I/DEBUG ( 268): 7a75d4f8 00000000 00000000 000000b8 00000023
I/DEBUG ( 268): 7a75d508 00000003 7c517980 7c46b530 7c46b530
I/DEBUG ( 268): 7a75d518 00000000 00000000 00000000 00000053
I/DEBUG ( 268): 7a75d528 74e93088 7c470c40 73ef0fcb 7c4f5f88
I/DEBUG ( 268): 7a75d538 7a75d518 7c470c3f 7c470c20 00000001
I/DEBUG ( 268): 7a75d548 78a82df0 00000001 00000004 7c46c590
I/DEBUG ( 268): 7a75d558 00000000 00000000 7a75d558 7a75d558
I/DEBUG ( 268): 7a75d568 00000000 228db417 400c0101 0000001b
I/DEBUG ( 268): 7a75d578 74f3b228 00000001 74a7d7f1 00000000
I/DEBUG ( 268): 7a75d588 78a88ee8 00000053 74e93030 7a75dda0
I/DEBUG ( 268): 7a75d598 00776569 7a7fd320 7a75d59b 7a75dd9b
I/DEBUG ( 268): 7a75d5a8 7a75dd80 00000001 78fed150 00000001
I/DEBUG ( 268): 7a75d5b8 00000002 7a7a0140 00000000 00000000
I/DEBUG ( 268): 7a75d5c8 7a75d5c0 7a75d5c0 00000000 7a75e620
I/DEBUG ( 268): 7a75d5d8 00000050 0000003b 74e930e0 7c471f60
I/DEBUG ( 268):
I/DEBUG ( 268): memory near fp:
I/DEBUG ( 268): 78ae6aa8 2fb1e6e5 791248f9 2fb1e70d 79124915
I/DEBUG ( 268): 78ae6ab8 2fb1e735 7912492d 2fb1e75d 79124945
I/DEBUG ( 268): 78ae6ac8 3b026ea1 00000013 7c4767f8 00000000
I/DEBUG ( 268): 78ae6ad8 00000010 0000001b 78b1ce58 78ae4e68
I/DEBUG ( 268): 78ae6ae8 789efda8 78ae71d0 3b01da15 00000013
I/DEBUG ( 268): 78ae6af8 789ef918 79112109 7911212d 0000008b
I/DEBUG ( 268): 78ae6b08 78b1c6b8 78b1c48c 00000000 00000000
I/DEBUG ( 268): 78ae6b18 00000000 00000000 00000000 00000000
I/DEBUG ( 268): 78ae6b28 00000000 00000000 00000000 00000000
I/DEBUG ( 268): 78ae6b38 00000000 00000000 00000000 00000000
I/DEBUG ( 268): 78ae6b48 00000000 00000000 00000000 00000000
I/DEBUG ( 268): 78ae6b58 00000000 00000100 00000000 00000000
I/DEBUG ( 268): 78ae6b68 00000000 00000000 00000000 00000000
I/DEBUG ( 268): 78ae6b78 00000000 00000000 00760000 00000000
I/DEBUG ( 268): 78ae6b88 004d0079 00000013 00000002 400c01c8
I/DEBUG ( 268): 78ae6b98 00000010 0000002b 00000001 74f4bc38
I/DEBUG ( 268):
I/DEBUG ( 268): memory near sp:
I/DEBUG ( 268): 78c1a058 00000001 740673a1 00000000 2182472c
I/DEBUG ( 268): 78c1a068 78c1a0a0 78ff6de4 00000000 7c470a10
I/DEBUG ( 268): 78c1a078 7c470a10 00000000 00000003 7c470a10
I/DEBUG ( 268): 78c1a088 740673a7 74a506bf 00000000 73fc7709
I/DEBUG ( 268): 78c1a098 78c1a0dc 7a5d1870 7a5d1870 78ff6dd8
I/DEBUG ( 268): 78c1a0a8 74c11aab 7c46d6e0 74c11aab 7c46d6e0
I/DEBUG ( 268): 78c1a0b8 74b9e413 78ff6dd8 7c46d6e0 74b9e413
I/DEBUG ( 268): 78c1a0c8 74c11aab 7c46d6e0 74b9e413 7a5d1870
I/DEBUG ( 268): 78c1a0d8 78c1a0f8 78c1a0f8 7c470a1c 742231bd
I/DEBUG ( 268): 78c1a0e8 78c1a0f8 73fc85b9 7a5d16d8 7a5d1850
I/DEBUG ( 268): 78c1a0f8 7a5d1870 7a5d1850 00000000 7c46d6e0
I/DEBUG ( 268): 78c1a108 7a5d1870 74000000 7dace518 7a5d16d8
I/DEBUG ( 268): 78c1a118 78c1a260 00000001 74f3fe54 742232d7
I/DEBUG ( 268): 78c1a128 7dace518 78c1a260 7a5d16d8 00000000
I/DEBUG ( 268): 78c1a138 7dace518 78c1a260 00000001 00000001
I/DEBUG ( 268): 78c1a148 74f3fe54 74223639 000000b0 78c1a1d4
I/DEBUG ( 268):
I/DEBUG ( 268): code around pc:
I/DEBUG ( 268): 74a4f93c 0230f104 466d62e6 3308447b e8826023
I/DEBUG ( 268): 74a4f94c 46200003 bf00bd7c 004db0f0 4604b537
I/DEBUG ( 268): 74a4f95c 68036f80 47886819 69c56820 da70f5e7
I/DEBUG ( 268): 74a4f96c 46132200 0198f100 f613a801 4620dfe5
I/DEBUG ( 268): 74a4f97c 47a8a901 b1109801 f5e03008 bd3edbd7
I/DEBUG ( 268): 74a4f98c bfe4f7ff 000cf1a0 bffaf7ff 4604b57f
I/DEBUG ( 268): 74a4f99c f1002500 f8a00680 e9d05072 f7cd0138
I/DEBUG ( 268): 74a4f9ac ed9fc2bc 22007b12 ec432300 ed8d2b11
I/DEBUG ( 268): 74a4f9bc ec411b00 ee860b16 46300b07 2b10ec53
I/DEBUG ( 268): 74a4f9cc d8a3f704 69de6823 da3af5e7 462b462a
I/DEBUG ( 268): 74a4f9dc 0198f100 f613a803 4620dfaf 47b0a903
I/DEBUG ( 268): 74a4f9ec b1109803 f5e03008 bd7fdba1 00000000
I/DEBUG ( 268): 74a4f9fc 408f4000 20c5f890 b1724603 2072f9b0
I/DEBUG ( 268): 74a4fa0c f8802100 2a0210c5 f7ffd001 69c0bfbf
I/DEBUG ( 268): 74a4fa1c 1d181e41 f61661d9 47709976 b1137c4b
I/DEBUG ( 268): 74a4fa2c f8a02102 f7ff1072 f1a0bfe5 f7ff000c
I/DEBUG ( 268):
I/DEBUG ( 268): code around lr:
I/DEBUG ( 268): 74a5069c dff9f602 68416820 47884620 21012200
I/DEBUG ( 268): 74a506ac 92006803 6add2203 47a8ab0b f7ff4620
I/DEBUG ( 268): 74a506bc 980bf94d f574b108 b013db31 bf00bd30
I/DEBUG ( 268): 74a506cc 001c14b1 0014ddfd 000cf1a0 bf86f7ff
I/DEBUG ( 268): 74a506dc 460eb573 46044615 b112b930 0028f102
I/DEBUG ( 268): 74a506ec f5a8e02e e02bfce1 f5714610 6803f373
I/DEBUG ( 268): 74a506fc e016b30b 0001f022 6840e000 6863bb00
I/DEBUG ( 268): 74a5070c 462aa802 f8401c59 60614d04 f5c24631
I/DEBUG ( 268): 74a5071c 4605f187 b1109801 f6903004 4628d9fb
I/DEBUG ( 268): 74a5072c a902e00e f8413008 46694d08 dc2df5df
I/DEBUG ( 268): 74a5073c d1e22800 68a2e7e2 0001f012 e7ddd1da
I/DEBUG ( 268): 74a5074c b5f7bd7c 4606460f f018a801 683dfa82
I/DEBUG ( 268): 74a5075c 603b2300 f5b19c01 6862f875 46284601
I/DEBUG ( 268): 74a5076c ffb6f7ff 46204601 fa1cf018 1d28b115
I/DEBUG ( 268): 74a5077c d9d0f690 f367f578 460568a2 b11a6860
I/DEBUG ( 268): 74a5078c f5a86811 4602fe29 46304629 f5b0f577
D/STATUSBAR-NetworkController( 1175): refreshSignalCluster: data=-1 bt=false
D/STATUSBAR-IconMerger( 1175): checkOverflow(576), More:false, Req:false Child:2
I/DEBUG ( 268): !@dumpstate -k -t -z -d -o /data/log/dumpstate_app_native -m 6834
I/BootReceiver( 816): Copying /data/tombstones/tombstone_07 to DropBox (SYSTEM_TOMBSTONE)
W/ActivityManager( 816): Force finishing activity com.example.webviewtest/.MainActivity
Both Firefox's and Chrome's EventSource
impls put a reference to the EventSource
object in the Event
s it passes to the listeners, in a target
attribute. This makes conditionally .close
-ing the EventSource
from a message listener very easy (i.e. evt.target.close()
).
Unfortunately, this polyfill does not do this, so one either has to close over the EventSource
object when adding listeners, or partially apply the object to a listener function defined elsewhere.
It'd be nice if there was a component.json
file to support installing this with component.
I'm wondering why there isn't better error handling?
XHR requests do send useful error messages, but you trigger onerror
without that information.
I was wondering if there was a special reason for that, if not, I wouldn't mind implementing it myself and submitting a pull request.
Hi,
drag and drop polyfill for Opera is not as perfect as expected.
I have a little html5 application which allows to edit some data for an object consisting of a main div element which is dragable and
contain 5 childs (1 img or div and 4 further divs). If I issue a double click on the object, I open a window allowing to set/modify some datas. This don't work for opera with your script operaDragAndDrop.js.
Drag and drop seem not to work for me, the only event I get are dragstart and dragend.
Regards
cant work in IIS php server
The polyfill is not usable for streaming (chunked) responses from yahoo queries as the response is a json object (and not in the hardcoded format).
Is there anyway to use the polyfill with json responses like above?
I tried to port the above but got stuck at the line 204 of the code.
EventSource has a long-polling fallback for browsers that don't support event streams.
EventSource also supports cross-domain-requests.
In IE9 you need to make an XDomainRequest (instead of XMLHttpRequest) if you want to do a cross-domain-request.
The problem is that code doesn't check properly whether the request is a cross-domain-request when deciding between XDR or XHR, it just always uses XDR (in IE9). This is important because an XDR requires a CORS policy (Allow-Access-* headers). It's silly to require a CORS policy for same-domain-requests. Not settings the CORS policy headers will cause IE9 to discard the response.
De decision is:
Transport = isCORSSupported ? XHR : (XDR !== undefined ? XDR : undefined)
As you can see it just checks whether CORS is supported, not wether CORS is required. Later on when Transport
is about to be used there is:
var withCredentials = isCORSSupported && options !== undefined && Boolean(options.withCredentials);
We can use withCredentials
to decide between XDR or XHR:
var xhr = new Transport(); // always yields XDR (in IE9)
// change to:
var xhr = withCredentials ? new Transport() : new XHR();
This fixes the problem but I feel like a refactor is required.
What if a cross-domain-request is required but is not supported?
This is related to: #41 but the suggestion to force XHR is silly, it should use whatever is required (but prefer XHR). I think my fix also solves that issue.
Good day!
I was reading through eventsource.js and saw something strange at Line 133.
Line 131: function getDuration(value, def) {
Line 132: var n = value;
Line 133: if (n !== n) {
Line 134: n = def;
Line 135: }
Line 136: return (n < MINIMUM_DURATION ? MINIMUM_DURATION : (n > MAXIMUM_DURATION ? MAXIMUM_DURATION : n));
Line 137: }
Is there any mistake here? Seems like the if statement will never be false.
It was changed in the cae1b45 or cae1b45#diff-e3467803443c0c8c621be962b3a7127b for convenience.
It was previously the following.
Line 131: function getDuration(value, def) {
Line 132: var n = Number(value) || def;
Line 133: return (n < MINIMUM_DURATION ? MINIMUM_DURATION : (n > MAXIMUM_DURATION ? MAXIMUM_DURATION : n));
Line 134: }
Regards,
William
It'd be nice to see an option to force XHR usage if we know the request won't be cross-origin, that way we can get the Cookie header from IE (since they are not sent under any circumstances with XDR) with the request.
I need cookies for requests that are within the same domain.
This is using XDomainRequest in IE8 for any type of request, so cookies are never set. Is there any workaround?
Thanks
Hi,
Maybe someone can explain, where I can find a problem.
In error logs I found, that only with this User-Agents EventSource doesn't work:
Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.3; rv:11.0) like Gecko
Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; AskTbORJ/5.15.9.29495; McAfee; BRI/2; GWX:DOWNLOADED; rv:11.0) like Gecko
Also, I see, that callback "onopen" and "onclose" works, but "onmessage" not.
Thank you for your help!
I was playing around with "eventsource.min.js" from branch master (generated 5 months ago) to figure out if it could avoid using XDomainRequest even in older IE in favor of XMLHttpRequest (because I´m only calling back to my own server so don´t need CORS but want the authentication cookie to be present).
Reading through the source code of the current "eventsource.js" (non-minified) I discovered the "Transport" option and decided to replace my minified older version with the current non-minified version and have a closer look.
After I did that and without changing anything else my app suddenly appeared to slow down for certain events:
All events are supposed to append some text to the page body.
The first and final event work as expected and their content appears in the browser right after they are logged server side.
With intermediate events, however, there suddenly is a significant lag between the time they are logged at the server and when their output appears in the browser.
I´m initializing the object like so:
var events = new EventSource('/resultblocks');
events.addEventListener('block', function(ev) {
document.body.innerHTML += ev.data + '<br/>';
console.log("chunk " + count++ + ': ' + ev.data.substring(0, 10));
}, false);
events.addEventListener('end', function(ev) {
document.body.innerHTML += "closing event stream";
events.close();
}, false);
The first and the intermediate events are "block" events.
So far, I ran my tests in IE 11 on Win7 Pro.
My JS knowledge is quite limited so I have no idea which changes that have gone in eventsource.js since eventsource.min.js was generated may cause the differing behavior.
I see this error
The data necessary to complete this operation is not yet available.
eventsource.js, line 192 character 7
latest version from master.
var eventSource = new EventSource(url, {
withCredentials: true,
Transport: XMLHttpRequest
});
Any idea how I can provide a better report?
Thanks
Edit: the value received in onEvent is empty
I am observing the following problematic behavior in all versions since 931f9d7 (tested till bc9b9e4 as of yesterday):
Every event I send from the server fires my event callback for the message
event 3 times instead of once (tested with Safari 6.0.2 on OSX).
Version 4c8a191 does not exhibit this behavior, so something in 931f9d7 broke it for me.
My event handler is a pretty basic echo test along these lines:
es = new EventSource('/events');
es.addEventListener('message', function (event) {
console.log('message', event);
$.get('/pingback/' + encodeURIComponent(event.data));
}, false);
Any idea what might cause this?
The setTimeout()
and clearTimeout()
methods are normally available in the window context and hence the code makes that assumption. However, the XHR/XDR interfaces are referenced through global
, which is a parameter to the immediately invoked function expression (IIFE).
This "issue" is a request to have the timer functions also accessed via global
, so that it is usable in non-browser JavaScript environment (E.g. QML).
Aside:
A related request would be to see an alternate approach than passing this
to IIFE. Say, expecting an object instance by a naming convention - i.e. instead of }(this));
using }(eventSourceConfig));
, where eventSourceConfig
would fill all the interfaces required by the EventSource polyfill.
[I know this will break existing users :-) but would like to hear opinions]
i could not find any hints about a license.
Without a license, the code is copyrighted by default. People can read the code, but they have no legal right to use it.
is this intended?
We decided to use this implementation since even the default Chrome implementation has given us trouble. Often the connection would not be reconnected automatically.
One example of this is when the server returns a 5xx error. Native Chrome will not attempt to reconnect, however this implementation will which I think is a better approach. I'm not entirely sure which approach is conforming to standards but in my case I prefer to always reconnect. I posted a question about this on StackOverflow and I will post a link to this library as an answer once my testing is completed (http://stackoverflow.com/questions/18275210/server-sent-events-nginx-proxy-breaks-reconnect-how-to-turn-off-nginx-502-err).
I've been looking through the code, but I'm still a bit unclear about when the library is trying to reconnect and when not. Are there certain cases when it will not reconnect on purpose or are all disconnects (including the server closing the connection on purpose) going to result in an automated reconnect?
I've also been wondering about this section in the documentation: "You need to send "comment" messages each 15-30 seconds, this messages will be used as heartbeat to detect disconnects". I haven't been able to find anything about "comment" messages in relation to EventSource. What I'm doing right now is to send ":keepalive" messages from the server every 30 seconds with the following node.js code. Is that sufficient?
setInterval(function() {
resp.write(":keepalive " + Date.now() + "\n\n");
}, 30000);
Thanks in advance for your help.
I wanted to use Yaffle to add CORS support to Chrome and Firefox; in my use-case I don't care about Internet Explorer, and I simply wanted to add CORS support.
The use-case is hosting a Rack application on a different port to stream events out of a Rails application. Rails development mode servers need to be locked into a "threadsafe" mode, which precludes reloading code and a bunch of other inconveniences.
I built a simple rack app which streams events out of Redis, published and subscribed using Redis pubsub. Using redis pubsub if there's no client, the message goes nowhere, this was chosen by design, as the page can hold the sse connection open if it wants, or the user can navigate away and their messages go into the ether.
With Yaffle, CORS works as expected (Rack app is using rack-cors
to allow all origins) but the repeated drop/pickup of the connection to the sse endpoint won't work for me, because I don't track "last messages", the messages are supposed to be ephemeral.
FWIW, this is only a rails dev mode thing, in Production the code would always be preloaded, and production servers support long lived, and multiple connections (of course).
I'm using the EventSource polyfill during development with a server that uses a self signed certificate when connecting via HTTPS. Everytime I use EventSource an "error" event is thrown immediately using those HTTPS connection.
Maybe I have configured it wrong. So, a point in the right direction great ;)
Output:
bower event-source-polyfill#0.0.3 not-cached git://github.com/Yaffle/EventSource.git#0.0.3
bower event-source-polyfill#0.0.3 resolve git://github.com/Yaffle/EventSource.git#0.0.3
bower event-source-polyfill#0.0.3 ENORESTARGET No tag found that was able to satisfy 0.0.3
Additional error details:
Available versions: 0.0.1
It didn't work with my own front/back-end code (whereas latest Firefox/Chrome did), so I then setup the example PHP back-end, and the example html front-end, but still no luck (still working in Firefox/Chrome). On the android browser I just see a blank screen. In the logs I can see eventsource.js was requested.
After waiting a few minutes I have three lines of "closed" on the android browser, and three apache log entries for events.php (at 19:02:30, 19:03:17, 19:04:40).
Then, waiting some more, its behaviour changes again and I get
opened:events.php
1;2;3;4...99;
closed
opened:events.php
closed
opened:events.php
closed
opened:events.php
closed
(and this is repeating every 2 seconds now, and each is causing a new entry in apache log)
[Android 2.3]
How many clients were you able to connect through EventSource on one server instance?
Hi! First of all, thanks for the good job. It is the first EventSource emulation I found, that really support error handling and truly work in FF.
BTW: I've spent all day yesterday trying to make FF proprietary multipart XMLHttpRequest error handling to work - but I failed, FF still loses any kind of disconnection events after multipart XMLHttpRequest receives first packet of data; looks like a FF bug.
So, about EventSource, just a few suggestions:
Thanks)
Using Chrome 24.0.1305.3 dev. Commit of polyfill: a51d92f.
I receive error "XMLHttpRequest.responseType "moz-chunked-text" is not supported." when subscribing to the stream..
Thanks for help, suggestions!
How combined with worder?
Hi, I'm trying to implement a sort of messages system with EventSource, angular, node and redis.
When the user logout it calls the close function, but I see that node don't stop the connection (it continues to output "{"err":null,"results":null}").
Angular code
var StreamHandler = {
set: function(){
var source = new EventSource('http://localhost:8080/stream');
MessageStream = source;
},
get: function(scope){
var source = MessageStream;
source.addEventListener('message', function(event) {
scope.$apply(function () {
scope.messages.push(JSON.parse(event.data));
var x = JSON.parse(event.data);
console.log(x);
});
}, false);
source.onerror = function(error) {
source.close();
console.log("CONN CLOSED");
}
},
close: function(){
// Verify if a Stream exist
if(MessageStream) {
var source = MessageStream;
source.close();
console.log("CONN CLOSED WITH LOGOUT");
}
} };
Node server.js
var express = require('express')
, cors = require('cors')
, redis = require("redis")
, app = express();
app.use(cors());
// Redis connection
client = redis.createClient();
app.get('/stream', function(req, res) {
logger = function(err, results) {
if(results != null) {
res.write("data:" + results + "\n\n");
}
console.log(JSON.stringify({err: err, results: results}));
};
setInterval(function() {
client.rpop("user:" + 2 + ":msg", logger);
}, 5000);
//send headers for event-stream connection
res.writeHead(200, {
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive'
});
res.on("close", function () {
console.log("CONN CLOSE")
res.end();
});
});
app.listen(8080, function(){
console.log('CORS-enabled web server listening on port 80');
});
hi! i'm using eventsource as a polyfill for internet explorer (of course), but, when using grunt-uglify plugin for my builds, i noticed that there are no "bang" comments in eventsource. at least, it is good to use them at least in the license section so it can be preserved in automated builds.
you can read more about here: https://github.com/mishoo/UglifyJS2#keeping-copyright-notices-or-other-comments
also, including it to bower would be nice (as another user already suggested).
best regards,
richard.
I am very new to Java programming, so I would like to beg a little forgiveness for my ignorance...
First of all, my test environment is Win7, 2008 Server R2, with Internet Exploder 11 and Chrome 32.0.1700.107.
Anyway, I took your PHP index.htm example directly from your example code, wrote a simple php server that does a MySql database query and returns a result.
Here is my problem: Each time there is a data update, rather than replace the previous line of text, the new data appears below the previous line which ultimately scrolls forever. Also, if I try to add any HTML tags, ("<.br><.b><.table>", etc.), it only displays them as plain text. i.e. "<.b>Test</.b>".
Can you please help me with this, or at least point me in the right direction?
Thanks
Ken
Hey,
Is there any support for custom event triggering by "event: " or a workaround to achieve this functionality?
Thanks!
UPDATE: Oh my, this is embarrassing. I was not adding "\n" at the end of the line. Sorry! You can close this issue.
More a question than an issue…
The README states:
It is required to send 2 KB padding for IE < 10 and Chrome < 13 at the top of the response stream
Is this still required? I don't see anything in the code that implies or accounts for a 2KB prelude, and everything seems to work fine with my application with very small eventstreams (< 500 bytes).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.