switch ($cls)
{
+ case 'KeepalivechannelAction':
+ case 'ClosechannelAction':
+ include_once $dir . '/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
+ return false;
case 'Realtime_channel':
include_once $dir.'/'.$cls.'.php';
return false;
}
}
+ /**
+ * Hook for RouterInitialized event.
+ *
+ * @param Net_URL_Mapper $m path-to-action mapper
+ * @return boolean hook return
+ */
+ function onRouterInitialized($m)
+ {
+ $m->connect('main/channel/:channelkey/keepalive',
+ array('action' => 'keepalivechannel'),
+ array('channelkey' => '[a-z0-9]{32}'));
+ $m->connect('main/channel/:channelkey/close',
+ array('action' => 'closechannel'),
+ array('channelkey' => '[a-z0-9]{32}'));
+ return true;
+ }
+
function onEndShowScripts($action)
{
- $timeline = $this->_getTimeline($action);
+ $channel = $this->_getChannel($action);
+
+ if (empty($channel)) {
+ return true;
+ }
+
+ $timeline = $this->_pathToChannel(array($channel->channel_key));
// If there's not a timeline on this page,
// just return true
}
else {
$pluginPath = common_path('plugins/Realtime/');
- $realtimeUI = ' RealtimeUpdate.initActions("'.$url.'", "'.$timeline.'", "'. $pluginPath .'");';
+ $keepalive = common_local_url('keepalivechannel', array('channelkey' => $channel->channel_key));
+ $close = common_local_url('closechannel', array('channelkey' => $channel->channel_key));
+ $realtimeUI = ' RealtimeUpdate.initActions("'.$url.'", "'.$timeline.'", "'. $pluginPath .'", "'.$keepalive.'", "'.$close.'"); ';
}
$script = ' $(document).ready(function() { '.
$realtimeUI.
- $this->_updateInitialize($timeline, $user_id).
+ $this->_updateInitialize($timeline, $user_id).
'}); ';
$action->inlineScript($script);
$json = $this->noticeAsJson($notice);
$this->_connect();
+
+ // XXX: We should probably fan-out here and do a
+ // new queue item for each path
foreach ($paths as $path) {
$channels = Realtime_channel::getAllChannels($action, $arg1, $arg2);
foreach ($channels as $channel) {
+
+ // XXX: We should probably fan-out here and do a
+ // new queue item for each user/path combo
+
if (is_null($channel->user_id)) {
$profile = null;
} else {
return '';
}
+
function _getTimeline($action)
+ {
+ $channel = $this->_getChannel($action);
+ if (empty($channel)) {
+ return null;
+ }
+
+ return $this->_pathToChannel(array($channel->channel_key));
+ }
+
+ function _getChannel($action)
{
$timeline = null;
$arg1 = null;
$action_name,
$arg1,
$arg2);
-
- if (!empty($channel)) {
- $timeline = $this->_pathToChannel(array($channel->channel_key));
- }
-
- return $timeline;
+
+ return $channel;
+ }
+
+ function onStartReadWriteTables(&$alwaysRW, &$rwdb)
+ {
+ $alwaysRW[] = 'realtime_channel';
+ return true;
}
}