package com.cmvr.framework.websocket.manager;

import cn.hutool.db.Session;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;

import java.io.IOException;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

@Component
public class WSSessionManager {
    private final Set<WebSocketSession> sessionSet = ConcurrentHashMap.newKeySet();

    public void addSession(WebSocketSession session) {
        sessionSet.add(session);
    }

    public void removeSession(WebSocketSession session) {
        sessionSet.remove(session);
    }

    public Collection<WebSocketSession> getAllSessions() {
        return sessionSet;
    }

    public boolean containsSession(Session session) {
        return sessionSet.contains(session);
    }
}
