Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Without STOMP , with native Spring Boot WebSocket API #2

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

abhisekmohantychinua
Copy link

Let's keep it very simple. In this version, I have implemented the flow just by changing some of the codes. I have kept it very very simple not going deeper into STOMP protocol. I have used the WebSocket class provided by the browser for web socket connection. Again in spring boot I have inherited 2 classes WebSocketConfigurer and TextWebSocketHandler . Things will be very clear after studying the commits.

  • Read the reference document for Spring Boot here
  • Read reference document for Javascript here

 - Pre existing stomp configuration has been removed
 - New configuration with the help of basic Spring WebSocket API
 - MyHandler.java which handles the different events during connection
 - Pre existing controller has been removed
 - Now login is implemented by overriding afterConnectionEstablished method.
 - The above method is compatible for token based authentication.
 - Instead of broker a List of WebSocketSession has been used to keep connected sessions.
 - Pre existing event handler
 - Now logout is implemented by overriding afterConnectionClosed method.
 - Disconnected session has been removed from stored list.
 - java.lang.IllegalStateException: Message will not be sent because the WebSocket session has been closed
 - The exception is fixed by sending messages to existing session.
 - Now message has been sent to all connected sessions
 - This is implemented by overriding handleTextMessage.
 - Manually publishing the message to all the sessions
 - Optimized previous Javascript code
 - Wrapped up with windows.onload
 - Previous libraries AJAX, Stomp has been removed
 - Instead of them native WebSocket class has been used
 - Unnecessary functions are removed and onMessageReceived, onError has been mapped to corresponding socket method
 - The payload.body has been replaced by payload.data
 - stompClient variable has been replaced by socket
 - No additional changes has been added
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant