commit3r commited on
Commit
c185c93
·
verified ·
1 Parent(s): 2caf0dc

remove all the frills and there is no way to enter another peers id - Follow Up Deployment

Browse files
Files changed (1) hide show
  1. index.html +19 -149
index.html CHANGED
@@ -137,25 +137,12 @@
137
 
138
  <!-- Main Content -->
139
  <div class="bg-[#c0c0c0] p-4">
140
- <!-- Connection Info -->
141
- <div class="mb-4 flex items-center justify-between">
142
- <div class="flex items-center">
143
- <span class="mr-2">Status:</span>
144
- <div id="status" class="bg-[#28c940] px-2 py-1 text-xs font-bold">CONNECTING...</div>
145
- </div>
146
- <div class="flex items-center">
147
- <span class="mr-2">Peer ID:</span>
148
- <div id="peer-id" class="peer-id">Generating...</div>
149
- </div>
150
- </div>
151
 
152
  <!-- Message Display -->
153
  <div class="message-box mb-4 h-64 overflow-hidden">
154
  <div id="message-container" class="terminal-text p-3 h-full overflow-y-auto scrollbar">
155
- <div>> Initializing WebRTC connection...</div>
156
- <div>> Using public STUN servers</div>
157
- <div>> Establishing peer connection...</div>
158
- <div id="connection-status" class="blink">> Waiting for peers</div>
159
  </div>
160
  </div>
161
 
@@ -172,159 +159,42 @@
172
  </div>
173
  </div>
174
 
175
- <!-- Status Bar -->
176
- <div class="status-bar px-3 py-1 flex justify-between text-xs">
177
- <div>Connected Peers: <span id="peer-count">0</span></div>
178
- <div>RetroText Stream v1.0</div>
179
- </div>
180
  </div>
181
 
182
  <script>
183
  document.addEventListener('DOMContentLoaded', () => {
184
- // DOM Elements
185
  const messageContainer = document.getElementById('message-container');
186
  const messageInput = document.getElementById('message-input');
187
  const sendBtn = document.getElementById('send-btn');
188
- const statusIndicator = document.getElementById('status');
189
- const peerIdDisplay = document.getElementById('peer-id');
190
- const connectionStatus = document.getElementById('connection-status');
191
- const peerCountDisplay = document.getElementById('peer-count');
192
-
193
- // State
194
- let peer = null;
195
- let connections = [];
196
- let peerId = null;
197
-
198
- // Initialize PeerJS
199
- function initializePeer() {
200
- // Generate a random peer ID
201
- peerId = 'retro-' + Math.random().toString(36).substr(2, 8).toUpperCase();
202
- peerIdDisplay.textContent = peerId;
203
-
204
- // Create peer
205
- peer = new Peer(peerId, {
206
- host: '0.peerjs.com',
207
- port: 443,
208
- secure: true,
209
- config: {
210
- iceServers: [
211
- { urls: 'stun:stun.l.google.com:19302' },
212
- { urls: 'stun:stun1.l.google.com:19302' }
213
- ]
214
- }
215
- });
216
-
217
- // Peer event handlers
218
- peer.on('open', (id) => {
219
- statusIndicator.textContent = 'CONNECTED';
220
- statusIndicator.className = 'bg-[#28c940] px-2 py-1 text-xs font-bold';
221
- connectionStatus.innerHTML = `> Ready to connect! Share ID: <span class="font-bold">${id}</span>`;
222
- messageInput.disabled = false;
223
- sendBtn.disabled = false;
224
- });
225
-
226
- peer.on('connection', (conn) => {
227
- setupConnection(conn);
228
- updatePeerCount();
229
- });
230
-
231
- peer.on('error', (err) => {
232
- console.error('Peer error:', err);
233
- appendMessage(`> ERROR: ${err.type} - ${err.message}`);
234
- statusIndicator.textContent = 'ERROR';
235
- statusIndicator.className = 'bg-[#ff6057] px-2 py-1 text-xs font-bold';
236
- });
237
-
238
- peer.on('disconnected', () => {
239
- statusIndicator.textContent = 'DISCONNECTED';
240
- statusIndicator.className = 'bg-[#ffbd2e] px-2 py-1 text-xs font-bold';
241
- appendMessage('> Disconnected from signaling server');
242
- });
243
- }
244
-
245
- // Set up a connection
246
- function setupConnection(conn) {
247
- connections.push(conn);
248
- updatePeerCount();
249
-
250
- conn.on('open', () => {
251
- appendMessage(`> Connected to peer: ${conn.peer.substr(0, 8)}`);
252
- });
253
-
254
- conn.on('data', (data) => {
255
- appendMessage(`${conn.peer.substr(0, 8)}> ${data}`);
256
- });
257
-
258
- conn.on('close', () => {
259
- connections = connections.filter(c => c.peer !== conn.peer);
260
- appendMessage(`> Disconnected from peer: ${conn.peer.substr(0, 8)}`);
261
- updatePeerCount();
262
- });
263
-
264
- conn.on('error', (err) => {
265
- console.error('Connection error:', err);
266
- appendMessage(`> ERROR with peer ${conn.peer.substr(0, 8)}: ${err.message}`);
267
- });
268
- }
269
-
270
- // Connect to another peer
271
- function connectToPeer(peerId) {
272
- if (!peer) return;
273
-
274
- const conn = peer.connect(peerId);
275
- setupConnection(conn);
276
- }
277
-
278
- // Send message to all connected peers
279
- function broadcastMessage(message) {
280
- if (message.trim() === '') return;
281
-
282
- connections.forEach(conn => {
283
- if (conn.open) {
284
- conn.send(message);
285
- }
286
- });
287
-
288
- appendMessage(`YOU> ${message}`);
289
- messageInput.value = '';
290
- }
291
-
292
- // Append message to display
293
  function appendMessage(message) {
294
  const messageElement = document.createElement('div');
295
  messageElement.textContent = message;
296
  messageContainer.appendChild(messageElement);
297
  messageContainer.scrollTop = messageContainer.scrollHeight;
298
  }
299
-
300
- // Update peer count display
301
- function updatePeerCount() {
302
- peerCountDisplay.textContent = connections.length;
303
- }
304
-
305
- // Event listeners
306
  sendBtn.addEventListener('click', () => {
307
- broadcastMessage(messageInput.value);
 
 
 
 
308
  });
309
-
310
  messageInput.addEventListener('keypress', (e) => {
311
  if (e.key === 'Enter') {
312
- broadcastMessage(messageInput.value);
 
 
 
 
313
  }
314
  });
315
-
316
- // Initialize
317
- initializePeer();
318
-
319
- // Handle URL parameters for connecting to a peer
320
- const urlParams = new URLSearchParams(window.location.search);
321
- const connectTo = urlParams.get('connect');
322
- if (connectTo) {
323
- setTimeout(() => {
324
- connectToPeer(connectTo);
325
- appendMessage(`> Attempting connection to ${connectTo.substr(0, 8)}...`);
326
- }, 2000);
327
- }
328
  });
