add realtime prototype

This commit is contained in:
Torsten Dittmann committed 2021-02-24 18:12:38 +01:00
1 parent f4f0f32468
commit 46f64b4faa
4 files changed
+195 -64

No files matched your search

+29 -2
View File
@@ -7,6 +7,11 @@ use Utopia\App;
class Realtime
{
/**
* @var string
*/
protected $project = '';
/**
* @var string
*/
@@ -26,15 +31,35 @@ class Realtime
/**
* Event constructor.
*
* @param string $project
* @param string $event
* @param array $payload
*/
public function __construct(string $event, array $payload)
public function __construct(string $project, string $event, array $payload)
{
$this->project = $project;
$this->event = $event;
$this->payload = new Document($payload);
}
/**
* @param string $project
* return $this
*/
public function setProject(string $project): self
{
$this->project = $project;
return $this;
}
/**
* @return string
*/
public function getProject(): string
{
return $this->project;
}
/**
* @param string $event
* return $this
@@ -115,11 +140,13 @@ class Realtime
$redis = new \Redis();
$redis->connect(App::getEnv('_APP_REDIS_HOST', ''), App::getEnv('_APP_REDIS_PORT', ''));
$redis->publish('realtime', json_encode([
'project' => $this->project,
'channels' => $this->channels,
'permissions' => $this->payload->getAttribute('$permissions.read'),
'data' => [
'event' => $this->event,
'timestamp' => time(),
'payload' => $this->payload
'payload' => $this->payload->getArrayCopy()
]
]));