ws-typed.rkt 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #lang typed/racket
  2. ;; Typed interface to WebSockets
  3. (require typed/web-server/http
  4. typed/net/url)
  5. (require/typed/provide
  6. net/rfc6455
  7. ;; TODO: differentiate between open and closed sockets?
  8. ;; opaque types ~~ abstract types w/ contracts
  9. [#:opaque WS ws-conn?]
  10. [ws-idle-timeout (Parameterof Number)]
  11. [ws-connect (->* (url) ;;; ws-url or wss-url
  12. (#:headers header
  13. #:protocol (U 'rfc6455 'hybi00))
  14. WS)]
  15. [ws-recv-evt (->* (WS)
  16. (#:payload-type (U 'auto 'text 'binary))
  17. (Evtof (U String Bytes EOF)))]
  18. [ws-send! (->* (WS
  19. (U String Bytes))
  20. (#:final-fragment? Boolean
  21. #:payload-type (U 'continuation 'text 'binary)
  22. #:flush? Boolean)
  23. Void)]
  24. [ws-close! (->* (WS)
  25. (#:status Integer
  26. #:reason String)
  27. Void)]
  28. [ws-conn-closed? (-> WS Boolean)]
  29. [ws-conn-close-status (-> WS (U Number False))]
  30. [ws-conn-close-reason (-> WS (U String False))]
  31. )