329
  </script>
330
  <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=commit3r/temp" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
 
137
 
138
  <!-- Main Content -->
139
  <div class="bg-[#c0c0c0] p-4">
 
 
 
 
 
 
 
 
 
 
 
140
 
141
  <!-- Message Display -->
142
  <div class="message-box mb-4 h-64 overflow-hidden">
143
  <div id="message-container" class="terminal-text p-3 h-full overflow-y-auto scrollbar">
144
+ <div>> Simple Text Broadcast</div>
145
+ <div>> Type messages below</div>
 
 
146
  </div>
147
  </div>
148
 
 
159
  </div>
160
  </div>
161
 
 
 
 
 
 
162
  </div>
163
 
164
  <script>
165
  document.addEventListener('DOMContentLoaded', () => {
 
166
  const messageContainer = document.getElementById('message-container');
167
  const messageInput = document.getElementById('message-input');
168
  const sendBtn = document.getElementById('send-btn');
169
+
170
+ // Enable input immediately
171
+ messageInput.disabled = false;
172
+ sendBtn.disabled = false;
173
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
174
  function appendMessage(message) {
175
  const messageElement = document.createElement('div');
176
  messageElement.textContent = message;
177
  messageContainer.appendChild(messageElement);
178
  messageContainer.scrollTop = messageContainer.scrollHeight;
179
  }
180
+
 
 
 
 
 
 
181
  sendBtn.addEventListener('click', () => {
182
+ const message = messageInput.value.trim();
183
+ if (message) {
184
+ appendMessage(`YOU> ${message}`);
185
+ messageInput.value = '';
186
+ }
187
  });
188
+
189
  messageInput.addEventListener('keypress', (e) => {
190
  if (e.key === 'Enter') {
191
+ const message = messageInput.value.trim();
192
+ if (message) {
193
+ appendMessage(`YOU> ${message}`);
194
+ messageInput.value = '';
195
+ }
196
  }
197
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
198
  });
199
  </script>
200
  <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=commit3r/temp" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>