Coder Social home page Coder Social logo

jquery.eventsource's Introduction

npx rwaldron

Or

npx rwaldron --xmas

jquery.eventsource's People

Contributors

rwaldron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jquery.eventsource's Issues

issue :: streamData[idx].split is not a function

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

yakyak doesn't work on chromium & ff

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.

#send

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

Polling and Last-Event-ID issues with IE

We have encountered two issues when using the plugin with IE 9 and IE 10.

  1. 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.

  2. 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 and causes errors

publicis 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.

Test for correct jqXHR object

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.

configurable retry time

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.