Tell the server we received the message.

@param ProtocolNode $node        The ProtocolTreeNode that contains the message.
@param string       $type
@param string       $participant
@param string       $callId
556408
public function sendReceipt($node, $type = 'read', $participant = null, $callId = null)
    {
        $messageHash = [];
        if ($type == 'read') {
            $messageHash['type'] = $type;
        }
        if ($participant != null) {
            $messageHash['participant'] = $participant;
        }
        $messageHash['to'] = $node->getAttribute('from');
        $messageHash['id'] = $node->getAttribute('id');
        $messageHash['t'] = $node->getAttribute('t');

        if ($callId != null) {
            $offerNode = new ProtocolNode('offer', ['call-id' => $callId], null, null);
            $messageNode = new ProtocolNode('receipt', $messageHash, [$offerNode], null);
        } else {
            $messageNode = new ProtocolNode('receipt', $messageHash, null, null);
        }
        $this->sendNode($messageNode);
        $this->eventManager()->fire('onSendMessageReceived',
            [
                $this->phoneNumber,
                $node->getAttribute('id'),
                $node->getAttribute('from'),
                $type,
            ]);
    }
463925
protected function processInboundDataNode(ProtocolNode $node)
    {
        $this->timeout = time();
        //echo niceVarDump($node);
        $this->debugPrint($node->nodeString('rx  ')."\n");
        $this->serverReceivedId = $node->getAttribute('id');

        if ($node->getTag() == 'challenge') {
            $this->processChallenge($node);
        } elseif ($node->getTag() == 'failure') {
            $this->loginStatus = Constants::DISCONNECTED_STATUS;
            $this->eventManager()->fire('onLoginFailed',
                [
                    $this->phoneNumber,
                    $node->getChild(0)->getTag(),
                ]);
            if ($node->getChild(0)->getTag() == 'not-authorized') {
                $this->logFile('error', 'Blocked number or wrong password. Use blockChecker.php');
            }
        } elseif ($node->getTag() == 'success') {
            if ($node->getAttribute('status') == 'active') {
                $this->loginStatus = Constants::CONNECTED_STATUS;
                $challengeData = $node->getData();
                file_put_contents($this->challengeFilename, $challengeData);
                $this->writer->setKey($this->outputKey);

                $this->eventManager()->fire('onLoginSuccess',
                    [
                        $this->phoneNumber,
                        $node->getAttribute('kind'),
                        $node->getAttribute('status'),
                        $node->getAttribute('creation'),
                        $node->getAttribute('expiration'),
                    ]);
            } elseif ($node->getAttribute('status') == 'expired') {
                $this->eventManager()->fire('onAccountExpired',
                    [
                        $this->phoneNumber,
                        $node->getAttribute('kind'),
                        $node->getAttribute('status'),
                        $node->getAttribute('creation'),
                        $node->getAttribute('expiration'),
                    ]);
            }
        } elseif ($node->getTag() == 'ack') {
            if ($node->getAttribute('class') == 'message') {
                $this->eventManager()->fire('onMessageReceivedServer',
                [
                    $this->phoneNumber,
                    $node->getAttribute('from'),
                    $node->getAttribute('id'),
                    $node->getAttribute('class'),
                    $node->getAttribute('t'),
                ]);
            }
        } elseif ($node->getTag() == 'receipt') {
            if ($node->hasChild('list')) {
                foreach ($node->getChild('list')->getChildren() as $child) {
                    $this->eventManager()->fire('onMessageReceivedClient',
                        [
                            $this->phoneNumber,
                            $node->getAttribute('from'),
                            $child->getAttribute('id'),
                            $node->getAttribute('type'),
                            $node->getAttribute('t'),
                            $node->getAttribute('participant'),
                        ]);
                }
            }
            if ($node->hasChild('retry')) {
                $this->sendGetCipherKeysFromUser(ExtractNumber($node->getAttribute('from')), true);
                $this->messageStore->setPending($node->getAttribute('id'), $node->getAttribute('from'));
            }
            if ($node->hasChild('error') && $node->getChild('error')->getAttribute('type') == 'enc-v1') {
                $this->v1Only[ExtractNumber($node->getAttribute('from'))] = true;
                $this->messageStore->setPending($node->getAttribute('id'), $node->getAttribute('from'));
                $this->sendPendingMessages($node->getAttribute('from'));
            }

            $this->eventManager()->fire('onMessageReceivedClient',
                [
                    $this->phoneNumber,
                    $node->getAttribute('from'),
                    $node->getAttribute('id'),
                    $node->getAttribute('type'),
                    $node->getAttribute('t'),
                    $node->getAttribute('participant'),
                ]);

            $this->sendAck($node, 'receipt');
        }
        if ($node->getTag() == 'message') {
            $handler = new MessageHandler($this, $node);
        }
        if ($node->getTag() == 'presence' && $node->getAttribute('status') == 'dirty') {
            //clear dirty
            $categories = [];
            if (count($node->getChildren()) > 0) {
                foreach ($node->getChildren() as $child) {
                    if ($child->getTag() == 'category') {
                        $categories[] = $child->getAttribute('name');
                    }
                }
            }
            $this->sendClearDirty($categories);
        }
        if (strcmp($node->getTag(), 'presence') == 0
            && strncmp($node->getAttribute('from'), $this->phoneNumber, strlen($this->phoneNumber)) != 0
            && strpos($node->getAttribute('from'), '-') === false) {
            $presence = [];
            if ($node->getAttribute('type') == null) {
                $this->eventManager()->fire('onPresenceAvailable',
                    [
                        $this->phoneNumber,
                        $node->getAttribute('from'),
                    ]);
            } else {
                $this->eventManager()->fire('onPresenceUnavailable',
                    [
                        $this->phoneNumber,
                        $node->getAttribute('from'),
                        $node->getAttribute('last'),
                    ]);
            }
        }
        if ($node->getTag() == 'presence'
            && strncmp($node->getAttribute('from'), $this->phoneNumber, strlen($this->phoneNumber)) != 0
            && strpos($node->getAttribute('from'), '-') !== false
            && $node->getAttribute('type') != null) {
            $groupId = $this->parseJID($node->getAttribute('from'));
            if ($node->getAttribute('add') != null) {
                $this->eventManager()->fire('onGroupsParticipantsAdd',
                    [
                        $this->phoneNumber,
                        $groupId,
                        $this->parseJID($node->getAttribute('add')),
                    ]);
            } elseif ($node->getAttribute('remove') != null) {
                $this->eventManager()->fire('onGroupsParticipantsRemove',
                    [
                        $this->phoneNumber,
                        $groupId,
                        $this->parseJID($node->getAttribute('remove')),
                    ]);
            }
        }
        if (strcmp($node->getTag(), 'chatstate') == 0
            && strncmp($node->getAttribute('from'), $this->phoneNumber, strlen($this->phoneNumber)) != 0) { // remove if isn't group
            if (strpos($node->getAttribute('from'), '-') === false) {
                if ($node->getChild(0)->getTag() == 'composing') {
                    $this->eventManager()->fire('onMessageComposing',
                  [
                    $this->phoneNumber,
                    $node->getAttribute('from'),
                    $node->getAttribute('id'),
                    'composing',
                    $node->getAttribute('t'),
                  ]);
                } else {
                    $this->eventManager()->fire('onMessagePaused',
                  [
                    $this->phoneNumber,
                    $node->getAttribute('from'),
                    $node->getAttribute('id'),
                    'paused',
                    $node->getAttribute('t'),
                  ]);
                }
            } else {
                if ($node->getChild(0)->getTag() == 'composing') {
                    $this->eventManager()->fire('onGroupMessageComposing',
                    [
                      $this->phoneNumber,
                      $node->getAttribute('from'),
                      $node->getAttribute('participant'),
                      $node->getAttribute('id'),
                      'composing',
                      $node->getAttribute('t'),
                    ]);
                } else {
                    $this->eventManager()->fire('onGroupMessagePaused',
                    [
                      $this->phoneNumber,
                      $node->getAttribute('from'),
                      $node->getAttribute('participant'),
                      $node->getAttribute('id'),
                      'paused',
                      $node->getAttribute('t'),
                    ]);
                }
            }
        }
        if ($node->getTag() == 'receipt') {
            $this->eventManager()->fire('onGetReceipt',
                [
                    $node->getAttribute('from'),
                    $node->getAttribute('id'),
                    $node->getAttribute('offline'),
                    $node->getAttribute('retry'),
                ]);
        }
        if ($node->getTag() == 'iq') {
            $handler = new IqHandler($this, $node);
        }

        if ($node->getTag() == 'notification') {
            $handler = new NotificationHandler($this, $node);
        }
        if ($node->getTag() == 'call') {
            if ($node->getChild(0)->getTag() == 'offer') {
                $callId = $node->getChild(0)->getAttribute('call-id');
                $this->sendReceipt($node, null, null, $callId);

                $this->eventManager()->fire('onCallReceived',
                [
                    $this->phoneNumber,
                    $node->getAttribute('from'),
                    $node->getAttribute('id'),
                    $node->getAttribute('notify'),
                    $node->getAttribute('t'),
                    $node->getChild(0)->getAttribute('call-id'),
                ]);
            } else {
                $this->sendAck($node, 'call');
            }
        }
        if ($node->getTag() == 'ib') {
            foreach ($node->getChildren() as $child) {
                switch ($child->getTag()) {
                    case 'dirty':
                        $this->sendClearDirty([$child->getAttribute('type')]);
                        break;
                    case 'account':
                        $this->eventManager()->fire('onPaymentRecieved',
                        [
                            $this->phoneNumber,
                            $child->getAttribute('kind'),
                            $child->getAttribute('status'),
                            $child->getAttribute('creation'),
                            $child->getAttribute('expiration'),
                        ]);
                        break;
                    case 'offline':

                        break;
                    default:
                        throw new Exception('ib handler for '.$child->getTag().' not implemented');
                }
            }
        }

        // Disconnect socket on stream error.
        if ($node->getTag() == 'stream:error') {
            $this->eventManager()->fire('onStreamError',
            [
                $node->getChild(0)->getTag(),
            ]);

            $this->logFile('error', 'Stream error {error}', ['error' => $node->getChild(0)->getTag()]);
            $this->disconnect();
        }
        if (isset($handler)) {
            $handler->Process();
            unset($handler);
        }
    }
