@@ -55,6 +55,7 @@ module Miso.FFI.Internal
55
55
, getElementById
56
56
, diff
57
57
, nextSibling
58
+ , previousSibling
58
59
-- * Conversions
59
60
, integralToJSString
60
61
, realFloatToJSString
@@ -99,6 +100,8 @@ module Miso.FFI.Internal
99
100
-- * Element
100
101
, files
101
102
, click
103
+ -- * Media
104
+ , getUserMedia
102
105
) where
103
106
-----------------------------------------------------------------------------
104
107
import Control.Concurrent (ThreadId , forkIO )
@@ -615,12 +618,18 @@ getParentComponentId domRef =
615
618
getComponentId :: JSVal -> JSM Int
616
619
getComponentId vtree = fromJSValUnchecked =<< vtree ! " componentId"
617
620
-----------------------------------------------------------------------------
618
- -- | Fetch sibling DOM node
621
+ -- | Fetch next sibling DOM node
619
622
--
620
623
-- @since 1.9.0.0
621
624
nextSibling :: JSVal -> JSM JSVal
622
625
nextSibling domRef = domRef ! " nextSibling"
623
626
-----------------------------------------------------------------------------
627
+ -- | Fetch previous sibling DOM node
628
+ --
629
+ -- @since 1.9.0.0
630
+ previousSibling :: JSVal -> JSM JSVal
631
+ previousSibling domRef = domRef ! " previousSibling"
632
+ -----------------------------------------------------------------------------
624
633
-- | When working with /<input>/ of type="file", this is useful for
625
634
-- extracting out the selected files.
626
635
--
@@ -645,3 +654,28 @@ files domRef = fromJSValUnchecked =<< domRef ! "files"
645
654
click :: () -> JSVal -> JSM ()
646
655
click () domRef = void $ domRef # " click" $ ([] :: [MisoString ])
647
656
-----------------------------------------------------------------------------
657
+ -- | Get Camera on user's device
658
+ --
659
+ -- <https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia>
660
+ --
661
+ getUserMedia
662
+ :: Bool
663
+ -- ^ video
664
+ -> Bool
665
+ -- ^ audio
666
+ -> (JSVal -> JSM () )
667
+ -- ^ successful
668
+ -> (JSVal -> JSM () )
669
+ -- ^ errorful
670
+ -> JSM ()
671
+ getUserMedia video audio successful errorful = do
672
+ params <- create
673
+ set (ms " video" ) video params
674
+ set (ms " audio" ) audio params
675
+ devices <- jsg " navigator" ! " mediaDevices"
676
+ promise <- devices # " getUserMedia" $ [params]
677
+ successfulCallback <- asyncCallback1 successful
678
+ void $ promise # " then" $ [successfulCallback]
679
+ errorfulCallback <- asyncCallback1 errorful
680
+ void $ promise # " catch" $ [errorfulCallback]
681
+ -----------------------------------------------------------------------------
0 commit comments