package com.dcs.hnyz.webSocket;

import com.dcs.hnyz.domain.dto.PageDeviceSubscribeDTO;
import com.dcs.hnyz.webSocket.handler.WebSocketSessionManager;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;

/**
 * PageWebSocketController
 * 处理客户端的订阅请求，记录pageCode和sessionId
 * @author: hmy
 * @date: 2025/5/30 15:59
 */
@CrossOrigin(origins = "*", allowCredentials = "false")
@Controller
public class PageWebSocketController {

    @MessageMapping("/subscribe/pageDevice")
    public void subscribePageDevice(@Payload PageDeviceSubscribeDTO dto, Principal user) {
        WebSocketSessionManager.register(dto.getPageCode(), user.getName(), dto.getDeviceGroupMap());
    }
}