81593
public function assertViewingNode($type, TableNode $fields)
    {
        $node = (object) array(
        'type' => $type,
        );
        foreach ($fields->getRowsHash() as $field => $value) {
            $node->{$field} = $value;
        }

        $saved = $this->nodeCreate($node);

        // Set internal browser on the node.
        $this->getSession()->visit($this->locatePath('/node/' . $saved->nid));
    }
388038
protected function addNode(int $start, string $type, int $line, int $offset1, int $offset2, $callback)
    {
        $this->flushText($start, $callback);

        switch ($type) {
            case self::TYPE_VARIABLE_ESCAPE:
                $end = $this->findVariable($start, true);
                break;
            case self::TYPE_VARIABLE_UNESCAPE:
                $end = $this->findVariable($start, false);
                break;
            case self::TYPE_SECTION_OPEN:
                $end = $this->findVariable($start, false);
                break;
            case self::TYPE_SECTION_CLOSE:
            default:
                $end = $this->findVariable($start, false);
                $this->level--;
                break;
        }

        call_user_func($callback, array(
            'type'  => $type,
            'line'  => $line,
            'start' => $start,
            'end'   => $end,
            'level' => $this->level,
            'value' => mb_substr($this->source, $start + $offset1, $end - $start - $offset2)
        ), $this->source);

        if ($type === self::TYPE_SECTION_OPEN) {
            $this->level++;
        }

        return $end - 1;
    }
920551
public function serialize(DAV\Server $server, \DOMElement $errorNode)
    {
        $doc = $errorNode->ownerDocument;

        $np = $doc->createElementNS(CalDAV\Plugin::NS_CALDAV, 'cal:supported-calendar-component');
        $errorNode->appendChild($np);
    }
455935
function(payload, callback) {
    var alice, bob, aliceChannel, bobChannel,
      aliceCandidates = [],
      aliceOffer;
    alice = peercon();
    bob = peercon();
    bob.on('ondatachannel', function (msg) {
      bobChannel = datachan(msg.channel);
      bobChannel.setBinaryType('arraybuffer', function () {});
      bobChannel.on('onmessage', function (msg) {
        alice.close();
        bob.close();
        callback(msg);
      });
    });
    bob.on('onicecandidate', function (msg) {
      msg.candidate && alice.addIceCandidate(msg.candidate);
    });
    alice.on('onicecandidate', function (msg) {
      // firefox needs ice candidates all sent before asking for an answer.
      if (!msg.candidate) {
        bob.setRemoteDescription(aliceOffer).then(function () {
          var last;
          while (aliceCandidates.length) {
            last = bob.addIceCandidate(aliceCandidates.shift());
          }
          return last;
        }).then(function () {
          return bob.createAnswer();
        }).then(function (answer) {
          return bob.setLocalDescription(answer).then(function () {return answer; });
        }).then(function (answer) {
          return alice.setRemoteDescription(answer);
        }, function (err) {
          console.error('RTC failed: ', err);
        });
      } else {
        aliceCandidates.push(msg.candidate);
      }
    });
    alice.createDataChannel('channel').then(function (id) {
      aliceChannel = datachan(id);
      aliceChannel.on('onopen', function () {
        if (payload instanceof ArrayBuffer) {
          aliceChannel.sendBuffer(payload);
        } else {
          aliceChannel.send(payload);
        }
      });
      aliceChannel.setBinaryType('arraybuffer').then(function () {
        return alice.createOffer();
      }).then(function (offer) {
        alice.setLocalDescription(offer);
        aliceOffer = offer;
      });
    }, function (err) {
      console.error('RTC failed: ', err);
    });
  }
