channels["$appId:$channel"][$socketId] = $data; } /** * Remove a member from the channel. To be called when they have * unsubscribed from the channel. * * @param string $appId * @param string $channel * @param string $socketId */ public function leaveChannel(string $appId, string $channel, string $socketId) { unset($this->channels["$appId:$channel"][$socketId]); if (empty($this->channels["$appId:$channel"])) { unset($this->channels["$appId:$channel"]); } } /** * Retrieve the full information about the members in a presence channel. * * @param string $appId * @param string $channel * @return PromiseInterface */ public function channelMembers(string $appId, string $channel) : PromiseInterface { $data = array_map(function ($user) { return json_decode($user); }, $this->channels["$appId:$channel"]); return new FulfilledPromise($data); } /** * Get the amount of users subscribed for each presence channel. * * @param string $appId * @param array $channelNames * @return PromiseInterface */ public function channelMemberCounts(string $appId, array $channelNames) : PromiseInterface { $data = []; foreach ($channelNames as $channel) { $data[$channel] = count($this->channels["$appId:$channel"]); } return new FulfilledPromise($data); } }