Skip to content

A simple subscription-esque RPC mechanism using WebSockets, ala the haskell websockets-rpc library (client only)

License

Notifications You must be signed in to change notification settings

athanclark/purescript-websockets-rpc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

purescript-websockets-rpc

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

Example

import WebSocket.RPC
import WebSocket (WEBSOCKET)

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
          . {url :: String, protocols :: Array String}
         -> (WebSocketClientRPCT MyRepDSL MyComDSL (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 =
  execWebSocketClientRPCT $ myClient {url: "ws://localhost", protocols: []}

see the example/ folder for a working one

About

A simple subscription-esque RPC mechanism using WebSockets, ala the haskell websockets-rpc library (client only)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages