packages feed

ghcjs-dom-javascript-0.10.0.0: src/GHCJS/DOM/JSFFI/Generated/WebSocket.hs

{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ForeignFunctionInterface, JavaScriptFFI #-}
{-# LANGUAGE ImplicitParams, ConstraintKinds, KindSignatures #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
-- | Generated by dom-gen from websockets (webref). Do not edit.
module GHCJS.DOM.JSFFI.Generated.WebSocket
       (js_newWebSocket, js_close, js_send, js_getUrl, js_getReadyState, js_getBufferedAmount, js_getExtensions, js_getProtocol, js_setBinaryType, js_getBinaryType, newWebSocket, close, send, getUrl, getReadyState, getBufferedAmount, getExtensions, getProtocol, setBinaryType, getBinaryType, pattern CONNECTING, pattern OPEN, pattern CLOSING, pattern CLOSED, open, error, closeEvent, message, WebSocket(..), gTypeWebSocket)
       where
import Prelude ((.), (==), (>>=), (<$>), (++), Bool(..), Maybe(..), IO, Int, Word, Double, Float)
import qualified Prelude as P
import Control.Monad (void)
import GHCJS.Types (JSVal, JSString)
import GHCJS.Foreign (jsUndefined, jsNull)
import GHCJS.DOM.Types
import qualified GHCJS.DOM.Types as Types
import GHCJS.DOM.EventTargetClosures (EventName, unsafeEventName, unsafeEventNameAsync)
import GHCJS.DOM.JSFFI.Generated.Enums

foreign import javascript safe "(($1, $2) => { return new globalThis[\"WebSocket\"]($1, $2); })"
        js_newWebSocket :: JSString -> JSVal -> IO WebSocket
-- | <https://developer.mozilla.org/docs/Web/API/WebSocket/WebSocket MDN WebSocket. documentation>
newWebSocket :: (MonadDOM m, ToJSString url, IsStringOrSequenceString protocols) => url -> Maybe protocols -> m WebSocket
newWebSocket url protocols = liftDOM (((P.maybe (P.return jsUndefined) toJSVal protocols) >>= \a2' -> js_newWebSocket (toJSString url) a2'))

foreign import javascript safe "(($1, $2, $3) => { return $1[\"close\"]($2, $3); })"
        js_close :: WebSocket -> JSVal -> (Optional JSString) -> IO ()
-- | <https://developer.mozilla.org/docs/Web/API/WebSocket/close MDN WebSocket.close documentation>
close :: (MonadDOM m, ToJSString reason) => WebSocket -> Maybe Word -> Maybe reason -> m ()
close self code reason = liftDOM (void (((P.maybe (P.return jsUndefined) toJSVal code) >>= \a2' -> js_close (self) a2' (toOptionalJSString reason))))

foreign import javascript safe "(($1, $2) => { return $1[\"send\"]($2); })"
        js_send :: WebSocket -> BlobPart -> IO ()
-- | <https://developer.mozilla.org/docs/Web/API/WebSocket/send MDN WebSocket.send documentation>
send :: (MonadDOM m, IsBlobPart data') => WebSocket -> data' -> m ()
send self data' = liftDOM (void ((js_send (self) (Types.toBlobPart data'))))

foreign import javascript unsafe "(($1) => { return $1[\"url\"]; })"
        js_getUrl :: WebSocket -> IO JSString
-- | <https://developer.mozilla.org/docs/Web/API/WebSocket/url MDN WebSocket.url documentation>
getUrl :: (MonadDOM m, FromJSString result) => WebSocket -> m result
getUrl self = liftDOM ((fromJSString <$> (js_getUrl (self))))

foreign import javascript unsafe "(($1) => { return $1[\"readyState\"]; })"
        js_getReadyState :: WebSocket -> IO Word
-- | <https://developer.mozilla.org/docs/Web/API/WebSocket/readyState MDN WebSocket.readyState documentation>
getReadyState :: (MonadDOM m) => WebSocket -> m Word
getReadyState self = liftDOM ((js_getReadyState (self)))

foreign import javascript unsafe "(($1) => { return $1[\"bufferedAmount\"]; })"
        js_getBufferedAmount :: WebSocket -> IO JSVal
-- | <https://developer.mozilla.org/docs/Web/API/WebSocket/bufferedAmount MDN WebSocket.bufferedAmount documentation>
getBufferedAmount :: (MonadDOM m) => WebSocket -> m Word53
getBufferedAmount self = liftDOM (((js_getBufferedAmount (self)) >>= fromJSValUnchecked))

foreign import javascript unsafe "(($1) => { return $1[\"extensions\"]; })"
        js_getExtensions :: WebSocket -> IO JSString
-- | <https://developer.mozilla.org/docs/Web/API/WebSocket/extensions MDN WebSocket.extensions documentation>
getExtensions :: (MonadDOM m, FromJSString result) => WebSocket -> m result
getExtensions self = liftDOM ((fromJSString <$> (js_getExtensions (self))))

foreign import javascript unsafe "(($1) => { return $1[\"protocol\"]; })"
        js_getProtocol :: WebSocket -> IO JSString
-- | <https://developer.mozilla.org/docs/Web/API/WebSocket/protocol MDN WebSocket.protocol documentation>
getProtocol :: (MonadDOM m, FromJSString result) => WebSocket -> m result
getProtocol self = liftDOM ((fromJSString <$> (js_getProtocol (self))))

foreign import javascript safe "(($1, $2) => { $1[\"binaryType\"] = $2; })"
        js_setBinaryType :: WebSocket -> JSVal -> IO ()
-- | <https://developer.mozilla.org/docs/Web/API/WebSocket/binaryType MDN WebSocket.binaryType documentation>
setBinaryType :: (MonadDOM m) => WebSocket -> BinaryType -> m ()
setBinaryType self val = liftDOM (void (((toJSVal val) >>= \a2' -> js_setBinaryType (self) a2')))

foreign import javascript unsafe "(($1) => { return $1[\"binaryType\"]; })"
        js_getBinaryType :: WebSocket -> IO JSVal
-- | <https://developer.mozilla.org/docs/Web/API/WebSocket/binaryType MDN WebSocket.binaryType documentation>
getBinaryType :: (MonadDOM m) => WebSocket -> m BinaryType
getBinaryType self = liftDOM (((js_getBinaryType (self)) >>= fromJSValUnchecked))

pattern CONNECTING = 0

pattern OPEN = 1

pattern CLOSING = 2

pattern CLOSED = 3

-- | <https://websockets.spec.whatwg.org/#dom-websocket-onopen open event>
open :: EventName WebSocket Event
open = unsafeEventNameAsync (toJSString "open")

-- | <https://websockets.spec.whatwg.org/#dom-websocket-onerror error event>
error :: EventName WebSocket Event
error = unsafeEventNameAsync (toJSString "error")

-- | <https://websockets.spec.whatwg.org/#dom-websocket-onclose close event>
closeEvent :: EventName WebSocket CloseEvent
closeEvent = unsafeEventNameAsync (toJSString "close")

-- | <https://websockets.spec.whatwg.org/#dom-websocket-onmessage message event>
message :: EventName WebSocket MessageEvent
message = unsafeEventNameAsync (toJSString "message")