EIOWebSocketTransport.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
102
103
104
105
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.eclipse.jetty.websocket.api.RemoteEndpoint
* org.eclipse.jetty.websocket.api.Session
* org.eclipse.jetty.websocket.api.WebSocketListener
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.granite.socketio.impl.engine;
import com.adobe.granite.socketio.impl.engine.EIOPacket;
import com.adobe.granite.socketio.impl.engine.EIOTransport;
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.Future;
import org.eclipse.jetty.websocket.api.RemoteEndpoint;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.WebSocketListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class EIOWebSocketTransport
extends EIOTransport
implements WebSocketListener {
private static final Logger log = LoggerFactory.getLogger(EIOWebSocketTransport.class);
public static final String NAME = "websocket";
public static final Set<String> UPGRADES = Collections.emptySet();
private Session outbound;
private final String id;
public EIOWebSocketTransport(String id) {
this.id = id;
}
@Override
public String getName() {
return "websocket";
}
@Override
public boolean supportsFraming() {
return true;
}
@Override
public Set<String> getUpgrades() {
return UPGRADES;
}
@Override
public /* varargs */ void send(EIOPacket ... packets) {
if (this.outbound == null) {
return;
}
for (EIOPacket packet : packets) {
String encoded = packet.encode();
log.trace("[{}] sendString({})", (Object)this.id, (Object)encoded);
try {
this.outbound.getRemote().sendStringByFuture(encoded).get();
continue;
}
catch (Exception e) {
log.error("[{}] error while sending data", (Throwable)e);
this.onError(e.getMessage());
}
}
}
@Override
protected void doClose() {
log.debug("[{}] closing", (Object)this.id);
if (this.outbound != null) {
this.outbound.close();
}
}
public void onWebSocketConnect(Session session) {
this.outbound = session;
this.onOpen();
}
public void onWebSocketClose(int statusCode, String reason) {
log.debug("[{}] onWebSocketClose({}, {})", new Object[]{this.id, statusCode, reason});
this.outbound = null;
this.onClose();
}
public void onWebSocketError(Throwable cause) {
log.debug("[{}] onWebSocketError()", (Object)this.id, (Object)cause);
this.onError(cause.getMessage());
}
public void onWebSocketText(String message) {
log.trace("[{}] onWebSocketText({})", (Object)this.id, (Object)message);
this.onData(message);
}
public void onWebSocketBinary(byte[] payload, int offset, int len) {
log.trace("[{}] onWebSocketBinary(<data>, {}, {})", new Object[]{this.id, offset, len});
throw new UnsupportedOperationException("binary frames not supported yet.");
}
}