當前位置: 首頁>>代碼示例>>Java>>正文


Java WebSocketSession.getId方法代碼示例

本文整理匯總了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);
}
 
開發者ID:csdbianhua,項目名稱:telemarket-skittle-alley,代碼行數:24,代碼來源:UserMsgHandler.java

示例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);
  }
}
 
開發者ID:jake-kent,項目名稱:TLIVideoConferencingv2,代碼行數:23,代碼來源:CallHandler.java

示例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);
}
 
開發者ID:csdbianhua,項目名稱:telemarket-skittle-alley,代碼行數:18,代碼來源:DrawGuessWebSocket.java

示例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);
}
 
開發者ID:csdbianhua,項目名稱:telemarket-skittle-alley,代碼行數:9,代碼來源:DrawGuessWebSocket.java


注:本文中的org.springframework.web.socket.WebSocketSession.getId方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。