--- bbb.module.orig	2010-03-21 00:49:23.000000000 +0000
+++ bbb.module	2010-05-28 14:23:12.000000000 +0000
@@ -18,14 +18,14 @@
 define('BIGBLUEBUTTON_BASE_URL', variable_get('bbb_base_url', 'http://195.34.183.202/bigbluebutton/'));
 define('BIGBLUEBUTTON_CREATE_URL', 'api/create');
 define('BIGBLUEBUTTON_JOIN_URL', 'api/join');
-define('BIGBLUEBUTTON_END_MEETING_URL', 'api/endMeeting');
+define('BIGBLUEBUTTON_END_MEETING_URL', 'api/end');
 define('BIGBLUEBUTTON_GET_MEETING_INFO_URL', 'api/getMeetingInfo');
 define('BIGBLUEBUTTON_IS_MEETING_RUNNING_URL', 'api/isMeetingRunning');
 // Define default settings
 define('BIGBLUEBUTTON_DISPLAY_MODE', variable_get('bbb_display_mode', 'inline'));
 define('BIGBLUEBUTTON_DISPLAY_HEIGHT', variable_get('bbb_display_height', '580px'));
 define('BIGBLUEBUTTON_DISPLAY_WIDTH', variable_get('bbb_display_width', '100%'));
-
+define('DRUPAL_BBB_CCK_DATE_FIELD','field_lesson_time');
 include_once(drupal_get_path('modules', 'bbb') . 'includes/api.bbb.inc');
 
 /* Drupal Core Hooks */
@@ -607,12 +607,12 @@
     case 'attend':
       // Get redirect URL
       $url = parse_url($meeting->url['join_' . $mode]);
-      drupal_goto($url['scheme'] . '://' . $url['host'] . $url['path'], $url['query']);
+      drupal_goto($url['scheme'] . '://' . $url['host']. (isset($url['port']) ? ':'.$url['port'] : '' ) . $url['path'], $url['query']);
       break;
     case 'moderate':
       // Get redirect URL
       $url = parse_url($meeting->url['join_' . $mode]);
-      drupal_goto($url['scheme'] . '://' . $url['host'] . $url['path'], $url['query']);
+      drupal_goto($url['scheme'] . '://' . $url['host'] . (isset($url['port']) ? ':'.$url['port'] : '' ) . $url['path'], $url['query']);
       break;
   }
 }
@@ -663,3 +663,27 @@
   $output .= '</div>';
   return $output;
 }
+
+
+/**
+* Implementation of hook_cron().
+*
+* checks for finishing meetings and sends an end meeting message
+*/
+function bbb_cron() {
+
+// TODO: config fields for timestamp delay
+// use php date() function instead of timestampadd which is only mysql
+ 
+ $res = db_query("select * from content_".DRUPAL_BBB_CCK_DATE_FIELD." where ".DRUPAL_BBB_CCK_DATE_FIELD."_value2 > now() AND ".DRUPAL_BBB_CCK_DATE_FIELD."_value2 < timestampadd(minute,5,now())");
+
+ while ($arr = db_fetch_array($res))
+ {
+   $meeting = bbb_get_meeting($arr['nid']);
+   if ($meeting->is_running)
+   {
+      bbb_api_endMeeting(array('meetingID' => $meeting->meetingID, 'password' => $meeting->moderatorPW));
+   }
+ }
+
+}
