Skip to content

Commit 6ec9626

Browse files
authored
Moved fonts, audio and libraries to common: volume as a zip file (#475)
* Moved `fonts`, `audio` and `libraries` to `common:` volume as a `zip` file * Fixed static analysis issues * Fixed linting issue
1 parent 10295a2 commit 6ec9626

38 files changed

+213
-364
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.vscode/
22
.idea/
33
browser/lib/
4+
browser/assets/
45
bin/
56
types/
67
node_modules*/

browser/fonts-alt/Apache License.txt

Lines changed: 0 additions & 201 deletions
This file was deleted.

browser/fonts-alt/Open Sans-Bold.ttf

-219 KB
Binary file not shown.
-208 KB
Binary file not shown.
-208 KB
Binary file not shown.
-212 KB
Binary file not shown.

browser/fonts-alt/Roboto Medium.ttf

-159 KB
Binary file not shown.

browser/fonts-alt/Roboto-Bold.ttf

-159 KB
Binary file not shown.
-160 KB
Binary file not shown.

browser/fonts-alt/Roboto-Italic.ttf

-158 KB
Binary file not shown.

browser/fonts-alt/Roboto-Regular.ttf

-159 KB
Binary file not shown.

browser/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ const customDeviceInfo = {
7474
developerId: "UniqueDeveloperId", // As in Roku devices, segregates Registry data
7575
locale: "en_US", // Used if app supports localization
7676
displayMode: "720p", // Supported modes: 480p (SD), 720p (HD) and 1080p (FHD)
77-
defaultFont: "Asap", // Default: "Asap" to use alternative fonts "Roboto" or "Open Sans"
78-
fontPath: "../fonts/", // change the fontPath to "../fonts-alt/"
7977
maxFps: 30, // Limited refresh rate to minimize issues with iOS/iPadOS
8078
appList: appList,
8179
};

config/webpack.zip.config.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const path = require("path");
2+
const CopyPlugin = require("copy-webpack-plugin");
3+
const ZipPlugin = require("zip-webpack-plugin");
4+
5+
module.exports = (env) => {
6+
return {
7+
entry: {},
8+
mode: "production",
9+
output: {
10+
path: path.resolve(__dirname, `../out/common_zip/`),
11+
publicPath: "/",
12+
},
13+
plugins: [
14+
new CopyPlugin({
15+
patterns: [
16+
{ from: "src/core/common/**", to: "./" },
17+
],
18+
}),
19+
new ZipPlugin({
20+
path: "../../browser/assets/",
21+
filename: `common.zip`,
22+
extension: "zip",
23+
zipOptions: {
24+
forceZip64Format: false,
25+
},
26+
exclude: [/\.csv$/],
27+
pathMapper: function (assetPath) {
28+
return assetPath.replace("src/core/common/", "");
29+
},
30+
}),
31+
],
32+
};
33+
};

docs/customization.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ const deviceInfo = {
1919
captionLanguage: "eng",
2020
clockFormat: "12h",
2121
displayMode: "720p", // Supported modes: 480p (SD), 720p (HD) and 1080p (FHD)
22-
defaultFont: "Asap",
23-
fontPath: "../fonts/",
2422
maxSimulStreams: 2, // Max number of audio resource streams (1, 2 or 3)
2523
customFeatures: [], // String array with custom features (see below)
2624
localIps: ["eth1,127.0.0.1"], // In a Browser isn't possible to get a real IP, populate it on NodeJS or Electron.

package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@
3333
"brs-cli": "./bin/brs.cli.js"
3434
},
3535
"scripts": {
36-
"build": "webpack --config ./config/webpack.config.js --env development && webpack --config ./config/webpack.cli.config.js --env development",
36+
"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",
3737
"build:libs": "webpack --config ./config/webpack.config.js --env development",
3838
"build:cli": "webpack --config ./config/webpack.cli.config.js --env development",
39-
"release": "webpack --config ./config/webpack.config.js --env production && webpack --config ./config/webpack.cli.config.js --env production",
39+
"build:zip": "webpack --config ./config/webpack.zip.config.js",
40+
"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",
4041
"start": "webpack serve --open --config ./config/webpack.config.js",
4142
"stats": "webpack-bundle-analyzer ./browser/lib/stats.json",
4243
"stats:api": "webpack-bundle-analyzer ./browser/lib/stats-api.json",
@@ -48,8 +49,7 @@
4849
"prepublishOnly": "npm-run-all --serial clean lint prettier release"
4950
},
5051
"files": [
51-
"browser/audio/",
52-
"browser/fonts/",
52+
"browser/assets/",
5353
"browser/lib/brs.worker.js",
5454
"browser/lib/*.LICENSE.txt",
5555
"bin/",
@@ -121,6 +121,7 @@
121121
"@typescript-eslint/eslint-plugin": "^8.17.0",
122122
"@typescript-eslint/parser": "^8.17.0",
123123
"buffer": "^6.0.3",
124+
"copy-webpack-plugin": "^12.0.2",
124125
"eslint": "^8.57.0",
125126
"eslint-config-prettier": "^9.1.0",
126127
"eslint-plugin-import": "^2.29.1",
@@ -141,7 +142,8 @@
141142
"webpack-cli": "^5.0.1",
142143
"webpack-dev-server": "^4.15.1",
143144
"webpack-shebang-plugin": "^1.1.8",
144-
"webpack-stats-plugin": "^1.1.3"
145+
"webpack-stats-plugin": "^1.1.3",
146+
"zip-webpack-plugin": "^4.0.3"
145147
},
146148
"jest": {
147149
"testEnvironment": "node"

src/api/index.ts

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import {
5454
subscribeSound,
5555
switchSoundState,
5656
handleSoundEvent,
57+
playHomeSound,
5758
} from "./sound";
5859
import {
5960
addVideo,
@@ -72,7 +73,6 @@ import packageInfo from "../../package.json";
7273
// Interpreter Library
7374
const brsWrkLib = getWorkerLibPath();
7475
let brsWorker: Worker;
75-
let homeWav: Howl;
7676

7777
// Package API
7878
export {
@@ -169,13 +169,6 @@ export function initialize(customDeviceInfo?: Partial<DeviceInfo>, options: any
169169
}
170170
sharedArray = new Int32Array(sharedBuffer);
171171
resetArray();
172-
// Setup Home Sound Effect
173-
if (homeWav === undefined) {
174-
homeWav = new Howl({ src: ["./audio/select.wav"] });
175-
homeWav.on("play", function () {
176-
terminate(AppExitReason.FINISHED);
177-
});
178-
}
179172
// Initialize Display and Control modules
180173
initDisplayModule(deviceData.displayMode, showStats);
181174
initControlModule(sharedArray, options);
@@ -197,7 +190,7 @@ export function initialize(customDeviceInfo?: Partial<DeviceInfo>, options: any
197190
subscribeControl("api", (event: string, data: any) => {
198191
if (event === "home") {
199192
if (currentApp.running) {
200-
homeWav.play();
193+
playHomeSound();
201194
}
202195
} else if (event === "poweroff") {
203196
if (currentApp.running) {
@@ -215,6 +208,8 @@ export function initialize(customDeviceInfo?: Partial<DeviceInfo>, options: any
215208
subscribeSound("api", (event: string, data: any) => {
216209
if (["error", "warning"].includes(event)) {
217210
apiException(event, data);
211+
} else if (event === "home") {
212+
terminate(AppExitReason.FINISHED);
218213
}
219214
});
220215
subscribeVideo("api", (event: string, data: any) => {
@@ -244,6 +239,7 @@ export function initialize(customDeviceInfo?: Partial<DeviceInfo>, options: any
244239
brsWorker = new Worker(brsWrkLib);
245240
brsWorker.addEventListener("message", workerCallback);
246241
brsWorker.postMessage("getVersion");
242+
updateDeviceAssets();
247243
}
248244

249245
// Observers Handling
@@ -409,7 +405,7 @@ function resetWorker() {
409405
brsWorker.removeEventListener("message", workerCallback);
410406
brsWorker.terminate();
411407
resetArray();
412-
resetSounds();
408+
resetSounds(deviceData.assets);
413409
resetVideo();
414410
}
415411

@@ -467,6 +463,28 @@ function runApp(payload: AppPayload) {
467463
}
468464
}
469465

466+
// Load Device Assets
467+
function updateDeviceAssets() {
468+
if (deviceData.assets.byteLength) {
469+
return;
470+
}
471+
fetch("./assets/common.zip")
472+
.then(async function (response) {
473+
if (response.status === 200 || response.status === 0) {
474+
return response.blob().then(function (zipBlob) {
475+
zipBlob.arrayBuffer().then(function (zipData) {
476+
deviceData.assets = zipData;
477+
});
478+
});
479+
} else {
480+
return Promise.reject(new Error(response.statusText));
481+
}
482+
})
483+
.catch((err) => {
484+
console.error(`Error attempting to load common.zip: ${err.message} (${err.name})`);
485+
});
486+
}
487+
470488
// Update App in the App List from the Current App object
471489
export function updateAppList() {
472490
if (deviceData.appList?.length) {

0 commit comments

Comments
 (0)