How to use the @xmpp/xml.Element function in @xmpp/xml

To help you get started, we’ve selected a few @xmpp/xml examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xmppjs / xmpp.js / packages / streamparser / index.js View on Github external
this.parser.on('startElement', (name, attrs) => {
    if (!self.element) {
      self.emit('startElement', name, attrs)
      self.emit('start', new Element(name, attrs))
    }

    // TODO: refuse anything but 
    if (!self.element && (name === 'stream:stream')) {
      self.emit('streamStart', attrs)
    } else {
      let child
      if (!self.element) { // eslint-disable-line no-negated-condition
        /* A new stanza */
        child = new Stanza(name, attrs)
        self.element = child
        /* For maxStanzaSize enforcement */
        self.bytesParsedOnStanzaBegin = self.bytesParsed
      } else {
        /* A child element of a stanza */
        child = new ElementInterface(name, attrs)
github xmppjs / xmpp.js / packages / node-xmpp-core / lib / Connection.js View on Github external
Connection.prototype.onStanza = function (stanza) {
  if (stanza.is('error', NS_STREAM)) {
    var error = new Error('' + getAllText(stanza))
    error.stanza = stanza
    this.socket.emit('error', error)
  } else if (stanza.is('features', this.NS_STREAM) &&
    this.allowTLS &&
    !this.isSecure &&
    stanza.getChild('starttls', this.NS_XMPP_TLS)) {
    /* Signal willingness to perform TLS handshake */
    this.send(new Element('starttls', { xmlns: this.NS_XMPP_TLS }))
  } else if (this.allowTLS &&
    stanza.is('proceed', this.NS_XMPP_TLS)) {
    /* Server is waiting for TLS handshake */
    this.setSecure()
  } else {
    this.emit('stanza', stanza)
  }
}
github xmppjs / xmpp.js / packages / node-xmpp-core / lib / Connection.js View on Github external
Connection.prototype.error = function (condition, message) {
  this.emit('error', new Error(message))

  if (!this.socket || !this.socket.writable) return

  /* RFC 3920, 4.7.1 stream-level errors rules */
  if (!this.streamOpened) this.openStream()

  var error = new Element('stream:error')
  error.c(condition, { xmlns: NS_XMPP_STREAMS })
  if (message) {
    error.c('text', {
      xmlns: NS_XMPP_STREAMS,
      'xml:lang': 'en'
    }).t(message)
  }

  this.send(error)
  this.end()
}
github xmppjs / xmpp.js / packages / connection / index.js View on Github external
headerElement() {
    return new xml.Element('', {
      version: '1.0',
      xmlns: this.NS,
    })
  }
github xmppjs / xmpp.js / packages / websocket / lib / Connection.js View on Github external
footerElement() {
    return new xml.Element('close', {
      xmlns: NS_FRAMING,
    })
  }
github xmppjs / xmpp.js / packages / websocket / lib / FramedParser.js View on Github external
onStartElement(name, attrs) {
    const element = new Element(name, attrs)

    const {cursor} = this

    if (cursor) {
      cursor.append(element)
    }

    this.cursor = element
  }