Package play.libs
Class Comet
- Object
-
- play.libs.Comet
-
public abstract class Comet extends Object
Provides an easy way to use a Comet formatted output with Akka Streams.There are two methods that can be used to convert strings and JSON,
Comet.string
andComet.json
. These methods build on top of the base method,Comet.flow
, which takes a Flow ofakka.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 Constructor Description Comet()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Flow<ByteString,ByteString,NotUsed>
flow(String callbackName)
Produces a flow of ByteString with a prepended block and a script wrapper.static Flow<ByteString,ByteString,NotUsed>
flow(String callbackName, String nonce)
Produces a flow of ByteString with a prepended block and a script wrapper.static Flow<com.fasterxml.jackson.databind.JsonNode,ByteString,NotUsed>
json(String callbackName)
Produces a flow of ByteString using `Json.stringify` from a Flow of JsonNode.static Flow<com.fasterxml.jackson.databind.JsonNode,ByteString,NotUsed>
json(String callbackName, String nonce)
Produces a flow of ByteString using `Json.stringify` from a Flow of JsonNode.static Flow<String,ByteString,NotUsed>
string(String callbackName)
Produces a Flow of escaped ByteString from a series of String elements.static Flow<String,ByteString,NotUsed>
string(String callbackName, String nonce)
Produces a Flow of escaped ByteString from a series of String elements.
-
-
-
Method Detail
-
string
public static Flow<String,ByteString,NotUsed> string(String callbackName)
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
public static Flow<String,ByteString,NotUsed> string(String callbackName, String nonce)
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. Ifnull
no nonce will be sent.- Returns:
- a flow of ByteString elements.
-
json
public static Flow<com.fasterxml.jackson.databind.JsonNode,ByteString,NotUsed> json(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,NotUsed> json(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. Ifnull
no nonce will be sent.- Returns:
- a flow of ByteString elements.
-
flow
public static Flow<ByteString,ByteString,NotUsed> flow(String callbackName)
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
public static Flow<ByteString,ByteString,NotUsed> flow(String callbackName, String nonce)
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. Ifnull
no nonce will be sent.- Returns:
- a flow of ByteString elements.
-
-