{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ImplicitParams, ConstraintKinds, KindSignatures #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
module JSDOM.Generated.WebSocket
(newWebSocket, newWebSocket', send, sendView, sendBlob, sendString,
close, pattern CONNECTING, pattern OPEN, pattern CLOSING,
pattern CLOSED, getUrl, getReadyState, getBufferedAmount, open,
message, error, closeEvent, getProtocol, getProtocolUnsafe,
getProtocolUnchecked, getExtensions, getExtensionsUnsafe,
getExtensionsUnchecked, setBinaryType, getBinaryType,
WebSocket(..), gTypeWebSocket)
where
import Prelude ((.), (==), (>>=), return, IO, Int, Float, Double, Bool(..), Maybe, maybe, fromIntegral, round, realToFrac, fmap, Show, Read, Eq, Ord, Maybe(..))
import qualified Prelude (error)
import Data.Typeable (Typeable)
import Data.Traversable (mapM)
import Language.Javascript.JSaddle (JSM(..), JSVal(..), JSString, strictEqual, toJSVal, valToStr, valToNumber, valToBool, js, jss, jsf, jsg, function, asyncFunction, new, array, jsUndefined, (!), (!!))
import Data.Int (Int64)
import Data.Word (Word, Word64)
import JSDOM.Types
import Control.Applicative ((<$>))
import Control.Monad (void)
import Control.Lens.Operators ((^.))
import JSDOM.EventTargetClosures (EventName, unsafeEventName, unsafeEventNameAsync)
import JSDOM.Enums
newWebSocket ::
(MonadDOM m, ToJSString url, ToJSString protocols) =>
url -> [protocols] -> m WebSocket
newWebSocket url protocols
= liftDOM
(WebSocket <$>
new (jsg "WebSocket") [toJSVal url, toJSVal (array protocols)])
newWebSocket' ::
(MonadDOM m, ToJSString url, ToJSString protocol) =>
url -> protocol -> m WebSocket
newWebSocket' url protocol
= liftDOM
(WebSocket <$>
new (jsg "WebSocket") [toJSVal url, toJSVal protocol])
send ::
(MonadDOM m, IsArrayBuffer data') => WebSocket -> data' -> m ()
send self data'
= liftDOM (void (self ^. jsf "send" [toJSVal data']))
sendView ::
(MonadDOM m, IsArrayBufferView data') => WebSocket -> data' -> m ()
sendView self data'
= liftDOM (void (self ^. jsf "send" [toJSVal data']))
sendBlob ::
(MonadDOM m, IsBlob data') => WebSocket -> data' -> m ()
sendBlob self data'
= liftDOM (void (self ^. jsf "send" [toJSVal data']))
sendString ::
(MonadDOM m, ToJSString data') => WebSocket -> data' -> m ()
sendString self data'
= liftDOM (void (self ^. jsf "send" [toJSVal data']))
close ::
(MonadDOM m, ToJSString reason) =>
WebSocket -> Maybe Word -> Maybe reason -> m ()
close self code reason
= liftDOM
(void (self ^. jsf "close" [toJSVal code, toJSVal reason]))
pattern CONNECTING = 0
pattern OPEN = 1
pattern CLOSING = 2
pattern CLOSED = 3
getUrl ::
(MonadDOM m, FromJSString result) => WebSocket -> m result
getUrl self = liftDOM ((self ^. js "url") >>= fromJSValUnchecked)
getReadyState :: (MonadDOM m) => WebSocket -> m Word
getReadyState self
= liftDOM (round <$> ((self ^. js "readyState") >>= valToNumber))
getBufferedAmount :: (MonadDOM m) => WebSocket -> m Word
getBufferedAmount self
= liftDOM
(round <$> ((self ^. js "bufferedAmount") >>= valToNumber))
open :: EventName WebSocket Event
open = unsafeEventNameAsync (toJSString "open")
message :: EventName WebSocket MessageEvent
message = unsafeEventNameAsync (toJSString "message")
error :: EventName WebSocket UIEvent
error = unsafeEventNameAsync (toJSString "error")
closeEvent :: EventName WebSocket CloseEvent
closeEvent = unsafeEventNameAsync (toJSString "close")
getProtocol ::
(MonadDOM m, FromJSString result) => WebSocket -> m (Maybe result)
getProtocol self
= liftDOM ((self ^. js "protocol") >>= fromMaybeJSString)
getProtocolUnsafe ::
(MonadDOM m, HasCallStack, FromJSString result) =>
WebSocket -> m result
getProtocolUnsafe self
= liftDOM
(((self ^. js "protocol") >>= fromMaybeJSString) >>=
maybe (Prelude.error "Nothing to return") return)
getProtocolUnchecked ::
(MonadDOM m, FromJSString result) => WebSocket -> m result
getProtocolUnchecked self
= liftDOM ((self ^. js "protocol") >>= fromJSValUnchecked)
getExtensions ::
(MonadDOM m, FromJSString result) => WebSocket -> m (Maybe result)
getExtensions self
= liftDOM ((self ^. js "extensions") >>= fromMaybeJSString)
getExtensionsUnsafe ::
(MonadDOM m, HasCallStack, FromJSString result) =>
WebSocket -> m result
getExtensionsUnsafe self
= liftDOM
(((self ^. js "extensions") >>= fromMaybeJSString) >>=
maybe (Prelude.error "Nothing to return") return)
getExtensionsUnchecked ::
(MonadDOM m, FromJSString result) => WebSocket -> m result
getExtensionsUnchecked self
= liftDOM ((self ^. js "extensions") >>= fromJSValUnchecked)
setBinaryType ::
(MonadDOM m, ToJSString val) => WebSocket -> val -> m ()
setBinaryType self val
= liftDOM (self ^. jss "binaryType" (toJSVal val))
getBinaryType ::
(MonadDOM m, FromJSString result) => WebSocket -> m result
getBinaryType self
= liftDOM ((self ^. js "binaryType") >>= fromJSValUnchecked)