Skip to content
drucall.module 3.28 KiB
Newer Older
Daniel Pocock's avatar
Daniel Pocock committed
<?php



function drucall_menu() {
  $items['drucall'] = array(
    'title' => 'DruCall',
    'page callback' => 'drucall_call',
    'access callback' => TRUE,
    'expanded' => TRUE,
  );

  $items['admin/config/drucall'] = array(
   'title' => 'DruCall WebRTC',
   'description' => 'Configure DruCall.',
   'position' => 'right',
   'weight' => -15,
   'page callback' => 'system_admin_menu_block_page',
   'access arguments' => array('administer drucall'),
   'file' => 'system.admin.inc',
   'file path' => drupal_get_path('module', 'system'),
  );

  $items['admin/config/drucall/settings'] = array(
    'title' => 'Settings',
    'description' => 'Administer DruCall server settings.',
    'weight' => 0,
    'page callback' => 'drupal_get_form',
    'page arguments' => array('drucall_admin'),
    'access arguments' => array('administer drucall'),
    'type' => MENU_LOCAL_TASK | MENU_NORMAL_ITEM,
    'file' => 'drucall.admin.inc',
  );


  return $items;
}

function drucall_theme() {
  return array(
    'drucall_phone' => array(
      'render element' => 'element',
      'template' => 'drucall-phone',
    ),
  );
}

function drucall_call() {
  global $language;

  // Make sure the necessary jQuery UI components are available on
  // the page, Drupal loads core jQuery automatically but not jQuery UI
  drupal_add_library('system', 'ui.draggable');
  drupal_add_library('system', 'ui.resizable');

  // We use the `libraries' module to load javascript dependencies:
  foreach ([ "jssip", "jscommunicator", "arbiterjs", "jqueryi18nproperties", "fontawesome" ] as $libname) {
    if (!($library = libraries_detect($libname))) {
      $error = "failed to load an essential component";
      $error_msg = "failed to load $libname - please install it (check the DruCall instructions)";
    }
    if($library && empty($library['installed'])) {
      $error = $library['error'];
      $error_msg = $library['error message'];
    }
    if(isset($error)) {
      drupal_set_message($error_msg, $error, FALSE);
      return $error;
    } 
    libraries_load($libname);
Daniel Pocock's avatar
Daniel Pocock committed

  $my_settings = array(
      'mod_path' => drupal_get_path('module', 'drucall'),
Daniel Pocock's avatar
Daniel Pocock committed
      'phone_number' => variable_get('default_destination'),
      'enable_audio' => variable_get('enable_audio'),
      'enable_video' => variable_get('enable_video'),
      'enable_chat' => variable_get('enable_chat'),
      'enable_dtmf_pad' => variable_get('enable_dtmf_pad'),
Daniel Pocock's avatar
Daniel Pocock committed
      'display_name' => variable_get('display_name'),
      'impi' => variable_get('auth_user'),
      'impu' => variable_get('from_uri'),
      'password' => variable_get('auth_password'),
      'realm' => variable_get('auth_realm'),
      'websocket_server_url' => variable_get('websocket_server_url'),
      'sip_outboundproxy_url' => variable_get('sip_outboundproxy_url'),
      'turn_server_url' => variable_get('turn_server_url'),
      'turn_username' => variable_get('turn_username'),
      'turn_password' => variable_get('turn_password'),
      'language_code' => $language->language,
Daniel Pocock's avatar
Daniel Pocock committed
  );

  drupal_add_js(
    array('drucall' => $my_settings),
    'setting');

  drupal_add_js(drupal_get_path('module', 'drucall') . '/js/drucall.js');
  drupal_add_css(drupal_get_path('module', 'drucall') . '/css/jscommunicator.css', array('group' => CSS_DEFAULT, 'type' => 'file'));

Daniel Pocock's avatar
Daniel Pocock committed
  return theme('drucall_phone');
}