streamplace streaming tools
6
fork

Configure Feed

Select the types of activity you want to include in your feed.

Implement DID verifcation

Verifies the DID is real on startup before connecting to any websockets

Woovie 964eb1c0 f48d4b75

+58 -3
+58 -3
src/App.vue
··· 4 4 // My implementation focuses on making it "Vueish" and implementing TTS 5 5 import { ref, onMounted } from "vue" 6 6 import type { Ref } from "vue" 7 + import { verifyStreamplaceDid, type VerificationResult } from "./composables/useDidVerification" 7 8 8 9 type Color = { 9 10 red: number, ··· 118 119 119 120 // TODO enum this 120 121 const websocketStatus = ref<string>('not connected') 122 + const verificationStatus = ref<VerificationResult | null>(null) 123 + const isVerifying = ref(false) 121 124 122 125 const voices = ref<Array<string>>([]) 123 126 const voiceSelector = ref<string | null>(null) ··· 177 180 178 181 let failures = 0 179 182 183 + async function verifyAndConnect() { 184 + if (!streamplaceUsername) { 185 + verificationStatus.value = { 186 + isValid: false, 187 + profile: null, 188 + error: "No username configured" 189 + } 190 + websocketStatus.value = "error: no username" 191 + return 192 + } 193 + 194 + isVerifying.value = true 195 + websocketStatus.value = "verifying username" 196 + 197 + try { 198 + const result = await verifyStreamplaceDid(streamplaceUsername) 199 + verificationStatus.value = result 200 + 201 + if (result.isValid) { 202 + console.log(`Verified user: ${result.profile?.handle} (${result.profile?.did})`) 203 + if (result.profile?.displayName) { 204 + console.log(`Display name: ${result.profile.displayName}`) 205 + } 206 + startChat() 207 + } else { 208 + websocketStatus.value = `error: ${result.error}` 209 + console.error(`Username verification failed: ${result.error}`) 210 + } 211 + } catch (err) { 212 + console.error("Verification error:", err) 213 + verificationStatus.value = { 214 + isValid: false, 215 + profile: null, 216 + error: "Verification failed" 217 + } 218 + websocketStatus.value = "error: verification failed" 219 + } finally { 220 + isVerifying.value = false 221 + } 222 + } 223 + 180 224 function startChat() { 181 225 websocketStatus.value = "connecting" 182 226 ··· 280 324 failures += 1 281 325 const delay = 3000 * Math.pow(2, Math.min(failures - 1, 5)) 282 326 console.log(`reconnecting in ${delay}ms`) 327 + // Skip verification on reconnect since we already verified 283 328 setTimeout(startChat, delay) 284 329 } 285 330 ··· 294 339 }, 5000) 295 340 } 296 341 297 - startChat() 342 + verifyAndConnect() 298 343 </script> 299 344 300 345 <template> ··· 327 372 </div> 328 373 <div class="option"> 329 374 <h1>Websocket Status</h1> 330 - <h2>User {{ streamplaceUsername }}</h2> 331 - <h2>{{ websocketStatus }}</h2> 375 + <h2>User: {{ streamplaceUsername }}</h2> 376 + <h2 v-if="isVerifying">Verifying...</h2> 377 + <h2 v-else-if="verificationStatus?.isValid" style="color: #4ade80;"> 378 + ✓ Verified: {{ verificationStatus.profile?.displayName || verificationStatus.profile?.handle }} 379 + </h2> 380 + <h2 v-else-if="verificationStatus && !verificationStatus.isValid" style="color: #f87171;"> 381 + ✗ {{ verificationStatus.error }} 382 + </h2> 383 + <h2>Status: {{ websocketStatus }}</h2> 384 + <p v-if="verificationStatus?.profile?.did" style="font-size: 0.8rem; color: #9ca3af;"> 385 + DID: {{ verificationStatus.profile.did }} 386 + </p> 332 387 </div> 333 388 </div> 334 389 </div>