Skip to content

Commit

Permalink
Moved fonts, audio and libraries to common: volume as a zip
Browse files Browse the repository at this point in the history
… file (#475)

* Moved `fonts`, `audio` and `libraries` to `common:` volume as a `zip` file

* Fixed static analysis issues

* Fixed linting issue
  • Loading branch information
lvcabral authored Feb 19, 2025
1 parent 10295a2 commit 6ec9626
Show file tree
Hide file tree
Showing 38 changed files with 213 additions and 364 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.vscode/
.idea/
browser/lib/
browser/assets/
bin/
types/
node_modules*/
Expand Down
201 changes: 0 additions & 201 deletions browser/fonts-alt/Apache License.txt

This file was deleted.

Binary file removed browser/fonts-alt/Open Sans-Bold.ttf
Binary file not shown.
Binary file removed browser/fonts-alt/Open Sans-BoldItalic.ttf
Binary file not shown.
Binary file removed browser/fonts-alt/Open Sans-Italic.ttf
Binary file not shown.
Binary file removed browser/fonts-alt/Open Sans-Regular.ttf
Binary file not shown.
Binary file removed browser/fonts-alt/Roboto Medium.ttf
Binary file not shown.
Binary file removed browser/fonts-alt/Roboto-Bold.ttf
Binary file not shown.
Binary file removed browser/fonts-alt/Roboto-BoldItalic.ttf
Binary file not shown.
Binary file removed browser/fonts-alt/Roboto-Italic.ttf
Binary file not shown.
Binary file removed browser/fonts-alt/Roboto-Regular.ttf
Binary file not shown.
2 changes: 0 additions & 2 deletions browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ const customDeviceInfo = {
developerId: "UniqueDeveloperId", // As in Roku devices, segregates Registry data
locale: "en_US", // Used if app supports localization
displayMode: "720p", // Supported modes: 480p (SD), 720p (HD) and 1080p (FHD)
defaultFont: "Asap", // Default: "Asap" to use alternative fonts "Roboto" or "Open Sans"
fontPath: "../fonts/", // change the fontPath to "../fonts-alt/"
maxFps: 30, // Limited refresh rate to minimize issues with iOS/iPadOS
appList: appList,
};
Expand Down
33 changes: 33 additions & 0 deletions config/webpack.zip.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const path = require("path");
const CopyPlugin = require("copy-webpack-plugin");
const ZipPlugin = require("zip-webpack-plugin");

module.exports = (env) => {
return {
entry: {},
mode: "production",
output: {
path: path.resolve(__dirname, `../out/common_zip/`),
publicPath: "/",
},
plugins: [
new CopyPlugin({
patterns: [
{ from: "src/core/common/**", to: "./" },
],
}),
new ZipPlugin({
path: "../../browser/assets/",
filename: `common.zip`,
extension: "zip",
zipOptions: {
forceZip64Format: false,
},
exclude: [/\.csv$/],
pathMapper: function (assetPath) {
return assetPath.replace("src/core/common/", "");
},
}),
],
};
};
2 changes: 0 additions & 2 deletions docs/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ const deviceInfo = {
captionLanguage: "eng",
clockFormat: "12h",
displayMode: "720p", // Supported modes: 480p (SD), 720p (HD) and 1080p (FHD)
defaultFont: "Asap",
fontPath: "../fonts/",
maxSimulStreams: 2, // Max number of audio resource streams (1, 2 or 3)
customFeatures: [], // String array with custom features (see below)
localIps: ["eth1,127.0.0.1"], // In a Browser isn't possible to get a real IP, populate it on NodeJS or Electron.
Expand Down
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@
"brs-cli": "./bin/brs.cli.js"
},
"scripts": {
"build": "webpack --config ./config/webpack.config.js --env development && webpack --config ./config/webpack.cli.config.js --env development",
"build": "webpack --config ./config/webpack.config.js --env development && webpack --config ./config/webpack.cli.config.js --env development && webpack --config ./config/webpack.zip.config.js",
"build:libs": "webpack --config ./config/webpack.config.js --env development",
"build:cli": "webpack --config ./config/webpack.cli.config.js --env development",
"release": "webpack --config ./config/webpack.config.js --env production && webpack --config ./config/webpack.cli.config.js --env production",
"build:zip": "webpack --config ./config/webpack.zip.config.js",
"release": "webpack --config ./config/webpack.config.js --env production && webpack --config ./config/webpack.cli.config.js --env production && webpack --config ./config/webpack.zip.config.js",
"start": "webpack serve --open --config ./config/webpack.config.js",
"stats": "webpack-bundle-analyzer ./browser/lib/stats.json",
"stats:api": "webpack-bundle-analyzer ./browser/lib/stats-api.json",
Expand All @@ -48,8 +49,7 @@
"prepublishOnly": "npm-run-all --serial clean lint prettier release"
},
"files": [
"browser/audio/",
"browser/fonts/",
"browser/assets/",
"browser/lib/brs.worker.js",
"browser/lib/*.LICENSE.txt",
"bin/",
Expand Down Expand Up @@ -121,6 +121,7 @@
"@typescript-eslint/eslint-plugin": "^8.17.0",
"@typescript-eslint/parser": "^8.17.0",
"buffer": "^6.0.3",
"copy-webpack-plugin": "^12.0.2",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
Expand All @@ -141,7 +142,8 @@
"webpack-cli": "^5.0.1",
"webpack-dev-server": "^4.15.1",
"webpack-shebang-plugin": "^1.1.8",
"webpack-stats-plugin": "^1.1.3"
"webpack-stats-plugin": "^1.1.3",
"zip-webpack-plugin": "^4.0.3"
},
"jest": {
"testEnvironment": "node"
Expand Down
38 changes: 28 additions & 10 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import {
subscribeSound,
switchSoundState,
handleSoundEvent,
playHomeSound,
} from "./sound";
import {
addVideo,
Expand All @@ -72,7 +73,6 @@ import packageInfo from "../../package.json";
// Interpreter Library
const brsWrkLib = getWorkerLibPath();
let brsWorker: Worker;
let homeWav: Howl;

// Package API
export {
Expand Down Expand Up @@ -169,13 +169,6 @@ export function initialize(customDeviceInfo?: Partial<DeviceInfo>, options: any
}
sharedArray = new Int32Array(sharedBuffer);
resetArray();
// Setup Home Sound Effect
if (homeWav === undefined) {
homeWav = new Howl({ src: ["./audio/select.wav"] });
homeWav.on("play", function () {
terminate(AppExitReason.FINISHED);
});
}
// Initialize Display and Control modules
initDisplayModule(deviceData.displayMode, showStats);
initControlModule(sharedArray, options);
Expand All @@ -197,7 +190,7 @@ export function initialize(customDeviceInfo?: Partial<DeviceInfo>, options: any
subscribeControl("api", (event: string, data: any) => {
if (event === "home") {
if (currentApp.running) {
homeWav.play();
playHomeSound();
}
} else if (event === "poweroff") {
if (currentApp.running) {
Expand All @@ -215,6 +208,8 @@ export function initialize(customDeviceInfo?: Partial<DeviceInfo>, options: any
subscribeSound("api", (event: string, data: any) => {
if (["error", "warning"].includes(event)) {
apiException(event, data);
} else if (event === "home") {
terminate(AppExitReason.FINISHED);
}
});
subscribeVideo("api", (event: string, data: any) => {
Expand Down Expand Up @@ -244,6 +239,7 @@ export function initialize(customDeviceInfo?: Partial<DeviceInfo>, options: any
brsWorker = new Worker(brsWrkLib);
brsWorker.addEventListener("message", workerCallback);
brsWorker.postMessage("getVersion");
updateDeviceAssets();
}

// Observers Handling
Expand Down Expand Up @@ -409,7 +405,7 @@ function resetWorker() {
brsWorker.removeEventListener("message", workerCallback);
brsWorker.terminate();
resetArray();
resetSounds();
resetSounds(deviceData.assets);
resetVideo();
}

Expand Down Expand Up @@ -467,6 +463,28 @@ function runApp(payload: AppPayload) {
}
}

// Load Device Assets
function updateDeviceAssets() {
if (deviceData.assets.byteLength) {
return;
}
fetch("./assets/common.zip")
.then(async function (response) {
if (response.status === 200 || response.status === 0) {
return response.blob().then(function (zipBlob) {
zipBlob.arrayBuffer().then(function (zipData) {
deviceData.assets = zipData;
});
});
} else {
return Promise.reject(new Error(response.statusText));
}
})
.catch((err) => {
console.error(`Error attempting to load common.zip: ${err.message} (${err.name})`);
});
}

// Update App in the App List from the Current App object
export function updateAppList() {
if (deviceData.appList?.length) {
Expand Down
Loading

0 comments on commit 6ec9626

Please sign in to comment.