Last active
November 6, 2015 14:06
-
-
Save agocorona/c1765b72ec915a53489f to your computer and use it in GitHub Desktop.
A websockets program for ghcjs that fails with ghcjs 0.2.0 and ghcjs-base commit 23b1311
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
in chrome console: | |
JavaScript exception: ReferenceError: h$closeWebSocket is not defined | |
rts.js:9543 user error (If you can read this, shutdownHaskellAndExit did not exit.) | |
rts.js:9543 user error (If you can read this, shutdownHaskellAndExit did not exit.) | |
rts.js:9543 user error (If you can read this, shutdownHaskellAndExit did no | |
.... | |
.... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE ForeignFunctionInterface, JavaScriptFFI, DeriveDataTypeable, | |
UnboxedTuples, GHCForeignImportPrim, UnliftedFFITypes, | |
MagicHash, OverloadedStrings | |
#-} | |
import JavaScript.Web.WebSocket | |
import JavaScript.Web.MessageEvent | |
--import JavaScript.Web.Blob.Internal (Blob, SomeBlob(..)) | |
--import JavaScript.TypedArray.ArrayBuffer.Internal (ArrayBuffer, SomeArrayBuffer(..)) | |
--import Data.JSString.Internal.Type (JSString(..)) | |
--import qualified Data.ByteString.Base64.Lazy as B64 | |
main :: IO () | |
main = do | |
ws <- connect WebSocketRequest | |
{ url = "ws://localhost:2000" | |
, protocols = ["chat"] | |
, onClose = Just $ const $ return() -- Maybe (CloseEvent -> IO ()) -- ^ called when the connection closes (at most once) | |
, onMessage = Just recMessage -- Maybe (MessageEvent -> IO ()) -- ^ called for each message | |
} | |
send "HELLO" ws | |
recMessage e= -- print "SOMething HAS BEEN RECEIVED" | |
do | |
let d = getData e | |
case d of | |
StringData str -> putStrLn "RECEIVED " >> print str | |
BlobData blob -> error " blob" | |
ArrayBufferData arrBuffer -> error "arrBuffer" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment