initial commit

This commit is contained in:
soruh 2023-05-31 23:33:40 +02:00
commit 62739eee28
24 changed files with 5318 additions and 0 deletions

1
backend/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

7
backend/Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "backend"
version = "0.1.0"

8
backend/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "backend"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

3
backend/src/main.rs Normal file
View File

@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}

13
frontend/.eslintignore Normal file
View File

@ -0,0 +1,13 @@
.DS_Store
node_modules
/build
/.svelte-kit
/package
.env
.env.*
!.env.example
# Ignore files for PNPM, NPM and YARN
pnpm-lock.yaml
package-lock.json
yarn.lock

30
frontend/.eslintrc.cjs Normal file
View File

@ -0,0 +1,30 @@
module.exports = {
root: true,
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:svelte/recommended',
'prettier'
],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
parserOptions: {
sourceType: 'module',
ecmaVersion: 2020,
extraFileExtensions: ['.svelte']
},
env: {
browser: true,
es2017: true,
node: true
},
overrides: [
{
files: ['*.svelte'],
parser: 'svelte-eslint-parser',
parserOptions: {
parser: '@typescript-eslint/parser'
}
}
]
};

10
frontend/.gitignore vendored Normal file
View File

@ -0,0 +1,10 @@
.DS_Store
node_modules
/build
/.svelte-kit
/package
.env
.env.*
!.env.example
vite.config.js.timestamp-*
vite.config.ts.timestamp-*

2
frontend/.npmrc Normal file
View File

@ -0,0 +1,2 @@
engine-strict=true
resolution-mode=highest

13
frontend/.prettierignore Normal file
View File

@ -0,0 +1,13 @@
.DS_Store
node_modules
/build
/.svelte-kit
/package
.env
.env.*
!.env.example
# Ignore files for PNPM, NPM and YARN
pnpm-lock.yaml
package-lock.json
yarn.lock

9
frontend/.prettierrc Normal file
View File

@ -0,0 +1,9 @@
{
"useTabs": true,
"singleQuote": true,
"trailingComma": "none",
"printWidth": 100,
"plugins": ["prettier-plugin-svelte"],
"pluginSearchDirs": ["."],
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
}

38
frontend/README.md Normal file
View File

@ -0,0 +1,38 @@
# create-svelte
Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte).
## Creating a project
If you're seeing this, you've probably already done this step. Congrats!
```bash
# create a new project in the current directory
npm create svelte@latest
# create a new project in my-app
npm create svelte@latest my-app
```
## Developing
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
```bash
npm run dev
# or start the server and open the app in a new browser tab
npm run dev -- --open
```
## Building
To create a production version of your app:
```bash
npm run build
```
You can preview the production build with `npm run preview`.
> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.

4885
frontend/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

32
frontend/package.json Normal file
View File

@ -0,0 +1,32 @@
{
"name": "frontend",
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "vite dev --strictPort --port 5173",
"build": "vite build",
"preview": "vite preview --strictPort --port 5173",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "prettier --plugin-search-dir . --check . && eslint .",
"format": "prettier --plugin-search-dir . --write ."
},
"devDependencies": {
"@sveltejs/adapter-auto": "^2.0.0",
"@sveltejs/adapter-static": "^2.0.2",
"@sveltejs/kit": "^1.5.0",
"@typescript-eslint/eslint-plugin": "^5.45.0",
"@typescript-eslint/parser": "^5.45.0",
"eslint": "^8.28.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-svelte": "^2.26.0",
"prettier": "^2.8.0",
"prettier-plugin-svelte": "^2.8.1",
"svelte": "^3.54.0",
"svelte-check": "^3.0.1",
"tslib": "^2.4.1",
"typescript": "^5.0.0",
"vite": "^4.3.0"
},
"type": "module"
}

13
frontend/src/app.d.ts vendored Normal file
View File

@ -0,0 +1,13 @@
// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces
declare global {
namespace App {
// interface Error {}
// interface Locals {}
// interface PageData {}
// interface Platform {}
}
}
export { };

12
frontend/src/app.html Normal file
View File

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width" />
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">
<div style="display: contents">%sveltekit.body%</div>
</body>
</html>

View File

@ -0,0 +1,2 @@
export const prerender = true
export const ssr = false;

View File

