From 5e13cbee14172ee14d3e79d9fa645c1de256f66d Mon Sep 17 00:00:00 2001 From: Robin Steinberg Date: Tue, 24 Aug 2021 22:27:20 +0200 Subject: [PATCH] Initial commit --- .gitignore | 102 +++++++++++++++++++++++++++++++++++++++++++++ .vscode/tasks.json | 36 ++++++++++++++++ index.html | 26 ++++++++++++ package.json | 21 ++++++++++ ts/app.ts | 71 +++++++++++++++++++++++++++++++ tsconfig.json | 11 +++++ 6 files changed, 267 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/tasks.json create mode 100644 index.html create mode 100644 package.json create mode 100644 ts/app.ts create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8781662 --- /dev/null +++ b/.gitignore @@ -0,0 +1,102 @@ +dist/ + +node_modules/ +.node_modules/ +built/* +tests/cases/rwc/* +tests/cases/test262/* +tests/cases/perf/* +!tests/cases/webharness/compilerToString.js +test-args.txt +~*.docx +\#*\# +.\#* +tests/baselines/local/* +tests/baselines/local.old/* +tests/services/baselines/local/* +tests/baselines/prototyping/local/* +tests/baselines/rwc/* +tests/baselines/test262/* +tests/baselines/reference/projectOutput/* +tests/baselines/local/projectOutput/* +tests/baselines/reference/testresults.tap +tests/services/baselines/prototyping/local/* +tests/services/browser/typescriptServices.js +src/harness/*.js +src/compiler/diagnosticInformationMap.generated.ts +src/compiler/diagnosticMessages.generated.json +src/parser/diagnosticInformationMap.generated.ts +src/parser/diagnosticMessages.generated.json +rwc-report.html +*.swp +build.json +*.actual +tests/webTestServer.js +tests/webTestServer.js.map +tests/webhost/*.d.ts +tests/webhost/webtsc.js +tests/cases/**/*.js +!tests/cases/docker/*.js/ +tests/cases/**/*.js.map +*.config +scripts/eslint/built/ +scripts/debug.bat +scripts/run.bat +scripts/word2md.js +scripts/buildProtocol.js +scripts/ior.js +scripts/authors.js +scripts/configurePrerelease.js +scripts/configureLanguageServiceBuild.js +scripts/open-user-pr.js +scripts/open-cherry-pick-pr.js +scripts/processDiagnosticMessages.d.ts +scripts/processDiagnosticMessages.js +scripts/produceLKG.js +scripts/importDefinitelyTypedTests/importDefinitelyTypedTests.js +scripts/generateLocalizedDiagnosticMessages.js +scripts/request-pr-review.js +scripts/*.js.map +scripts/typings/ +coverage/ +internal/ +**/.DS_Store +.settings +**/.vs +**/.vscode/* +!**/.vscode/tasks.json +!**/.vscode/settings.template.json +!**/.vscode/launch.template.json +!**/.vscode/extensions.json +!tests/cases/projects/projectOption/**/node_modules +!tests/cases/projects/NodeModulesSearch/**/* +!tests/baselines/reference/project/nodeModules*/**/* +.idea +yarn.lock +yarn-error.log +.parallelperf.* +tests/cases/user/*/package-lock.json +tests/cases/user/*/node_modules/ +tests/cases/user/*/**/*.js +tests/cases/user/*/**/*.js.map +tests/cases/user/*/**/*.d.ts +!tests/cases/user/zone.js/ +!tests/cases/user/bignumber.js/ +!tests/cases/user/discord.js/ +tests/baselines/reference/dt +.failed-tests +TEST-results.xml +package-lock.json +tests/cases/user/npm/npm +tests/cases/user/TypeScript-React-Starter/TypeScript-React-Starter +tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter +tests/cases/user/TypeScript-React-Native-Starter/TypeScript-React-Native-Starter +tests/cases/user/TypeScript-Vue-Starter/TypeScript-Vue-Starter +tests/cases/user/TypeScript-WeChat-Starter/TypeScript-WeChat-Starter +tests/cases/user/create-react-app/create-react-app +tests/cases/user/fp-ts/fp-ts +tests/cases/user/webpack/webpack +tests/cases/user/puppeteer/puppeteer +tests/cases/user/axios-src/axios-src +tests/cases/user/prettier/prettier +.eslintcache diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..f07746b --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,36 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "npm", + "script": "debug", + "label": "npm debug", + "isBackground": true, + "problemMatcher": [ + "$tsc-watch" + ] + }, + { + "type": "typescript", + "tsconfig": "tsconfig.json", + "option": "watch", + "problemMatcher": [ + "$tsc-watch" + ], + "group": "build", + "label": "tsc: Watch" + }, + { + "type": "typescript", + "tsconfig": "tsconfig.json", + "problemMatcher": [ + "$tsc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "label": "tsc: Erstellen – tsconfig.json" + } + ] +} diff --git a/index.html b/index.html new file mode 100644 index 0000000..db244da --- /dev/null +++ b/index.html @@ -0,0 +1,26 @@ + + + + Canvas Receiver + + + +
+ + + + diff --git a/package.json b/package.json new file mode 100644 index 0000000..c00c45a --- /dev/null +++ b/package.json @@ -0,0 +1,21 @@ +{ + "name": "canvas", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "build": "tsc -p ./", + "watch": "tsc -watch -p ./", + "serve": "serve -l 8082 .", + "debug": "npm-run-all --parallel watch serve", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "devDependencies": { + "@tsconfig/recommended": "^1.0.1", + "npm-run-all": "^4.1.5", + "serve": "^12.0.0", + "typescript": "^4.3.5" + } +} diff --git a/ts/app.ts b/ts/app.ts new file mode 100644 index 0000000..b2c4951 --- /dev/null +++ b/ts/app.ts @@ -0,0 +1,71 @@ +class CanvasReceiverController { + private canvasDiv: HTMLDivElement; + private canvas!: HTMLCanvasElement; + private ctx!: CanvasRenderingContext2D | null; + private ws: WebSocket; + + constructor() { + this.canvasDiv = document.querySelector('#canvas') as HTMLDivElement; + + this.createCanvas(); + + this.ws = new WebSocket('ws://localhost:8081', 'json'); + + this.ws.onmessage = message => this.processMessage(message); + this.ws.onopen = () => this.ws.send("RECEIVER"); + } + + private createCanvas() { + this.canvas = document.createElement('canvas'); + this.canvasDiv.appendChild(this.canvas); + this.canvas.width = this.canvas.offsetWidth; + this.canvas.height = this.canvas.offsetHeight; + this.ctx = this.canvas.getContext('2d'); + } + + processMessage(message: MessageEvent) { + if (message.data === "CLEAR") { + this.canvasDiv.removeChild(this.canvas); + this.createCanvas(); + } else { + this.draw(JSON.parse(message.data)); + } + } + + draw(path: Coordinates[]) { + if (!this.ctx) { + return; + } + + const first = path.shift(); + + if (!first) { + return; + } + + this.ctx.beginPath(); + this.ctx.moveTo(first.x, first.y); + + for (const cur of path) { + this.ctx.lineTo(cur.x, cur.y); + } + + this.ctx.lineWidth = 1; + this.ctx.stroke(); + } +} + + +class Coordinates { + public x: number; + public y: number; + + constructor(x: number, y: number) { + this.x = x; + this.y = y; + } +} + +const app = new CanvasReceiverController(); + +export { app }; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..7ead152 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "target": "ES2015", + "module": "ES2015", + "outDir": "dist", + "sourceMap": true + }, + "extends": "@tsconfig/recommended/tsconfig.json", + "include": ["ts/**/*"], + "exclude": ["node_modules", "**/*.spec.ts"] +} \ No newline at end of file