audio & express socket.io

This commit is contained in:
bach 2025-02-28 14:51:15 +01:00
parent b1c9f6170b
commit 840ec3e044
13 changed files with 1579 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules

13
audio/index.html Normal file
View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<script src="script.js"></script>
</body>
</html>

BIN
audio/muddy_files.mp3 Normal file

Binary file not shown.

8
audio/script.js Normal file
View File

@ -0,0 +1,8 @@
var myAudio = document.createElement('audio');
myAudio.setAttribute('src','muddy_files.mp3');
myAudio.playbackRate = 0.3;
myAudio.play();

0
audio/style.css Normal file
View File

14
express/assets/front.js Normal file
View File

@ -0,0 +1,14 @@
const socket = io();
var myAudio = document.createElement('audio');
myAudio.setAttribute('src','muddy_files.mp3');
socket.on('speed', (speed) => {
console.log('recieved speed', speed);
myAudio.playbackRate = speed;
});
myAudio.playbackRate = 0.1;
myAudio.play();

Binary file not shown.

7
express/assets/socket.io.min.js vendored Normal file

File diff suppressed because one or more lines are too long

3
express/assets/style.css Normal file
View File

@ -0,0 +1,3 @@
body{
background-color: red;
}

1476
express/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

17
express/package.json Normal file
View File

@ -0,0 +1,17 @@
{
"name": "express",
"version": "1.0.0",
"description": "",
"license": "ISC",
"author": "",
"type": "commonjs",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"express": "^4.21.2",
"pug": "^3.0.3",
"socket.io": "^4.8.1"
}
}

32
express/server.js Normal file
View File

@ -0,0 +1,32 @@
const express = require('express');
const { createServer } = require('node:http');
const { Server } = require('socket.io');
const app = express();
const server = createServer(app);
const io = new Server(server);
const port = 3000
app.set('view engine', 'pug')
app.use(express.static('assets'))
app.get('/', (req, res) => {
// res.send('Hello World!')
res.render('index', { title: 'Hey', message: 'Hello there PUG!' })
})
io.on('connection', (socket) => {
console.log('a user connected');
let speed = 0.1;
setInterval(() => {
speed+=0.1;
socket.emit('speed', speed);
}, 2000);
});
server.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})

8
express/views/index.pug Normal file
View File

@ -0,0 +1,8 @@
html
head
title= title
link(rel="stylesheet", href="style.css")
body
h1= message
script(src="socket.io.min.js")
script(src="front.js")