npx rwaldron
Or
npx rwaldron --xmas
Harnessing the EventSource API with jQuery
seems to have issue with master branch file jquery.eventsource.js
when using Example 3 : JSON open callback (url: '../test-event-sources/event-source-2.php')
there are JS error : "streamData[idx].split is not a function"
seems error caused by line: 125:
" return !!sdata && sdata;"
when I changed it with code from "futures" branch
if ( sdata ) {
return sdata;
}
issue disapear
This happens on Windows7 professional Apache Web Server , browser FireFox 4.0.1
Browser: chromium
Version: 6.0.472.62 (59676) Ubuntu 10.04
Browser: Firefox
Version: 3.6.10 (Ubuntu 10.04)
The chat area was one big blank, white area. Don't know if people saw what I sent to the channel.
Hi!
I have spinner issue described at http://groups.google.com/a/chromium.org/group/chromium-html5/browse_thread/thread/be1a6ee5b0af3a3d for 12.0.742.112 (90304) Built on Ubuntu 11.04, running on LinuxMint 11.
Wonder if we could employ the provided solution (deferring)
TIA,
--Vladimir
Hi!
Wonder if we could augment the eventsource instance with #send() method, which could send an async request to listening URL using specified dataType. So to say, provide a requesting capability.
TIA,
--Vladimir
We have encountered two issues when using the plugin with IE 9 and IE 10.
We have observed that when an Ajax call times out because there are no new events, the source in not queried again.
We have also observed multiple parallel requests because the timer set to poll the source again after processing the events from the current request is not fired once, but multiple times.
We have refactored the code to poll again into a separate method and we have added an error handler for the Ajax call, handler that calls this refactored method.
When the fall-back implementation is used, the Last-Event-ID request header is not set. Due to this, our server application sends all the events, both new and old, on each request.
To resolve this problem we have made a change to get the lastEventId value from the parsed data and we have added the Last-Event-ID header to the Ajax call.
public
is a keyword - therefor it causes error when using a compressor e.g. yuicompressor.
Solution:
Enclose in doublequotes:
pluginFns = {
"public": {
and access using pluginFns["public"]
instead of pluginFns.public
.
Alternatively rename it.
Also about test-units
There are 2 test that failed
1.Non-Native Streams are [object XMLHttpRequest]
Expected: "[object XMLHttpRequest]"
Result: "[object Object]"
..........................
2.Non-Native Streams are [object XMLHttpRequest]
Expected:"[object XMLHttpRequest]"
Result: "[object Object]"
Are you sure that they should be [object XMLHttpRequest] ?
because, from JQuery docs :
"The jqXHR Object
The jQuery XMLHttpRequest (jqXHR) object returned by $.ajax() as of jQuery 1.5 is a superset of the browser's native XMLHttpRequest object. For example, it contains responseText and responseXML properties, as well as a getResponseHeader() method. When the transport mechanism is something other than XMLHttpRequest (for example, a script tag for a JSONP request) the jqXHR object simulates native XHR functionality where possible.
As of jQuery 1.5.1, the jqXHR object also contains the overrideMimeType method.
The yakyakface Test Suite is broken, because it loads the master version of QUnit via github, and the API has changed: test() vs QUnit.test()
etc.
The Bocoup one gives a 404.
I saw in that page : http://www.html5rocks.com/en/tutorials/eventsource/basics/#toc-reconnection-timeout
that is possible to control reconnection timeout, but in your code in fallback function - it is hard-coded to 500 !
setTimeout(
function () {
pluginFns._private.openPollingSource.call( this, options );
},
// matches speed of host api EventSource
500
);
When I try it in Chrome - that use Native EventSource and set in php file immediately after content type
header("Content-Type: text/event-stream\n\n"); echo "retry: 10000\n"; //set reconnection-timeout to 10sec. echo 'data: ' . json_encode( array( 0 => array( 'time' => time(), 'message' => 'Some kind of foo' ), 1 => array( 'time' => time(), 'message' => 'Some kind of quux' ) ) ) . "\n";
Chrome try to reconnect exactly after 10 sec.
But Firefox - that use fallback - not.
Also , depending to W3C specifications there are other fields that can be sent from server
http://dev.w3.org/html5/eventsource/#processField
your code seems to parse only DATA field and probably "last event ID" (no test it)
but when i set "retry" field (before data field) - parsing of DATA seems to goes wrong - it messes with "retry" field.
I make some changes to test setting retry time
(see code marked by //DOBRYS)
//--------------------------------------------
// open fallback event source
openPollingSource: function ( options ) {
var rec_timeout = 400;//DOBRYS
var label = options.label,
source;
if ( stream.cache[label] ) {
source = jQuery.ajax({
type: "GET",
url: options.url,
data: options.data,
beforeSend: function () {
if ( stream.cache[label] ) {
this.label = label;
stream.cache[label].options.open.call( this );
}
},
success: function ( data ) {
var tempdata,
label = options.label,
parsedData = [],
streamData = jQuery.map( data.split("\n"), function(sdata, i) {
return !!sdata && sdata;
}),
idx = 0, length = streamData.length;
if ( jQuery.isArray(streamData) ) {
console.log('???');
console.log(streamData)
//something in that loop mess code formating in issue field
//so, will replace loop with dummy val..
for (idx loop) {
if ( streamData[idx] ) {
tempdata = streamData[idx].split("data: ")[1];
//DOBRYS
if(streamData[idx].split("retry: ")[1]){
rec_timeout = streamData[idx].split("retry: ")[1];//DOBRYS
}//eof DOBRYS
// Convert `dataType` here
if ( options.dataType === "json" ) {
tempdata = jQuery.parseJSON( tempdata );
}
parsedData[ parsedData.length ] = tempdata;
}
}
}
if ( stream.cache[label] ) {
this.label = label;
stream.cache[label].lastEventId++;
stream.cache[label].history[stream.cache[label].lastEventId] = parsedData;
stream.cache[label].options.message.call(this, parsedData[0] ? parsedData[0] : null, {
data: parsedData,
lastEventId: stream.cache[label].lastEventId
});
console.log('rec_timeout: ' + rec_timeout);//DOBRYS
var reconnect_time_out = rec_timeout ? rec_timeout : 500;//DOBRYS
console.log('reconnect_time_out:' + reconnect_time_out);//DOBRYS
setTimeout(
function () {
pluginFns._private.openPollingSource.call( this, options );
},
// matches speed of host api EventSource
reconnect_time_out
);
}
},
cache: false,
timeout: 50000
});
}
return source;
}
//--------------------------------------------
With these changes - reconnect timeout seems to work.
But "data" in message: function(data) { ....
is NULL
Think that is from adding "retry" field before data field (in php file)
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.