Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Readme examples update

  • Loading branch information...
commit cc3839a9370ebb841c4fc3fe18b820366c3ec9df 1 parent 522f839
@rwaldron authored
Showing with 89 additions and 89 deletions.
  1. +89 −89 README.markdown
View
178 README.markdown
@@ -18,7 +18,7 @@ and falls back to Ajax polling logic when it's not. Contributions must conform t
## Some Thoughts...
* Q. why use EventSource rather than Websockets?<br>
- A. EventSource is easier to setup on server (uses http), lighter and most of the times - that's what you acually need. (via temp01)
+ A. EventSource is easier to setup on server (uses http), lighter and most of the times - that's what you acually need. (via temp01)
## Real World Example
@@ -40,121 +40,121 @@ and falls back to Ajax polling logic when it's not. Contributions must conform t
## Usage
- $.eventsource({
-
- // Assign a label to this event source
-
- label: 'event-source-label',
+ $.eventsource({
+
+ // Assign a label to this event source
+
+ label: "event-source-label",
- // Set the file to receive data from the server
+ // Set the file to receive data from the server
- url: 'event-sources/server-event-source.php',
-
- // Set the type of data you expect to be returned
- // text, json supported
-
- dataType: 'json',
-
- // Set a callback to fire when the event source is opened
- // `onopen`
- open: function (data) {
+ url: "event-sources/server-event-source.php",
+
+ // Set the type of data you expect to be returned
+ // text, json supported
+
+ dataType: "json",
+
+ // Set a callback to fire when the event source is opened
+ // `onopen`
+ open: function( data ) {
- console.log(data);
+ console.log( data );
- },
+ },
- // Set a callback to fire when a message is received
- // `onmessage`
- message: function (data) {
+ // Set a callback to fire when a message is received
+ // `onmessage`
+ message: function( data ) {
- console.log(data);
+ console.log( data );
- }
- });
-
-
- // Close event sources by label name
-
- $.eventsource('close', 'event-source-label');
-
+ }
+ });
+
+
+ // Close event sources by label name
+
+ $.eventsource("close", "event-source-label");
+
## Varied Content Type Usage
-
- // PLAIN TEXT EXAMPLE - NO CONTENT TYPE GIVEN
- $.eventsource({
- label: 'text-event-source',
- url: 'test-event-sources/text-event-source.php',
- open: function () {
+
+ // PLAIN TEXT EXAMPLE - NO CONTENT TYPE GIVEN
+ $.eventsource({
+ label: "text-event-source",
+ url: "test-event-sources/text-event-source.php",
+ open: function() {
- console.log( 'opened' );
+ console.log( "opened" );
- },
- message: function (data) {
+ },
+ message: function( data ) {
- console.log(data);
+ console.log( data );
- $.eventsource('close', 'text-event-source');
- }
- });
-
- // PLAIN TEXT EXAMPLE - HAS CONTENT TYPE
- $.eventsource({
- label: 'text-event-source-ct',
- url: 'test-event-sources/text-event-source-ct.php',
- dataType: 'text',
+ $.eventsource("close", "text-event-source");
+ }
+ });
+
+ // PLAIN TEXT EXAMPLE - HAS CONTENT TYPE
+ $.eventsource({
+ label: "text-event-source-ct",
+ url: "test-event-sources/text-event-source-ct.php",
+ dataType: "text",
- message: function (data) {
+ message: function( data ) {
- console.log(data);
+ console.log( data );
- $.eventsource('close', 'text-event-source-ct');
- }
- });
+ $.eventsource("close", "text-event-source-ct");
+ }
+ });
- // JSON EXAMPLE - HAS CONTENT TYPE
- $.eventsource({
- label: 'json-event-source',
- url: 'test-event-sources/json-event-source.php',
- dataType: 'json',
- open: function () {
+ // JSON EXAMPLE - HAS CONTENT TYPE
+ $.eventsource({
+ label: "json-event-source",
+ url: "test-event-sources/json-event-source.php",
+ dataType: "json",
+ open: function() {
- console.log( 'opened' );
-
- },
- message: function (data) {
+ console.log( "opened" );
+
+ },
+ message: function( data ) {
- console.log(data);
+ console.log( data );
- $.eventsource('close', 'json-event-source');
- }
- });
-
+ $.eventsource("close", "json-event-source");
+ }
+ });
+
## Accessing your current event sources:
-
- // Returns an object containing all the currently active eventsource streams
- $.eventsource('streams')
+
+ // Returns an object containing all the currently active eventsource streams
+ $.eventsource("streams")
-
+
## Server Source Requirements
-
- // Server response MUST be Content-Type: text/event-stream
- // Server response MUST be prepended with 'data: '
-
-
- // Examples:
-
- // PHP
- header("Content-Type: text/event-stream\n\n");
- echo 'data: this is a valid response';
-
-
- // Python
- print "Content-Type: text/event-stream"
- print "data: this is a valid response"
+
+ // Server response MUST be Content-Type: text/event-stream
+ // Server response MUST be prepended with "data: "
+
+
+ // Examples:
+
+ // PHP
+ header("Content-Type: text/event-stream\n\n");
+ echo "data: this is a valid response";
+
+
+ // Python
+ print "Content-Type: text/event-stream"
+ print "data: this is a valid response"
Please sign in to comment.
Something went wrong with that request. Please try again.