Here are the different shapes of the MediaStream constraints:
{ audio: true, video: true }
Or
{
audio: true,
video: { width: 1280, height: 720 }
}
Or
{
audio: true,
video: {
width: { min: 1280 },
height: { min: 720 }
}
}
Or
{
audio: true,
video: {
width: { min: 1024, ideal: 1280, max: 1920 },
height: { min: 776, ideal: 720, max: 1080 }
}
}
Or
{ audio: true, video: { facingMode: "user" } }
{ audio: true, video: { facingMode: { exact: "environment" } } }
It looks trivial but … not in Elm.
I feel that I should use a flat record to represent this data on the Elm side:
type alias Constraints =
{ audio : Bool
, video : Bool
, videoWidth : Maybe Int
, videoHeight: Maybe Int
, videoWidthMin: Maybe Int
, ...
}
But I feel also that I could just implement several constraints environments:
type alias Constraints =
{ audio : Bool
, video : Bool
}
type alias VideoSizeConstraints =
{ audio : Bool
, video : Bool
, videoWidth : Int
, videoHeight: Int
}
type alias VideoMinSizeConstraints =
{ audio : Bool
, video : Bool
, videoWidthMin: Int
, videoHeightMin: Int
}
Then pattern match on the type alias to parse it and send the data through a port and call navigator.mediaDevices.getUserMedia()
on the javascript side.
It is definitely much more code to write but I prefer this than one record full of Maybe values.
What do you think of?