mirror of
https://github.com/yume-chan/ya-webadb.git
synced 2025-10-05 19:42:15 +02:00
chore: integrate ESLint
This commit is contained in:
parent
8bcd0ab913
commit
aa033e4de6
177 changed files with 5604 additions and 3798 deletions
11
libraries/scrcpy-decoder-webcodecs/.eslintrc.cjs
Normal file
11
libraries/scrcpy-decoder-webcodecs/.eslintrc.cjs
Normal file
|
@ -0,0 +1,11 @@
|
|||
module.exports = {
|
||||
"extends": [
|
||||
"@yume-chan"
|
||||
],
|
||||
parserOptions: {
|
||||
tsconfigRootDir: __dirname,
|
||||
project: [
|
||||
"./tsconfig.test.json"
|
||||
],
|
||||
},
|
||||
}
|
16
libraries/scrcpy-decoder-webcodecs/.npmignore
Normal file
16
libraries/scrcpy-decoder-webcodecs/.npmignore
Normal file
|
@ -0,0 +1,16 @@
|
|||
.rush
|
||||
|
||||
# Test
|
||||
coverage
|
||||
**/*.spec.ts
|
||||
**/*.spec.js
|
||||
**/*.spec.js.map
|
||||
**/__helpers__
|
||||
jest.config.js
|
||||
|
||||
.eslintrc.cjs
|
||||
tsconfig.json
|
||||
tsconfig.test.json
|
||||
|
||||
# Logs
|
||||
*.log
|
|
@ -29,6 +29,7 @@
|
|||
"build": "tsc -b tsconfig.build.json",
|
||||
"build:watch": "tsc -b tsconfig.build.json",
|
||||
"//test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage",
|
||||
"lint": "eslint src/**/*.ts --fix",
|
||||
"prepublishOnly": "npm run build"
|
||||
},
|
||||
"dependencies": {
|
||||
|
@ -39,10 +40,12 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@jest/globals": "^29.3.1",
|
||||
"@yume-chan/ts-package-builder": "workspace:^1.0.0",
|
||||
"@yume-chan/eslint-config": "workspace:^1.0.0",
|
||||
"@yume-chan/tsconfig": "workspace:^1.0.0",
|
||||
"cross-env": "^7.0.3",
|
||||
"eslint": "^8.30.0",
|
||||
"jest": "^29.3.1",
|
||||
"ts-jest": "^29.0.3",
|
||||
"typescript": "^4.8.4"
|
||||
"typescript": "^4.9.4"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
import type { H264Configuration, ScrcpyVideoStreamPacket } from '@yume-chan/scrcpy';
|
||||
import { WritableStream } from '@yume-chan/stream-extra';
|
||||
import {
|
||||
type H264Configuration,
|
||||
type ScrcpyVideoStreamPacket,
|
||||
} from "@yume-chan/scrcpy";
|
||||
import { WritableStream } from "@yume-chan/stream-extra";
|
||||
|
||||
function toHex(value: number) {
|
||||
return value.toString(16).padStart(2, '0').toUpperCase();
|
||||
return value.toString(16).padStart(2, "0").toUpperCase();
|
||||
}
|
||||
|
||||
export class WebCodecsDecoder {
|
||||
|
@ -12,25 +15,31 @@ export class WebCodecsDecoder {
|
|||
public readonly maxLevel = undefined;
|
||||
|
||||
private _writable: WritableStream<ScrcpyVideoStreamPacket>;
|
||||
public get writable() { return this._writable; }
|
||||
public get writable() {
|
||||
return this._writable;
|
||||
}
|
||||
|
||||
private _renderer: HTMLCanvasElement;
|
||||
public get renderer() { return this._renderer; }
|
||||
public get renderer() {
|
||||
return this._renderer;
|
||||
}
|
||||
|
||||
private _frameRendered = 0;
|
||||
public get frameRendered() { return this._frameRendered; }
|
||||
public get frameRendered() {
|
||||
return this._frameRendered;
|
||||
}
|
||||
|
||||
private context: CanvasRenderingContext2D;
|
||||
private decoder: VideoDecoder;
|
||||
|
||||
// Limit FPS to system refresh rate
|
||||
private lastFrame: VideoFrame | undefined;
|
||||
private animationFrame: number = 0;
|
||||
private animationFrame = 0;
|
||||
|
||||
public constructor() {
|
||||
this._renderer = document.createElement('canvas');
|
||||
this._renderer = document.createElement("canvas");
|
||||
|
||||
this.context = this._renderer.getContext('2d')!;
|
||||
this.context = this._renderer.getContext("2d")!;
|
||||
this.decoder = new VideoDecoder({
|
||||
output: (frame) => {
|
||||
if (this.lastFrame) {
|
||||
|
@ -43,25 +52,30 @@ export class WebCodecsDecoder {
|
|||
this.render();
|
||||
}
|
||||
},
|
||||
error() { },
|
||||
error(e) {
|
||||
void e;
|
||||
},
|
||||
});
|
||||
|
||||
this._writable = new WritableStream<ScrcpyVideoStreamPacket>({
|
||||
write: async (packet) => {
|
||||
write: (packet) => {
|
||||
switch (packet.type) {
|
||||
case 'configuration':
|
||||
case "configuration":
|
||||
this.configure(packet.data);
|
||||
break;
|
||||
case 'frame':
|
||||
this.decoder.decode(new EncodedVideoChunk({
|
||||
// Treat `undefined` as `key`, otherwise won't decode.
|
||||
type: packet.keyframe === false ? 'delta' : 'key',
|
||||
timestamp: 0,
|
||||
data: packet.data,
|
||||
}));
|
||||
case "frame":
|
||||
this.decoder.decode(
|
||||
new EncodedVideoChunk({
|
||||
// Treat `undefined` as `key`, otherwise won't decode.
|
||||
type:
|
||||
packet.keyframe === false ? "delta" : "key",
|
||||
timestamp: 0,
|
||||
data: packet.data,
|
||||
})
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -84,7 +98,9 @@ export class WebCodecsDecoder {
|
|||
|
||||
// https://www.rfc-editor.org/rfc/rfc6381#section-3.3
|
||||
// ISO Base Media File Format Name Space
|
||||
const codec = `avc1.${[profileIndex, constraintSet, levelIndex].map(toHex).join('')}`;
|
||||
const codec = `avc1.${[profileIndex, constraintSet, levelIndex]
|
||||
.map(toHex)
|
||||
.join("")}`;
|
||||
this.decoder.configure({
|
||||
codec: codec,
|
||||
optimizeForLatency: true,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"extends": "./node_modules/@yume-chan/ts-package-builder/tsconfig.base.json",
|
||||
"extends": "./node_modules/@yume-chan/tsconfig/tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"lib": [
|
||||
"ESNext",
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
{
|
||||
"extends": "./tsconfig.build.json",
|
||||
"compilerOptions": {
|
||||
"types": [
|
||||
],
|
||||
},
|
||||
"exclude": []
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue