DisplayImpl.java
3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.socketio.SocketIOEmitter
* com.adobe.granite.socketio.SocketIONamespace
* org.apache.sling.commons.json.JSONArray
* 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.ScreensManagerImpl;
import com.adobe.cq.screens.sessions.impl.ScreensSessionImpl;
import com.adobe.granite.socketio.SocketIOEmitter;
import com.adobe.granite.socketio.SocketIONamespace;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentMap;
import org.apache.sling.commons.json.JSONArray;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
public class DisplayImpl
implements Display {
private final String id;
private final ScreensManagerImpl mgr;
private final List<Device> devices = new LinkedList<Device>();
private ScreensSessionImpl session;
public DisplayImpl(String id, ScreensManagerImpl mgr) {
this.id = id;
this.mgr = mgr;
}
@Override
public String getId() {
return this.id;
}
@Override
public List<Device> getDevices() {
return this.devices;
}
@Override
public ScreensSession getSession() {
return this.session;
}
public ScreensSessionImpl getOrCreateSession(SocketIONamespace nsp) {
if (this.session == null) {
this.session = new ScreensSessionImpl(this, this.mgr);
this.session.open(nsp.to(new String[]{this.id}));
}
return this.session;
}
@Override
public JSONObject toJSON() {
try {
JSONObject obj = new JSONObject();
obj.put("id", (Object)this.id);
JSONArray d = new JSONArray();
obj.put("devices", (Object)d);
for (Device device : this.devices) {
d.put((Object)device.toJSON());
}
if (this.session != null) {
HashMap<String, Object> userData;
ScreensManagerImpl.AuthInfo authInfo = this.session.getAuthInfo();
if (authInfo != null) {
JSONObject auth = new JSONObject();
auth.put("userId", (Object)authInfo.getUserId());
auth.put("tokenId", (Object)authInfo.getTokenId());
obj.put("auth", (Object)auth);
}
if (!(userData = new HashMap<String, Object>(this.session.getUserData())).isEmpty()) {
obj.put("data", userData);
}
}
return obj;
}
catch (JSONException e) {
throw new IllegalStateException((Throwable)e);
}
}
public void close() {
if (this.session != null) {
this.session.close();
}
this.session = null;
}
}