-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
119 additions
and
46 deletions.
There are no files selected for viewing
51 changes: 28 additions & 23 deletions
51
src/main/java/com/backend/elearning/configuration/WebSocketConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,28 @@ | ||
//package com.backend.elearning.configuration; | ||
// | ||
//import org.springframework.context.annotation.Configuration; | ||
//import org.springframework.messaging.simp.config.MessageBrokerRegistry; | ||
//import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; | ||
//import org.springframework.web.socket.config.annotation.StompEndpointRegistry; | ||
//import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; | ||
// | ||
//@Configuration | ||
//@EnableWebSocketMessageBroker | ||
//public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { | ||
// | ||
// @Override | ||
// public void registerStompEndpoints(StompEndpointRegistry registry) { | ||
// registry.addEndpoint("/ws").withSockJS(); | ||
// } | ||
// | ||
// @Override | ||
// public void configureMessageBroker(MessageBrokerRegistry registry) { | ||
// registry.setApplicationDestinationPrefixes("/app"); | ||
// registry.enableSimpleBroker("/topic"); | ||
// } | ||
//} | ||
package com.backend.elearning.configuration; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.messaging.simp.config.MessageBrokerRegistry; | ||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; | ||
import org.springframework.web.socket.config.annotation.StompEndpointRegistry; | ||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; | ||
|
||
@Configuration | ||
@EnableWebSocketMessageBroker | ||
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { | ||
|
||
@Override | ||
public void configureMessageBroker(MessageBrokerRegistry config) { | ||
config.enableSimpleBroker("/topic"); // Topic for broadcasting | ||
config.setApplicationDestinationPrefixes("/app"); // Prefix for client requests | ||
} | ||
|
||
@Override | ||
public void registerStompEndpoints(StompEndpointRegistry registry) { | ||
registry.addEndpoint("/ws") // Plain WebSocket endpoint | ||
.setAllowedOrigins("*"); // Allow frontend origin | ||
|
||
registry.addEndpoint("/sockjs/ws") // SockJS fallback endpoint | ||
.setAllowedOrigins("*") | ||
.withSockJS(); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/com/backend/elearning/domain/chat/ChatService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.backend.elearning.domain.chat; | ||
|
||
public class ChatService { | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/backend/elearning/domain/chat/Message.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.backend.elearning.domain.chat; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public class Message { | ||
private String sender; | ||
private String content; | ||
|
||
// Getters and Setters | ||
public String getSender() { | ||
return sender; | ||
} | ||
|
||
public void setSender(String sender) { | ||
this.sender = sender; | ||
} | ||
|
||
public String getContent() { | ||
return content; | ||
} | ||
|
||
public void setContent(String content) { | ||
this.content = content; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/com/backend/elearning/domain/chat/MessageController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.backend.elearning.domain.chat; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.messaging.handler.annotation.DestinationVariable; | ||
import org.springframework.messaging.simp.SimpMessagingTemplate; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import org.springframework.messaging.handler.annotation.MessageMapping; | ||
import org.springframework.messaging.handler.annotation.SendTo; | ||
import org.springframework.stereotype.Controller; | ||
|
||
@Controller | ||
public class MessageController { | ||
private final SimpMessagingTemplate messagingTemplate; | ||
|
||
public MessageController(SimpMessagingTemplate messagingTemplate) { | ||
this.messagingTemplate = messagingTemplate; | ||
} | ||
@MessageMapping("/chat/{roomId}") // Match room-specific endpoints | ||
public void sendMessage(@DestinationVariable String roomId, Message message) { | ||
// Broadcast message to room-specific topic | ||
messagingTemplate.convertAndSend("/topic/rooms/" + roomId, message); | ||
} | ||
|
||
public static class Message { | ||
private String sender; | ||
private String content; | ||
|
||
// Getters and setters | ||
public String getSender() { | ||
return sender; | ||
} | ||
|
||
public void setSender(String sender) { | ||
this.sender = sender; | ||
} | ||
|
||
public String getContent() { | ||
return content; | ||
} | ||
|
||
public void setContent(String content) { | ||
this.content = content; | ||
} | ||
} | ||
} |
5 changes: 1 addition & 4 deletions
5
src/main/java/com/backend/elearning/domain/classroom/Classroom.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ackend/elearning/reference/Reference.java → ...elearning/domain/reference/Reference.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 1 addition & 4 deletions
5
...arning/reference/ReferenceController.java → ...domain/reference/ReferenceController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...d/elearning/reference/ReferenceGetVM.java → ...ning/domain/reference/ReferenceGetVM.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../elearning/reference/ReferencePostVM.java → ...ing/domain/reference/ReferencePostVM.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...arning/reference/ReferenceRepository.java → ...domain/reference/ReferenceRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...elearning/reference/ReferenceService.java → ...ng/domain/reference/ReferenceService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...rning/reference/ReferenceServiceImpl.java → ...omain/reference/ReferenceServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...kend/elearning/reference/ReferenceVM.java → ...earning/domain/reference/ReferenceVM.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
src/main/java/com/backend/elearning/domain/referencefile/ReferenceFile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
src/main/java/com/backend/elearning/domain/referencefile/ReferenceFileServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters