package com.zanxiang.game.module.manage.websocket;

import org.springframework.stereotype.Component;
import org.springframework.web.socket.WebSocketSession;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author : lingfeng
 * @time : 2024-02-23
 * @description : 客服消息SocketSession管理
 */
@Component
public class KfMsgWebSocketSessionRegistry {

    private final ConcurrentHashMap<Long, WebSocketSession> sessions = new ConcurrentHashMap<>();

    public void addSession(Long userId, WebSocketSession session) {
        sessions.put(userId, session);
    }

    public WebSocketSession getSession(Long userId) {
        return sessions.get(userId);
    }

    public void removeSession(Long userId) {
        sessions.remove(userId);
    }

    public List<WebSocketSession> getAllSessions() {
        return new ArrayList<>(sessions.values());
    }
}
