Skip to content

Commit

Permalink
update dependencies and code
Browse files Browse the repository at this point in the history
This is the usual dependency update before a release (scheduled
to be the v3.26.2).

After updating `typescript-eslint`, new linter errors made their
apparitions, for cases where an `any` type is used as a function
argument (the rule in question is
[no-unsafe-argument](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/no-unsafe-argument.md)).

That's a rule we want (`any` is ___bad___ after all!) but RxJS,
our main dependency, does not respect it well.
Especially, some operators which transform an observable into
another without needing to look at the items of the source
Observable (e.g. `mapTo`, `mergeMapTo`, `switchMapTo`,
`ignoreElements`) have an `any` in their type definition for the type
of the source Observable's elements (where an `unknown` would actually
suffice and be type-safe).

Replacing on their side this `any` by `unknown` is planned for their
8.x.x release (which is not yet released). In the meantime, we had to
find a solution.

I chose to do two things:

  1. Replace all the "***To" (`mapTo`, `mergeMapTo` and so on)
     operators by their callback-based equivalent (`map`,
     `mergeMap` and so on).
     I did that mostly because RxJS devs [seems to plan
     deprecating the ***To operators anyway in profit of the
     callback-based ones](ReactiveX/rxjs#6399).

  2. For the last remaining operator, `ignoreElements()`, I just
  disabled the rule with a long comment attached on top of each case.
  • Loading branch information
peaBerberian committed Dec 15, 2021
1 parent ae5b918 commit 07b88fa
Show file tree
Hide file tree
Showing 59 changed files with 4,233 additions and 4,199 deletions.
8,125 changes: 4,034 additions & 4,091 deletions package-lock.json

Large diffs are not rendered by default.

70 changes: 35 additions & 35 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,63 +80,63 @@
"dependencies": {
"next-tick": "1.1.0",
"pinkie": "2.0.4",
"rxjs": "7.3.0"
"rxjs": "7.4.0"
},
"devDependencies": {
"@babel/core": "7.15.5",
"@babel/plugin-transform-runtime": "7.15.0",
"@babel/preset-env": "7.15.6",
"@babel/preset-react": "7.14.5",
"@types/chai": "4.2.21",
"@types/jest": "27.0.1",
"@babel/core": "7.16.5",
"@babel/plugin-transform-runtime": "7.16.5",
"@babel/preset-env": "7.16.5",
"@babel/preset-react": "7.16.5",
"@types/chai": "4.3.0",
"@types/jest": "27.0.3",
"@types/mocha": "9.0.0",
"@types/node": "16.9.1",
"@types/sinon": "10.0.2",
"@typescript-eslint/eslint-plugin": "4.31.0",
"@typescript-eslint/eslint-plugin-tslint": "4.31.0",
"@typescript-eslint/parser": "4.31.0",
"@types/node": "16.11.13",
"@types/sinon": "10.0.6",
"@typescript-eslint/eslint-plugin": "5.7.0",
"@typescript-eslint/eslint-plugin-tslint": "5.7.0",
"@typescript-eslint/parser": "5.7.0",
"arraybuffer-loader": "1.0.8",
"babel-loader": "8.2.2",
"babel-loader": "8.2.3",
"chai": "4.3.4",
"cheerio": "1.0.0-rc.10",
"core-js": "3.17.3",
"esbuild": "0.12.25",
"eslint": "7.32.0",
"eslint-plugin-import": "2.24.2",
"eslint-plugin-jsdoc": "36.1.0",
"eslint-plugin-react": "7.25.1",
"core-js": "3.19.3",
"esbuild": "0.14.5",
"eslint": "8.4.1",
"eslint-plugin-import": "2.25.3",
"eslint-plugin-jsdoc": "37.2.1",
"eslint-plugin-react": "7.27.1",
"esm": "3.2.25",
"express": "4.17.1",
"highlight.js": "11.2.0",
"highlight.js": "11.3.1",
"html-entities": "^2.3.2",
"istanbul-instrumenter-loader": "3.0.1",
"jest": "27.2.0",
"karma": "6.3.4",
"jest": "27.4.5",
"karma": "6.3.9",
"karma-chrome-launcher": "3.1.0",
"karma-coverage-istanbul-reporter": "3.0.3",
"karma-firefox-launcher": "2.1.1",
"karma-firefox-launcher": "2.1.2",
"karma-mocha": "2.0.1",
"karma-mocha-reporter": "2.2.5",
"karma-mocha-reporter": "2.2.3",
"karma-webpack": "5.0.0",
"markdown-it": "12.2.0",
"mocha": "9.1.1",
"markdown-it": "12.3.0",
"mocha": "9.1.3",
"mocha-loader": "5.1.5",
"raw-loader": "4.0.2",
"react": "17.0.2",
"react-dom": "17.0.2",
"regenerator-runtime": "0.13.9",
"rimraf": "3.0.2",
"sanitize-html": "2.5.0",
"sanitize-html": "2.6.1",
"semver": "7.3.5",
"sinon": "11.1.2",
"terser-webpack-plugin": "5.2.4",
"ts-jest": "27.0.5",
"ts-loader": "9.2.5",
"sinon": "12.0.1",
"terser-webpack-plugin": "5.2.5",
"ts-jest": "27.1.1",
"ts-loader": "9.2.6",
"tslint": "6.1.3",
"typescript": "4.4.3",
"webpack": "5.52.1",
"webpack-bundle-analyzer": "4.4.2",
"webpack-cli": "4.8.0"
"typescript": "4.5.4",
"webpack": "5.65.0",
"webpack-bundle-analyzer": "4.5.0",
"webpack-cli": "4.9.1"
},
"scripts-list": {
"Build a demo page (e.g. to test a code change)": {
Expand Down
1 change: 1 addition & 0 deletions src/compat/__tests__/add_text_track.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/no-unsafe-call */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-unsafe-argument */

describe("compat - addTextTrack", () => {
beforeEach(() => {
Expand Down
1 change: 1 addition & 0 deletions src/compat/__tests__/when_loaded_metadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-call */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/no-unsafe-argument */

import {
finalize,
Expand Down
1 change: 1 addition & 0 deletions src/compat/__tests__/when_media_source_open.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-call */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/no-unsafe-argument */

import {
finalize,
Expand Down
12 changes: 6 additions & 6 deletions src/compat/eme/custom_media_keys/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ import {
import getWebKitMediaKeysCallbacks from "./webkit_media_keys";
import { WebKitMediaKeysConstructor } from "./webkit_media_keys_constructor";

let requestMediaKeySystemAccess : null |
((keyType : string,
config : MediaKeySystemConfiguration[])
=> Observable<MediaKeySystemAccess |
CustomMediaKeySystemAccess>)
= null;
/** Generic implementation of the navigator.requestMediaKeySystemAccess API. */
type ICompatRequestMediaKeySystemAccessFn =
(keyType : string, config : MediaKeySystemConfiguration[]) =>
Observable<MediaKeySystemAccess | CustomMediaKeySystemAccess>;

let requestMediaKeySystemAccess : null | ICompatRequestMediaKeySystemAccessFn = null;

let _setMediaKeys :
((elt: HTMLMediaElement, mediaKeys: MediaKeys | ICustomMediaKeys | null) => void) =
Expand Down
7 changes: 5 additions & 2 deletions src/compat/eme/custom_media_keys/old_webkit_media_keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,15 @@ class OldWebkitMediaKeySession
const licenseTypedArray =
license instanceof ArrayBuffer ? new Uint8Array(license) :
license;
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const json = JSON.parse(utf8ToStr(licenseTypedArray));
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-argument */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
const json = JSON.parse(utf8ToStr(licenseTypedArray));
const key = base64ToBytes(json.keys[0].k);
const kid = base64ToBytes(json.keys[0].kid);
/* eslint-enable @typescript-eslint/no-unsafe-member-access */
/* eslint-enable @typescript-eslint/no-unsafe-argument */
/* eslint-enable @typescript-eslint/no-unsafe-assignment */
resolve(this._vid.webkitAddKey(this._key, key, kid, /* sessionId */ ""));
} else {
resolve(this._vid.webkitAddKey(this._key, license, null, /* sessionId */ ""));
Expand Down
4 changes: 2 additions & 2 deletions src/compat/eme/load_session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import {
defer as observableDefer,
mapTo,
map,
mergeMap,
Observable,
of as observableOf,
Expand Down Expand Up @@ -66,6 +66,6 @@ export default function loadSession(
return observableRace(
observableTimer(EME_WAITING_DELAY_LOADED_SESSION_EMPTY_KEYSTATUSES),
onKeyStatusesChange$(session)
).pipe(take(1), mapTo(isLoaded));
).pipe(take(1), map(() => isLoaded));
}));
}
3 changes: 1 addition & 2 deletions src/compat/event_listeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
fromEvent as observableFromEvent,
interval as observableInterval,
map,
mapTo,
merge as observableMerge,
of as observableOf,
startWith,
Expand Down Expand Up @@ -269,7 +268,7 @@ function onPictureInPictureEvent$(
}).pictureInPictureWindow ?? null,
}))),
observableFromEvent(mediaElement, "leavepictureinpicture")
.pipe(mapTo({ isEnabled: false, pipWindow: null }))
.pipe(map(() => ({ isEnabled: false, pipWindow: null })))
).pipe(startWith(initialState));
});
}
Expand Down
6 changes: 6 additions & 0 deletions src/core/abr/representation_estimator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ import PendingRequestsStore from "./pending_requests_store";
import RepresentationScoreCalculator from "./representation_score_calculator";
import selectOptimalRepresentation from "./select_optimal_representation";

