Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?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() {
Daniel Pocock
committed
global $user;
// 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
committed
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
$caller_domain = variable_get('sip_domain');
$display_name = '';
$caller_uri = '';
$caller_auth_user = '';
$caller_password = '';
$sip_register = FALSE;
if($user->uid != 0 && !empty($caller_domain)) {
// A user is logged in
$display_name = $user->name;
// FIXME: should check that Drupal username is valid for SIP
$caller_uri = 'sip:' . $user->name . '@' . $caller_domain;
$sip_register = TRUE;
} else {
// Guest user
$display_name = variable_get('display_name');
$caller_uri = variable_get('from_uri');
$caller_auth_user = variable_get('auth_user');
$caller_password = variable_get('auth_password');
}
$ws_cookie_secret = variable_get('ws_cookie_secret');
$websocket_server_url = variable_get('websocket_server_url');
$ws_cookies_in_url = variable_get('ws_cookies_in_url');
if(!empty($ws_cookie_secret)) {
$ws_cookie_timeout = variable_get('ws_cookie_timeout'); // seconds
$sip_from = explode(':', $caller_uri)[1];
$sip_to = '*@*';
$ws_cookie_domain = variable_get('ws_cookie_domain');
$ws_url = parse_url($websocket_server_url);
if(empty($ws_cookie_domain)) {
$ws_cookie_domain = $ws_url['host'];
}
$time_limit = REQUEST_TIME + $ws_cookie_timeout; // seconds
$cookie_value = '1:' . REQUEST_TIME . ':' . $time_limit . ':' . $sip_from . ':' . $sip_to;
$cookie_value_encoded = urlencode($cookie_value);
$extra_value = ''; // TODO - a shopping cart ID,
// order ID, customer ID or some other value
// Example sending the Drupal session ID through SIP
if(!empty($user->ssid))
$extra_value = 'drupal:ssid:' . $user->ssid;
else
$extra_value = 'drupal:sid:' . $user->sid;
$extra_value_encoded = urlencode($extra_value);
$digest_input = $cookie_value . ':' . $extra_value;
$cookie_mac = hash_hmac ('sha1', $digest_input, $ws_cookie_secret);
setrawcookie("WSSessionInfo", $cookie_value_encoded, $time_limit, '/', $ws_cookie_domain);
setrawcookie("WSSessionExtra", $extra_value_encoded, $time_limit, '/', $ws_cookie_domain);
setrawcookie("WSSessionMAC", $cookie_mac, $time_limit, '/', $ws_cookie_domain);
if($ws_cookies_in_url) {
if(empty($ws_url['path']))
$websocket_server_url = $websocket_server_url . '/';
$websocket_server_url = $websocket_server_url . ';WSSessionInfo=' . $cookie_value_encoded . ';WSSessionExtra=' . $extra_value_encoded . ';WSSessionMAC=' . $cookie_mac;
}
}
'mod_path' => drupal_get_path('module', 'drucall'),
'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
committed
'display_name' => $display_name,
'impi' => $caller_auth_user,
'impu' => $caller_uri,
'password' => $caller_password,
Daniel Pocock
committed
'websocket_server_url' => $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
committed
'sip_register' => $sip_register,
'extra_header_value' => $extra_value,
);
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'));