miso
Copyright(C) 2016-2026 David M. Johnson
LicenseBSD3-style (see the file LICENSE)
MaintainerDavid M. Johnson <code@dmj.io>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

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
  | GotLocation Geolocation
  | LocationError GeolocationError
  | RequestCamera
  | GotStream Stream
  | MediaError JSVal

update :: Action -> Effect p props Model Action
update RequestLocation =
  geolocation GotLocation LocationError
update RequestCamera =
  getUserMedia (userMedia { audio = False }) GotStream MediaError
update _ = pure ()

API groups

Error handling

Geolocation errors are decoded from the browser's GeolocationPositionError object into GeolocationError, which carries a GeolocationErrorCode (PERMISSION_DENIED, POSITION_UNAVAILABLE, TIMEOUT) and a human-readable message string.

See also

Synopsis

User media

getUserMedia Source #

Arguments

:: UserMedia

Options

-> (Stream -> action)

Successful callback

-> (JSVal -> action)

Errorful callback

-> Effect parent props model action 

data UserMedia Source #

Type for dealing with 'navigator.mediaDevices.getUserMedia'

https://developer.mozilla.org/en-US/docs/Web/API/Navigator/mediaDevices

Constructors

UserMedia 

Fields

  • audio :: Bool

    Request access to the user's microphone

  • video :: Bool

    Request access to the user's camera

Instances

Instances details
Show UserMedia Source # 
Instance details

Defined in Miso.Navigator

Eq UserMedia Source # 
Instance details

Defined in Miso.Navigator

type Stream = JSVal Source #

A media stream

Clipboard

copyClipboard Source #

Arguments

:: MisoString

Options

-> action

Successful callback

-> (JSVal -> action)

Errorful callback

-> Effect parent props model action 

OnLine

isOnLine Source #

Arguments

:: (Bool -> action)

Successful callback

-> Effect parent props model action 

Geolocation

geolocation Source #

Arguments

:: (Geolocation -> action)

Success callback; receives the device's current position

-> (GeolocationError -> action)

Error callback; receives a GeolocationError with code and message

-> Effect parent props model action 

data Geolocation Source #

Geolocation holds latitude, longitude and accuracy, among others.

Constructors

Geolocation 

Fields

Instances

Instances details
Show Geolocation Source # 
Instance details

Defined in Miso.Navigator

Eq Geolocation Source # 
Instance details

Defined in Miso.Navigator

FromJSVal Geolocation Source # 
Instance details

Defined in Miso.Navigator