// NOTE As of now (RxJS 7.4.0), RxJS defines `ignoreElements` default
// first type parameter as `any` instead of the perfectly fine `unknown`,
// leading to linter issues, as it forbids the usage of `any`.
// This is why we're disabling the eslint rule.
/* eslint-disable @typescript-eslint/no-unsafe-argument */

/**
* Adaptive BitRate estimate object.
*
Expand Down
1 change: 1 addition & 0 deletions src/core/api/__tests__/option_utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-call */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/no-unsafe-argument */
/* eslint-disable @typescript-eslint/no-explicit-any */

import config from "../../../config";
Expand Down
10 changes: 5 additions & 5 deletions src/core/api/emit_seek_events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import {
defer as observableDefer,
EMPTY,
filter,
mapTo,
map,
merge as observableMerge,
Observable,
startWith,
switchMapTo,
switchMap,
take,
} from "rxjs";
import { IPlaybackObservation } from "./playback_observer";
Expand All @@ -47,13 +47,13 @@ export default function emitSeekEvents(

const isSeeking$ = observation$.pipe(
filter((observation : IPlaybackObservation) => observation.event === "seeking"),
mapTo("seeking" as const)
map(() => "seeking" as const)
);
const hasSeeked$ = isSeeking$.pipe(
switchMapTo(
switchMap(() =>
observation$.pipe(
filter((observation : IPlaybackObservation) => observation.event === "seeked"),
mapTo("seeked" as const),
map(() => "seeked" as const),
take(1)))
);
const seekingEvents$ = observableMerge(isSeeking$, hasSeeked$);
Expand Down
5 changes: 2 additions & 3 deletions src/core/api/playback_observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
fromEvent as observableFromEvent,
interval as observableInterval,
map,
mapTo,
merge as observableMerge,
Observable,
share,
Expand Down Expand Up @@ -245,15 +244,15 @@ export default class PlaybackObserver {
const eventObs : Array< Observable< IPlaybackObserverEventType > > =
SCANNED_MEDIA_ELEMENTS_EVENTS.map((eventName) =>
observableFromEvent(this._mediaElement, eventName)
.pipe(mapTo(eventName)));
.pipe(map(() => eventName)));

const interval = this._lowLatencyMode ? SAMPLING_INTERVAL_LOW_LATENCY :
this._withMediaSource ? SAMPLING_INTERVAL_MEDIASOURCE :
SAMPLING_INTERVAL_NO_MEDIASOURCE;

const interval$ : Observable<"timeupdate"> =
observableInterval(interval)
.pipe(mapTo("timeupdate"));
.pipe(map(() => "timeupdate"));

return observableMerge(interval$, ...eventObs).pipe(
map((event : IPlaybackObserverEventType) => {
Expand Down
12 changes: 5 additions & 7 deletions src/core/api/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ import {
EMPTY,
filter,
map,
mapTo,
merge as observableMerge,
mergeMap,
mergeMapTo,
Observable,
of as observableOf,
ReplaySubject,
Expand All @@ -41,7 +39,7 @@ import {
startWith,
Subject,
Subscription,
switchMapTo,
switchMap,
take,
takeUntil,
} from "rxjs";
Expand Down Expand Up @@ -1028,7 +1026,7 @@ class Player extends EventEmitter<IPublicAPIEvent> {
observableOf(PLAYER_STATES.LOADING), // Begin with LOADING

// LOADED as soon as the first "loaded" event is sent
loaded$.pipe(take(1), mapTo(PLAYER_STATES.LOADED)),
loaded$.pipe(take(1), map(() => PLAYER_STATES.LOADED)),

observableMerge(
loadedStateUpdates$
Expand All @@ -1040,10 +1038,10 @@ class Player extends EventEmitter<IPublicAPIEvent> {

// when reloading
reloading$.pipe(
switchMapTo(
switchMap(() =>
loaded$.pipe(
take(1), // wait for the next loaded event
mergeMapTo(loadedStateUpdates$), // to update the state as usual
mergeMap(() => loadedStateUpdates$), // to update the state as usual
startWith(PLAYER_STATES.RELOADING) // Starts with "RELOADING" state
)
)
Expand Down Expand Up @@ -1074,7 +1072,7 @@ class Player extends EventEmitter<IPublicAPIEvent> {

// Link "seeking" and "seeked" events (once the content is loaded)
loaded$.pipe(
switchMapTo(emitSeekEvents(this.videoElement, observation$)),
switchMap(() => emitSeekEvents(this.videoElement, observation$)),
takeUntil(stopContent$)
).subscribe((evt : "seeking" | "seeked") => {
log.info(`API: Triggering "${evt}" event`);
Expand Down
1 change: 1 addition & 0 deletions src/core/eme/__tests__/__global__/init_data.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-call */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/no-unsafe-argument */
/* eslint-disable @typescript-eslint/restrict-template-expressions */
/* eslint-disable @typescript-eslint/no-explicit-any */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-call */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/no-unsafe-argument */
/* eslint-disable @typescript-eslint/no-explicit-any */

import {
Expand Down
1 change: 1 addition & 0 deletions src/core/eme/__tests__/__global__/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-call */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/no-unsafe-argument */
/* eslint-disable no-restricted-properties */

import {
Expand Down
5 changes: 5 additions & 0 deletions src/core/eme/clear_eme_session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ export default function clearEMESession(
{
log.info("EME: closing all current sessions.");
return currentState.loadedSessionsStore.closeAllSessions()
// NOTE As of now (RxJS 7.4.0), RxJS defines `ignoreElements` default
// first type parameter as `any` instead of the perfectly fine `unknown`,
// leading to linter issues, as it forbids the usage of `any`.
// This is why we're disabling the eslint rule.
/* eslint-disable-next-line @typescript-eslint/no-unsafe-argument */
.pipe(ignoreElements());
}
log.info("EME: Nothing to clear. Returning right away. No state =",
Expand Down
4 changes: 2 additions & 2 deletions src/core/eme/dispose_media_keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import {
defer as observableDefer,
mergeMapTo,
mergeMap,
Observable,
of as observableOf,
} from "rxjs";
Expand All @@ -41,6 +41,6 @@ export default function disposeMediaKeys(
const { loadedSessionsStore } = currentState;
MediaKeysInfosStore.clearState(mediaElement);
return loadedSessionsStore.closeAllSessions()
.pipe(mergeMapTo(setMediaKeys(mediaElement, null)));
.pipe(mergeMap(() => setMediaKeys(mediaElement, null)));
});
}
5 changes: 2 additions & 3 deletions src/core/eme/session_events_listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
EMPTY,
identity,
map,
mapTo,
merge as observableMerge,
mergeMap,
Observable,
Expand Down Expand Up @@ -287,8 +286,8 @@ function updateSessionWithMessage(
throw new EncryptedMediaError("KEY_UPDATE_ERROR", reason);
}),
tap(() => { log.info("EME: MediaKeySession update succeeded."); }),
mapTo({ type: "session-updated" as const,
value: { session, license: message, initializationData } })
map(() => ({ type: "session-updated" as const,
value: { session, license: message, initializationData } }))
);
}

Expand Down
Loading

0 comments on commit 07b88fa

Please sign in to comment.