DeviceImpl.java 2.55 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.granite.socketio.SocketIONamespace
 *  org.apache.sling.commons.json.JSONException
 *  org.apache.sling.commons.json.JSONObject
 */
package com.adobe.cq.screens.sessions.impl;

import com.adobe.cq.screens.sessions.Device;
import com.adobe.cq.screens.sessions.Display;
import com.adobe.cq.screens.sessions.ScreensSession;
import com.adobe.cq.screens.sessions.impl.DisplayImpl;
import com.adobe.cq.screens.sessions.impl.ScreensSessionImpl;
import com.adobe.granite.socketio.SocketIONamespace;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;

public class DeviceImpl
implements Device {
    private final String id;
    private final DisplayImpl screen;
    private int width;
    private int height;
    private boolean autoRegistered;

    public DeviceImpl(String id, DisplayImpl screen) {
        this.id = id;
        this.screen = screen;
    }

    @Override
    public String getId() {
        return this.id;
    }

    @Override
    public Display getDisplay() {
        return this.screen;
    }

    @Override
    public int getWidth() {
        return this.width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    @Override
    public int getHeight() {
        return this.height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public boolean isAutoRegistered() {
        return this.autoRegistered;
    }

    public void setAutoRegistered(boolean autoRegistered) {
        this.autoRegistered = autoRegistered;
    }

    public ScreensSessionImpl connect(SocketIONamespace nsp) {
        ScreensSessionImpl session = this.screen.getOrCreateSession(nsp);
        session.connect(this);
        return session;
    }

    public boolean isConnected() {
        ScreensSessionImpl session = (ScreensSessionImpl)this.screen.getSession();
        return session != null && session.isConnected(this);
    }

    public void disconnect() {
        ScreensSessionImpl session = (ScreensSessionImpl)this.screen.getSession();
        if (session != null) {
            session.disconnect(this);
        }
    }

    @Override
    public JSONObject toJSON() {
        try {
            JSONObject obj = new JSONObject();
            obj.put("id", (Object)this.id);
            obj.put("w", this.width);
            obj.put("h", this.height);
            return obj;
        }
        catch (JSONException e) {
            throw new IllegalStateException((Throwable)e);
        }
    }
}