Safe Haskell | None |
---|
The Sunroof server module provides infrastructure to use Sunroof together with kansas-comet.
It supports setting up a simple server with sunroofServer
and provides basic functions for serverside communication
with the connected website (syncJS
, asyncJS
and rsyncJS
).
This module also provides the abstractions for Downlink
and Uplink
. They represent directed channels for sending data
from the server to the website and the other way aroun.
The sent data is queued and operations block properly if there
is no data available.
- syncJS :: forall a t. SunroofResult a => SunroofEngine -> JS t a -> IO (ResultOf a)
- asyncJS :: SunroofEngine -> JS t () -> IO ()
- rsyncJS :: forall a t. Sunroof a => SunroofEngine -> JS t a -> IO a
- class Sunroof a => SunroofResult a where
- type ResultOf a
- jsonToValue :: Proxy a -> Value -> ResultOf a
- data SunroofEngine = SunroofEngine {
- cometDocument :: Document
- uVar :: TVar Uniq
- engineVerbose :: Int
- compilerOpts :: CompilerOpts
- timings :: Maybe (TVar (Timings NominalDiffTime))
- jsonToJS :: Value -> Expr
- sunroofServer :: SunroofServerOptions -> SunroofApp -> IO ()
- data SunroofServerOptions = SunroofServerOptions {}
- type SunroofApp = SunroofEngine -> IO ()
- debugSunroofEngine :: IO SunroofEngine
- data Downlink a
- newDownlink :: forall a. (Sunroof a, SunroofArgument a) => SunroofEngine -> IO (Downlink a)
- getDownlink :: (Sunroof a, SunroofArgument a) => Downlink a -> JSB a
- putDownlink :: (Sunroof a, SunroofArgument a) => Downlink a -> JSA a -> IO ()
- data Uplink a
- newUplink :: SunroofEngine -> IO (Uplink a)
- getUplink :: forall a. SunroofResult a => Uplink a -> IO (ResultOf a)
- putUplink :: Sunroof a => a -> Uplink a -> JS t ()
- data Timings a = Timings {
- compileTime :: !a
- sendTime :: !a
- waitTime :: !a
- newTimings :: SunroofEngine -> IO SunroofEngine
- resetTimings :: SunroofEngine -> IO ()
- getTimings :: SunroofEngine -> IO (Timings NominalDiffTime)
Basic Comet Server
syncJS :: forall a t. SunroofResult a => SunroofEngine -> JS t a -> IO (ResultOf a)Source
Executes the Javascript in the browser and waits for the result value.
The result value is given the corresponding Haskell type,
if possible (see SunroofResult
).
asyncJS :: SunroofEngine -> JS t () -> IO ()Source
Executes the Javascript in the browser without waiting for a result.
rsyncJS :: forall a t. Sunroof a => SunroofEngine -> JS t a -> IO aSource
Executes the Javascript in the browser and waits for the result. The returned value is just a reference to the computed value. This allows to precompile values like function in the browser.
class Sunroof a => SunroofResult a whereSource
Provides correspondant Haskell types for certain Sunroof types.
jsonToValue :: Proxy a -> Value -> ResultOf aSource
Converts the given JSON value to the corresponding Haskell value. A error is thrown if the JSON value can not be converted.
SunroofResult () |
|
SunroofResult JSString | |
SunroofResult JSNumber | |
SunroofResult JSBool | |
SunroofResult a => SunroofResult (JSArray a) |
|
data SunroofEngine Source
The SunroofEngine
provides the verbosity level and
kansas comet document to the SunroofApp
.
SunroofEngine | |
|
sunroofServer :: SunroofServerOptions -> SunroofApp -> IO ()Source
Sets up a comet server ready to use with sunroof.
sunroofServer opts app
:
The opts
give various configuration for the comet server.
See SunroofServerOptions
for further information on this.
The application to run is given by app
. It takes the current
engine/document as parameter. The document is needed for calls to syncJS
,
asyncJS
and rsyncJS
.
The server provides the kansas comet Javascript on the path
js/kansas-comet.js
.
Since kansas-comet.js
is a JQuery plugin you have to also
load a decent version of jquery.js
(or jquery.min.js
)
and also jquery-json.js
. They are available at:
For the index file to setup the communication correctly with the comet
server it has to load the kansas-comet.js
after the JQuery code
inside the head
(assuming you placed the JQuery code under js/
):
<script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript" src="js/jquery-json.js"></script> <script type="text/javascript" src="js/kansas-comet.js"></script>
It also has to execute the following Javascript at the end of the index file to initialize the communication:
<script type="text/javascript"> $(document).ready(function() { $.kc.connect("/ajax"); }); </script>
The string /ajax
has to be set to whatever the comet prefix
in the Options
provided by the SunroofServerOptions
is.
These snippits will work for the def
instance.
Additional debug information can be displayed in the browser when adding the following element to the index file:
<div id="debug-log"></div>
Look into the example folder to see all of this in action.
data SunroofServerOptions Source
The SunroofServerOptions
specify the configuration of the
sunroof comet server infrastructure.
See sunroofServer
and SunroofServerOptions
for further information.
SunroofServerOptions | |
|
Default SunroofServerOptions | The |
type SunroofApp = SunroofEngine -> IO ()Source
A comet application takes the engine/document we are currently communicating with and delivers the IO action to be executed as server application.
debugSunroofEngine :: IO SunroofEngineSource
Setup a SunroofEngine
for debugging.
Downlink
Downlink
s are an abstraction provided for sending
Javascript data from the server to the website.
The type parameter describes the elements
that are transmited through the downlink.
newDownlink :: forall a. (Sunroof a, SunroofArgument a) => SunroofEngine -> IO (Downlink a)Source
Create a new downlink.
getDownlink :: (Sunroof a, SunroofArgument a) => Downlink a -> JSB aSource
Request data in the downlink. This may block until data is available.
putDownlink :: (Sunroof a, SunroofArgument a) => Downlink a -> JSA a -> IO ()Source
Send data to the website.
Uplink
Uplink
s are an abstraction provided for sending
Javascript data from the website back to the server.
Only data that can be translated back to a Haskell
value can be sent back.
The type parameter describes the elements
that are transmited through the uplink.
newUplink :: SunroofEngine -> IO (Uplink a)Source
Create a new uplink.
getUplink :: forall a. SunroofResult a => Uplink a -> IO (ResultOf a)Source
Request data in the uplink. This may block until data is available.
Timing
Timings for communication and compilation.
Timings | |
|
newTimings :: SunroofEngine -> IO SunroofEngineSource
Create timings in the SunroofEngine
.
resetTimings :: SunroofEngine -> IO ()Source
Reset all timings.
getTimings :: SunroofEngine -> IO (Timings NominalDiffTime)Source
Get timings from the SunroofEngine
.