本文整理汇总了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);
}