Пример #1
0
 /**
  * @param Session $session
  * @param UnsubscribeMessage $msg
  * @return UnsubscribedMessage
  */
 public function processUnsubscribe(Session $session, UnsubscribeMessage $msg)
 {
     $subscription = $this->getSubscriptionById($msg->getSubscriptionId());
     if (!$subscription || !isset($this->topics[$subscription->getTopic()])) {
         $errorMsg = ErrorMessage::createErrorMessageFromMessage($msg);
         $session->sendMessage($errorMsg->setErrorURI('wamp.error.no_such_subscription'));
     }
     $topicName = $subscription->getTopic();
     $subscribers = $this->topics[$topicName];
     /* @var $subscriber Session */
     foreach ($this->topics[$topicName] as $key => $subscriber) {
         if ($subscriber == $session) {
             unset($subscribers[$key]);
         }
     }
     $this->subscriptions->detach($subscription);
     $session->sendMessage(new UnsubscribedMessage($msg->getRequestId()));
 }
Пример #2
0
 /**
  * @param Session $session
  * @param UnsubscribeMessage $msg
  * @return bool|Subscription
  */
 public function processUnsubscribe(Session $session, UnsubscribeMessage $msg)
 {
     if ($this->containsSubscriptionId($msg->getSubscriptionId())) {
         /** @var Subscription $subscription */
         $subscription = $this->subscriptions[$msg->getSubscriptionId()];
         if ($session !== $subscription->getSession()) {
             Logger::alert($this, "Unsubscribe request from non-owner: " . json_encode($msg));
             return false;
         }
         $this->removeSubscription($subscription);
         $session->sendMessage(new UnsubscribedMessage($msg->getRequestId()));
         return $subscription;
     }
     return false;
 }