@ -0,0 +1,107 @@
<script lang="ts">
import { polyfill_RTCIceCandidate } from './polyfill';
import * as media from './media';
polyfill_RTCIceCandidate();
let media_devices = media.devices;
let available_devices = media.availableDevices;
let video: HTMLMediaElement;
let public_ip: string | null = '';
$: getUserMediaOptions = {
audio: $available_devices.audioinput,
video: $available_devices.videoinput
};
media.initialize().then(() => console.log('options:', getUserMediaOptions));
async function getUserMedia() {
const supportedConstraints = navigator.mediaDevices.getSupportedConstraints();
console.log(supportedConstraints);
const iceServers = [
// Test some TURN server
{
urls: ['turn:turn.h.glsys.de:3478'],
username: 'test',
credential: 'test123'
}
// Test some STUN server
// { urls: ['stun:turn.h.glsys.de:3478'] },
];
let pc = new RTCPeerConnection({ iceServers });
pc.onicecandidate = (e) => {
if (!e.candidate) return;
console.log(e.candidate.candidate);
// If a srflx candidate was found, notify that the STUN server works!
if (e.candidate.type == 'srflx') {
console.log('The STUN server is reachable!');
console.log(` Your Public IP Address is: ${e.candidate.address}`);
public_ip = e.candidate.address;
}
// If a relay candidate was found, notify that the TURN server works!
if (e.candidate.type == 'relay') {
console.log('The TURN server is reachable !');
}
};
pc.onicegatheringstatechange = (e) => {
console.log(e);
};
// Log errors:
// Remember that in most of the cases, even if its working, you will find a STUN host lookup received error
// Chrome tried to look up the IPv6 DNS record for server and got an error in that process. However, it may still be accessible through the IPv4 address
pc.onicecandidateerror = (e) => {
console.error(e);
};
let offer = await pc.createOffer({
offerToReceiveAudio: true
// offerToReceiveVideo: true
});
console.log(offer);
await pc.setLocalDescription(offer);
return;
console.log('options:', getUserMediaOptions);
let stream = await navigator.mediaDevices.getUserMedia(getUserMediaOptions);
let stream2 = await navigator.mediaDevices.getDisplayMedia({ audio: true });
await media.update();
console.log(stream);
video.srcObject = stream;
await video.play();
console.log(stream.getAudioTracks());
console.log(stream.getVideoTracks());
}
</script>
<h1>Welcome</h1>
<p>Your public ip is: {public_ip || 'unknown'}</p>
<button on:click={getUserMedia}>start</button>
<video bind:this={video} />
<p>See also: <a href="/a">a</a></p>
<ul>
{#each $media_devices as device}
<li>{device.kind} | <code>{device.deviceId}</code> | {device.label}</li>
{/each}
</ul>
<div>{JSON.stringify($available_devices)}</div>

View File

@ -0,0 +1 @@
<h1>A</h1>

View File

@ -0,0 +1,37 @@
import { writable, type Writable, derived, type Readable } from 'svelte/store';
export const devices: Writable<MediaDeviceInfo[]> = writable([]);
export const availableDevices: Readable<{
audioinput: boolean,
audiooutput: boolean,
videoinput: boolean,
}> = derived(devices, $devices => {
let available: { [key in MediaDeviceKind]: boolean } = {
audioinput: false,
audiooutput: false,
videoinput: false,
};
for (const device of $devices) {
if (available.hasOwnProperty(device.kind)) available[device.kind] = true;
}
return available;
})
export async function initialize() {
await update();
addEventListener("devicechange", event => {
console.log(event);
update();
});
}
export async function update() {
devices.set(await navigator.mediaDevices.enumerateDevices());
}

View File

@ -0,0 +1,43 @@
export function polyfill_RTCIceCandidate() {
function get_field(candidate: string, n: number): string | null {
return candidate ? candidate.split(' ').slice(n)[0] ?? null : null;
}
function polyfill(prop: string, f: (candidate: string) => any) {
if (!RTCIceCandidate.prototype.hasOwnProperty(prop))
Object.defineProperty(RTCIceCandidate.prototype, prop, {
get: function () {
return f.apply(this, [this.candidate]);
}
});
}
polyfill('foundation', (candidate) => get_field(candidate, 0)?.split(':', 1)[1] ?? null);
polyfill('component', (candidate) => {
let id = get_field(candidate, 1);
if (id == null) return id;
switch (+id) {
case 1:
return 'rtp';
case 2:
return 'rtcp';
default:
return null;
}
});
polyfill('protocol', (candidate) => get_field(candidate, 2)?.toLowerCase() ?? null);
polyfill('priority', (candidate) => get_field(candidate, 3));
polyfill('address', (candidate) => get_field(candidate, 4));
polyfill('port', (candidate) => get_field(candidate, 5));
polyfill('type', (candidate) => get_field(candidate, 7));
polyfill('relatedAddress', (candidate) =>
get_field(candidate, 8) == 'raddr' ? get_field(candidate, 9) : null
);
polyfill('relatedPort', (candidate) => {
let i = get_field(candidate, 8) == 'raddr' ? 10 : 8;
return get_field(candidate, i) == 'rport' ? get_field(candidate, i + 1) : null;
});
polyfill('tcpType', function (this: { protocol: string }, candidate) {
return this.protocol === 'tcp' ? get_field(candidate, -1) : null;
});
}

BIN
frontend/static/favicon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

28
frontend/svelte.config.js Normal file
View File

@ -0,0 +1,28 @@
// import adapter from '@sveltejs/adapter-auto';
import adapter from '@sveltejs/adapter-static';
import { vitePreprocess } from '@sveltejs/kit/vite';
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
// for more information about preprocessors
preprocess: vitePreprocess(),
kit: {
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
// If your environment is not supported or you settled on a specific environment, switch out the adapter.
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
// adapter: adapter()
adapter: adapter({
// default options are shown. On some platforms
// these options are set automatically — see below
pages: 'build',
assets: 'build',
fallback: null,
precompress: false,
strict: true
}),
}
};
export default config;

18
frontend/tsconfig.json Normal file
View File

@ -0,0 +1,18 @@
{
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"strictNullChecks": true
}
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
//
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
// from the referenced tsconfig.json - TypeScript does not merge them in
}

6
frontend/vite.config.ts Normal file
View File

@ -0,0 +1,6 @@
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [sveltekit()]
});