|
@@ -9,13 +9,15 @@ import com.corundumstudio.socketio.annotation.OnDisconnect;
|
|
|
import com.corundumstudio.socketio.annotation.OnEvent;
|
|
|
import com.ym.mec.web.support.anno.NamespaceReference;
|
|
|
import com.ym.mec.web.support.anno.OnNamespace;
|
|
|
-import com.ym.mec.web.support.mes.ChatObject;
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
import org.apache.logging.log4j.Logger;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
|
+/**
|
|
|
+ * var socket = io.connect('http://ip:prot/namespeace')
|
|
|
+ */
|
|
|
|
|
|
@Component
|
|
|
@OnNamespace("/whiteboard")
|
|
@@ -27,8 +29,7 @@ public class WhiteboardHandler {
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 添加connect事件,当客户端发起连接时调用,本文中将clientid与sessionid存入数据库
|
|
|
- * 方便后面发送消息时查找到对应的目标client
|
|
|
+ * 发送初始化房间事件
|
|
|
*/
|
|
|
@OnConnect
|
|
|
public void onConnect(SocketIOClient client) {
|
|
@@ -38,28 +39,20 @@ public class WhiteboardHandler {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 添加@OnDisconnect事件,客户端断开连接时调用,刷新客户端信息
|
|
|
+ * 添加@OnDisconnect事件,客户端断开连接时调用
|
|
|
*/
|
|
|
@OnDisconnect
|
|
|
public void onDisconnect(SocketIOClient client) {
|
|
|
client.disconnect();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
- * test
|
|
|
- *
|
|
|
+ * 加入房间事件
|
|
|
* @param client
|
|
|
* @param data
|
|
|
* @param ackRequest
|
|
|
*/
|
|
|
- @OnEvent(value = "message")
|
|
|
- public void onEvent(SocketIOClient client, ChatObject data, AckRequest ackRequest) {
|
|
|
- System.out.println("chat1 namespace " + namespace.getName());
|
|
|
- namespace.getBroadcastOperations().sendEvent("message", data);
|
|
|
- System.out.println("chat1 sessionId " + client.getSessionId());
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
@OnEvent(value = "join-room")
|
|
|
public void joinRoom(SocketIOClient client, Object data, AckRequest ackRequest) {
|
|
|
BroadcastOperations roomOperations = namespace.getRoomOperations("whiteboard");
|
|
@@ -78,12 +71,24 @@ public class WhiteboardHandler {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 转发 server-broadcast =>client-broadcast
|
|
|
+ * @param client
|
|
|
+ * @param data
|
|
|
+ * @param ackRequest
|
|
|
+ */
|
|
|
@OnEvent(value = "server-broadcast")
|
|
|
public void serverBroadcast(SocketIOClient client, Object data, AckRequest ackRequest) {
|
|
|
BroadcastOperations roomOperations = namespace.getRoomOperations("whiteboard");
|
|
|
roomOperations.sendEvent("client-broadcast", data);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 转发 server-volatile-broadcast =>client-broadcast
|
|
|
+ * @param client
|
|
|
+ * @param data
|
|
|
+ * @param ackRequest
|
|
|
+ */
|
|
|
@OnEvent(value = "server-volatile-broadcast")
|
|
|
public void serverVolatileBroadcast(SocketIOClient client, Object data, AckRequest ackRequest) {
|
|
|
BroadcastOperations roomOperations = namespace.getRoomOperations("whiteboard");
|