From 18a02d74908e937d1a16097750cccebba527612c Mon Sep 17 00:00:00 2001 From: TreetopFlyer Date: Mon, 25 Apr 2022 17:23:23 -0400 Subject: [PATCH] buncha stuff --- app.js | 185 +++++++++++++++++++++++++++++++++++++++++------ index.html | 41 +---------- testdata-01.json | 142 ++++++++++++++++++++++++++++++++++++ testdata-02.json | 142 ++++++++++++++++++++++++++++++++++++ 4 files changed, 451 insertions(+), 59 deletions(-) create mode 100644 testdata-01.json create mode 100644 testdata-02.json diff --git a/app.js b/app.js index f107a25..2e6dae7 100644 --- a/app.js +++ b/app.js @@ -1,9 +1,48 @@ // @ts-check /// +import 'https://js.boxcast.com/v3.min.js'; import { h, html, render } from "https://esm.sh/htm/preact"; -import { createContext, Fragment } from 'https://esm.sh/preact'; import { useReducer, useState, useEffect, useLayoutEffect, useMemo, useRef } from 'https://esm.sh/preact/hooks'; +import State01 from "./testdata-01.json" assert { type: "json" }; +import State02 from "./testdata-02.json" assert { type: "json" }; + +const Styles = { + Broadcast: + { + position: "relative", + display: "flex", + padding: "5px 0 5px 0", + }, + Time: + { + width: "75px", + marginRight: "5px", + fontSize: "16px", + textAlign: "right", + }, + Partition: + { + margin: "10px 0 0 0", + }, + Pointer: + { + width: "75px", + }, + Alert: + { + position: "fixed", + right: "20px", + bottom: "20px", + width: "300px", + height: "200px", + background: "#333", + borderRadius: "5px", + transition: "all 0.4s", + color: "#fff", + } +}; +const PlayerID = "boxcast-player" /** @type {(props:{channel:string, interval:number})=>any} */ const App = props => @@ -17,20 +56,43 @@ const App = props => /** @type {Boxcast.StateBinding} */ const [LiveGet, LiveSet] = useState(""); - /** @type {(item:Boxcast.Broadcast)=>boolean} */ - const Iterator = (item) => item.timeframe == "current" || item.timeframe == "preroll"; + /** @type {(inList:Array)=>Array} */ + const SortStart = (inList) => { + inList.sort((a, b) => a.starts_at > b.starts_at ? 1 : -1); + inList.forEach( item => item.start = DateParse(item.starts_at)); + return inList; + } + const Player = useRef(null); + // on mount useEffect(()=> { + Player.current = boxcast(`#${PlayerID}`); + /* + Player.current.loadChannel(props.channel, + { + showTitle: true, + showDescription: true, + showCountdown: true, + + //selectedBroadcastId: "yo8sefnnejvw3cx3vhup", + showRelated: false, + onLoadBroadcast: console.log, + + autoplay: true, + defaultVideo: "next" + }); + */ + + return; /** @type {()=>Promise} */ const Ping = async () => { const response = await fetch(`https://rest.boxcast.com/channels/${props.channel}/broadcasts?l=50`); /** @type {Array} */ const json = await response.json(); - json.sort((a, b) => a.starts_at > b.starts_at ? 1 : -1); - ListSet(json); + ListSet(SortStart(json)); }; Ping(); @@ -39,6 +101,7 @@ const App = props => } , []); + // on new list useEffect(()=> { let live = ""; @@ -50,47 +113,125 @@ const App = props => break; } } + if(LiveGet != live) + { + console.log("new video starting") + } if(SelectedGet != live) { - + console.log("would you like to switch?"); } LiveSet(live); } , [ListGet]); + // on new event started useEffect(()=> { // alert("New session is starting.") + } , [LiveGet]); - return html` -
- ${ - ListGet.map(item => html`<${BroadcastItem} item=${item} active=${item.id == SelectedGet} select=${()=>SelectedSet(item.id)} />`) + // on new video selected + useEffect(()=> + { + Player.current.loadChannel(props.channel, + { + selectedBroadcastId: SelectedGet, + showTitle: true, + showDescription: true, + showCountdown: true, + showRelated: false, + autoplay: true, + defaultVideo: "next" + }); } + , [SelectedGet]) + + return html` +
+
+
+ + +
+
+ ${ + ListGet.map( (item, index) => h( + BroadcastItem, + { + item: item, + previous: ListGet[index-1], + priority: item.id == LiveGet, + selected: item.id == SelectedGet, + select: ()=>SelectedSet(item.id) + } + )) + } +
+ <${BroadcastAlert}>
`; } -/** @type {(props:{item:Boxcast.Broadcast, active:boolean, select:()=>void})=>any} */ -const BroadcastItem = ({item, active, select}) => +/** @type {(props:{item:Boxcast.Broadcast, previous: false | Boxcast.Broadcast, priority:boolean, selected:boolean, select:()=>void})=>any} */ +const BroadcastItem = ({item, previous, priority, selected, select}) => { - const startDate = useMemo(()=>DateParse(item.starts_at), [item.starts_at]); + let pointerText; + if(item.timeframe == "current" || item.timeframe == "preroll") + { + pointerText = `Live:`; + } + else if (priority) + { + pointerText = `Next:`; + } + + let partition; + if(!previous || (previous.start.Date !== item.start.Date)) + { + partition = html`

${item.start.Day}, ${item.start.Month} ${item.start.Date}

` + } + + let buttonText; + if(item.timeframe == "past") + { + buttonText = "Recording"; + } + if(item.timeframe == "current" || item.timeframe == "preroll") + { + buttonText = "Watch"; + } + if(item.timeframe == "future") + { + buttonText = "Preview"; + } + if(selected) + { + buttonText = "(Viewing)"; + } return html` -
- ${startDate.Month} ${startDate.Date} + ${ partition } +
+
${ pointerText }
+
${item.start.Hours}:${item.start.Minutes} ${item.start.M}
${item.name} - ${startDate.Hours}:${startDate.Minutes} ${startDate.M} - ${ - active ? html`
Active
` : null - } -

${item.id}

-
- `; + +
`; }; +const BroadcastAlert = () => +{ + return html` +
+ X +

A new session is starting.

+ +
+ `; +} /** @type {(inDate:string)=>Boxcast.Date} */ const DateParse = (inDateString) => diff --git a/index.html b/index.html index 5779e7a..57d0184 100644 --- a/index.html +++ b/index.html @@ -3,57 +3,24 @@
-
-
+
\ No newline at end of file diff --git a/testdata-01.json b/testdata-01.json new file mode 100644 index 0000000..6517e0e --- /dev/null +++ b/testdata-01.json @@ -0,0 +1,142 @@ +[ + { + "id": "a3fvb7xs5yrl7xr50lyr", + "name": "Welcome and Main Session 1", + "starts_at": "2022-05-02T18:55:00Z", + "stops_at": "2022-05-02T20:20:00Z", + "timeframe": "future", + "description": "", + "preview": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "poster": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "transcoder_profile": "", + "account_id": "ilkxk5hkn51drmocrv0d", + "channel_id": "welcome-and-main-session-1-sfry0q5zi5fpjtxzsnih", + "tags": [] + }, + { + "id": "ur7p1uqz6rl3dx7drvgf", + "name": "Breakout Session - Alistair Begg", + "starts_at": "2022-05-02T20:25:00Z", + "stops_at": "2022-05-02T21:45:00Z", + "timeframe": "future", + "description": "", + "preview": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "poster": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "transcoder_profile": "", + "account_id": "ilkxk5hkn51drmocrv0d", + "channel_id": "breakout-session---alistair-begg-gkkr1jga58geasofpnmd", + "tags": [] + }, + { + "id": "n1w1rbpaaohkrx2aumll", + "name": "Main Session 2 -John Woodhouse", + "starts_at": "2022-05-02T23:10:00Z", + "stops_at": "2022-05-03T00:30:00Z", + "timeframe": "future", + "description": "", + "preview": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "poster": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "transcoder_profile": "", + "account_id": "ilkxk5hkn51drmocrv0d", + "channel_id": "breakout-session---alistair-begg-mnhpqpgyg8kobjgqerpw", + "tags": [] + }, + { + "id": "wwomf8amsgnct6esof3s", + "name": "Main Session 3 -Alistair Begg", + "starts_at": "2022-05-03T13:10:00Z", + "stops_at": "2022-05-03T14:30:00Z", + "timeframe": "future", + "description": "", + "preview": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "poster": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "transcoder_profile": "", + "account_id": "ilkxk5hkn51drmocrv0d", + "channel_id": "main-session-2--john-woodhouse-giplu3h3d7rsgays1yyg", + "tags": [] + }, + { + "id": "mjzsudcjjqor4qvpioqx", + "name": "Main Session 4 -John Woodhouse", + "starts_at": "2022-05-03T14:55:00Z", + "stops_at": "2022-05-03T16:15:00Z", + "timeframe": "future", + "description": "", + "preview": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "poster": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "transcoder_profile": "", + "account_id": "ilkxk5hkn51drmocrv0d", + "channel_id": "main-session-2--john-woodhouse-odnunx2aaa1ztxqtufaj", + "tags": [] + }, + { + "id": "ybwm92ssmqhshhrfpvfr", + "name": "Main Session 5 -John Woodhouse", + "starts_at": "2022-05-03T17:25:00Z", + "stops_at": "2022-05-03T18:35:00Z", + "timeframe": "future", + "description": "", + "preview": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "poster": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "transcoder_profile": "", + "account_id": "ilkxk5hkn51drmocrv0d", + "channel_id": "main-session-2--john-woodhouse-wdyqpnsguolrvjwl4aei", + "tags": [] + }, + { + "id": "jed2ccr6o9vukpavrs7t", + "name": "Breakout Session -Tony Merida", + "starts_at": "2022-05-03T18:40:00Z", + "stops_at": "2022-05-03T20:00:00Z", + "timeframe": "future", + "description": "", + "preview": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "poster": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "transcoder_profile": "", + "account_id": "ilkxk5hkn51drmocrv0d", + "channel_id": "main-session-6--tony-merida-xkw75et1zzz48xdq5grz", + "tags": [] + }, + { + "id": "yo8sefnnejvw3cx3vhup", + "name": "Q\u0026A with Alistair Begg", + "starts_at": "2022-05-04T00:25:00Z", + "stops_at": "2022-05-04T01:45:00Z", + "timeframe": "future", + "description": "", + "preview": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "poster": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "transcoder_profile": "", + "account_id": "ilkxk5hkn51drmocrv0d", + "channel_id": "main-session-2--john-woodhouse-r7ufs6iabwuch7w9hgmm", + "tags": [] + }, + { + "id": "ht6wddox6ompgbusacle", + "name": "Main Session 6 - John Woodhouse", + "starts_at": "2022-05-04T13:10:00Z", + "stops_at": "2022-05-04T14:30:00Z", + "timeframe": "future", + "description": "", + "preview": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "poster": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "transcoder_profile": "", + "account_id": "ilkxk5hkn51drmocrv0d", + "channel_id": "qa-with-alistair-begg-mmyh7oyiecuuqxykafff", + "tags": [] + }, + { + "id": "r9s2oqfl4vhxzfkx1bwf", + "name": "Panel Q\u0026A", + "starts_at": "2022-05-04T14:55:00Z", + "stops_at": "2022-05-04T16:30:00Z", + "timeframe": "future", + "description": "", + "preview": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "poster": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "transcoder_profile": "", + "account_id": "ilkxk5hkn51drmocrv0d", + "channel_id": "panel-qa-v7jfkqhc8viidxebcvvk", + "tags": [] + } +] \ No newline at end of file diff --git a/testdata-02.json b/testdata-02.json new file mode 100644 index 0000000..330e881 --- /dev/null +++ b/testdata-02.json @@ -0,0 +1,142 @@ +[ + { + "id": "a3fvb7xs5yrl7xr50lyr", + "name": "Welcome and Main Session 1", + "starts_at": "2022-05-02T18:55:00Z", + "stops_at": "2022-05-02T20:20:00Z", + "timeframe": "past", + "description": "", + "preview": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "poster": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "transcoder_profile": "", + "account_id": "ilkxk5hkn51drmocrv0d", + "channel_id": "welcome-and-main-session-1-sfry0q5zi5fpjtxzsnih", + "tags": [] + }, + { + "id": "ur7p1uqz6rl3dx7drvgf", + "name": "Breakout Session - Alistair Begg", + "starts_at": "2022-05-02T20:25:00Z", + "stops_at": "2022-05-02T21:45:00Z", + "timeframe": "preroll", + "description": "", + "preview": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "poster": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "transcoder_profile": "", + "account_id": "ilkxk5hkn51drmocrv0d", + "channel_id": "breakout-session---alistair-begg-gkkr1jga58geasofpnmd", + "tags": [] + }, + { + "id": "n1w1rbpaaohkrx2aumll", + "name": "Main Session 2 -John Woodhouse", + "starts_at": "2022-05-02T23:10:00Z", + "stops_at": "2022-05-03T00:30:00Z", + "timeframe": "future", + "description": "", + "preview": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "poster": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "transcoder_profile": "", + "account_id": "ilkxk5hkn51drmocrv0d", + "channel_id": "breakout-session---alistair-begg-mnhpqpgyg8kobjgqerpw", + "tags": [] + }, + { + "id": "wwomf8amsgnct6esof3s", + "name": "Main Session 3 -Alistair Begg", + "starts_at": "2022-05-03T13:10:00Z", + "stops_at": "2022-05-03T14:30:00Z", + "timeframe": "future", + "description": "", + "preview": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "poster": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "transcoder_profile": "", + "account_id": "ilkxk5hkn51drmocrv0d", + "channel_id": "main-session-2--john-woodhouse-giplu3h3d7rsgays1yyg", + "tags": [] + }, + { + "id": "mjzsudcjjqor4qvpioqx", + "name": "Main Session 4 -John Woodhouse", + "starts_at": "2022-05-03T14:55:00Z", + "stops_at": "2022-05-03T16:15:00Z", + "timeframe": "future", + "description": "", + "preview": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "poster": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "transcoder_profile": "", + "account_id": "ilkxk5hkn51drmocrv0d", + "channel_id": "main-session-2--john-woodhouse-odnunx2aaa1ztxqtufaj", + "tags": [] + }, + { + "id": "ybwm92ssmqhshhrfpvfr", + "name": "Main Session 5 -John Woodhouse", + "starts_at": "2022-05-03T17:25:00Z", + "stops_at": "2022-05-03T18:35:00Z", + "timeframe": "future", + "description": "", + "preview": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "poster": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "transcoder_profile": "", + "account_id": "ilkxk5hkn51drmocrv0d", + "channel_id": "main-session-2--john-woodhouse-wdyqpnsguolrvjwl4aei", + "tags": [] + }, + { + "id": "jed2ccr6o9vukpavrs7t", + "name": "Breakout Session -Tony Merida", + "starts_at": "2022-05-03T18:40:00Z", + "stops_at": "2022-05-03T20:00:00Z", + "timeframe": "future", + "description": "", + "preview": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "poster": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "transcoder_profile": "", + "account_id": "ilkxk5hkn51drmocrv0d", + "channel_id": "main-session-6--tony-merida-xkw75et1zzz48xdq5grz", + "tags": [] + }, + { + "id": "yo8sefnnejvw3cx3vhup", + "name": "Q\u0026A with Alistair Begg", + "starts_at": "2022-05-04T00:25:00Z", + "stops_at": "2022-05-04T01:45:00Z", + "timeframe": "future", + "description": "", + "preview": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "poster": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "transcoder_profile": "", + "account_id": "ilkxk5hkn51drmocrv0d", + "channel_id": "main-session-2--john-woodhouse-r7ufs6iabwuch7w9hgmm", + "tags": [] + }, + { + "id": "ht6wddox6ompgbusacle", + "name": "Main Session 6 - John Woodhouse", + "starts_at": "2022-05-04T13:10:00Z", + "stops_at": "2022-05-04T14:30:00Z", + "timeframe": "future", + "description": "", + "preview": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "poster": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "transcoder_profile": "", + "account_id": "ilkxk5hkn51drmocrv0d", + "channel_id": "qa-with-alistair-begg-mmyh7oyiecuuqxykafff", + "tags": [] + }, + { + "id": "r9s2oqfl4vhxzfkx1bwf", + "name": "Panel Q\u0026A", + "starts_at": "2022-05-04T14:55:00Z", + "stops_at": "2022-05-04T16:30:00Z", + "timeframe": "future", + "description": "", + "preview": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "poster": "https://uploads.boxcast.com/ilkxk5hkn51drmocrv0d/2022-03/ahf78osidyvoujyhhq8r/BoxcastImage.jpg", + "transcoder_profile": "", + "account_id": "ilkxk5hkn51drmocrv0d", + "channel_id": "panel-qa-v7jfkqhc8viidxebcvvk", + "tags": [] + } +] \ No newline at end of file