|
|
|
@ -1,5 +1,6 @@ |
|
|
|
package app.bcms.jchat.websocket; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import org.apache.commons.logging.Log; |
|
|
|
import org.apache.commons.logging.LogFactory; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
@ -29,6 +30,17 @@ public class WebSocketServer { |
|
|
|
|
|
|
|
@OnMessage |
|
|
|
public void onMessage(String message, Session session) { |
|
|
|
JSONObject json = JSONObject.parseObject(message); |
|
|
|
String mtype = json.getString("type"); |
|
|
|
// 返回的信息
|
|
|
|
JSONObject outjson = new JSONObject(); |
|
|
|
log.info("msg type :"+mtype); |
|
|
|
switch (mtype) { |
|
|
|
case "pong":outjson.put("ping","pong");break; |
|
|
|
} |
|
|
|
// send message
|
|
|
|
String outjsonstr =outjson.toString(); |
|
|
|
WebSocketManager.sentToUser(session,outjsonstr); |
|
|
|
log.info("来自SessionId:"+session.getId()+"的消息:{}"+message); |
|
|
|
} |
|
|
|
|
|
|
|
|