diff --git a/CHANGELOG.md b/CHANGELOG.md
index 350f0506..d46e7a83 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,9 +7,66 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+This version went through a major refactor, which resulted in a different arcitecture of the app to support new features, the rewrite of many pieces, as well as new features.
+
### Added
-- Slightly more information in the error dialog when videos fail to play
+- The concept of a `Queue`. Videos can now be queued to play one after another.
+ - Currently the queue is funcitonal, but no proper UI to support it, such as seeing the queue, clearing it, and so on.
+ - UI for the `Queue` will be introduced in a future version.
+ - Videos and playlists can be queued from the web app
+- Support for Playlists
+ - Home screen now shows both created and saved playlists
+ - Playlists have their own view to scroll through their videos
+ - Playlist videos play one after the other
+ - Playlists show up in search results
+- Continious scrolling of feed where supported (pagination)
+ - Subscriptions, Search, Playlists and Search based feeds (like `Funny` and `News` in the home screen)
+ - Not yet supported in the web app
+- Home screen placeholder items while items are loading
+- Settings screen has been rewritten with a better design
+- Access to public instances
+ - New UI to list public instances, or to specify a custom instance
+ - Testing system to make sure the instance is properly setup and usable
+- Playlet now tolerate certain missing configurations in Invidious (such as not configuring the domain)
+- Better error handling, error dialogs, with more information on what went wrong
+- Multiple Brighterscript plugins to support different functionalities of the app
+- Testing framework, and some tests
+- Performance imporvements
+ - Lazy loading where applicable
+ - Screens do not load until opened for the first time
+ - Not all feeds are loaded at once, feeds are loaded on demand while scrolling
+ - App profiled, some bottlenecks identified and fixed
+ - QR Code generation happens on background thread
+- More consistent logging, and the ability to retreive a log file of current run and the previous run
+- New `HttpClient` for making web requests, which supports `SendAndForget` and Cancellation, with a reduced `rendezvous`
+- Open API spec file describing available APIs in the Playlet Web Server
+
+### Changed
+
+- Lots of refactors and rewrites in general
+- The developer settings are now always visible in the web app
+- The web server is now decoupled from Playlet specific logic
+- When not logged in, authenticated feed (like user Subscriptions and Playlists) show a "Login to view X" message, with a QR Code that redirects to the login screen
+- [Breaking change] web apis changed a bit (for example the `/api/command` endpoint is removed) refer to the [Open API spec](docs/playlet-web-api.yml)
+
+### Removed
+
+- `roku-requests` package. A new HttpClient has been written to fit the need of Playlet instead. Some of the reasons to do this:
+ - It was causing a lot of `rendezvous`
+ - It has no real way to send a request without waiting for it to finish (send and forget)
+ - Some of the API was quirky (need to specify `parseJson: false` to ask it NOT to parse the response)
+ - It reads the response data, headers, error codes and etc even if they are not needed
+ - Excessive logging without a way to toggle it, or redirect it to a file
+- Some unused parts of the code (Like basic auth in the server, WebSockets, RegistryRouter, Kanji QR Code)
+ - These were unsued and/or feature flagged features. Things can be restored as needed.
+- The video player loading spinner when the video is minimized: this added too much hacky code with minimum value.
+
+### Fixed
+
+- Different issues caused by background tasks in the home screen
+- An issue caused by manipulating the loading spinner on the video player
+- An issue where the web server hangs if the payload contains unicode characters
## [0.10.3] - 2023-07-24
diff --git a/README.md b/README.md
index cbfd8b05..5b2bc6d2 100644
--- a/README.md
+++ b/README.md
@@ -25,8 +25,8 @@ Playlet is an unofficial Youtube client for Roku 📺
-|  |  |  |
-|-------------------------------------------------|-------------------------------------------------|-------------------------------------------------|
+|  |  |  |
+| ---------------------------------- | -------------------------------------- | ------------------------------------------ |
diff --git a/config/bsconfig.base.json b/config/bsconfig.base.json
index 22bf5b32..0421dd73 100644
--- a/config/bsconfig.base.json
+++ b/config/bsconfig.base.json
@@ -14,6 +14,12 @@
"regex": "\\.SetFocus\\(.+\\)",
"regexFlags": "ig",
"message": "SetFocus() is not allowed. Use NodeSetFocus() instead."
+ },
+ {
+ "code": "NO_OBSERVE_STRING_CALLBACK",
+ "regex": "\\.observeField(scoped)?\\s*\\(\\s*\"\\w+\"\\s*,\\s*\"\\w+\"\\s*\\)",
+ "regexFlags": "ig",
+ "message": "observeField(\"field\", \"callback\") is not allowed. Use observeField(\"field\", FuncName(callback)) instead."
}
],
"files": [
diff --git a/docs/README.md b/docs/README.md
index c44aa5fb..53e6472f 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -11,6 +11,7 @@ This document contains various kinds of information related to Playlet developme
- [RALE (Roku Advanced Layout Editor)](#rale-roku-advanced-layout-editor)
- [BrighterScript](#brighterscript)
- [BrighterScript Linter/Formatter](#brighterscript-linterformatter)
+ - [BrighterScript Plugins](#brighterscript-plugins)
- [Playlet App](#playlet-app)
- [Why separate between Playlet and Playlet Lib?](#why-separate-between-playlet-and-playlet-lib)
- [Playlet Lib](#playlet-lib)
@@ -23,6 +24,7 @@ This document contains various kinds of information related to Playlet developme
- [User preferences](#user-preferences)
- [Home page layout](#home-page-layout)
- [Playlet Web App](#playlet-web-app)
+- [Testing](#testing)
- [Svelte development](#svelte-development)
- [Tailwind/Daisy UI](#tailwinddaisy-ui)
- [API calls (proxy authenticated)](#api-calls-proxy-authenticated)
@@ -97,7 +99,7 @@ Well, if you do happen to use it, Playlet is configured to connect to RALE.
### BrighterScript
-[BrighterScript](https://github.com/rokucommunity/brighterscript) is a community driven programming language that compiles to BrightScript and has [useful features](https://github.com/rokucommunity/BrighterScript/blob/master/docs/readme.md). Playlet uses BrighterScript features a lot across the code base, and even implements a couple of BrighterScript plugins (More on that later).
+[BrighterScript](https://github.com/rokucommunity/brighterscript) is a community driven programming language that compiles to BrightScript and has [useful features](https://github.com/rokucommunity/BrighterScript/blob/master/docs/readme.md). Playlet uses BrighterScript features a lot across the code base, and even implements a few of BrighterScript plugins.
### BrighterScript Linter/Formatter
@@ -112,17 +114,21 @@ npm run lint
npm run lint:fix
```
+### BrighterScript Plugins
+
+See [Playlet Brighterscript Plugins](./plugins.md)
+
## Playlet App
-Playlet is split into two parts: `Playlet (the app)` and `Playlet Lib`.
+Playlet is split into two parts: `Playlet App` and `Playlet Lib`.
-Playlet (the app) is a regular Roku app, that uses a [ComponentLibrary](https://developer.roku.com/en-ca/docs/references/scenegraph/control-nodes/componentlibrary.md) to load the rest of the app from [Playlet Lib](#playlet-lib).
+`Playlet App` is a regular Roku app, that uses a [ComponentLibrary](https://developer.roku.com/en-ca/docs/references/scenegraph/control-nodes/componentlibrary.md) to load the rest of the app from [Playlet Lib](#playlet-lib).
-In a way, Playlet (the app) is a thin loader, while most of the logic lives in [Playlet Lib](#playlet-lib).
+In a way, `Playlet App` is a thin loader, while most of the logic lives in [Playlet Lib](#playlet-lib).
-Playlet app is responsible for a few things:
+`Playlet App` is responsible for a few things:
-- Load Playlet lib
+- Load `Playlet lib`
- By default, it tries to load the latest version from Github
- If that fails (for example, if Github was down), it fallsback to loading an embedded copy of Playlet Lib
- `if Github was down` -> yes, this has happened in the past, and it did not stop Playlet for working.
@@ -142,11 +148,12 @@ There are a few reasons we made this separation:
- It is simply easier to release: Releasing Playlet Lib on Github, and everyone receives the latest version immediately, is very conveninct and less of a hassle, than going through the Roku Channel store.
- I've had instances where I was trying to pass the certfication for Playlet to publish it. One of the criterias is to pass a some automated tests. But the tests were failing because their system could not connect to their Roku test devices (connection keeps timing out). My only option was to keep trying over and over until it worked.
- It might sound that Playlet Lib is just a workaround for the Roku Channel release process. But phrased differently, Roku Channel release process is not good enough of what we need for Playlet.
+- Canary builds: The latest version of Playlet can be tested as soon as it lands in the main branch. This is a great way to test newer features in production, without affecting the stability of the released version. Roku has the concept of "beta" channels, but they are more cumbersome.
- Enable forks. If for some reason someone wanted to use a fork of Playlet (for example, another folk had other features or bug fixes that this repo doesn't), they don't need to publish a complete new app. The url to load playlet is configurable, and can be changed through a simple web api. Allowing and enabling forks is what makes FOSS thrive.
## Playlet Lib
-Playlet Lib is a [ComponentLibrary](https://developer.roku.com/en-ca/docs/references/scenegraph/control-nodes/componentlibrary.md) that gets loaded by [Playlet App](#playlet-app). It containes pretty much all the logic needed to run the app.
+`Playlet Lib` is a [ComponentLibrary](https://developer.roku.com/en-ca/docs/references/scenegraph/control-nodes/componentlibrary.md) that gets loaded by [Playlet App](#playlet-app). It containes pretty much all the logic needed to run the app.
### WebServer
@@ -159,6 +166,10 @@ Playlet lib comes equipped with a web server that runs on port 8888 when the app
The web server runs on a continiously running [Task](https://developer.roku.com/en-ca/docs/references/scenegraph/control-nodes/task.md) and uses a middeware system to manage routes, serve static files, [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS), and more.
+The server's API enpoints are described through the Open API spec file [playlet-web-api.yml](./playlet-web-api.yml)
+
+Please note: while we would like to keep the API stable as much as possible, Playlet can't reasonbly maintain multiple versions of the API like traditional web apis, because it adds complexity and maintainablity burden on an app the runs in constrained environment. In short, we'll try not to break the API, but we might from time to time.
+
#### Debug endpoints
Additionally, the web server exposes Web APIs in debug mode to help with debugging. To name a few examples:
@@ -176,46 +187,12 @@ Since Component Libraries are simply zip files hosted at some https endpoint, Gi
### Dev library hosted by VS Code Extension
When in debug mode, Playlet lib is packaged and served locally on port 8080, and Playlet app would use it instead of the Playlet lib from Github. This is an important detail, because once you stop debugging in VS Code, the dev app on your Roku TV won't function anymore, with an error:
+
> Could not load Playlet component library from any of the following urls:
>
> - \[debug\] http://192.168.1.x:8080/playlet-lib.zip
-> Please restart Playlet.
-> If the problem persist, contact Playlet authors.
-
-### AsyncAwait Task Generator
-
-To implement functionality that runs in background threads, [Task](https://developer.roku.com/en-ca/docs/references/scenegraph/control-nodes/task.md)s must be used.
-
-Setting up a task involves lots of boilerplate: setting up the task in an xml file, defining inputs and outputs, code to listen for a task to finish, and so on.
-
-That's why there's a BrighterScript plugin that generates a task for a function with the attribute `@asynctask`.
-
-In a separate file, define the task function:
-
-```brighterscript
-@asynctask
-function MyBackgroundTask(input as object) as object
- myVar = input.myVar
-
- value = DoWork(myVar)
-
- return {
- value: value
- }
-end function
-```
-
-And use the function like so
-
-```brighterscript
-StartAsyncTask(MyBackgroundTask, {myVar: "some input"}, function(output as object) as void
- if output.success
- print(output.result.value)
- end if
-end function)
-```
-
-Although very useful, this pattern might not be the best for long running tasks (like the Web Server) or other tasks that require task reuse. This is because `StartAsyncTask` create a new instance of the task every time.
+> Please restart Playlet.
+> If the problem persist, contact Playlet authors.
### Feature flags
@@ -223,7 +200,7 @@ Playlet uses [bs_const](https://developer.roku.com/en-ca/docs/references/brights
### User preferences
-Playlet uses a json file that lists user preferences. It should be under [playlet-lib/src/config/preferences.json](/playlet-lib/src/config/preferences.json)
+Playlet uses a json file that lists user preferences. It should be under [playlet-lib/src/config/preferences.json5](/playlet-lib/src/config/preferences.json5)
This file defines the kind of preferences that users can change, such as autoplay, preferred quality, and so on.
This file is parsed at runtime and UI for the settings is generated. The same mechanism is used for Playlet and the Web App.
@@ -232,18 +209,35 @@ Additionally, the web server exposes the settings under `/api/preferences`, whic
### Home page layout
-When Playlet starts, it shows a video feed in the screen. Subscription, Trending videos, and so on.
+When Playlet starts, it shows a video feed on the screen. Subscription, Trending videos, and so on.
-The layout is defined under [playlet-lib/src/config/default_home_layout.json](/playlet-lib/src/config/default_home_layout.json).
+The layout is defined under [playlet-lib/src/config/default_home_layout.json5](/playlet-lib/src/config/default_home_layout.json5).
This could allow users to define custom layouts, so they can see what they find relevant in the home page. This can include Subscription, Trending, Popular videos, Search per keywords, or Playlists.
Additionally each feed has information on how it is fetched. For now, only Invidious can be data source, but other systems should be configured in the same way.
-Invidious API definitions are defined under [playlet-lib/src/config/invidious_video_api.json](/playlet-lib/src/config/invidious_video_api.json), and Playlet parses these at runtime and make the right API calls to fetch the data.
+Invidious API definitions are defined under [playlet-lib/src/config/invidious_video_api.json5](/playlet-lib/src/config/invidious_video_api.json5), and Playlet parses these at runtime and make the right API calls to fetch the data.
Finally, this layout system is what allows both the BrightScript app and the Web app to display the same homepage.
+## Testing
+
+Playlet uses [Rooibos](https://github.com/georgejecook/rooibos) for testing.
+
+Files following the pattern `*.spec.bs` are considered test files and are only included in test builds.
+Additionally, sometimes tests require additional setup (creating test components with multiple files). In this case, they can all be placed in a folder named `tests`. Any `tests` folder will only be included in test builds.
+
+Running the tests for both `playlet-app` and `playlet-lib` can be done with a single command:
+
+```bash
+npm run test
+```
+
+Which will build the test app, deploy, run tests and parse the output for results.
+
+Tests do not cover a lot right now, but at least there's a testing setup in place.
+
## Playlet Web App
Playlet comes with a web app built with [Svelte](https://svelte.dev/). The web app can be used to browse videos, search, cast videos to TV, and even change preferences.
@@ -293,15 +287,11 @@ For API calls that don't require authentication, the web app fetches data from I
### Developer settings
-To access developer settings, open the web app, and append the parameter `dev=1` to the url. Example:
+The developer settings are only visible through the web app. They are found at the buttom of the settings page.
-```bash
-http://192.168.1.107:8888/index.html?dev=1
-```
+For now, it allows you to point to a different Github release other than the default `latest`.
-This reveals an additional settings section in preferences. For now, it allows you to point to a different Github release other than the default `latest`.
-
-This is mostly useful to QA the `unstable` release in a "production" setting before making it available to all users as the official "latest" version.
+This is mostly useful to QA the `unstable` release in a "production" setting before making it available to all users as the official "latest" version. Consider the `unstable` version a [Canary release](https://en.wikipedia.org/wiki/Feature_toggle#Canary_release)
#### In case of a softlock
diff --git a/docs/plugins.md b/docs/plugins.md
new file mode 100644
index 00000000..ae652a0a
--- /dev/null
+++ b/docs/plugins.md
@@ -0,0 +1,460 @@
+# Playlet Brighterscript Plugins
+
+
+
+Playlet implements a few [Brighterscript Plugins](https://github.com/rokucommunity/brighterscript/blob/master/docs/plugins.md). The plugins inject themselves in the compilation process, allowing the modification of bs scripts, xml components, and even assets or the app manifest. Let's start with a simple one:
+
+## Json5/Yaml support
+
+This plugin allows us to include `jsonc`, `json5` and `yaml` files into the app as static assets. They are an alternative to plain `json`, which for instance, does not support comments. Additionally, this plugin minifies the `json` files.
+
+### Why
+
+Brightscript can only parse json natively using [ParseJson](https://developer.roku.com/en-ca/docs/references/brightscript/language/global-utility-functions.md#parsejsonjsonstring-as-string-flags---as-string-as-object). But it is nice to format config files as we please, include comments, and use the [Json5](https://json5.org/) format in general. Additionally, we get smaller files than the original assets.
+
+### How
+
+At the end of the build, the plugin scans for certain files (`jsonc`, `json`, `json5` and `yaml`), and converts them to plain json, while keeping the original file name. That way they are all parsable by the [ParseJson](https://developer.roku.com/en-ca/docs/references/brightscript/language/global-utility-functions.md#parsejsonjsonstring-as-string-flags---as-string-as-object) function, even though their original format is not compatible.
+
+## Manifest editing
+
+This plugin allows us to make modifications to the app manifest dynamically, mostly based on compiler flags.
+
+### Why
+
+A few reasons. For example:
+
+- If `--debug` flag is passed to the compiler, we want the `DEBUG` [compilation constant](https://developer.roku.com/en-ca/docs/references/brightscript/language/conditional-compilation.md) to be true
+- If `--test-mode` flag is passed, Turn `playlet-lib` into a standalone app instead of a component library, so we can run it as a standalone app for testing
+- Allows us to `DEBUG_HOST_IP_ADDRESS` with the local ip address of the debugging machine, so that `playlet-app` is able to find the `playlet-lib.zip` file that VSCode is serving during a debug session.
+
+### How
+
+We simply read the content of the original manifest, and modify it before the compilation starts. When the build is finished, we restore the source file of the manifest.
+
+## Validation
+
+This plugin allows us to add custom diagnostic errors messages to source code, to prevent using certain patterns of functions.
+
+### Why
+
+Let's see an example. consider this code:
+
+```brighterscript
+node.ObserveField("someField", "OnSomeFieldChanged")
+```
+
+This code makes it possible to make a typo in "OnSomeFieldChanged", and this callback ends up never firing.
+
+Let's suppose we want to eliminate this pattern and always use:
+
+```brighterscript
+node.ObserveField("someField", FuncName(OnSomeFieldChanged))
+```
+
+Where `FuncName` will determine the function name at runtime. This way, we will get a linter error if there's a typo, and adds a bit of safety.
+
+### How
+
+It's usually possible to create all types of validation plugins using the [brigherscript plugin APIs](https://github.com/rokucommunity/brighterscript/blob/master/docs/plugins.md). But this particular plugin is generic enough to allow us to define rules based on Regex. To define the rule in the previous example, we simply add this to the `bsconfig.json` file:
+
+```json
+"validation": [
+ {
+ "code": "NO_OBSERVE_STRING_CALLBACK",
+ "regex": "\\.observeField(scoped)?\\s*\\(\\s*\"\\w+\"\\s*,\\s*\"\\w+\"\\s*\\)",
+ "regexFlags": "ig",
+ "message": "observeField(\"field\", \"callback\") is not allowed. Use observeField(\"field\", FuncName(callback)) instead."
+ }
+],
+```
+
+The plugin will scan all the code for usage matching `"regex"` with the `"regexFlags"`. If found, it will error with the `"message"` and the error code `"code"`.
+
+The code allows us to ignore this diagnostics message, using the following:
+
+```brighterscript
+' bs:disable-next-line NO_OBSERVE_STRING_CALLBACK
+node.ObserveField("someField", "OnSomeFieldChanged")
+```
+
+## Includes
+
+This plugin allows us "include" different pieces of a component, enabling [Composition over inheritance](https://en.wikipedia.org/wiki/Composition_over_inheritance)
+
+### Why
+
+Consider a "behaviour" that we want in multiple components. For example:
+
+```xml
+
+
+
+
+
+
+
+```
+
+```brighterscript
+' Beep.bs
+function OnBeepSet()
+ print("BEEP BEEP!")
+end function
+```
+
+Imagine you want to enable many components to "Beep". You have a few options:
+
+- Inheritance: you make a base component that can "Beep", and extend it in different components. This can seem ok at first, but as your app scales, it becomes a burden to manage these inheritance relationships.
+- Copy the fields, and the `