Skip to content
Snippets Groups Projects
Verified Commit 2a41b343 authored by Jonas Zohren's avatar Jonas Zohren :speech_balloon:
Browse files

Initial commit

parents
No related branches found
No related tags found
No related merge requests found
.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
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'],
plugins: ['svelte3', '@typescript-eslint'],
ignorePatterns: ['*.cjs'],
overrides: [{ files: ['*.svelte'], processor: 'svelte3/svelte3' }],
settings: {
'svelte3/typescript': () => require('typescript')
},
parserOptions: {
sourceType: 'module',
ecmaVersion: 2020
},
env: {
browser: true,
es2017: true,
node: true
}
};
.DS_Store
node_modules
/pages
/.svelte-kit
/package
.env
.env.*
!.env.example
static/*.mp3
\ No newline at end of file
.npmrc 0 → 100644
engine-strict=true
.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
{
"useTabs": true,
"singleQuote": true,
"trailingComma": "none",
"printWidth": 100,
"plugins": ["prettier-plugin-svelte"],
"pluginSearchDirs": ["."],
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
}
# 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.
{
"name": "webapp",
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"test": "playwright test",
"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": {
"@playwright/test": "^1.25.0",
"@sveltejs/adapter-auto": "next",
"@sveltejs/kit": "next",
"@typescript-eslint/eslint-plugin": "^5.27.0",
"@typescript-eslint/parser": "^5.27.0",
"eslint": "^8.16.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-svelte3": "^4.0.0",
"prettier": "^2.6.2",
"prettier-plugin-svelte": "^2.7.0",
"svelte": "^3.44.0",
"svelte-check": "^2.7.1",
"svelte-preprocess": "^4.10.6",
"tslib": "^2.3.1",
"typescript": "^4.7.4",
"vite": "^3.1.0"
},
"type": "module",
"dependencies": {
"@sveltejs/adapter-static": "1.0.0-next.43"
}
}
import type { PlaywrightTestConfig } from '@playwright/test';
const config: PlaywrightTestConfig = {
webServer: {
command: 'npm run build && npm run preview',
port: 4173
}
};
export default config;
This diff is collapsed.
// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces
// and what to do when importing types
declare namespace App {
// interface Locals {}
// interface PageData {}
// interface Error {}
// interface Platform {}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<link rel="stylesheet" href="/water.css" />
<meta name="viewport" content="width=device-width" />
%sveltekit.head%
</head>
<body>
<div>%sveltekit.body%</div>
</body>
</html>
<script lang="ts">
import { browser } from '$app/environment';
const MP3_PATH = '/experiment.mp3';
let audioBlobUrl: string | null = null;
let audioElement: HTMLAudioElement | null = null;
let loaded = false;
let hasClickedParticipateButton = false;
export async function cacheMp3() {
if (!browser) {
return;
}
try {
const rawRes = await fetch(MP3_PATH);
if (!rawRes.ok) {
throw new Error('fetching MP3 file did not succeed');
}
const blob = await rawRes.blob();
if (audioBlobUrl !== null) {
window.URL.revokeObjectURL(audioBlobUrl);
}
audioBlobUrl = window.URL.createObjectURL(blob);
loaded = true;
} catch (e) {
alert(
'Die MP3 konnte nicht geladen werden. Die genaue Fehlermeldung findet sich in der Browser-Konsole.'
);
console.error(e);
}
}
cacheMp3();
let startTime = Date.now() + 5 * 1000;
const rtf1 = new Intl.RelativeTimeFormat('de');
let startsInSec = startsInSeconds();
function startsInSeconds() {
return rtf1.format(Math.floor((startTime - Date.now()) / 1000), 'seconds');
}
setTimeout(startPlaying, startTime - Date.now());
function startPlaying(): void {
if (audioElement === null || startTime > Date.now()) {
return;
}
syncAudioIfNeeded();
}
function neededCurrentMp3Position() {
return Math.round(Date.now() / 1000) - Math.round(startTime / 1000);
}
function syncAudioIfNeeded() {
if (audioElement == null) {
return;
}
if (startTime > Date.now() || Date.now() > startTime + audioElement.duration * 1000) {
// We are outside of the time the audio schould be playing. Pause it:
audioElement.pause();
return;
}
if (Math.abs(neededCurrentMp3Position() - audioElement.currentTime) > 2) {
audioElement.currentTime = neededCurrentMp3Position();
}
if (audioElement.paused) {
try {
audioElement.play();
} catch (error) {
// User probably needs to click button
hasClickedParticipateButton = false;
}
}
}
function clickParticipating(): void {
hasClickedParticipateButton = true;
startPlaying();
}
let position = 0;
let total = 1000;
setInterval(tick, 500);
function tick(): void {
startsInSec = startsInSeconds();
position = Math.floor(neededCurrentMp3Position() ?? 0);
total = Math.floor(audioElement?.duration ?? 1000);
syncAudioIfNeeded();
}
</script>
<h1>MP3-Experiment</h1>
<b>TU Dortmund | 04.10.2022</b>
<br />
<audio
style="width: 100%;"
controls
on:seeked={syncAudioIfNeeded}
src={audioBlobUrl}
bind:this={audioElement}
/>
<hr />
<p>Willkommen beim ersten MP3-Experiment an der TU Dortmund.</p>
<p>
Am 04.10.2022 um 09:40 Uhr geht es los: Verbinde deine Kopfhörer mit deinem Smartphone, klicke auf
den Knopf und folge den Audio-Anweisungen.
</p>
<p>
📍 Startpunkt ist die S-Bahn-Haltestelle <a href="https://goo.gl/maps/kdnqXhC9GvWAUtCE6">
Dortmund Universtität S
</a> (oberirdisch)
</p>
<p>🎧 Bitte vergiss deine Kopfhörer nicht.</p>
{#if neededCurrentMp3Position() <= 0 && position <= 0}
<p>
<b>✋ Bald geht es los.</b> Die MP3 wird automatisch abgespielt. Das Experiment beginnt {startsInSec}.
</p>
{/if}
{#if !hasClickedParticipateButton}
<p>
<b
>⚠️ Um mitzumachen, musst du auf den Knopf drücken, damit diese Website dir Ton abspielen
darf!</b
>
</p>
{/if}
<button
style="width: 100%; height: 5rem; font-size: 1.5rem;"
disabled={hasClickedParticipateButton}
on:click={clickParticipating}
>
{#if hasClickedParticipateButton}
✅ Du machst mit
{:else}
Hier klicken um mitzumachen!
{/if}
</button>
<progress style="width: 100%;" value={position} max={total} />
<input type="checkbox" disabled name="mp3-loaded" id="mp3-loaded" checked={loaded} /> MP3-Datei
geladen
<input
type="checkbox"
disabled
name="participating"
id="participating"
checked={hasClickedParticipateButton}
/>
Macht mit
<details>
<summary>Musik-Lizenzen</summary>
<p>
Für die Zusammenstellung der MP3 haben wir Hintergrundmusik mit Creative Commons-Lizenz benutzt.
Um die Lizenz-Bedingungen zu erfüllen, ist hier eine Auflistung der verwendeten Musik:
</p>
<pre>
Fast Lane by Ghostrifter & Devyzed
Creative Commons — Attribution-NoDerivs 3.0 Unported — CC BY-ND 3.0
Music promoted by https://www.chosic.com/free-music/all/
Natural Love by Imperss | https://soundcloud.com/imperss
Music promoted by https://www.chosic.com/free-music/all/
Creative Commons CC BY 3.0
https://creativecommons.org/licenses/by/3.0/
</pre>
</details>
static/favicon.png

1.53 KiB

This diff is collapsed.
import adapter from '@sveltejs/adapter-static';
import preprocess from 'svelte-preprocess';
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://github.com/sveltejs/svelte-preprocess
// for more information about preprocessors
preprocess: preprocess(),
kit: {
adapter: adapter({
pages: 'pages',
precompress: true,
fallback: 'index.html'
}),
trailingSlash: 'always'
}
};
export default config;
import { expect, test } from '@playwright/test';
test('index page has expected h1', async ({ page }) => {
await page.goto('/');
expect(await page.textContent('h1')).toBe('Welcome to SvelteKit');
});
{
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": 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
}
import { sveltekit } from '@sveltejs/kit/vite';
import type { UserConfig } from 'vite';
const config: UserConfig = {
plugins: [sveltekit()]
};
export default config;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment