ghcjs-dom-javascript-0.10.0.0: src/GHCJS/DOM/JSFFI/Generated/EventSource.hs
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ForeignFunctionInterface, JavaScriptFFI #-}
{-# LANGUAGE ImplicitParams, ConstraintKinds, KindSignatures #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
-- | Generated by dom-gen from html (webref). Do not edit.
module GHCJS.DOM.JSFFI.Generated.EventSource
(js_newEventSource, js_close, js_getUrl, js_getWithCredentials, js_getReadyState, newEventSource, close, getUrl, getWithCredentials, getReadyState, pattern CONNECTING, pattern OPEN, pattern CLOSED, open, message, error, EventSource(..), gTypeEventSource)
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[\"EventSource\"]($1, $2); })"
js_newEventSource :: JSString -> JSVal -> IO EventSource
-- | <https://developer.mozilla.org/docs/Web/API/EventSource/EventSource MDN EventSource. documentation>
newEventSource :: (MonadDOM m, ToJSString url) => url -> Maybe EventSourceInit -> m EventSource
newEventSource url eventSourceInitDict = liftDOM (((P.maybe (P.return jsUndefined) toJSVal eventSourceInitDict) >>= \a2' -> js_newEventSource (toJSString url) a2'))
foreign import javascript safe "(($1) => { return $1[\"close\"](); })"
js_close :: EventSource -> IO ()
-- | <https://developer.mozilla.org/docs/Web/API/EventSource/close MDN EventSource.close documentation>
close :: (MonadDOM m) => EventSource -> m ()
close self = liftDOM (void ((js_close (self))))
foreign import javascript unsafe "(($1) => { return $1[\"url\"]; })"
js_getUrl :: EventSource -> IO JSString
-- | <https://developer.mozilla.org/docs/Web/API/EventSource/url MDN EventSource.url documentation>
getUrl :: (MonadDOM m, FromJSString result) => EventSource -> m result
getUrl self = liftDOM ((fromJSString <$> (js_getUrl (self))))
foreign import javascript unsafe "(($1) => { return $1[\"withCredentials\"]; })"
js_getWithCredentials :: EventSource -> IO Bool
-- | <https://developer.mozilla.org/docs/Web/API/EventSource/withCredentials MDN EventSource.withCredentials documentation>
getWithCredentials :: (MonadDOM m) => EventSource -> m Bool
getWithCredentials self = liftDOM ((js_getWithCredentials (self)))
foreign import javascript unsafe "(($1) => { return $1[\"readyState\"]; })"
js_getReadyState :: EventSource -> IO Word
-- | <https://developer.mozilla.org/docs/Web/API/EventSource/readyState MDN EventSource.readyState documentation>
getReadyState :: (MonadDOM m) => EventSource -> m Word
getReadyState self = liftDOM ((js_getReadyState (self)))
pattern CONNECTING = 0
pattern OPEN = 1
pattern CLOSED = 2
-- | <https://html.spec.whatwg.org/multipage/server-sent-events.html#handler-eventsource-onopen open event>
open :: EventName EventSource Event
open = unsafeEventNameAsync (toJSString "open")
-- | <https://html.spec.whatwg.org/multipage/server-sent-events.html#handler-eventsource-onmessage message event>
message :: EventName EventSource MessageEvent
message = unsafeEventNameAsync (toJSString "message")
-- | <https://html.spec.whatwg.org/multipage/server-sent-events.html#handler-eventsource-onerror error event>
error :: EventName EventSource Event
error = unsafeEventNameAsync (toJSString "error")