Skip to content

Commit 033cb8a

Browse files
committed
add prettier
1 parent a5ea764 commit 033cb8a

File tree

16 files changed

+408
-251
lines changed

16 files changed

+408
-251
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

.prettierrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

audio-context/index.html

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,41 @@
55
</head>
66
<body>
77
<div>
8-
<div style="font-family: sans-serif">
9-
Volume: <input type="range" id="volumeSlider" min="0" max="2" value="1" step="0.01" />
10-
Reverb: <input type="checkbox" id="reverbToggle" />
11-
Noise: <input type="checkbox" id="noiseToggle" />
12-
</div>
13-
<div id="cloudComputerDiv" style="height:720px;width:1280px"></div>
8+
<div style="font-family: sans-serif">
9+
Volume:
10+
<input
11+
type="range"
12+
id="volumeSlider"
13+
min="0"
14+
max="2"
15+
value="1"
16+
step="0.01"
17+
/>
18+
Reverb: <input type="checkbox" id="reverbToggle" /> Noise:
19+
<input type="checkbox" id="noiseToggle" />
20+
</div>
21+
<div id="cloudComputerDiv" style="height: 720px; width: 1280px"></div>
1422
</div>
1523
<script type="module">
16-
import Hyperbeam from 'https://unpkg.com/@hyperbeam/web@latest/dist/index.js';
24+
import Hyperbeam from "https://unpkg.com/@hyperbeam/web@latest/dist/index.js";
1725
const audioCtx = new (window.AudioContext || window.webkitAudioContext)();
1826
const gainNode = audioCtx.createGain();
1927
const noiseNode = brownNoise(audioCtx);
2028
const reverbNode = reverb(audioCtx, 2, 4);
21-
const resp = await fetch('/computer');
29+
const resp = await fetch("/computer");
2230
const data = await resp.json();
2331
const hb = await Hyperbeam(cloudComputerDiv, data.embed_url, {
24-
audioTrackCb: tryAudio
32+
audioTrackCb: tryAudio,
2533
});
2634

27-
let source
35+
let source;
2836
function tryAudio(track) {
2937
// audioCtx.createMediaStreamTrackSource(track) is only supported by Firefox
3038
const stream = new MediaStream([track]);
3139
source = audioCtx.createMediaStreamSource(stream);
3240
source.connect(gainNode);
3341
gainNode.connect(audioCtx.destination);
34-
console.log('connected audio track:', track);
42+
console.log("connected audio track:", track);
3543
}
3644

3745
function enableReverb() {
@@ -51,38 +59,38 @@
5159
noiseNode.disconnect();
5260
}
5361

