|
|
@ -34,6 +34,8 @@ import com.fr.third.socketio.MultiTypeArgs; |
|
|
|
import com.fr.third.socketio.SocketIOClient; |
|
|
|
import com.fr.third.socketio.SocketIOClient; |
|
|
|
import com.fr.third.socketio.SocketIONamespace; |
|
|
|
import com.fr.third.socketio.SocketIONamespace; |
|
|
|
import com.fr.third.socketio.annotation.ScannerEngine; |
|
|
|
import com.fr.third.socketio.annotation.ScannerEngine; |
|
|
|
|
|
|
|
import com.fr.third.socketio.listener.interceptor.EventInterceptor; |
|
|
|
|
|
|
|
import com.fr.third.socketio.listener.interceptor.Interceptor; |
|
|
|
import com.fr.third.socketio.protocol.JsonSupport; |
|
|
|
import com.fr.third.socketio.protocol.JsonSupport; |
|
|
|
import com.fr.third.socketio.protocol.Packet; |
|
|
|
import com.fr.third.socketio.protocol.Packet; |
|
|
|
import com.fr.third.socketio.store.StoreFactory; |
|
|
|
import com.fr.third.socketio.store.StoreFactory; |
|
|
@ -74,6 +76,7 @@ public class Namespace implements SocketIONamespace { |
|
|
|
private final JsonSupport jsonSupport; |
|
|
|
private final JsonSupport jsonSupport; |
|
|
|
private final StoreFactory storeFactory; |
|
|
|
private final StoreFactory storeFactory; |
|
|
|
private final ExceptionListener exceptionListener; |
|
|
|
private final ExceptionListener exceptionListener; |
|
|
|
|
|
|
|
private final Configuration configuration; |
|
|
|
|
|
|
|
|
|
|
|
public Namespace(String name, Configuration configuration) { |
|
|
|
public Namespace(String name, Configuration configuration) { |
|
|
|
super(); |
|
|
|
super(); |
|
|
@ -82,6 +85,7 @@ public class Namespace implements SocketIONamespace { |
|
|
|
this.storeFactory = configuration.getStoreFactory(); |
|
|
|
this.storeFactory = configuration.getStoreFactory(); |
|
|
|
this.exceptionListener = configuration.getExceptionListener(); |
|
|
|
this.exceptionListener = configuration.getExceptionListener(); |
|
|
|
this.ackMode = configuration.getAckMode(); |
|
|
|
this.ackMode = configuration.getAckMode(); |
|
|
|
|
|
|
|
this.configuration = configuration; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void addClient(SocketIOClient client) { |
|
|
|
public void addClient(SocketIOClient client) { |
|
|
@ -137,7 +141,16 @@ public class Namespace implements SocketIONamespace { |
|
|
|
if (entry == null) { |
|
|
|
if (entry == null) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
for (EventInterceptor eventInterceptor: configuration.getEventInterceptors()) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
//不影响后续执行
|
|
|
|
|
|
|
|
if (eventInterceptor.accept(eventName, client, args)) { |
|
|
|
|
|
|
|
eventInterceptor.before(client, args, ackRequest); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
exceptionListener.onEventException(e, args, client); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
try { |
|
|
|
try { |
|
|
|
Queue<DataListener> listeners = entry.getListeners(); |
|
|
|
Queue<DataListener> listeners = entry.getListeners(); |
|
|
|
for (DataListener dataListener : listeners) { |
|
|
|
for (DataListener dataListener : listeners) { |
|
|
@ -149,6 +162,17 @@ public class Namespace implements SocketIONamespace { |
|
|
|
if (ackMode == AckMode.AUTO_SUCCESS_ONLY) { |
|
|
|
if (ackMode == AckMode.AUTO_SUCCESS_ONLY) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
for (EventInterceptor eventInterceptor: configuration.getEventInterceptors()) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
//不影响后续执行
|
|
|
|
|
|
|
|
if (eventInterceptor.accept(eventName, client, args)) { |
|
|
|
|
|
|
|
eventInterceptor.after(client, args, ackRequest); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
exceptionListener.onEventException(e, args, client); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sendAck(ackRequest); |
|
|
|
sendAck(ackRequest); |
|
|
@ -190,12 +214,15 @@ public class Namespace implements SocketIONamespace { |
|
|
|
} |
|
|
|
} |
|
|
|
clientRooms.remove(client.getSessionId()); |
|
|
|
clientRooms.remove(client.getSessionId()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
callInterceptor(client, false, true); |
|
|
|
try { |
|
|
|
try { |
|
|
|
for (DisconnectListener listener : disconnectListeners) { |
|
|
|
for (DisconnectListener listener : disconnectListeners) { |
|
|
|
listener.onDisconnect(client); |
|
|
|
listener.onDisconnect(client); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
exceptionListener.onDisconnectException(e, client); |
|
|
|
exceptionListener.onDisconnectException(e, client); |
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
callInterceptor(client, false, false); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -208,15 +235,39 @@ public class Namespace implements SocketIONamespace { |
|
|
|
join(getName(), client.getSessionId()); |
|
|
|
join(getName(), client.getSessionId()); |
|
|
|
storeFactory.pubSubStore().publish(PubSubType.JOIN, new JoinLeaveMessage(client.getSessionId(), getName(), getName())); |
|
|
|
storeFactory.pubSubStore().publish(PubSubType.JOIN, new JoinLeaveMessage(client.getSessionId(), getName(), getName())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
callInterceptor(client, true, true); |
|
|
|
try { |
|
|
|
try { |
|
|
|
for (ConnectListener listener : connectListeners) { |
|
|
|
for (ConnectListener listener : connectListeners) { |
|
|
|
listener.onConnect(client); |
|
|
|
listener.onConnect(client); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
exceptionListener.onConnectException(e, client); |
|
|
|
exceptionListener.onConnectException(e, client); |
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
callInterceptor(client, true, false); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void callInterceptor(SocketIOClient client, boolean connect, boolean before) { |
|
|
|
|
|
|
|
List<Interceptor> interceptors = connect ? configuration.getConnectInterceptors() : configuration.getDisconnectInterceptors(); |
|
|
|
|
|
|
|
for (Interceptor interceptor: interceptors) { |
|
|
|
|
|
|
|
try{ |
|
|
|
|
|
|
|
if (interceptor.accept(client)) { |
|
|
|
|
|
|
|
if (before) { |
|
|
|
|
|
|
|
interceptor.before(client); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
interceptor.after(client); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
if (connect) { |
|
|
|
|
|
|
|
exceptionListener.onConnectException(e, client); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
exceptionListener.onDisconnectException(e, client); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void addPingListener(PingListener listener) { |
|
|
|
public void addPingListener(PingListener listener) { |
|
|
|
pingListeners.add(listener); |
|
|
|
pingListeners.add(listener); |
|
|
|