Package

purescript-websockets-rpc

Repository
athanclark/purescript-websockets-rpc
License
BSD-3-Clause
Uploaded by
athanclark

for use with a websockets-rpc-compliant websocket server, the purescript-websocket-simple client library, and purescript-argonaut json serialization system.

Example

import WebSocket.RPC

data MySubDSL = Foo
  deriving (EncodeJson, DecodeJson) -- you should figure this out

data MySupDSL = Bar
  deriving (EncodeJson, DecodeJson)

data MyRepDSL = Baz
  deriving (EncodeJson, DecodeJson)

data MyComDSL = Qux
  deriving (EncodeJson, DecodeJson)





myClient :: forall eff. ClientAppT (WebSocketClientRPCT MyRepDSL MyComDSL (Eff (AllEffs eff))) Unit
myClient = rpcClient $ \dispatch -> do
  -- could dispatch more than one subscription here
  dispatch myClient'
  where
    myClient' :: RPCClient MySubDSL MySupDSL MyRepDSL MyComDSL (Eff (AllEffs eff))
    myClient' =
      { subscription: Foo
      , onReply: \{supply,cancel} Baz -> do
          x <- randomInt 1 10
          if x == 10 then cancel else supply Bar
      , onComplete: \Qux ->
          log "ayooo"
      }
      
      
main :: Eff _ Unit
main = do
  conn <- newWebSocket (URL "localhost") []
  execWebSocketClientRPCT (myClient conn)