Exemple #1
0
 /**
  * @param  NodeInterface    $node
  * @return MediaInterface
  * @throws RuntimeException
  */
 public function createMedia(NodeInterface $node)
 {
     $type = $node->getAttribute('type');
     $factory = null;
     switch ($type) {
         case self::TYPE_IMAGE:
             $factory = new ImageFactory();
             break;
         case self::TYPE_VIDEO:
             $factory = new VideoFactory();
             break;
         case self::TYPE_AUDIO:
             $factory = new AudioFactory();
             break;
         case self::TYPE_VCARD:
             $factory = new VcardFactory();
             break;
         case self::TYPE_LOCATION:
             $factory = new LocationFactory();
             break;
     }
     if (!$factory) {
         throw new RuntimeException("Media type unknown");
     }
     return $factory->createMedia($node);
 }
Exemple #2
0
 /**
  * @param  NodeInterface  $node
  * @return MediaInterface
  */
 public function createMedia(NodeInterface $node)
 {
     $media = new Vcard();
     $media->setType($node->getAttribute('type'));
     $media->setName($node->getChild('vcard')->getAttribute('name'));
     $media->setData($node->getChild('vcard')->getData());
     return $media;
 }
 /**
  * @param  NodeInterface $node
  * @return AudioInfo
  */
 public function createInfo(NodeInterface $node)
 {
     $media = new AudioInfo();
     $media->setCodec($node->getAttribute('acodec'));
     $media->setBitrate($this->convertIntIfValid($node->getAttribute('abitrate')));
     $media->setSampFreq($this->convertIntIfValid($node->getAttribute('asampfreq')));
     $media->setSampFmt($this->convertIntIfValid($node->getAttribute('asampfmt')));
     return $media;
 }
Exemple #4
0
 /**
  * @param  NodeInterface $node
  * @return $this
  */
 protected function writeInternal(NodeInterface $node)
 {
     $len = 1;
     if ($node->getAttributes() != null) {
         $len += count($node->getAttributes()) * 2;
     }
     if (count($node->getChildren()) > 0) {
         $len += 1;
     }
     if (strlen($node->getData()) > 0) {
         $len += 1;
     }
     $this->writeListStart($len);
     $this->writeString($node->getName());
     $this->writeAttributes($node->getAttributes());
     if (strlen($node->getData()) > 0) {
         $this->writeBytes($node->getData());
     }
     if ($node->getChildren()) {
         $this->writeListStart(count($node->getChildren()));
         foreach ($node->getChildren() as $child) {
             $this->writeInternal($child);
         }
     }
     return $this;
 }
Exemple #5
0
 /**
  * @param  NodeInterface $node
  * @return Presence
  */
 public function createPresence(NodeInterface $node)
 {
     $presence = new Presence();
     $presence->setFrom(Identity::parseJID($node->getAttribute('from')));
     $presence->setLast($node->getAttribute('last'));
     switch ($node->getAttribute('type')) {
         case 'unavailable':
             $presence->setType(Presence::TYPE_UNAVAILABLE);
             break;
         default:
             $presence->setType(Presence::TYPE_AVAILABLE);
     }
     return $presence;
 }
Exemple #6
0
 /**
  * @param  NodeInterface             $node
  * @return MessageMedia|MessageText
  * @throws \InvalidArgumentException
  */
 public function createMessage(NodeInterface $node)
 {
     $type = $node->getAttribute('type');
     switch ($type) {
         case AbstractMessage::TYPE_TEXT:
             $factory = new MessageTextFactory();
             break;
         case AbstractMessage::TYPE_MEDIA:
             $factory = new MessageMediaFactory();
             break;
         default:
             throw new InvalidArgumentException("Invalid message type");
     }
     return $factory->createMessage($node);
 }
 /**
  * @param Client        $client
  * @param NodeInterface $node
  */
 protected function sendNotificationAck(Client $client, NodeInterface $node)
 {
     $ackNode = new Node();
     if ($node->hasAttribute("to")) {
         $ackNode->setAttribute('from', $node->getAttribute("to"));
     }
     if ($node->hasAttribute("participant")) {
         $ackNode->setAttribute('participant', $node->getAttribute("participant"));
     }
     $ackNode->setAttribute('to', $node->getAttribute("from"));
     $ackNode->setAttribute('class', $node->getName());
     $ackNode->setAttribute('id', $node->getAttribute("id"));
     $ackNode->setAttribute('type', $node->getAttribute("type"));
     $client->sendNode($ackNode);
 }
Exemple #8
0
 /**
  * @param  NodeInterface  $node
  * @return MediaInterface
  */
 public function createMedia(NodeInterface $node)
 {
     $media = new Location();
     $media->setType($node->getAttribute('type'));
     $media->setEncoding($node->getAttribute('encoding'));
     $media->setName($node->getAttribute('name'));
     $media->setLongitude((double) $node->getAttribute('longitude'));
     $media->setLatitude((double) $node->getAttribute('latitude'));
     $media->setUrl($node->getAttribute('url'));
     $media->setData($node->getData());
     return $media;
 }
 protected function parseGroupPresence(Client $client, NodeInterface $node)
 {
     $groupId = Identity::parseJID($node->getAttribute('from'));
     if (null != $node->getAttribute('add')) {
         $added = Identity::parseJID($node->getAttribute('add'));
         $client->getEventManager()->trigger('onGroupParticipantAdded', $client, ['group' => $groupId, 'participant' => $added]);
     } elseif (null != $node->getAttribute('remove')) {
         $removed = Identity::parseJID($node->getAttribute('remove'));
         $author = Identity::parseJID($node->getAttribute('author'));
         $client->getEventManager()->trigger('onGroupParticipantRemoved', $client, ['group' => $groupId, 'participant' => $removed, 'author' => $author]);
     }
 }
