|
1 | 1 | <!-- Github Luckystriike: https://github.com/luckystriike22/TresJsPlayground/ --> |
2 | 2 | <script lang="ts" setup> |
3 | | -const analyser = shallowRef(); |
4 | | -const audioStream = shallowRef(); |
5 | | -const dataArray = shallowRef(); |
6 | | -const showInfoDialog = shallowRef(false); |
| 3 | +const analyser = shallowRef() |
| 4 | +const audioStream = shallowRef() |
| 5 | +const dataArray = shallowRef() |
| 6 | +const showInfoDialog = shallowRef(false) |
7 | 7 |
|
8 | 8 | // lifecycle |
9 | 9 | onMounted(async () => { |
10 | | - await nextTick(); |
| 10 | + await nextTick() |
11 | 11 |
|
12 | 12 | try { |
13 | 13 | const access = await navigator.permissions.query({ name: 'microphone' }) |
14 | | - showInfoDialog.value = access.state != "granted"; |
| 14 | + showInfoDialog.value = access.state != 'granted' |
15 | 15 |
|
16 | | - audioStream.value = await navigator.mediaDevices.getUserMedia({ audio: true }); |
17 | | - showInfoDialog.value = false; |
| 16 | + audioStream.value = await navigator.mediaDevices.getUserMedia({ audio: true }) |
| 17 | + showInfoDialog.value = false |
18 | 18 | handleMicrophoneAccess() |
19 | 19 |
|
20 | | - } catch (error) { |
21 | | - showInfoDialog.value = true; |
22 | | - alert('Not able to accessing microphone'); |
| 20 | + } |
| 21 | + catch (error) { |
| 22 | + showInfoDialog.value = true |
| 23 | + alert('Not able to accessing microphone') |
23 | 24 | } |
24 | 25 | }) |
25 | 26 |
|
26 | 27 | // handle the microphone connection |
27 | 28 | const handleMicrophoneAccess = () => { |
28 | | - const audioContext = new (window.AudioContext)(); |
29 | | - const source = audioContext.createMediaStreamSource(audioStream.value); |
| 29 | + const audioContext = new (window.AudioContext)() |
| 30 | + const source = audioContext.createMediaStreamSource(audioStream.value) |
30 | 31 |
|
31 | | - analyser.value = audioContext.createAnalyser(); |
32 | | - analyser.value.fftSize = 2048; |
33 | | - source.connect(analyser.value); |
| 32 | + analyser.value = audioContext.createAnalyser() |
| 33 | + analyser.value.fftSize = 2048 |
| 34 | + source.connect(analyser.value) |
34 | 35 |
|
35 | | - const bufferLength = analyser.value.frequencyBinCount; |
36 | | - dataArray.value = new Uint8Array(bufferLength); |
37 | | -}; |
| 36 | + const bufferLength = analyser.value.frequencyBinCount |
| 37 | + dataArray.value = new Uint8Array(bufferLength) |
| 38 | +} |
38 | 39 | </script> |
39 | 40 |
|
40 | 41 | <template> |
41 | 42 | <button |
42 | | - class="gitBtn bg-gray-600 hover:bg-gray-700 opacity-40 transition-color shadow-lg hover:shadow-xl infline-flex w-12 h-12 justify-center items-center rounded-full absolute bottom-2 right-2"> |
43 | | - <a href="https://github.com/Tresjs/lab/tree/main/components/content/dancing-blob" target="_blank">Code</a> |
| 43 | + class="gitBtn bg-gray-600 hover:bg-gray-700 opacity-40 transition-color shadow-lg hover:shadow-xl infline-flex w-12 h-12 justify-center items-center rounded-full absolute bottom-2 right-2" |
| 44 | + > |
| 45 | + <a |
| 46 | + href="https://github.com/Tresjs/lab/tree/main/components/content/dancing-blob" |
| 47 | + target="_blank" |
| 48 | + >Code</a> |
44 | 49 | </button> |
45 | 50 |
|
46 | | - <TresCanvas :clear-color="'#0c1a30'" v-show="!showInfoDialog"> |
47 | | - <TheDancingBlob :analyser="analyser" :data-array="dataArray" /> |
| 51 | + <TresCanvas |
| 52 | + v-show="!showInfoDialog" |
| 53 | + clear-color="#0c1a30" |
| 54 | + > |
| 55 | + <TheDancingBlob |
| 56 | + :analyser="analyser" |
| 57 | + :data-array="dataArray" |
| 58 | + /> |
48 | 59 | </TresCanvas> |
49 | | - <span class="blobPermissionDialog justify-center items-center infline-flex absolute" v-if="showInfoDialog"> |
| 60 | + <span |
| 61 | + v-if="showInfoDialog" |
| 62 | + class="blobPermissionDialog justify-center items-center infline-flex absolute" |
| 63 | + > |
50 | 64 | <p> |
51 | | - Hey! <br /> |
| 65 | + Hey! <br> |
52 | 66 | This site requires microphone permissions. The |
53 | 67 | microphone is only used to calculate the frequency necessary for the blob to dance. A browser pop-up will ask you |
54 | 68 | for permission. |
55 | 69 | </p> |
56 | 70 | </span> |
57 | | - |
58 | 71 | </template> |
59 | 72 |
|
60 | 73 | <style scoped> |
|
0 commit comments