3 * StatusNet, the distributed open-source microblogging tool
5 * Plugin to do "real time" updates using Comet/Bayeux
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Evan Prodromou <evan@status.net>
25 * @copyright 2009 StatusNet, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://status.net/
30 if (!defined('GNUSOCIAL') && !defined('STATUSNET')) {
35 * Plugin to do realtime updates using Comet
39 * @author Evan Prodromou <evan@status.net>
40 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
41 * @link http://status.net/
43 class CometPlugin extends RealtimePlugin
45 public $server = null;
46 public $username = null;
47 public $password = null;
48 public $prefix = null;
49 protected $bay = null;
51 function __construct($server=null, $username=null, $password=null, $prefix=null)
53 $this->server = $server;
54 $this->username = $username;
55 $this->password = $password;
56 $this->prefix = $prefix;
58 parent::__construct();
61 function _getScripts()
63 $scripts = parent::_getScripts();
65 $ours = array('js/jquery.comet.js', 'js/cometupdate.js');
67 foreach ($ours as $script) {
68 $scripts[] = $this->path($script);
74 function _updateInitialize($timeline, $user_id)
76 $script = parent::_updateInitialize($timeline, $user_id);
77 return $script." CometUpdate.init(\"$this->server\", \"$timeline\", $user_id, \"$this->replyurl\", \"$this->favorurl\", \"$this->deleteurl\");";
82 require_once INSTALLDIR.'/plugins/Comet/extlib/Bayeux/Bayeux.class.php';
83 // Bayeux? Comet? Huh? These terms confuse me
84 $this->bay = new Bayeux($this->server, $this->user, $this->password);
87 function _publish($timeline, $json)
89 $this->bay->publish($timeline, $json);
92 function _disconnect()
97 function _pathToChannel($path)
99 if (!empty($this->prefix)) {
100 array_unshift($path, $this->prefix);
102 return '/' . implode('/', $path);
105 function onPluginVersion(&$versions)
107 $versions[] = array('name' => 'Comet',
108 'version' => GNUSOCIAL_VERSION,
109 'author' => 'Evan Prodromou',
110 'homepage' => 'http://status.net/wiki/Plugin:Comet',
112 // TRANS: Plugin description message. Bayeux is a protocol for transporting asynchronous messages
113 // TRANS: and Comet is a web application model.
114 _m('Plugin to make updates using Comet and Bayeux.'));