Switch to eslint and fix issues

This commit is contained in:
hensm
2021-04-26 05:36:55 +01:00
parent 2d0fa4c844
commit d478742c4b
100 changed files with 1537 additions and 608 deletions

View File

@@ -8,7 +8,7 @@ import { Message } from "../../messaging";
import { Receiver } from "../../types";
function startMediaServer (filePath: string, port: number)
function startMediaServer(filePath: string, port: number)
: Promise<{ mediaPath: string
, subtitlePaths: string[]
, localAddress: string }> {
@@ -22,7 +22,7 @@ function startMediaServer (filePath: string, port: number)
}
} as Message);
backgroundPort.addEventListener("message", function onMessage (ev) {
backgroundPort.addEventListener("message", function onMessage(ev) {
const message = ev.data as Message;
if (message.subject.startsWith("mediaCast:mediaServer")) {
@@ -54,14 +54,14 @@ let currentMedia: cast.media.Media;
let mediaElement: HTMLMediaElement;
function getSession (opts: InitOptions): Promise<cast.Session> {
function getSession(opts: InitOptions): Promise<cast.Session> {
return new Promise(async (resolve, reject) => {
/**
* If a receiver is available, call requestSession. If a
* specific receiver was specified, bypass receiver selector
* and create session directly.
*/
function receiverListener (availability: string) {
function receiverListener(availability: string) {
if (availability === cast.ReceiverAvailability.AVAILABLE) {
if (opts.receiver) {
cast._requestSession(
@@ -76,14 +76,14 @@ function getSession (opts: InitOptions): Promise<cast.Session> {
}
}
function sessionListener () {
function sessionListener() {
// TODO: Handle this
}
function onRequestSessionSuccess (session: cast.Session) {
function onRequestSessionSuccess(session: cast.Session) {
resolve(session);
}
function onRequestSessionError (err: cast.Error) {
function onRequestSessionError(err: cast.Error) {
reject(err.description);
}
@@ -101,7 +101,7 @@ function getSession (opts: InitOptions): Promise<cast.Session> {
});
}
function getMedia (opts: InitOptions): Promise<cast.media.Media> {
function getMedia(opts: InitOptions): Promise<cast.media.Media> {
return new Promise(async (resolve, reject) => {
let mediaUrl = new URL(opts.mediaUrl);
let subtitleUrls: URL[] = [];
@@ -233,16 +233,15 @@ function getMedia (opts: InitOptions): Promise<cast.media.Media> {
let ignoreMediaEvents = false;
async function registerMediaElementListeners () {
if (await options.get("mediaSyncElement")) {
function checkIgnore (ev: Event) {
if (ignoreMediaEvents) {
ignoreMediaEvents = false;
ev.stopImmediatePropagation();
}
async function registerMediaElementListeners() {
function checkIgnore(ev: Event) {
if (ignoreMediaEvents) {
ignoreMediaEvents = false;
ev.stopImmediatePropagation();
}
}
if (await options.get("mediaSyncElement")) {
mediaElement.addEventListener("play", checkIgnore, true);
mediaElement.addEventListener("pause", checkIgnore, true);
mediaElement.addEventListener("suspend", checkIgnore, true);
@@ -348,7 +347,7 @@ interface InitOptions {
targetElementId?: number;
}
export async function init (opts: InitOptions) {
export async function init(opts: InitOptions) {
backgroundPort = await ensureInit();
const isLocalMedia = opts.mediaUrl.startsWith("file://");
@@ -380,8 +379,7 @@ export async function init (opts: InitOptions) {
});
if (await options.get("mediaStopOnUnload")) {
// tslint:disable-next-line: no-empty
currentSession.stop(() => {}, () => {});
currentSession.stop();
}
});
}

View File

@@ -4,7 +4,7 @@
* Walk up the prototype chain until the specified property
* descriptor is found, otherwise return undefined.
*/
export function getPropertyDescriptor (
export function getPropertyDescriptor(
target: any, prop: string | number | symbol)
: PropertyDescriptor | undefined {
@@ -23,7 +23,7 @@ export function getPropertyDescriptor (
* Bind either the getter/setter functions or the value function
* to a target object.
*/
export function bindPropertyDescriptor (
export function bindPropertyDescriptor(
desc: PropertyDescriptor, target: any)
: PropertyDescriptor {
@@ -42,7 +42,7 @@ export function bindPropertyDescriptor (
* be further up in the prototype chain), re-bind it to the target
* element and collect them into a property descriptor map.
*/
export function clonePropsDescriptor<T> (
export function clonePropsDescriptor<T>(
target: T, props: any[])
: PropertyDescriptorMap {
@@ -57,15 +57,15 @@ export function clonePropsDescriptor<T> (
}, {});
}
export function makeGetterDescriptor (val: any): PropertyDescriptor {
export function makeGetterDescriptor(val: any): PropertyDescriptor {
return {
enumerable: true
, configurable: true
, get () { return val; }
, get() { return val; }
};
}
export function makeValueDescriptor (val: any): PropertyDescriptor {
export function makeValueDescriptor(val: any): PropertyDescriptor {
return {
enumerable: true
, configurable: true

View File

@@ -28,8 +28,7 @@ Element.prototype.attachShadow = function (init) {
};
function getShadowRootFromNode (node: Node): ShadowRoot | undefined {
function getShadowRootFromNode(node: Node): ShadowRoot | undefined {
// Don't touch our custom element
if (node instanceof PlayerElement) {
return;
@@ -45,13 +44,13 @@ const DQS_XPATH_EXPRESSION = `//*[contains(name(), "-")]`;
* Return the first matching querySelector result on any ShadowRoot
* nodes present in the document.
*/
function deepQuerySelector (selector: string): Element | null {
function deepQuerySelector(selector: string): Element | null {
const result = document.evaluate(
DQS_XPATH_EXPRESSION, document, null
, XPathResult.ORDERED_NODE_ITERATOR_TYPE);
let node: Node | null;
// tslint:disable-next-line: no-conditional-assignment
// eslint-disable-next-line no-cond-assign
while (node = result.iterateNext()) {
const shadowRoot = getShadowRootFromNode(node);
if (!shadowRoot) {
@@ -71,7 +70,7 @@ function deepQuerySelector (selector: string): Element | null {
* Collect and return the results of querySelectorAll on any
* ShadowRoot nodes present in the document.
*/
function deepQuerySelectorAll (selector: string): Node[] {
function deepQuerySelectorAll(selector: string): Node[] {
const result = document.evaluate(
DQS_XPATH_EXPRESSION, document, null
, XPathResult.ORDERED_NODE_ITERATOR_TYPE);
@@ -79,7 +78,7 @@ function deepQuerySelectorAll (selector: string): Node[] {
const nodes: Node[] = [];
let node: Node | null;
// tslint:disable-next-line: no-conditional-assignment
// eslint-disable-next-line no-cond-assign
while (node = result.iterateNext()) {
const shadowRoot = getShadowRootFromNode(node);
if (shadowRoot) {
@@ -116,7 +115,7 @@ const mediaElementAttributes = mediaElementTypes
* functions are proxied to the internal media element.
*/
class PlayerElement extends HTMLElement {
constructor () {
constructor() {
super();
const shadowRoot = this.attachShadow({ mode: "closed" });
@@ -204,11 +203,11 @@ class PlayerElement extends HTMLElement {
class AudioPlayerElement extends PlayerElement {}
class VideoPlayerElement extends PlayerElement {
set overlayHidden (val: boolean) {
set overlayHidden(val: boolean) {
const shadowRoot = internalShadowRoots.get(this);
(shadowRoot?.querySelector(".overlay") as HTMLDivElement).hidden = val;
}
get overlayHidden () {
get overlayHidden() {
const shadowRoot = internalShadowRoots.get(this);
return (shadowRoot?.querySelector(".overlay") as HTMLDivElement).hidden;
}
@@ -234,7 +233,7 @@ const _createElementNS = document.createElementNS;
* custom element version that imitates the original. Otherwise, returns
* the result of the original.
*/
function createElement (
function createElement(
tagName: string
, options?: ElementCreationOptions) {
@@ -264,7 +263,7 @@ function createElement (
* patched `createElement` function, otherwise return the result of the
* original.
*/
function createElementNS (
function createElementNS(
namespaceURI: string
, qualifiedName: string
, options?: ElementCreationOptions) {
@@ -298,7 +297,7 @@ Object.defineProperties(document, {
* `createElement` function, fetches the shadow root and copies any
* attributes before swapping with the original element in-place.
*/
function wrapMediaElement (mediaElement: HTMLMediaElement) {
function wrapMediaElement(mediaElement: HTMLMediaElement) {
const wrappedMedia = document.createElement(mediaElement.tagName);
const shadowRoot = internalShadowRoots.get(wrappedMedia);

View File

@@ -27,7 +27,7 @@ let peerConnection: RTCPeerConnection;
* Sends a message to the fx_cast app running on the
* receiver device.
*/
function sendAppMessage (subject: string, data: any) {
function sendAppMessage(subject: string, data: any) {
if (!session) {
return;
}
@@ -44,7 +44,7 @@ window.addEventListener("beforeunload", () => {
});
async function onRequestSessionSuccess (newSession: cast.Session) {
async function onRequestSessionSuccess(newSession: cast.Session) {
cast.logMessage("onRequestSessionSuccess");
session = newSession;
@@ -102,7 +102,7 @@ async function onRequestSessionSuccess (newSession: cast.Session) {
let lastFrame: DOMHighResTimeStamp;
window.requestAnimationFrame(
function draw (now: DOMHighResTimeStamp) {
function draw(now: DOMHighResTimeStamp) {
if (!lastFrame) {
lastFrame = now;
@@ -153,7 +153,7 @@ async function onRequestSessionSuccess (newSession: cast.Session) {
}
function receiverListener (availability: string) {
function receiverListener(availability: string) {
cast.logMessage("receiverListener");
if (wasSessionRequested) {
@@ -170,16 +170,16 @@ function receiverListener (availability: string) {
}
function onRequestSessionError () {
function onRequestSessionError() {
cast.logMessage("onRequestSessionError");
}
function sessionListener () {
function sessionListener() {
cast.logMessage("sessionListener");
}
function onInitializeSuccess () {
function onInitializeSuccess() {
cast.logMessage("onInitializeSuccess");
}
function onInitializeError () {
function onInitializeError() {
cast.logMessage("onInitializeError");
}