Skip to content

Commit

Permalink
Improve Prettier and ESLint configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlika committed Jan 13, 2024
1 parent a600e2e commit 7937c81
Show file tree
Hide file tree
Showing 36 changed files with 235 additions and 290 deletions.
16 changes: 7 additions & 9 deletions .eslintrc.common.cjs
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
module.exports = {
root: true,
env: {
es2021: true
es2021: true,
},
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
"plugin:@typescript-eslint/recommended",
],
plugins: ["@typescript-eslint", "prettier"],
plugins: ["@typescript-eslint"],
ignorePatterns: ["/.eslintrc.cjs", "/lib", "/dist", "/vite.config.ts"],
rules: {
"prettier/prettier": "error",
"no-console": "warn",
"@typescript-eslint/prefer-nullish-coalescing": "error",
"curly": ["warn", "multi-line", "consistent"],
"spaced-comment": ["warn", "always", {"markers": ["/"]}],
"no-debugger": "warn"
}
curly: ["warn", "multi-line", "consistent"],
"spaced-comment": ["warn", "always", { markers: ["/"] }],
"no-debugger": "warn",
},
};
2 changes: 0 additions & 2 deletions .prettierrc.common.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module.exports = {
editorconfig: true,
singleQuote: false,
trailingComma: "es5"
};
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"@typescript-eslint/eslint-plugin": "^6.18.1",
"@typescript-eslint/parser": "^6.18.1",
"eslint": "^8.56.0",
"eslint-plugin-prettier": "^5.1.3",
"prettier": "^3.1.1",
"rimraf": "^5.0.5",
"typescript": "^5.3.3",
Expand Down
4 changes: 2 additions & 2 deletions packages/p2p-media-loader-core/src/bandwidth-calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class BandwidthCalculator {

getBandwidthLoadingOnly(
seconds: number,
ignoreThresholdTimestamp = Number.NEGATIVE_INFINITY
ignoreThresholdTimestamp = Number.NEGATIVE_INFINITY,
) {
if (!this.loadingOnlyTimestamps.length) return 0;
const milliseconds = seconds * 1000;
Expand Down Expand Up @@ -60,7 +60,7 @@ export class BandwidthCalculator {
getBandwidth(
seconds: number,
ignoreThresholdTimestamp = Number.NEGATIVE_INFINITY,
now = performance.now()
now = performance.now(),
) {
if (!this.timestamps.length) return 0;
const milliseconds = seconds * 1000;
Expand Down
10 changes: 5 additions & 5 deletions packages/p2p-media-loader-core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class Core<TStream extends Stream = Stream> {
hasSegment(segmentLocalId: string): boolean {
const segment = StreamUtils.getSegmentFromStreamsMap(
this.streams,
segmentLocalId
segmentLocalId,
);
return !!segment;
}
Expand All @@ -73,7 +73,7 @@ export class Core<TStream extends Stream = Stream> {
updateStream(
streamLocalId: string,
addSegments?: SegmentBase[],
removeSegmentIds?: string[]
removeSegmentIds?: string[],
): void {
const stream = this.streams.get(streamLocalId);
if (!stream) return;
Expand All @@ -94,7 +94,7 @@ export class Core<TStream extends Stream = Stream> {
if (!this.segmentStorage) {
this.segmentStorage = new SegmentsMemoryStorage(
this.manifestResponseUrl,
this.settings
this.settings,
);
await this.segmentStorage.initialize();
}
Expand Down Expand Up @@ -144,7 +144,7 @@ export class Core<TStream extends Stream = Stream> {

const segment = StreamUtils.getSegmentFromStreamsMap(
this.streams,
segmentId
segmentId,
);
if (!segment) {
throw new Error(`Not found segment with id: ${segmentId}`);
Expand All @@ -168,7 +168,7 @@ export class Core<TStream extends Stream = Stream> {
this.settings,
this.bandwidthCalculators,
this.segmentStorage,
this.eventHandlers
this.eventHandlers,
);
};
const streamTypeLoaderKeyMap = {
Expand Down
2 changes: 1 addition & 1 deletion packages/p2p-media-loader-core/src/declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ declare module "bittorrent-tracker" {

on<E extends keyof TrackerClientEvents>(
event: E,
handler: TrackerClientEvents[E]
handler: TrackerClientEvents[E],
): void;

start(): void;
Expand Down
8 changes: 4 additions & 4 deletions packages/p2p-media-loader-core/src/http-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class HttpRequestExecutor {

constructor(
private readonly request: Request,
private readonly settings: HttpSettings
private readonly settings: HttpSettings,
) {
const { byteRange } = this.request.segment;
if (byteRange) this.byteRange = { ...byteRange };
Expand All @@ -42,7 +42,7 @@ export class HttpRequestExecutor {
{
abort: () => this.abortController.abort("abort"),
notReceivingBytesTimeoutMs: httpNotReceivingBytesTimeoutMs,
}
},
);
void this.fetch();
}
Expand Down Expand Up @@ -92,7 +92,7 @@ export class HttpRequestExecutor {
if (response.status !== 206) {
throw new RequestError(
"http-unexpected-status-code",
response.statusText
response.statusText,
);
}
const contentLengthHeader = response.headers.get("Content-Length");
Expand Down Expand Up @@ -146,7 +146,7 @@ export class HttpRequestExecutor {
}

async function* readStream(
reader: ReadableStreamDefaultReader<Uint8Array>
reader: ReadableStreamDefaultReader<Uint8Array>,
): AsyncGenerator<Uint8Array> {
while (true) {
const { done, value } = await reader.read();
Expand Down
30 changes: 15 additions & 15 deletions packages/p2p-media-loader-core/src/hybrid-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class HybridLoader {
private readonly settings: Settings,
private readonly bandwidthCalculators: BandwidthCalculators,
private readonly segmentStorage: SegmentsMemoryStorage,
private readonly eventHandlers?: Pick<CoreEventHandlers, "onSegmentLoaded">
private readonly eventHandlers?: Pick<CoreEventHandlers, "onSegmentLoaded">,
) {
const activeStream = this.lastRequestedSegment.stream;
this.playback = { position: this.lastRequestedSegment.startTime, rate: 1 };
Expand All @@ -49,7 +49,7 @@ export class HybridLoader {
this.requestProcessQueueMicrotask,
this.bandwidthCalculators,
this.playback,
this.settings
this.settings,
);

if (!this.segmentStorage.isInitialized) {
Expand All @@ -60,15 +60,15 @@ export class HybridLoader {
return StreamUtils.isSegmentActualInPlayback(
segment,
this.playback,
this.settings
this.settings,
);
});
this.p2pLoaders = new P2PLoadersContainer(
this.streamManifestUrl,
this.lastRequestedSegment.stream,
this.requests,
this.segmentStorage,
this.settings
this.settings,
);

this.logger = debug(`core:hybrid-loader-${activeStream.type}`);
Expand Down Expand Up @@ -102,7 +102,7 @@ export class HybridLoader {
if (data) {
engineRequest.resolve(
data,
this.bandwidthCalculators.all.getBandwidthLoadingOnly(3)
this.bandwidthCalculators.all.getBandwidthLoadingOnly(3),
);
}
} else {
Expand Down Expand Up @@ -135,7 +135,7 @@ export class HybridLoader {

private processRequests(
queueSegmentIds: Set<string>,
queueDownloadRatio: number
queueDownloadRatio: number,
) {
const { stream } = this.lastRequestedSegment;
const { httpErrorRetries } = this.settings;
Expand Down Expand Up @@ -163,7 +163,7 @@ export class HybridLoader {
if (engineRequest) {
engineRequest.resolve(
request.data,
this.getBandwidth(queueDownloadRatio)
this.getBandwidth(queueDownloadRatio),
);
this.engineRequest = undefined;
}
Expand Down Expand Up @@ -308,7 +308,7 @@ export class HybridLoader {
this.engineRequest.abort();
this.logger(
"abort: ",
LoggerUtils.getSegmentString(this.engineRequest.segment)
LoggerUtils.getSegmentString(this.engineRequest.segment),
);
this.engineRequest = undefined;
}
Expand Down Expand Up @@ -339,7 +339,7 @@ export class HybridLoader {
for (const { segment, statuses } of QueueUtils.generateQueue(
this.lastRequestedSegment,
this.playback,
this.settings
this.settings,
)) {
if (
!statuses.isHttpDownloadable ||
Expand Down Expand Up @@ -372,7 +372,7 @@ export class HybridLoader {

private abortLastHttpLoadingInQueueAfterItem(
queue: QueueUtils.QueueItem[],
segment: Segment
segment: Segment,
): boolean {
for (const { segment: itemSegment } of Utils.arrayBackwards(queue)) {
if (itemSegment === segment) break;
Expand All @@ -387,7 +387,7 @@ export class HybridLoader {

private abortLastP2PLoadingInQueueAfterItem(
queue: QueueUtils.QueueItem[],
segment: Segment
segment: Segment,
): boolean {
for (const { segment: itemSegment } of Utils.arrayBackwards(queue)) {
if (itemSegment === segment) break;
Expand All @@ -408,7 +408,7 @@ export class HybridLoader {
for (const item of QueueUtils.generateQueue(
this.lastRequestedSegment,
this.playback,
this.settings
this.settings,
)) {
maxPossibleLength++;
const { segment } = item;
Expand Down Expand Up @@ -444,19 +444,19 @@ export class HybridLoader {
const bandwidth = Math.max(
all.getBandwidth(30, levelChangedTimestamp),
all.getBandwidth(60, levelChangedTimestamp),
all.getBandwidth(90, levelChangedTimestamp)
all.getBandwidth(90, levelChangedTimestamp),
);
if (queueDownloadRatio >= 0.8 || bandwidth >= activeLevelBitrate * 0.9) {
return Math.max(
all.getBandwidthLoadingOnly(1),
all.getBandwidthLoadingOnly(3),
all.getBandwidthLoadingOnly(5)
all.getBandwidthLoadingOnly(5),
);
}
const httpRealBandwidth = Math.max(
http.getBandwidthLoadingOnly(1),
http.getBandwidthLoadingOnly(3),
http.getBandwidthLoadingOnly(5)
http.getBandwidthLoadingOnly(5),
);
return Math.max(bandwidth, httpRealBandwidth);
}
Expand Down
Loading

0 comments on commit 7937c81

Please sign in to comment.