sendTrickleCandidate method

dynamic sendTrickleCandidate (
  1. int handleId,
  2. Map<String, dynamic> candidate
)

Implementation

sendTrickleCandidate(int handleId, Map<String, dynamic> candidate) {
  if (!this.connected) {
    Janus.warn("Is the server down? (connected=false)");
    return;
  }
  Plugin pluginHandle = this.pluginHandles[handleId.toString()];
  if (pluginHandle == null) {
    Janus.warn("Invalid handle");
    return;
  }
  Map<String, dynamic> request = {
    "janus": "trickle",
    "candidate": candidate,
    "transaction": Janus.randomString(12)
  };
  if (pluginHandle.handleToken != null)
    request["token"] = pluginHandle.handleToken;
  if (this.apiSecret != null) request["apisecret"] = this.apiSecret;
  Janus.vdebug(
      "Sending trickle candidate (handle=" + handleId.toString() + "):");
  Janus.vdebug(request);
  if (this.websockets) {
    request["session_id"] = this.sessionId;
    request["handle_id"] = handleId;
    this.ws.send(jsonEncode(request));
    return;
  }

  GatewayCallbacks httpCallbacks = GatewayCallbacks();
  httpCallbacks.success = (json) {
    Janus.vdebug("Candidate sent!");
    Janus.vdebug(json);
    if (json["janus"] != "ack") {
      Janus.error("Ooops: " +
          json["error"]["code"].toString() +
          " " +
          json["error"]["reason"]);
      return;
    }
  };

  httpCallbacks.error = (textStatus, errorThrown) {
    Janus.error(textStatus + ":" + errorThrown); // FIXME
  };

  Janus.httpAPICall(
      this.server +
          "/" +
          this.sessionId.toString() +
          "/" +
          handleId.toString(),
      {
        'verb': 'POST',
        'withCredentials': this.withCredentials,
        'body': request
      },
      httpCallbacks);
}