1075079
public function findNodes($message_type, $ask)
    {
        $nodes = Node::findByTypeAndPattern($message_type, $ask);

        if ($nodes->count() === 0) {
            $nodes = Node::findByTypeAndPattern('default');
        }

        return $nodes->filter(function ($node) {
            $pageId = Conversation::get('page_id');

            return (empty($node['sources']) || (isset($node->sources['global']) && $node->sources['global'] == true)
                || (isset($node->sources[$pageId]) && $node->sources[$pageId] == true));
        });
    }
722856
public void init (NodeRecord record)
    {
        _record = record;
        _client = new Client(null, _omgr) {
            @Override protected void convertFromRemote (DObject target, DEvent event) {
                super.convertFromRemote(target, event);
                // rewrite the event's target oid using the oid currently configured on the
                // distributed object (we will have it mapped in our remote server's oid space,
                // but it may have been remapped into the oid space of the local server)
                event.setTargetOid(target.getOid());
                // assign an eventId to this event so that our stale event detection code can
                // properly deal with it
                event.eventId = PeerNode.this._omgr.getNextEventId(true);
            }
            @Override protected Communicator createCommunicator () {
                return PeerNode.this.createCommunicator(this);
            }
            @Override protected boolean isFailureLoggable (FailureType type) {
                return (type != FailureType.UNSUBSCRIBE_NOT_PROXIED) &&
                        super.isFailureLoggable(type);
            }
        };
        _client.addClientObserver(this);
        _client.getInvocationDirector().setMaximumListenerAge(getMaximumInvocationWait());
    }
1252408
public function enterNode(Node $node)
    {
        if (!$node instanceof FuncCall && !$node instanceof MethodCall && !$node instanceof StaticCall) {
            return;
        }

        foreach ($node->args as $arg) {
            if ($arg->byRef) {
                throw new FatalErrorException(self::EXCEPTION_MESSAGE, 0, E_ERROR, null, $node->getLine());
            }
        }
    }
