11# javascript-bridge [ ![ Build Status] ( https://img.shields.io/travis/ku-fpg/javascript-bridge.svg?style=flat )] ( https://travis-ci.org/ku-fpg/javascript-bridge )
22
3- ** javascript-bridge** is an easy way of calling JavaScript from
4- Haskell, using web-sockets as the underlying transport
3+ ** javascript-bridge** is a straightforward way of calling JavaScript
4+ from Haskell, using web-sockets as the underlying transport
55mechanism. Conceptually, javascript-bridge gives Haskell acccess to
6- the JavaScript ` eval ` function. However, using a remote monad, as
7- well as supporting evaluation of JavaScript fragments, we also support
8- calling and returning values from JavaScript functions, constructing
9- and using remote objects, and sending events from JavaScript to
10- Haskell.
6+ the JavaScript ` eval ` function. However, we also support calling and
7+ returning values from JavaScript functions, constructing and using
8+ remote objects, and sending events from JavaScript to Haskell, all
9+ using a remote monad.
1110
12- # High-level overview of API
11+ # Overview of API
1312
1413** javascript-bridge** remotely executes JavaScript * fragments* .
1514The basic Haskell idiom is.
@@ -45,8 +44,8 @@ then listening for the event in Haskell.
4544```Haskell
4645 do -- Have JavaScript send an event to Haskell
4746 send eng $ command $ " event('Hello!')"
48- -- Have Haskell wait for the event
49- e :: String <- listen eng
47+ -- Have Haskell wait for the event, which is an Aeson 'Value'.
48+ e :: Value <- listen eng
5049 print e
5150```
5251
@@ -67,13 +66,12 @@ app :: Engine -> IO ()
6766app = send eng $ command " console.log('Hello!')"
6867```
6968
70- Next, include the following fragment in your HTML code,
71- replacing * localhost* with your web address.
69+ Next, include the following fragment in your HTML code.
7270
7371``` HTML
7472 <script >
75- jsb = new WebSocket (' ws://localhost:3000/ ' ) ;
76- jsb .onmessage = function (evt ){ eval (evt .data );} ;
73+ window . jsb = {ws : new WebSocket (' ws://' + location . host )} ;
74+ jsb .ws . onmessage = (evt ) => eval (evt .data );
7775 </script >
7876```
7977
0 commit comments