| Copyright | (C) 2016-2026 David M. Johnson |
|---|---|
| License | BSD3-style (see the file LICENSE) |
| Maintainer | David M. Johnson <code@dmj.io> |
| Stability | experimental |
| Portability | non-portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Miso.Navigator
Description
Overview
Miso.Navigator wraps the browser's
Navigator
API as Effect combinators that integrate directly into the
Model-View-Update loop. Each function returns an Effect and
feeds its result back as an action via withSink or
io.
Quick start
import Miso import Miso.Navigator data Action = RequestLocation | GotLocationGeolocation| LocationErrorGeolocationError| RequestCamera | GotStreamStream| MediaErrorJSValupdate :: Action ->Effectp props Model Action update RequestLocation =geolocationGotLocation LocationError update RequestCamera =getUserMedia(userMedia{ audio = False }) GotStream MediaError update _ = pure ()
API groups
- Camera / microphone ('Navigator.mediaDevices.getUserMedia'):
getUserMedia,userMedia,UserMedia,Stream - Clipboard ('Navigator.clipboard.writeText'):
copyClipboard - Online status (
onLine):isOnLine - Geolocation ('Navigator.geolocation.getCurrentPosition'):
geolocation,Geolocation,GeolocationError,GeolocationErrorCode
Error handling
Geolocation errors are decoded from the browser's
GeolocationPositionError
object into GeolocationError, which carries a GeolocationErrorCode
(, PERMISSION_DENIED, POSITION_UNAVAILABLE) and a
human-readable message string.TIMEOUT
See also
- Miso.FFI.Internal —
getUserMedia,copyClipboard,geolocation,isOnLine— the raw IO primitives - Miso.Subscription.OnLine — subscription-based online/offline monitoring
- Miso.Effect —
withSink,io
Synopsis
- getUserMedia :: UserMedia -> (Stream -> action) -> (JSVal -> action) -> Effect parent props model action
- userMedia :: UserMedia
- data UserMedia = UserMedia {}
- type Stream = JSVal
- copyClipboard :: MisoString -> action -> (JSVal -> action) -> Effect parent props model action
- isOnLine :: (Bool -> action) -> Effect parent props model action
- geolocation :: (Geolocation -> action) -> (GeolocationError -> action) -> Effect parent props model action
- data Geolocation = Geolocation {}
- data GeolocationError = GeolocationError GeolocationErrorCode MisoString
- data GeolocationErrorCode
User media
Arguments
| :: UserMedia | Options |
| -> (Stream -> action) | Successful callback |
| -> (JSVal -> action) | Errorful callback |
| -> Effect parent props model action |
Get access to user's media devices.
https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia
Type for dealing with 'navigator.mediaDevices.getUserMedia'
https://developer.mozilla.org/en-US/docs/Web/API/Navigator/mediaDevices
Constructors
| UserMedia | |
Instances
Clipboard
Arguments
| :: MisoString | Options |
| -> action | Successful callback |
| -> (JSVal -> action) | Errorful callback |
| -> Effect parent props model action |
Get access to the user's clipboard.
https://developer.mozilla.org/en-US/docs/Web/API/Navigator/clipboard
OnLine
Get user's online status
https://developer.mozilla.org/en-US/docs/Web/API/Navigator/onLine
Geolocation
Arguments
| :: (Geolocation -> action) | Success callback; receives the device's current position |
| -> (GeolocationError -> action) | Error callback; receives a |
| -> Effect parent props model action |
Geolocation fetching
https://developer.mozilla.org/en-US/docs/Web/API/Navigator/geolocation
data Geolocation Source #
Geolocation holds latitude, longitude and accuracy, among others.
Constructors
| Geolocation | |
Instances
| Show Geolocation Source # | |
Defined in Miso.Navigator Methods showsPrec :: Int -> Geolocation -> ShowS # show :: Geolocation -> String # showList :: [Geolocation] -> ShowS # | |
| Eq Geolocation Source # | |
Defined in Miso.Navigator | |
| FromJSVal Geolocation Source # | |
Defined in Miso.Navigator Methods fromJSVal :: JSVal -> IO (Maybe Geolocation) Source # fromJSValUnchecked :: JSVal -> IO Geolocation Source # | |
data GeolocationError Source #
Geolocation errors
Constructors
| GeolocationError GeolocationErrorCode MisoString |
Instances
| Show GeolocationError Source # | |
Defined in Miso.Navigator Methods showsPrec :: Int -> GeolocationError -> ShowS # show :: GeolocationError -> String # showList :: [GeolocationError] -> ShowS # | |
| Eq GeolocationError Source # | |
Defined in Miso.Navigator Methods (==) :: GeolocationError -> GeolocationError -> Bool # (/=) :: GeolocationError -> GeolocationError -> Bool # | |
| FromJSVal GeolocationError Source # | |
Defined in Miso.Navigator | |
data GeolocationErrorCode Source #
Geolocation error code
Constructors
| PERMISSION_DENIED | |
| POSITION_UNAVAILABLE | |
| TIMEOUT |