package com.cmvr.framework.websocket.handler;

import com.cmvr.framework.websocket.annotation.WSMessageType;
import com.cmvr.framework.websocket.enums.WSMessageTypeEnum;
import com.cmvr.framework.websocket.message.WSCameraCommandMessage;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;

@WSMessageType(value = WSMessageTypeEnum.CAMERA_COMMAND, messageClass = WSCameraCommandMessage.class)
public class CameraCommandMessageHandler implements WSMessageHandler<WSCameraCommandMessage> {

    @Override
    public void handle(WebSocketSession session, WSCameraCommandMessage message) throws Exception {
        String cameraId = message.getCameraId();
        String action = message.getAction();
        if ("open".equals(action)) {
            System.out.println("打开摄像头: " + cameraId);
            session.sendMessage(new TextMessage("摄像头 " + cameraId + " 已打开"));
        } else if ("close".equals(action)) {
            System.out.println("关闭摄像头: " + cameraId);
            session.sendMessage(new TextMessage("摄像头 " + cameraId + " 已关闭"));
        } else {
            System.out.println("未知摄像头操作: " + action);
            session.sendMessage(new TextMessage("未知操作: " + action));
        }
    }
}
