| | |
| | | import com.whyc.config.WebSocketConfig; |
| | | import com.whyc.dto.LockAlmDto; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.pojo.plus_user.UserInf; |
| | | import com.whyc.service.LockAlarmService; |
| | | import com.whyc.util.ActionUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.servlet.http.HttpSession; |
| | | import javax.websocket.*; |
| | | import javax.websocket.server.ServerEndpoint; |
| | | import java.util.HashMap; |
| | |
| | | |
| | | private volatile boolean runFlag = true; |
| | | |
| | | private static HttpSession httpSession; |
| | | |
| | | private volatile Map<String, Thread> threadMap = new HashMap<>(); |
| | | |
| | | private volatile Map<Long,Boolean> threadFlagMap = new HashMap<>(); |
| | |
| | | |
| | | |
| | | @OnOpen |
| | | public void onOpen(Session session) { |
| | | public void onOpen(Session session, EndpointConfig config) { |
| | | this.session = session; |
| | | this.httpSession = (HttpSession) config.getUserProperties().get("httpSession"); |
| | | } |
| | | @OnMessage |
| | | public void onMessage(Session session, String message) { |
| | | LockAlmDto almDto= ActionUtil.getGson().fromJson(message,LockAlmDto.class); |
| | | if(httpSession!=null){ |
| | | UserInf user = (UserInf) httpSession.getAttribute("user"); |
| | | almDto.setUid(user.getUid()); |
| | | }else{ |
| | | almDto.setUid(10001); |
| | | } |
| | | thread = new Thread("Thread_areaLockStateSocket") { |
| | | @Override |
| | | public void run() { |