1308622
public function invoke($node, NodeInterface $parent): void
    {
        if (! $node instanceof Node\Stmt\ClassMethod || ! $parent instanceof InterfaceModelInterface) {
            throw new Exception('MethodNodeParser is made to parse a method node');
        }

        // Retrieve visibility
        $function = new FunctionModel();
        $function->setVisibility(MethodVisibilityHelper::getVisibility($node));

        // If no private / protected methods parsing is required
        if (! $function->isPublic() && ! $this->config->hasPrivateParsing()) {
            return;
        }

        $function->setParentNode($parent);
        $function->setName($node->name);
        $function->setIsFinal($node->isFinal());
        $function->setIsStatic($node->isStatic());
        $function->setIsAbstract($node->isAbstract());

        $this->parseFunction($node, $function);

        $parent->addFunction($function);

        if ($this->autoGetterOrSetter($function, $parent)) {
            return;
        }
        if (($documentation = $node->getDocComment()) !== null) {
            $this->documentationNodeParser->invoke($documentation, $function);
        }
    }
207563
public function hasType(NodeType $type)
    {
        foreach ($this->types as $t) {
            if ($t->getId() == $type->getId()) { return true; }
        }

        return false;
    }
206724
function (node, type, callback) {
      if (node.addEventListener) {
        node.addEventListener(type, function (e) {
          callback(e, e.target)
        }, false)
      } else if (node.attachEvent) {
        node.attachEvent('on' + type, function (e) {
          callback(e, e.srcElement)
        })
      }
    }
679300
public function createPage(
        $refEntityType,
        $pageTitle,
        $locale,
        Node $parentNode = null)
    {
        $user = $this->getAdminUser();

        $newPage = $this->createNewPage($refEntityType, $pageTitle);
        if (null !== $parentNode) {
            $parentNodeTranslation = $parentNode->getNodeTranslation($locale, true);
            $parentNodeVersion = $parentNodeTranslation->getPublicNodeVersion();
            $parentPage = $parentNodeVersion->getRef($this->em);
            $newPage->setParent($parentPage);
        }

        /* @var Node $nodeNewPage */
        $nodeNewPage = $this->em->getRepository('KunstmaanNodeBundle:Node')->createNodeFor($newPage, $locale, $user);
        $nodeTranslation = $nodeNewPage->getNodeTranslation($locale, true);
        if (null !== $parentNode) {
            $weight = $this->em->getRepository('KunstmaanNodeBundle:NodeTranslation')->getMaxChildrenWeight(
                    $parentNode,
                    $locale
                ) + 1;
            $nodeTranslation->setWeight($weight);
        }

        if ($newPage->isStructureNode()) {
            $nodeTranslation->setSlug('');
        }

        $this->em->persist($nodeTranslation);
        $this->em->flush();

        $nodeVersion = $nodeTranslation->getPublicNodeVersion();

        $this->eventDispatcher->dispatch(
            Events::ADD_NODE,
            new NodeEvent(
                $nodeNewPage, $nodeTranslation, $nodeVersion, $newPage
            )
        );

        return $nodeTranslation;
    }
514271
public function beforeAdoptNode(NodeInterface $node, Context $context, $recursive)
    {
        if (!$this->eventEmittingService->isEnabled()) {
            return;
        }

        if ($this->currentlyAdopting === 0) {
            /* @var $nodeEvent NodeEvent */
            $nodeEvent = $this->eventEmittingService->emit(self::NODE_ADOPT, [
                'targetWorkspace' => $context->getWorkspaceName(),
                'targetDimensions' => $context->getTargetDimensions(),
                'recursive' => $recursive
            ], NodeEvent::class);
            $nodeEvent->setNode($node);
            $this->eventEmittingService->pushContext();
        }

        $this->currentlyAdopting++;
    }
793327
public function sendSetGroupSubject($gjid, $subject)
    {
        $child = new ProtocolNode('subject', null, null, $subject);
        $node = new ProtocolNode('iq',
            [
                'id'    => $this->createIqId(),
                'type'  => 'set',
                'to'    => $this->getJID($gjid),
                'xmlns' => 'w:g2',
            ], [$child], null);

        $this->sendNode($node);
    }
1294223
function assertNodeType(node, type) {
    assertDefined(node, 'should be called with a node');
    assertEqual(node.tNode.type, type, "should be a " + typeName(type));
}
621930
public function createNodes($type, TableNode $nodesTable)
    {
        foreach ($nodesTable->getHash() as $nodeHash) {
            $node = (object) $nodeHash;
            $node->type = $type;
            $this->nodeCreate($node);
        }
    }