Exemple #10
0
 /**
  * @param  NodeInterface $node
  * @return VideoInfo
  */
 public function createInfo(NodeInterface $node)
 {
     $media = new VideoInfo();
     $media->setWidth($this->convertIntIfValid($node->getAttribute('width')));
     $media->setHeight($this->convertIntIfValid($node->getAttribute('height')));
     $media->setCodec($node->getAttribute('vcodec'));
     $media->setFps($this->convertIntIfValid($node->getAttribute('fps')));
     $media->setBitrate($this->convertIntIfValid($node->getAttribute('vbitrate')));
     return $media;
 }
 /**
  * @param  NodeInterface $node
  * @return MessageText
  */
 public function createMessage(NodeInterface $node)
 {
     $message = new MessageText();
     $message->setBody($node->getChild('body')->getData());
     $participant = $node->getAttribute('participant');
     $from = $node->getAttribute('from');
     if ($participant) {
         $message->setFrom(Identity::parseJID($participant));
         $message->setGroupId(Identity::parseJID($from));
     } else {
         $message->setFrom(Identity::parseJID($from));
     }
     $message->setId($node->getAttribute('id'));
     $dateTime = new DateTime();
     $dateTime->setTimestamp((int) $node->getAttribute('t'));
     $message->setDateTime($dateTime);
     $message->setNotify($node->getAttribute('notify'));
     $message->setType($node->getAttribute('type'));
     return $message;
 }
Exemple #12
0
 /**
  * @param  NodeInterface  $node
  * @return MediaInterface
  */
 public function createMedia(NodeInterface $node)
 {
     $media = new Image();
     $media->setType($node->getAttribute('type'));
     $media->setIp($node->getAttribute('ip'));
     $media->setData($node->getData());
     $media->setUrl($node->getAttribute('url'));
     $media->setFile($node->getAttribute('file'));
     $media->setMimeType($node->getAttribute('mimetype'));
     $media->setFileHash($node->getAttribute('filehash'));
     $media->setWidth($this->convertIntIfValid($node->getAttribute('width')));
     $media->setHeight($this->convertIntIfValid($node->getAttribute('height')));
     $media->setSize($this->convertIntIfValid($node->getAttribute('size')));
     $media->setEncoding($node->getAttribute('encoding'));
     return $media;
 }
Exemple #13
0
 /**
  * @param  NodeInterface  $node
  * @return MediaInterface
  */
 public function createMedia(NodeInterface $node)
 {
     $media = new Audio();
     $media->setType($node->getAttribute('type'));
     $media->setIp($node->getAttribute('ip'));
     $media->setData($node->getData());
     $media->setUrl($node->getAttribute('url'));
     $media->setFile($node->getAttribute('file'));
     $media->setMimeType($node->getAttribute('mimetype'));
     $media->setFileHash($node->getAttribute('filehash'));
     $media->setSize($this->convertIntIfValid($node->getAttribute('size')));
     $media->setSeconds($this->convertIntIfValid($node->getAttribute('seconds')));
     $media->setDuration($this->convertIntIfValid($node->getAttribute('duration')));
     $media->setAudioInfo($this->getAudioInfoFactory()->createInfo($node));
     return $media;
 }
Exemple #14
0
 protected function sendReceipt(Client $client, NodeInterface $node)
 {
     $receipt = new Receipt();
     $receipt->setTo($node->getAttribute('from'));
     $receipt->setId($node->getAttribute('id'));
     $client->send($receipt);
     return $this;
 }
Exemple #15
0
 /**
  * @param NodeInterface $pingNode
  */
 protected function sendPong(NodeInterface $pingNode)
 {
     $pongNode = new Node();
     $pongNode->setName('iq');
     $pongNode->setAttribute('to', Client::WHATSAPP_SERVER);
     $pongNode->setAttribute('to', $pingNode->getAttribute('id'));
     $pongNode->setAttribute('type', 'result');
     $this->getClient()->sendNode($pongNode);
 }
Exemple #16
0
 /**
  * @param  NodeInterface $node
  * @return bool
  */
 protected function canInjectId(NodeInterface $node)
 {
     if (!$node->hasAttribute('id')) {
         return false;
     }
     $id = $node->getAttribute('id');
     return null === $id || '-' === substr($id, -1, 1);
 }
Exemple #17
0
 /**
  * @param  NodeInterface $node
  * @return bool
  */
 protected function isNodeFromGroup(NodeInterface $node)
 {
     return false !== strpos($node->getAttribute('from'), "-");
 }