|
21 | 21 | margin: 0 auto; |
22 | 22 | } |
23 | 23 |
|
24 | | - .messages { |
25 | | - width: 100%; |
26 | | - height: 300px; |
27 | | - background: white; |
28 | | - border: 1px solid #ddd; |
29 | | - border-radius: 4px; |
30 | | - padding: 10px; |
31 | | - margin: 20px 0; |
32 | | - font-size: 16px; |
33 | | - font-family: monospace; |
34 | | - resize: vertical; |
35 | | - overflow-y: scroll; |
36 | | - } |
37 | | - |
38 | 24 | .audio-indicator { |
39 | 25 | display: inline-block; |
40 | 26 | width: 20px; |
|
60 | 46 | margin: 20px 0; |
61 | 47 | } |
62 | 48 |
|
| 49 | + .form-group { |
| 50 | + margin-bottom: 15px; |
| 51 | + } |
| 52 | + |
| 53 | + label { |
| 54 | + display: block; |
| 55 | + margin-bottom: 5px; |
| 56 | + font-weight: bold; |
| 57 | + } |
| 58 | + |
63 | 59 | input { |
64 | 60 | width: 100%; |
65 | 61 | padding: 8px; |
66 | 62 | font-size: 16px; |
67 | 63 | border: 1px solid #ddd; |
68 | 64 | border-radius: 4px; |
69 | | - margin-bottom: 10px; |
70 | 65 | } |
71 | 66 |
|
72 | 67 | button { |
@@ -107,11 +102,12 @@ <h1> |
107 | 102 | <span id="audioIndicator" class="audio-indicator"></span> |
108 | 103 | OpenAI WebRTC Audio Session |
109 | 104 | </h1> |
110 | | - |
111 | | - <div class="messages" id="messages"></div> |
112 | 105 |
|
113 | 106 | <div class="controls"> |
114 | | - <input type="password" id="tokenInput" placeholder="Enter your API token"> |
| 107 | + <div class="form-group"> |
| 108 | + <label for="tokenInput">OpenAI API Token</label> |
| 109 | + <input type="password" id="tokenInput"> |
| 110 | + </div> |
115 | 111 | <button id="startButton">Start Session</button> |
116 | 112 | </div> |
117 | 113 |
|
|
136 | 132 | pc.ondatachannel = event => { |
137 | 133 | const channel = event.channel |
138 | 134 | channel.onmessage = msg => { |
139 | | - appendMessage(decoder.decode(msg.data)) |
| 135 | + console.log(decoder.decode(msg.data)) |
140 | 136 | } |
141 | 137 | } |
142 | 138 |
|
@@ -167,20 +163,20 @@ <h1> |
167 | 163 |
|
168 | 164 | const startButton = document.getElementById('startButton') |
169 | 165 | const tokenInput = document.getElementById('tokenInput') |
170 | | -const messages = document.getElementById('messages') |
171 | 166 | const status = document.getElementById('status') |
172 | 167 | const audioIndicator = document.getElementById('audioIndicator') |
173 | 168 |
|
174 | 169 | let peerConnection = null |
175 | 170 | let audioContext = null |
176 | 171 | let audioStream = null |
177 | 172 |
|
178 | | -function appendMessage(text) { |
179 | | - const div = document.createElement('div') |
180 | | - div.textContent = text |
181 | | - messages.appendChild(div) |
182 | | - messages.scrollTop = messages.scrollHeight |
183 | | -} |
| 173 | +// Load saved API key on page load |
| 174 | +document.addEventListener('DOMContentLoaded', () => { |
| 175 | + const savedToken = localStorage.getItem('openai_api_key') |
| 176 | + if (savedToken) { |
| 177 | + tokenInput.value = savedToken |
| 178 | + } |
| 179 | +}) |
184 | 180 |
|
185 | 181 | // Audio visualization |
186 | 182 | function setupAudioVisualization(stream) { |
|
209 | 205 |
|
210 | 206 | async function startSession() { |
211 | 207 | try { |
| 208 | + // Save API key to localStorage |
| 209 | + localStorage.setItem('openai_api_key', tokenInput.value) |
| 210 | + |
212 | 211 | status.className = 'status' |
213 | 212 | status.textContent = 'Requesting microphone access...' |
214 | 213 |
|
|
0 commit comments