Spaces:
Running
on
A10G
Running
on
A10G
GitLab CI
commited on
Commit
·
6f6d855
1
Parent(s):
a2d1655
Update game build from GitLab CI
Browse files- server/static/godot/index.pck +0 -0
- server/static/index.html +90 -46
server/static/godot/index.pck
CHANGED
Binary files a/server/static/godot/index.pck and b/server/static/godot/index.pck differ
|
|
server/static/index.html
CHANGED
@@ -4,7 +4,7 @@
|
|
4 |
<head>
|
5 |
<meta charset="UTF-8">
|
6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
7 |
-
<title>
|
8 |
<style>
|
9 |
html,
|
10 |
body {
|
@@ -34,56 +34,100 @@
|
|
34 |
const serverUrl = "./api/process"
|
35 |
const FETCH_TIMEOUT = 5000 // 5 seconds timeout
|
36 |
|
37 |
-
// Check
|
38 |
-
|
39 |
-
|
40 |
-
alert('Your browser does not support audio recording. Please try using a modern browser like Chrome, Firefox, or Edge.')
|
41 |
-
throw new Error('Audio recording not supported')
|
42 |
-
}
|
43 |
-
|
44 |
-
// Set up audio recording
|
45 |
-
navigator.mediaDevices.getUserMedia({ audio: true })
|
46 |
-
.then(stream => {
|
47 |
-
const audioContext = new (window.AudioContext || window.webkitAudioContext)()
|
48 |
-
const mediaRecorder = new MediaRecorder(stream)
|
49 |
-
const audioChunks = []
|
50 |
|
51 |
-
|
52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
fetch(serverUrl, {
|
64 |
-
method: 'POST',
|
65 |
-
body: formData
|
66 |
-
}).then(response => {
|
67 |
-
console.log('Audio chunk sent successfully')
|
68 |
-
}).catch(error => {
|
69 |
-
console.error('Error sending audio chunk:', error)
|
70 |
-
})
|
71 |
-
}
|
72 |
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
}
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
</script>
|
88 |
</body>
|
89 |
|
|
|
4 |
<head>
|
5 |
<meta charset="UTF-8">
|
6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
7 |
+
<title>Parental Control</title>
|
8 |
<style>
|
9 |
html,
|
10 |
body {
|
|
|
34 |
const serverUrl = "./api/process"
|
35 |
const FETCH_TIMEOUT = 5000 // 5 seconds timeout
|
36 |
|
37 |
+
// Check server availability first
|
38 |
+
const controller = new AbortController()
|
39 |
+
const timeout = setTimeout(() => controller.abort(), FETCH_TIMEOUT)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
+
fetch("./api/data", {
|
42 |
+
method: 'GET',
|
43 |
+
signal: controller.signal
|
44 |
+
})
|
45 |
+
.then(response => {
|
46 |
+
clearTimeout(timeout)
|
47 |
+
if (!response.ok) {
|
48 |
+
throw new Error(`Server check failed: ${response.status}`)
|
49 |
}
|
50 |
+
console.log('Server check successful')
|
51 |
+
setupAudioRecording()
|
52 |
+
})
|
53 |
+
.catch(error => {
|
54 |
+
clearTimeout(timeout)
|
55 |
+
const errorMessage = error.name === 'AbortError'
|
56 |
+
? 'Server request timed out. Please try again later.'
|
57 |
+
: 'Could not connect to the server. Please try again later.'
|
58 |
+
console.error('Server check failed:', error)
|
59 |
+
console.error(errorMessage)
|
60 |
+
throw error
|
61 |
+
})
|
62 |
|
63 |
+
// Move existing audio setup into a function
|
64 |
+
function setupAudioRecording() {
|
65 |
+
// Check if browser supports audio recording
|
66 |
+
if (!navigator.mediaDevices?.getUserMedia) {
|
67 |
+
console.error('Your browser does not support audio recording.')
|
68 |
+
console.error('Please try using a modern browser like Chrome, Firefox, or Edge.')
|
69 |
+
throw new Error('Audio recording not supported')
|
70 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
|
72 |
+
navigator.mediaDevices.getUserMedia({ audio: true })
|
73 |
+
.then(stream => {
|
74 |
+
const audioContext = new (window.AudioContext || window.webkitAudioContext)()
|
75 |
+
const mediaRecorder = new MediaRecorder(stream)
|
76 |
+
const audioChunks = []
|
77 |
+
|
78 |
+
mediaRecorder.ondataavailable = event => {
|
79 |
+
audioChunks.push(event.data)
|
80 |
}
|
81 |
+
|
82 |
+
mediaRecorder.onstop = () => {
|
83 |
+
const audioBlob = new Blob(audioChunks, { type: 'audio/webm' })
|
84 |
+
audioChunks.length = 0 // Clear chunks after creating the Blob
|
85 |
+
|
86 |
+
// Convert Blob to base64
|
87 |
+
const reader = new FileReader()
|
88 |
+
reader.readAsDataURL(audioBlob)
|
89 |
+
reader.onloadend = () => {
|
90 |
+
// Extract the base64 data (remove the data URL prefix)
|
91 |
+
const base64Audio = reader.result.split(',')[1]
|
92 |
+
|
93 |
+
// Send as JSON with base64-encoded audio
|
94 |
+
const audioController = new AbortController()
|
95 |
+
const audioTimeout = setTimeout(() => audioController.abort(), FETCH_TIMEOUT)
|
96 |
+
|
97 |
+
fetch(serverUrl, {
|
98 |
+
method: 'POST',
|
99 |
+
headers: {
|
100 |
+
'Content-Type': 'application/json'
|
101 |
+
},
|
102 |
+
body: JSON.stringify({
|
103 |
+
audio_chunk: base64Audio
|
104 |
+
}),
|
105 |
+
signal: audioController.signal
|
106 |
+
}).then(response => {
|
107 |
+
clearTimeout(audioTimeout)
|
108 |
+
console.log('Audio chunk sent successfully')
|
109 |
+
}).catch(error => {
|
110 |
+
clearTimeout(audioTimeout)
|
111 |
+
console.error('Error sending audio chunk:', error)
|
112 |
+
})
|
113 |
+
}
|
114 |
+
}
|
115 |
+
|
116 |
+
// Start recording in intervals
|
117 |
+
const chunkInterval = 300 // Chunk duration in milliseconds
|
118 |
+
setInterval(() => {
|
119 |
+
if (mediaRecorder.state === 'recording') {
|
120 |
+
mediaRecorder.stop()
|
121 |
+
mediaRecorder.start()
|
122 |
+
} else {
|
123 |
+
mediaRecorder.start()
|
124 |
+
}
|
125 |
+
}, chunkInterval)
|
126 |
+
})
|
127 |
+
.catch(error => {
|
128 |
+
console.error('Error accessing microphone:', error)
|
129 |
+
})
|
130 |
+
}
|
131 |
</script>
|
132 |
</body>
|
133 |
|