play.libs
Class EventSource

java.lang.Object
  extended by play.mvc.Results.Chunks<java.lang.String>
      extended by play.libs.EventSource

public abstract class EventSource
extends Results.Chunks<java.lang.String>


Nested Class Summary
 
Nested classes/interfaces inherited from class play.mvc.Results.Chunks
Results.Chunks.Out<A>
 
Constructor Summary
EventSource()
          Create a new EventSource socket
 
Method Summary
 void close()
          Close the channel
abstract  void onConnected()
          The socket is ready, you can start sending messages.
 void onDisconnected(F.Callback0 callback)
          Add a callback to be notified when the client has disconnected.
 void onReady(Results.Chunks.Out<java.lang.String> out)
          Called when the Chunked stream is ready.
 void sendData(java.lang.String data)
          Sending a generic event.
 void sendDataById(java.lang.String eventId, java.lang.String data)
          Setting an ID lets the browser keep track of the last event fired so that if, the connection to the server is dropped, a special HTTP header (Last-Event-ID) is set with the new request.
 void sendDataByName(java.lang.String eventName, java.lang.String data)
          A single event source can generate different types events by including an event name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EventSource

public EventSource()
Create a new EventSource socket

Method Detail

onReady

public void onReady(Results.Chunks.Out<java.lang.String> out)
Description copied from class: Results.Chunks
Called when the Chunked stream is ready.

Specified by:
onReady in class Results.Chunks<java.lang.String>
Parameters:
out - The out stream.

sendDataByName

public void sendDataByName(java.lang.String eventName,
                           java.lang.String data)
A single event source can generate different types events by including an event name. On the client, an event listener can be setup to listen to that particular event.

Parameters:
eventName - Unique name of the event.
data - data associated with event

sendDataById

public void sendDataById(java.lang.String eventId,
                         java.lang.String data)
Setting an ID lets the browser keep track of the last event fired so that if, the connection to the server is dropped, a special HTTP header (Last-Event-ID) is set with the new request. This lets the browser determine which event is appropriate to fire.

Parameters:
eventId - Unique event id.
data - data associated with event

sendData

public void sendData(java.lang.String data)
Sending a generic event. On the client, 'message' event listener can be setup to listen to this event.

Parameters:
data - data associated with event

onConnected

public abstract void onConnected()
The socket is ready, you can start sending messages.


onDisconnected

public void onDisconnected(F.Callback0 callback)
Add a callback to be notified when the client has disconnected.


close

public void close()
Close the channel