/** * @param Session $session * @param PublishMessage $msg */ public function processPublish(Session $session, PublishMessage $msg) { $this->manager->debug("processing publish message"); $receivers = isset($this->topics[$msg->getTopicName()]) ? $this->topics[$msg->getTopicName()] : null; //If the topic doesn't have any subscribers if (empty($receivers)) { $receivers = array(); } // see if they wanted confirmation $options = $msg->getOptions(); if (is_array($options)) { if (isset($options['acknowledge']) && $options['acknowledge'] == true) { $publicationId = Session::getUniqueId(); $session->sendMessage(new PublishedMessage($msg->getRequestId(), $publicationId)); } } $eventMsg = EventMessage::createFromPublishMessage($msg); /* @var $receiver Session */ foreach ($receivers as $receiver) { if ($receiver != $session) { $receiver->sendMessage($eventMsg); } } }
/** * Process publish message * * @param \Thruway\Session $session * @param \Thruway\Message\PublishMessage $msg */ protected function processPublish(Session $session, PublishMessage $msg) { Logger::debug($this, "processing publish message"); $includePublisher = false; $excludedSessions = []; $whiteList = null; $options = $msg->getOptions(); if (is_array($options)) { // see if they wanted confirmation if (isset($options['acknowledge']) && $options['acknowledge'] == true) { $publicationId = Session::getUniqueId(); $session->sendMessage(new PublishedMessage($msg->getRequestId(), $publicationId)); } if (isset($options['exclude_me']) && !$options['exclude_me']) { $includePublisher = true; } if (isset($options['exclude']) && is_array($options['exclude'])) { // fixup exclude array - make sure it is legit foreach ($options['exclude'] as $excludedSession) { if (is_numeric($excludedSession)) { array_push($excludedSessions, $excludedSession); } } } if (isset($options['eligible']) && is_array($options['eligible'])) { $whiteList = []; foreach ($options['eligible'] as $sessionId) { if (is_numeric($sessionId)) { array_push($whiteList, $sessionId); } } } } /* @var $subscription \Thruway\Subscription */ foreach ($this->subscriptions as $subscription) { if ($msg->getTopicName() == $subscription->getTopic() && ($includePublisher || $subscription->getSession() != $session)) { if (!in_array($subscription->getSession()->getSessionId(), $excludedSessions)) { if ($whiteList === null || in_array($subscription->getSession()->getSessionId(), $whiteList)) { $eventMsg = EventMessage::createFromPublishMessage($msg, $subscription->getId()); $this->disclosePublisherOption($session, $eventMsg, $subscription); $subscription->getSession()->sendMessage($eventMsg); } } } } }