File tree Expand file tree Collapse file tree 2 files changed +1
-7
lines changed
votingWebSockets-Front/src/VoteApp Expand file tree Collapse file tree 2 files changed +1
-7
lines changed Original file line number Diff line number Diff line change 1
- import React from 'react'
2
1
3
2
export const Votes = ( ) => {
4
3
return (
Original file line number Diff line number Diff line change @@ -30,11 +30,8 @@ export const subscribeToVoteUpdates = (
30
30
onVoteUpdate : ( vote : VoteCountResponse ) => void
31
31
) => {
32
32
33
-
34
- // Establish the WebSocket connection to the server
35
33
const socket = new WebSocket ( 'wss://backend-wspq.onrender.com/ws/voting' ) ;
36
34
37
- // Handle connection open event
38
35
socket . onopen = ( ) => {
39
36
console . log ( 'WebSocket connection established' ) ;
40
37
} ;
@@ -44,7 +41,7 @@ export const subscribeToVoteUpdates = (
44
41
try {
45
42
const voteUpdate : VoteCountResponse = JSON . parse ( event . data ) ;
46
43
console . log ( voteUpdate ) ;
47
- onVoteUpdate ( voteUpdate ) ; // Call the callback function with the received data
44
+ onVoteUpdate ( voteUpdate ) ;
48
45
} catch ( error ) {
49
46
console . error ( 'Error processing WebSocket message:' , error ) ;
50
47
}
@@ -55,7 +52,6 @@ export const subscribeToVoteUpdates = (
55
52
console . error ( 'WebSocket error:' , error ) ;
56
53
} ;
57
54
58
- // Handle WebSocket connection close event
59
55
socket . onclose = ( event ) => {
60
56
if ( event . wasClean ) {
61
57
console . log ( `WebSocket connection closed cleanly, code=${ event . code } , reason=${ event . reason } ` ) ;
@@ -64,7 +60,6 @@ export const subscribeToVoteUpdates = (
64
60
}
65
61
} ;
66
62
67
- // Return a cleanup function to close the WebSocket when it's no longer needed
68
63
return ( ) => {
69
64
socket . close ( ) ;
70
65
} ;
You can’t perform that action at this time.
0 commit comments