mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-22 14:41:29 +01:00
move who is available via push to push class and backends
This commit is contained in:
parent
1ac0ff826e
commit
9817d25a47
@ -415,7 +415,8 @@
|
|||||||
{
|
{
|
||||||
egw.json('websocket', {}, undefined, this).openWebSocket(
|
egw.json('websocket', {}, undefined, this).openWebSocket(
|
||||||
egw_script.getAttribute('data-websocket-url'),
|
egw_script.getAttribute('data-websocket-url'),
|
||||||
JSON.parse(egw_script.getAttribute('data-websocket-tokens'))
|
JSON.parse(egw_script.getAttribute('data-websocket-tokens')),
|
||||||
|
parseInt(egw_script.getAttribute('data-websocket-account_id'))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
5
api/js/jsapi/egw_global.d.ts
vendored
5
api/js/jsapi/egw_global.d.ts
vendored
@ -685,11 +685,12 @@ declare class JsonRequest
|
|||||||
* Open websocket to push server (and keeps it open)
|
* Open websocket to push server (and keeps it open)
|
||||||
*
|
*
|
||||||
* @param {string} url this.websocket(s)://host:port
|
* @param {string} url this.websocket(s)://host:port
|
||||||
* @param {array} tokens tokens to subscribe too
|
* @param {array} tokens tokens to subscribe too: sesssion-, user- and instance-token (in that order!)
|
||||||
|
* @param {number} account_id to connect for
|
||||||
* @param {function} error option error callback(_msg) used instead our default this.error
|
* @param {function} error option error callback(_msg) used instead our default this.error
|
||||||
* @param {int} reconnect timeout in ms (internal)
|
* @param {int} reconnect timeout in ms (internal)
|
||||||
*/
|
*/
|
||||||
openWebSocket(url : string, tokens : string[], error : Function, reconnect : number);
|
openWebSocket(url : string, tokens : string[], account_id : number, error : Function, reconnect : number);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -98,11 +98,12 @@ egw.extend('json', egw.MODULE_WND_LOCAL, function(_app, _wnd)
|
|||||||
* Open websocket to push server (and keeps it open)
|
* Open websocket to push server (and keeps it open)
|
||||||
*
|
*
|
||||||
* @param {string} url this.websocket(s)://host:port
|
* @param {string} url this.websocket(s)://host:port
|
||||||
* @param {array} tokens tokens to subscribe too
|
* @param {array} tokens tokens to subscribe too: sesssion-, user- and instance-token (in that order!)
|
||||||
|
* @param {number} account_id to connect for
|
||||||
* @param {function} error option error callback(_msg) used instead our default this.error
|
* @param {function} error option error callback(_msg) used instead our default this.error
|
||||||
* @param {int} reconnect timeout in ms (internal)
|
* @param {int} reconnect timeout in ms (internal)
|
||||||
*/
|
*/
|
||||||
json_request.prototype.openWebSocket = function(url, tokens, error, reconnect)
|
json_request.prototype.openWebSocket = function(url, tokens, account_id, error, reconnect)
|
||||||
{
|
{
|
||||||
const min_reconnect_time = 1000;
|
const min_reconnect_time = 1000;
|
||||||
const max_reconnect_time = 300000;
|
const max_reconnect_time = 300000;
|
||||||
@ -113,7 +114,8 @@ egw.extend('json', egw.MODULE_WND_LOCAL, function(_app, _wnd)
|
|||||||
{
|
{
|
||||||
reconnect_time = min_reconnect_time;
|
reconnect_time = min_reconnect_time;
|
||||||
this.websocket.send(JSON.stringify({
|
this.websocket.send(JSON.stringify({
|
||||||
subscribe: tokens
|
subscribe: tokens,
|
||||||
|
account_id: parseInt(account_id)
|
||||||
}));
|
}));
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
@ -147,7 +149,7 @@ egw.extend('json', egw.MODULE_WND_LOCAL, function(_app, _wnd)
|
|||||||
// e.g. server process killed or network down
|
// e.g. server process killed or network down
|
||||||
// event.code is usually 1006 in this case
|
// event.code is usually 1006 in this case
|
||||||
console.log('[close] Connection died --> reconnect in '+reconnect_time+'ms');
|
console.log('[close] Connection died --> reconnect in '+reconnect_time+'ms');
|
||||||
window.setTimeout(jQuery.proxy(this.openWebSocket, this, url, tokens, error, reconnect_time), reconnect_time);
|
window.setTimeout(jQuery.proxy(this.openWebSocket, this, url, tokens, account_id, error, reconnect_time), reconnect_time);
|
||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
},
|
},
|
||||||
|
@ -49,6 +49,18 @@ class Push extends Msg
|
|||||||
*/
|
*/
|
||||||
const SESSION = null;
|
const SESSION = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How long to cache online status / maximum frequency for querying
|
||||||
|
*/
|
||||||
|
const INSTANCE_ONLINE_CACHE_EXPIRATION = 10;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* account_id's of users currently online
|
||||||
|
*
|
||||||
|
* @var array|null
|
||||||
|
*/
|
||||||
|
protected static $online;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param int $account_id =null account_id to push message too or
|
* @param int $account_id =null account_id to push message too or
|
||||||
@ -67,6 +79,37 @@ class Push extends Msg
|
|||||||
* @throws Exception\NotOnline if $account_id is not online
|
* @throws Exception\NotOnline if $account_id is not online
|
||||||
*/
|
*/
|
||||||
protected function addGeneric($key, $data)
|
protected function addGeneric($key, $data)
|
||||||
|
{
|
||||||
|
self::checkSetBackend();
|
||||||
|
|
||||||
|
self::$backend->addGeneric($this->account_id, $key, $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get users online / connected to push-server
|
||||||
|
*
|
||||||
|
* @return array of integer account_id currently available for push
|
||||||
|
*/
|
||||||
|
public function online()
|
||||||
|
{
|
||||||
|
if (!isset(self::$online))
|
||||||
|
{
|
||||||
|
self::$online = Api\Cache::getInstance(__CLASS__, 'online', function()
|
||||||
|
{
|
||||||
|
self::checkSetBackend();
|
||||||
|
|
||||||
|
return self::$backend->online();
|
||||||
|
}, [], self::INSTANCE_ONLINE_CACHE_EXPIRATION);
|
||||||
|
}
|
||||||
|
return self::$online;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check and if neccessary set push backend
|
||||||
|
*
|
||||||
|
* @throws Exception\NotOnline
|
||||||
|
*/
|
||||||
|
protected function checkSetBackend()
|
||||||
{
|
{
|
||||||
if (!isset(self::$backend))
|
if (!isset(self::$backend))
|
||||||
{
|
{
|
||||||
|
@ -27,4 +27,11 @@ interface PushBackend
|
|||||||
* @throws Exception\NotOnline if $account_id is not online
|
* @throws Exception\NotOnline if $account_id is not online
|
||||||
*/
|
*/
|
||||||
public function addGeneric($account_id, $key, $data);
|
public function addGeneric($account_id, $key, $data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get users online / connected to push-server
|
||||||
|
*
|
||||||
|
* @return array of integer account_id currently available for push
|
||||||
|
*/
|
||||||
|
public function online();
|
||||||
}
|
}
|
||||||
|
@ -135,5 +135,20 @@ class notifications_push implements Json\PushBackend
|
|||||||
{
|
{
|
||||||
self::$db =& $GLOBALS['egw']->db;
|
self::$db =& $GLOBALS['egw']->db;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get users online / connected to push-server
|
||||||
|
*
|
||||||
|
* @return array of integer account_id currently available for push
|
||||||
|
*/
|
||||||
|
public function online()
|
||||||
|
{
|
||||||
|
$online = [];
|
||||||
|
foreach($GLOBALS['egw']->session->session_list(0, 'DESC', 'session_dla', true, ['notification_heartbeat IS NOT NULL']) as $row)
|
||||||
|
{
|
||||||
|
$online[] = (int)$row['account_id'];
|
||||||
|
}
|
||||||
|
return array_unique($online);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
notifications_push::init_static();
|
notifications_push::init_static();
|
||||||
|
Loading…
Reference in New Issue
Block a user