54-
volumeSlider.addEventListener('input', (e) => {
62+
volumeSlider.addEventListener("input", (e) => {
5563
gainNode.gain.value = e.target.value;
5664
});
5765

58-
reverbToggle.addEventListener('change', (e) => {
66+
reverbToggle.addEventListener("change", (e) => {
5967
if (e.target.checked) {
6068
enableReverb();
6169
} else {
6270
disableReverb();
6371
}
64-
})
72+
});
6573

66-
noiseToggle.addEventListener('change', (e) => {
74+
noiseToggle.addEventListener("change", (e) => {
6775
if (e.target.checked) {
6876
enableNoise();
6977
} else {
7078
disableNoise();
7179
}
72-
})
80+
});
7381

74-
window.addEventListener('mouseup', async () => {
82+
window.addEventListener("mouseup", async () => {
7583
// AudioContext will start in a suspended state if no user gestures
7684
// have been received on the page: need to check if suspended and resume
77-
if (audioCtx.state === 'suspended') {
85+
if (audioCtx.state === "suspended") {
7886
try {
7987
await audioCtx.resume();
80-
console.log('audioCtx state:', audioCtx.state);
88+
console.log("audioCtx state:", audioCtx.state);
8189
} catch (e) {
8290
console.error(e);
8391
}
8492
}
85-
})
93+
});
8694

8795
// Inspired by https://github.com/web-audio-components/simple-reverb/blob/master/index.js
8896
function reverb(ctx, seconds, decay, reverse = false) {
@@ -93,8 +101,10 @@
93101
const impulseR = impulse.getChannelData(1);
94102
for (let i = 0; i < length; i++) {
95103
const n = reverse ? length - i : i;
96-
impulseL[i] = (Math.random() * 2 - 1) * Math.pow(1 - n / length, decay);
97-
impulseR[i] = (Math.random() * 2 - 1) * Math.pow(1 - n / length, decay);
104+
impulseL[i] =
105+
(Math.random() * 2 - 1) * Math.pow(1 - n / length, decay);
106+
impulseR[i] =
107+
(Math.random() * 2 - 1) * Math.pow(1 - n / length, decay);
98108
}
99109
const reverbNode = ctx.createConvolver();
100110
reverbNode.buffer = impulse;
@@ -107,18 +117,17 @@
107117
const bufferSize = 4096;
108118
let lastOut = 0.0;
109119
const node = ctx.createScriptProcessor(bufferSize, 1, 1);
110-
node.onaudioprocess = function(e) {
120+
node.onaudioprocess = function (e) {
111121
let output = e.outputBuffer.getChannelData(0);
112122
for (let i = 0; i < bufferSize; i++) {
113123
const white = Math.random() * 2 - 1;
114-
output[i] = (lastOut + (0.02 * white)) / 1.02;
124+
output[i] = (lastOut + 0.02 * white) / 1.02;
115125
lastOut = output[i];
116126
output[i] *= 3.5; // (roughly) compensate for gain
117127
}
118-
}
128+
};
119129
return node;
120130
}
121131
</script>
122-
</div>
123132
</body>
124133
</html>

audio-context/server.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
const path = require('path');
2-
const express = require('express');
3-
const axios = require('axios');
1+
const path = require("path");
2+
const express = require("express");
3+
const axios = require("axios");
44
const app = express();
55

6-
app.get('/', (req, res) => {
7-
res.sendFile(path.join(__dirname, '/index.html'));
6+
app.get("/", (req, res) => {
7+
res.sendFile(path.join(__dirname, "/index.html"));
88
});
99

1010
// Get a cloud computer object. If no object exists, create it.
1111
let computer;
12-
app.get('/computer', async (req, res) => {
12+
app.get("/computer", async (req, res) => {
1313
if (computer) {
1414
res.send(computer);
1515
return;
@@ -18,16 +18,20 @@ app.get('/computer', async (req, res) => {
1818
start_url: "https://youtube.com/watch?v=EcBPaZwjWQc",
1919
ublock: true,
2020
timeout: {
21-
offline: 10
21+
offline: 10,
2222
},
2323
};
24-
const resp = await axios.post('https://engine.hyperbeam.com/v0/vm', hbConfig, {
25-
headers: { 'Authorization': `Bearer ${process.env.HB_API_KEY}` }
26-
});
24+
const resp = await axios.post(
25+
"https://engine.hyperbeam.com/v0/vm",
26+
hbConfig,
27+
{
28+
headers: { Authorization: `Bearer ${process.env.HB_API_KEY}` },
29+
}
30+
);
2731
computer = resp.data;
2832
res.send(computer);
29-
})
33+
});
3034

3135
app.listen(8080, () => {
32-
console.log('Server start at http://localhost:8080');
36+
console.log("Server start at http://localhost:8080");
3337
});

chrome-extension/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Visit http://localhost:8080. You should see the "Hello Extensions" extension pin
2929
Have you modified the extension code and want to run your modified extension? First, terminate the server by pressing CTRL+C. After that, run the following commands:
3030

3131
```bash
32-
npm run build
32+
npm run build
3333
npm run start
3434
```
3535

chrome-extension/server.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ const zipPath = path.resolve(__dirname, "./extension.zip");
99
const vmConfig = {
1010
offline_timeout: 300,
1111
extension: {
12-
field: "ex"
13-
}
12+
field: "ex",
13+
},
1414
};
1515

1616
let computer;
17-
app.get('/', async (req, res) => {
17+
app.get("/", async (req, res) => {
1818
if (computer) {
1919
res.redirect(302, computer.embed_url);
2020
return;
@@ -27,11 +27,15 @@ app.get('/', async (req, res) => {
2727
const headers = formData.getHeaders();
2828
headers["Authorization"] = `Bearer ${process.env.HB_API_KEY}`;
2929

30-
const resp = await axios.post('https://engine.hyperbeam.com/v0/vm', formData, {headers});
30+
const resp = await axios.post(
31+
"https://engine.hyperbeam.com/v0/vm",
32+
formData,
33+
{ headers }
34+
);
3135
computer = resp.data;
3236
res.redirect(302, computer.embed_url);
3337
});
3438

3539
app.listen(8080, () => {
36-
console.log('Server start at http://localhost:8080');
40+
console.log("Server start at http://localhost:8080");
3741
});

multicursor/index.html

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,34 +31,43 @@
3131
<body>
3232
<div id="hb-computer-container"></div>
3333
<div class="cursor hidden">
34-
<svg class="icon" width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
34+
<svg
35+
class="icon"
36+
width="32"
37+
height="32"
38+
viewBox="0 0 32 32"
39+
fill="none"
40+
xmlns="http://www.w3.org/2000/svg"
41+
>
3542
<path
3643
d="M14.3331 24.4662C14.4454 24.758 14.8616 24.7486 14.9605 24.4519L17.3333 17.3333L24.4519 14.9605C24.7486 14.8616 24.758 14.4454 24.4662 14.3331L8.70001 8.26923C8.43043 8.16555 8.16555 8.43043 8.26923 8.70001L14.3331 24.4662Z"
37-
fill="red" />
44+
fill="red"
45+
/>
3846
<path
3947
d="M14.3331 24.4662C14.4454 24.758 14.8616 24.7486 14.9605 24.4519L17.3333 17.3333L24.4519 14.9605C24.7486 14.8616 24.758 14.4454 24.4662 14.3331L8.70001 8.26923C8.43043 8.16555 8.16555 8.43043 8.26923 8.70001L14.3331 24.4662Z"
4048
stroke="white"
41-
stroke-linejoin="round" />
49+
stroke-linejoin="round"
50+
/>
4251
</svg>
4352
</div>
4453
<script type="module">
45-
import Hyperbeam from 'https://unpkg.com/@hyperbeam/web@latest/dist/index.js'
54+
import Hyperbeam from "https://unpkg.com/@hyperbeam/web@latest/dist/index.js";
4655

47-
const resp = await fetch('/computer');
56+
const resp = await fetch("/computer");
4857
const data = await resp.json();
49-
const cursorNode = document.querySelector('.cursor')
58+
const cursorNode = document.querySelector(".cursor");
5059

51-
const container = document.getElementById('hb-computer-container');
60+
const container = document.getElementById("hb-computer-container");
5261
const rect = container.getBoundingClientRect();
5362
const cursors = new Map();
5463

5564
function newCursor(userId) {
56-
const elm = cursorNode.cloneNode(true)
57-
elm.classList.remove('hidden')
65+
const elm = cursorNode.cloneNode(true);
66+
elm.classList.remove("hidden");
5867
document.body.appendChild(elm);
5968
const onCloseTimeout = () => {
60-
cursors.delete(userId);
61-
elm.remove();
69+
cursors.delete(userId);
70+
elm.remove();
6271
};
6372
const onFadeTimeout = () => {
6473
elm.style.opacity = 0;
@@ -67,7 +76,7 @@
6776
let fadeTimeout = setTimeout(onFadeTimeout, 5000);
6877
const update = (p) => {
6978
elm.style.opacity = 1;
70-
elm.style.setProperty('transform', `translate(${p[0]}px, ${p[1]}px)`);
79+
elm.style.setProperty("transform", `translate(${p[0]}px, ${p[1]}px)`);
7180
clearTimeout(closeTimeout);
7281
clearTimeout(fadeTimeout);
7382
closeTimeout = setTimeout(onCloseTimeout, 9000);
@@ -87,7 +96,7 @@
8796
container.offsetHeight * y + rect.top,
8897
];
8998
updateCursor(position);
90-
}
99+
},
91100
});
92101
</script>
93102
</body>

multicursor/server.js

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,46 @@
1-
const path = require('path');
2-
const express = require('express');
3-
const axios = require('axios');
1+
const path = require("path");
2+
const express = require("express");
3+
const axios = require("axios");
44
const app = express();
55

6-
app.get('/', (req, res) => {
7-
res.sendFile(path.join(__dirname, '/index.html'));
6+
app.get("/", (req, res) => {
7+
res.sendFile(path.join(__dirname, "/index.html"));
88
});
99

1010
// Get a cloud computer object. If no object exists, create it.
1111
let computer;
12-
app.get('/computer', async (req, res) => {
12+
app.get("/computer", async (req, res) => {
1313
if (computer) {
1414
res.send(computer);
1515
return;
1616
}
17-
const roles = ['control', 'clipboard_copy', 'programmatic_navigation', 'cursor_data'];
17+
const roles = [
18+
"control",
19+
"clipboard_copy",
20+
"programmatic_navigation",
21+
"cursor_data",
22+
];
1823
const hbConfig = {
1924
hide_cursor: true,
2025
default_roles: roles,
2126
timeout: {
22-
offline: 10
27+
offline: 10,
2328
},
2429
quality: {
25-
mode: 'sharp'
26-
}
30+
mode: "sharp",
31+
},
2732
};
28-
const resp = await axios.post('https://engine.hyperbeam.com/v0/vm', hbConfig, {
29-
headers: { 'Authorization': `Bearer ${process.env.HB_API_KEY}` }
30-
});
33+
const resp = await axios.post(
34+
"https://engine.hyperbeam.com/v0/vm",
35+
hbConfig,
36+
{
37+
headers: { Authorization: `Bearer ${process.env.HB_API_KEY}` },
38+
}
39+
);
3140
computer = resp.data;
3241
res.send(computer);
3342
});
3443

3544
app.listen(8080, () => {
36-
console.log('Server start at http://localhost:8080');
45+
console.log("Server start at http://localhost:8080");
3746
});

0 commit comments

Comments
 (0)