Добавлена подписка на стримы по ws

This commit is contained in:
serega6531
2019-04-30 01:20:52 +03:00
parent 0663bbfe6e
commit 0e9820fb46
6 changed files with 106 additions and 7 deletions

View File

@@ -0,0 +1,29 @@
package ru.serega6531.packmate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler;
import ru.serega6531.packmate.service.PacketsSubscriptionService;
@Component
public class WebSocketHandler extends TextWebSocketHandler {
private final PacketsSubscriptionService subscriptionService;
@Autowired
public WebSocketHandler(PacketsSubscriptionService subscriptionService) {
this.subscriptionService = subscriptionService;
}
@Override
public void afterConnectionEstablished(WebSocketSession session) {
subscriptionService.addSubscriber(session);
}
@Override
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) {
subscriptionService.removeSubscriber(session);
}
}