Support time

This commit is contained in:
Thomas Forgione 2020-10-04 21:31:16 +02:00
parent 42de337746
commit a1ccbbefa3
3 changed files with 57 additions and 5 deletions

View File

@ -17,9 +17,22 @@
flags: { width: window.innerWidth, height: window.innerHeight }
});
var lastId, player;
app.ports.registerVideo.subscribe(function(args) {
var time = parseInt(args[2], 10) || undefined;
requestAnimationFrame(function() {
vd.setup(args[0], args[1] + "/manifest.mpd")
if (args[0] !== lastId) {
lastId = args[0];
player = vd.setup(args[0], {
v: args[1] + "/manifest.mpd",
t: parseInt(args[2], 10) || 0
});
} else if (time !== undefined ){
player.currentTime(time);
}
});
});
</script>

View File

@ -2,6 +2,7 @@ module Core exposing (FullModel(..), Model, Msg(..), Page(..), init, subscriptio
import Browser.Events as Events
import Browser.Navigation as Nav
import Dict exposing (Dict)
import Element
import Ports
import Task
@ -85,9 +86,32 @@ update msg model =
( UrlReceived url, Loaded m ) ->
let
split =
String.split "/" (Maybe.withDefault "" url.fragment)
splits =
String.split "?" (Maybe.withDefault "" url.fragment)
( split, args ) =
case splits of
h1 :: h2 :: _ ->
( String.split "/" h1, parseQueryString h2 )
h1 :: _ ->
( String.split "/" h1, Dict.empty )
_ ->
( [], Dict.empty )
time =
case Maybe.map String.toInt (Dict.get "t" args) of
Just (Just 0) ->
Nothing
Just (Just t) ->
Just t
_ ->
Nothing
-- String.split "/" (Maybe.withDefault "" (List.head splits))
( playlistName, videoName ) =
case split of
p :: v :: _ ->
@ -114,7 +138,7 @@ update msg model =
case ( playlist, video ) of
( Just p, Just v ) ->
( Video p v
, Ports.registerVideo ( Twitch.videoId v, v.url )
, Ports.registerVideo ( Twitch.videoId v, v.url, time )
)
( Just p, Nothing ) ->
@ -127,3 +151,18 @@ update msg model =
_ ->
( model, Cmd.none )
splitter : String -> Maybe ( String, String )
splitter input =
case String.split "=" input of
h :: t ->
Just ( h, String.join "=" t )
_ ->
Nothing
parseQueryString : String -> Dict String String
parseQueryString input =
Dict.fromList (List.filterMap splitter (String.split "&" input))

View File

@ -1,4 +1,4 @@
port module Ports exposing (registerVideo)
port registerVideo : ( String, String ) -> Cmd msg
port registerVideo : ( String, String, Maybe Int ) -> Cmd msg