11async function startSignalR ( ) {
22 try {
3+ // Stap 1: Haal negotiate-informatie op
34 const negotiateResponse = await fetch ( "https://chatproxy.azurewebsites.net/api/negotiate" , {
45 method : "POST"
56 } ) ;
@@ -9,21 +10,30 @@ async function startSignalR() {
910 }
1011
1112 const negotiateData = await negotiateResponse . json ( ) ;
13+ console . log ( "🔐 Negotiation gelukt:" , negotiateData ) ;
1214
15+ // Stap 2: Start de SignalR-verbinding
1316 const connection = new signalR . HubConnectionBuilder ( )
14- . withUrl ( negotiateData . url , {
17+ . withUrl ( "https://chatproxysignalr.service.signalr.net/client/?hub=chat" , {
1518 accessTokenFactory : ( ) => negotiateData . accessToken
1619 } )
1720 . configureLogging ( signalR . LogLevel . Information )
1821 . build ( ) ;
1922
23+ // Stap 3: Ontvang berichten van de backend
2024 connection . on ( "newToken" , token => {
21- streamOutput . textContent += token ;
22- chat . scrollTop = chat . scrollHeight ;
25+ const chat = document . getElementById ( "chat" ) ;
26+ const streamOutput = document . getElementById ( "streamOutput" ) ;
27+ if ( streamOutput && chat ) {
28+ streamOutput . textContent += token ;
29+ chat . scrollTop = chat . scrollHeight ;
30+ }
2331 } ) ;
2432
33+ // Stap 4: Start verbinding
2534 await connection . start ( ) ;
2635 console . log ( "✅ Verbonden met SignalR" ) ;
36+
2737 } catch ( err ) {
2838 console . error ( "❌ SignalR fout:" , err ) ;
2939 }
0 commit comments