You are here

function nodejs_init in Node.js integration 6

Same name and namespace in other branches
  1. 7 nodejs.module \nodejs_init()

Implements hook_init().

File

./nodejs.module, line 185

Code

function nodejs_init() {
  register_shutdown_function(array(
    'nodejs',
    'sendMessages',
  ));
  $_SESSION['nodejs_config'] = $nodejs_config = nodejs_get_config();
  if (isset($nodejs_config['serviceKey'])) {
    unset($nodejs_config['serviceKey']);
  }
  $socket_io_config = nodejs_get_socketio_js_config($nodejs_config);
  $hackity_hack = <<<JS
//--><!]]>
</script>
<script type="text/javascript" src="{<span class="php-variable">$socket_io_config</span>[<span class="php-string">'path'</span>]}"></script>
<script type="text/javascript">
<!--//--><![CDATA[//><!--]]
JS;
  drupal_add_js($hackity_hack, 'inline', 'header');
  drupal_add_js(drupal_get_path('module', 'nodejs') . '/nodejs.js', 'module', 'footer');
  if (isset($nodejs_config)) {
    foreach ($nodejs_config as $key => $value) {
      drupal_add_js(array(
        'nodejs' => array(
          $key => $value,
        ),
      ), 'setting');
    }
  }
  foreach (nodejs_get_js_handlers() as $handler_file) {
    drupal_add_js($handler_file, 'file', 'footer', FALSE, TRUE);
  }
}