Package play.libs
Class Comet
java.lang.Object
play.libs.Comet
Provides an easy way to use a Comet formatted output with Pekko Streams.
There are two methods that can be used to convert strings and JSON, Comet.string and
Comet.json. These methods build on top of the base method, Comet.flow, which
takes a Flow of org.apache.pekko.util.ByteString and organizes it into Comet format.
public Result liveClock() {
final DateTimeFormatter df = DateTimeFormatter.ofPattern("HH mm ss");
final Source tickSource = Source.tick(Duration.Zero(), Duration.create(100, MILLISECONDS), "TICK");
final Source eventSource = tickSource.map((tick) -> df.format(ZonedDateTime.now()));
final Source<ByteString, NotUsed> flow = eventSource.via(Comet.string("parent.clockChanged"));
return ok().chunked(flow).as(Http.MimeTypes.HTML);
}
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Flow<ByteString,ByteString, NotUsed> Produces a flow of ByteString with a prepended block and a script wrapper.static Flow<ByteString,ByteString, NotUsed> Produces a flow of ByteString with a prepended block and a script wrapper.static Flow<com.fasterxml.jackson.databind.JsonNode,ByteString, NotUsed> Produces a flow of ByteString using `Json.stringify` from a Flow of JsonNode.static Flow<com.fasterxml.jackson.databind.JsonNode,ByteString, NotUsed> Produces a flow of ByteString using `Json.stringify` from a Flow of JsonNode.static Flow<String,ByteString, NotUsed> Produces a Flow of escaped ByteString from a series of String elements.static Flow<String,ByteString, NotUsed> Produces a Flow of escaped ByteString from a series of String elements.
-
Constructor Details
-
Comet
public Comet()
-
-
Method Details
-
string
Produces a Flow of escaped ByteString from a series of String elements. Calls out to Comet.flow internally.- Parameters:
callbackName- the javascript callback method.- Returns:
- a flow of ByteString elements.
-
string
Produces a Flow of escaped ByteString from a series of String elements. Calls out to Comet.flow internally.- Parameters:
callbackName- the javascript callback method.nonce- The CSP nonce to use for the script tag. Ifnullno nonce will be sent.- Returns:
- a flow of ByteString elements.
-
json
public static Flow<com.fasterxml.jackson.databind.JsonNode,ByteString, jsonNotUsed> (String callbackName) Produces a flow of ByteString using `Json.stringify` from a Flow of JsonNode. Calls out to Comet.flow internally.- Parameters:
callbackName- the javascript callback method.- Returns:
- a flow of ByteString elements.
-
json
public static Flow<com.fasterxml.jackson.databind.JsonNode,ByteString, jsonNotUsed> (String callbackName, String nonce) Produces a flow of ByteString using `Json.stringify` from a Flow of JsonNode. Calls out to Comet.flow internally.- Parameters:
callbackName- the javascript callback method.nonce- The CSP nonce to use for the script tag. Ifnullno nonce will be sent.- Returns:
- a flow of ByteString elements.
-
flow
Produces a flow of ByteString with a prepended block and a script wrapper.- Parameters:
callbackName- the javascript callback method.- Returns:
- a flow of ByteString elements.
-
flow
Produces a flow of ByteString with a prepended block and a script wrapper.- Parameters:
callbackName- the javascript callback method.nonce- The CSP nonce to use for the script tag. Ifnullno nonce will be sent.- Returns:
- a flow of ByteString elements.
-