This repository has been archived by the owner on Nov 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 73
feat: HtmlVideoElement, HtmlMediaElement, TextTrack, VideoTrack #196
Open
illusionalsagacity
wants to merge
6
commits into
reasonml-community:master
Choose a base branch
from
illusionalsagacity:media-video-element
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1727301
feat: HtmlVideoElement, HtmlMediaElement, TextTrack, VideoTrack
d79658b
chore: update package version
41918ae
refactor: rename asVideoElement to ofElement
7694033
Merge remote-tracking branch 'upstream/master' into media-video-element
4f525cc
fix: use Js.Promise.t over Js.promise
ebf0b3d
fix: type sig
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/** | ||
* Spec: https://html.spec.whatwg.org/multipage/media.html#htmlmediaelement | ||
*/ | ||
module Impl = (T: {type t;}) => { | ||
type t_htmlMediaElement = T.t; | ||
|
||
type mediaProvider; // TODO: one of MediaStream, MediaSource, or Blob | ||
|
||
/** Properties */ | ||
[@bs.get] external buffered: t_htmlMediaElement => Webapi__TimeRanges.t = "buffered"; | ||
|
||
// This is part of the recommendation spec | ||
// type mediaController; // TODO | ||
// [@bs.get] [@bs.return nullable] external controller: t_htmlMediaElement => option(mediaController) = "controller"; | ||
// [@bs.set] external setController: (t_htmlMediaElement, mediaController) => unit = "controller"; | ||
|
||
[@bs.get] external controls: t_htmlMediaElement => bool = "controls"; | ||
[@bs.set] external setControls: (t_htmlMediaElement, bool) => unit = "controls"; | ||
|
||
/** One or more of "nodownload", "nofullscreen", and "noremoteplayback" */ | ||
[@bs.get] external controlsList: t_htmlMediaElement => Dom.domTokenList = "controlsList"; | ||
|
||
[@bs.get] [@bs.return nullable] external crossOrigin: t_htmlMediaElement => option(string) = "crossOrigin"; | ||
[@bs.set] | ||
external setCrossOrigin: | ||
( | ||
t_htmlMediaElement, | ||
[@bs.string] [ | `anonymous | [@bs.as "use-credentials"] `useCredentials | [@bs.as ""] `empty] | ||
) => | ||
unit = | ||
"crossOrigin"; | ||
|
||
[@bs.get] external currentSrc: t_htmlMediaElement => string = "currentSrc"; | ||
|
||
[@bs.get] external currentTime: t_htmlMediaElement => float = "currentTime"; | ||
[@bs.set] external setCurrentTime: (t_htmlMediaElement, float) => unit = "currentTime"; | ||
|
||
[@bs.get] external defaultMuted: t_htmlMediaElement => bool = "defaultMuted"; | ||
[@bs.set] external setDefaultMuted: (t_htmlMediaElement, bool) => unit = "defaultMuted"; | ||
|
||
[@bs.get] external defaultPlaybackRate: t_htmlMediaElement => float = "defaultPlaybackRate"; | ||
[@bs.set] external setDefaultPlaybackRate: (t_htmlMediaElement, float) => unit = "defaultPlaybackRate"; | ||
|
||
[@bs.get] external disableRemotePlayback: t_htmlMediaElement => bool = "disableRemotePlayback"; | ||
[@bs.set] external setDisableRemotePlayback: (t_htmlMediaElement, bool) => unit = "disableRemotePlayback"; | ||
|
||
[@bs.get] external duration: t_htmlMediaElement => float = "duration"; | ||
[@bs.get] external ended: t_htmlMediaElement => bool = "ended"; | ||
[@bs.get] [@bs.return nullable] external error: t_htmlMediaElement => option(Webapi__Dom__MediaError.t) = "error"; | ||
|
||
[@bs.get] external loop: t_htmlMediaElement => bool = "loop"; | ||
[@bs.set] external setLoop: (t_htmlMediaElement, bool) => unit = "loop"; | ||
|
||
// [@bs.get] external mediaGroup: t_htmlMediaElement => string = "mediaGroup"; // Not well supported | ||
// [@bs.set] external setMediaGroup: (t_htmlMediaElement, string) => unit = "mediaGroup"; // Not well supported | ||
|
||
[@bs.get] external muted: t_htmlMediaElement => bool = "muted"; | ||
[@bs.set] external setMuted: (t_htmlMediaElement, bool) => unit = "muted"; | ||
|
||
type mediaNetworkState = | ||
| NetworkEmpty // 0 | ||
| NetworkIdle // 1 | ||
| NetworkLoading // 2 | ||
| NetworkNoSource; // 3 | ||
|
||
let decodeNetworkState = fun | ||
| 0 => Some(NetworkEmpty) | ||
| 1 => Some(NetworkIdle) | ||
| 2 => Some(NetworkLoading) | ||
| 3 => Some(NetworkNoSource) | ||
| _ => None; | ||
|
||
[@bs.get] external _networkState: t_htmlMediaElement => int = "networkState"; | ||
let networkState = t_htmlMediaElement => _networkState(t_htmlMediaElement) |> decodeNetworkState; | ||
|
||
[@bs.get] external paused: t_htmlMediaElement => bool = "paused"; | ||
|
||
[@bs.get] external playbackRate: t_htmlMediaElement => float = "playbackRate"; | ||
[@bs.set] external setPlaybackRate: (t_htmlMediaElement, float) => unit = "playbackRate"; | ||
|
||
[@bs.get] external played: t_htmlMediaElement => Webapi__TimeRanges.t = "played"; | ||
[@bs.get] external preload: t_htmlMediaElement => string = "preload"; | ||
|
||
type readyStateEnum = | ||
| HaveNothing | ||
| HaveMetadata | ||
| HaveCurrentData | ||
| HaveFutureData | ||
| HaveEnoughData; | ||
|
||
let decodeReadyState = fun | ||
| 0 => Some(HaveNothing) | ||
| 1 => Some(HaveMetadata) | ||
| 2 => Some(HaveCurrentData) | ||
| 3 => Some(HaveFutureData) | ||
| 4 => Some(HaveEnoughData) | ||
| _ => None; | ||
|
||
[@bs.get] external _readyState: t_htmlMediaElement => int = "readyState"; | ||
let readyState = t => _readyState(t) |> decodeReadyState; | ||
|
||
[@bs.get] external seekable: t_htmlMediaElement => Webapi__TimeRanges.t = "seekable"; | ||
[@bs.get] external seeking: t_htmlMediaElement => bool = "seeking"; | ||
// [@bs.get] external sinkId: t_htmlMediaElement => string = "sinkId"; // experimental | ||
|
||
[@bs.get] external src: t_htmlMediaElement => string = "src"; | ||
[@bs.set] external setSrc: (t_htmlMediaElement, string) => unit = "src"; | ||
|
||
[@bs.get] [@bs.return nullable] external srcObject: t_htmlMediaElement => option(mediaProvider) = "srcObject"; | ||
|
||
[@bs.get] external audioTracks: t_htmlMediaElement => Webapi__AudioTrackList.t = "textTracks"; | ||
[@bs.get] external textTracks: t_htmlMediaElement => Webapi__TextTrackList.t = "textTracks"; | ||
|
||
// [@bs.get] external videoTracks: t_htmlMediaElement => Webapi__VideoTrackList.t = "videoTracks"; // Not widely available | ||
|
||
[@bs.get] external volume: t_htmlMediaElement => float = "volume"; | ||
[@bs.set] external setVolume: (t_htmlMediaElement, float) => unit = "volume"; | ||
|
||
/** Methods */ | ||
|
||
[@bs.send] external addTextTrack: (t_htmlMediaElement, Webapi__TextTrack.textTrackKind, ~label: string, ~language: string, unit) => Webapi__TextTrack.t = "addTextTrack"; | ||
|
||
// return is one of "probably", "maybe", or "" | ||
[@bs.send] external canPlayType: (t_htmlMediaElement, string) => string = "canPlayType"; | ||
// [@bs.send] external fastSeek: (t_htmlMediaElement, float) => unit = "fastSeek"; // experimental | ||
[@bs.send] external load: t_htmlMediaElement => unit = "load"; | ||
[@bs.send] external pause: t_htmlMediaElement => unit = "pause"; | ||
[@bs.send] external play: t_htmlMediaElement => Js.Promise.t(unit) = "play"; | ||
|
||
// [@bs.send] external getStartDate: t_htmlMediaElement => Js.Date.t = "getStartDate"; // not supported? | ||
}; | ||
|
||
type t; // TODO: Dom.htmlMediaElement | ||
|
||
include Webapi__Dom__EventTarget.Impl({type nonrec t = t;}); | ||
include Webapi__Dom__Node.Impl({type nonrec t = t;}); | ||
include Webapi__Dom__Element.Impl({type nonrec t = t;}); | ||
include Webapi__Dom__HtmlElement.Impl({type nonrec t = t;}); | ||
include Impl({type nonrec t = t;}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Spec: https://html.spec.whatwg.org/multipage/media.html#htmlvideoelement | ||
*/ | ||
module Impl = (T: {type t;}) => { | ||
type t_htmlVideoElement = T.t; | ||
|
||
external unsafeOfElement: Dom.element => t_htmlVideoElement = "%identity"; | ||
|
||
let ofElement = (el): option(t_htmlVideoElement) => switch(Webapi__Dom__Element.tagName(el)) { | ||
| "VIDEO" => el->unsafeOfElement->Some | ||
| _ => None | ||
}; | ||
|
||
/** Properties */ | ||
[@bs.get] external height: t_htmlVideoElement => int = "height"; | ||
[@bs.set] external setHeight: (t_htmlVideoElement, int) => unit = "height"; | ||
[@bs.get] external poster: t_htmlVideoElement => string = "poster"; | ||
[@bs.set] external setPoster: (t_htmlVideoElement, string) => unit = "poster"; | ||
[@bs.get] external videoHeight: t_htmlVideoElement => int = "videoHeight"; | ||
[@bs.get] external videoWidth: t_htmlVideoElement => int = "videoWidth"; | ||
[@bs.get] external width: t_htmlVideoElement => int = "width"; | ||
[@bs.set] external setWidth: (t_htmlVideoElement, int) => unit = "width"; | ||
}; | ||
|
||
type t; // TODO: Dom.htmlVideoElement | ||
|
||
include Webapi__Dom__EventTarget.Impl({ type nonrec t = t; }); | ||
include Webapi__Dom__Node.Impl({ type nonrec t = t; }); | ||
include Webapi__Dom__Element.Impl({ type nonrec t = t; }); | ||
include Webapi__Dom__HtmlElement.Impl({ type nonrec t = t; }); | ||
include Webapi__Dom__HtmlMediaElement.Impl({ type nonrec t = t; }); | ||
include Impl({ type nonrec t = t; }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Spec: https://html.spec.whatwg.org/multipage/media.html#mediaerror | ||
*/ | ||
type t; | ||
|
||
type errorType = | ||
| ERR_ABORTED | ||
| ERR_NETWORK | ||
| ERR_DECODE | ||
| ERR_SRC_NOT_SUPPORTED; | ||
|
||
let decodeErrorType = fun | ||
| 1 => Some(ERR_ABORTED) | ||
| 2 => Some(ERR_NETWORK) | ||
| 3 => Some(ERR_DECODE) | ||
| 4 => Some(ERR_SRC_NOT_SUPPORTED) | ||
| _ => None; | ||
|
||
/** Properties */ | ||
|
||
[@bs.get] external _code: t => int = "code"; | ||
let code = t => _code(t) |> decodeErrorType; | ||
[@bs.get] external message: t => string = "message"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Spec: https://html.spec.whatwg.org/multipage/media.html#texttrackcue | ||
*/ | ||
type t; | ||
|
||
include Webapi__Dom__EventTarget.Impl({ type nonrec t = t; }); | ||
|
||
// FIXME: circular dep | ||
// [@bs.get] [@bs.return nullable] external track: t => option(Webapi__TextTrack.t) = "track"; | ||
[@bs.get] external id: t => string = "id"; | ||
[@bs.set] external setId: (t, string) => unit = "id"; | ||
[@bs.get] external startTime: t => float = "startTime"; | ||
[@bs.set] external setStartTime: (t, float) => unit = "startTime"; | ||
[@bs.get] external endTime: t => float = "endTime"; | ||
[@bs.set] external setEndTime: (t, float) => unit = "endTime"; | ||
[@bs.get] external pauseOnExit: t => bool = "pauseOnExit"; | ||
[@bs.set] external setPauseOnExit: (t, bool) => unit = "pauseOnExit"; |
11 changes: 11 additions & 0 deletions
11
src/Webapi/TextTrack/Webapi__TextTrack__TextTrackCueList.re
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* Spec: https://html.spec.whatwg.org/multipage/media.html#texttrackcuelist | ||
*/ | ||
type t; | ||
|
||
/** Properties */ | ||
[@bs.get] external length: t => int = "length"; | ||
[@bs.get_index] [@bs.return nullable] external get: (t, int) => option(Webapi__TextTrack__TextTrackCue.t) = ""; | ||
|
||
/** Methods */ | ||
[@bs.send] [@bs.return nullable] external getCueById: (t, string) => option(Webapi__TextTrack__TextTrackCue.t) = "getCueById"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Spec: https://html.spec.whatwg.org/multipage/media.html#audiotrack | ||
*/ | ||
type t; | ||
|
||
/** Properties */ | ||
|
||
[@bs.get] external id: t => string = "id"; | ||
[@bs.get] external kind: t => string = "kind"; | ||
[@bs.get] external label: t => string = "label"; | ||
[@bs.get] external language: t => string = "language"; | ||
|
||
[@bs.get] external enabled: t => bool = "enabled"; | ||
[@bs.set] external setEnabled: (t, bool) => unit = "enabled"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Spec: https://html.spec.whatwg.org/multipage/media.html#audiotracklist | ||
*/ | ||
type t; | ||
include Webapi__Dom__EventTarget.Impl({ type nonrec t = t; }); | ||
|
||
/** Properties */ | ||
|
||
[@bs.get] external length: t => float = "length"; | ||
[@bs.get_index] external get: (t, int) => option(Webapi__AudioTrack.t) = ""; | ||
|
||
/** Methods */ | ||
|
||
[@bs.send] [@bs.return nullable] external getTrackById: (t, string) => option(Webapi__AudioTrack.t) = "getTrackById"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Spec: https://html.spec.whatwg.org/multipage/media.html#texttrack | ||
*/ | ||
type t; | ||
include Webapi__Dom__EventTarget.Impl({ type nonrec t = t; }); | ||
|
||
/** @since 0.20.0 */ | ||
module TextTrackCueList = Webapi__TextTrack__TextTrackCueList; | ||
/** @since 0.20.0 */ | ||
module TextTrackCue = Webapi__TextTrack__TextTrackCue; | ||
|
||
// TODO: string enum for | ||
// enum TextTrackMode { "disabled", "hidden", "showing" }; | ||
// enum TextTrackKind { "subtitles", "captions", "descriptions", "chapters", "metadata" }; | ||
type textTrackMode = string; | ||
type textTrackKind = string; | ||
|
||
/** Properties */ | ||
|
||
[@bs.get] external activeCues: t => option(TextTrackCueList.t) = "activeCues"; | ||
[@bs.get] external cues: t => option(TextTrackCueList.t) = "cues"; | ||
[@bs.get] external id: t => string = "id"; | ||
[@bs.get] external inBandMetadataTrackDispatchType: t => option(string) = "inBandMetadataTrackDispatchType"; | ||
[@bs.get] external kind: t => textTrackKind = "kind"; | ||
[@bs.get] external label: t => string = "label"; | ||
[@bs.get] external language: t => string = "language"; | ||
[@bs.get] external mode: t => textTrackMode = "mode"; | ||
[@bs.set] external setMode: (t, textTrackMode) => unit = "mode"; | ||
|
||
/** Methods */ | ||
|
||
[@bs.send] external addCue: (t, TextTrackCue.t) => unit = "addCue"; | ||
[@bs.send] external removeCue: (t, TextTrackCue.t) => unit = "removeCue"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* Spec: https://html.spec.whatwg.org/multipage/media.html#texttracklist | ||
*/ | ||
|
||
type t; | ||
include Webapi__Dom__EventTarget.Impl({ type nonrec t = t; }); | ||
|
||
[@bs.get] external length: t => float = "length"; | ||
[@bs.get_index] external get: (t, int) => option(Webapi__TextTrack.t) = ""; | ||
[@bs.send] [@bs.return nullable] external getTrackById: (t, string) => option(Webapi__TextTrack.t) = "getTrackById"; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking this might be a
Webapi__MediaProvider.t
instead of a local phantom type