myxine-client-0.0.0.2: A Haskell client for the Myxine GUI server

Safe HaskellNone
LanguageHaskell2010

Myxine.Direct

Contents

Description

Usually, it makes the most sense to run a Myxine application using the Page abstraction in the main module. However, this reactive model-view-controller approach may not be appropriate for all needs. The functions below are a one-to-one mapping to the API of the Myxine server.

Like the Myxine server API itself, this interface has a small surface area. You can send a new page Update using sendUpdate, you can loop over all page events using withEvents, and you can evaluate raw JavaScript using evaluateJs.

Synopsis

Page locations on localhost

data PageLocation Source #

The options for connecting to the Myxine server. This is an opaque Monoid: set options by combining pagePort and/or pagePath using their Semigroup instance.

pagePort :: PagePort -> PageLocation Source #

Set the port to a non-default port. This is only necessary when Myxine is running on a non-default port also.

data PagePort Source #

A local port at which the server is expected to be running. Create one using an integer literal or fromInteger.

pagePath :: PagePath -> PageLocation Source #

Set the path to something other than the default of /.

data PagePath Source #

A path at "localhost/..." at which to perform some action. Create one using a string literal or fromString.

Instances
Eq PagePath Source # 
Instance details

Defined in Myxine.Direct

Ord PagePath Source # 
Instance details

Defined in Myxine.Direct

Show PagePath Source # 
Instance details

Defined in Myxine.Direct

IsString PagePath Source # 
Instance details

Defined in Myxine.Direct

Sending updates to pages

data Update Source #

A full page update as ready-to-send to the Myxine server.

Constructors

Dynamic

A dynamic page which can be updated live

Fields

Static

A static file which is hosted precisely as specified

Fields

Instances
Eq Update Source # 
Instance details

Defined in Myxine.Direct

Methods

(==) :: Update -> Update -> Bool #

(/=) :: Update -> Update -> Bool #

Ord Update Source # 
Instance details

Defined in Myxine.Direct

Show Update Source # 
Instance details

Defined in Myxine.Direct

data PageContent Source #

The view of a page, as rendered in the browser. Create page content with pageBody and pageTitle, and combine content using the Semigroup instance.

Note: The Semigroup instance for PageContent takes the last specified pageTitle (if any), and concatenates in order each specified pageBody.

pageBody :: Text -> PageContent Source #

Create a rendered PageContent with an empty title and the specified text as its body.

pageTitle :: Text -> PageContent Source #

Create a rendered PageContent with an empty body and the specified text as its title.

sendUpdate Source #

Arguments

:: PageLocation

The location of the page to update

-> Update

The new content of the page to display

-> IO () 

Send a full-page update to Myxine at a particular port and path. An Update is either a Dynamic page body with an optional title, or a Static file with a particular Content-Type.

Looping over typed events

withEvents Source #

Arguments

:: PageLocation

The location of the page to listen for events from

-> Maybe [Some EventType]

The list of events for which to listen

-> (forall d. EventType d -> d -> [Target] -> IO ())

The action to perform when each event happens

-> IO () 

Given a page location and list of events, make a request to Myxine for the event stream at that location and run the provided callback for each typed event in the stream. If no list of events is specified (Nothing), every event will be listened for. If the specific list of no events (Just []) is specified, this function will sleep forever.

This blocks until the stream is closed by the server, or an exception is encountered. This throws EventParseException if the server sends an unparseable event (this shouldn't happen in normal operation), and HttpException if the underlying connection has an issue.

Evaluating raw JavaScript in the context of a page

data JavaScript Source #

A piece of raw JavaScript to evaluate: either an expression or a block of statements. Expressions need not terminate with a return statement but cannot span multiple lines; block need to have an explicit return, but can contain multiple statements and lines.

Constructors

JsExpression Text

A JavaScript expression

JsBlock Text

A block of JavaScript statements

evaluateJs Source #

Arguments

:: FromJSON a 
=> PageLocation

The location of the page in which to evaluate the JavaScript

-> Maybe Int

An optional override for the default timeout of 1000 milliseconds

-> JavaScript

The JavaScript to evaluate: either a JsExpression or a JsBlock

-> IO (Either String a) 

Evaluate some raw JavaScript in the context of a given page

Returns either a deserialized Haskell type, or a human-readable string describing any error that occurred. Possible errors include:

  • Any exception in the given JavaScript
  • Absence of any browser window currently viewing the page (since there's no way to evaluate JavaScript without a JavaScript engine)
  • Evaluation timeout (default is 1000 milliseconds, but can be overridden in the timeout parameter to this function
  • Invalid JSON response for the result type inferred (use Value if you don't know what shape of data you're waiting to receive).

Further caveats:

  • JavaScript undefined is translated to null in the results
  • JsBlock inputs which don't explicitly return a value result in null
  • Return types are limited to those which can be serialized via @JSON.stringify@, which does not work for cyclic objects (like window, document, and all DOM nodes), and may fail to serialize some properties for other non-scalar values. If you want to return a non-scalar value like a list or dictionary, construct it explicitly yourself by copying from the fields of the object you're interested in.

Exceptions

data EventParseException Source #

If the response from the server fails to parse, this exception is thrown. This should never happen in ordinary circumstances; if it does, your version of the client library may mismatch the version of the Myxine server you are running, or there may be a bug in the Myxine server or this library.

If you encounter this exception in the wild, please file a bug report at https://github.com/GaloisInc/myxine/issues/new. Thanks!

Constructors

TargetParseException String

The target path failed to parse

UnknownEventTypeException ByteString

The event type failed to parse

EventDataParseException ByteString String ByteString

The properties associated with the event type failed to parse

The Some existential