コード例 #1
0
  protected boolean isValidWebRTCConnectionState(
      WebRTCClient webRTCClient1, WebRTCClient webRTCClient2, WebRTCConnection.State state) {

    WebRTCConnection webRTCClient1TowebRTCClient2WebRTCConnection =
        webRTCClient1.getWebRTCConnection(webRTCClient2);

    if (webRTCClient1TowebRTCClient2WebRTCConnection == null) {
      return false;
    }

    WebRTCConnection webRTCClient2TowebRTCClient1WebRTCConnection =
        webRTCClient2.getWebRTCConnection(webRTCClient1);

    if (webRTCClient2TowebRTCClient1WebRTCConnection == null) {
      return false;
    }

    if (webRTCClient1TowebRTCClient2WebRTCConnection
        != webRTCClient2TowebRTCClient1WebRTCConnection) {

      return false;
    }

    if (webRTCClient1TowebRTCClient2WebRTCConnection.getState() != state) {
      return false;
    }

    return true;
  }
コード例 #2
0
  public void checkWebRTCConnectionsStates() {
    for (WebRTCClient webRTCClient : _webRTCClients.values()) {
      for (WebRTCClient otherWebRTCClient : webRTCClient.getWebRTCClients()) {

        WebRTCConnection webRTCConnection = webRTCClient.getWebRTCConnection(otherWebRTCClient);

        if (webRTCConnection.getState() != WebRTCConnection.State.INITIATED) {

          continue;
        }

        long initiatedDurationTime = webRTCConnection.getInitiatedDurationTime();

        if (initiatedDurationTime <= _CONNECTION_TIMEOUT_DURATION_TIME) {

          continue;
        }

        webRTCClient.removeBilateralWebRTCConnection(otherWebRTCClient);

        pushLostConnectionStateWebRTCMail(webRTCClient, otherWebRTCClient, "timeout");

        pushLostConnectionStateWebRTCMail(otherWebRTCClient, webRTCClient, "timeout");
      }
    }
  }
コード例 #3
0
  public void answer(long sourceUserId, long destinationUserId, boolean answer) {

    addWebRTCClient(sourceUserId);

    if (!hasAvailableWebRTCClient(sourceUserId)) {
      return;
    }

    if (!hasAvailableWebRTCClient(destinationUserId)) {
      pushErrorWebRTCMail(destinationUserId, sourceUserId, "unavailableUser");

      return;
    }

    WebRTCClient sourceWebRTCClient = getWebRTCClient(sourceUserId);
    WebRTCClient destinationWebRTCClient = getWebRTCClient(destinationUserId);

    if (!isValidWebRTCConnectionState(
        sourceWebRTCClient, destinationWebRTCClient, WebRTCConnection.State.INITIATED)) {

      pushErrorWebRTCMail(destinationUserId, sourceUserId, "invalidState");

      return;
    }

    WebRTCConnection webRTCConnection =
        sourceWebRTCClient.getWebRTCConnection(destinationWebRTCClient);

    WebRTCClient webRTCConnectionSourceWebRTCClient = webRTCConnection.getSourceWebRTCClient();

    if (webRTCConnectionSourceWebRTCClient == sourceWebRTCClient) {
      pushErrorWebRTCMail(destinationUserId, sourceUserId, "cannotAnswer");

      return;
    }

    if (answer) {
      webRTCConnection.setState(WebRTCConnection.State.CONNECTED);
    } else {
      sourceWebRTCClient.removeBilateralWebRTCConnection(destinationWebRTCClient);
    }

    JSONObject messageJSONObject = JSONFactoryUtil.createJSONObject();

    messageJSONObject.put("answer", answer);
    messageJSONObject.put("type", "answer");

    pushConnectionStateWebRTCMail(sourceWebRTCClient, destinationWebRTCClient, messageJSONObject);
  }
コード例 #4
0
  public void call(long sourceUserId, long destinationUserId) {
    addWebRTCClient(sourceUserId);

    if (!hasAvailableWebRTCClient(sourceUserId)) {
      return;
    }

    if (!hasAvailableWebRTCClient(destinationUserId)) {
      pushErrorWebRTCMail(destinationUserId, sourceUserId, "unavailableUser");

      return;
    }

    WebRTCClient sourceWebRTCClient = getWebRTCClient(sourceUserId);
    WebRTCClient destinationWebRTCClient = getWebRTCClient(destinationUserId);

    if (sourceWebRTCClient.hasWebRTCConnection(destinationWebRTCClient)
        || destinationWebRTCClient.hasWebRTCConnection(sourceWebRTCClient)) {

      pushErrorWebRTCMail(destinationUserId, sourceUserId, "existingConnection");

      return;
    }

    WebRTCConnection webRTCConnection = new WebRTCConnection(sourceWebRTCClient);

    webRTCConnection.setState(WebRTCConnection.State.INITIATED);

    destinationWebRTCClient.addWebRTCConnection(sourceWebRTCClient, webRTCConnection);

    sourceWebRTCClient.addWebRTCConnection(destinationWebRTCClient, webRTCConnection);

    JSONObject messageJSONObject = JSONFactoryUtil.createJSONObject();

    messageJSONObject.put("type", "call");

    pushConnectionStateWebRTCMail(sourceWebRTCClient, destinationWebRTCClient, messageJSONObject);
  }
コード例 #5
0
  public void resetWebRTCClient(long userId) {
    WebRTCClient webRTCClient = getWebRTCClient(userId);

    if (webRTCClient == null) {
      return;
    }

    Set<WebRTCClient> webRTCClients = webRTCClient.getWebRTCClients();

    for (WebRTCClient otherWebRTCClient : webRTCClients) {
      WebRTCConnection webRTCConnection = webRTCClient.getWebRTCConnection(webRTCClient);

      WebRTCConnection.State state = webRTCConnection.getState();

      if (state != WebRTCConnection.State.DISCONNECTED) {
        pushLostConnectionStateWebRTCMail(webRTCClient, otherWebRTCClient, "reset");
      }
    }

    webRTCClient.reset();

    webRTCClient.updatePresenceTime();
  }