You are here

class Nodejs in Node.js integration 6

Same name and namespace in other branches
  1. 7 nodejs.module \Nodejs

Hierarchy

Expanded class hierarchy of Nodejs

1 string reference to 'Nodejs'
nodejs_menu in ./nodejs.module
Implements hook_menu().

File

./nodejs.module, line 584

View source
class Nodejs {
  public static $messages = array();
  public static $config = NULL;
  public static $baseUrl = NULL;
  public static $headers = NULL;
  public static function initConfig() {
    if (!isset(self::$config)) {
      self::$config = nodejs_get_config();
      self::$headers = array(
        'NodejsServiceKey' => self::$config['serviceKey'],
      );
      self::$baseUrl = nodejs_get_url(self::$config);
    }
  }
  public static function getMessages() {
    return self::$messages;
  }
  public static function enqueueMessage(StdClass $message) {
    self::$messages[] = $message;
  }
  public static function sendMessages() {
    foreach (self::$messages as $message) {
      self::sendMessage($message);
    }
  }
  public static function sendMessage(StdClass $message) {
    self::initConfig();
    drupal_alter('nodejs_message', $message);
    $message->clientSocketId = str_replace("/", "", nodejs_get_client_socket_id());
    $request_method = 'POST';
    $request_retry = 3;
    $data = json_encode($message);
    return drupal_http_request(self::$baseUrl . 'nodejs/publish', self::$headers, $request_method, $data, $request_retry);
  }
  public static function setUserPresenceList($uid, array $uids) {
    self::initConfig();
    return drupal_http_request(self::$baseUrl . "nodejs/user/presence-list/{$uid}/" . implode(',', $uids), self::$headers);
  }
  public static function logoutUser($token) {
    self::initConfig();
    return drupal_http_request(self::$baseUrl . "nodejs/user/logout/{$token}", self::$headers);
  }
  public static function sendContentTokenMessage($message) {
    self::initConfig();
    $message->clientSocketId = nodejs_get_client_socket_id();
    $request_method = 'POST';
    $request_retry = 3;
    $data = json_encode($message);
    return drupal_http_request(self::$baseUrl . 'nodejs/content/token/message', self::$headers, $request_method, $data, $request_retry);
  }
  public static function sendContentToken($message) {
    self::initConfig();
    $request_method = 'POST';
    $request_retry = 3;
    $data = json_encode($message);
    return drupal_http_request(self::$baseUrl . 'nodejs/content/token', self::$headers, $request_method, $data, $request_retry);
  }
  public static function kickUser($uid) {
    self::initConfig();
    return drupal_http_request(self::$baseUrl . "nodejs/user/kick/{$uid}", self::$headers);
  }
  public static function addUserToChannel($uid, $channel) {
    self::initConfig();
    return drupal_http_request(self::$baseUrl . "nodejs/user/channel/add/{$channel}/{$uid}", self::$headers);
  }
  public static function removeUserFromChannel($uid, $channel) {
    self::initConfig();
    return drupal_http_request(self::$baseUrl . "nodejs/user/channel/remove/{$channel}/{$uid}", self::$headers);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Nodejs::$baseUrl public static property
Nodejs::$config public static property
Nodejs::$headers public static property
Nodejs::$messages public static property
Nodejs::addUserToChannel public static function
Nodejs::enqueueMessage public static function
Nodejs::getMessages public static function
Nodejs::initConfig public static function
Nodejs::kickUser public static function
Nodejs::logoutUser public static function
Nodejs::removeUserFromChannel public static function
Nodejs::sendContentToken public static function
Nodejs::sendContentTokenMessage public static function
Nodejs::sendMessage public static function
Nodejs::sendMessages public static function
Nodejs::setUserPresenceList public static function