Add prettier and re-format .js files

This commit is contained in:
hensm
2021-08-31 07:59:58 +01:00
parent 9339b1a306
commit d6ca1325dc
38 changed files with 908 additions and 13254 deletions

5
.prettierrc.json Normal file
View File

@@ -0,0 +1,5 @@
{
"arrowParens": "avoid",
"tabWidth": 4,
"trailingComma": "none"
}

View File

@@ -13,40 +13,36 @@ const { spawnSync } = require("child_process");
const meta = require("../package.json");
const paths = require("./lib/paths");
const { author
, homepage } = require("../../package.json");
const { author, homepage } = require("../../package.json");
const EXTENSION_ID = "fx_cast@matt.tf";
// Command line args
const argv = minimist(process.argv.slice(2), {
boolean: [ "usePkg", "package", "skipNativeBuilds" ]
, string: [ "arch", "packageType" ]
, default: {
arch: os.arch()
, package: false
boolean: ["usePkg", "package", "skipNativeBuilds"],
string: ["arch", "packageType"],
default: {
arch: os.arch(),
package: false,
// Linux package type (deb/rpm)
, packageType: "deb"
, skipNativeBuilds: false
packageType: "deb",
skipNativeBuilds: false
}
});
const supportedTargets = [
"win-x64"
, "win-x86"
, "macos-x64"
, "macos-arm64"
, "linux-x64"
"win-x64",
"win-x86",
"macos-x64",
"macos-arm64",
"linux-x64"
];
const supportedPlatforms = [];
const supportedArchs = [];
for (const target of supportedTargets) {
const [ platform, arch ] = target.split("-");
const [platform, arch] = target.split("-");
supportedPlatforms.push(platform);
supportedArchs.push(arch);
@@ -61,14 +57,13 @@ if (!supportedArchs.includes(argv.arch)) {
process.exit(1);
}
const ROOT_PATH = path.join(__dirname, "..");
const SRC_PATH = path.join(ROOT_PATH, "src");
const BUILD_PATH = path.join(ROOT_PATH, "build");
const spawnOptions = {
shell: true
, stdio: [ process.stdin, process.stdout, process.stderr ]
shell: true,
stdio: [process.stdin, process.stdout, process.stderr]
};
/**
@@ -80,26 +75,29 @@ fs.removeSync(paths.DIST_PATH, { recursive: true });
fs.ensureDirSync(BUILD_PATH);
fs.ensureDirSync(paths.DIST_PATH, { recursive: true });
const MDNS_BINDING_PATH = path.join(
__dirname, "../node_modules/mdns/build/Release/");
__dirname,
"../node_modules/mdns/build/Release/"
);
const MDNS_BINDING_NAME = "dns_sd_bindings.node";
async function build () {
async function build() {
// Run tsc
spawnSync(`tsc --project ${ROOT_PATH} \
--outDir ${BUILD_PATH}`
, spawnOptions);
spawnSync(
`tsc --project ${ROOT_PATH}
--outDir ${BUILD_PATH}`,
spawnOptions
);
/**
* Native app manifest
* https://mdn.io/Native_manifests#Native_messaging_manifests
*/
const manifest = {
"name": meta.__applicationName
, "description": ""
, "type": "stdio"
, "allowed_extensions": [ EXTENSION_ID ]
name: meta.__applicationName,
description: "",
type: "stdio",
allowed_extensions: [EXTENSION_ID]
};
/**
@@ -109,63 +107,80 @@ async function build () {
if (argv.package || argv.usePkg) {
// Need a minimal package.json for pkg.
const pkgManifest = {
bin: "main.js"
, pkg: {
bin: "main.js",
pkg: {
/**
* Workaround for pkg asset detection
* https://github.com/thibauts/node-castv2/issues/46
*/
"assets": "../../node_modules/castv2/lib/cast_channel.proto"
assets: "../../node_modules/castv2/lib/cast_channel.proto"
}
};
const executableName = paths.getExecutableName(process.platform);
const executablePath = paths.getExecutablePath(process.platform, argv.arch);
const executablePath = paths.getExecutablePath(
process.platform,
argv.arch
);
// Write pkg manifest
fs.writeFileSync(path.join(BUILD_PATH, "src/package.json")
, JSON.stringify(pkgManifest))
fs.writeFileSync(
path.join(BUILD_PATH, "src/package.json"),
JSON.stringify(pkgManifest)
);
// Run pkg to create a single executable
await pkg.exec([
path.join(BUILD_PATH, "src")
, "--target", `node12-${paths.pkgPlatformMap[process.platform]}-${argv.arch}`
, "--output", path.join(BUILD_PATH, executableName)
path.join(BUILD_PATH, "src"),
"--target",
`node12-${paths.pkgPlatformMap[process.platform]}-${argv.arch}`,
"--output",
path.join(BUILD_PATH, executableName)
]);
fs.copySync(path.join(MDNS_BINDING_PATH, MDNS_BINDING_NAME)
, path.join(BUILD_PATH, MDNS_BINDING_NAME));
fs.copySync(
path.join(MDNS_BINDING_PATH, MDNS_BINDING_NAME),
path.join(BUILD_PATH, MDNS_BINDING_NAME)
);
fs.removeSync(path.join(BUILD_PATH, "src"));
manifest.path = !argv.package && argv.usePkg
? path.join(paths.DIST_PATH, executableName)
: path.join(executablePath, executableName);
manifest.path =
!argv.package && argv.usePkg
? path.join(paths.DIST_PATH, executableName)
: path.join(executablePath, executableName);
} else {
let launcherPath = path.join(BUILD_PATH
, meta.__applicationExecutableName);
let launcherPath = path.join(
BUILD_PATH,
meta.__applicationExecutableName
);
const modulesDir = path.join(ROOT_PATH, "node_modules");
// Write launcher script
switch (process.platform) {
case "win32": {
launcherPath += ".bat";
fs.writeFileSync(launcherPath,
`@echo off
fs.writeFileSync(
launcherPath,
`@echo off
setlocal
set NODE_PATH=${modulesDir}
node %~dp0src\\main.js --__name %~n0%~x0 %*
endlocal
`);
`
);
break;
}
case "linux":
case "darwin": {
launcherPath += ".sh";
fs.writeFileSync(launcherPath,
`#!/usr/bin/env sh
fs.writeFileSync(
launcherPath,
`#!/usr/bin/env sh
NODE_PATH="${modulesDir}" node $(dirname $0)/src/main.js --__name $(basename $0) "$@"
`);
`
);
break;
}
}
@@ -173,11 +188,11 @@ NODE_PATH="${modulesDir}" node $(dirname $0)/src/main.js --__name $(basename $0)
manifest.path = path.join(paths.DIST_PATH, path.basename(launcherPath));
}
// Write app manifest
fs.writeFileSync(path.join(BUILD_PATH, paths.MANIFEST_NAME)
, JSON.stringify(manifest, null, 4));
fs.writeFileSync(
path.join(BUILD_PATH, paths.MANIFEST_NAME),
JSON.stringify(manifest, null, 4)
);
// Ensure file permissions are correct
for (const file of fs.readdirSync(BUILD_PATH)) {
@@ -194,19 +209,20 @@ NODE_PATH="${modulesDir}" node $(dirname $0)/src/main.js --__name $(basename $0)
if (installerName) {
// Move installer to dist
fs.moveSync(
path.join(BUILD_PATH, installerName)
, path.join(paths.DIST_PATH, path.basename(installerName))
, { overwrite: true });
path.join(BUILD_PATH, installerName),
path.join(paths.DIST_PATH, path.basename(installerName)),
{ overwrite: true }
);
}
} else {
// Move tsc output and launcher to dist
fs.moveSync(BUILD_PATH, paths.DIST_PATH, { overwrite: true });
/*
spawnSync("npm install --production", {
...spawnOptions
, cwd: paths.DIST_PATH
});
*/
spawnSync("npm install --production", {
...spawnOptions
, cwd: paths.DIST_PATH
});
*/
}
// Remove build directory
@@ -217,31 +233,34 @@ NODE_PATH="${modulesDir}" node $(dirname $0)/src/main.js --__name $(basename $0)
* Takes a platform and returns the path of the created
* installer package.
*/
async function packageApp (platform, arch) {
async function packageApp(platform, arch) {
const packageFunctionArgs = [
arch
arch,
// platformExecutableName
, paths.getExecutableName(platform, arch)
paths.getExecutableName(platform, arch),
// platformExecutablePath
, paths.getExecutablePath(platform, arch)
paths.getExecutablePath(platform, arch),
// platformManifestPath
, paths.getManifestPath(platform, arch, argv.packageType)
paths.getManifestPath(platform, arch, argv.packageType)
];
switch (platform) {
case "win32": return packageWin32(...packageFunctionArgs);
case "darwin": return packageDarwin(...packageFunctionArgs);
case "win32":
return packageWin32(...packageFunctionArgs);
case "darwin":
return packageDarwin(...packageFunctionArgs);
case "linux": {
switch (argv.packageType) {
case "deb": return packageLinuxDeb(...packageFunctionArgs);
case "rpm": return packageLinuxRpm(...packageFunctionArgs);
case "deb":
return packageLinuxDeb(...packageFunctionArgs);
case "rpm":
return packageLinuxRpm(...packageFunctionArgs);
}
break;
}
default: {
console.error("Unsupported target platform");
process.exit(1);
@@ -262,14 +281,13 @@ async function packageApp (platform, arch) {
* Requires the pkgbuild and productbuild command line
* utilities. Only possible on macOS.
*/
function packageDarwin (
arch
, platformExecutableName
, platformExecutablePath
, platformManifestPath) {
const outputName = `${meta.__applicationName}-${
meta.__applicationVersion}-${arch}.pkg`;
function packageDarwin(
arch,
platformExecutableName,
platformExecutablePath,
platformManifestPath
) {
const outputName = `${meta.__applicationName}-${meta.__applicationVersion}-${arch}.pkg`;
const componentName = `${meta.__applicationName}_component.pkg`;
const packagingDir = path.join(__dirname, "../packaging/mac/");
@@ -285,30 +303,35 @@ function packageDarwin (
fs.ensureDirSync(rootManifestPath, { recursive: true });
// Move files to root
fs.moveSync(path.join(BUILD_PATH, platformExecutableName)
, path.join(rootExecutablePath, platformExecutableName));
fs.moveSync(path.join(BUILD_PATH, MDNS_BINDING_NAME)
, path.join(rootExecutablePath, MDNS_BINDING_NAME));
fs.moveSync(path.join(BUILD_PATH, paths.MANIFEST_NAME)
, path.join(rootManifestPath, paths.MANIFEST_NAME));
fs.moveSync(
path.join(BUILD_PATH, platformExecutableName),
path.join(rootExecutablePath, platformExecutableName)
);
fs.moveSync(
path.join(BUILD_PATH, MDNS_BINDING_NAME),
path.join(rootExecutablePath, MDNS_BINDING_NAME)
);
fs.moveSync(
path.join(BUILD_PATH, paths.MANIFEST_NAME),
path.join(rootManifestPath, paths.MANIFEST_NAME)
);
// Copy static files to be processed
fs.copySync(packagingDir, packagingOutputDir);
const view = {
applicationName: meta.__applicationName
, manifestName: paths.MANIFEST_NAME
, componentName
, packageId: `tf.matt.${meta.__applicationName}`
, executablePath: platformExecutablePath
, manifestPath: platformManifestPath
applicationName: meta.__applicationName,
manifestName: paths.MANIFEST_NAME,
componentName,
packageId: `tf.matt.${meta.__applicationName}`,
executablePath: platformExecutablePath,
manifestPath: platformManifestPath
};
// Template paths
const templatePaths = [
path.join(packagingOutputDir, "scripts/postinstall")
, path.join(packagingOutputDir, "distribution.xml")
path.join(packagingOutputDir, "scripts/postinstall"),
path.join(packagingOutputDir, "distribution.xml")
];
// Do templating on static files
@@ -317,25 +340,26 @@ function packageDarwin (
fs.writeFileSync(templatePath, mustache.render(templateContent, view));
}
// Build component package
spawnSync(`
pkgbuild --root ${rootPath} \
--identifier "tf.matt.${meta.__applicationName}" \
--version "${meta.__applicationVersion}" \
--scripts ${path.join(packagingOutputDir, "scripts")} \
${path.join(BUILD_PATH, componentName)}`
, spawnOptions);
spawnSync(
`pkgbuild --root ${rootPath} \
--identifier "tf.matt.${meta.__applicationName}" \
--version "${meta.__applicationVersion}" \
--scripts ${path.join(packagingOutputDir, "scripts")} \
${path.join(BUILD_PATH, componentName)}`,
spawnOptions
);
// Distribution XML file
const distFilePath = path.join(packagingOutputDir, "distribution.xml");
// Build installer package
spawnSync(`
productbuild --distribution ${distFilePath} \
--package-path ${BUILD_PATH} \
${path.join(BUILD_PATH, outputName)}`
, spawnOptions);
spawnSync(
`productbuild --distribution ${distFilePath} \
--package-path ${BUILD_PATH} \
${path.join(BUILD_PATH, outputName)}`,
spawnOptions
);
return outputName;
}
@@ -349,14 +373,13 @@ function packageDarwin (
* package from root.
* Requires the dpkg-deb command line utility.
*/
function packageLinuxDeb (
arch
, platformExecutableName
, platformExecutablePath
, platformManifestPath) {
const outputName = `${meta.__applicationName}-${
meta.__applicationVersion}-${arch}.deb`;
function packageLinuxDeb(
arch,
platformExecutableName,
platformExecutablePath,
platformManifestPath
) {
const outputName = `${meta.__applicationName}-${meta.__applicationVersion}-${arch}.deb`;
// Create root
const rootPath = path.join(BUILD_PATH, "root");
@@ -367,12 +390,18 @@ function packageLinuxDeb (
fs.ensureDirSync(rootManifestPath, { recursive: true });
// Move files to root
fs.moveSync(path.join(BUILD_PATH, platformExecutableName)
, path.join(rootExecutablePath, platformExecutableName));
fs.moveSync(path.join(BUILD_PATH, MDNS_BINDING_NAME)
, path.join(rootExecutablePath, MDNS_BINDING_NAME));
fs.moveSync(path.join(BUILD_PATH, paths.MANIFEST_NAME)
, path.join(rootManifestPath, paths.MANIFEST_NAME));
fs.moveSync(
path.join(BUILD_PATH, platformExecutableName),
path.join(rootExecutablePath, platformExecutableName)
);
fs.moveSync(
path.join(BUILD_PATH, MDNS_BINDING_NAME),
path.join(rootExecutablePath, MDNS_BINDING_NAME)
);
fs.moveSync(
path.join(BUILD_PATH, paths.MANIFEST_NAME),
path.join(rootManifestPath, paths.MANIFEST_NAME)
);
const controlDir = path.join(__dirname, "../packaging/linux/deb/DEBIAN/");
const controlOutputDir = path.join(rootPath, path.basename(controlDir));
@@ -383,23 +412,24 @@ function packageLinuxDeb (
const view = {
// Debian package names can't contain underscores
packageName: meta.__applicationName.replace(/_/g, "-")
, applicationName: meta.__applicationName
, applicationVersion: meta.__applicationVersion
, author
packageName: meta.__applicationName.replace(/_/g, "-"),
applicationName: meta.__applicationName,
applicationVersion: meta.__applicationVersion,
author
};
// Do templating on control file
fs.writeFileSync(controlFilePath
, mustache.render(
fs.readFileSync(controlFilePath).toString()
, view));
fs.writeFileSync(
controlFilePath,
mustache.render(fs.readFileSync(controlFilePath).toString(), view)
);
// Build .deb package
spawnSync(`
dpkg-deb --build ${rootPath} \
${path.join(BUILD_PATH, outputName)}`
, spawnOptions);
spawnSync(
`dpkg-deb --build ${rootPath} \
${path.join(BUILD_PATH, outputName)}`,
spawnOptions
);
return outputName;
}
@@ -411,48 +441,47 @@ function packageLinuxDeb (
* (packaging/linux/rpm/package.spec) to build the package.
* Requires the rpmbuild command line utility.
*/
function packageLinuxRpm (
arch
, platformExecutableName
, platformExecutablePath
, platformManifestPath) {
function packageLinuxRpm(
arch,
platformExecutableName,
platformExecutablePath,
platformManifestPath
) {
const outputName = `${meta.__applicationName}-${meta.__applicationVersion}-${arch}.rpm`;
const outputName = `${meta.__applicationName}-${
meta.__applicationVersion}-${arch}.rpm`;
const specPath = path.join(__dirname
, "../packaging/linux/rpm/package.spec");
const specPath = path.join(
__dirname,
"../packaging/linux/rpm/package.spec"
);
const specOutputPath = path.join(BUILD_PATH, path.basename(specPath));
const view = {
packageName: meta.__applicationName
, applicationName: meta.__applicationName
, applicationVersion: meta.__applicationVersion
, executablePath: platformExecutablePath
, manifestPath: platformManifestPath
, executableName: platformExecutableName
, manifestName: paths.MANIFEST_NAME
, bindingName: MDNS_BINDING_NAME
packageName: meta.__applicationName,
applicationName: meta.__applicationName,
applicationVersion: meta.__applicationVersion,
executablePath: platformExecutablePath,
manifestPath: platformManifestPath,
executableName: platformExecutableName,
manifestName: paths.MANIFEST_NAME,
bindingName: MDNS_BINDING_NAME
};
fs.writeFileSync(specOutputPath
, mustache.render(
fs.readFileSync(specPath).toString()
, view));
fs.writeFileSync(
specOutputPath,
mustache.render(fs.readFileSync(specPath).toString(), view)
);
const rpmArchMap = {
"x86": "i386"
, "x64": "x86_64"
};
const rpmArchMap = { x86: "i386", x64: "x86_64" };
spawnSync(`
rpmbuild -bb ${specOutputPath} \
--define "_distdir ${BUILD_PATH}" \
--define "_rpmdir ${BUILD_PATH}" \
--define "_rpmfilename ${outputName}" \
--target=${rpmArchMap[arch]}-linux`
, spawnOptions);
spawnSync(
`rpmbuild -bb ${specOutputPath} \
--define "_distdir ${BUILD_PATH}" \
--define "_rpmdir ${BUILD_PATH}" \
--define "_rpmfilename ${outputName}" \
--target=${rpmArchMap[arch]}-linux`,
spawnOptions
);
return outputName;
}
@@ -464,47 +493,44 @@ function packageLinuxRpm (
* script (packaging/win/installer.nsi). Requires the
* makensis command line utility.
*/
function packageWin32 (
arch
, platformExecutableName
, platformExecutablePath
, platformManifestPath) {
const outputName = `${meta.__applicationName}-${
meta.__applicationVersion}-${arch}.exe`;
function packageWin32(
arch,
platformExecutableName,
platformExecutablePath,
platformManifestPath
) {
const outputName = `${meta.__applicationName}-${meta.__applicationVersion}-${arch}.exe`;
const scriptPath = path.join(__dirname, "../packaging/win/installer.nsi");
const scriptOutputPath = path.join(BUILD_PATH, path.basename(scriptPath));
const view = {
applicationName: meta.__applicationName
, applicationVersion: meta.__applicationVersion
, executableName: platformExecutableName
, executablePath: platformExecutablePath
, manifestName: paths.MANIFEST_NAME
, bindingName: MDNS_BINDING_NAME
, winRegistryKey: paths.REGISTRY_KEY
, outputName
, licensePath: paths.LICENSE_PATH
applicationName: meta.__applicationName,
applicationVersion: meta.__applicationVersion,
executableName: platformExecutableName,
executablePath: platformExecutablePath,
manifestName: paths.MANIFEST_NAME,
bindingName: MDNS_BINDING_NAME,
winRegistryKey: paths.REGISTRY_KEY,
outputName,
licensePath: paths.LICENSE_PATH,
// Uninstaller keys
, registryPublisher: author
, registryUrlInfoAbout: homepage
registryPublisher: author,
registryUrlInfoAbout: homepage
};
// Write templated script to build dir
fs.writeFileSync(scriptOutputPath
, mustache.render(
fs.readFileSync(scriptPath).toString()
, view));
fs.writeFileSync(
scriptOutputPath,
mustache.render(fs.readFileSync(scriptPath).toString(), view)
);
spawnSync(`makensis /DARCH=${arch} ${scriptOutputPath}`
, spawnOptions);
spawnSync(`makensis /DARCH=${arch} ${scriptOutputPath}`, spawnOptions);
return outputName;
}
build().catch(e => {
console.log("Build failed", e);
process.exit(1);

View File

@@ -5,24 +5,20 @@ const minimist = require("minimist");
const paths = require("./lib/paths");
const argv = minimist(process.argv.slice(2), {
boolean: [ "remove" ]
, default: {
boolean: ["remove"],
default: {
remove: false
}
});
const CURRENT_MANIFEST_PATH = path.join(paths.DIST_PATH, paths.MANIFEST_NAME);
if (!fs.existsSync(CURRENT_MANIFEST_PATH) && !argv.remove) {
console.error("No manifest in dist/app/ to install.");
process.exit(1);
}
const platform = os.platform();
const arch = os.arch();
@@ -30,9 +26,12 @@ switch (platform) {
case "darwin":
case "linux": {
// Manifest location within home directory
const destination = path.join(os.homedir(), platform === "linux"
? ".mozilla/native-messaging-hosts/"
: paths.getManifestPath(platform, arch));
const destination = path.join(
os.homedir(),
platform === "linux"
? ".mozilla/native-messaging-hosts/"
: paths.getManifestPath(platform, arch)
);
if (argv.remove) {
fs.remove(path.join(destination, paths.MANIFEST_NAME));
@@ -41,11 +40,13 @@ switch (platform) {
// Install manifest
fs.ensureDirSync(destination);
fs.copyFileSync(CURRENT_MANIFEST_PATH
, path.join(destination, paths.MANIFEST_NAME));
fs.copyFileSync(
CURRENT_MANIFEST_PATH,
path.join(destination, paths.MANIFEST_NAME)
);
break;
};
}
case "win32": {
const { Registry } = require("rage-edit");
@@ -56,14 +57,10 @@ switch (platform) {
break;
}
Registry.set(
REGISTRY_PATH
, ""
, CURRENT_MANIFEST_PATH
, "REG_SZ");
Registry.set(REGISTRY_PATH, "", CURRENT_MANIFEST_PATH, "REG_SZ");
break;
};
}
default: {
console.error("Sorry, this installer does not yet support your OS");

View File

@@ -2,10 +2,11 @@
const path = require("path");
const { __applicationName
, __applicationDirectoryName
, __applicationExecutableName } = require("../../package.json");
const {
__applicationName,
__applicationDirectoryName,
__applicationExecutableName
} = require("../../package.json");
const rootPath = path.join(__dirname, "../../../");
@@ -15,9 +16,9 @@ exports.LICENSE_PATH = path.join(rootPath, "LICENSE");
exports.REGISTRY_KEY = __applicationName;
exports.pkgPlatformMap = {
win32: "win"
, darwin: "macos"
, linux: "linux"
win32: "win",
darwin: "macos",
linux: "linux"
};
exports.MANIFEST_NAME = `${__applicationName}.json`;
@@ -30,7 +31,7 @@ exports.getExecutableName = platform => {
case "linux":
return __applicationExecutableName;
}
}
};
exports.getExecutablePath = (platform, arch) => {
const EXECUTABLE_PATH_WIN32_X64 = `C:\\Program Files\\${__applicationDirectoryName}\\`;
@@ -41,32 +42,42 @@ exports.getExecutablePath = (platform, arch) => {
switch (platform) {
case "win32":
switch (arch) {
case "x86": return EXECUTABLE_PATH_WIN32_X86;
case "x64": return EXECUTABLE_PATH_WIN32_X64;
case "x86":
return EXECUTABLE_PATH_WIN32_X86;
case "x64":
return EXECUTABLE_PATH_WIN32_X64;
}
break;
case "darwin": return EXECUTABLE_PATH_DARWIN;
case "linux": return EXECUTABLE_PATH_LINUX;
case "darwin":
return EXECUTABLE_PATH_DARWIN;
case "linux":
return EXECUTABLE_PATH_LINUX;
}
};
exports.getManifestPath = (platform, arch, linuxPackageType) => {
const MANIFEST_PATH_DARWIN = "/Library/Application Support/Mozilla/NativeMessagingHosts/";
const MANIFEST_PATH_DARWIN =
"/Library/Application Support/Mozilla/NativeMessagingHosts/";
const MANIFEST_PATH_LINUX_DEB = "/usr/lib/mozilla/native-messaging-hosts/";
const MANIFEST_PATH_LINUX_RPM ="/usr/lib64/mozilla/native-messaging-hosts/";
const MANIFEST_PATH_LINUX_RPM =
"/usr/lib64/mozilla/native-messaging-hosts/";
switch (platform) {
case "win32":
switch (arch) {
case "x86":
case "x64": return exports.getExecutablePath(platform, arch);
case "x64":
return exports.getExecutablePath(platform, arch);
}
break;
case "darwin": return MANIFEST_PATH_DARWIN;
case "darwin":
return MANIFEST_PATH_DARWIN;
case "linux":
switch (linuxPackageType) {
case "deb": return MANIFEST_PATH_LINUX_DEB;
case "rpm": return MANIFEST_PATH_LINUX_RPM;
case "deb":
return MANIFEST_PATH_LINUX_DEB;
case "rpm":
return MANIFEST_PATH_LINUX_RPM;
}
break;

2074
app/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -8,13 +8,13 @@ for (const faq of document.querySelectorAll(".faq")) {
faq.id = formattedSummary;
if (window.location.hash) {
faq.open = decodeURIComponent(
window.location.hash.slice(1)) === formattedSummary;
faq.open =
decodeURIComponent(window.location.hash.slice(1)) ===
formattedSummary;
}
}
function updateThemeClass (mediaQuery) {
function updateThemeClass(mediaQuery) {
if (mediaQuery.matches) {
document.documentElement.classList.remove("theme-dark");
document.documentElement.classList.add("theme-light");
@@ -29,10 +29,10 @@ const prefersLightScheme = window.matchMedia("(prefers-color-scheme: light)");
updateThemeClass(prefersLightScheme);
prefersLightScheme.addListener(updateThemeClass);
const downloadAppBtn = document.querySelector(".download__app");
const downloadAppOther = document.querySelector(".download__app-other");
const downloadAppOtherSummary = downloadAppOther.querySelector(":scope > summary");
const downloadAppOtherSummary =
downloadAppOther.querySelector(":scope > summary");
// Ext download button
const downloadExtBtn = document.querySelector(".download__ext");
@@ -45,7 +45,6 @@ const appListMacBtn = document.querySelector(".app-list__mac");
const appListDebBtn = document.querySelector(".app-list__deb");
const appListRpmBtn = document.querySelector(".app-list__rpm");
let platform;
switch (navigator.platform) {
@@ -79,8 +78,7 @@ switch (navigator.platform) {
appListRpmBtn.classList.add("button");
}
function populateAppListApp (element, fileUrl, fileName, fileSize, version) {
function populateAppListApp(element, fileUrl, fileName, fileSize, version) {
element.href = fileUrl;
element.title = `${fileName} (${fileSize})`;
element.dataset.fileSize = fileSize;
@@ -88,7 +86,6 @@ function populateAppListApp (element, fileUrl, fileName, fileSize, version) {
element.removeAttribute("disabled");
}
const ENDPOINT_URL = "https://api.github.com/repos/hensm/fx_cast/releases";
fetch(ENDPOINT_URL)
@@ -96,7 +93,7 @@ fetch(ENDPOINT_URL)
.then(onResponse)
.catch(onError);
function onResponse (res) {
function onResponse(res) {
for (const release of res.reverse()) {
for (const asset of release.assets) {
const formattedSize = formatSize(asset.size);
@@ -113,18 +110,25 @@ function onResponse (res) {
downloadExtBtn.removeAttribute("disabled");
break;
case "exe":
switch (asset.name.match(REGEX_ARCH).pop()) {
case "x86":
populateAppListApp(
appListWin32Btn, asset.browser_download_url
, asset.name, formattedSize, tag_name);
appListWin32Btn,
asset.browser_download_url,
asset.name,
formattedSize,
tag_name
);
break;
case "x64":
populateAppListApp(
appListWin64Btn, asset.browser_download_url
, asset.name, formattedSize, tag_name);
appListWin64Btn,
asset.browser_download_url,
asset.name,
formattedSize,
tag_name
);
break;
}
@@ -132,20 +136,32 @@ function onResponse (res) {
case "pkg":
populateAppListApp(
appListMacBtn, asset.browser_download_url
, asset.name, formattedSize, tag_name);
appListMacBtn,
asset.browser_download_url,
asset.name,
formattedSize,
tag_name
);
break;
case "deb":
populateAppListApp(
appListDebBtn, asset.browser_download_url
, asset.name, formattedSize, tag_name);
appListDebBtn,
asset.browser_download_url,
asset.name,
formattedSize,
tag_name
);
break;
case "rpm":
populateAppListApp(
appListRpmBtn, asset.browser_download_url
, asset.name, formattedSize, tag_name);
appListRpmBtn,
asset.browser_download_url,
asset.name,
formattedSize,
tag_name
);
break;
}
}
@@ -156,7 +172,8 @@ function onResponse (res) {
case "win":
downloadAppBtn.href = appListWin64Btn.href;
downloadAppBtn.title = appListWin64Btn.title;
downloadAppBtn.dataset.version = appListWin64Btn.dataset.version;
downloadAppBtn.dataset.version =
appListWin64Btn.dataset.version;
break;
case "mac":
downloadAppBtn.href = appListMacBtn.href;
@@ -173,12 +190,11 @@ function onResponse (res) {
}
}
function onError (err) {
function onError(err) {
console.error("Failed to fetch download links", err);
}
function formatSize (bytes, precision = 1, useMetric = false) {
function formatSize(bytes, precision = 1, useMetric = false) {
const factor = useMetric ? 1000 : 1024;
// Sizes in bytes
@@ -190,25 +206,25 @@ function formatSize (bytes, precision = 1, useMetric = false) {
if (bytes >= 0 && bytes < kxbyte) {
return `${bytes} B`;
} else if (bytes >= kxbyte && bytes < mxbyte) {
return `${(bytes / kxbyte).toFixed(precision)} ${
useMetric ? "KB" : "KiB"}`;
useMetric ? "KB" : "KiB"
}`;
} else if (bytes >= mxbyte && bytes < gxbyte) {
return `${(bytes / mxbyte).toFixed(precision)} ${
useMetric ? "MB" : "MiB"}`;
useMetric ? "MB" : "MiB"
}`;
} else if (bytes >= gxbyte && bytes < txbyte) {
return `${(bytes / gxbyte).toFixed(precision)} ${
useMetric ? "GB" : "GiB"}`;
useMetric ? "GB" : "GiB"
}`;
} else if (bytes >= txbyte && bytes < pxbyte) {
return `${(bytes / txbyte).toFixed(precision)} ${
useMetric ? "TB" : "TiB"}`;
useMetric ? "TB" : "TiB"
}`;
} else if (bytes >= pxbyte) {
return `${(bytes / pxbyte).toFixed(precision)} ${
useMetric ? "PB" : "PiB"}`;
useMetric ? "PB" : "PiB"
}`;
}
}

View File

@@ -8,12 +8,12 @@ const mediaManager = new cast.receiver.MediaManager(mediaElement);
mediaElement.height = window.innerHeight;
mediaElement.width = window.innerWidth;
let senderId;
const messageBus = castReceiverManager.getCastMessageBus(
"urn:x-cast:fx_cast"
, cast.receiver.CastMessageBus.MessageType.JSON);
"urn:x-cast:fx_cast",
cast.receiver.CastMessageBus.MessageType.JSON
);
messageBus.onMessage = async message => {
const { subject, data } = message.data;
@@ -27,8 +27,8 @@ messageBus.onMessage = async message => {
await pc.setLocalDescription(desc);
messageBus.send(message.senderId, {
subject: "peerConnectionAnswer"
, data: desc
subject: "peerConnectionAnswer",
data: desc
});
break;
@@ -46,13 +46,12 @@ messageBus.onMessage = async message => {
}
};
const pc = new RTCPeerConnection();
pc.addEventListener("icecandidate", ev => {
messageBus.send(senderId, {
subject: "iceCandidate"
, data: ev.candidate
subject: "iceCandidate",
data: ev.candidate
});
});
@@ -64,7 +63,6 @@ pc.addEventListener("addstream", ev => {
splash.classList.add("splash--disabled");
});
// TODO: Fix API shim to make this work
castReceiverManager.onSenderDisconnected = ev => {
if (castReceiverManager.getSenders().length <= 0) {

View File

@@ -6,21 +6,19 @@ const path = require("path");
const minimist = require("minimist");
const webExt = require("web-ext");
const BRIDGE_NAME = "fx_cast_bridge";
const BRIDGE_VERSION = "0.1.0";
const MIRRORING_APP_ID = "19A6F4AE";
const argv = minimist(process.argv.slice(2), {
boolean: [ "package", "watch" ]
, string: [ "mirroringAppId", "mode" ]
, default: {
package: false
, watch: false
, mirroringAppId: MIRRORING_APP_ID
, mode: "development"
boolean: ["package", "watch"],
string: ["mirroringAppId", "mode"],
default: {
package: false,
watch: false,
mirroringAppId: MIRRORING_APP_ID,
mode: "development"
}
});
@@ -34,7 +32,6 @@ if (argv.package) {
argv.mode = "production";
}
// Paths
const rootPath = path.resolve(__dirname, "../");
const srcPath = path.join(rootPath, "src");
@@ -51,48 +48,50 @@ const preactCompatPlugin = {
*/
name: "preact-compat",
setup(build) {
const preactPath = path.resolve(__dirname
, "../node_modules/preact/compat/dist/compat.module.js");
const preactPath = path.resolve(
__dirname,
"../node_modules/preact/compat/dist/compat.module.js"
);
build.onResolve(
{ filter: /^(react|react-dom)$/ }
, (args) => ({ path: preactPath }));
build.onResolve({ filter: /^(react|react-dom)$/ }, args => ({
path: preactPath
}));
}
}
};
/** @type esbuild.BuildOptions */
const buildOpts = {
bundle: true
, target: "firefox64"
, logLevel: "info"
, sourcemap: "inline"
bundle: true,
target: "firefox64",
logLevel: "info",
sourcemap: "inline",
, outdir: outPath
, outbase: srcPath
outdir: outPath,
outbase: srcPath,
, entryPoints: [
entryPoints: [
// Main
`${srcPath}/background/background.ts`
`${srcPath}/background/background.ts`,
// Media sender
, `${srcPath}/senders/media/index.ts`
, `${srcPath}/senders/media/overlay/overlayContent.ts`
, `${srcPath}/senders/media/overlay/overlayContentLoader.ts`
`${srcPath}/senders/media/index.ts`,
`${srcPath}/senders/media/overlay/overlayContent.ts`,
`${srcPath}/senders/media/overlay/overlayContentLoader.ts`,
// Mirroring sender
, `${srcPath}/senders/mirroring.ts`
`${srcPath}/senders/mirroring.ts`,
// Shim
, `${srcPath}/shim/index.ts`
, `${srcPath}/shim/content.ts`
, `${srcPath}/shim/contentBridge.ts`
`${srcPath}/shim/index.ts`,
`${srcPath}/shim/content.ts`,
`${srcPath}/shim/contentBridge.ts`,
// UI
, `${srcPath}/ui/popup/index.tsx`
, `${srcPath}/ui/options/index.tsx`
]
, define: {
BRIDGE_NAME: `"${BRIDGE_NAME}"`
, BRIDGE_VERSION: `"${BRIDGE_VERSION}"`
, MIRRORING_APP_ID: `"${argv.mirroringAppId}"`
}
, plugins: [ preactCompatPlugin ]
`${srcPath}/ui/popup/index.tsx`,
`${srcPath}/ui/options/index.tsx`
],
define: {
BRIDGE_NAME: `"${BRIDGE_NAME}"`,
BRIDGE_VERSION: `"${BRIDGE_VERSION}"`,
MIRRORING_APP_ID: `"${argv.mirroringAppId}"`
},
plugins: [preactCompatPlugin]
};
// Set production options
@@ -113,12 +112,13 @@ function onBuildResult(result) {
}
const manifest = JSON.parse(
fs.readFileSync(`${srcPath}/manifest.json`
, { encoding: "utf-8" }));
fs.readFileSync(`${srcPath}/manifest.json`, { encoding: "utf-8" })
);
manifest.content_security_policy = argv.mode === "production"
? "script-src 'self'; object-src 'self'"
: "script-src 'self' 'unsafe-eval'; object-src 'self'";
manifest.content_security_policy =
argv.mode === "production"
? "script-src 'self'; object-src 'self'"
: "script-src 'self' 'unsafe-eval'; object-src 'self'";
fs.writeFileSync(`${outPath}/manifest.json`, JSON.stringify(manifest));
@@ -132,14 +132,14 @@ function onBuildResult(result) {
* @param {string} dest Destination path
* @param {RegExp} excludeRegex Match for file exclusion
*/
function copy(src, dest, excludeRegex) {
function copy(src, dest, excludeRegex) {
if (!fs.existsSync(src)) return;
const stats = fs.statSync(src);
if (!stats.isDirectory()) {
const dirName = path.dirname(dest);
if (!fs.existsSync(dirName)) {
fs.mkdirSync(dirName , { recursive: true });
fs.mkdirSync(dirName, { recursive: true });
}
fs.copyFileSync(src, dest);
return;
@@ -155,41 +155,49 @@ function onBuildResult(result) {
fs.removeSync(distPath);
if (argv.watch) {
esbuild.build({
...buildOpts
, watch: {
onRebuild(_err, result) {
return onBuildResult(result);
esbuild
.build({
...buildOpts,
watch: {
onRebuild(_err, result) {
return onBuildResult(result);
}
}
}
}).then(onBuildResult);
})
.then(onBuildResult);
} else {
esbuild.build(buildOpts).then(result => {
onBuildResult(result);
if (argv.package) {
webExt.cmd.build({
/**
* Webpack output at sourceDir is built into an extension
* archive at artifactsDir.
*/
sourceDir: unpackedPath
, artifactsDir: distPath
, overwriteDest: true
}, {
// Prevent auto-exit
shouldExitProgram: false
}).then(result => {
const outputName = path.basename(result.extensionPath);
webExt.cmd
.build(
{
/**
* Webpack output at sourceDir is built into an extension
* archive at artifactsDir.
*/
sourceDir: unpackedPath,
artifactsDir: distPath,
overwriteDest: true
},
{
// Prevent auto-exit
shouldExitProgram: false
}
)
.then(result => {
const outputName = path.basename(result.extensionPath);
// Rename output extension to XPI
fs.moveSync(path.join(distPath, outputName)
, path.join(distPath, outputName.replace(
"zip", "xpi")));
// Rename output extension to XPI
fs.moveSync(
path.join(distPath, outputName),
path.join(distPath, outputName.replace("zip", "xpi"))
);
// Only need the built extension archive
fs.remove(unpackedPath);
});
// Only need the built extension archive
fs.remove(unpackedPath);
});
}
});
}

8482
ext/package-lock.json generated

File diff suppressed because it is too large Load Diff

2051
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -29,6 +29,7 @@
"glob": "^7.1.6",
"jasmine-console-reporter": "^3.1.0",
"minimist": "^1.2.5",
"prettier": "^2.3.2",
"selenium-webdriver": "^4.0.0-beta.1",
"ws": "^7.4.3"
}

View File

@@ -9,56 +9,54 @@ const env = jasmine.getEnv();
// Copy to window
Object.assign(window, jasmineRequire.interface(jasmine, env));
// Create query string
const queryString = new jasmine.QueryString({
getWindowLocation () {
getWindowLocation() {
return window.location;
}
});
// If spec is present in the query string
const filterSpecs = !!queryString.getParam("spec");
// Create HTML reporter
const htmlReporter = new jasmine.HtmlReporter({
env
, filterSpecs
, timer: new jasmine.Timer()
env,
filterSpecs,
timer: new jasmine.Timer(),
, getContainer () {
getContainer() {
return document.body;
}
},
// Bound functions
, navigateWithNewParam: queryString.navigateWithNewParam.bind(queryString)
, addToExistingQueryString: queryString.fullStringWithNewParam.bind(queryString)
, createElement: document.createElement.bind(document)
, createTextNode: document.createTextNode.bind(document)
navigateWithNewParam: queryString.navigateWithNewParam.bind(queryString),
addToExistingQueryString:
queryString.fullStringWithNewParam.bind(queryString),
createElement: document.createElement.bind(document),
createTextNode: document.createTextNode.bind(document)
});
// Create spec filter
const specFilter = new jasmine.HtmlSpecFilter({
filterString () {
filterString() {
return queryString.getParam("spec");
}
});
// Add reporters
env.addReporter(jsApiReporter);
env.addReporter(htmlReporter);
// Configure Env
env.configure({
failFast : queryString.getParam("failFast")
, hideDisabled : queryString.getParam("hideDisabled")
, oneFailurePerSpec : queryString.getParam("oneFailurePerSpec")
, random : queryString.getParam("random")
, seed : queryString.getParam("seed")
failFast: queryString.getParam("failFast"),
hideDisabled: queryString.getParam("hideDisabled"),
oneFailurePerSpec: queryString.getParam("oneFailurePerSpec"),
random: queryString.getParam("random"),
seed: queryString.getParam("seed"),
, specFilter (spec) {
specFilter(spec) {
return specFilter.matches(spec.getFullName());
}
});

View File

@@ -15,20 +15,19 @@ const chrome = require("selenium-webdriver/chrome");
// Webdriver shorthands
const { By, until } = webdriver;
const { __extensionName
, __extensionVersion } = require("../ext/package.json");
const { __extensionName, __extensionVersion } = require("../ext/package.json");
const extensionArchivePath = path.join(
__dirname, "../dist/ext"
, `${__extensionName}-${__extensionVersion}.xpi`)
__dirname,
"../dist/ext",
`${__extensionName}-${__extensionVersion}.xpi`
);
if (!fs.existsSync(extensionArchivePath)) {
console.error("Extension archive not found.");
process.exit(1);
}
const TEST_PAGE_URL = `file:///${__dirname}/SpecRunner.html`;
const POLLING_PAGE_URL = `file:///${__dirname}/polling.html`;
@@ -37,10 +36,10 @@ const firefoxOptions = new firefox.Options()
.addExtensions(extensionArchivePath)
.setPreference("xpinstall.signatures.required", false);
const chromeOptions = new chrome.Options()
.excludeSwitches([ "disable-background-networking"
, "disable-default-apps"]);
const chromeOptions = new chrome.Options().excludeSwitches([
"disable-background-networking",
"disable-default-apps"
]);
/**
* Chrome doesn't load the media router extension immediately
@@ -50,11 +49,11 @@ const chromeOptions = new chrome.Options()
* Workaround is to poll every 100ms, refresh the page, and
* check whether the chrome.cast API objects are defined.
*/
function waitUntilDefined (
driver
, pollingTimeout = 10000
, pollingFrequency = 100) {
function waitUntilDefined(
driver,
pollingTimeout = 10000,
pollingFrequency = 100
) {
return new Promise(async (resolve, reject) => {
let elapsedTime = pollingFrequency;
@@ -92,7 +91,7 @@ function waitUntilDefined (
* channel.
*/
class MessageProxy extends EventEmitter {
constructor () {
constructor() {
super();
const wss = new WebSocket.Server({
@@ -104,7 +103,7 @@ class MessageProxy extends EventEmitter {
const messageContent = JSON.parse(message);
this.emit(messageContent.subject, messageContent.data);
});
})
});
}
}
@@ -112,13 +111,13 @@ class MessageProxy extends EventEmitter {
* Ensures cast API is loaded before finding and injecting spec
* file scripts into the test page.
*/
async function injectSpecs (driver) {
const [ loaded, errorInfo ] = await driver.executeAsyncScript(() => {
async function injectSpecs(driver) {
const [loaded, errorInfo] = await driver.executeAsyncScript(() => {
const callback = arguments[arguments.length - 1];
// If already loaded, return immediately
if (chrome.cast !== undefined) {
callback([ true ]);
callback([true]);
}
// Set Cast API callback
@@ -133,7 +132,6 @@ async function injectSpecs (driver) {
return;
}
// Get spec files
const specFiles = glob.sync("spec/**/*.spec.js", {
cwd: __dirname
@@ -171,7 +169,6 @@ async function injectSpecs (driver) {
console.log("Cast extension loaded!");
}
// Create console reporter and message proxy.
const reporter = new JasmineConsoleReporter();
const messageProxy = new MessageProxy();
@@ -185,12 +182,14 @@ async function injectSpecs (driver) {
* Forward events from Jasmine standlone via message proxy to
* console reporter.
*/
messageProxy.on("jasmineDone" , result => reporter.jasmineDone(result));
messageProxy.on("jasmineStarted" , result => reporter.jasmineStarted(result));
messageProxy.on("specDone" , result => reporter.specDone(result));
messageProxy.on("specStarted" , result => reporter.specStarted(result));
messageProxy.on("suiteDone" , result => reporter.suiteDone(result));
messageProxy.on("suiteStarted" , result => reporter.suiteStarted(result));
messageProxy.on("jasmineDone", result => reporter.jasmineDone(result));
messageProxy.on("jasmineStarted", result =>
reporter.jasmineStarted(result)
);
messageProxy.on("specDone", result => reporter.specDone(result));
messageProxy.on("specStarted", result => reporter.specStarted(result));
messageProxy.on("suiteDone", result => reporter.suiteDone(result));
messageProxy.on("suiteStarted", result => reporter.suiteStarted(result));
// Load Jasmine test page
driver.get(TEST_PAGE_URL);

View File

@@ -4,18 +4,18 @@
const socket = new WebSocket("ws://localhost:8080");
window.messageProxy = {
sendMessage (message) {
sendMessage(message) {
socket.send(JSON.stringify(message));
}
}
};
const reporterMethods = [
"jasmineDone"
, "jasmineStarted"
, "specDone"
, "specStarted"
, "suiteDone"
, "suiteStarted"
"jasmineDone",
"jasmineStarted",
"specDone",
"specStarted",
"suiteDone",
"suiteStarted"
];
const customReporter = {};
@@ -24,10 +24,10 @@ const customReporter = {};
for (const method of reporterMethods) {
customReporter[method] = function (result) {
messageProxy.sendMessage({
subject: method
, data: result
subject: method,
data: result
});
}
};
}
socket.addEventListener("open", ev => {

View File

@@ -16,17 +16,19 @@ describe("chrome.cast.ApiConfig", () => {
it("should have expected assigned properties", async () => {
const sessionRequest = new chrome.cast.SessionRequest(
chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID);
chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID
);
function sessionListener () {}
function receiverListener () {}
function sessionListener() {}
function receiverListener() {}
const apiConfig = new chrome.cast.ApiConfig(
sessionRequest
, sessionListener
, receiverListener
, chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED
, chrome.cast.DefaultActionPolicy.CAST_THIS_TAB);
sessionRequest,
sessionListener,
receiverListener,
chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED,
chrome.cast.DefaultActionPolicy.CAST_THIS_TAB
);
expect(typeof apiConfig.sessionListener).toBe("function");
expect(typeof apiConfig.receiverListener).toBe("function");

View File

@@ -10,8 +10,9 @@ describe("chrome.cast.DialRequest", () => {
it("should have expected assigned properties", async () => {
const dialRequest = new chrome.cast.DialRequest(
"testAppName"
, "testLaunchParameter");
"testAppName",
"testLaunchParameter"
);
expect(dialRequest.appName).toBe("testAppName");
expect(dialRequest.launchParameter).toBe("testLaunchParameter");

View File

@@ -11,13 +11,13 @@ describe("chrome.cast.Error", () => {
it("should have expected assigned properties", async () => {
const error = new chrome.cast.Error(
chrome.cast.ErrorCode.CANCEL
, "testErrorDescription"
, { testErrorDetails: "testErrorDetails" });
chrome.cast.ErrorCode.CANCEL,
"testErrorDescription",
{ testErrorDetails: "testErrorDetails" }
);
expect(error.code).toBe("cancel");
expect(error.description).toBe("testErrorDescription");
expect(error.details).toEqual(
{ testErrorDetails: "testErrorDetails" });
expect(error.details).toEqual({ testErrorDetails: "testErrorDetails" });
});
});

View File

@@ -15,15 +15,20 @@ describe("chrome.cast.Receiver", () => {
it("should have expected assigned properties", async () => {
const receiver = new chrome.cast.Receiver(
"testLabel"
, "testFriendlyName"
, [ chrome.cast.Capability.VIDEO_OUT
, chrome.cast.Capability.AUDIO_OUT ]
, new chrome.cast.Volume(1, false));
"testLabel",
"testFriendlyName",
[
chrome.cast.Capability.VIDEO_OUT,
chrome.cast.Capability.AUDIO_OUT
],
new chrome.cast.Volume(1, false)
);
expect(receiver.capabilities).toEqual([ "video_out", "audio_out" ]);
expect(receiver.capabilities).toEqual(["video_out", "audio_out"]);
expect(receiver.friendlyName).toBe("testFriendlyName");
expect(receiver.label).toBe("testLabel");
expect(receiver.volume).toEqual(jasmine.objectContaining({ level: 1, muted: false }));
expect(receiver.volume).toEqual(
jasmine.objectContaining({ level: 1, muted: false })
);
});
});

View File

@@ -2,8 +2,7 @@
describe("chrome.cast.ReceiverDisplayStatus", () => {
it("should have all properties", async () => {
const receiverDisplayStatus =
new chrome.cast.ReceiverDisplayStatus();
const receiverDisplayStatus = new chrome.cast.ReceiverDisplayStatus();
expect(typeof receiverDisplayStatus.appImages).toBe("undefined");
expect(typeof receiverDisplayStatus.statusText).toBe("undefined");
@@ -12,14 +11,27 @@ describe("chrome.cast.ReceiverDisplayStatus", () => {
it("should have expected assigned properties", async () => {
const receiverDisplayStatus = new chrome.cast.ReceiverDisplayStatus(
"testStatusText"
, [
new chrome.cast.Image("http://example.com/1")
, new chrome.cast.Image("http://example.com/2")
]);
"testStatusText",
[
new chrome.cast.Image("http://example.com/1"),
new chrome.cast.Image("http://example.com/2")
]
);
expect(receiverDisplayStatus.statusText).toBe("testStatusText");
expect(receiverDisplayStatus.appImages).toContain(jasmine.objectContaining({ url: "http://example.com/1", height: null, width: null }))
expect(receiverDisplayStatus.appImages).toContain(jasmine.objectContaining({ url: "http://example.com/2", height: null, width: null }))
expect(receiverDisplayStatus.appImages).toContain(
jasmine.objectContaining({
url: "http://example.com/1",
height: null,
width: null
})
);
expect(receiverDisplayStatus.appImages).toContain(
jasmine.objectContaining({
url: "http://example.com/2",
height: null,
width: null
})
);
});
});

View File

@@ -11,7 +11,8 @@ describe("chrome.cast.SenderApplication", () => {
it("should have expected assigned properties", async () => {
const senderApplication = new chrome.cast.SenderApplication(
chrome.cast.SenderPlatform.CHROME);
chrome.cast.SenderPlatform.CHROME
);
expect(senderApplication.platform).toBe("chrome");
});

View File

@@ -19,16 +19,19 @@ describe("chrome.cast.Session", () => {
it("should have expected assigned properties", async () => {
const session = new chrome.cast.Session(
"__sessionId"
, "__appId"
, "__displayName"
, [ new chrome.cast.Image("http://example.com") ]
, new chrome.cast.Receiver("__label", "__friendlyName"));
"__sessionId",
"__appId",
"__displayName",
[new chrome.cast.Image("http://example.com")],
new chrome.cast.Receiver("__label", "__friendlyName")
);
expect(session.appId).toBe("__appId");
expect(session.appImages).toEqual(jasmine.arrayContaining([
jasmine.objectContaining({ url: "http://example.com" })
]));
expect(session.appImages).toEqual(
jasmine.arrayContaining([
jasmine.objectContaining({ url: "http://example.com" })
])
);
expect(session.displayName).toBe("__displayName");
expect(session.receiver).toEqual(jasmine.any(chrome.cast.Receiver));
expect(session.sessionId).toBe("__sessionId");

View File

@@ -5,7 +5,7 @@ describe("chrome.cast.SessionRequest", () => {
const sessionRequest = new chrome.cast.SessionRequest();
expect(sessionRequest.appId).toBe(undefined);
expect(sessionRequest.capabilities).toEqual([ "video_out", "audio_out" ]);
expect(sessionRequest.capabilities).toEqual(["video_out", "audio_out"]);
expect(sessionRequest.dialRequest).toBe(null);
expect(sessionRequest.language).toBe(null);
expect(sessionRequest.requestSessionTimeout).toBe(60000);
@@ -13,13 +13,13 @@ describe("chrome.cast.SessionRequest", () => {
it("should have expected assigned properties", async () => {
const sessionRequest = new chrome.cast.SessionRequest(
"__appId"
, [ chrome.cast.Capability.VIDEO_OUT
, chrome.cast.Capability.AUDIO_IN ]
, 5000);
"__appId",
[chrome.cast.Capability.VIDEO_OUT, chrome.cast.Capability.AUDIO_IN],
5000
);
expect(sessionRequest.appId).toBe("__appId");
expect(sessionRequest.capabilities).toEqual([ "video_out", "audio_in" ]);
expect(sessionRequest.capabilities).toEqual(["video_out", "audio_in"]);
expect(sessionRequest.requestSessionTimeout).toBe(5000);
});
});

View File

@@ -41,84 +41,106 @@ describe("chrome", () => {
});
it("should have all api enums", () => {
expect(chrome.cast.AutoJoinPolicy).toEqual(jasmine.objectContaining({
CUSTOM_CONTROLLER_SCOPED: "custom_controller_scoped"
, TAB_AND_ORIGIN_SCOPED: "tab_and_origin_scoped"
, ORIGIN_SCOPED: "origin_scoped"
, PAGE_SCOPED: "page_scoped"
}));
expect(chrome.cast.AutoJoinPolicy).toEqual(
jasmine.objectContaining({
CUSTOM_CONTROLLER_SCOPED: "custom_controller_scoped",
TAB_AND_ORIGIN_SCOPED: "tab_and_origin_scoped",
ORIGIN_SCOPED: "origin_scoped",
PAGE_SCOPED: "page_scoped"
})
);
expect(chrome.cast.Capability).toEqual(jasmine.objectContaining({
VIDEO_OUT: "video_out"
, AUDIO_OUT: "audio_out"
, VIDEO_IN: "video_in"
, AUDIO_IN: "audio_in"
, MULTIZONE_GROUP: "multizone_group"
}));
expect(chrome.cast.Capability).toEqual(
jasmine.objectContaining({
VIDEO_OUT: "video_out",
AUDIO_OUT: "audio_out",
VIDEO_IN: "video_in",
AUDIO_IN: "audio_in",
MULTIZONE_GROUP: "multizone_group"
})
);
expect(chrome.cast.DefaultActionPolicy).toEqual(jasmine.objectContaining({
CREATE_SESSION: "create_session"
, CAST_THIS_TAB: "cast_this_tab"
}));
expect(chrome.cast.DefaultActionPolicy).toEqual(
jasmine.objectContaining({
CREATE_SESSION: "create_session",
CAST_THIS_TAB: "cast_this_tab"
})
);
expect(chrome.cast.DialAppState).toEqual(jasmine.objectContaining({
RUNNING: "running"
, STOPPED: "stopped"
, ERROR: "error"
}));
expect(chrome.cast.DialAppState).toEqual(
jasmine.objectContaining({
RUNNING: "running",
STOPPED: "stopped",
ERROR: "error"
})
);
expect(chrome.cast.ErrorCode).toEqual(jasmine.objectContaining({
CANCEL: "cancel"
, TIMEOUT: "timeout"
, API_NOT_INITIALIZED: "api_not_initialized"
, INVALID_PARAMETER: "invalid_parameter"
, EXTENSION_NOT_COMPATIBLE: "extension_not_compatible"
, EXTENSION_MISSING: "extension_missing"
, RECEIVER_UNAVAILABLE: "receiver_unavailable"
, SESSION_ERROR: "session_error"
, CHANNEL_ERROR: "channel_error"
, LOAD_MEDIA_FAILED: "load_media_failed"
}));
expect(chrome.cast.ErrorCode).toEqual(
jasmine.objectContaining({
CANCEL: "cancel",
TIMEOUT: "timeout",
API_NOT_INITIALIZED: "api_not_initialized",
INVALID_PARAMETER: "invalid_parameter",
EXTENSION_NOT_COMPATIBLE: "extension_not_compatible",
EXTENSION_MISSING: "extension_missing",
RECEIVER_UNAVAILABLE: "receiver_unavailable",
SESSION_ERROR: "session_error",
CHANNEL_ERROR: "channel_error",
LOAD_MEDIA_FAILED: "load_media_failed"
})
);
expect(chrome.cast.ReceiverAction).toEqual(jasmine.objectContaining({
CAST: "cast"
, STOP: "stop"
}));
expect(chrome.cast.ReceiverAction).toEqual(
jasmine.objectContaining({
CAST: "cast",
STOP: "stop"
})
);
expect(chrome.cast.ReceiverAvailability).toEqual(jasmine.objectContaining({
AVAILABLE: "available"
, UNAVAILABLE: "unavailable"
}));
expect(chrome.cast.ReceiverAvailability).toEqual(
jasmine.objectContaining({
AVAILABLE: "available",
UNAVAILABLE: "unavailable"
})
);
expect(chrome.cast.ReceiverType).toEqual(jasmine.objectContaining({
CAST: "cast"
, DIAL: "dial"
, HANGOUT: "hangout"
, CUSTOM: "custom"
}));
expect(chrome.cast.ReceiverType).toEqual(
jasmine.objectContaining({
CAST: "cast",
DIAL: "dial",
HANGOUT: "hangout",
CUSTOM: "custom"
})
);
expect(chrome.cast.SenderPlatform).toEqual(jasmine.objectContaining({
CHROME: "chrome"
, IOS: "ios"
, ANDROID: "android"
}));
expect(chrome.cast.SenderPlatform).toEqual(
jasmine.objectContaining({
CHROME: "chrome",
IOS: "ios",
ANDROID: "android"
})
);
expect(chrome.cast.SessionStatus).toEqual(jasmine.objectContaining({
CONNECTED: "connected"
, DISCONNECTED: "disconnected"
, STOPPED: "stopped"
}));
expect(chrome.cast.SessionStatus).toEqual(
jasmine.objectContaining({
CONNECTED: "connected",
DISCONNECTED: "disconnected",
STOPPED: "stopped"
})
);
expect(chrome.cast.VolumeControlType).toEqual(jasmine.objectContaining({
ATTENUATION: "attenuation"
, FIXED: "fixed"
, MASTER: "master"
}));
expect(chrome.cast.VolumeControlType).toEqual(
jasmine.objectContaining({
ATTENUATION: "attenuation",
FIXED: "fixed",
MASTER: "master"
})
);
});
});
describe("chrome.cast.media", () => {
it ("should have all api classes", () => {
it("should have all api classes", () => {
expect(chrome.cast.media.EditTracksInfoRequest).toBeDefined();
expect(chrome.cast.media.GenericMediaMetadata).toBeDefined();
expect(chrome.cast.media.GetStatusRequest).toBeDefined();
@@ -144,90 +166,116 @@ describe("chrome", () => {
expect(chrome.cast.media.VolumeRequest).toBeDefined();
});
it ("should have all api enums", () => {
expect(chrome.cast.media.IdleReason).toEqual(jasmine.objectContaining({
CANCELLED: "CANCELLED"
, INTERRUPTED: "INTERRUPTED"
, FINISHED: "FINISHED"
, ERROR: "ERROR"
}));
expect(chrome.cast.media.MediaCommand).toEqual(jasmine.objectContaining({
PAUSE: "pause"
, SEEK: "seek"
, STREAM_VOLUME: "stream_volume"
, STREAM_MUTE: "stream_mute"
}));
expect(chrome.cast.media.MetadataType).toEqual(jasmine.objectContaining({
GENERIC: 0
, MOVIE: 1
, TV_SHOW: 2
, MUSIC_TRACK: 3
, PHOTO: 4
}));
expect(chrome.cast.media.PlayerState).toEqual(jasmine.objectContaining({
IDLE: "IDLE"
, PLAYING: "PLAYING"
, PAUSED: "PAUSED"
, BUFFERING: "BUFFERING"
}));
expect(chrome.cast.media.RepeatMode).toEqual(jasmine.objectContaining({
OFF: "REPEAT_OFF"
, ALL: "REPEAT_ALL"
, SINGLE: "REPEAT_SINGLE"
, ALL_AND_SHUFFLE: "REPEAT_ALL_AND_SHUFFLE"
}));
expect(chrome.cast.media.ResumeState).toEqual(jasmine.objectContaining({
PLAYBACK_START: "PLAYBACK_START"
, PLAYBACK_PAUSE: "PLAYBACK_PAUSE"
}));
expect(chrome.cast.media.StreamType).toEqual(jasmine.objectContaining({
BUFFERED: "BUFFERED"
, LIVE: "LIVE"
, OTHER: "OTHER"
}));
expect(chrome.cast.media.TextTrackEdgeType).toEqual(jasmine.objectContaining({
NONE: "NONE"
, OUTLINE: "OUTLINE"
, DROP_SHADOW: "DROP_SHADOW"
, RAISED: "RAISED"
, DEPRESSED: "DEPRESSED"
}));
expect(chrome.cast.media.TextTrackFontGenericFamily).toEqual(jasmine.objectContaining({
SANS_SERIF: "SANS_SERIF"
, MONOSPACED_SANS_SERIF: "MONOSPACED_SANS_SERIF"
, SERIF: "SERIF"
, MONOSPACED_SERIF: "MONOSPACED_SERIF"
, CASUAL: "CASUAL"
, CURSIVE: "CURSIVE"
, SMALL_CAPITALS: "SMALL_CAPITALS"
}));
expect(chrome.cast.media.TextTrackFontStyle).toEqual(jasmine.objectContaining({
NORMAL: "NORMAL"
, BOLD: "BOLD"
, BOLD_ITALIC: "BOLD_ITALIC"
, ITALIC: "ITALIC"
}));
expect(chrome.cast.media.TextTrackType).toEqual(jasmine.objectContaining({
SUBTITLES: "SUBTITLES"
, CAPTIONS: "CAPTIONS"
, DESCRIPTIONS: "DESCRIPTIONS"
, CHAPTERS: "CHAPTERS"
, METADATA: "METADATA"
}));
expect(chrome.cast.media.TextTrackWindowType).toEqual(jasmine.objectContaining({
NONE: "NONE"
, NORMAL: "NORMAL"
, ROUNDED_CORNERS: "ROUNDED_CORNERS"
}));
expect(chrome.cast.media.TrackType).toEqual(jasmine.objectContaining({
TEXT: "TEXT"
, AUDIO: "AUDIO"
, VIDEO: "VIDEO"
}));
it("should have all api enums", () => {
expect(chrome.cast.media.IdleReason).toEqual(
jasmine.objectContaining({
CANCELLED: "CANCELLED",
INTERRUPTED: "INTERRUPTED",
FINISHED: "FINISHED",
ERROR: "ERROR"
})
);
expect(chrome.cast.media.MediaCommand).toEqual(
jasmine.objectContaining({
PAUSE: "pause",
SEEK: "seek",
STREAM_VOLUME: "stream_volume",
STREAM_MUTE: "stream_mute"
})
);
expect(chrome.cast.media.MetadataType).toEqual(
jasmine.objectContaining({
GENERIC: 0,
MOVIE: 1,
TV_SHOW: 2,
MUSIC_TRACK: 3,
PHOTO: 4
})
);
expect(chrome.cast.media.PlayerState).toEqual(
jasmine.objectContaining({
IDLE: "IDLE",
PLAYING: "PLAYING",
PAUSED: "PAUSED",
BUFFERING: "BUFFERING"
})
);
expect(chrome.cast.media.RepeatMode).toEqual(
jasmine.objectContaining({
OFF: "REPEAT_OFF",
ALL: "REPEAT_ALL",
SINGLE: "REPEAT_SINGLE",
ALL_AND_SHUFFLE: "REPEAT_ALL_AND_SHUFFLE"
})
);
expect(chrome.cast.media.ResumeState).toEqual(
jasmine.objectContaining({
PLAYBACK_START: "PLAYBACK_START",
PLAYBACK_PAUSE: "PLAYBACK_PAUSE"
})
);
expect(chrome.cast.media.StreamType).toEqual(
jasmine.objectContaining({
BUFFERED: "BUFFERED",
LIVE: "LIVE",
OTHER: "OTHER"
})
);
expect(chrome.cast.media.TextTrackEdgeType).toEqual(
jasmine.objectContaining({
NONE: "NONE",
OUTLINE: "OUTLINE",
DROP_SHADOW: "DROP_SHADOW",
RAISED: "RAISED",
DEPRESSED: "DEPRESSED"
})
);
expect(chrome.cast.media.TextTrackFontGenericFamily).toEqual(
jasmine.objectContaining({
SANS_SERIF: "SANS_SERIF",
MONOSPACED_SANS_SERIF: "MONOSPACED_SANS_SERIF",
SERIF: "SERIF",
MONOSPACED_SERIF: "MONOSPACED_SERIF",
CASUAL: "CASUAL",
CURSIVE: "CURSIVE",
SMALL_CAPITALS: "SMALL_CAPITALS"
})
);
expect(chrome.cast.media.TextTrackFontStyle).toEqual(
jasmine.objectContaining({
NORMAL: "NORMAL",
BOLD: "BOLD",
BOLD_ITALIC: "BOLD_ITALIC",
ITALIC: "ITALIC"
})
);
expect(chrome.cast.media.TextTrackType).toEqual(
jasmine.objectContaining({
SUBTITLES: "SUBTITLES",
CAPTIONS: "CAPTIONS",
DESCRIPTIONS: "DESCRIPTIONS",
CHAPTERS: "CHAPTERS",
METADATA: "METADATA"
})
);
expect(chrome.cast.media.TextTrackWindowType).toEqual(
jasmine.objectContaining({
NONE: "NONE",
NORMAL: "NORMAL",
ROUNDED_CORNERS: "ROUNDED_CORNERS"
})
);
expect(chrome.cast.media.TrackType).toEqual(
jasmine.objectContaining({
TEXT: "TEXT",
AUDIO: "AUDIO",
VIDEO: "VIDEO"
})
);
});
describe("chrome.cast.media.timeout", () => {
it ("should have all properties", () => {
it("should have all properties", () => {
expect(chrome.cast.media.timeout.editTracksInfo).toBe(0);
expect(chrome.cast.media.timeout.getStatus).toBe(0);
expect(chrome.cast.media.timeout.load).toBe(0);
@@ -237,7 +285,7 @@ describe("chrome", () => {
expect(chrome.cast.media.timeout.seek).toBe(0);
expect(chrome.cast.media.timeout.setVolume).toBe(0);
expect(chrome.cast.media.timeout.stop).toBe(0);
})
});
});
});
});

View File

@@ -2,7 +2,8 @@
describe("chrome.cast.media.EditTracksInfoRequest", () => {
it("should have all properties", async () => {
const editTracksInfoRequest = new chrome.cast.media.EditTracksInfoRequest();
const editTracksInfoRequest =
new chrome.cast.media.EditTracksInfoRequest();
expect(editTracksInfoRequest.activeTrackIds).toBe(null);
expect(editTracksInfoRequest.requestId).toBe(0);
@@ -15,14 +16,19 @@ describe("chrome.cast.media.EditTracksInfoRequest", () => {
textTrackStyle.fontFamily = "__fontFamily";
textTrackStyle.windowRoundedCornerRadius = 5;
const editTracksInfoRequest = new chrome.cast.media.EditTracksInfoRequest(
[ 5, 8, 12 ], textTrackStyle);
const editTracksInfoRequest =
new chrome.cast.media.EditTracksInfoRequest(
[5, 8, 12],
textTrackStyle
);
expect(editTracksInfoRequest.activeTrackIds).toEqual([ 5, 8, 12 ]);
expect(editTracksInfoRequest.textTrackStyle).toEqual(jasmine.objectContaining({
backgroundColor: "#fefefeff"
, fontFamily: "__fontFamily"
, windowRoundedCornerRadius: 5
}));
expect(editTracksInfoRequest.activeTrackIds).toEqual([5, 8, 12]);
expect(editTracksInfoRequest.textTrackStyle).toEqual(
jasmine.objectContaining({
backgroundColor: "#fefefeff",
fontFamily: "__fontFamily",
windowRoundedCornerRadius: 5
})
);
});
});

View File

@@ -2,7 +2,8 @@
describe("chrome.cast.media.GenericMediaMetadata", () => {
it("should have all properties", async () => {
const genericMediaMetadata = new chrome.cast.media.GenericMediaMetadata();
const genericMediaMetadata =
new chrome.cast.media.GenericMediaMetadata();
expect(genericMediaMetadata.images).toBe(undefined);
expect(genericMediaMetadata.metadataType).toBe(0);

View File

@@ -16,12 +16,16 @@ describe("chrome.cast.media.LoadRequest", () => {
it("should have expected assigned properties", async () => {
const mediaInfo = new chrome.cast.media.MediaInfo(
"__contentId", "video/mp4");
"__contentId",
"video/mp4"
);
const loadRequest = new chrome.cast.media.LoadRequest(mediaInfo);
expect(loadRequest.media).toEqual(jasmine.objectContaining({
contentId: "__contentId"
, contentType: "video/mp4"
}));
expect(loadRequest.media).toEqual(
jasmine.objectContaining({
contentId: "__contentId",
contentType: "video/mp4"
})
);
});
});

View File

@@ -19,10 +19,12 @@ describe("chrome.cast.media.Media", () => {
expect(media.repeatMode).toBe("REPEAT_OFF");
expect(media.sessionId).toBe(undefined);
expect(media.supportedMediaCommands).toEqual([]);
expect(media.volume).toEqual(jasmine.objectContaining({
level: null
, muted: null
}));
expect(media.volume).toEqual(
jasmine.objectContaining({
level: null,
muted: null
})
);
});
it("should have expected assigned properties", async () => {

View File

@@ -15,7 +15,10 @@ describe("chrome.cast.media.MediaInfo", () => {
});
it("should have expected assigned properties", async () => {
const mediaInfo = new chrome.cast.media.MediaInfo("__contentId", "video/mp4");
const mediaInfo = new chrome.cast.media.MediaInfo(
"__contentId",
"video/mp4"
);
expect(mediaInfo.contentId).toBe("__contentId");
expect(mediaInfo.contentType).toBe("video/mp4");

View File

@@ -2,7 +2,8 @@
describe("chrome.cast.media.MusicTrackMediaMetadata", () => {
it("should have all properties", async () => {
const musicTrackMediaMetadata = new chrome.cast.media.MusicTrackMediaMetadata();
const musicTrackMediaMetadata =
new chrome.cast.media.MusicTrackMediaMetadata();
expect(musicTrackMediaMetadata.albumArtist).toBe(undefined);
expect(musicTrackMediaMetadata.albumName).toBe(undefined);

View File

@@ -2,7 +2,8 @@
describe("chrome.cast.media.QueueInsertItemsRequest", () => {
it("should have all properties", async () => {
const queueInsertItemsRequest = new chrome.cast.media.QueueInsertItemsRequest();
const queueInsertItemsRequest =
new chrome.cast.media.QueueInsertItemsRequest();
expect(queueInsertItemsRequest.customData).toBe(null);
expect(queueInsertItemsRequest.insertBefore).toBe(null);
@@ -16,20 +17,25 @@ describe("chrome.cast.media.QueueInsertItemsRequest", () => {
const media1 = new chrome.cast.media.MediaInfo("media1", "video/mp4");
const media2 = new chrome.cast.media.MediaInfo("media2", "audio/mp3");
const queueInsertItemsRequest = new chrome.cast.media.QueueInsertItemsRequest([
new chrome.cast.media.QueueItem(media1)
, new chrome.cast.media.QueueItem(media2)
]);
const queueInsertItemsRequest =
new chrome.cast.media.QueueInsertItemsRequest([
new chrome.cast.media.QueueItem(media1),
new chrome.cast.media.QueueItem(media2)
]);
expect(queueInsertItemsRequest.items).toEqual([
jasmine.objectContaining({ media: jasmine.objectContaining({
contentId: "media1"
, contentType: "video/mp4"
})})
, jasmine.objectContaining({ media: jasmine.objectContaining({
contentId: "media2"
, contentType: "audio/mp3"
})})
jasmine.objectContaining({
media: jasmine.objectContaining({
contentId: "media1",
contentType: "video/mp4"
})
}),
jasmine.objectContaining({
media: jasmine.objectContaining({
contentId: "media2",
contentType: "audio/mp3"
})
})
]);
});
});

View File

@@ -15,12 +15,17 @@ describe("chrome.cast.media.QueueItem", () => {
});
it("should have expected assigned properties", async () => {
const media = new chrome.cast.media.MediaInfo("__contentId", "video/mp4");
const media = new chrome.cast.media.MediaInfo(
"__contentId",
"video/mp4"
);
const queueItem = new chrome.cast.media.QueueItem(media);
expect(queueItem.media).toEqual(jasmine.objectContaining({
contentId: "__contentId"
, contentType: "video/mp4"
}));
expect(queueItem.media).toEqual(
jasmine.objectContaining({
contentId: "__contentId",
contentType: "video/mp4"
})
);
});
});

View File

@@ -18,19 +18,23 @@ describe("chrome.cast.media.QueueLoadRequest", () => {
const media2 = new chrome.cast.media.MediaInfo("media2", "audio/mp3");
const queueLoadRequest = new chrome.cast.media.QueueLoadRequest([
new chrome.cast.media.QueueItem(media1)
, new chrome.cast.media.QueueItem(media2)
new chrome.cast.media.QueueItem(media1),
new chrome.cast.media.QueueItem(media2)
]);
expect(queueLoadRequest.items).toEqual([
jasmine.objectContaining({ media: jasmine.objectContaining({
contentId: "media1"
, contentType: "video/mp4"
})})
, jasmine.objectContaining({ media: jasmine.objectContaining({
contentId: "media2"
, contentType: "audio/mp3"
})})
jasmine.objectContaining({
media: jasmine.objectContaining({
contentId: "media1",
contentType: "video/mp4"
})
}),
jasmine.objectContaining({
media: jasmine.objectContaining({
contentId: "media2",
contentType: "audio/mp3"
})
})
]);
});
});

View File

@@ -2,7 +2,8 @@
describe("chrome.cast.media.QueueRemoveItemsRequest", () => {
it("should have all properties", async () => {
const queueRemoveItemsRequest = new chrome.cast.media.QueueRemoveItemsRequest();
const queueRemoveItemsRequest =
new chrome.cast.media.QueueRemoveItemsRequest();
expect(queueRemoveItemsRequest.customData).toBe(null);
expect(queueRemoveItemsRequest.itemIds).toBe(undefined);
@@ -12,9 +13,9 @@ describe("chrome.cast.media.QueueRemoveItemsRequest", () => {
});
it("should have expected assigned properties", async () => {
const queueRemoveItemsRequest = new chrome.cast.media.QueueRemoveItemsRequest(
[ 5, 8, 12 ]);
const queueRemoveItemsRequest =
new chrome.cast.media.QueueRemoveItemsRequest([5, 8, 12]);
expect(queueRemoveItemsRequest.itemIds).toEqual([ 5, 8, 12 ]);
expect(queueRemoveItemsRequest.itemIds).toEqual([5, 8, 12]);
});
});

View File

@@ -2,7 +2,8 @@
describe("chrome.cast.media.QueueReorderItemsRequest", () => {
it("should have all properties", async () => {
const queueReorderItemsRequest = new chrome.cast.media.QueueReorderItemsRequest();
const queueReorderItemsRequest =
new chrome.cast.media.QueueReorderItemsRequest();
expect(queueReorderItemsRequest.customData).toBe(null);
expect(queueReorderItemsRequest.insertBefore).toBe(null);
@@ -13,9 +14,9 @@ describe("chrome.cast.media.QueueReorderItemsRequest", () => {
});
it("should have expected assigned properties", async () => {
const queueReorderItemsRequest = new chrome.cast.media.QueueReorderItemsRequest(
[ 5, 8, 12 ]);
const queueReorderItemsRequest =
new chrome.cast.media.QueueReorderItemsRequest([5, 8, 12]);
expect(queueReorderItemsRequest.itemIds).toEqual([ 5, 8, 12 ]);
expect(queueReorderItemsRequest.itemIds).toEqual([5, 8, 12]);
});
});

View File

@@ -2,7 +2,8 @@
describe("chrome.cast.media.QueueSetPropertiesRequest", () => {
it("should have all properties", async () => {
const queueSetPropertiesRequest = new chrome.cast.media.QueueSetPropertiesRequest();
const queueSetPropertiesRequest =
new chrome.cast.media.QueueSetPropertiesRequest();
expect(queueSetPropertiesRequest.customData).toBe(null);
expect(queueSetPropertiesRequest.repeatMode).toBe(null);

View File

@@ -2,7 +2,8 @@
describe("chrome.cast.media.QueueUpdateItemsRequest", () => {
it("should have all properties", async () => {
const queueUpdateItemsRequest = new chrome.cast.media.QueueUpdateItemsRequest();
const queueUpdateItemsRequest =
new chrome.cast.media.QueueUpdateItemsRequest();
expect(queueUpdateItemsRequest.customData).toBe(null);
expect(queueUpdateItemsRequest.items).toBe(undefined);
@@ -15,20 +16,25 @@ describe("chrome.cast.media.QueueUpdateItemsRequest", () => {
const media1 = new chrome.cast.media.MediaInfo("media1", "video/mp4");
const media2 = new chrome.cast.media.MediaInfo("media2", "audio/mp3");
const queueUpdateItemsRequest = new chrome.cast.media.QueueUpdateItemsRequest([
new chrome.cast.media.QueueItem(media1)
, new chrome.cast.media.QueueItem(media2)
]);
const queueUpdateItemsRequest =
new chrome.cast.media.QueueUpdateItemsRequest([
new chrome.cast.media.QueueItem(media1),
new chrome.cast.media.QueueItem(media2)
]);
expect(queueUpdateItemsRequest.items).toEqual([
jasmine.objectContaining({ media: jasmine.objectContaining({
contentId: "media1"
, contentType: "video/mp4"
})})
, jasmine.objectContaining({ media: jasmine.objectContaining({
contentId: "media2"
, contentType: "audio/mp3"
})})
jasmine.objectContaining({
media: jasmine.objectContaining({
contentId: "media1",
contentType: "video/mp4"
})
}),
jasmine.objectContaining({
media: jasmine.objectContaining({
contentId: "media2",
contentType: "audio/mp3"
})
})
]);
});
});

View File

@@ -15,7 +15,10 @@ describe("chrome.cast.media.Track", () => {
});
it("should have expected assigned properties", async () => {
const track = new chrome.cast.media.Track(5, chrome.cast.media.TrackType.TEXT);
const track = new chrome.cast.media.Track(
5,
chrome.cast.media.TrackType.TEXT
);
expect(track.trackId).toBe(5);
expect(track.type).toBe("TEXT");

View File

@@ -12,9 +12,11 @@ describe("chrome.cast.media.VolumeRequest", () => {
const volume = new chrome.cast.Volume(0.5, false);
const volumeRequest = new chrome.cast.media.VolumeRequest(volume);
expect(volumeRequest.volume).toEqual(jasmine.objectContaining({
level: 0.5
, muted: false
}));
expect(volumeRequest.volume).toEqual(
jasmine.objectContaining({
level: 0.5,
muted: false
})
);
});
});