class WebSocketDeviceSession implements DeviceSession {

    @Getter
    @Setter
    private volatile DeviceOperator operator;

    @Setter
    private WebSocketExchange exchange;

    private final long connectTime = System.currentTimeMillis();

    private Duration keepAliveTimeout;

    public WebSocketDeviceSession(DeviceOperator device, WebSocketExchange exchange) {
        this.operator = device;
        this.exchange = exchange;
    }

    @Override
    public String getId() {
        return getDeviceId();
    }

    @Override
    public String getDeviceId() {
        return operator == null ? "unknown" : operator.getDeviceId();
    }

    @Override
    public long lastPingTime() {
        return exchange.getLastKeepAliveTime();
    }

    @Override
    public long connectTime() {
        return connectTime;
    }

    @Override
    public Mono<Boolean> send(EncodedMessage encodedMessage) {
        if (encodedMessage instanceof WebSocketMessage) {
            return exchange
                .send(((WebSocketMessage) encodedMessage))
                .thenReturn(true);
        } else {
            return exchange
                .send(DefaultWebSocketMessage.of(WebSocketMessage.Type.TEXT, encodedMessage.getPayload()))
                .thenReturn(true);
        }

    }

    @Override
    public Transport getTransport() {
        return DefaultTransport.WebSocket;
    }

    @Override
    public void close() {
        exchange.close()
                .subscribe();
    }

    @Override
    public void ping() {
    }

    @Override
    public boolean isAlive() {
        return exchange.isAlive();
    }

    @Override
    public void onClose(Runnable call) {
        exchange.closeHandler(call);
    }

    public InetSocketAddress getAddress() {
        return exchange.getRemoteAddress().orElse(null);
    }

    @Override
    public void setKeepAliveTimeout(Duration timeout) {
        keepAliveTimeout = timeout;
        exchange.setKeepAliveTimeout(timeout);
    }

    @Override
    public Duration getKeepAliveTimeout() {
        return keepAliveTimeout;
    }

    public WebSocketDeviceSession copy() {<FILL_FUNCTION_BODY>}
}

        WebSocketDeviceSession session = new WebSocketDeviceSession(operator, exchange);

        session.setKeepAliveTimeout(keepAliveTimeout);
        return session;
    
<no_super_class>