2019-03-25 22:00:54 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace BeyondCode\LaravelWebSockets\PubSub;
|
|
|
|
|
|
|
|
|
|
use React\EventLoop\LoopInterface;
|
2019-03-29 19:33:46 +00:00
|
|
|
use React\Promise\PromiseInterface;
|
2020-08-13 11:02:58 +00:00
|
|
|
use stdClass;
|
2019-03-25 22:00:54 +00:00
|
|
|
|
|
|
|
|
interface ReplicationInterface
|
|
|
|
|
{
|
|
|
|
|
/**
|
2019-03-25 22:37:14 +00:00
|
|
|
* Boot the pub/sub provider (open connections, initial subscriptions, etc).
|
2019-03-25 22:00:54 +00:00
|
|
|
*
|
2020-08-14 05:42:17 +00:00
|
|
|
* @param LoopInterface $loop
|
2020-08-14 12:35:36 +00:00
|
|
|
* @param string|null $factoryClass
|
2019-03-25 22:00:54 +00:00
|
|
|
* @return self
|
|
|
|
|
*/
|
2020-08-14 12:35:36 +00:00
|
|
|
public function boot(LoopInterface $loop, $factoryClass = null): self;
|
2019-03-25 22:00:54 +00:00
|
|
|
|
|
|
|
|
/**
|
2019-03-25 22:37:14 +00:00
|
|
|
* Publish a payload on a specific channel, for a specific app.
|
2019-03-25 22:00:54 +00:00
|
|
|
*
|
2020-08-14 05:42:17 +00:00
|
|
|
* @param string $appId
|
|
|
|
|
* @param string $channel
|
|
|
|
|
* @param stdClass $payload
|
2019-03-25 22:00:54 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2020-08-18 17:21:22 +00:00
|
|
|
public function publish($appId, string $channel, stdClass $payload): bool;
|
2019-03-25 22:00:54 +00:00
|
|
|
|
|
|
|
|
/**
|
2019-03-25 22:37:14 +00:00
|
|
|
* Subscribe to receive messages for a channel.
|
2019-03-25 22:00:54 +00:00
|
|
|
*
|
2020-08-14 05:42:17 +00:00
|
|
|
* @param string $appId
|
|
|
|
|
* @param string $channel
|
2019-03-25 22:00:54 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2020-08-18 17:21:22 +00:00
|
|
|
public function subscribe($appId, string $channel): bool;
|
2019-03-25 22:00:54 +00:00
|
|
|
|
|
|
|
|
/**
|
2019-03-25 22:37:14 +00:00
|
|
|
* Unsubscribe from a channel.
|
2019-03-25 22:00:54 +00:00
|
|
|
*
|
2020-08-14 05:42:17 +00:00
|
|
|
* @param string $appId
|
|
|
|
|
* @param string $channel
|
2019-03-25 22:00:54 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2020-08-18 17:21:22 +00:00
|
|
|
public function unsubscribe($appId, string $channel): bool;
|
2019-03-29 19:33:46 +00:00
|
|
|
|
2020-09-03 13:31:19 +00:00
|
|
|
/**
|
|
|
|
|
* Subscribe to the app's pubsub keyspace.
|
|
|
|
|
*
|
|
|
|
|
* @param mixed $appId
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function subscribeToApp($appId): bool;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Unsubscribe from the app's pubsub keyspace.
|
|
|
|
|
*
|
|
|
|
|
* @param mixed $appId
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function unsubscribeFromApp($appId): bool;
|
|
|
|
|
|
2019-03-29 19:33:46 +00:00
|
|
|
/**
|
|
|
|
|
* Add a member to a channel. To be called when they have
|
|
|
|
|
* subscribed to the channel.
|
|
|
|
|
*
|
2020-08-14 05:42:17 +00:00
|
|
|
* @param string $appId
|
|
|
|
|
* @param string $channel
|
|
|
|
|
* @param string $socketId
|
|
|
|
|
* @param string $data
|
|
|
|
|
* @return void
|
2019-03-29 19:33:46 +00:00
|
|
|
*/
|
2020-08-18 17:21:22 +00:00
|
|
|
public function joinChannel($appId, string $channel, string $socketId, string $data);
|
2019-03-29 19:33:46 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove a member from the channel. To be called when they have
|
|
|
|
|
* unsubscribed from the channel.
|
|
|
|
|
*
|
2020-08-14 05:42:17 +00:00
|
|
|
* @param string $appId
|
|
|
|
|
* @param string $channel
|
|
|
|
|
* @param string $socketId
|
|
|
|
|
* @return void
|
2019-03-29 19:33:46 +00:00
|
|
|
*/
|
2020-08-18 17:21:22 +00:00
|
|
|
public function leaveChannel($appId, string $channel, string $socketId);
|
2019-03-29 19:33:46 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve the full information about the members in a presence channel.
|
|
|
|
|
*
|
2020-08-14 05:42:17 +00:00
|
|
|
* @param string $appId
|
|
|
|
|
* @param string $channel
|
2019-03-29 19:33:46 +00:00
|
|
|
* @return PromiseInterface
|
|
|
|
|
*/
|
2020-08-18 17:21:22 +00:00
|
|
|
public function channelMembers($appId, string $channel): PromiseInterface;
|
2019-03-29 19:33:46 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the amount of users subscribed for each presence channel.
|
|
|
|
|
*
|
2020-08-14 05:42:17 +00:00
|
|
|
* @param string $appId
|
|
|
|
|
* @param array $channelNames
|
2019-03-29 19:33:46 +00:00
|
|
|
* @return PromiseInterface
|
|
|
|
|
*/
|
2020-08-18 17:21:22 +00:00
|
|
|
public function channelMemberCounts($appId, array $channelNames): PromiseInterface;
|
2020-09-03 13:31:19 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the amount of unique connections.
|
|
|
|
|
*
|
|
|
|
|
* @param mixed $appId
|
2020-09-04 08:34:33 +00:00
|
|
|
* @return null|int
|
|
|
|
|
*/
|
|
|
|
|
public function getLocalConnectionsCount($appId);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the amount of connections aggregated on multiple instances.
|
|
|
|
|
*
|
|
|
|
|
* @param mixed $appId
|
2020-09-03 13:31:19 +00:00
|
|
|
* @return null|int|\React\Promise\PromiseInterface
|
|
|
|
|
*/
|
2020-09-04 08:34:33 +00:00
|
|
|
public function getGlobalConnectionsCount($appId);
|
2019-03-25 22:00:54 +00:00
|
|
|
}
|