本文整理匯總了Java中org.springframework.web.socket.WebSocketSession.getId方法的典型用法代碼示例。如果您正苦於以下問題:Java WebSocketSession.getId方法的具體用法?Java WebSocketSession.getId怎麽用?Java WebSocketSession.getId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.web.socket.WebSocketSession
的用法示例。
在下文中一共展示了WebSocketSession.getId方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: apply
import org.springframework.web.socket.WebSocketSession; //導入方法依賴的package包/類
@Override
public void apply(ApiRequest request, ApiResponse response, WebSocketSession session) {
String msg = StringEscapeUtils.escapeHtml4(request.getMsg());
if (StringUtils.isBlank(msg)) {
return;
}
Map<String, Object> attributes = session.getAttributes();
String id = session.getId();
DrawPlayerInfo info = ((DrawPlayerInfo) attributes.get("info"));
DrawGuessContext ctx = (DrawGuessContext) attributes.get("ctx");
DrawGameStatus status = ctx.status();
ArrayList<String> msgs = new ArrayList<>(2);
if (status == DrawGameStatus.RUN) {
if (StringUtils.equals(id, ctx.getCurrentUser())) {
protectSecret(info, ctx, msg, msgs);
} else {
processGussPerson(info, ctx, msg, msgs);
}
} else {
msgs.add("<b>" + info.getName() + "</b>: " + msg);
}
response.setCode(DrawCode.DRAW_MSG.getCode()).setData(msgs);
}
示例2: stop
import org.springframework.web.socket.WebSocketSession; //導入方法依賴的package包/類
private synchronized void stop(WebSocketSession session) throws IOException {
String sessionId = session.getId();
if (teacherUserSession != null && teacherUserSession.getSession().getId().equals(sessionId)) {
for (UserSession student : students.values()) {
JsonObject response = new JsonObject();
response.addProperty("id", "stopCommunication");
student.sendMessage(response);
}
log.info("Releasing media pipeline");
if (pipeline != null) {
pipeline.release();
}
pipeline = null;
teacherUserSession = null;
} else if (students.containsKey(sessionId)) {
if (students.get(sessionId).getWebRtcEndpoint() != null) {
students.get(sessionId).getWebRtcEndpoint().release();
}
students.remove(sessionId);
}
}
示例3: afterConnectionEstablished
import org.springframework.web.socket.WebSocketSession; //導入方法依賴的package包/類
@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
String id = session.getId();
clients.put(id, session);
DrawGuessContext ctx = drawGuess.connected(session);
JSONObject obj = new JSONObject();
obj.put("info", session.getAttributes().get("info"));
broadcast(transformToMsg(ApiResponse.code(DrawCode.USER_JOIN.getCode(), obj)), id);
obj.put("players", clients.values()
.stream()
.map((w) -> w.getAttributes().get("info"))
.collect(Collectors.toList()));
obj.put("ctx", ctx);
obj.put("assign", true);
obj.put("timestamp", Instant.now().toEpochMilli());
sendTo(transformToMsg(ApiResponse.code(DrawCode.USER_JOIN.getCode(), obj)), id);
}
示例4: afterConnectionClosed
import org.springframework.web.socket.WebSocketSession; //導入方法依賴的package包/類
@Override
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
String id = session.getId();
clients.remove(id);
drawGuess.closed(session);
broadcast(transformToMsg(ApiResponse.code(DrawCode.USER_LEFT.getCode(), session.getAttributes().get("info"))),
null);
}