eventHandler method

dynamic eventHandler ()

Implementation

eventHandler() {
  if (this.sessionId == null) {
    return;
  }
  Janus.debug('Long poll...');
  if (!this.connected) {
    Janus.warn("Is the server down? (connected=false)");
    return;
  }
  String longpoll = this.server +
      "/" +
      this.sessionId.toString() +
      "?rid=" +
      (new DateTime.now()).millisecondsSinceEpoch.toString();
  Janus.log(longpoll);
  if (this.maxev > 0) longpoll = longpoll + "&maxev=" + this.maxev.toString();
  if (this.token != null)
    longpoll = longpoll + "&token=" + Uri.encodeFull(token);
  if (this.apiSecret != null)
    longpoll = longpoll + "&apisecret=" + Uri.encodeFull(this.apiSecret);

  GatewayCallbacks httpCallbacks = GatewayCallbacks();
  httpCallbacks.success = handleEvent;
  httpCallbacks.error = (textStatus, errorThrown) {
    Janus.error(textStatus + ":", errorThrown);
    retries++;
    if (retries > 3) {
      // Did we just lose the server? :-(
      connected = false;
      gatewayCallbacks.error("Lost connection to the server (is it down?)");
      return;
    }
    eventHandler();
  };
  Janus.httpAPICall(longpoll,
      {'verb': 'GET', 'withCredentials': withCredentials}, httpCallbacks);
}